| 1 | Index: wp-includes/formatting.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-includes/formatting.php (revision 11082) |
|---|
| 4 | +++ wp-includes/formatting.php (working copy) |
|---|
| 5 | @@ -28,13 +28,19 @@ |
|---|
| 6 | */ |
|---|
| 7 | function wptexturize($text) { |
|---|
| 8 | global $wp_cockneyreplace; |
|---|
| 9 | + global $shortcode_tags; |
|---|
| 10 | + |
|---|
| 11 | $next = true; |
|---|
| 12 | $has_pre_parent = false; |
|---|
| 13 | $output = ''; |
|---|
| 14 | $curl = ''; |
|---|
| 15 | - $textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE); |
|---|
| 16 | - $stop = count($textarr); |
|---|
| 17 | |
|---|
| 18 | + $tagnames = array_keys($shortcode_tags); |
|---|
| 19 | + $tagregexp = join('|', array_map('preg_quote', $tagnames)); |
|---|
| 20 | + $regex = '/(<[^>]*>|(?<!\[)\[('.$tagregexp.')\b[^\/\]]*\/?\](?:.+?\[\/\2\])?)/s'; |
|---|
| 21 | + $textarr = preg_split($regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE); |
|---|
| 22 | + $stop = count($textarr); |
|---|
| 23 | + |
|---|
| 24 | // if a plugin has provided an autocorrect array, use it |
|---|
| 25 | if ( isset($wp_cockneyreplace) ) { |
|---|
| 26 | $cockney = array_keys($wp_cockneyreplace); |
|---|
| 27 | @@ -50,10 +56,20 @@ |
|---|
| 28 | $dynamic_characters = array('/\'(\d\d(?:’|\')?s)/', '/(\s|\A|")\'/', '/(\d+)"/', '/(\d+)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A)"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/(\d+)x(\d+)/'); |
|---|
| 29 | $dynamic_replacements = array('’$1','$1‘', '$1″', '$1′', '$1’$2', '$1“$2', '”$1', '’$1', '$1×$2'); |
|---|
| 30 | |
|---|
| 31 | + $skip_count = 0; |
|---|
| 32 | + $shortcode_start_regex = '/^\[(?:'.$tagregexp.')\b/'; |
|---|
| 33 | for ( $i = 0; $i < $stop; $i++ ) { |
|---|
| 34 | $curl = $textarr[$i]; |
|---|
| 35 | |
|---|
| 36 | - if ( !empty($curl) && '<' != $curl{0} && '[' != $curl{0} && $next && !$has_pre_parent) { // If it's not a tag |
|---|
| 37 | + if ($skip_count > 0) { |
|---|
| 38 | + $skip_count--; |
|---|
| 39 | + continue; |
|---|
| 40 | + } elseif (empty($curl)) { |
|---|
| 41 | + $next = true; |
|---|
| 42 | + continue; |
|---|
| 43 | + } elseif (preg_match($shortcode_start_regex, ltrim($curl))) { //shortcode |
|---|
| 44 | + $skip_count = 1; |
|---|
| 45 | + } elseif ('<' != $curl{0} && $next && !$has_pre_parent) { // If it's not a tag |
|---|
| 46 | // static strings |
|---|
| 47 | $curl = str_replace($static_characters, $static_replacements, $curl); |
|---|
| 48 | // regular expressions |
|---|