Make WordPress Core

Ticket #10702: 10702.diff

File 10702.diff, 3.2 KB (added by kovshenin, 12 years ago)
  • wp-includes/shortcodes.php

     
    147147        if (empty($shortcode_tags) || !is_array($shortcode_tags))
    148148                return $content;
    149149
     150        if ( ! strstr( $content, '[' ) )
     151                return $content;
     152
    150153        $pattern = get_shortcode_regex();
    151         return preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content );
     154        $count = 1;
     155        while ( $count )
     156                $content = preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content, -1, $count );
     157
     158        // Restore [[shortcode]] notation
     159        $content = str_replace( array( '%escaped_shortcode_tag%', '%/escaped_shortcode_tag%' ), array( '[', ']' ), $content );
     160        return $content;
    152161}
    153162
    154163/**
     
    178187
    179188        // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag()
    180189        // Also, see shortcode_unautop() and shortcode.js.
    181         return
     190        $pattern =
    182191                  '\\['                              // Opening bracket
    183192                . '(\\[?)'                           // 1: Optional second opening bracket for escaping shortcodes: [[tag]]
    184193                . "($tagregexp)"                     // 2: Shortcode name
     
    193202                . '(?:'
    194203                .     '(\\/)'                        // 4: Self closing tag ...
    195204                .     '\\]'                          // ... and closing bracket
     205
    196206                . '|'
    197207                .     '\\]'                          // Closing bracket
     208
     209                .     '(?='                          // Positive lookahead, match the tag only if followed by...
     210                .         '[^\\[]*'                  // A non-opening bracket
     211                .         '\\[\\/\\2\\]'             // Followed by the tag's closing tag
     212                .     ')'
     213
    198214                .     '(?:'
    199215                .         '('                        // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags
    200216                .             '[^\\[]*+'             // Not an opening bracket
     
    204220                .             ')*+'
    205221                .         ')'
    206222                .         '\\[\\/\\2\\]'             // Closing shortcode tag
    207                 .     ')?'
     223                .     ')'
     224
     225                . '|'
     226                .     '\\]'                          // Closing bracket
     227                .     '(?!.*\\[\\/\\2\\])'           // Closing shortcode tag
     228
    208229                . ')'
    209230                . '(\\]?)';                          // 6: Optional second closing brocket for escaping shortcodes: [[tag]]
     231
     232        return $pattern;
    210233}
    211234
    212235/**
     
    225248
    226249        // allow [[foo]] syntax for escaping a tag
    227250        if ( $m[1] == '[' && $m[6] == ']' ) {
    228                 return substr($m[0], 1, -1);
     251                return '%escaped_shortcode_tag%' . substr( $m[0], 2, -2 ) . '%/escaped_shortcode_tag%';
    229252        }
    230253
    231254        $tag = $m[2];
     
    320343
    321344        $pattern = get_shortcode_regex();
    322345
    323         return preg_replace_callback( "/$pattern/s", 'strip_shortcode_tag', $content );
     346        $count = 1;
     347        while ( $count )
     348                $content = preg_replace_callback( "/$pattern/s", 'strip_shortcode_tag', $content, -1, $count );
     349
     350        $content = str_replace( array( '%escaped_shortcode_tag%', '%/escaped_shortcode_tag%' ), array( '[', ']' ), $content );
     351        return $content;
    324352}
    325353
    326354function strip_shortcode_tag( $m ) {
    327355        // allow [[foo]] syntax for escaping a tag
    328356        if ( $m[1] == '[' && $m[6] == ']' ) {
    329                 return substr($m[0], 1, -1);
     357                return '%escaped_shortcode_tag%' . substr( $m[0], 2, -2 ) . '%/escaped_shortcode_tag%';
    330358        }
    331359
    332360        return $m[1] . $m[6];