Make WordPress Core

Ticket #6969: wp6969_b.diff

File wp6969_b.diff, 2.9 KB (added by mzizka, 17 years ago)

Patch to prevent texturizing of shortcode content

  • wp-includes/shortcodes.php

     
    170170 *
    171171 * @return string The shortcode search regular expression
    172172 */
    173 function get_shortcode_regex() {
     173function get_shortcode_regex($start = false) {
    174174        global $shortcode_tags;
    175175        $tagnames = array_keys($shortcode_tags);
    176176        $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
    177 
    178         return '(.?)\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)';
     177        if ($start) {
     178                return '\[('.$tagregexp.')\b';
     179        } else {
     180                return '(.?)\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)';
     181        }
    179182}
    180183
    181184/**
  • wp-includes/formatting.php

     
    2222 *
    2323 * @since 0.71
    2424 * @uses $wp_cockneyreplace Array of formatted entities for certain common phrases
     25 * @uses get_shortcode_regex() Gets the search pattern for searching shortcodes.
    2526 *
    2627 * @param string $text The text to be formatted
    2728 * @return string The string replaced with html entities
     
    3233        $has_pre_parent = false;
    3334        $output = '';
    3435        $curl = '';
    35         $textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
     36        $shortcode_regex = get_shortcode_regex();
     37        preg_match_all("/$shortcode_regex/s", $text, $shortcode_matches,  PREG_SET_ORDER);
     38        // We must replace \2 with \3 from returned regexp since we are adding a capture.
     39        $regex = '/(<[^>]*>|' . str_replace('\2', '\3', $shortcode_regex) . ')/s';
     40        $textarr = preg_split($regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    3641        $stop = count($textarr);
    3742
    3843        // if a plugin has provided an autocorrect array, use it
     
    5055        $dynamic_characters = array('/\'(\d\d(?:&#8217;|\')?s)/', '/(\s|\A|")\'/', '/(\d+)"/', '/(\d+)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A)"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/(\d+)x(\d+)/');
    5156        $dynamic_replacements = array('&#8217;$1','$1&#8216;', '$1&#8243;', '$1&#8242;', '$1&#8217;$2', '$1&#8220;$2', '&#8221;$1', '&#8217;$1', '$1&#215;$2');
    5257
     58        $skip_count = 0;
     59        $shortcode_start_regex = "/^" . get_shortcode_regex(true) . "/";
     60        $shortcode_idx = 0;
    5361        for ( $i = 0; $i < $stop; $i++ ) {
    5462                $curl = $textarr[$i];
    5563
    56                 if ( !empty($curl) && '<' != $curl{0} && '[' != $curl{0} && $next && !$has_pre_parent) { // If it's not a tag
     64                if ($skip_count > 0) {
     65                        $skip_count--;
     66                        continue;
     67                } elseif (empty($curl)) {
     68                        $next = true;
     69                        continue;
     70                }       elseif (preg_match($shortcode_start_regex, ltrim($curl))) { //shortcode
     71                        $skip_count = count($shortcode_matches[$shortcode_idx++]) - 1;
     72                } elseif ('<' != $curl{0} && $next && !$has_pre_parent) { // If it's not a tag
    5773                        // static strings
    5874                        $curl = str_replace($static_characters, $static_replacements, $curl);
    5975                        // regular expressions