Make WordPress Core

Ticket #10082: 10082.3.diff

File 10082.3.diff, 2.2 KB (added by dd32, 16 years ago)
  • wp-includes/shortcodes.php

     
    175175        $tagnames = array_keys($shortcode_tags);
    176176        $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
    177177
    178         return '(.?)\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)';
     178        return '(\[?)'                                                                          // possibly escape shortcode, part 1
     179                . "\[($tagregexp)"                                                              // a valid shortcode, e.g. [foo
     180                        . '(?=[\s\]\/])'                                                        // Only match the shortcode if its followed by a space, a closing slash, or a closing bracket
     181                        . '(.*?)'                                                                       // maybe attributes
     182                        . '(\/)?'                                                                       // mark self-closing shortcode with a /
     183                        . '\]'
     184                . '('
     185                        . '?(4)'                                                                        // stop if the shortcode is self-closing
     186                . '|'
     187                        . '(?:'
     188                                . "((?:(?!\[(?:\\2)\b).)*?)"            // look-ahead to make the shortcodes non-greedy
     189                                . '\[\/\2\]'                                                    // stop on [/foo]
     190                        . ')?'
     191                . ')?'                                                                                  // allow for [foo] to be treated as [foo/]
     192                . '(\]?)';                                                                              // possibly escape shortcode, part 2
    179193}
    180194
    181195/**
     
    192206function do_shortcode_tag($m) {
    193207        global $shortcode_tags;
    194208
    195         // allow [[foo]] syntax for escaping a tag
    196         if ($m[1] == '[' && $m[6] == ']') {
    197                 return substr($m[0], 1, -1);
    198         }
     209        $return = array_shift($m);
     210        $begin = array_shift($m);
     211        $end = array_pop($m);
    199212
    200         $tag = $m[2];
    201         $attr = shortcode_parse_atts($m[3]);
     213        // allow [[foo]] and [[foo]bar[/foo]] syntax for escaping a tag
     214        if ( $begin == '[' && $end == ']' )
     215                return substr($return, 1, -1);
    202216
    203         if ( isset($m[5]) ) {
     217        $tag = array_shift($m);
     218        $attr = array_shift($m);
     219        $content = array_pop($m);
     220       
     221        $attr = shortcode_parse_atts($attr);
     222
     223        if ( $content ) {
    204224                // enclosing tag - extra parameter
    205                 return $m[1] . call_user_func($shortcode_tags[$tag], $attr, $m[5], $m[2]) . $m[6];
     225                $result = call_user_func($shortcode_tags[$tag], $attr, $content, $tag);
    206226        } else {
    207227                // self-closing tag
    208                 return $m[1] . call_user_func($shortcode_tags[$tag], $attr, NULL, $m[2]) . $m[6];
     228                $result = call_user_func($shortcode_tags[$tag], $attr, NULL, $tag);
    209229        }
     230        return do_shortcode($result);
    210231}
    211232
    212233/**