Edit File by line
/home/barbar84/www/wp-inclu...
File: formatting.php
if ( strpos( $pee, '<option' ) !== false ) {
[500] Fix | Delete
$pee = preg_replace( '|\s*<option|', '<option', $pee );
[501] Fix | Delete
$pee = preg_replace( '|</option>\s*|', '</option>', $pee );
[502] Fix | Delete
}
[503] Fix | Delete
[504] Fix | Delete
/*
[505] Fix | Delete
* Collapse line breaks inside <object> elements, before <param> and <embed> elements
[506] Fix | Delete
* so they don't get autop'd.
[507] Fix | Delete
*/
[508] Fix | Delete
if ( strpos( $pee, '</object>' ) !== false ) {
[509] Fix | Delete
$pee = preg_replace( '|(<object[^>]*>)\s*|', '$1', $pee );
[510] Fix | Delete
$pee = preg_replace( '|\s*</object>|', '</object>', $pee );
[511] Fix | Delete
$pee = preg_replace( '%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee );
[512] Fix | Delete
}
[513] Fix | Delete
[514] Fix | Delete
/*
[515] Fix | Delete
* Collapse line breaks inside <audio> and <video> elements,
[516] Fix | Delete
* before and after <source> and <track> elements.
[517] Fix | Delete
*/
[518] Fix | Delete
if ( strpos( $pee, '<source' ) !== false || strpos( $pee, '<track' ) !== false ) {
[519] Fix | Delete
$pee = preg_replace( '%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee );
[520] Fix | Delete
$pee = preg_replace( '%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee );
[521] Fix | Delete
$pee = preg_replace( '%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee );
[522] Fix | Delete
}
[523] Fix | Delete
[524] Fix | Delete
// Collapse line breaks before and after <figcaption> elements.
[525] Fix | Delete
if ( strpos( $pee, '<figcaption' ) !== false ) {
[526] Fix | Delete
$pee = preg_replace( '|\s*(<figcaption[^>]*>)|', '$1', $pee );
[527] Fix | Delete
$pee = preg_replace( '|</figcaption>\s*|', '</figcaption>', $pee );
[528] Fix | Delete
}
[529] Fix | Delete
[530] Fix | Delete
// Remove more than two contiguous line breaks.
[531] Fix | Delete
$pee = preg_replace( "/\n\n+/", "\n\n", $pee );
[532] Fix | Delete
[533] Fix | Delete
// Split up the contents into an array of strings, separated by double line breaks.
[534] Fix | Delete
$pees = preg_split( '/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY );
[535] Fix | Delete
[536] Fix | Delete
// Reset $pee prior to rebuilding.
[537] Fix | Delete
$pee = '';
[538] Fix | Delete
[539] Fix | Delete
// Rebuild the content as a string, wrapping every bit with a <p>.
[540] Fix | Delete
foreach ( $pees as $tinkle ) {
[541] Fix | Delete
$pee .= '<p>' . trim( $tinkle, "\n" ) . "</p>\n";
[542] Fix | Delete
}
[543] Fix | Delete
[544] Fix | Delete
// Under certain strange conditions it could create a P of entirely whitespace.
[545] Fix | Delete
$pee = preg_replace( '|<p>\s*</p>|', '', $pee );
[546] Fix | Delete
[547] Fix | Delete
// Add a closing <p> inside <div>, <address>, or <form> tag if missing.
[548] Fix | Delete
$pee = preg_replace( '!<p>([^<]+)</(div|address|form)>!', '<p>$1</p></$2>', $pee );
[549] Fix | Delete
[550] Fix | Delete
// If an opening or closing block element tag is wrapped in a <p>, unwrap it.
[551] Fix | Delete
$pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $pee );
[552] Fix | Delete
[553] Fix | Delete
// In some cases <li> may get wrapped in <p>, fix them.
[554] Fix | Delete
$pee = preg_replace( '|<p>(<li.+?)</p>|', '$1', $pee );
[555] Fix | Delete
[556] Fix | Delete
// If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
[557] Fix | Delete
$pee = preg_replace( '|<p><blockquote([^>]*)>|i', '<blockquote$1><p>', $pee );
[558] Fix | Delete
$pee = str_replace( '</blockquote></p>', '</p></blockquote>', $pee );
[559] Fix | Delete
[560] Fix | Delete
// If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
[561] Fix | Delete
$pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)!', '$1', $pee );
[562] Fix | Delete
[563] Fix | Delete
// If an opening or closing block element tag is followed by a closing <p> tag, remove it.
[564] Fix | Delete
$pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $pee );
[565] Fix | Delete
[566] Fix | Delete
// Optionally insert line breaks.
[567] Fix | Delete
if ( $br ) {
[568] Fix | Delete
// Replace newlines that shouldn't be touched with a placeholder.
[569] Fix | Delete
$pee = preg_replace_callback( '/<(script|style|svg).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee );
[570] Fix | Delete
[571] Fix | Delete
// Normalize <br>
[572] Fix | Delete
$pee = str_replace( array( '<br>', '<br/>' ), '<br />', $pee );
[573] Fix | Delete
[574] Fix | Delete
// Replace any new line characters that aren't preceded by a <br /> with a <br />.
[575] Fix | Delete
$pee = preg_replace( '|(?<!<br />)\s*\n|', "<br />\n", $pee );
[576] Fix | Delete
[577] Fix | Delete
// Replace newline placeholders with newlines.
[578] Fix | Delete
$pee = str_replace( '<WPPreserveNewline />', "\n", $pee );
[579] Fix | Delete
}
[580] Fix | Delete
[581] Fix | Delete
// If a <br /> tag is after an opening or closing block tag, remove it.
[582] Fix | Delete
$pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*<br />!', '$1', $pee );
[583] Fix | Delete
[584] Fix | Delete
// If a <br /> tag is before a subset of opening or closing block tags, remove it.
[585] Fix | Delete
$pee = preg_replace( '!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee );
[586] Fix | Delete
$pee = preg_replace( "|\n</p>$|", '</p>', $pee );
[587] Fix | Delete
[588] Fix | Delete
// Replace placeholder <pre> tags with their original content.
[589] Fix | Delete
if ( ! empty( $pre_tags ) ) {
[590] Fix | Delete
$pee = str_replace( array_keys( $pre_tags ), array_values( $pre_tags ), $pee );
[591] Fix | Delete
}
[592] Fix | Delete
[593] Fix | Delete
// Restore newlines in all elements.
[594] Fix | Delete
if ( false !== strpos( $pee, '<!-- wpnl -->' ) ) {
[595] Fix | Delete
$pee = str_replace( array( ' <!-- wpnl --> ', '<!-- wpnl -->' ), "\n", $pee );
[596] Fix | Delete
}
[597] Fix | Delete
[598] Fix | Delete
return $pee;
[599] Fix | Delete
}
[600] Fix | Delete
[601] Fix | Delete
/**
[602] Fix | Delete
* Separate HTML elements and comments from the text.
[603] Fix | Delete
*
[604] Fix | Delete
* @since 4.2.4
[605] Fix | Delete
*
[606] Fix | Delete
* @param string $input The text which has to be formatted.
[607] Fix | Delete
* @return string[] Array of the formatted text.
[608] Fix | Delete
*/
[609] Fix | Delete
function wp_html_split( $input ) {
[610] Fix | Delete
return preg_split( get_html_split_regex(), $input, -1, PREG_SPLIT_DELIM_CAPTURE );
[611] Fix | Delete
}
[612] Fix | Delete
[613] Fix | Delete
/**
[614] Fix | Delete
* Retrieve the regular expression for an HTML element.
[615] Fix | Delete
*
[616] Fix | Delete
* @since 4.4.0
[617] Fix | Delete
*
[618] Fix | Delete
* @return string The regular expression
[619] Fix | Delete
*/
[620] Fix | Delete
function get_html_split_regex() {
[621] Fix | Delete
static $regex;
[622] Fix | Delete
[623] Fix | Delete
if ( ! isset( $regex ) ) {
[624] Fix | Delete
// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
[625] Fix | Delete
$comments =
[626] Fix | Delete
'!' // Start of comment, after the <.
[627] Fix | Delete
. '(?:' // Unroll the loop: Consume everything until --> is found.
[628] Fix | Delete
. '-(?!->)' // Dash not followed by end of comment.
[629] Fix | Delete
. '[^\-]*+' // Consume non-dashes.
[630] Fix | Delete
. ')*+' // Loop possessively.
[631] Fix | Delete
. '(?:-->)?'; // End of comment. If not found, match all input.
[632] Fix | Delete
[633] Fix | Delete
$cdata =
[634] Fix | Delete
'!\[CDATA\[' // Start of comment, after the <.
[635] Fix | Delete
. '[^\]]*+' // Consume non-].
[636] Fix | Delete
. '(?:' // Unroll the loop: Consume everything until ]]> is found.
[637] Fix | Delete
. '](?!]>)' // One ] not followed by end of comment.
[638] Fix | Delete
. '[^\]]*+' // Consume non-].
[639] Fix | Delete
. ')*+' // Loop possessively.
[640] Fix | Delete
. '(?:]]>)?'; // End of comment. If not found, match all input.
[641] Fix | Delete
[642] Fix | Delete
$escaped =
[643] Fix | Delete
'(?=' // Is the element escaped?
[644] Fix | Delete
. '!--'
[645] Fix | Delete
. '|'
[646] Fix | Delete
. '!\[CDATA\['
[647] Fix | Delete
. ')'
[648] Fix | Delete
. '(?(?=!-)' // If yes, which type?
[649] Fix | Delete
. $comments
[650] Fix | Delete
. '|'
[651] Fix | Delete
. $cdata
[652] Fix | Delete
. ')';
[653] Fix | Delete
[654] Fix | Delete
$regex =
[655] Fix | Delete
'/(' // Capture the entire match.
[656] Fix | Delete
. '<' // Find start of element.
[657] Fix | Delete
. '(?' // Conditional expression follows.
[658] Fix | Delete
. $escaped // Find end of escaped element.
[659] Fix | Delete
. '|' // ...else...
[660] Fix | Delete
. '[^>]*>?' // Find end of normal element.
[661] Fix | Delete
. ')'
[662] Fix | Delete
. ')/';
[663] Fix | Delete
// phpcs:enable
[664] Fix | Delete
}
[665] Fix | Delete
[666] Fix | Delete
return $regex;
[667] Fix | Delete
}
[668] Fix | Delete
[669] Fix | Delete
/**
[670] Fix | Delete
* Retrieve the combined regular expression for HTML and shortcodes.
[671] Fix | Delete
*
[672] Fix | Delete
* @access private
[673] Fix | Delete
* @ignore
[674] Fix | Delete
* @internal This function will be removed in 4.5.0 per Shortcode API Roadmap.
[675] Fix | Delete
* @since 4.4.0
[676] Fix | Delete
*
[677] Fix | Delete
* @param string $shortcode_regex The result from _get_wptexturize_shortcode_regex(). Optional.
[678] Fix | Delete
* @return string The regular expression
[679] Fix | Delete
*/
[680] Fix | Delete
function _get_wptexturize_split_regex( $shortcode_regex = '' ) {
[681] Fix | Delete
static $html_regex;
[682] Fix | Delete
[683] Fix | Delete
if ( ! isset( $html_regex ) ) {
[684] Fix | Delete
// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
[685] Fix | Delete
$comment_regex =
[686] Fix | Delete
'!' // Start of comment, after the <.
[687] Fix | Delete
. '(?:' // Unroll the loop: Consume everything until --> is found.
[688] Fix | Delete
. '-(?!->)' // Dash not followed by end of comment.
[689] Fix | Delete
. '[^\-]*+' // Consume non-dashes.
[690] Fix | Delete
. ')*+' // Loop possessively.
[691] Fix | Delete
. '(?:-->)?'; // End of comment. If not found, match all input.
[692] Fix | Delete
[693] Fix | Delete
$html_regex = // Needs replaced with wp_html_split() per Shortcode API Roadmap.
[694] Fix | Delete
'<' // Find start of element.
[695] Fix | Delete
. '(?(?=!--)' // Is this a comment?
[696] Fix | Delete
. $comment_regex // Find end of comment.
[697] Fix | Delete
. '|'
[698] Fix | Delete
. '[^>]*>?' // Find end of element. If not found, match all input.
[699] Fix | Delete
. ')';
[700] Fix | Delete
// phpcs:enable
[701] Fix | Delete
}
[702] Fix | Delete
[703] Fix | Delete
if ( empty( $shortcode_regex ) ) {
[704] Fix | Delete
$regex = '/(' . $html_regex . ')/';
[705] Fix | Delete
} else {
[706] Fix | Delete
$regex = '/(' . $html_regex . '|' . $shortcode_regex . ')/';
[707] Fix | Delete
}
[708] Fix | Delete
[709] Fix | Delete
return $regex;
[710] Fix | Delete
}
[711] Fix | Delete
[712] Fix | Delete
/**
[713] Fix | Delete
* Retrieve the regular expression for shortcodes.
[714] Fix | Delete
*
[715] Fix | Delete
* @access private
[716] Fix | Delete
* @ignore
[717] Fix | Delete
* @since 4.4.0
[718] Fix | Delete
*
[719] Fix | Delete
* @param string[] $tagnames Array of shortcodes to find.
[720] Fix | Delete
* @return string The regular expression
[721] Fix | Delete
*/
[722] Fix | Delete
function _get_wptexturize_shortcode_regex( $tagnames ) {
[723] Fix | Delete
$tagregexp = implode( '|', array_map( 'preg_quote', $tagnames ) );
[724] Fix | Delete
$tagregexp = "(?:$tagregexp)(?=[\\s\\]\\/])"; // Excerpt of get_shortcode_regex().
[725] Fix | Delete
// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
[726] Fix | Delete
$regex =
[727] Fix | Delete
'\[' // Find start of shortcode.
[728] Fix | Delete
. '[\/\[]?' // Shortcodes may begin with [/ or [[.
[729] Fix | Delete
. $tagregexp // Only match registered shortcodes, because performance.
[730] Fix | Delete
. '(?:'
[731] Fix | Delete
. '[^\[\]<>]+' // Shortcodes do not contain other shortcodes. Quantifier critical.
[732] Fix | Delete
. '|'
[733] Fix | Delete
. '<[^\[\]>]*>' // HTML elements permitted. Prevents matching ] before >.
[734] Fix | Delete
. ')*+' // Possessive critical.
[735] Fix | Delete
. '\]' // Find end of shortcode.
[736] Fix | Delete
. '\]?'; // Shortcodes may end with ]].
[737] Fix | Delete
// phpcs:enable
[738] Fix | Delete
[739] Fix | Delete
return $regex;
[740] Fix | Delete
}
[741] Fix | Delete
[742] Fix | Delete
/**
[743] Fix | Delete
* Replace characters or phrases within HTML elements only.
[744] Fix | Delete
*
[745] Fix | Delete
* @since 4.2.3
[746] Fix | Delete
*
[747] Fix | Delete
* @param string $haystack The text which has to be formatted.
[748] Fix | Delete
* @param array $replace_pairs In the form array('from' => 'to', ...).
[749] Fix | Delete
* @return string The formatted text.
[750] Fix | Delete
*/
[751] Fix | Delete
function wp_replace_in_html_tags( $haystack, $replace_pairs ) {
[752] Fix | Delete
// Find all elements.
[753] Fix | Delete
$textarr = wp_html_split( $haystack );
[754] Fix | Delete
$changed = false;
[755] Fix | Delete
[756] Fix | Delete
// Optimize when searching for one item.
[757] Fix | Delete
if ( 1 === count( $replace_pairs ) ) {
[758] Fix | Delete
// Extract $needle and $replace.
[759] Fix | Delete
foreach ( $replace_pairs as $needle => $replace ) {
[760] Fix | Delete
}
[761] Fix | Delete
[762] Fix | Delete
// Loop through delimiters (elements) only.
[763] Fix | Delete
for ( $i = 1, $c = count( $textarr ); $i < $c; $i += 2 ) {
[764] Fix | Delete
if ( false !== strpos( $textarr[ $i ], $needle ) ) {
[765] Fix | Delete
$textarr[ $i ] = str_replace( $needle, $replace, $textarr[ $i ] );
[766] Fix | Delete
$changed = true;
[767] Fix | Delete
}
[768] Fix | Delete
}
[769] Fix | Delete
} else {
[770] Fix | Delete
// Extract all $needles.
[771] Fix | Delete
$needles = array_keys( $replace_pairs );
[772] Fix | Delete
[773] Fix | Delete
// Loop through delimiters (elements) only.
[774] Fix | Delete
for ( $i = 1, $c = count( $textarr ); $i < $c; $i += 2 ) {
[775] Fix | Delete
foreach ( $needles as $needle ) {
[776] Fix | Delete
if ( false !== strpos( $textarr[ $i ], $needle ) ) {
[777] Fix | Delete
$textarr[ $i ] = strtr( $textarr[ $i ], $replace_pairs );
[778] Fix | Delete
$changed = true;
[779] Fix | Delete
// After one strtr() break out of the foreach loop and look at next element.
[780] Fix | Delete
break;
[781] Fix | Delete
}
[782] Fix | Delete
}
[783] Fix | Delete
}
[784] Fix | Delete
}
[785] Fix | Delete
[786] Fix | Delete
if ( $changed ) {
[787] Fix | Delete
$haystack = implode( $textarr );
[788] Fix | Delete
}
[789] Fix | Delete
[790] Fix | Delete
return $haystack;
[791] Fix | Delete
}
[792] Fix | Delete
[793] Fix | Delete
/**
[794] Fix | Delete
* Newline preservation help function for wpautop
[795] Fix | Delete
*
[796] Fix | Delete
* @since 3.1.0
[797] Fix | Delete
* @access private
[798] Fix | Delete
*
[799] Fix | Delete
* @param array $matches preg_replace_callback matches array
[800] Fix | Delete
* @return string
[801] Fix | Delete
*/
[802] Fix | Delete
function _autop_newline_preservation_helper( $matches ) {
[803] Fix | Delete
return str_replace( "\n", '<WPPreserveNewline />', $matches[0] );
[804] Fix | Delete
}
[805] Fix | Delete
[806] Fix | Delete
/**
[807] Fix | Delete
* Don't auto-p wrap shortcodes that stand alone
[808] Fix | Delete
*
[809] Fix | Delete
* Ensures that shortcodes are not wrapped in `<p>...</p>`.
[810] Fix | Delete
*
[811] Fix | Delete
* @since 2.9.0
[812] Fix | Delete
*
[813] Fix | Delete
* @global array $shortcode_tags
[814] Fix | Delete
*
[815] Fix | Delete
* @param string $pee The content.
[816] Fix | Delete
* @return string The filtered content.
[817] Fix | Delete
*/
[818] Fix | Delete
function shortcode_unautop( $pee ) {
[819] Fix | Delete
global $shortcode_tags;
[820] Fix | Delete
[821] Fix | Delete
if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) {
[822] Fix | Delete
return $pee;
[823] Fix | Delete
}
[824] Fix | Delete
[825] Fix | Delete
$tagregexp = implode( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) );
[826] Fix | Delete
$spaces = wp_spaces_regexp();
[827] Fix | Delete
[828] Fix | Delete
// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound,WordPress.WhiteSpace.PrecisionAlignment.Found -- don't remove regex indentation
[829] Fix | Delete
$pattern =
[830] Fix | Delete
'/'
[831] Fix | Delete
. '<p>' // Opening paragraph.
[832] Fix | Delete
. '(?:' . $spaces . ')*+' // Optional leading whitespace.
[833] Fix | Delete
. '(' // 1: The shortcode.
[834] Fix | Delete
. '\\[' // Opening bracket.
[835] Fix | Delete
. "($tagregexp)" // 2: Shortcode name.
[836] Fix | Delete
. '(?![\\w-])' // Not followed by word character or hyphen.
[837] Fix | Delete
// Unroll the loop: Inside the opening shortcode tag.
[838] Fix | Delete
. '[^\\]\\/]*' // Not a closing bracket or forward slash.
[839] Fix | Delete
. '(?:'
[840] Fix | Delete
. '\\/(?!\\])' // A forward slash not followed by a closing bracket.
[841] Fix | Delete
. '[^\\]\\/]*' // Not a closing bracket or forward slash.
[842] Fix | Delete
. ')*?'
[843] Fix | Delete
. '(?:'
[844] Fix | Delete
. '\\/\\]' // Self closing tag and closing bracket.
[845] Fix | Delete
. '|'
[846] Fix | Delete
. '\\]' // Closing bracket.
[847] Fix | Delete
. '(?:' // Unroll the loop: Optionally, anything between the opening and closing shortcode tags.
[848] Fix | Delete
. '[^\\[]*+' // Not an opening bracket.
[849] Fix | Delete
. '(?:'
[850] Fix | Delete
. '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag.
[851] Fix | Delete
. '[^\\[]*+' // Not an opening bracket.
[852] Fix | Delete
. ')*+'
[853] Fix | Delete
. '\\[\\/\\2\\]' // Closing shortcode tag.
[854] Fix | Delete
. ')?'
[855] Fix | Delete
. ')'
[856] Fix | Delete
. ')'
[857] Fix | Delete
. '(?:' . $spaces . ')*+' // Optional trailing whitespace.
[858] Fix | Delete
. '<\\/p>' // Closing paragraph.
[859] Fix | Delete
. '/';
[860] Fix | Delete
// phpcs:enable
[861] Fix | Delete
[862] Fix | Delete
return preg_replace( $pattern, '$1', $pee );
[863] Fix | Delete
}
[864] Fix | Delete
[865] Fix | Delete
/**
[866] Fix | Delete
* Checks to see if a string is utf8 encoded.
[867] Fix | Delete
*
[868] Fix | Delete
* NOTE: This function checks for 5-Byte sequences, UTF8
[869] Fix | Delete
* has Bytes Sequences with a maximum length of 4.
[870] Fix | Delete
*
[871] Fix | Delete
* @author bmorel at ssi dot fr (modified)
[872] Fix | Delete
* @since 1.2.1
[873] Fix | Delete
*
[874] Fix | Delete
* @param string $str The string to be checked
[875] Fix | Delete
* @return bool True if $str fits a UTF-8 model, false otherwise.
[876] Fix | Delete
*/
[877] Fix | Delete
function seems_utf8( $str ) {
[878] Fix | Delete
mbstring_binary_safe_encoding();
[879] Fix | Delete
$length = strlen( $str );
[880] Fix | Delete
reset_mbstring_encoding();
[881] Fix | Delete
for ( $i = 0; $i < $length; $i++ ) {
[882] Fix | Delete
$c = ord( $str[ $i ] );
[883] Fix | Delete
if ( $c < 0x80 ) {
[884] Fix | Delete
$n = 0; // 0bbbbbbb
[885] Fix | Delete
} elseif ( ( $c & 0xE0 ) == 0xC0 ) {
[886] Fix | Delete
$n = 1; // 110bbbbb
[887] Fix | Delete
} elseif ( ( $c & 0xF0 ) == 0xE0 ) {
[888] Fix | Delete
$n = 2; // 1110bbbb
[889] Fix | Delete
} elseif ( ( $c & 0xF8 ) == 0xF0 ) {
[890] Fix | Delete
$n = 3; // 11110bbb
[891] Fix | Delete
} elseif ( ( $c & 0xFC ) == 0xF8 ) {
[892] Fix | Delete
$n = 4; // 111110bb
[893] Fix | Delete
} elseif ( ( $c & 0xFE ) == 0xFC ) {
[894] Fix | Delete
$n = 5; // 1111110b
[895] Fix | Delete
} else {
[896] Fix | Delete
return false; // Does not match any model.
[897] Fix | Delete
}
[898] Fix | Delete
for ( $j = 0; $j < $n; $j++ ) { // n bytes matching 10bbbbbb follow ?
[899] Fix | Delete
if ( ( ++$i == $length ) || ( ( ord( $str[ $i ] ) & 0xC0 ) != 0x80 ) ) {
[900] Fix | Delete
return false;
[901] Fix | Delete
}
[902] Fix | Delete
}
[903] Fix | Delete
}
[904] Fix | Delete
return true;
[905] Fix | Delete
}
[906] Fix | Delete
[907] Fix | Delete
/**
[908] Fix | Delete
* Converts a number of special characters into their HTML entities.
[909] Fix | Delete
*
[910] Fix | Delete
* Specifically deals with: &, <, >, ", and '.
[911] Fix | Delete
*
[912] Fix | Delete
* $quote_style can be set to ENT_COMPAT to encode " to
[913] Fix | Delete
* &quot;, or ENT_QUOTES to do both. Default is ENT_NOQUOTES where no quotes are encoded.
[914] Fix | Delete
*
[915] Fix | Delete
* @since 1.2.2
[916] Fix | Delete
* @since 5.5.0 `$quote_style` also accepts `ENT_XML1`.
[917] Fix | Delete
* @access private
[918] Fix | Delete
*
[919] Fix | Delete
* @param string $string The text which is to be encoded.
[920] Fix | Delete
* @param int|string $quote_style Optional. Converts double quotes if set to ENT_COMPAT,
[921] Fix | Delete
* both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES.
[922] Fix | Delete
* Converts single and double quotes, as well as converting HTML
[923] Fix | Delete
* named entities (that are not also XML named entities) to their
[924] Fix | Delete
* code points if set to ENT_XML1. Also compatible with old values;
[925] Fix | Delete
* converting single quotes if set to 'single',
[926] Fix | Delete
* double if set to 'double' or both if otherwise set.
[927] Fix | Delete
* Default is ENT_NOQUOTES.
[928] Fix | Delete
* @param false|string $charset Optional. The character encoding of the string. Default false.
[929] Fix | Delete
* @param bool $double_encode Optional. Whether to encode existing HTML entities. Default false.
[930] Fix | Delete
* @return string The encoded text with HTML entities.
[931] Fix | Delete
*/
[932] Fix | Delete
function _wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) {
[933] Fix | Delete
$string = (string) $string;
[934] Fix | Delete
[935] Fix | Delete
if ( 0 === strlen( $string ) ) {
[936] Fix | Delete
return '';
[937] Fix | Delete
}
[938] Fix | Delete
[939] Fix | Delete
// Don't bother if there are no specialchars - saves some processing.
[940] Fix | Delete
if ( ! preg_match( '/[&<>"\']/', $string ) ) {
[941] Fix | Delete
return $string;
[942] Fix | Delete
}
[943] Fix | Delete
[944] Fix | Delete
// Account for the previous behaviour of the function when the $quote_style is not an accepted value.
[945] Fix | Delete
if ( empty( $quote_style ) ) {
[946] Fix | Delete
$quote_style = ENT_NOQUOTES;
[947] Fix | Delete
} elseif ( ENT_XML1 === $quote_style ) {
[948] Fix | Delete
$quote_style = ENT_QUOTES | ENT_XML1;
[949] Fix | Delete
} elseif ( ! in_array( $quote_style, array( ENT_NOQUOTES, ENT_COMPAT, ENT_QUOTES, 'single', 'double' ), true ) ) {
[950] Fix | Delete
$quote_style = ENT_QUOTES;
[951] Fix | Delete
}
[952] Fix | Delete
[953] Fix | Delete
// Store the site charset as a static to avoid multiple calls to wp_load_alloptions().
[954] Fix | Delete
if ( ! $charset ) {
[955] Fix | Delete
static $_charset = null;
[956] Fix | Delete
if ( ! isset( $_charset ) ) {
[957] Fix | Delete
$alloptions = wp_load_alloptions();
[958] Fix | Delete
$_charset = isset( $alloptions['blog_charset'] ) ? $alloptions['blog_charset'] : '';
[959] Fix | Delete
}
[960] Fix | Delete
$charset = $_charset;
[961] Fix | Delete
}
[962] Fix | Delete
[963] Fix | Delete
if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ), true ) ) {
[964] Fix | Delete
$charset = 'UTF-8';
[965] Fix | Delete
}
[966] Fix | Delete
[967] Fix | Delete
$_quote_style = $quote_style;
[968] Fix | Delete
[969] Fix | Delete
if ( 'double' === $quote_style ) {
[970] Fix | Delete
$quote_style = ENT_COMPAT;
[971] Fix | Delete
$_quote_style = ENT_COMPAT;
[972] Fix | Delete
} elseif ( 'single' === $quote_style ) {
[973] Fix | Delete
$quote_style = ENT_NOQUOTES;
[974] Fix | Delete
}
[975] Fix | Delete
[976] Fix | Delete
if ( ! $double_encode ) {
[977] Fix | Delete
// Guarantee every &entity; is valid, convert &garbage; into &amp;garbage;
[978] Fix | Delete
// This is required for PHP < 5.4.0 because ENT_HTML401 flag is unavailable.
[979] Fix | Delete
$string = wp_kses_normalize_entities( $string, ( $quote_style & ENT_XML1 ) ? 'xml' : 'html' );
[980] Fix | Delete
}
[981] Fix | Delete
[982] Fix | Delete
$string = htmlspecialchars( $string, $quote_style, $charset, $double_encode );
[983] Fix | Delete
[984] Fix | Delete
// Back-compat.
[985] Fix | Delete
if ( 'single' === $_quote_style ) {
[986] Fix | Delete
$string = str_replace( "'", '&#039;', $string );
[987] Fix | Delete
}
[988] Fix | Delete
[989] Fix | Delete
return $string;
[990] Fix | Delete
}
[991] Fix | Delete
[992] Fix | Delete
/**
[993] Fix | Delete
* Converts a number of HTML entities into their special characters.
[994] Fix | Delete
*
[995] Fix | Delete
* Specifically deals with: &, <, >, ", and '.
[996] Fix | Delete
*
[997] Fix | Delete
* $quote_style can be set to ENT_COMPAT to decode " entities,
[998] Fix | Delete
* or ENT_QUOTES to do both " and '. Default is ENT_NOQUOTES where no quotes are decoded.
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function