WordPress.org

Make WordPress Core

Ticket #16684: 16684.patch

File 16684.patch, 3.4 KB (added by hakre, 3 years ago)

Improved version.

  • wp-includes/formatting.php

     
    2828 */ 
    2929function wptexturize($text) { 
    3030        global $wp_cockneyreplace; 
    31         static $static_setup = false, $opening_quote, $closing_quote, $default_no_texturize_tags, $default_no_texturize_shortcodes, $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements; 
    32         $output = ''; 
    33         $curl = ''; 
    34         $textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE); 
    35         $stop = count($textarr); 
     31        static $opening_quote, $closing_quote, $default_no_texturize_tags, $default_no_texturize_shortcodes, $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements; 
    3632 
    37         // No need to set up these variables more than once 
    38         if (!$static_setup) { 
     33        // No need to set up these static variables more than once 
     34        if ( empty( $opening_quote ) ) { 
    3935                /* translators: opening curly quote */ 
    4036                $opening_quote = _x('&#8220;', 'opening curly quote'); 
    4137                /* translators: closing curly quote */ 
     
    5854 
    5955                $dynamic_characters = array('/\'(\d\d(?:&#8217;|\')?s)/', '/\'(\d)/', '/(\s|\A|[([{<]|")\'/', '/(\d)"/', '/(\d)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A|[([{<])"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/\b(\d+)x(\d+)\b/'); 
    6056                $dynamic_replacements = array('&#8217;$1','&#8217;$1', '$1&#8216;', '$1&#8243;', '$1&#8242;', '$1&#8217;$2', '$1' . $opening_quote . '$2', $closing_quote . '$1', '&#8217;$1', '$1&#215;$2'); 
    61  
    62                 $static_setup = true; 
    6357        } 
    6458 
    6559        // Transform into regexp sub-expression used in _wptexturize_pushpop_element 
     
    7064        $no_texturize_tags_stack = array(); 
    7165        $no_texturize_shortcodes_stack = array(); 
    7266 
    73         for ( $i = 0; $i < $stop; $i++ ) { 
    74                 $curl = $textarr[$i]; 
     67        $textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE); 
    7568 
    76                 if ( !empty($curl) && '<' != $curl[0] && '[' != $curl[0] 
    77                                 && empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack)) { 
    78                         // This is not a tag, nor is the texturization disabled 
    79                         // static strings 
     69        foreach( $textarr as &$curl ) { 
     70                if ( empty( $curl ) ) 
     71                        continue; 
     72 
     73                // Only call _wptexturize_pushpop_element if first char is correct tag opening 
     74                $first = $curl[0]; 
     75                if ('<' === $first) { 
     76                        _wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>'); 
     77                } elseif ('[' === $first) { 
     78                        _wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']'); 
     79                } elseif (empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack)) { 
     80                        // This is not a tag, nor is the texturization disabled static strings 
    8081                        $curl = str_replace($static_characters, $static_replacements, $curl); 
    8182                        // regular expressions 
    8283                        $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl); 
    83                 } elseif (!empty($curl)) { 
    84                         /* 
    85                          * Only call _wptexturize_pushpop_element if first char is correct 
    86                          * tag opening 
    87                          */ 
    88                         if ('<' == $curl[0]) 
    89                                 _wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>'); 
    90                         elseif ('[' == $curl[0]) 
    91                                 _wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']'); 
    9284                } 
    93  
    9485                $curl = preg_replace('/&([^#])(?![a-zA-Z1-4]{1,8};)/', '&#038;$1', $curl); 
    95                 $output .= $curl; 
    9686        } 
    97  
    98         return $output; 
     87        return implode( '', $textarr ); 
    9988} 
    10089 
    10190/**