.
- $pee = preg_replace('|]*)>|i', "", $pee);
- $pee = str_replace('
', '
', $pee);
+ $pee = preg_replace( '|]*)>|i', '', $pee );
+ $pee = str_replace( '
', '
', $pee );
// If an opening or closing block element tag is preceded by an opening tag, remove it.
- $pee = preg_replace('!
\s*(?' . $allblocks . '[^>]*>)!', "$1", $pee);
+ $pee = preg_replace( '!
\s*(?' . $allblocks . '[^>]*>)!', '$1', $pee );
// If an opening or closing block element tag is followed by a closing
tag, remove it.
- $pee = preg_replace('!(?' . $allblocks . '[^>]*>)\s*
!', "$1", $pee);
+ $pee = preg_replace( '!(?' . $allblocks . '[^>]*>)\s*!', '$1', $pee );
// Optionally insert line breaks.
if ( $br ) {
// Replace newlines that shouldn't be touched with a placeholder.
- $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee);
+ $pee = preg_replace_callback( '/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee );
// Normalize
$pee = str_replace( array( '
', '
' ), '
', $pee );
// Replace any new line characters that aren't preceded by a
with a
.
- $pee = preg_replace('|(?)\s*\n|', "
\n", $pee);
+ $pee = preg_replace( '|(?)\s*\n|', "
\n", $pee );
// Replace newline placeholders with newlines.
- $pee = str_replace('', "\n", $pee);
+ $pee = str_replace( '', "\n", $pee );
}
// If a
tag is after an opening or closing block tag, remove it.
- $pee = preg_replace('!(?' . $allblocks . '[^>]*>)\s*
!', "$1", $pee);
+ $pee = preg_replace( '!(?' . $allblocks . '[^>]*>)\s*
!', '$1', $pee );
// If a
tag is before a subset of opening or closing block tags, remove it.
- $pee = preg_replace('!
(\s*?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
+ $pee = preg_replace( '!
(\s*?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee );
$pee = preg_replace( "|\n$|", '', $pee );
// Replace placeholder tags with their original content.
- if ( !empty($pre_tags) )
- $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
+ if ( ! empty( $pre_tags ) ) {
+ $pee = str_replace( array_keys( $pre_tags ), array_values( $pre_tags ), $pee );
+ }
// Restore newlines in all elements.
if ( false !== strpos( $pee, '' ) ) {
@@ -617,8 +634,9 @@
static $regex;
if ( ! isset( $regex ) ) {
+ // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
$comments =
- '!' // Start of comment, after the <.
+ '!' // Start of comment, after the <.
. '(?:' // Unroll the loop: Consume everything until --> is found.
. '-(?!->)' // Dash not followed by end of comment.
. '[^\-]*+' // Consume non-dashes.
@@ -626,7 +644,7 @@
. '(?:-->)?'; // End of comment. If not found, match all input.
$cdata =
- '!\[CDATA\[' // Start of comment, after the <.
+ '!\[CDATA\[' // Start of comment, after the <.
. '[^\]]*+' // Consume non-].
. '(?:' // Unroll the loop: Consume everything until ]]> is found.
. '](?!]>)' // One ] not followed by end of comment.
@@ -635,7 +653,7 @@
. '(?:]]>)?'; // End of comment. If not found, match all input.
$escaped =
- '(?=' // Is the element escaped?
+ '(?=' // Is the element escaped?
. '!--'
. '|'
. '!\[CDATA\['
@@ -647,7 +665,7 @@
. ')';
$regex =
- '/(' // Capture the entire match.
+ '/(' // Capture the entire match.
. '<' // Find start of element.
. '(?' // Conditional expression follows.
. $escaped // Find end of escaped element.
@@ -655,6 +673,7 @@
. '[^>]*>?' // Find end of normal element.
. ')'
. ')/';
+ // phpcs:enable
}
return $regex;
@@ -677,21 +696,23 @@
static $html_regex;
if ( ! isset( $html_regex ) ) {
+ // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
$comment_regex =
- '!' // Start of comment, after the <.
+ '!' // Start of comment, after the <.
. '(?:' // Unroll the loop: Consume everything until --> is found.
. '-(?!->)' // Dash not followed by end of comment.
. '[^\-]*+' // Consume non-dashes.
. ')*+' // Loop possessively.
. '(?:-->)?'; // End of comment. If not found, match all input.
- $html_regex = // Needs replaced with wp_html_split() per Shortcode API Roadmap.
- '<' // Find start of element.
+ $html_regex = // Needs replaced with wp_html_split() per Shortcode API Roadmap.
+ '<' // Find start of element.
. '(?(?=!--)' // Is this a comment?
. $comment_regex // Find end of comment.
. '|'
. '[^>]*>?' // Find end of element. If not found, match all input.
. ')';
+ // phpcs:enable
}
if ( empty( $shortcode_regex ) ) {
@@ -717,8 +738,9 @@
function _get_wptexturize_shortcode_regex( $tagnames ) {
$tagregexp = join( '|', array_map( 'preg_quote', $tagnames ) );
$tagregexp = "(?:$tagregexp)(?=[\\s\\]\\/])"; // Excerpt of get_shortcode_regex().
+ // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
$regex =
- '\[' // Find start of shortcode.
+ '\[' // Find start of shortcode.
. '[\/\[]?' // Shortcodes may begin with [/ or [[
. $tagregexp // Only match registered shortcodes, because performance.
. '(?:'
@@ -728,6 +750,7 @@
. ')*+' // Possessive critical.
. '\]' // Find end of shortcode.
. '\]?'; // Shortcodes may end with ]]
+ // phpcs:enable
return $regex;
}
@@ -749,13 +772,14 @@
// Optimize when searching for one item.
if ( 1 === count( $replace_pairs ) ) {
// Extract $needle and $replace.
- foreach ( $replace_pairs as $needle => $replace );
+ foreach ( $replace_pairs as $needle => $replace ) {
+ }
// Loop through delimiters (elements) only.
for ( $i = 1, $c = count( $textarr ); $i < $c; $i += 2 ) {
- if ( false !== strpos( $textarr[$i], $needle ) ) {
- $textarr[$i] = str_replace( $needle, $replace, $textarr[$i] );
- $changed = true;
+ if ( false !== strpos( $textarr[ $i ], $needle ) ) {
+ $textarr[ $i ] = str_replace( $needle, $replace, $textarr[ $i ] );
+ $changed = true;
}
}
} else {
@@ -765,9 +789,9 @@
// Loop through delimiters (elements) only.
for ( $i = 1, $c = count( $textarr ); $i < $c; $i += 2 ) {
foreach ( $needles as $needle ) {
- if ( false !== strpos( $textarr[$i], $needle ) ) {
- $textarr[$i] = strtr( $textarr[$i], $replace_pairs );
- $changed = true;
+ if ( false !== strpos( $textarr[ $i ], $needle ) ) {
+ $textarr[ $i ] = strtr( $textarr[ $i ], $replace_pairs );
+ $changed = true;
// After one strtr() break out of the foreach loop and look at next element.
break;
}
@@ -792,7 +816,7 @@
* @return string
*/
function _autop_newline_preservation_helper( $matches ) {
- return str_replace( "\n", "", $matches[0] );
+ return str_replace( "\n", '', $matches[0] );
}
/**
@@ -810,22 +834,23 @@
function shortcode_unautop( $pee ) {
global $shortcode_tags;
- if ( empty( $shortcode_tags ) || !is_array( $shortcode_tags ) ) {
+ if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) {
return $pee;
}
$tagregexp = join( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) );
- $spaces = wp_spaces_regexp();
-
+ $spaces = wp_spaces_regexp();
+
+ // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
$pattern =
- '/'
+ '/'
. '' // Opening paragraph
. '(?:' . $spaces . ')*+' // Optional leading whitespace
. '(' // 1: The shortcode
. '\\[' // Opening bracket
. "($tagregexp)" // 2: Shortcode name
. '(?![\\w-])' // Not followed by word character or hyphen
- // Unroll the loop: Inside the opening shortcode tag
+ // Unroll the loop: Inside the opening shortcode tag
. '[^\\]\\/]*' // Not a closing bracket or forward slash
. '(?:'
. '\\/(?!\\])' // A forward slash not followed by a closing bracket
@@ -848,6 +873,7 @@
. '(?:' . $spaces . ')*+' // optional trailing whitespace
. '<\\/p>' // closing paragraph
. '/';
+ // phpcs:enable
return preg_replace( $pattern, '$1', $pee );
}
@@ -866,20 +892,29 @@
*/
function seems_utf8( $str ) {
mbstring_binary_safe_encoding();
- $length = strlen($str);
+ $length = strlen( $str );
reset_mbstring_encoding();
- for ($i=0; $i < $length; $i++) {
- $c = ord($str[$i]);
- if ($c < 0x80) $n = 0; // 0bbbbbbb
- elseif (($c & 0xE0) == 0xC0) $n=1; // 110bbbbb
- elseif (($c & 0xF0) == 0xE0) $n=2; // 1110bbbb
- elseif (($c & 0xF8) == 0xF0) $n=3; // 11110bbb
- elseif (($c & 0xFC) == 0xF8) $n=4; // 111110bb
- elseif (($c & 0xFE) == 0xFC) $n=5; // 1111110b
- else return false; // Does not match any model
- for ($j=0; $j<$n; $j++) { // n bytes matching 10bbbbbb follow ?
- if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80))
+ for ( $i = 0; $i < $length; $i++ ) {
+ $c = ord( $str[ $i ] );
+ if ( $c < 0x80 ) {
+ $n = 0; // 0bbbbbbb
+ } elseif ( ( $c & 0xE0 ) == 0xC0 ) {
+ $n = 1; // 110bbbbb
+ } elseif ( ( $c & 0xF0 ) == 0xE0 ) {
+ $n = 2; // 1110bbbb
+ } elseif ( ( $c & 0xF8 ) == 0xF0 ) {
+ $n = 3; // 11110bbb
+ } elseif ( ( $c & 0xFC ) == 0xF8 ) {
+ $n = 4; // 111110bb
+ } elseif ( ( $c & 0xFE ) == 0xFC ) {
+ $n = 5; // 1111110b
+ } else {
+ return false; // Does not match any model
+ }
+ for ( $j = 0; $j < $n; $j++ ) { // n bytes matching 10bbbbbb follow ?
+ if ( ( ++$i == $length ) || ( ( ord( $str[ $i ] ) & 0xC0 ) != 0x80 ) ) {
return false;
+ }
}
}
return true;
@@ -911,36 +946,40 @@
function _wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) {
$string = (string) $string;
- if ( 0 === strlen( $string ) )
+ if ( 0 === strlen( $string ) ) {
return '';
+ }
// Don't bother if there are no specialchars - saves some processing
- if ( ! preg_match( '/[&<>"\']/', $string ) )
+ if ( ! preg_match( '/[&<>"\']/', $string ) ) {
return $string;
+ }
// Account for the previous behaviour of the function when the $quote_style is not an accepted value
- if ( empty( $quote_style ) )
+ if ( empty( $quote_style ) ) {
$quote_style = ENT_NOQUOTES;
- elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) )
+ } elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {
$quote_style = ENT_QUOTES;
+ }
// Store the site charset as a static to avoid multiple calls to wp_load_alloptions()
if ( ! $charset ) {
static $_charset = null;
if ( ! isset( $_charset ) ) {
$alloptions = wp_load_alloptions();
- $_charset = isset( $alloptions['blog_charset'] ) ? $alloptions['blog_charset'] : '';
+ $_charset = isset( $alloptions['blog_charset'] ) ? $alloptions['blog_charset'] : '';
}
$charset = $_charset;
}
- if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) )
+ if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) ) {
$charset = 'UTF-8';
+ }
$_quote_style = $quote_style;
if ( $quote_style === 'double' ) {
- $quote_style = ENT_COMPAT;
+ $quote_style = ENT_COMPAT;
$_quote_style = ENT_COMPAT;
} elseif ( $quote_style === 'single' ) {
$quote_style = ENT_NOQUOTES;
@@ -955,8 +994,9 @@
$string = @htmlspecialchars( $string, $quote_style, $charset, $double_encode );
// Back-compat.
- if ( 'single' === $_quote_style )
+ if ( 'single' === $_quote_style ) {
$string = str_replace( "'", ''', $string );
+ }
return $string;
}
@@ -996,29 +1036,55 @@
// Match the previous behaviour of _wp_specialchars() when the $quote_style is not an accepted value
if ( empty( $quote_style ) ) {
$quote_style = ENT_NOQUOTES;
- } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {
+ } elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {
$quote_style = ENT_QUOTES;
}
// More complete than get_html_translation_table( HTML_SPECIALCHARS )
- $single = array( ''' => '\'', ''' => '\'' );
- $single_preg = array( '/*39;/' => ''', '/*27;/i' => ''' );
- $double = array( '"' => '"', '"' => '"', '"' => '"' );
- $double_preg = array( '/*34;/' => '"', '/*22;/i' => '"' );
- $others = array( '<' => '<', '<' => '<', '>' => '>', '>' => '>', '&' => '&', '&' => '&', '&' => '&' );
- $others_preg = array( '/*60;/' => '<', '/*62;/' => '>', '/*38;/' => '&', '/*26;/i' => '&' );
+ $single = array(
+ ''' => '\'',
+ ''' => '\'',
+ );
+ $single_preg = array(
+ '/*39;/' => ''',
+ '/*27;/i' => ''',
+ );
+ $double = array(
+ '"' => '"',
+ '"' => '"',
+ '"' => '"',
+ );
+ $double_preg = array(
+ '/*34;/' => '"',
+ '/*22;/i' => '"',
+ );
+ $others = array(
+ '<' => '<',
+ '<' => '<',
+ '>' => '>',
+ '>' => '>',
+ '&' => '&',
+ '&' => '&',
+ '&' => '&',
+ );
+ $others_preg = array(
+ '/*60;/' => '<',
+ '/*62;/' => '>',
+ '/*38;/' => '&',
+ '/*26;/i' => '&',
+ );
if ( $quote_style === ENT_QUOTES ) {
- $translation = array_merge( $single, $double, $others );
+ $translation = array_merge( $single, $double, $others );
$translation_preg = array_merge( $single_preg, $double_preg, $others_preg );
} elseif ( $quote_style === ENT_COMPAT || $quote_style === 'double' ) {
- $translation = array_merge( $double, $others );
+ $translation = array_merge( $double, $others );
$translation_preg = array_merge( $double_preg, $others_preg );
} elseif ( $quote_style === 'single' ) {
- $translation = array_merge( $single, $others );
+ $translation = array_merge( $single, $others );
$translation_preg = array_merge( $single_preg, $others_preg );
} elseif ( $quote_style === ENT_NOQUOTES ) {
- $translation = $others;
+ $translation = $others;
$translation_preg = $others_preg;
}
@@ -1063,7 +1129,7 @@
$utf8_pcre = @preg_match( '/^./u', 'a' );
}
// We can't demand utf8 in the PCRE installation, so just return the string in those cases
- if ( !$utf8_pcre ) {
+ if ( ! $utf8_pcre ) {
return $string;
}
@@ -1090,23 +1156,24 @@
* @return string String with Unicode encoded for URI.
*/
function utf8_uri_encode( $utf8_string, $length = 0 ) {
- $unicode = '';
- $values = array();
- $num_octets = 1;
+ $unicode = '';
+ $values = array();
+ $num_octets = 1;
$unicode_length = 0;
mbstring_binary_safe_encoding();
$string_length = strlen( $utf8_string );
reset_mbstring_encoding();
- for ($i = 0; $i < $string_length; $i++ ) {
+ for ( $i = 0; $i < $string_length; $i++ ) {
$value = ord( $utf8_string[ $i ] );
if ( $value < 128 ) {
- if ( $length && ( $unicode_length >= $length ) )
+ if ( $length && ( $unicode_length >= $length ) ) {
break;
- $unicode .= chr($value);
+ }
+ $unicode .= chr( $value );
$unicode_length++;
} else {
if ( count( $values ) == 0 ) {
@@ -1121,8 +1188,9 @@
$values[] = $value;
- if ( $length && ( $unicode_length + ($num_octets * 3) ) > $length )
+ if ( $length && ( $unicode_length + ( $num_octets * 3 ) ) > $length ) {
break;
+ }
if ( count( $values ) == $num_octets ) {
for ( $j = 0; $j < $num_octets; $j++ ) {
$unicode .= '%' . dechex( $values[ $j ] );
@@ -1130,7 +1198,7 @@
$unicode_length += $num_octets * 3;
- $values = array();
+ $values = array();
$num_octets = 1;
}
}
@@ -1526,233 +1594,387 @@
* @return string Filtered string with replaced "nice" characters.
*/
function remove_accents( $string ) {
- if ( !preg_match('/[\x80-\xff]/', $string) )
+ if ( ! preg_match( '/[\x80-\xff]/', $string ) ) {
return $string;
-
- if (seems_utf8($string)) {
+ }
+
+ if ( seems_utf8( $string ) ) {
$chars = array(
- // Decompositions for Latin-1 Supplement
- 'ª' => 'a', 'º' => 'o',
- 'À' => 'A', 'Á' => 'A',
- 'Â' => 'A', 'Ã' => 'A',
- 'Ä' => 'A', 'Å' => 'A',
- 'Æ' => 'AE','Ç' => 'C',
- 'È' => 'E', 'É' => 'E',
- 'Ê' => 'E', 'Ë' => 'E',
- 'Ì' => 'I', 'Í' => 'I',
- 'Î' => 'I', 'Ï' => 'I',
- 'Ð' => 'D', 'Ñ' => 'N',
- 'Ò' => 'O', 'Ó' => 'O',
- 'Ô' => 'O', 'Õ' => 'O',
- 'Ö' => 'O', 'Ù' => 'U',
- 'Ú' => 'U', 'Û' => 'U',
- 'Ü' => 'U', 'Ý' => 'Y',
- 'Þ' => 'TH','ß' => 's',
- 'à' => 'a', 'á' => 'a',
- 'â' => 'a', 'ã' => 'a',
- 'ä' => 'a', 'å' => 'a',
- 'æ' => 'ae','ç' => 'c',
- 'è' => 'e', 'é' => 'e',
- 'ê' => 'e', 'ë' => 'e',
- 'ì' => 'i', 'í' => 'i',
- 'î' => 'i', 'ï' => 'i',
- 'ð' => 'd', 'ñ' => 'n',
- 'ò' => 'o', 'ó' => 'o',
- 'ô' => 'o', 'õ' => 'o',
- 'ö' => 'o', 'ø' => 'o',
- 'ù' => 'u', 'ú' => 'u',
- 'û' => 'u', 'ü' => 'u',
- 'ý' => 'y', 'þ' => 'th',
- 'ÿ' => 'y', 'Ø' => 'O',
- // Decompositions for Latin Extended-A
- 'Ā' => 'A', 'ā' => 'a',
- 'Ă' => 'A', 'ă' => 'a',
- 'Ą' => 'A', 'ą' => 'a',
- 'Ć' => 'C', 'ć' => 'c',
- 'Ĉ' => 'C', 'ĉ' => 'c',
- 'Ċ' => 'C', 'ċ' => 'c',
- 'Č' => 'C', 'č' => 'c',
- 'Ď' => 'D', 'ď' => 'd',
- 'Đ' => 'D', 'đ' => 'd',
- 'Ē' => 'E', 'ē' => 'e',
- 'Ĕ' => 'E', 'ĕ' => 'e',
- 'Ė' => 'E', 'ė' => 'e',
- 'Ę' => 'E', 'ę' => 'e',
- 'Ě' => 'E', 'ě' => 'e',
- 'Ĝ' => 'G', 'ĝ' => 'g',
- 'Ğ' => 'G', 'ğ' => 'g',
- 'Ġ' => 'G', 'ġ' => 'g',
- 'Ģ' => 'G', 'ģ' => 'g',
- 'Ĥ' => 'H', 'ĥ' => 'h',
- 'Ħ' => 'H', 'ħ' => 'h',
- 'Ĩ' => 'I', 'ĩ' => 'i',
- 'Ī' => 'I', 'ī' => 'i',
- 'Ĭ' => 'I', 'ĭ' => 'i',
- 'Į' => 'I', 'į' => 'i',
- 'İ' => 'I', 'ı' => 'i',
- 'IJ' => 'IJ','ij' => 'ij',
- 'Ĵ' => 'J', 'ĵ' => 'j',
- 'Ķ' => 'K', 'ķ' => 'k',
- 'ĸ' => 'k', 'Ĺ' => 'L',
- 'ĺ' => 'l', 'Ļ' => 'L',
- 'ļ' => 'l', 'Ľ' => 'L',
- 'ľ' => 'l', 'Ŀ' => 'L',
- 'ŀ' => 'l', 'Ł' => 'L',
- 'ł' => 'l', 'Ń' => 'N',
- 'ń' => 'n', 'Ņ' => 'N',
- 'ņ' => 'n', 'Ň' => 'N',
- 'ň' => 'n', 'ʼn' => 'n',
- 'Ŋ' => 'N', 'ŋ' => 'n',
- 'Ō' => 'O', 'ō' => 'o',
- 'Ŏ' => 'O', 'ŏ' => 'o',
- 'Ő' => 'O', 'ő' => 'o',
- 'Œ' => 'OE','œ' => 'oe',
- 'Ŕ' => 'R','ŕ' => 'r',
- 'Ŗ' => 'R','ŗ' => 'r',
- 'Ř' => 'R','ř' => 'r',
- 'Ś' => 'S','ś' => 's',
- 'Ŝ' => 'S','ŝ' => 's',
- 'Ş' => 'S','ş' => 's',
- 'Š' => 'S', 'š' => 's',
- 'Ţ' => 'T', 'ţ' => 't',
- 'Ť' => 'T', 'ť' => 't',
- 'Ŧ' => 'T', 'ŧ' => 't',
- 'Ũ' => 'U', 'ũ' => 'u',
- 'Ū' => 'U', 'ū' => 'u',
- 'Ŭ' => 'U', 'ŭ' => 'u',
- 'Ů' => 'U', 'ů' => 'u',
- 'Ű' => 'U', 'ű' => 'u',
- 'Ų' => 'U', 'ų' => 'u',
- 'Ŵ' => 'W', 'ŵ' => 'w',
- 'Ŷ' => 'Y', 'ŷ' => 'y',
- 'Ÿ' => 'Y', 'Ź' => 'Z',
- 'ź' => 'z', 'Ż' => 'Z',
- 'ż' => 'z', 'Ž' => 'Z',
- 'ž' => 'z', 'ſ' => 's',
- // Decompositions for Latin Extended-B
- 'Ș' => 'S', 'ș' => 's',
- 'Ț' => 'T', 'ț' => 't',
- // Euro Sign
- '€' => 'E',
- // GBP (Pound) Sign
- '£' => '',
- // Vowels with diacritic (Vietnamese)
- // unmarked
- 'Ơ' => 'O', 'ơ' => 'o',
- 'Ư' => 'U', 'ư' => 'u',
- // grave accent
- 'Ầ' => 'A', 'ầ' => 'a',
- 'Ằ' => 'A', 'ằ' => 'a',
- 'Ề' => 'E', 'ề' => 'e',
- 'Ồ' => 'O', 'ồ' => 'o',
- 'Ờ' => 'O', 'ờ' => 'o',
- 'Ừ' => 'U', 'ừ' => 'u',
- 'Ỳ' => 'Y', 'ỳ' => 'y',
- // hook
- 'Ả' => 'A', 'ả' => 'a',
- 'Ẩ' => 'A', 'ẩ' => 'a',
- 'Ẳ' => 'A', 'ẳ' => 'a',
- 'Ẻ' => 'E', 'ẻ' => 'e',
- 'Ể' => 'E', 'ể' => 'e',
- 'Ỉ' => 'I', 'ỉ' => 'i',
- 'Ỏ' => 'O', 'ỏ' => 'o',
- 'Ổ' => 'O', 'ổ' => 'o',
- 'Ở' => 'O', 'ở' => 'o',
- 'Ủ' => 'U', 'ủ' => 'u',
- 'Ử' => 'U', 'ử' => 'u',
- 'Ỷ' => 'Y', 'ỷ' => 'y',
- // tilde
- 'Ẫ' => 'A', 'ẫ' => 'a',
- 'Ẵ' => 'A', 'ẵ' => 'a',
- 'Ẽ' => 'E', 'ẽ' => 'e',
- 'Ễ' => 'E', 'ễ' => 'e',
- 'Ỗ' => 'O', 'ỗ' => 'o',
- 'Ỡ' => 'O', 'ỡ' => 'o',
- 'Ữ' => 'U', 'ữ' => 'u',
- 'Ỹ' => 'Y', 'ỹ' => 'y',
- // acute accent
- 'Ấ' => 'A', 'ấ' => 'a',
- 'Ắ' => 'A', 'ắ' => 'a',
- 'Ế' => 'E', 'ế' => 'e',
- 'Ố' => 'O', 'ố' => 'o',
- 'Ớ' => 'O', 'ớ' => 'o',
- 'Ứ' => 'U', 'ứ' => 'u',
- // dot below
- 'Ạ' => 'A', 'ạ' => 'a',
- 'Ậ' => 'A', 'ậ' => 'a',
- 'Ặ' => 'A', 'ặ' => 'a',
- 'Ẹ' => 'E', 'ẹ' => 'e',
- 'Ệ' => 'E', 'ệ' => 'e',
- 'Ị' => 'I', 'ị' => 'i',
- 'Ọ' => 'O', 'ọ' => 'o',
- 'Ộ' => 'O', 'ộ' => 'o',
- 'Ợ' => 'O', 'ợ' => 'o',
- 'Ụ' => 'U', 'ụ' => 'u',
- 'Ự' => 'U', 'ự' => 'u',
- 'Ỵ' => 'Y', 'ỵ' => 'y',
- // Vowels with diacritic (Chinese, Hanyu Pinyin)
- 'ɑ' => 'a',
- // macron
- 'Ǖ' => 'U', 'ǖ' => 'u',
- // acute accent
- 'Ǘ' => 'U', 'ǘ' => 'u',
- // caron
- 'Ǎ' => 'A', 'ǎ' => 'a',
- 'Ǐ' => 'I', 'ǐ' => 'i',
- 'Ǒ' => 'O', 'ǒ' => 'o',
- 'Ǔ' => 'U', 'ǔ' => 'u',
- 'Ǚ' => 'U', 'ǚ' => 'u',
- // grave accent
- 'Ǜ' => 'U', 'ǜ' => 'u',
+ // Decompositions for Latin-1 Supplement
+ 'ª' => 'a',
+ 'º' => 'o',
+ 'À' => 'A',
+ 'Á' => 'A',
+ 'Â' => 'A',
+ 'Ã' => 'A',
+ 'Ä' => 'A',
+ 'Å' => 'A',
+ 'Æ' => 'AE',
+ 'Ç' => 'C',
+ 'È' => 'E',
+ 'É' => 'E',
+ 'Ê' => 'E',
+ 'Ë' => 'E',
+ 'Ì' => 'I',
+ 'Í' => 'I',
+ 'Î' => 'I',
+ 'Ï' => 'I',
+ 'Ð' => 'D',
+ 'Ñ' => 'N',
+ 'Ò' => 'O',
+ 'Ó' => 'O',
+ 'Ô' => 'O',
+ 'Õ' => 'O',
+ 'Ö' => 'O',
+ 'Ù' => 'U',
+ 'Ú' => 'U',
+ 'Û' => 'U',
+ 'Ü' => 'U',
+ 'Ý' => 'Y',
+ 'Þ' => 'TH',
+ 'ß' => 's',
+ 'à' => 'a',
+ 'á' => 'a',
+ 'â' => 'a',
+ 'ã' => 'a',
+ 'ä' => 'a',
+ 'å' => 'a',
+ 'æ' => 'ae',
+ 'ç' => 'c',
+ 'è' => 'e',
+ 'é' => 'e',
+ 'ê' => 'e',
+ 'ë' => 'e',
+ 'ì' => 'i',
+ 'í' => 'i',
+ 'î' => 'i',
+ 'ï' => 'i',
+ 'ð' => 'd',
+ 'ñ' => 'n',
+ 'ò' => 'o',
+ 'ó' => 'o',
+ 'ô' => 'o',
+ 'õ' => 'o',
+ 'ö' => 'o',
+ 'ø' => 'o',
+ 'ù' => 'u',
+ 'ú' => 'u',
+ 'û' => 'u',
+ 'ü' => 'u',
+ 'ý' => 'y',
+ 'þ' => 'th',
+ 'ÿ' => 'y',
+ 'Ø' => 'O',
+ // Decompositions for Latin Extended-A
+ 'Ā' => 'A',
+ 'ā' => 'a',
+ 'Ă' => 'A',
+ 'ă' => 'a',
+ 'Ą' => 'A',
+ 'ą' => 'a',
+ 'Ć' => 'C',
+ 'ć' => 'c',
+ 'Ĉ' => 'C',
+ 'ĉ' => 'c',
+ 'Ċ' => 'C',
+ 'ċ' => 'c',
+ 'Č' => 'C',
+ 'č' => 'c',
+ 'Ď' => 'D',
+ 'ď' => 'd',
+ 'Đ' => 'D',
+ 'đ' => 'd',
+ 'Ē' => 'E',
+ 'ē' => 'e',
+ 'Ĕ' => 'E',
+ 'ĕ' => 'e',
+ 'Ė' => 'E',
+ 'ė' => 'e',
+ 'Ę' => 'E',
+ 'ę' => 'e',
+ 'Ě' => 'E',
+ 'ě' => 'e',
+ 'Ĝ' => 'G',
+ 'ĝ' => 'g',
+ 'Ğ' => 'G',
+ 'ğ' => 'g',
+ 'Ġ' => 'G',
+ 'ġ' => 'g',
+ 'Ģ' => 'G',
+ 'ģ' => 'g',
+ 'Ĥ' => 'H',
+ 'ĥ' => 'h',
+ 'Ħ' => 'H',
+ 'ħ' => 'h',
+ 'Ĩ' => 'I',
+ 'ĩ' => 'i',
+ 'Ī' => 'I',
+ 'ī' => 'i',
+ 'Ĭ' => 'I',
+ 'ĭ' => 'i',
+ 'Į' => 'I',
+ 'į' => 'i',
+ 'İ' => 'I',
+ 'ı' => 'i',
+ 'IJ' => 'IJ',
+ 'ij' => 'ij',
+ 'Ĵ' => 'J',
+ 'ĵ' => 'j',
+ 'Ķ' => 'K',
+ 'ķ' => 'k',
+ 'ĸ' => 'k',
+ 'Ĺ' => 'L',
+ 'ĺ' => 'l',
+ 'Ļ' => 'L',
+ 'ļ' => 'l',
+ 'Ľ' => 'L',
+ 'ľ' => 'l',
+ 'Ŀ' => 'L',
+ 'ŀ' => 'l',
+ 'Ł' => 'L',
+ 'ł' => 'l',
+ 'Ń' => 'N',
+ 'ń' => 'n',
+ 'Ņ' => 'N',
+ 'ņ' => 'n',
+ 'Ň' => 'N',
+ 'ň' => 'n',
+ 'ʼn' => 'n',
+ 'Ŋ' => 'N',
+ 'ŋ' => 'n',
+ 'Ō' => 'O',
+ 'ō' => 'o',
+ 'Ŏ' => 'O',
+ 'ŏ' => 'o',
+ 'Ő' => 'O',
+ 'ő' => 'o',
+ 'Œ' => 'OE',
+ 'œ' => 'oe',
+ 'Ŕ' => 'R',
+ 'ŕ' => 'r',
+ 'Ŗ' => 'R',
+ 'ŗ' => 'r',
+ 'Ř' => 'R',
+ 'ř' => 'r',
+ 'Ś' => 'S',
+ 'ś' => 's',
+ 'Ŝ' => 'S',
+ 'ŝ' => 's',
+ 'Ş' => 'S',
+ 'ş' => 's',
+ 'Š' => 'S',
+ 'š' => 's',
+ 'Ţ' => 'T',
+ 'ţ' => 't',
+ 'Ť' => 'T',
+ 'ť' => 't',
+ 'Ŧ' => 'T',
+ 'ŧ' => 't',
+ 'Ũ' => 'U',
+ 'ũ' => 'u',
+ 'Ū' => 'U',
+ 'ū' => 'u',
+ 'Ŭ' => 'U',
+ 'ŭ' => 'u',
+ 'Ů' => 'U',
+ 'ů' => 'u',
+ 'Ű' => 'U',
+ 'ű' => 'u',
+ 'Ų' => 'U',
+ 'ų' => 'u',
+ 'Ŵ' => 'W',
+ 'ŵ' => 'w',
+ 'Ŷ' => 'Y',
+ 'ŷ' => 'y',
+ 'Ÿ' => 'Y',
+ 'Ź' => 'Z',
+ 'ź' => 'z',
+ 'Ż' => 'Z',
+ 'ż' => 'z',
+ 'Ž' => 'Z',
+ 'ž' => 'z',
+ 'ſ' => 's',
+ // Decompositions for Latin Extended-B
+ 'Ș' => 'S',
+ 'ș' => 's',
+ 'Ț' => 'T',
+ 'ț' => 't',
+ // Euro Sign
+ '€' => 'E',
+ // GBP (Pound) Sign
+ '£' => '',
+ // Vowels with diacritic (Vietnamese)
+ // unmarked
+ 'Ơ' => 'O',
+ 'ơ' => 'o',
+ 'Ư' => 'U',
+ 'ư' => 'u',
+ // grave accent
+ 'Ầ' => 'A',
+ 'ầ' => 'a',
+ 'Ằ' => 'A',
+ 'ằ' => 'a',
+ 'Ề' => 'E',
+ 'ề' => 'e',
+ 'Ồ' => 'O',
+ 'ồ' => 'o',
+ 'Ờ' => 'O',
+ 'ờ' => 'o',
+ 'Ừ' => 'U',
+ 'ừ' => 'u',
+ 'Ỳ' => 'Y',
+ 'ỳ' => 'y',
+ // hook
+ 'Ả' => 'A',
+ 'ả' => 'a',
+ 'Ẩ' => 'A',
+ 'ẩ' => 'a',
+ 'Ẳ' => 'A',
+ 'ẳ' => 'a',
+ 'Ẻ' => 'E',
+ 'ẻ' => 'e',
+ 'Ể' => 'E',
+ 'ể' => 'e',
+ 'Ỉ' => 'I',
+ 'ỉ' => 'i',
+ 'Ỏ' => 'O',
+ 'ỏ' => 'o',
+ 'Ổ' => 'O',
+ 'ổ' => 'o',
+ 'Ở' => 'O',
+ 'ở' => 'o',
+ 'Ủ' => 'U',
+ 'ủ' => 'u',
+ 'Ử' => 'U',
+ 'ử' => 'u',
+ 'Ỷ' => 'Y',
+ 'ỷ' => 'y',
+ // tilde
+ 'Ẫ' => 'A',
+ 'ẫ' => 'a',
+ 'Ẵ' => 'A',
+ 'ẵ' => 'a',
+ 'Ẽ' => 'E',
+ 'ẽ' => 'e',
+ 'Ễ' => 'E',
+ 'ễ' => 'e',
+ 'Ỗ' => 'O',
+ 'ỗ' => 'o',
+ 'Ỡ' => 'O',
+ 'ỡ' => 'o',
+ 'Ữ' => 'U',
+ 'ữ' => 'u',
+ 'Ỹ' => 'Y',
+ 'ỹ' => 'y',
+ // acute accent
+ 'Ấ' => 'A',
+ 'ấ' => 'a',
+ 'Ắ' => 'A',
+ 'ắ' => 'a',
+ 'Ế' => 'E',
+ 'ế' => 'e',
+ 'Ố' => 'O',
+ 'ố' => 'o',
+ 'Ớ' => 'O',
+ 'ớ' => 'o',
+ 'Ứ' => 'U',
+ 'ứ' => 'u',
+ // dot below
+ 'Ạ' => 'A',
+ 'ạ' => 'a',
+ 'Ậ' => 'A',
+ 'ậ' => 'a',
+ 'Ặ' => 'A',
+ 'ặ' => 'a',
+ 'Ẹ' => 'E',
+ 'ẹ' => 'e',
+ 'Ệ' => 'E',
+ 'ệ' => 'e',
+ 'Ị' => 'I',
+ 'ị' => 'i',
+ 'Ọ' => 'O',
+ 'ọ' => 'o',
+ 'Ộ' => 'O',
+ 'ộ' => 'o',
+ 'Ợ' => 'O',
+ 'ợ' => 'o',
+ 'Ụ' => 'U',
+ 'ụ' => 'u',
+ 'Ự' => 'U',
+ 'ự' => 'u',
+ 'Ỵ' => 'Y',
+ 'ỵ' => 'y',
+ // Vowels with diacritic (Chinese, Hanyu Pinyin)
+ 'ɑ' => 'a',
+ // macron
+ 'Ǖ' => 'U',
+ 'ǖ' => 'u',
+ // acute accent
+ 'Ǘ' => 'U',
+ 'ǘ' => 'u',
+ // caron
+ 'Ǎ' => 'A',
+ 'ǎ' => 'a',
+ 'Ǐ' => 'I',
+ 'ǐ' => 'i',
+ 'Ǒ' => 'O',
+ 'ǒ' => 'o',
+ 'Ǔ' => 'U',
+ 'ǔ' => 'u',
+ 'Ǚ' => 'U',
+ 'ǚ' => 'u',
+ // grave accent
+ 'Ǜ' => 'U',
+ 'ǜ' => 'u',
);
// Used for locale-specific rules
$locale = get_locale();
if ( 'de_DE' == $locale || 'de_DE_formal' == $locale || 'de_CH' == $locale || 'de_CH_informal' == $locale ) {
- $chars[ 'Ä' ] = 'Ae';
- $chars[ 'ä' ] = 'ae';
- $chars[ 'Ö' ] = 'Oe';
- $chars[ 'ö' ] = 'oe';
- $chars[ 'Ü' ] = 'Ue';
- $chars[ 'ü' ] = 'ue';
- $chars[ 'ß' ] = 'ss';
+ $chars['Ä'] = 'Ae';
+ $chars['ä'] = 'ae';
+ $chars['Ö'] = 'Oe';
+ $chars['ö'] = 'oe';
+ $chars['Ü'] = 'Ue';
+ $chars['ü'] = 'ue';
+ $chars['ß'] = 'ss';
} elseif ( 'da_DK' === $locale ) {
- $chars[ 'Æ' ] = 'Ae';
- $chars[ 'æ' ] = 'ae';
- $chars[ 'Ø' ] = 'Oe';
- $chars[ 'ø' ] = 'oe';
- $chars[ 'Å' ] = 'Aa';
- $chars[ 'å' ] = 'aa';
+ $chars['Æ'] = 'Ae';
+ $chars['æ'] = 'ae';
+ $chars['Ø'] = 'Oe';
+ $chars['ø'] = 'oe';
+ $chars['Å'] = 'Aa';
+ $chars['å'] = 'aa';
} elseif ( 'ca' === $locale ) {
- $chars[ 'l·l' ] = 'll';
+ $chars['l·l'] = 'll';
} elseif ( 'sr_RS' === $locale || 'bs_BA' === $locale ) {
- $chars[ 'Đ' ] = 'DJ';
- $chars[ 'đ' ] = 'dj';
+ $chars['Đ'] = 'DJ';
+ $chars['đ'] = 'dj';
}
- $string = strtr($string, $chars);
+ $string = strtr( $string, $chars );
} else {
$chars = array();
// Assume ISO-8859-1 if not UTF-8
$chars['in'] = "\x80\x83\x8a\x8e\x9a\x9e"
- ."\x9f\xa2\xa5\xb5\xc0\xc1\xc2"
- ."\xc3\xc4\xc5\xc7\xc8\xc9\xca"
- ."\xcb\xcc\xcd\xce\xcf\xd1\xd2"
- ."\xd3\xd4\xd5\xd6\xd8\xd9\xda"
- ."\xdb\xdc\xdd\xe0\xe1\xe2\xe3"
- ."\xe4\xe5\xe7\xe8\xe9\xea\xeb"
- ."\xec\xed\xee\xef\xf1\xf2\xf3"
- ."\xf4\xf5\xf6\xf8\xf9\xfa\xfb"
- ."\xfc\xfd\xff";
-
- $chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy";
-
- $string = strtr($string, $chars['in'], $chars['out']);
- $double_chars = array();
- $double_chars['in'] = array("\x8c", "\x9c", "\xc6", "\xd0", "\xde", "\xdf", "\xe6", "\xf0", "\xfe");
- $double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th');
- $string = str_replace($double_chars['in'], $double_chars['out'], $string);
+ . "\x9f\xa2\xa5\xb5\xc0\xc1\xc2"
+ . "\xc3\xc4\xc5\xc7\xc8\xc9\xca"
+ . "\xcb\xcc\xcd\xce\xcf\xd1\xd2"
+ . "\xd3\xd4\xd5\xd6\xd8\xd9\xda"
+ . "\xdb\xdc\xdd\xe0\xe1\xe2\xe3"
+ . "\xe4\xe5\xe7\xe8\xe9\xea\xeb"
+ . "\xec\xed\xee\xef\xf1\xf2\xf3"
+ . "\xf4\xf5\xf6\xf8\xf9\xfa\xfb"
+ . "\xfc\xfd\xff";
+
+ $chars['out'] = 'EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy';
+
+ $string = strtr( $string, $chars['in'], $chars['out'] );
+ $double_chars = array();
+ $double_chars['in'] = array( "\x8c", "\x9c", "\xc6", "\xd0", "\xde", "\xdf", "\xe6", "\xf0", "\xfe" );
+ $double_chars['out'] = array( 'OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th' );
+ $string = str_replace( $double_chars['in'], $double_chars['out'], $string );
}
return $string;
@@ -1774,8 +1996,8 @@
* @return string The sanitized filename
*/
function sanitize_file_name( $filename ) {
- $filename_raw = $filename;
- $special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", "%", "+", chr(0));
+ $filename_raw = $filename;
+ $special_chars = array( '?', '[', ']', '/', '\\', '=', '<', '>', ':', ';', ',', "'", '"', '&', '$', '#', '*', '(', ')', '|', '~', '`', '!', '{', '}', '%', '+', chr( 0 ) );
/**
* Filters the list of characters to remove from a filename.
*
@@ -1785,22 +2007,22 @@
* @param string $filename_raw Filename as it was passed into sanitize_file_name().
*/
$special_chars = apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw );
- $filename = preg_replace( "#\x{00a0}#siu", ' ', $filename );
- $filename = str_replace( $special_chars, '', $filename );
- $filename = str_replace( array( '%20', '+' ), '-', $filename );
- $filename = preg_replace( '/[\r\n\t -]+/', '-', $filename );
- $filename = trim( $filename, '.-_' );
+ $filename = preg_replace( "#\x{00a0}#siu", ' ', $filename );
+ $filename = str_replace( $special_chars, '', $filename );
+ $filename = str_replace( array( '%20', '+' ), '-', $filename );
+ $filename = preg_replace( '/[\r\n\t -]+/', '-', $filename );
+ $filename = trim( $filename, '.-_' );
if ( false === strpos( $filename, '.' ) ) {
$mime_types = wp_get_mime_types();
- $filetype = wp_check_filetype( 'test.' . $filename, $mime_types );
+ $filetype = wp_check_filetype( 'test.' . $filename, $mime_types );
if ( $filetype['ext'] === $filename ) {
$filename = 'unnamed-file.' . $filetype['ext'];
}
}
// Split the filename into a base and extension[s]
- $parts = explode('.', $filename);
+ $parts = explode( '.', $filename );
// Return if only one extension
if ( count( $parts ) <= 2 ) {
@@ -1816,18 +2038,18 @@
}
// Process multiple extensions
- $filename = array_shift($parts);
- $extension = array_pop($parts);
- $mimes = get_allowed_mime_types();
+ $filename = array_shift( $parts );
+ $extension = array_pop( $parts );
+ $mimes = get_allowed_mime_types();
/*
* Loop over any intermediate extensions. Postfix them with a trailing underscore
* if they are a 2 - 5 character long alpha string not in the extension whitelist.
*/
- foreach ( (array) $parts as $part) {
+ foreach ( (array) $parts as $part ) {
$filename .= '.' . $part;
- if ( preg_match("/^[a-zA-Z]{2,5}\d?$/", $part) ) {
+ if ( preg_match( '/^[a-zA-Z]{2,5}\d?$/', $part ) ) {
$allowed = false;
foreach ( $mimes as $ext_preg => $mime_match ) {
$ext_preg = '!^(' . $ext_preg . ')$!i';
@@ -1836,13 +2058,14 @@
break;
}
}
- if ( !$allowed )
+ if ( ! $allowed ) {
$filename .= '_';
+ }
}
}
$filename .= '.' . $extension;
/** This filter is documented in wp-includes/formatting.php */
- return apply_filters('sanitize_file_name', $filename, $filename_raw);
+ return apply_filters( 'sanitize_file_name', $filename, $filename_raw );
}
/**
@@ -1861,15 +2084,16 @@
*/
function sanitize_user( $username, $strict = false ) {
$raw_username = $username;
- $username = wp_strip_all_tags( $username );
- $username = remove_accents( $username );
+ $username = wp_strip_all_tags( $username );
+ $username = remove_accents( $username );
// Kill octets
$username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username );
$username = preg_replace( '/&.+?;/', '', $username ); // Kill entities
// If strict, reduce to ASCII for max portability.
- if ( $strict )
+ if ( $strict ) {
$username = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $username );
+ }
$username = trim( $username );
// Consolidate contiguous whitespace
@@ -1899,8 +2123,8 @@
*/
function sanitize_key( $key ) {
$raw_key = $key;
- $key = strtolower( $key );
- $key = preg_replace( '/[^a-z0-9_\-]/', '', $key );
+ $key = strtolower( $key );
+ $key = preg_replace( '/[^a-z0-9_\-]/', '', $key );
/**
* Filters a sanitized key string.
@@ -1930,8 +2154,9 @@
function sanitize_title( $title, $fallback_title = '', $context = 'save' ) {
$raw_title = $title;
- if ( 'save' == $context )
- $title = remove_accents($title);
+ if ( 'save' == $context ) {
+ $title = remove_accents( $title );
+ }
/**
* Filters a sanitized title string.
@@ -1944,8 +2169,9 @@
*/
$title = apply_filters( 'sanitize_title', $title, $raw_title, $context );
- if ( '' === $title || false === $title )
+ if ( '' === $title || false === $title ) {
$title = $fallback_title;
+ }
return $title;
}
@@ -1978,22 +2204,22 @@
* @return string The sanitized title.
*/
function sanitize_title_with_dashes( $title, $raw_title = '', $context = 'display' ) {
- $title = strip_tags($title);
+ $title = strip_tags( $title );
// Preserve escaped octets.
- $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
+ $title = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title );
// Remove percent signs that are not part of an octet.
- $title = str_replace('%', '', $title);
+ $title = str_replace( '%', '', $title );
// Restore octets.
- $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
-
- if (seems_utf8($title)) {
- if (function_exists('mb_strtolower')) {
- $title = mb_strtolower($title, 'UTF-8');
+ $title = preg_replace( '|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title );
+
+ if ( seems_utf8( $title ) ) {
+ if ( function_exists( 'mb_strtolower' ) ) {
+ $title = mb_strtolower( $title, 'UTF-8' );
}
- $title = utf8_uri_encode($title, 200);
+ $title = utf8_uri_encode( $title, 200 );
}
- $title = strtolower($title);
+ $title = strtolower( $title );
if ( 'save' == $context ) {
// Convert nbsp, ndash and mdash to hyphens
@@ -2004,33 +2230,58 @@
$title = str_replace( '/', '-', $title );
// Strip these characters entirely
- $title = str_replace( array(
- // iexcl and iquest
- '%c2%a1', '%c2%bf',
- // angle quotes
- '%c2%ab', '%c2%bb', '%e2%80%b9', '%e2%80%ba',
- // curly quotes
- '%e2%80%98', '%e2%80%99', '%e2%80%9c', '%e2%80%9d',
- '%e2%80%9a', '%e2%80%9b', '%e2%80%9e', '%e2%80%9f',
- // copy, reg, deg, hellip and trade
- '%c2%a9', '%c2%ae', '%c2%b0', '%e2%80%a6', '%e2%84%a2',
- // acute accents
- '%c2%b4', '%cb%8a', '%cc%81', '%cd%81',
- // grave accent, macron, caron
- '%cc%80', '%cc%84', '%cc%8c',
- ), '', $title );
+ $title = str_replace(
+ array(
+ // soft hyphens
+ '%c2%ad',
+ // iexcl and iquest
+ '%c2%a1',
+ '%c2%bf',
+ // angle quotes
+ '%c2%ab',
+ '%c2%bb',
+ '%e2%80%b9',
+ '%e2%80%ba',
+ // curly quotes
+ '%e2%80%98',
+ '%e2%80%99',
+ '%e2%80%9c',
+ '%e2%80%9d',
+ '%e2%80%9a',
+ '%e2%80%9b',
+ '%e2%80%9e',
+ '%e2%80%9f',
+ // copy, reg, deg, hellip and trade
+ '%c2%a9',
+ '%c2%ae',
+ '%c2%b0',
+ '%e2%80%a6',
+ '%e2%84%a2',
+ // acute accents
+ '%c2%b4',
+ '%cb%8a',
+ '%cc%81',
+ '%cd%81',
+ // grave accent, macron, caron
+ '%cc%80',
+ '%cc%84',
+ '%cc%8c',
+ ),
+ '',
+ $title
+ );
// Convert times to x
$title = str_replace( '%c3%97', 'x', $title );
}
- $title = preg_replace('/&.+?;/', '', $title); // kill entities
- $title = str_replace('.', '-', $title);
-
- $title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
- $title = preg_replace('/\s+/', '-', $title);
- $title = preg_replace('|-+|', '-', $title);
- $title = trim($title, '-');
+ $title = preg_replace( '/&.+?;/', '', $title ); // kill entities
+ $title = str_replace( '.', '-', $title );
+
+ $title = preg_replace( '/[^%a-z0-9 _-]/', '', $title );
+ $title = preg_replace( '/\s+/', '-', $title );
+ $title = preg_replace( '|-+|', '-', $title );
+ $title = trim( $title, '-' );
return $title;
}
@@ -2067,7 +2318,7 @@
*
* @param string $class The classname to be sanitized
* @param string $fallback Optional. The value to return if the sanitization ends up as an empty string.
- * Defaults to an empty string.
+ * Defaults to an empty string.
* @return string The sanitized value
*/
function sanitize_html_class( $class, $fallback = '' ) {
@@ -2154,7 +2405,7 @@
'' => 'œ',
'' => '',
'' => 'ž',
- '' => 'Ÿ'
+ '' => 'Ÿ',
);
if ( strpos( $content, '' ) !== false ) {
@@ -2174,7 +2425,7 @@
* @return string Balanced text
*/
function balanceTags( $text, $force = false ) {
- if ( $force || get_option('use_balanceTags') == 1 ) {
+ if ( $force || get_option( 'use_balanceTags' ) == 1 ) {
return force_balance_tags( $text );
} else {
return $text;
@@ -2192,55 +2443,55 @@
* @version 1.1
* @todo Make better - change loop condition to $text in 1.2
* @internal Modified by Scott Reilly (coffee2code) 02 Aug 2004
- * 1.1 Fixed handling of append/stack pop order of end text
- * Added Cleaning Hooks
- * 1.0 First Version
+ * 1.1 Fixed handling of append/stack pop order of end text
+ * Added Cleaning Hooks
+ * 1.0 First Version
*
* @param string $text Text to be balanced.
* @return string Balanced text.
*/
function force_balance_tags( $text ) {
- $tagstack = array();
+ $tagstack = array();
$stacksize = 0;
- $tagqueue = '';
- $newtext = '';
+ $tagqueue = '';
+ $newtext = '';
// Known single-entity/self-closing tags
$single_tags = array( 'area', 'base', 'basefont', 'br', 'col', 'command', 'embed', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param', 'source' );
// Tags that can be immediately nested within themselves
$nestable_tags = array( 'blockquote', 'div', 'object', 'q', 'span' );
// WP bug fix for comments - in case you REALLY meant to type '< !--'
- $text = str_replace('< !--', '< !--', $text);
+ $text = str_replace( '< !--', '< !--', $text );
// WP bug fix for LOVE <3 (and other situations with '<' before a number)
- $text = preg_replace('#<([0-9]{1})#', '<$1', $text);
-
- while ( preg_match("/<(\/?[\w:]*)\s*([^>]*)>/", $text, $regex) ) {
+ $text = preg_replace( '#<([0-9]{1})#', '<$1', $text );
+
+ while ( preg_match( '/<(\/?[\w:]*)\s*([^>]*)>/', $text, $regex ) ) {
$newtext .= $tagqueue;
- $i = strpos($text, $regex[0]);
- $l = strlen($regex[0]);
+ $i = strpos( $text, $regex[0] );
+ $l = strlen( $regex[0] );
// clear the shifter
$tagqueue = '';
// Pop or Push
- if ( isset($regex[1][0]) && '/' == $regex[1][0] ) { // End Tag
- $tag = strtolower(substr($regex[1],1));
+ if ( isset( $regex[1][0] ) && '/' == $regex[1][0] ) { // End Tag
+ $tag = strtolower( substr( $regex[1], 1 ) );
// if too many closing tags
if ( $stacksize <= 0 ) {
$tag = '';
// or close to be safe $tag = '/' . $tag;
- }
- // if stacktop value = tag close value then pop
- elseif ( $tagstack[$stacksize - 1] == $tag ) { // found closing tag
+
+ // if stacktop value = tag close value then pop
+ } elseif ( $tagstack[ $stacksize - 1 ] == $tag ) { // found closing tag
$tag = '' . $tag . '>'; // Close Tag
// Pop
array_pop( $tagstack );
$stacksize--;
} else { // closing tag not at top, search for it
- for ( $j = $stacksize-1; $j >= 0; $j-- ) {
- if ( $tagstack[$j] == $tag ) {
- // add tag to tagqueue
- for ( $k = $stacksize-1; $k >= $j; $k--) {
+ for ( $j = $stacksize - 1; $j >= 0; $j-- ) {
+ if ( $tagstack[ $j ] == $tag ) {
+ // add tag to tagqueue
+ for ( $k = $stacksize - 1; $k >= $j; $k-- ) {
$tagqueue .= '' . array_pop( $tagstack ) . '>';
$stacksize--;
}
@@ -2250,29 +2501,24 @@
$tag = '';
}
} else { // Begin Tag
- $tag = strtolower($regex[1]);
+ $tag = strtolower( $regex[1] );
// Tag Cleaning
// If it's an empty tag "< >", do nothing
if ( '' == $tag ) {
// do nothing
- }
- // ElseIf it presents itself as a self-closing tag...
- elseif ( substr( $regex[2], -1 ) == '/' ) {
+ } elseif ( substr( $regex[2], -1 ) == '/' ) { // ElseIf it presents itself as a self-closing tag...
// ...but it isn't a known single-entity self-closing tag, then don't let it be treated as such and
// immediately close it with a closing tag (the tag will encapsulate no text as a result)
- if ( ! in_array( $tag, $single_tags ) )
+ if ( ! in_array( $tag, $single_tags ) ) {
$regex[2] = trim( substr( $regex[2], 0, -1 ) ) . ">$tag";
- }
- // ElseIf it's a known single-entity tag but it doesn't close itself, do so
- elseif ( in_array($tag, $single_tags) ) {
+ }
+ } elseif ( in_array( $tag, $single_tags ) ) { // ElseIf it's a known single-entity tag but it doesn't close itself, do so
$regex[2] .= '/';
- }
- // Else it's not a single-entity tag
- else {
+ } else { // Else it's not a single-entity tag
// If the top of the stack is the same as the tag we want to push, close previous tag
- if ( $stacksize > 0 && !in_array($tag, $nestable_tags) && $tagstack[$stacksize - 1] == $tag ) {
+ if ( $stacksize > 0 && ! in_array( $tag, $nestable_tags ) && $tagstack[ $stacksize - 1 ] == $tag ) {
$tagqueue = '' . array_pop( $tagstack ) . '>';
$stacksize--;
}
@@ -2281,18 +2527,19 @@
// Attributes
$attributes = $regex[2];
- if ( ! empty( $attributes ) && $attributes[0] != '>' )
+ if ( ! empty( $attributes ) && $attributes[0] != '>' ) {
$attributes = ' ' . $attributes;
+ }
$tag = '<' . $tag . $attributes . '>';
//If already queuing a close tag, then put this tag on, too
- if ( !empty($tagqueue) ) {
+ if ( ! empty( $tagqueue ) ) {
$tagqueue .= $tag;
- $tag = '';
+ $tag = '';
}
}
- $newtext .= substr($text, 0, $i) . $tag;
- $text = substr($text, $i + $l);
+ $newtext .= substr( $text, 0, $i ) . $tag;
+ $text = substr( $text, $i + $l );
}
// Clear Tag Queue
@@ -2302,12 +2549,13 @@
$newtext .= $text;
// Empty Stack
- while( $x = array_pop($tagstack) )
+ while ( $x = array_pop( $tagstack ) ) {
$newtext .= '' . $x . '>'; // Add remaining tags to close
+ }
// WP fix for the bug with HTML comments
- $newtext = str_replace("< !--","