X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/3e7fab96d7874067884348df10bbdcdefa4a89ad..11be15bd505d66a91e2c80062190b13e315a04a9:/wp-includes/formatting.php?ds=sidebyside
diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php
index 76f41d85..aef2b637 100644
--- a/wp-includes/formatting.php
+++ b/wp-includes/formatting.php
@@ -1,158 +1,590 @@
+ * 'cause today's effort makes it worth tomorrow's "holiday"...
+ *
+ * Becomes:
+ *
+ * ’cause today’s effort makes it worth tomorrow’s “holiday”…
+ *
+ * Code within certain html blocks are skipped.
+ *
+ * @since 0.71
+ * @uses $wp_cockneyreplace Array of formatted entities for certain common phrases
+ *
+ * @param string $text The text to be formatted
+ * @return string The string replaced with html entities
+ */
function wptexturize($text) {
global $wp_cockneyreplace;
- $next = true;
- $output = '';
- $curl = '';
- $textarr = preg_split('/(<.*>)/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
- $stop = count($textarr);
-
- // if a plugin has provided an autocorrect array, use it
- if ( isset($wp_cockneyreplace) ) {
- $cockney = array_keys($wp_cockneyreplace);
- $cockneyreplace = array_values($wp_cockneyreplace);
- } else {
- $cockney = array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round","'cause");
- $cockneyreplace = array("’tain’t","’twere","’twas","’tis","’twill","’til","’bout","’nuff","’round","’cause");
+ static $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements,
+ $default_no_texturize_tags, $default_no_texturize_shortcodes;
+
+ // No need to set up these static variables more than once
+ if ( ! isset( $static_characters ) ) {
+ /* translators: opening curly double quote */
+ $opening_quote = _x( '“', 'opening curly double quote' );
+ /* translators: closing curly double quote */
+ $closing_quote = _x( '”', 'closing curly double quote' );
+
+ /* translators: apostrophe, for example in 'cause or can't */
+ $apos = _x( '’', 'apostrophe' );
+
+ /* translators: prime, for example in 9' (nine feet) */
+ $prime = _x( '′', 'prime' );
+ /* translators: double prime, for example in 9" (nine inches) */
+ $double_prime = _x( '″', 'double prime' );
+
+ /* translators: opening curly single quote */
+ $opening_single_quote = _x( '‘', 'opening curly single quote' );
+ /* translators: closing curly single quote */
+ $closing_single_quote = _x( '’', 'closing curly single quote' );
+
+ /* translators: en dash */
+ $en_dash = _x( '–', 'en dash' );
+ /* translators: em dash */
+ $em_dash = _x( '—', 'em dash' );
+
+ $default_no_texturize_tags = array('pre', 'code', 'kbd', 'style', 'script', 'tt');
+ $default_no_texturize_shortcodes = array('code');
+
+ // if a plugin has provided an autocorrect array, use it
+ if ( isset($wp_cockneyreplace) ) {
+ $cockney = array_keys($wp_cockneyreplace);
+ $cockneyreplace = array_values($wp_cockneyreplace);
+ } elseif ( "'" != $apos ) { // Only bother if we're doing a replacement.
+ $cockney = array( "'tain't", "'twere", "'twas", "'tis", "'twill", "'til", "'bout", "'nuff", "'round", "'cause" );
+ $cockneyreplace = array( $apos . "tain" . $apos . "t", $apos . "twere", $apos . "twas", $apos . "tis", $apos . "twill", $apos . "til", $apos . "bout", $apos . "nuff", $apos . "round", $apos . "cause" );
+ } else {
+ $cockney = $cockneyreplace = array();
+ }
+
+ $static_characters = array_merge( array( '---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'\'', ' (tm)' ), $cockney );
+ $static_replacements = array_merge( array( $em_dash, ' ' . $em_dash . ' ', $en_dash, ' ' . $en_dash . ' ', 'xn--', '…', $opening_quote, $closing_quote, ' ™' ), $cockneyreplace );
+
+ $dynamic = array();
+ if ( "'" != $apos ) {
+ $dynamic[ '/\'(\d\d(?:’|\')?s)/' ] = $apos . '$1'; // '99's
+ $dynamic[ '/\'(\d)/' ] = $apos . '$1'; // '99
+ }
+ if ( "'" != $opening_single_quote )
+ $dynamic[ '/(\s|\A|[([{<]|")\'/' ] = '$1' . $opening_single_quote; // opening single quote, even after (, {, <, [
+ if ( '"' != $double_prime )
+ $dynamic[ '/(\d)"/' ] = '$1' . $double_prime; // 9" (double prime)
+ if ( "'" != $prime )
+ $dynamic[ '/(\d)\'/' ] = '$1' . $prime; // 9' (prime)
+ if ( "'" != $apos )
+ $dynamic[ '/(\S)\'([^\'\s])/' ] = '$1' . $apos . '$2'; // apostrophe in a word
+ if ( '"' != $opening_quote )
+ $dynamic[ '/(\s|\A|[([{<])"(?!\s)/' ] = '$1' . $opening_quote . '$2'; // opening double quote, even after (, {, <, [
+ if ( '"' != $closing_quote )
+ $dynamic[ '/"(\s|\S|\Z)/' ] = $closing_quote . '$1'; // closing double quote
+ if ( "'" != $closing_single_quote )
+ $dynamic[ '/\'([\s.]|\Z)/' ] = $closing_single_quote . '$1'; // closing single quote
+
+ $dynamic[ '/\b(\d+)x(\d+)\b/' ] = '$1×$2'; // 9x9 (times)
+
+ $dynamic_characters = array_keys( $dynamic );
+ $dynamic_replacements = array_values( $dynamic );
}
- $static_characters = array_merge(array('---', ' -- ', '--', 'xn–', '...', '``', '\'s', '\'\'', ' (tm)'), $cockney);
- $static_replacements = array_merge(array('—', ' — ', '–', 'xn--', '…', '“', '’s', '”', ' ™'), $cockneyreplace);
+ // Transform into regexp sub-expression used in _wptexturize_pushpop_element
+ // Must do this every time in case plugins use these filters in a context sensitive manner
+ $no_texturize_tags = '(' . implode('|', apply_filters('no_texturize_tags', $default_no_texturize_tags) ) . ')';
+ $no_texturize_shortcodes = '(' . implode('|', apply_filters('no_texturize_shortcodes', $default_no_texturize_shortcodes) ) . ')';
+
+ $no_texturize_tags_stack = array();
+ $no_texturize_shortcodes_stack = array();
- $dynamic_characters = array('/\'(\d\d(?:’|\')?s)/', '/(\s|\A|")\'/', '/(\d+)"/', '/(\d+)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A)"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/(\d+)x(\d+)/');
- $dynamic_replacements = array('’$1','$1‘', '$1″', '$1′', '$1’$2', '$1“$2', '”$1', '’$1', '$1×$2');
+ $textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
- for ( $i = 0; $i < $stop; $i++ ) {
- $curl = $textarr[$i];
+ foreach ( $textarr as &$curl ) {
+ if ( empty( $curl ) )
+ continue;
- if (isset($curl{0}) && '<' != $curl{0} && $next) { // If it's not a tag
- // static strings
+ // Only call _wptexturize_pushpop_element if first char is correct tag opening
+ $first = $curl[0];
+ if ( '<' === $first ) {
+ _wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>');
+ } elseif ( '[' === $first ) {
+ _wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']');
+ } elseif ( empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack) ) {
+ // This is not a tag, nor is the texturization disabled static strings
$curl = str_replace($static_characters, $static_replacements, $curl);
// regular expressions
$curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl);
- } elseif (strpos($curl, '') {
+ // Check if it is a closing tag -- otherwise assume opening tag
+ if (strncmp($opening . '/', $text, 2)) {
+ // Opening? Check $text+1 against disabled elements
+ if (preg_match('/^' . $disabled_elements . '\b/', substr($text, 1), $matches)) {
+ /*
+ * This disables texturize until we find a closing tag of our type
+ * (e.g. ) even if there was invalid nesting before that
+ *
+ * Example: in the case sadsadasd
"baba"
+ * "baba" won't be texturize
+ */
+
+ array_push($stack, $matches[1]);
+ }
+ } else {
+ // Closing? Check $text+2 against disabled elements
+ $c = preg_quote($closing, '/');
+ if (preg_match('/^' . $disabled_elements . $c . '/', substr($text, 2), $matches)) {
+ $last = array_pop($stack);
+
+ // Make sure it matches the opening tag
+ if ($last != $matches[1])
+ array_push($stack, $last);
+ }
+ }
}
-// Accepts matches array from preg_replace_callback in wpautop()
-// or a string
-function clean_pre($matches) {
- if ( is_array($matches) )
- $text = $matches[1] . $matches[2] . "";
- else
- $text = $matches;
+/**
+ * Replaces double line-breaks with paragraph elements.
+ *
+ * A group of regex replaces used to identify text formatted with newlines and
+ * replace double line-breaks with HTML paragraph tags. The remaining
+ * line-breaks after conversion become <
> tags, unless $br is set to '0'
+ * or 'false'.
+ *
+ * @since 0.71
+ *
+ * @param string $pee The text which has to be formatted.
+ * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
+ * @return string Text which has been converted into correct paragraph tags.
+ */
+function wpautop($pee, $br = true) {
+ $pre_tags = array();
+
+ if ( trim($pee) === '' )
+ return '';
- $text = str_replace('
', '', $text);
- $text = str_replace('
', "\n", $text);
- $text = str_replace('
', '', $text);
+ $pee = $pee . "\n"; // just to make things a little easier, pad the end
- return $text;
-}
+ if ( strpos($pee, '', $pee );
+ $last_pee = array_pop($pee_parts);
+ $pee = '';
+ $i = 0;
+
+ foreach ( $pee_parts as $pee_part ) {
+ $start = strpos($pee_part, '";
+ $pre_tags[$name] = substr( $pee_part, $start ) . '
';
+
+ $pee .= substr( $pee_part, 0, $start ) . $name;
+ $i++;
+ }
+
+ $pee .= $last_pee;
+ }
-function wpautop($pee, $br = 1) {
- $pee = $pee . "\n"; // just to make things a little easier, pad the end
$pee = preg_replace('|
\s*
|', "\n\n", $pee);
// Space things out a little
- $allblocks = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr)';
+ $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
$pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
$pee = preg_replace('!(' . $allblocks . '>)!', "$1\n\n", $pee);
$pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
+ if ( strpos($pee, '