| 36 | | /* translators: opening curly quote */ |
| 37 | | $opening_quote = _x('“', 'opening curly quote'); |
| 38 | | /* translators: closing curly quote */ |
| 39 | | $closing_quote = _x('”', 'closing curly quote'); |
| | 44 | $no_texturize_tags = apply_filters('no_texturize_tags', array('pre', 'code', 'kbd', 'style', 'script', 'tt')); |
| | 45 | $no_texturize_shortcodes = apply_filters('no_texturize_shortcodes', array('code')); |
| 41 | | $no_texturize_tags = apply_filters('no_texturize_tags', array('pre', 'code', 'kbd', 'style', 'script', 'tt')); |
| 42 | | $no_texturize_shortcodes = apply_filters('no_texturize_shortcodes', array('code')); |
| 43 | | $no_texturize_tags_stack = array(); |
| 44 | | $no_texturize_shortcodes_stack = array(); |
| | 47 | // Transform into regexp sub-expression used in _wptexturize_pushpop_element |
| | 48 | $no_texturize_tags = '(' . implode('|', $no_texturize_tags) . ')'; |
| | 49 | $no_texturize_shortcodes = '(' . implode('|', $no_texturize_shortcodes) . ')'; |
| 46 | | // if a plugin has provided an autocorrect array, use it |
| 47 | | if ( isset($wp_cockneyreplace) ) { |
| 48 | | $cockney = array_keys($wp_cockneyreplace); |
| 49 | | $cockneyreplace = array_values($wp_cockneyreplace); |
| 50 | | } else { |
| 51 | | $cockney = array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round","'cause"); |
| 52 | | $cockneyreplace = array("’tain’t","’twere","’twas","’tis","’twill","’til","’bout","’nuff","’round","’cause"); |
| | 51 | // if a plugin has provided an autocorrect array, use it |
| | 52 | if ( isset($wp_cockneyreplace) ) { |
| | 53 | $cockney = array_keys($wp_cockneyreplace); |
| | 54 | $cockneyreplace = array_values($wp_cockneyreplace); |
| | 55 | } else { |
| | 56 | $cockney = array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round","'cause"); |
| | 57 | $cockneyreplace = array("’tain’t","’twere","’twas","’tis","’twill","’til","’bout","’nuff","’round","’cause"); |
| | 58 | } |
| | 59 | |
| | 60 | $static_characters = array_merge(array('---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'s', '\'\'', ' (tm)'), $cockney); |
| | 61 | $static_replacements = array_merge(array('—', ' — ', '–', ' – ', 'xn--', '…', $opening_quote, '’s', $closing_quote, ' ™'), $cockneyreplace); |
| | 62 | |
| | 63 | $dynamic_characters = array('/\'(\d\d(?:’|\')?s)/', '/(\s|\A|[([{<]|")\'/', '/(\d+)"/', '/(\d+)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A|[([{<])"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/(\d+)x(\d+)/'); |
| | 64 | $dynamic_replacements = array('’$1','$1‘', '$1″', '$1′', '$1’$2', '$1' . $opening_quote . '$2', $closing_quote . '$1', '’$1', '$1×$2'); |
| | 65 | |
| | 66 | $static_setup = true; |
| 55 | | $static_characters = array_merge(array('---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'s', '\'\'', ' (tm)'), $cockney); |
| 56 | | $static_replacements = array_merge(array('—', ' — ', '–', ' – ', 'xn--', '…', $opening_quote, '’s', $closing_quote, ' ™'), $cockneyreplace); |
| | 69 | $no_texturize_tags_stack = array(); |
| | 70 | $no_texturize_shortcodes_stack = array(); |
| 70 | | } else { |
| 71 | | wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>'); |
| 72 | | wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']'); |
| | 82 | } elseif (!empty($curl)) { |
| | 83 | /* |
| | 84 | * Only call _wptexturize_pushpop_element if first char is correct |
| | 85 | * tag opening |
| | 86 | */ |
| | 87 | if ('<' == $curl{0}) |
| | 88 | _wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>'); |
| | 89 | elseif ('[' == $curl{0}) |
| | 90 | _wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']'); |
| 82 | | function wptexturize_pushpop_element($text, &$stack, $disabled_elements, $opening = '<', $closing = '>') { |
| 83 | | $o = preg_quote($opening, '/'); |
| 84 | | $c = preg_quote($closing, '/'); |
| 85 | | foreach($disabled_elements as $element) { |
| 86 | | if (preg_match('/^'.$o.$element.'\b/', $text)) array_push($stack, $element); |
| 87 | | if (preg_match('/^'.$o.'\/'.$element.$c.'/', $text)) { |
| | 100 | /** |
| | 101 | * Search for disabled element tags. Push element to stack on tag open and pop |
| | 102 | * on tag close. Assumes first character of $text is tag opening. |
| | 103 | * |
| | 104 | * @access private |
| | 105 | * @since 2.9.0 |
| | 106 | * |
| | 107 | * @param string $text Text to check. First character is assumed to be $opening |
| | 108 | * @param array $stack Array used as stack of opened tag elements |
| | 109 | * @param string $disabled_elements Tags to match against formatted as regexp sub-expression |
| | 110 | * @param string $opening Tag opening character, assumed to be 1 character long |
| | 111 | * @param string $opening Tag closing character |
| | 112 | * @return object |
| | 113 | */ |
| | 114 | function _wptexturize_pushpop_element($text, &$stack, $disabled_elements, $opening = '<', $closing = '>') { |
| | 115 | // Check if it is a closing tag -- otherwise assume opening tag |
| | 116 | if (strncmp($opening . '/', $text, 2)) { |
| | 117 | // Opening? Check $text+1 against disabled elements |
| | 118 | if (preg_match('/^' . $disabled_elements . '\b/', substr($text, 1), $matches)) { |
| | 119 | /* |
| | 120 | * This disables texturize until we find a closing tag of our type |
| | 121 | * (e.g. <pre>) even if there was invalid nesting before that |
| | 122 | * |
| | 123 | * Example: in the case <pre>sadsadasd</code>"baba"</pre> |
| | 124 | * "baba" won't be texturize |
| | 125 | */ |
| | 126 | |
| | 127 | array_push($stack, $matches[1]); |
| | 128 | } |
| | 129 | } else { |
| | 130 | // Closing? Check $text+2 against disabled elements |
| | 131 | $c = preg_quote($closing, '/'); |
| | 132 | if (preg_match('/^' . $disabled_elements . $c . '/', substr($text, 2), $matches)) { |