Make WordPress Core

Ticket #15600: 15600.3.diff

File 15600.3.diff, 6.2 KB (added by mdawaffe, 12 years ago)
  • wp-includes/shortcodes.php

     
    148148                return $content;
    149149
    150150        $pattern = get_shortcode_regex();
    151         return preg_replace_callback('/'.$pattern.'/s', 'do_shortcode_tag', $content);
     151        return preg_replace_callback( "/$pattern/sx", 'do_shortcode_tag', $content );
    152152}
    153153
    154154/**
     
    175175        $tagnames = array_keys($shortcode_tags);
    176176        $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
    177177
    178         // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcodes()
    179         return '(.?)\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)';
     178        // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag()
     179        return "
     180                \\[                              # Opening bracket
     181                (\\[?)                           # 1: Optional second opening bracket for escaping shortcodes: [[tag]]
     182                ( $tagregexp )                   # 2: Shortcode name
     183                \\b                              # Word boundary
     184                (                                # 3: Unroll the loop: Inside the opening shortcode tag
     185                    [^\\]'\"\\/]*                # Not a closing bracket, single or double quote, or forward slash
     186                    (?:
     187                        (?:
     188                            '[^']*+'             # Anything in single quotes
     189                        |
     190                            \"[^\"]*+\"          # Anything in double quotes
     191                        |
     192                            \\/(?!\\])           # A forward slash not followed by a closing bracket
     193                        )
     194                        [^\\]'\"\\/]*            # Not a closing bracket, single or double quote, or forward slash
     195                    )*?
     196                )
     197                (?:
     198                    \\/\\]                       # Self closing tag and closing bracket
     199                |
     200                    \\]                          # Closing bracket
     201                    (?:
     202                        (                        # 4: Unroll the loop: Optionally, anything between the opening and closing shortcode tags
     203                            [^\\[]*+             # Not an opening bracket
     204                            (?:
     205                                \\[(?!\\/\\2\\]) # An opening bracket not followed by the closing shortcode tag
     206                                [^\\[]*+         # Not an opening bracket
     207                            )*+
     208                        )
     209                        \\[\\/\\2\\]             # Closing shortcode tag
     210                    )?
     211                )
     212                (\\]?)                           # 5: Optional second closing brocket for escaping shortcodes: [[tag]]
     213        ";
    180214}
    181215
    182216/**
     
    194228        global $shortcode_tags;
    195229
    196230        // allow [[foo]] syntax for escaping a tag
    197         if ( $m[1] == '[' && $m[6] == ']' ) {
     231        if ( $m[1] == '[' && $m[5] == ']' ) {
    198232                return substr($m[0], 1, -1);
    199233        }
    200234
    201235        $tag = $m[2];
    202236        $attr = shortcode_parse_atts( $m[3] );
    203237
    204         if ( isset( $m[5] ) ) {
     238        if ( isset( $m[4] ) ) {
    205239                // enclosing tag - extra parameter
    206                 return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, $m[5], $tag ) . $m[6];
     240                return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, $m[4], $tag ) . $m[5];
    207241        } else {
    208242                // self-closing tag
    209                 return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, NULL,  $tag ) . $m[6];
     243                return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, NULL,  $tag ) . $m[5];
    210244        }
    211245}
    212246
     
    290324
    291325        $pattern = get_shortcode_regex();
    292326
    293         return preg_replace('/'.$pattern.'/s', '$1$6', $content);
     327        return preg_replace_callback( "/$pattern/sx", 'strip_shortcode_tag', $content );
    294328}
    295329
     330function strip_shortcode_tag( $m ) {
     331        // allow [[foo]] syntax for escaping a tag
     332        if ( $m[1] == '[' && $m[5] == ']' ) {
     333                return substr($m[0], 1, -1);
     334        }
     335
     336        return $m[1] . $m[5];
     337}
     338
    296339add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop()
    297340
    298 ?>
    299  No newline at end of file
     341?>
  • wp-includes/formatting.php

     
    232232 * @param string $pee The content.
    233233 * @return string The filtered content.
    234234 */
    235 function shortcode_unautop($pee) {
     235function shortcode_unautop( $pee ) {
    236236        global $shortcode_tags;
    237237
    238         if ( !empty($shortcode_tags) && is_array($shortcode_tags) ) {
    239                 $tagnames = array_keys($shortcode_tags);
    240                 $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
    241                 $pee = preg_replace('/<p>\\s*?(\\[(' . $tagregexp . ')\\b.*?\\/?\\](?:.+?\\[\\/\\2\\])?)\\s*<\\/p>/s', '$1', $pee);
     238        if ( empty( $shortcode_tags ) || !is_array( $shortcode_tags ) ) {
     239                return $pee;
    242240        }
    243241
    244         return $pee;
     242        $tagregexp = join( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) );
     243
     244        $pattern = "/
     245                <p>                              # Opening paragraph
     246                \\s*+                            # Optional leading whitespace
     247                (                                # 1: The shortcode
     248                    \\[                          # Opening bracket
     249                    ( $tagregexp )               # 2: Shortcode name
     250                    \\b                          # Word boundary
     251                                                 # Unroll the loop: Inside the opening shortcode tag
     252                    [^\\]'\"\\/]*                # Not a closing bracket, single or double quote, or forward slash
     253                    (?:
     254                        (?:
     255                            '[^']*+'             # Anything in single quotes
     256                        |
     257                            \"[^\"]*+\"          # Anything in double quotes
     258                        |
     259                            \\/(?!\\])           # A forward slash not followed by a closing bracket
     260                        )
     261                        [^\\]'\"\\/]*            # Not a closing bracket, single or double quote, or forward slash
     262                    )*?
     263                    (?:
     264                        \\/\\]                   # Self closing tag and closing bracket
     265                    |
     266                        \\]                      # Closing bracket
     267                        (?:                      # Unroll the loop: Optionally, anything between the opening and closing shortcode tags
     268                            [^\\[]*+             # Not an opening bracket
     269                            (?:
     270                                \\[(?!\\/\\2\\]) # An opening bracket not followed by the closing shortcode tag
     271                                [^\\[]*+         # Not an opening bracket
     272                            )*+
     273                            \\[\\/\\2\\]         # Closing shortcode tag
     274                        )?
     275                    )
     276                )
     277                \\s*+                            # optional trailing whitespace
     278                <\\/p>                           # closing paragraph
     279        /sx";
     280
     281        return preg_replace( $pattern, '$1', $pee );
    245282}
    246283
    247284/**