Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

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