Make WordPress Core

Ticket #21013: 21013.2.patch

File 21013.2.patch, 4.3 KB (added by SergeyBiryukov, 12 years ago)
  • wp-includes/compat.php

     
    1414}
    1515
    1616if ( !function_exists('mb_substr') ):
    17         function mb_substr( $str, $start, $length=null, $encoding=null ) {
     17        function mb_substr( $str, $start, $length = null, $encoding = null ) {
    1818                return _mb_substr($str, $start, $length, $encoding);
    1919        }
    2020endif;
    2121
    22 function _mb_substr( $str, $start, $length=null, $encoding=null ) {
    23         // the solution below, works only for utf-8, so in case of a different
     22function _mb_substr( $str, $start, $length = null, $encoding = null ) {
     23        // the solution below works only for utf-8, so in case of a different
    2424        // charset, just use built-in substr
    2525        $charset = get_option( 'blog_charset' );
    26         if ( !in_array( $charset, array('utf8', 'utf-8', 'UTF8', 'UTF-8') ) ) {
    27                 return is_null( $length )? substr( $str, $start ) : substr( $str, $start, $length);
     26        if ( !in_array( $charset, array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) {
     27                return is_null( $length ) ? substr( $str, $start ) : substr( $str, $start, $length);
    2828        }
    2929        // use the regex unicode support to separate the UTF-8 characters into an array
    3030        preg_match_all( '/./us', $str, $match );
    31         $chars = is_null( $length )? array_slice( $match[0], $start ) : array_slice( $match[0], $start, $length );
     31        $chars = is_null( $length ) ? array_slice( $match[0], $start ) : array_slice( $match[0], $start, $length );
    3232        return implode( '', $chars );
    3333}
    3434
     35if ( !function_exists('mb_strlen') ):
     36        function mb_strlen( $str, $encoding = null ) {
     37                return _mb_strlen($str, $encoding);
     38        }
     39endif;
     40
     41function _mb_strlen( $str, $encoding = null ) {
     42        // the solution below works only for utf-8, so in case of a different
     43        // charset, just use built-in strlen
     44        $charset = get_option( 'blog_charset' );
     45        if ( !in_array( $charset, array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) {
     46                return strlen( $str );
     47        }
     48        // use the regex unicode support to separate the UTF-8 characters into an array
     49        return preg_match_all( '/./us', $str, $match );
     50}
     51
    3552if ( !function_exists('hash_hmac') ):
    3653function hash_hmac($algo, $data, $key, $raw_output = false) {
    3754        return _hash_hmac($algo, $data, $key, $raw_output);
  • wp-includes/post.php

     
    28502850                if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) {
    28512851                        $suffix = 2;
    28522852                        do {
    2853                                 $alt_post_name = substr ($slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
     2853                                $slug = urldecode( $slug );
     2854                                $length = min( 200, mb_strlen( $slug ) );
     2855                                $alt_post_name = urlencode( mb_substr( $slug, 0, $length - ( strlen( $suffix ) + 1 ) ) . "-$suffix" );
    28542856                                $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post_ID ) );
    28552857                                $suffix++;
    28562858                        } while ( $post_name_check );
     
    28652867                if ( $post_name_check || in_array( $slug, $feeds ) || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug )  || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) {
    28662868                        $suffix = 2;
    28672869                        do {
    2868                                 $alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
     2870                                $slug = urldecode( $slug );
     2871                                $length = min( 200, mb_strlen( $slug ) );
     2872                                $alt_post_name = urlencode( mb_substr( $slug, 0, $length - ( strlen( $suffix ) + 1 ) ) . "-$suffix" );
    28692873                                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID, $post_parent ) );
    28702874                                $suffix++;
    28712875                        } while ( $post_name_check );
     
    28792883                if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {
    28802884                        $suffix = 2;
    28812885                        do {
    2882                                 $alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
     2886                                $slug = urldecode( $slug );
     2887                                $length = min( 200, mb_strlen( $slug ) );
     2888                                $alt_post_name = urlencode( mb_substr( $slug, 0, $length - ( strlen( $suffix ) + 1 ) ) . "-$suffix" );
    28832889                                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID ) );
    28842890                                $suffix++;
    28852891                        } while ( $post_name_check );