Ticket #6444: 6444.004.diff

File 6444.004.diff, 5.8 kB (added by AaronCampbell, 3 months ago)
  • formatting.php

    old new  
    2626        for ( $i = 0; $i < $stop; $i++ ) { 
    2727                $curl = $textarr[$i]; 
    2828 
    29                 if (isset($curl{0}) && '<' != $curl{0} && '[' != $curl{0} && $next) { // If it's not a tag 
     29                if (isset($curl{0}) && '<' != $curl{0} && '[' != $curl{0} && $next) { // If it's not a tag or shortcode 
    3030                        // static strings 
    3131                        $curl = str_replace($static_characters, $static_replacements, $curl); 
    3232                        // regular expressions 
     
    7474        $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates 
    7575        $pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end 
    7676        $pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace 
     77        $pee = preg_replace('/<p>(\s*?' . get_shortcode_regex(true) . '\s*)<\/p>/s', '$1', $pee); // don't auto-p wrap post-formatting shortcodes 
    7778        $pee = preg_replace('!<p>([^<]+)\s*?(</(?:div|address|form)[^>]*>)!', "<p>$1</p>$2", $pee); 
    7879        $pee = preg_replace( '|<p>|', "$1<p>", $pee ); 
    7980        $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag 
     
    840841                $text = get_the_content(''); 
    841842                $text = apply_filters('the_content', $text); 
    842843                $text = str_replace(']]>', ']]&gt;', $text); 
     844                $text = preg_replace('|//\s*<!\[CDATA\[|', '<![CDATA[', $text); 
    843845                $text = strip_tags($text); 
    844846                $excerpt_length = 55; 
    845847                $words = explode(' ', $text, $excerpt_length + 1); 
  • shortcodes.php

    old new  
    4747 
    4848$shortcode_tags = array(); 
    4949 
    50 function add_shortcode($tag, $func) { 
     50function add_shortcode($tag, $func, $after_formatting = false) { 
    5151        global $shortcode_tags; 
    5252 
    53         if ( is_callable($func) ) 
    54                 $shortcode_tags[$tag] = $func; 
     53        if ( is_callable($func) ) { 
     54                $shortcode_tags[($after_formatting)? 11:9][$tag] = $func; 
     55        } 
    5556} 
    5657 
    5758function remove_shortcode($tag) { 
    5859        global $shortcode_tags; 
    5960 
    60         unset($shortcode_tags[$tag]); 
     61        unset($shortcode_tags[9][$tag], $shortcode_tags[11][$tag]); 
    6162} 
    6263 
    6364function remove_all_shortcodes() { 
     
    6667        $shortcode_tags = array(); 
    6768} 
    6869 
    69 function do_shortcode($content) { 
     70function do_shortcode_after_formatting($content) { 
     71    return do_shortcode($content, true); 
     72
     73function do_shortcode($content, $after_formatting = false) { 
     74    $pattern = get_shortcode_regex($after_formatting); 
     75    if (!$pattern) { 
     76        return $content; 
     77    } else { 
     78        $callback_func = 'do_shortcode_tag'; 
     79        if ($after_formatting) 
     80           $callback_func .= '_after_formatting'; 
     81 
     82        return preg_replace_callback('/' . $pattern . '/s', $callback_func, $content); 
     83    } 
     84
     85function get_shortcode_regex($after_formatting) { 
    7086        global $shortcode_tags; 
    7187 
    72         if (empty($shortcode_tags) || !is_array($shortcode_tags)) 
    73                 return $content
     88        if (empty($shortcode_tags[($after_formatting)? 11:9]) || !is_array($shortcode_tags[($after_formatting)? 11:9])) 
     89                return false
    7490 
    75         $tagnames = array_keys($shortcode_tags); 
     91        $tagnames = array_keys($shortcode_tags[($after_formatting)? 11:9]); 
    7692        $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); 
    7793 
    78         $pattern = '/\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?/s'; 
     94        return '\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?'; 
     95
    7996 
    80         return preg_replace_callback($pattern, 'do_shortcode_tag', $content); 
     97function do_shortcode_tag_after_formatting($m) { 
     98    return do_shortcode_tag($m, true); 
    8199} 
    82  
    83 function do_shortcode_tag($m) { 
     100function do_shortcode_tag($m, $after_formatting = false) { 
    84101        global $shortcode_tags; 
    85102 
    86103        $tag = $m[1]; 
     
    88105 
    89106        if ( isset($m[4]) ) { 
    90107                // enclosing tag - extra parameter 
    91                 return call_user_func($shortcode_tags[$tag], $attr, $m[4]); 
     108                return call_user_func($shortcode_tags[($after_formatting)? 11:9][$tag], $attr, $m[4]); 
    92109        } else { 
    93110                // self-closing tag 
    94                 return call_user_func($shortcode_tags[$tag], $attr); 
     111                return call_user_func($shortcode_tags[($after_formatting)? 11:9][$tag], $attr); 
    95112        } 
    96113} 
    97114 
     
    129146        return $out; 
    130147} 
    131148 
    132 add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop()  
     149add_filter( 'the_content', 'do_shortcode', 9 ); 
     150add_filter( 'the_content', 'do_shortcode_after_formatting', 11 ); 
    133151 
    134152?> 
  • media.php

    old new  
    285285 
    286286        if ( is_array($size) || empty($size) || empty($imagedata['sizes'][$size]) ) 
    287287                return false; 
    288                  
     288 
    289289        $data = $imagedata['sizes'][$size]; 
    290290        // include the full filesystem path of the intermediate file 
    291291        if ( empty($data['path']) && !empty($data['file']) ) { 
     
    299299// get an image to represent an attachment - a mime icon for files, thumbnail or intermediate size for images 
    300300// returns an array (url, width, height), or false if no image is available 
    301301function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon = false) { 
    302          
     302 
    303303        // get a thumbnail or intermediate image if there is one 
    304304        if ( $image = image_downsize($attachment_id, $size) ) 
    305305                return $image; 
     
    326326                        $size = join('x', $size); 
    327327                $html = '<img src="'.attribute_escape($src).'" '.$hwstring.'class="attachment-'.attribute_escape($size).'" alt="" />'; 
    328328        } 
    329          
     329 
    330330        return $html; 
    331331} 
    332332 
    333 add_shortcode('gallery', 'gallery_shortcode'); 
     333add_shortcode('gallery', 'gallery_shortcode', true); 
    334334 
    335335function gallery_shortcode($attr) { 
    336336        global $post; 
     
    375375        $captiontag = tag_escape($captiontag); 
    376376        $columns = intval($columns); 
    377377        $itemwidth = $columns > 0 ? floor(100/$columns) : 100; 
    378          
     378 
    379379        $output = apply_filters('gallery_style', " 
    380380                <style type='text/css'> 
    381381                        .gallery {