WordPress.org

Make WordPress Core

Ticket #21013: 21013.3.patch

File 21013.3.patch, 4.6 KB (added by SergeyBiryukov, 6 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";
    2854                                 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post_ID ) );
     2853                                $slug = urldecode( $slug );
     2854                                $length = min( 200, mb_strlen( $slug ) );
     2855                                $alt_post_name = mb_substr( $slug, 0, $length - ( strlen( $suffix ) + 1 ) );
     2856                                $alt_post_name = urlencode( rtrim( $alt_post_name, '-' ) . "-$suffix" );
     2857                                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID ) );
    28552858                                $suffix++;
    28562859                        } while ( $post_name_check );
    28572860                        $slug = $alt_post_name;
     
    28652868                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 ) ) {
    28662869                        $suffix = 2;
    28672870                        do {
    2868                                 $alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
     2871                                $slug = urldecode( $slug );
     2872                                $length = min( 200, mb_strlen( $slug ) );
     2873                                $alt_post_name = mb_substr( $slug, 0, $length - ( strlen( $suffix ) + 1 ) );
     2874                                $alt_post_name = urlencode( rtrim( $alt_post_name, '-' ) . "-$suffix" );
    28692875                                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID, $post_parent ) );
    28702876                                $suffix++;
    28712877                        } while ( $post_name_check );
     
    28792885                if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {
    28802886                        $suffix = 2;
    28812887                        do {
    2882                                 $alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
     2888                                $slug = urldecode( $slug );
     2889                                $length = min( 200, mb_strlen( $slug ) );
     2890                                $alt_post_name = mb_substr( $slug, 0, $length - ( strlen( $suffix ) + 1 ) );
     2891                                $alt_post_name = urlencode( rtrim( $alt_post_name, '-' ) . "-$suffix" );
    28832892                                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID ) );
    28842893                                $suffix++;
    28852894                        } while ( $post_name_check );