Edit File by line
/home/barbar84/public_h.../wp-inclu...
File: formatting.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Main WordPress Formatting API.
[2] Fix | Delete
*
[3] Fix | Delete
* Handles many functions for formatting output.
[4] Fix | Delete
*
[5] Fix | Delete
* @package WordPress
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Replaces common plain text characters with formatted entities.
[10] Fix | Delete
*
[11] Fix | Delete
* Returns given text with transformations of quotes into smart quotes, apostrophes,
[12] Fix | Delete
* dashes, ellipses, the trademark symbol, and the multiplication symbol.
[13] Fix | Delete
*
[14] Fix | Delete
* As an example,
[15] Fix | Delete
*
[16] Fix | Delete
* 'cause today's effort makes it worth tomorrow's "holiday" ...
[17] Fix | Delete
*
[18] Fix | Delete
* Becomes:
[19] Fix | Delete
*
[20] Fix | Delete
* &#8217;cause today&#8217;s effort makes it worth tomorrow&#8217;s &#8220;holiday&#8221; &#8230;
[21] Fix | Delete
*
[22] Fix | Delete
* Code within certain HTML blocks are skipped.
[23] Fix | Delete
*
[24] Fix | Delete
* Do not use this function before the {@see 'init'} action hook; everything will break.
[25] Fix | Delete
*
[26] Fix | Delete
* @since 0.71
[27] Fix | Delete
*
[28] Fix | Delete
* @global array $wp_cockneyreplace Array of formatted entities for certain common phrases.
[29] Fix | Delete
* @global array $shortcode_tags
[30] Fix | Delete
*
[31] Fix | Delete
* @param string $text The text to be formatted.
[32] Fix | Delete
* @param bool $reset Set to true for unit testing. Translated patterns will reset.
[33] Fix | Delete
* @return string The string replaced with HTML entities.
[34] Fix | Delete
*/
[35] Fix | Delete
function wptexturize( $text, $reset = false ) {
[36] Fix | Delete
global $wp_cockneyreplace, $shortcode_tags;
[37] Fix | Delete
static $static_characters = null,
[38] Fix | Delete
$static_replacements = null,
[39] Fix | Delete
$dynamic_characters = null,
[40] Fix | Delete
$dynamic_replacements = null,
[41] Fix | Delete
$default_no_texturize_tags = null,
[42] Fix | Delete
$default_no_texturize_shortcodes = null,
[43] Fix | Delete
$run_texturize = true,
[44] Fix | Delete
$apos = null,
[45] Fix | Delete
$prime = null,
[46] Fix | Delete
$double_prime = null,
[47] Fix | Delete
$opening_quote = null,
[48] Fix | Delete
$closing_quote = null,
[49] Fix | Delete
$opening_single_quote = null,
[50] Fix | Delete
$closing_single_quote = null,
[51] Fix | Delete
$open_q_flag = '<!--oq-->',
[52] Fix | Delete
$open_sq_flag = '<!--osq-->',
[53] Fix | Delete
$apos_flag = '<!--apos-->';
[54] Fix | Delete
[55] Fix | Delete
// If there's nothing to do, just stop.
[56] Fix | Delete
if ( empty( $text ) || false === $run_texturize ) {
[57] Fix | Delete
return $text;
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
// Set up static variables. Run once only.
[61] Fix | Delete
if ( $reset || ! isset( $static_characters ) ) {
[62] Fix | Delete
/**
[63] Fix | Delete
* Filters whether to skip running wptexturize().
[64] Fix | Delete
*
[65] Fix | Delete
* Returning false from the filter will effectively short-circuit wptexturize()
[66] Fix | Delete
* and return the original text passed to the function instead.
[67] Fix | Delete
*
[68] Fix | Delete
* The filter runs only once, the first time wptexturize() is called.
[69] Fix | Delete
*
[70] Fix | Delete
* @since 4.0.0
[71] Fix | Delete
*
[72] Fix | Delete
* @see wptexturize()
[73] Fix | Delete
*
[74] Fix | Delete
* @param bool $run_texturize Whether to short-circuit wptexturize().
[75] Fix | Delete
*/
[76] Fix | Delete
$run_texturize = apply_filters( 'run_wptexturize', $run_texturize );
[77] Fix | Delete
if ( false === $run_texturize ) {
[78] Fix | Delete
return $text;
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
/* translators: Opening curly double quote. */
[82] Fix | Delete
$opening_quote = _x( '&#8220;', 'opening curly double quote' );
[83] Fix | Delete
/* translators: Closing curly double quote. */
[84] Fix | Delete
$closing_quote = _x( '&#8221;', 'closing curly double quote' );
[85] Fix | Delete
[86] Fix | Delete
/* translators: Apostrophe, for example in 'cause or can't. */
[87] Fix | Delete
$apos = _x( '&#8217;', 'apostrophe' );
[88] Fix | Delete
[89] Fix | Delete
/* translators: Prime, for example in 9' (nine feet). */
[90] Fix | Delete
$prime = _x( '&#8242;', 'prime' );
[91] Fix | Delete
/* translators: Double prime, for example in 9" (nine inches). */
[92] Fix | Delete
$double_prime = _x( '&#8243;', 'double prime' );
[93] Fix | Delete
[94] Fix | Delete
/* translators: Opening curly single quote. */
[95] Fix | Delete
$opening_single_quote = _x( '&#8216;', 'opening curly single quote' );
[96] Fix | Delete
/* translators: Closing curly single quote. */
[97] Fix | Delete
$closing_single_quote = _x( '&#8217;', 'closing curly single quote' );
[98] Fix | Delete
[99] Fix | Delete
/* translators: En dash. */
[100] Fix | Delete
$en_dash = _x( '&#8211;', 'en dash' );
[101] Fix | Delete
/* translators: Em dash. */
[102] Fix | Delete
$em_dash = _x( '&#8212;', 'em dash' );
[103] Fix | Delete
[104] Fix | Delete
$default_no_texturize_tags = array( 'pre', 'code', 'kbd', 'style', 'script', 'tt' );
[105] Fix | Delete
$default_no_texturize_shortcodes = array( 'code' );
[106] Fix | Delete
[107] Fix | Delete
// If a plugin has provided an autocorrect array, use it.
[108] Fix | Delete
if ( isset( $wp_cockneyreplace ) ) {
[109] Fix | Delete
$cockney = array_keys( $wp_cockneyreplace );
[110] Fix | Delete
$cockneyreplace = array_values( $wp_cockneyreplace );
[111] Fix | Delete
} else {
[112] Fix | Delete
/*
[113] Fix | Delete
* translators: This is a comma-separated list of words that defy the syntax of quotations in normal use,
[114] Fix | Delete
* for example... 'We do not have enough words yet'... is a typical quoted phrase. But when we write
[115] Fix | Delete
* lines of code 'til we have enough of 'em, then we need to insert apostrophes instead of quotes.
[116] Fix | Delete
*/
[117] Fix | Delete
$cockney = explode(
[118] Fix | Delete
',',
[119] Fix | Delete
_x(
[120] Fix | Delete
"'tain't,'twere,'twas,'tis,'twill,'til,'bout,'nuff,'round,'cause,'em",
[121] Fix | Delete
'Comma-separated list of words to texturize in your language'
[122] Fix | Delete
)
[123] Fix | Delete
);
[124] Fix | Delete
[125] Fix | Delete
$cockneyreplace = explode(
[126] Fix | Delete
',',
[127] Fix | Delete
_x(
[128] Fix | Delete
'&#8217;tain&#8217;t,&#8217;twere,&#8217;twas,&#8217;tis,&#8217;twill,&#8217;til,&#8217;bout,&#8217;nuff,&#8217;round,&#8217;cause,&#8217;em',
[129] Fix | Delete
'Comma-separated list of replacement words in your language'
[130] Fix | Delete
)
[131] Fix | Delete
);
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
$static_characters = array_merge( array( '...', '``', '\'\'', ' (tm)' ), $cockney );
[135] Fix | Delete
$static_replacements = array_merge( array( '&#8230;', $opening_quote, $closing_quote, ' &#8482;' ), $cockneyreplace );
[136] Fix | Delete
[137] Fix | Delete
// Pattern-based replacements of characters.
[138] Fix | Delete
// Sort the remaining patterns into several arrays for performance tuning.
[139] Fix | Delete
$dynamic_characters = array(
[140] Fix | Delete
'apos' => array(),
[141] Fix | Delete
'quote' => array(),
[142] Fix | Delete
'dash' => array(),
[143] Fix | Delete
);
[144] Fix | Delete
$dynamic_replacements = array(
[145] Fix | Delete
'apos' => array(),
[146] Fix | Delete
'quote' => array(),
[147] Fix | Delete
'dash' => array(),
[148] Fix | Delete
);
[149] Fix | Delete
$dynamic = array();
[150] Fix | Delete
$spaces = wp_spaces_regexp();
[151] Fix | Delete
[152] Fix | Delete
// '99' and '99" are ambiguous among other patterns; assume it's an abbreviated year at the end of a quotation.
[153] Fix | Delete
if ( "'" !== $apos || "'" !== $closing_single_quote ) {
[154] Fix | Delete
$dynamic[ '/\'(\d\d)\'(?=\Z|[.,:;!?)}\-\]]|&gt;|' . $spaces . ')/' ] = $apos_flag . '$1' . $closing_single_quote;
[155] Fix | Delete
}
[156] Fix | Delete
if ( "'" !== $apos || '"' !== $closing_quote ) {
[157] Fix | Delete
$dynamic[ '/\'(\d\d)"(?=\Z|[.,:;!?)}\-\]]|&gt;|' . $spaces . ')/' ] = $apos_flag . '$1' . $closing_quote;
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
// '99 '99s '99's (apostrophe) But never '9 or '99% or '999 or '99.0.
[161] Fix | Delete
if ( "'" !== $apos ) {
[162] Fix | Delete
$dynamic['/\'(?=\d\d(?:\Z|(?![%\d]|[.,]\d)))/'] = $apos_flag;
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
// Quoted numbers like '0.42'.
[166] Fix | Delete
if ( "'" !== $opening_single_quote && "'" !== $closing_single_quote ) {
[167] Fix | Delete
$dynamic[ '/(?<=\A|' . $spaces . ')\'(\d[.,\d]*)\'/' ] = $open_sq_flag . '$1' . $closing_single_quote;
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
// Single quote at start, or preceded by (, {, <, [, ", -, or spaces.
[171] Fix | Delete
if ( "'" !== $opening_single_quote ) {
[172] Fix | Delete
$dynamic[ '/(?<=\A|[([{"\-]|&lt;|' . $spaces . ')\'/' ] = $open_sq_flag;
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
// Apostrophe in a word. No spaces, double apostrophes, or other punctuation.
[176] Fix | Delete
if ( "'" !== $apos ) {
[177] Fix | Delete
$dynamic[ '/(?<!' . $spaces . ')\'(?!\Z|[.,:;!?"\'(){}[\]\-]|&[lg]t;|' . $spaces . ')/' ] = $apos_flag;
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
$dynamic_characters['apos'] = array_keys( $dynamic );
[181] Fix | Delete
$dynamic_replacements['apos'] = array_values( $dynamic );
[182] Fix | Delete
$dynamic = array();
[183] Fix | Delete
[184] Fix | Delete
// Quoted numbers like "42".
[185] Fix | Delete
if ( '"' !== $opening_quote && '"' !== $closing_quote ) {
[186] Fix | Delete
$dynamic[ '/(?<=\A|' . $spaces . ')"(\d[.,\d]*)"/' ] = $open_q_flag . '$1' . $closing_quote;
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
// Double quote at start, or preceded by (, {, <, [, -, or spaces, and not followed by spaces.
[190] Fix | Delete
if ( '"' !== $opening_quote ) {
[191] Fix | Delete
$dynamic[ '/(?<=\A|[([{\-]|&lt;|' . $spaces . ')"(?!' . $spaces . ')/' ] = $open_q_flag;
[192] Fix | Delete
}
[193] Fix | Delete
[194] Fix | Delete
$dynamic_characters['quote'] = array_keys( $dynamic );
[195] Fix | Delete
$dynamic_replacements['quote'] = array_values( $dynamic );
[196] Fix | Delete
$dynamic = array();
[197] Fix | Delete
[198] Fix | Delete
// Dashes and spaces.
[199] Fix | Delete
$dynamic['/---/'] = $em_dash;
[200] Fix | Delete
$dynamic[ '/(?<=^|' . $spaces . ')--(?=$|' . $spaces . ')/' ] = $em_dash;
[201] Fix | Delete
$dynamic['/(?<!xn)--/'] = $en_dash;
[202] Fix | Delete
$dynamic[ '/(?<=^|' . $spaces . ')-(?=$|' . $spaces . ')/' ] = $en_dash;
[203] Fix | Delete
[204] Fix | Delete
$dynamic_characters['dash'] = array_keys( $dynamic );
[205] Fix | Delete
$dynamic_replacements['dash'] = array_values( $dynamic );
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
// Must do this every time in case plugins use these filters in a context sensitive manner.
[209] Fix | Delete
/**
[210] Fix | Delete
* Filters the list of HTML elements not to texturize.
[211] Fix | Delete
*
[212] Fix | Delete
* @since 2.8.0
[213] Fix | Delete
*
[214] Fix | Delete
* @param string[] $default_no_texturize_tags An array of HTML element names.
[215] Fix | Delete
*/
[216] Fix | Delete
$no_texturize_tags = apply_filters( 'no_texturize_tags', $default_no_texturize_tags );
[217] Fix | Delete
/**
[218] Fix | Delete
* Filters the list of shortcodes not to texturize.
[219] Fix | Delete
*
[220] Fix | Delete
* @since 2.8.0
[221] Fix | Delete
*
[222] Fix | Delete
* @param string[] $default_no_texturize_shortcodes An array of shortcode names.
[223] Fix | Delete
*/
[224] Fix | Delete
$no_texturize_shortcodes = apply_filters( 'no_texturize_shortcodes', $default_no_texturize_shortcodes );
[225] Fix | Delete
[226] Fix | Delete
$no_texturize_tags_stack = array();
[227] Fix | Delete
$no_texturize_shortcodes_stack = array();
[228] Fix | Delete
[229] Fix | Delete
// Look for shortcodes and HTML elements.
[230] Fix | Delete
[231] Fix | Delete
preg_match_all( '@\[/?([^<>&/\[\]\x00-\x20=]++)@', $text, $matches );
[232] Fix | Delete
$tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] );
[233] Fix | Delete
$found_shortcodes = ! empty( $tagnames );
[234] Fix | Delete
$shortcode_regex = $found_shortcodes ? _get_wptexturize_shortcode_regex( $tagnames ) : '';
[235] Fix | Delete
$regex = _get_wptexturize_split_regex( $shortcode_regex );
[236] Fix | Delete
[237] Fix | Delete
$textarr = preg_split( $regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
[238] Fix | Delete
[239] Fix | Delete
foreach ( $textarr as &$curl ) {
[240] Fix | Delete
// Only call _wptexturize_pushpop_element if $curl is a delimiter.
[241] Fix | Delete
$first = $curl[0];
[242] Fix | Delete
if ( '<' === $first ) {
[243] Fix | Delete
if ( '<!--' === substr( $curl, 0, 4 ) ) {
[244] Fix | Delete
// This is an HTML comment delimiter.
[245] Fix | Delete
continue;
[246] Fix | Delete
} else {
[247] Fix | Delete
// This is an HTML element delimiter.
[248] Fix | Delete
[249] Fix | Delete
// Replace each & with &#038; unless it already looks like an entity.
[250] Fix | Delete
$curl = preg_replace( '/&(?!#(?:\d+|x[a-f0-9]+);|[a-z1-4]{1,8};)/i', '&#038;', $curl );
[251] Fix | Delete
[252] Fix | Delete
_wptexturize_pushpop_element( $curl, $no_texturize_tags_stack, $no_texturize_tags );
[253] Fix | Delete
}
[254] Fix | Delete
} elseif ( '' === trim( $curl ) ) {
[255] Fix | Delete
// This is a newline between delimiters. Performance improves when we check this.
[256] Fix | Delete
continue;
[257] Fix | Delete
[258] Fix | Delete
} elseif ( '[' === $first && $found_shortcodes && 1 === preg_match( '/^' . $shortcode_regex . '$/', $curl ) ) {
[259] Fix | Delete
// This is a shortcode delimiter.
[260] Fix | Delete
[261] Fix | Delete
if ( '[[' !== substr( $curl, 0, 2 ) && ']]' !== substr( $curl, -2 ) ) {
[262] Fix | Delete
// Looks like a normal shortcode.
[263] Fix | Delete
_wptexturize_pushpop_element( $curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes );
[264] Fix | Delete
} else {
[265] Fix | Delete
// Looks like an escaped shortcode.
[266] Fix | Delete
continue;
[267] Fix | Delete
}
[268] Fix | Delete
} elseif ( empty( $no_texturize_shortcodes_stack ) && empty( $no_texturize_tags_stack ) ) {
[269] Fix | Delete
// This is neither a delimiter, nor is this content inside of no_texturize pairs. Do texturize.
[270] Fix | Delete
[271] Fix | Delete
$curl = str_replace( $static_characters, $static_replacements, $curl );
[272] Fix | Delete
[273] Fix | Delete
if ( false !== strpos( $curl, "'" ) ) {
[274] Fix | Delete
$curl = preg_replace( $dynamic_characters['apos'], $dynamic_replacements['apos'], $curl );
[275] Fix | Delete
$curl = wptexturize_primes( $curl, "'", $prime, $open_sq_flag, $closing_single_quote );
[276] Fix | Delete
$curl = str_replace( $apos_flag, $apos, $curl );
[277] Fix | Delete
$curl = str_replace( $open_sq_flag, $opening_single_quote, $curl );
[278] Fix | Delete
}
[279] Fix | Delete
if ( false !== strpos( $curl, '"' ) ) {
[280] Fix | Delete
$curl = preg_replace( $dynamic_characters['quote'], $dynamic_replacements['quote'], $curl );
[281] Fix | Delete
$curl = wptexturize_primes( $curl, '"', $double_prime, $open_q_flag, $closing_quote );
[282] Fix | Delete
$curl = str_replace( $open_q_flag, $opening_quote, $curl );
[283] Fix | Delete
}
[284] Fix | Delete
if ( false !== strpos( $curl, '-' ) ) {
[285] Fix | Delete
$curl = preg_replace( $dynamic_characters['dash'], $dynamic_replacements['dash'], $curl );
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
// 9x9 (times), but never 0x9999.
[289] Fix | Delete
if ( 1 === preg_match( '/(?<=\d)x\d/', $curl ) ) {
[290] Fix | Delete
// Searching for a digit is 10 times more expensive than for the x, so we avoid doing this one!
[291] Fix | Delete
$curl = preg_replace( '/\b(\d(?(?<=0)[\d\.,]+|[\d\.,]*))x(\d[\d\.,]*)\b/', '$1&#215;$2', $curl );
[292] Fix | Delete
}
[293] Fix | Delete
[294] Fix | Delete
// Replace each & with &#038; unless it already looks like an entity.
[295] Fix | Delete
$curl = preg_replace( '/&(?!#(?:\d+|x[a-f0-9]+);|[a-z1-4]{1,8};)/i', '&#038;', $curl );
[296] Fix | Delete
}
[297] Fix | Delete
}
[298] Fix | Delete
[299] Fix | Delete
return implode( '', $textarr );
[300] Fix | Delete
}
[301] Fix | Delete
[302] Fix | Delete
/**
[303] Fix | Delete
* Implements a logic tree to determine whether or not "7'." represents seven feet,
[304] Fix | Delete
* then converts the special char into either a prime char or a closing quote char.
[305] Fix | Delete
*
[306] Fix | Delete
* @since 4.3.0
[307] Fix | Delete
*
[308] Fix | Delete
* @param string $haystack The plain text to be searched.
[309] Fix | Delete
* @param string $needle The character to search for such as ' or ".
[310] Fix | Delete
* @param string $prime The prime char to use for replacement.
[311] Fix | Delete
* @param string $open_quote The opening quote char. Opening quote replacement must be
[312] Fix | Delete
* accomplished already.
[313] Fix | Delete
* @param string $close_quote The closing quote char to use for replacement.
[314] Fix | Delete
* @return string The $haystack value after primes and quotes replacements.
[315] Fix | Delete
*/
[316] Fix | Delete
function wptexturize_primes( $haystack, $needle, $prime, $open_quote, $close_quote ) {
[317] Fix | Delete
$spaces = wp_spaces_regexp();
[318] Fix | Delete
$flag = '<!--wp-prime-or-quote-->';
[319] Fix | Delete
$quote_pattern = "/$needle(?=\\Z|[.,:;!?)}\\-\\]]|&gt;|" . $spaces . ')/';
[320] Fix | Delete
$prime_pattern = "/(?<=\\d)$needle/";
[321] Fix | Delete
$flag_after_digit = "/(?<=\\d)$flag/";
[322] Fix | Delete
$flag_no_digit = "/(?<!\\d)$flag/";
[323] Fix | Delete
[324] Fix | Delete
$sentences = explode( $open_quote, $haystack );
[325] Fix | Delete
[326] Fix | Delete
foreach ( $sentences as $key => &$sentence ) {
[327] Fix | Delete
if ( false === strpos( $sentence, $needle ) ) {
[328] Fix | Delete
continue;
[329] Fix | Delete
} elseif ( 0 !== $key && 0 === substr_count( $sentence, $close_quote ) ) {
[330] Fix | Delete
$sentence = preg_replace( $quote_pattern, $flag, $sentence, -1, $count );
[331] Fix | Delete
if ( $count > 1 ) {
[332] Fix | Delete
// This sentence appears to have multiple closing quotes. Attempt Vulcan logic.
[333] Fix | Delete
$sentence = preg_replace( $flag_no_digit, $close_quote, $sentence, -1, $count2 );
[334] Fix | Delete
if ( 0 === $count2 ) {
[335] Fix | Delete
// Try looking for a quote followed by a period.
[336] Fix | Delete
$count2 = substr_count( $sentence, "$flag." );
[337] Fix | Delete
if ( $count2 > 0 ) {
[338] Fix | Delete
// Assume the rightmost quote-period match is the end of quotation.
[339] Fix | Delete
$pos = strrpos( $sentence, "$flag." );
[340] Fix | Delete
} else {
[341] Fix | Delete
// When all else fails, make the rightmost candidate a closing quote.
[342] Fix | Delete
// This is most likely to be problematic in the context of bug #18549.
[343] Fix | Delete
$pos = strrpos( $sentence, $flag );
[344] Fix | Delete
}
[345] Fix | Delete
$sentence = substr_replace( $sentence, $close_quote, $pos, strlen( $flag ) );
[346] Fix | Delete
}
[347] Fix | Delete
// Use conventional replacement on any remaining primes and quotes.
[348] Fix | Delete
$sentence = preg_replace( $prime_pattern, $prime, $sentence );
[349] Fix | Delete
$sentence = preg_replace( $flag_after_digit, $prime, $sentence );
[350] Fix | Delete
$sentence = str_replace( $flag, $close_quote, $sentence );
[351] Fix | Delete
} elseif ( 1 == $count ) {
[352] Fix | Delete
// Found only one closing quote candidate, so give it priority over primes.
[353] Fix | Delete
$sentence = str_replace( $flag, $close_quote, $sentence );
[354] Fix | Delete
$sentence = preg_replace( $prime_pattern, $prime, $sentence );
[355] Fix | Delete
} else {
[356] Fix | Delete
// No closing quotes found. Just run primes pattern.
[357] Fix | Delete
$sentence = preg_replace( $prime_pattern, $prime, $sentence );
[358] Fix | Delete
}
[359] Fix | Delete
} else {
[360] Fix | Delete
$sentence = preg_replace( $prime_pattern, $prime, $sentence );
[361] Fix | Delete
$sentence = preg_replace( $quote_pattern, $close_quote, $sentence );
[362] Fix | Delete
}
[363] Fix | Delete
if ( '"' === $needle && false !== strpos( $sentence, '"' ) ) {
[364] Fix | Delete
$sentence = str_replace( '"', $close_quote, $sentence );
[365] Fix | Delete
}
[366] Fix | Delete
}
[367] Fix | Delete
[368] Fix | Delete
return implode( $open_quote, $sentences );
[369] Fix | Delete
}
[370] Fix | Delete
[371] Fix | Delete
/**
[372] Fix | Delete
* Search for disabled element tags. Push element to stack on tag open and pop
[373] Fix | Delete
* on tag close.
[374] Fix | Delete
*
[375] Fix | Delete
* Assumes first char of $text is tag opening and last char is tag closing.
[376] Fix | Delete
* Assumes second char of $text is optionally '/' to indicate closing as in </html>.
[377] Fix | Delete
*
[378] Fix | Delete
* @since 2.9.0
[379] Fix | Delete
* @access private
[380] Fix | Delete
*
[381] Fix | Delete
* @param string $text Text to check. Must be a tag like `<html>` or `[shortcode]`.
[382] Fix | Delete
* @param string[] $stack Array of open tag elements.
[383] Fix | Delete
* @param string[] $disabled_elements Array of tag names to match against. Spaces are not allowed in tag names.
[384] Fix | Delete
*/
[385] Fix | Delete
function _wptexturize_pushpop_element( $text, &$stack, $disabled_elements ) {
[386] Fix | Delete
// Is it an opening tag or closing tag?
[387] Fix | Delete
if ( isset( $text[1] ) && '/' !== $text[1] ) {
[388] Fix | Delete
$opening_tag = true;
[389] Fix | Delete
$name_offset = 1;
[390] Fix | Delete
} elseif ( 0 === count( $stack ) ) {
[391] Fix | Delete
// Stack is empty. Just stop.
[392] Fix | Delete
return;
[393] Fix | Delete
} else {
[394] Fix | Delete
$opening_tag = false;
[395] Fix | Delete
$name_offset = 2;
[396] Fix | Delete
}
[397] Fix | Delete
[398] Fix | Delete
// Parse out the tag name.
[399] Fix | Delete
$space = strpos( $text, ' ' );
[400] Fix | Delete
if ( false === $space ) {
[401] Fix | Delete
$space = -1;
[402] Fix | Delete
} else {
[403] Fix | Delete
$space -= $name_offset;
[404] Fix | Delete
}
[405] Fix | Delete
$tag = substr( $text, $name_offset, $space );
[406] Fix | Delete
[407] Fix | Delete
// Handle disabled tags.
[408] Fix | Delete
if ( in_array( $tag, $disabled_elements, true ) ) {
[409] Fix | Delete
if ( $opening_tag ) {
[410] Fix | Delete
/*
[411] Fix | Delete
* This disables texturize until we find a closing tag of our type
[412] Fix | Delete
* (e.g. <pre>) even if there was invalid nesting before that.
[413] Fix | Delete
*
[414] Fix | Delete
* Example: in the case <pre>sadsadasd</code>"baba"</pre>
[415] Fix | Delete
* "baba" won't be texturized.
[416] Fix | Delete
*/
[417] Fix | Delete
[418] Fix | Delete
array_push( $stack, $tag );
[419] Fix | Delete
} elseif ( end( $stack ) == $tag ) {
[420] Fix | Delete
array_pop( $stack );
[421] Fix | Delete
}
[422] Fix | Delete
}
[423] Fix | Delete
}
[424] Fix | Delete
[425] Fix | Delete
/**
[426] Fix | Delete
* Replaces double line breaks with paragraph elements.
[427] Fix | Delete
*
[428] Fix | Delete
* A group of regex replaces used to identify text formatted with newlines and
[429] Fix | Delete
* replace double line breaks with HTML paragraph tags. The remaining line breaks
[430] Fix | Delete
* after conversion become <<br />> tags, unless $br is set to '0' or 'false'.
[431] Fix | Delete
*
[432] Fix | Delete
* @since 0.71
[433] Fix | Delete
*
[434] Fix | Delete
* @param string $pee The text which has to be formatted.
[435] Fix | Delete
* @param bool $br Optional. If set, this will convert all remaining line breaks
[436] Fix | Delete
* after paragraphing. Line breaks within `<script>`, `<style>`,
[437] Fix | Delete
* and `<svg>` tags are not affected. Default true.
[438] Fix | Delete
* @return string Text which has been converted into correct paragraph tags.
[439] Fix | Delete
*/
[440] Fix | Delete
function wpautop( $pee, $br = true ) {
[441] Fix | Delete
$pre_tags = array();
[442] Fix | Delete
[443] Fix | Delete
if ( trim( $pee ) === '' ) {
[444] Fix | Delete
return '';
[445] Fix | Delete
}
[446] Fix | Delete
[447] Fix | Delete
// Just to make things a little easier, pad the end.
[448] Fix | Delete
$pee = $pee . "\n";
[449] Fix | Delete
[450] Fix | Delete
/*
[451] Fix | Delete
* Pre tags shouldn't be touched by autop.
[452] Fix | Delete
* Replace pre tags with placeholders and bring them back after autop.
[453] Fix | Delete
*/
[454] Fix | Delete
if ( strpos( $pee, '<pre' ) !== false ) {
[455] Fix | Delete
$pee_parts = explode( '</pre>', $pee );
[456] Fix | Delete
$last_pee = array_pop( $pee_parts );
[457] Fix | Delete
$pee = '';
[458] Fix | Delete
$i = 0;
[459] Fix | Delete
[460] Fix | Delete
foreach ( $pee_parts as $pee_part ) {
[461] Fix | Delete
$start = strpos( $pee_part, '<pre' );
[462] Fix | Delete
[463] Fix | Delete
// Malformed HTML?
[464] Fix | Delete
if ( false === $start ) {
[465] Fix | Delete
$pee .= $pee_part;
[466] Fix | Delete
continue;
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
$name = "<pre wp-pre-tag-$i></pre>";
[470] Fix | Delete
$pre_tags[ $name ] = substr( $pee_part, $start ) . '</pre>';
[471] Fix | Delete
[472] Fix | Delete
$pee .= substr( $pee_part, 0, $start ) . $name;
[473] Fix | Delete
$i++;
[474] Fix | Delete
}
[475] Fix | Delete
[476] Fix | Delete
$pee .= $last_pee;
[477] Fix | Delete
}
[478] Fix | Delete
// Change multiple <br>'s into two line breaks, which will turn into paragraphs.
[479] Fix | Delete
$pee = preg_replace( '|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee );
[480] Fix | Delete
[481] Fix | Delete
$allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
[482] Fix | Delete
[483] Fix | Delete
// Add a double line break above block-level opening tags.
[484] Fix | Delete
$pee = preg_replace( '!(<' . $allblocks . '[\s/>])!', "\n\n$1", $pee );
[485] Fix | Delete
[486] Fix | Delete
// Add a double line break below block-level closing tags.
[487] Fix | Delete
$pee = preg_replace( '!(</' . $allblocks . '>)!', "$1\n\n", $pee );
[488] Fix | Delete
[489] Fix | Delete
// Add a double line break after hr tags, which are self closing.
[490] Fix | Delete
$pee = preg_replace( '!(<hr\s*?/?>)!', "$1\n\n", $pee );
[491] Fix | Delete
[492] Fix | Delete
// Standardize newline characters to "\n".
[493] Fix | Delete
$pee = str_replace( array( "\r\n", "\r" ), "\n", $pee );
[494] Fix | Delete
[495] Fix | Delete
// Find newlines in all elements and add placeholders.
[496] Fix | Delete
$pee = wp_replace_in_html_tags( $pee, array( "\n" => ' <!-- wpnl --> ' ) );
[497] Fix | Delete
[498] Fix | Delete
// Collapse line breaks before and after <option> elements so they don't get autop'd.
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function