Revert [7700] from trunk in preparation for a different #6444 solution

git-svn-id: https://develop.svn.wordpress.org/trunk@7814 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Mark Jaquith 2008-04-25 00:43:44 +00:00
parent eae779df32
commit 24a68a43b4
3 changed files with 21 additions and 41 deletions

View File

@ -26,7 +26,7 @@ function wptexturize($text) {
for ( $i = 0; $i < $stop; $i++ ) { for ( $i = 0; $i < $stop; $i++ ) {
$curl = $textarr[$i]; $curl = $textarr[$i];
if (isset($curl{0}) && '<' != $curl{0} && '[' != $curl{0} && $next) { // If it's not a tag or shortcode if (isset($curl{0}) && '<' != $curl{0} && '[' != $curl{0} && $next) { // If it's not a tag
// static strings // static strings
$curl = str_replace($static_characters, $static_replacements, $curl); $curl = str_replace($static_characters, $static_replacements, $curl);
// regular expressions // regular expressions
@ -74,7 +74,6 @@ function wpautop($pee, $br = 1) {
$pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
$pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end $pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end
$pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace $pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
$pee = preg_replace('/<p>(\s*?' . get_shortcode_regex(true) . '\s*)<\/p>/s', '$1', $pee); // don't auto-p wrap post-formatting shortcodes
$pee = preg_replace('!<p>([^<]+)\s*?(</(?:div|address|form)[^>]*>)!', "<p>$1</p>$2", $pee); $pee = preg_replace('!<p>([^<]+)\s*?(</(?:div|address|form)[^>]*>)!', "<p>$1</p>$2", $pee);
$pee = preg_replace( '|<p>|', "$1<p>", $pee ); $pee = preg_replace( '|<p>|', "$1<p>", $pee );
$pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag
@ -841,7 +840,6 @@ function wp_trim_excerpt($text) { // Fakes an excerpt if needed
$text = get_the_content(''); $text = get_the_content('');
$text = apply_filters('the_content', $text); $text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]&gt;', $text); $text = str_replace(']]>', ']]&gt;', $text);
$text = preg_replace('|//\s*<!\[CDATA\[|', '<![CDATA[', $text);
$text = strip_tags($text); $text = strip_tags($text);
$excerpt_length = 55; $excerpt_length = 55;
$words = explode(' ', $text, $excerpt_length + 1); $words = explode(' ', $text, $excerpt_length + 1);

View File

@ -332,7 +332,7 @@ function wp_get_attachment_image($attachment_id, $size='thumbnail', $icon = fals
return $html; return $html;
} }
add_shortcode('gallery', 'gallery_shortcode', true); add_shortcode('gallery', 'gallery_shortcode');
function gallery_shortcode($attr) { function gallery_shortcode($attr) {
global $post; global $post;

View File

@ -47,18 +47,17 @@ add_shortcode('baztag', 'baztag_func');
$shortcode_tags = array(); $shortcode_tags = array();
function add_shortcode($tag, $func, $after_formatting = false) { function add_shortcode($tag, $func) {
global $shortcode_tags; global $shortcode_tags;
if ( is_callable($func) ) { if ( is_callable($func) )
$shortcode_tags[($after_formatting)? 11:9][$tag] = $func; $shortcode_tags[$tag] = $func;
}
} }
function remove_shortcode($tag) { function remove_shortcode($tag) {
global $shortcode_tags; global $shortcode_tags;
unset($shortcode_tags[9][$tag], $shortcode_tags[11][$tag]); unset($shortcode_tags[$tag]);
} }
function remove_all_shortcodes() { function remove_all_shortcodes() {
@ -67,37 +66,21 @@ function remove_all_shortcodes() {
$shortcode_tags = array(); $shortcode_tags = array();
} }
function do_shortcode_after_formatting($content) { function do_shortcode($content) {
return do_shortcode($content, true);
}
function do_shortcode($content, $after_formatting = false) {
$pattern = get_shortcode_regex($after_formatting);
if (!$pattern) {
return $content;
} else {
$callback_func = 'do_shortcode_tag';
if ($after_formatting)
$callback_func .= '_after_formatting';
return preg_replace_callback('/' . $pattern . '/s', $callback_func, $content);
}
}
function get_shortcode_regex($after_formatting) {
global $shortcode_tags; global $shortcode_tags;
if (empty($shortcode_tags[($after_formatting)? 11:9]) || !is_array($shortcode_tags[($after_formatting)? 11:9])) if (empty($shortcode_tags) || !is_array($shortcode_tags))
return false; return $content;
$tagnames = array_keys($shortcode_tags[($after_formatting)? 11:9]); $tagnames = array_keys($shortcode_tags);
$tagregexp = join( '|', array_map('preg_quote', $tagnames) ); $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
return '\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?'; $pattern = '/\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?/s';
return preg_replace_callback($pattern, 'do_shortcode_tag', $content);
} }
function do_shortcode_tag_after_formatting($m) { function do_shortcode_tag($m) {
return do_shortcode_tag($m, true);
}
function do_shortcode_tag($m, $after_formatting = false) {
global $shortcode_tags; global $shortcode_tags;
$tag = $m[1]; $tag = $m[1];
@ -105,10 +88,10 @@ function do_shortcode_tag($m, $after_formatting = false) {
if ( isset($m[4]) ) { if ( isset($m[4]) ) {
// enclosing tag - extra parameter // enclosing tag - extra parameter
return call_user_func($shortcode_tags[($after_formatting)? 11:9][$tag], $attr, $m[4]); return call_user_func($shortcode_tags[$tag], $attr, $m[4]);
} else { } else {
// self-closing tag // self-closing tag
return call_user_func($shortcode_tags[($after_formatting)? 11:9][$tag], $attr); return call_user_func($shortcode_tags[$tag], $attr);
} }
} }
@ -147,7 +130,6 @@ function shortcode_atts($pairs, $atts) {
return $out; return $out;
} }
add_filter( 'the_content', 'do_shortcode', 9 ); add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop()
add_filter( 'the_content', 'do_shortcode_after_formatting', 11 );
?> ?>