[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 // Last sync [WP12504] 3 4 /** 5 * From WP wp-includes/formatting.php 6 * 7 * Missing functions are indicated in comments 8 */ 9 10 /** 11 * Main BackPress Formatting API. 12 * 13 * Handles many functions for formatting output. 14 * 15 * @package BackPress 16 **/ 17 18 if ( !function_exists( 'wptexturize' ) ) : 19 /** 20 * Replaces common plain text characters into formatted entities 21 * 22 * As an example, 23 * <code> 24 * 'cause today's effort makes it worth tomorrow's "holiday"... 25 * </code> 26 * Becomes: 27 * <code> 28 * ’cause today’s effort makes it worth tomorrow’s “holiday”… 29 * </code> 30 * Code within certain html blocks are skipped. 31 * 32 * @since 0.71 33 * @uses $wp_cockneyreplace Array of formatted entities for certain common phrases 34 * 35 * @param string $text The text to be formatted 36 * @return string The string replaced with html entities 37 */ 38 function wptexturize($text) { 39 global $wp_cockneyreplace; 40 static $static_setup = false, $opening_quote, $closing_quote, $default_no_texturize_tags, $default_no_texturize_shortcodes, $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements; 41 $output = ''; 42 $curl = ''; 43 $textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE); 44 $stop = count($textarr); 45 46 // No need to setup these variables more than once 47 if (!$static_setup) { 48 /* translators: opening curly quote */ 49 $opening_quote = _x('“', 'opening curly quote'); 50 /* translators: closing curly quote */ 51 $closing_quote = _x('”', 'closing curly quote'); 52 53 $default_no_texturize_tags = array('pre', 'code', 'kbd', 'style', 'script', 'tt'); 54 $default_no_texturize_shortcodes = array('code'); 55 56 // if a plugin has provided an autocorrect array, use it 57 if ( isset($wp_cockneyreplace) ) { 58 $cockney = array_keys($wp_cockneyreplace); 59 $cockneyreplace = array_values($wp_cockneyreplace); 60 } else { 61 $cockney = array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round","'cause"); 62 $cockneyreplace = array("’tain’t","’twere","’twas","’tis","’twill","’til","’bout","’nuff","’round","’cause"); 63 } 64 65 $static_characters = array_merge(array('---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'s', '\'\'', ' (tm)'), $cockney); 66 $static_replacements = array_merge(array('—', ' — ', '–', ' – ', 'xn--', '…', $opening_quote, '’s', $closing_quote, ' ™'), $cockneyreplace); 67 68 $dynamic_characters = array('/\'(\d\d(?:’|\')?s)/', '/(\s|\A|[([{<]|")\'/', '/(\d+)"/', '/(\d+)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A|[([{<])"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/(\d+)x(\d+)/'); 69 $dynamic_replacements = array('’$1','$1‘', '$1″', '$1′', '$1’$2', '$1' . $opening_quote . '$2', $closing_quote . '$1', '’$1', '$1×$2'); 70 71 $static_setup = true; 72 } 73 74 // Transform into regexp sub-expression used in _wptexturize_pushpop_element 75 // Must do this everytime in case plugins use these filters in a context sensitive manner 76 $no_texturize_tags = '(' . implode('|', apply_filters('no_texturize_tags', $default_no_texturize_tags) ) . ')'; 77 $no_texturize_shortcodes = '(' . implode('|', apply_filters('no_texturize_shortcodes', $default_no_texturize_shortcodes) ) . ')'; 78 79 $no_texturize_tags_stack = array(); 80 $no_texturize_shortcodes_stack = array(); 81 82 for ( $i = 0; $i < $stop; $i++ ) { 83 $curl = $textarr[$i]; 84 85 if ( !empty($curl) && '<' != $curl{0} && '[' != $curl{0} 86 && empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack)) { 87 // This is not a tag, nor is the texturization disabled 88 // static strings 89 $curl = str_replace($static_characters, $static_replacements, $curl); 90 // regular expressions 91 $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl); 92 } elseif (!empty($curl)) { 93 /* 94 * Only call _wptexturize_pushpop_element if first char is correct 95 * tag opening 96 */ 97 if ('<' == $curl{0}) 98 _wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>'); 99 elseif ('[' == $curl{0}) 100 _wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']'); 101 } 102 103 $curl = preg_replace('/&([^#])(?![a-zA-Z1-4]{1,8};)/', '&$1', $curl); 104 $output .= $curl; 105 } 106 107 return $output; 108 } 109 endif; 110 111 if ( !function_exists( '_wptexturize_pushpop_element' ) ) : 112 /** 113 * Search for disabled element tags. Push element to stack on tag open and pop 114 * on tag close. Assumes first character of $text is tag opening. 115 * 116 * @access private 117 * @since 2.9.0 118 * 119 * @param string $text Text to check. First character is assumed to be $opening 120 * @param array $stack Array used as stack of opened tag elements 121 * @param string $disabled_elements Tags to match against formatted as regexp sub-expression 122 * @param string $opening Tag opening character, assumed to be 1 character long 123 * @param string $opening Tag closing character 124 * @return object 125 */ 126 function _wptexturize_pushpop_element($text, &$stack, $disabled_elements, $opening = '<', $closing = '>') { 127 // Check if it is a closing tag -- otherwise assume opening tag 128 if (strncmp($opening . '/', $text, 2)) { 129 // Opening? Check $text+1 against disabled elements 130 if (preg_match('/^' . $disabled_elements . '\b/', substr($text, 1), $matches)) { 131 /* 132 * This disables texturize until we find a closing tag of our type 133 * (e.g. <pre>) even if there was invalid nesting before that 134 * 135 * Example: in the case <pre>sadsadasd</code>"baba"</pre> 136 * "baba" won't be texturize 137 */ 138 139 array_push($stack, $matches[1]); 140 } 141 } else { 142 // Closing? Check $text+2 against disabled elements 143 $c = preg_quote($closing, '/'); 144 if (preg_match('/^' . $disabled_elements . $c . '/', substr($text, 2), $matches)) { 145 $last = array_pop($stack); 146 147 // Make sure it matches the opening tag 148 if ($last != $matches[1]) 149 array_push($stack, $last); 150 } 151 } 152 } 153 endif; 154 155 if ( !function_exists( 'clean_pre' ) ) : 156 /** 157 * Accepts matches array from preg_replace_callback in wpautop() or a string. 158 * 159 * Ensures that the contents of a <<pre>>...<</pre>> HTML block are not 160 * converted into paragraphs or line-breaks. 161 * 162 * @since 1.2.0 163 * 164 * @param array|string $matches The array or string 165 * @return string The pre block without paragraph/line-break conversion. 166 */ 167 function clean_pre($matches) { 168 if ( is_array($matches) ) 169 $text = $matches[1] . $matches[2] . "</pre>"; 170 else 171 $text = $matches; 172 173 $text = str_replace('<br />', '', $text); 174 $text = str_replace('<p>', "\n", $text); 175 $text = str_replace('</p>', '', $text); 176 177 return $text; 178 } 179 endif; 180 181 // ! function wpautop() 182 183 if ( !function_exists('seems_utf8') ) : 184 /** 185 * Checks to see if a string is utf8 encoded. 186 * 187 * NOTE: This function checks for 5-Byte sequences, UTF8 188 * has Bytes Sequences with a maximum length of 4. 189 * 190 * @author bmorel at ssi dot fr (modified) 191 * @since 1.2.1 192 * 193 * @param string $str The string to be checked 194 * @return bool True if $str fits a UTF-8 model, false otherwise. 195 */ 196 function seems_utf8($str) { 197 $length = strlen($str); 198 for ($i=0; $i < $length; $i++) { 199 $c = ord($str[$i]); 200 if ($c < 0x80) $n = 0; # 0bbbbbbb 201 elseif (($c & 0xE0) == 0xC0) $n=1; # 110bbbbb 202 elseif (($c & 0xF0) == 0xE0) $n=2; # 1110bbbb 203 elseif (($c & 0xF8) == 0xF0) $n=3; # 11110bbb 204 elseif (($c & 0xFC) == 0xF8) $n=4; # 111110bb 205 elseif (($c & 0xFE) == 0xFC) $n=5; # 1111110b 206 else return false; # Does not match any model 207 for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? 208 if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80)) 209 return false; 210 } 211 } 212 return true; 213 } 214 endif; 215 216 217 218 if ( !function_exists('_wp_specialchars') ) : 219 /** 220 * Converts a number of special characters into their HTML entities. 221 * 222 * Specifically deals with: &, <, >, ", and '. 223 * 224 * $quote_style can be set to ENT_COMPAT to encode " to 225 * ", or ENT_QUOTES to do both. Default is ENT_NOQUOTES where no quotes are encoded. 226 * 227 * @since 1.2.2 228 * 229 * @param string $string The text which is to be encoded. 230 * @param mixed $quote_style Optional. Converts double quotes if set to ENT_COMPAT, both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES. Also compatible with old values; converting single quotes if set to 'single', double if set to 'double' or both if otherwise set. Default is ENT_NOQUOTES. 231 * @param string $charset Optional. The character encoding of the string. Default is false. 232 * @param boolean $double_encode Optional. Whether or not to encode existing html entities. Default is false. 233 * @return string The encoded text with HTML entities. 234 */ 235 function _wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) { 236 $string = (string) $string; 237 238 if ( 0 === strlen( $string ) ) { 239 return ''; 240 } 241 242 // Don't bother if there are no specialchars - saves some processing 243 if ( !preg_match( '/[&<>"\']/', $string ) ) { 244 return $string; 245 } 246 247 // Account for the previous behaviour of the function when the $quote_style is not an accepted value 248 if ( empty( $quote_style ) ) { 249 $quote_style = ENT_NOQUOTES; 250 } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) { 251 $quote_style = ENT_QUOTES; 252 } 253 254 // Store the site charset as a static to avoid multiple calls to backpress_get_option() 255 if ( !$charset ) { 256 static $_charset; 257 if ( !isset( $_charset ) ) { 258 $_charset = backpress_get_option( 'charset' ); 259 } 260 $charset = $_charset; 261 } 262 if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) ) { 263 $charset = 'UTF-8'; 264 } 265 266 $_quote_style = $quote_style; 267 268 if ( $quote_style === 'double' ) { 269 $quote_style = ENT_COMPAT; 270 $_quote_style = ENT_COMPAT; 271 } elseif ( $quote_style === 'single' ) { 272 $quote_style = ENT_NOQUOTES; 273 } 274 275 // Handle double encoding ourselves 276 if ( !$double_encode ) { 277 $string = wp_specialchars_decode( $string, $_quote_style ); 278 $string = preg_replace( '/&(#?x?[0-9a-z]+);/i', '|wp_entity|$1|/wp_entity|', $string ); 279 } 280 281 $string = @htmlspecialchars( $string, $quote_style, $charset ); 282 283 // Handle double encoding ourselves 284 if ( !$double_encode ) { 285 $string = str_replace( array( '|wp_entity|', '|/wp_entity|' ), array( '&', ';' ), $string ); 286 } 287 288 // Backwards compatibility 289 if ( 'single' === $_quote_style ) { 290 $string = str_replace( "'", ''', $string ); 291 } 292 293 return $string; 294 } 295 endif; 296 297 if ( !function_exists( 'wp_specialchars_decode' ) ) : 298 /** 299 * Converts a number of HTML entities into their special characters. 300 * 301 * Specifically deals with: &, <, >, ", and '. 302 * 303 * $quote_style can be set to ENT_COMPAT to decode " entities, 304 * or ENT_QUOTES to do both " and '. Default is ENT_NOQUOTES where no quotes are decoded. 305 * 306 * @since 2.8 307 * 308 * @param string $string The text which is to be decoded. 309 * @param mixed $quote_style Optional. Converts double quotes if set to ENT_COMPAT, both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES. Also compatible with old _wp_specialchars() values; converting single quotes if set to 'single', double if set to 'double' or both if otherwise set. Default is ENT_NOQUOTES. 310 * @return string The decoded text without HTML entities. 311 */ 312 function wp_specialchars_decode( $string, $quote_style = ENT_NOQUOTES ) { 313 $string = (string) $string; 314 315 if ( 0 === strlen( $string ) ) { 316 return ''; 317 } 318 319 // Don't bother if there are no entities - saves a lot of processing 320 if ( strpos( $string, '&' ) === false ) { 321 return $string; 322 } 323 324 // Match the previous behaviour of _wp_specialchars() when the $quote_style is not an accepted value 325 if ( empty( $quote_style ) ) { 326 $quote_style = ENT_NOQUOTES; 327 } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) { 328 $quote_style = ENT_QUOTES; 329 } 330 331 // More complete than get_html_translation_table( HTML_SPECIALCHARS ) 332 $single = array( ''' => '\'', ''' => '\'' ); 333 $single_preg = array( '/�*39;/' => ''', '/�*27;/i' => ''' ); 334 $double = array( '"' => '"', '"' => '"', '"' => '"' ); 335 $double_preg = array( '/�*34;/' => '"', '/�*22;/i' => '"' ); 336 $others = array( '<' => '<', '<' => '<', '>' => '>', '>' => '>', '&' => '&', '&' => '&', '&' => '&' ); 337 $others_preg = array( '/�*60;/' => '<', '/�*62;/' => '>', '/�*38;/' => '&', '/�*26;/i' => '&' ); 338 339 if ( $quote_style === ENT_QUOTES ) { 340 $translation = array_merge( $single, $double, $others ); 341 $translation_preg = array_merge( $single_preg, $double_preg, $others_preg ); 342 } elseif ( $quote_style === ENT_COMPAT || $quote_style === 'double' ) { 343 $translation = array_merge( $double, $others ); 344 $translation_preg = array_merge( $double_preg, $others_preg ); 345 } elseif ( $quote_style === 'single' ) { 346 $translation = array_merge( $single, $others ); 347 $translation_preg = array_merge( $single_preg, $others_preg ); 348 } elseif ( $quote_style === ENT_NOQUOTES ) { 349 $translation = $others; 350 $translation_preg = $others_preg; 351 } 352 353 // Remove zero padding on numeric entities 354 $string = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $string ); 355 356 // Replace characters according to translation table 357 return strtr( $string, $translation ); 358 } 359 endif; 360 361 if ( !function_exists( 'wp_check_invalid_utf8' ) ) : 362 /** 363 * Checks for invalid UTF8 in a string. 364 * 365 * @since 2.8 366 * 367 * @param string $string The text which is to be checked. 368 * @param boolean $strip Optional. Whether to attempt to strip out invalid UTF8. Default is false. 369 * @return string The checked text. 370 */ 371 function wp_check_invalid_utf8( $string, $strip = false ) { 372 $string = (string) $string; 373 374 if ( 0 === strlen( $string ) ) { 375 return ''; 376 } 377 378 // Store the site charset as a static to avoid multiple calls to backpress_get_option() 379 static $is_utf8; 380 if ( !isset( $is_utf8 ) ) { 381 $is_utf8 = in_array( backpress_get_option( 'charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ); 382 } 383 if ( !$is_utf8 ) { 384 return $string; 385 } 386 387 // Check for support for utf8 in the installed PCRE library once and store the result in a static 388 static $utf8_pcre; 389 if ( !isset( $utf8_pcre ) ) { 390 $utf8_pcre = @preg_match( '/^./u', 'a' ); 391 } 392 // We can't demand utf8 in the PCRE installation, so just return the string in those cases 393 if ( !$utf8_pcre ) { 394 return $string; 395 } 396 397 // preg_match fails when it encounters invalid UTF8 in $string 398 if ( 1 === @preg_match( '/^./us', $string ) ) { 399 return $string; 400 } 401 402 // Attempt to strip the bad chars if requested (not recommended) 403 if ( $strip && function_exists( 'iconv' ) ) { 404 return iconv( 'utf-8', 'utf-8', $string ); 405 } 406 407 return ''; 408 } 409 endif; 410 411 if ( !function_exists('utf8_uri_encode') ) : 412 /** 413 * Encode the Unicode values to be used in the URI. 414 * 415 * @since 1.5.0 416 * 417 * @param string $utf8_string 418 * @param int $length Max length of the string 419 * @return string String with Unicode encoded for URI. 420 */ 421 function utf8_uri_encode( $utf8_string, $length = 0 ) { 422 $unicode = ''; 423 $values = array(); 424 $num_octets = 1; 425 $unicode_length = 0; 426 427 $string_length = strlen( $utf8_string ); 428 for ($i = 0; $i < $string_length; $i++ ) { 429 430 $value = ord( $utf8_string[ $i ] ); 431 432 if ( $value < 128 ) { 433 if ( $length && ( $unicode_length >= $length ) ) 434 break; 435 $unicode .= chr($value); 436 $unicode_length++; 437 } else { 438 if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3; 439 440 $values[] = $value; 441 442 if ( $length && ( $unicode_length + ($num_octets * 3) ) > $length ) 443 break; 444 if ( count( $values ) == $num_octets ) { 445 if ($num_octets == 3) { 446 $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]); 447 $unicode_length += 9; 448 } else { 449 $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]); 450 $unicode_length += 6; 451 } 452 453 $values = array(); 454 $num_octets = 1; 455 } 456 } 457 } 458 459 return $unicode; 460 } 461 endif; 462 463 if ( !function_exists('remove_accents') ) : 464 /** 465 * Converts all accent characters to ASCII characters. 466 * 467 * If there are no accent characters, then the string given is just returned. 468 * 469 * @since 1.2.1 470 * 471 * @param string $string Text that might have accent characters 472 * @return string Filtered string with replaced "nice" characters. 473 */ 474 function remove_accents($string) { 475 if ( !preg_match('/[\x80-\xff]/', $string) ) 476 return $string; 477 478 if (seems_utf8($string)) { 479 $chars = array( 480 // Decompositions for Latin-1 Supplement 481 chr(195).chr(128) => 'A', chr(195).chr(129) => 'A', 482 chr(195).chr(130) => 'A', chr(195).chr(131) => 'A', 483 chr(195).chr(132) => 'A', chr(195).chr(133) => 'A', 484 chr(195).chr(135) => 'C', chr(195).chr(136) => 'E', 485 chr(195).chr(137) => 'E', chr(195).chr(138) => 'E', 486 chr(195).chr(139) => 'E', chr(195).chr(140) => 'I', 487 chr(195).chr(141) => 'I', chr(195).chr(142) => 'I', 488 chr(195).chr(143) => 'I', chr(195).chr(145) => 'N', 489 chr(195).chr(146) => 'O', chr(195).chr(147) => 'O', 490 chr(195).chr(148) => 'O', chr(195).chr(149) => 'O', 491 chr(195).chr(150) => 'O', chr(195).chr(153) => 'U', 492 chr(195).chr(154) => 'U', chr(195).chr(155) => 'U', 493 chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y', 494 chr(195).chr(159) => 's', chr(195).chr(160) => 'a', 495 chr(195).chr(161) => 'a', chr(195).chr(162) => 'a', 496 chr(195).chr(163) => 'a', chr(195).chr(164) => 'a', 497 chr(195).chr(165) => 'a', chr(195).chr(167) => 'c', 498 chr(195).chr(168) => 'e', chr(195).chr(169) => 'e', 499 chr(195).chr(170) => 'e', chr(195).chr(171) => 'e', 500 chr(195).chr(172) => 'i', chr(195).chr(173) => 'i', 501 chr(195).chr(174) => 'i', chr(195).chr(175) => 'i', 502 chr(195).chr(177) => 'n', chr(195).chr(178) => 'o', 503 chr(195).chr(179) => 'o', chr(195).chr(180) => 'o', 504 chr(195).chr(181) => 'o', chr(195).chr(182) => 'o', 505 chr(195).chr(182) => 'o', chr(195).chr(185) => 'u', 506 chr(195).chr(186) => 'u', chr(195).chr(187) => 'u', 507 chr(195).chr(188) => 'u', chr(195).chr(189) => 'y', 508 chr(195).chr(191) => 'y', 509 // Decompositions for Latin Extended-A 510 chr(196).chr(128) => 'A', chr(196).chr(129) => 'a', 511 chr(196).chr(130) => 'A', chr(196).chr(131) => 'a', 512 chr(196).chr(132) => 'A', chr(196).chr(133) => 'a', 513 chr(196).chr(134) => 'C', chr(196).chr(135) => 'c', 514 chr(196).chr(136) => 'C', chr(196).chr(137) => 'c', 515 chr(196).chr(138) => 'C', chr(196).chr(139) => 'c', 516 chr(196).chr(140) => 'C', chr(196).chr(141) => 'c', 517 chr(196).chr(142) => 'D', chr(196).chr(143) => 'd', 518 chr(196).chr(144) => 'D', chr(196).chr(145) => 'd', 519 chr(196).chr(146) => 'E', chr(196).chr(147) => 'e', 520 chr(196).chr(148) => 'E', chr(196).chr(149) => 'e', 521 chr(196).chr(150) => 'E', chr(196).chr(151) => 'e', 522 chr(196).chr(152) => 'E', chr(196).chr(153) => 'e', 523 chr(196).chr(154) => 'E', chr(196).chr(155) => 'e', 524 chr(196).chr(156) => 'G', chr(196).chr(157) => 'g', 525 chr(196).chr(158) => 'G', chr(196).chr(159) => 'g', 526 chr(196).chr(160) => 'G', chr(196).chr(161) => 'g', 527 chr(196).chr(162) => 'G', chr(196).chr(163) => 'g', 528 chr(196).chr(164) => 'H', chr(196).chr(165) => 'h', 529 chr(196).chr(166) => 'H', chr(196).chr(167) => 'h', 530 chr(196).chr(168) => 'I', chr(196).chr(169) => 'i', 531 chr(196).chr(170) => 'I', chr(196).chr(171) => 'i', 532 chr(196).chr(172) => 'I', chr(196).chr(173) => 'i', 533 chr(196).chr(174) => 'I', chr(196).chr(175) => 'i', 534 chr(196).chr(176) => 'I', chr(196).chr(177) => 'i', 535 chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij', 536 chr(196).chr(180) => 'J', chr(196).chr(181) => 'j', 537 chr(196).chr(182) => 'K', chr(196).chr(183) => 'k', 538 chr(196).chr(184) => 'k', chr(196).chr(185) => 'L', 539 chr(196).chr(186) => 'l', chr(196).chr(187) => 'L', 540 chr(196).chr(188) => 'l', chr(196).chr(189) => 'L', 541 chr(196).chr(190) => 'l', chr(196).chr(191) => 'L', 542 chr(197).chr(128) => 'l', chr(197).chr(129) => 'L', 543 chr(197).chr(130) => 'l', chr(197).chr(131) => 'N', 544 chr(197).chr(132) => 'n', chr(197).chr(133) => 'N', 545 chr(197).chr(134) => 'n', chr(197).chr(135) => 'N', 546 chr(197).chr(136) => 'n', chr(197).chr(137) => 'N', 547 chr(197).chr(138) => 'n', chr(197).chr(139) => 'N', 548 chr(197).chr(140) => 'O', chr(197).chr(141) => 'o', 549 chr(197).chr(142) => 'O', chr(197).chr(143) => 'o', 550 chr(197).chr(144) => 'O', chr(197).chr(145) => 'o', 551 chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe', 552 chr(197).chr(148) => 'R',chr(197).chr(149) => 'r', 553 chr(197).chr(150) => 'R',chr(197).chr(151) => 'r', 554 chr(197).chr(152) => 'R',chr(197).chr(153) => 'r', 555 chr(197).chr(154) => 'S',chr(197).chr(155) => 's', 556 chr(197).chr(156) => 'S',chr(197).chr(157) => 's', 557 chr(197).chr(158) => 'S',chr(197).chr(159) => 's', 558 chr(197).chr(160) => 'S', chr(197).chr(161) => 's', 559 chr(197).chr(162) => 'T', chr(197).chr(163) => 't', 560 chr(197).chr(164) => 'T', chr(197).chr(165) => 't', 561 chr(197).chr(166) => 'T', chr(197).chr(167) => 't', 562 chr(197).chr(168) => 'U', chr(197).chr(169) => 'u', 563 chr(197).chr(170) => 'U', chr(197).chr(171) => 'u', 564 chr(197).chr(172) => 'U', chr(197).chr(173) => 'u', 565 chr(197).chr(174) => 'U', chr(197).chr(175) => 'u', 566 chr(197).chr(176) => 'U', chr(197).chr(177) => 'u', 567 chr(197).chr(178) => 'U', chr(197).chr(179) => 'u', 568 chr(197).chr(180) => 'W', chr(197).chr(181) => 'w', 569 chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y', 570 chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z', 571 chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z', 572 chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z', 573 chr(197).chr(190) => 'z', chr(197).chr(191) => 's', 574 // Euro Sign 575 chr(226).chr(130).chr(172) => 'E', 576 // GBP (Pound) Sign 577 chr(194).chr(163) => ''); 578 579 $string = strtr($string, $chars); 580 } else { 581 // Assume ISO-8859-1 if not UTF-8 582 $chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158) 583 .chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194) 584 .chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202) 585 .chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210) 586 .chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218) 587 .chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227) 588 .chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235) 589 .chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243) 590 .chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251) 591 .chr(252).chr(253).chr(255); 592 593 $chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy"; 594 595 $string = strtr($string, $chars['in'], $chars['out']); 596 $double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254)); 597 $double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th'); 598 $string = str_replace($double_chars['in'], $double_chars['out'], $string); 599 } 600 601 return $string; 602 } 603 endif; 604 605 // ! function sanitize_file_name() 606 607 if ( !function_exists('sanitize_user') ) : 608 /** 609 * Sanitize username stripping out unsafe characters. 610 * 611 * If $strict is true, only alphanumeric characters (as well as _, space, ., -, 612 * @) are returned. 613 * Removes tags, octets, entities, and if strict is enabled, will remove all 614 * non-ASCII characters. After sanitizing, it passes the username, raw username 615 * (the username in the parameter), and the strict parameter as parameters for 616 * the filter. 617 * 618 * @since 2.0.0 619 * @uses apply_filters() Calls 'sanitize_user' hook on username, raw username, 620 * and $strict parameter. 621 * 622 * @param string $username The username to be sanitized. 623 * @param bool $strict If set limits $username to specific characters. Default false. 624 * @return string The sanitized username, after passing through filters. 625 */ 626 function sanitize_user( $username, $strict = false ) { 627 $raw_username = $username; 628 $username = wp_strip_all_tags($username); 629 // Kill octets 630 $username = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '', $username); 631 $username = preg_replace('/&.+?;/', '', $username); // Kill entities 632 633 // If strict, reduce to ASCII for max portability. 634 if ( $strict ) 635 $username = preg_replace('|[^a-z0-9 _.\-@]|i', '', $username); 636 637 // Consolidate contiguous whitespace 638 $username = preg_replace('|\s+|', ' ', $username); 639 640 return apply_filters('sanitize_user', $username, $raw_username, $strict); 641 } 642 endif; 643 644 if ( !function_exists('sanitize_title') ) : 645 /** 646 * Sanitizes title or use fallback title. 647 * 648 * Specifically, HTML and PHP tags are stripped. Further actions can be added 649 * via the plugin API. If $title is empty and $fallback_title is set, the latter 650 * will be used. 651 * 652 * @since 1.0.0 653 * 654 * @param string $title The string to be sanitized. 655 * @param string $fallback_title Optional. A title to use if $title is empty. 656 * @return string The sanitized string. 657 */ 658 function sanitize_title($title, $fallback_title = '') { 659 $raw_title = $title; 660 $title = strip_tags($title); 661 $title = apply_filters('sanitize_title', $title, $raw_title); 662 663 if ( '' === $title || false === $title ) 664 $title = $fallback_title; 665 666 return $title; 667 } 668 endif; 669 670 if ( !function_exists('sanitize_title_with_dashes') ) : 671 /** 672 * Sanitizes title, replacing whitespace with dashes. 673 * 674 * Limits the output to alphanumeric characters, underscore (_) and dash (-). 675 * Whitespace becomes a dash. 676 * 677 * @since 1.2.0 678 * 679 * @param string $title The title to be sanitized. 680 * @return string The sanitized title. 681 */ 682 function sanitize_title_with_dashes($title) { 683 $title = strip_tags($title); 684 // Preserve escaped octets. 685 $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title); 686 // Remove percent signs that are not part of an octet. 687 $title = str_replace('%', '', $title); 688 // Restore octets. 689 $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title); 690 691 $title = remove_accents($title); 692 if (seems_utf8($title)) { 693 if (function_exists('mb_strtolower')) { 694 $title = mb_strtolower($title, 'UTF-8'); 695 } 696 $title = utf8_uri_encode($title, 200); 697 } 698 699 $title = strtolower($title); 700 $title = preg_replace('/&.+?;/', '', $title); // kill entities 701 $title = str_replace('.', '-', $title); 702 $title = preg_replace('/[^%a-z0-9 _-]/', '', $title); 703 $title = preg_replace('/\s+/', '-', $title); 704 $title = preg_replace('|-+|', '-', $title); 705 $title = trim($title, '-'); 706 707 return $title; 708 } 709 endif; 710 711 // ! function sanitize_sql_orderby() 712 // ! function sanitize_html_class() 713 // ! function convert_chars() 714 // ! function funky_javascript_callback() 715 // ! function funky_javascript_fix() 716 // ! function balanceTags() 717 718 if ( !function_exists( 'force_balance_tags' ) ) : 719 /** 720 * Balances tags of string using a modified stack. 721 * 722 * @since 2.0.4 723 * 724 * @author Leonard Lin <leonard@acm.org> 725 * @license GPL v2.0 726 * @copyright November 4, 2001 727 * @version 1.1 728 * @todo Make better - change loop condition to $text in 1.2 729 * @internal Modified by Scott Reilly (coffee2code) 02 Aug 2004 730 * 1.1 Fixed handling of append/stack pop order of end text 731 * Added Cleaning Hooks 732 * 1.0 First Version 733 * 734 * @param string $text Text to be balanced. 735 * @return string Balanced text. 736 */ 737 function force_balance_tags( $text ) { 738 $tagstack = array(); $stacksize = 0; $tagqueue = ''; $newtext = ''; 739 $single_tags = array('br', 'hr', 'img', 'input'); //Known single-entity/self-closing tags 740 $nestable_tags = array('blockquote', 'div', 'span'); //Tags that can be immediately nested within themselves 741 742 # WP bug fix for comments - in case you REALLY meant to type '< !--' 743 $text = str_replace('< !--', '< !--', $text); 744 # WP bug fix for LOVE <3 (and other situations with '<' before a number) 745 $text = preg_replace('#<([0-9]{1})#', '<$1', $text); 746 747 while (preg_match("/<(\/?\w*)\s*([^>]*)>/",$text,$regex)) { 748 $newtext .= $tagqueue; 749 750 $i = strpos($text,$regex[0]); 751 $l = strlen($regex[0]); 752 753 // clear the shifter 754 $tagqueue = ''; 755 // Pop or Push 756 if ( isset($regex[1][0]) && '/' == $regex[1][0] ) { // End Tag 757 $tag = strtolower(substr($regex[1],1)); 758 // if too many closing tags 759 if($stacksize <= 0) { 760 $tag = ''; 761 //or close to be safe $tag = '/' . $tag; 762 } 763 // if stacktop value = tag close value then pop 764 else if ($tagstack[$stacksize - 1] == $tag) { // found closing tag 765 $tag = '</' . $tag . '>'; // Close Tag 766 // Pop 767 array_pop ($tagstack); 768 $stacksize--; 769 } else { // closing tag not at top, search for it 770 for ($j=$stacksize-1;$j>=0;$j--) { 771 if ($tagstack[$j] == $tag) { 772 // add tag to tagqueue 773 for ($k=$stacksize-1;$k>=$j;$k--){ 774 $tagqueue .= '</' . array_pop ($tagstack) . '>'; 775 $stacksize--; 776 } 777 break; 778 } 779 } 780 $tag = ''; 781 } 782 } else { // Begin Tag 783 $tag = strtolower($regex[1]); 784 785 // Tag Cleaning 786 787 // If self-closing or '', don't do anything. 788 if((substr($regex[2],-1) == '/') || ($tag == '')) { 789 } 790 // ElseIf it's a known single-entity tag but it doesn't close itself, do so 791 elseif ( in_array($tag, $single_tags) ) { 792 $regex[2] .= '/'; 793 } else { // Push the tag onto the stack 794 // If the top of the stack is the same as the tag we want to push, close previous tag 795 if (($stacksize > 0) && !in_array($tag, $nestable_tags) && ($tagstack[$stacksize - 1] == $tag)) { 796 $tagqueue = '</' . array_pop ($tagstack) . '>'; 797 $stacksize--; 798 } 799 $stacksize = array_push ($tagstack, $tag); 800 } 801 802 // Attributes 803 $attributes = $regex[2]; 804 if($attributes) { 805 $attributes = ' '.$attributes; 806 } 807 $tag = '<'.$tag.$attributes.'>'; 808 //If already queuing a close tag, then put this tag on, too 809 if ($tagqueue) { 810 $tagqueue .= $tag; 811 $tag = ''; 812 } 813 } 814 $newtext .= substr($text,0,$i) . $tag; 815 $text = substr($text,$i+$l); 816 } 817 818 // Clear Tag Queue 819 $newtext .= $tagqueue; 820 821 // Add Remaining text 822 $newtext .= $text; 823 824 // Empty Stack 825 while($x = array_pop($tagstack)) { 826 $newtext .= '</' . $x . '>'; // Add remaining tags to close 827 } 828 829 // WP fix for the bug with HTML comments 830 $newtext = str_replace("< !--","<!--",$newtext); 831 $newtext = str_replace("< !--","< !--",$newtext); 832 833 return $newtext; 834 } 835 endif; 836 837 if ( !function_exists('format_to_edit') ) : 838 /** 839 * Acts on text which is about to be edited. 840 * 841 * Unless $richedit is set, it is simply a holder for the 'format_to_edit' 842 * filter. If $richedit is set true htmlspecialchars() will be run on the 843 * content, converting special characters to HTMl entities. 844 * 845 * @since 0.71 846 * 847 * @param string $content The text about to be edited. 848 * @param bool $richedit Whether or not the $content should pass through htmlspecialchars(). Default false. 849 * @return string The text after the filter (and possibly htmlspecialchars()) has been run. 850 */ 851 function format_to_edit($content, $richedit = false) { 852 $content = apply_filters('format_to_edit', $content); 853 if (! $richedit ) 854 $content = htmlspecialchars($content); 855 return $content; 856 } 857 endif; 858 859 // !format_to_post() 860 861 if ( !function_exists( 'zeroise' ) ) : 862 /** 863 * Add leading zeros when necessary. 864 * 865 * If you set the threshold to '4' and the number is '10', then you will get 866 * back '0010'. If you set the number to '4' and the number is '5000', then you 867 * will get back '5000'. 868 * 869 * Uses sprintf to append the amount of zeros based on the $threshold parameter 870 * and the size of the number. If the number is large enough, then no zeros will 871 * be appended. 872 * 873 * @since 0.71 874 * 875 * @param mixed $number Number to append zeros to if not greater than threshold. 876 * @param int $threshold Digit places number needs to be to not have zeros added. 877 * @return string Adds leading zeros to number if needed. 878 */ 879 function zeroise($number, $threshold) { 880 return sprintf('%0'.$threshold.'s', $number); 881 } 882 endif; 883 884 if ( !function_exists( 'backslashit' ) ) : 885 /** 886 * Adds backslashes before letters and before a number at the start of a string. 887 * 888 * @since 0.71 889 * 890 * @param string $string Value to which backslashes will be added. 891 * @return string String with backslashes inserted. 892 */ 893 function backslashit($string) { 894 $string = preg_replace('/^([0-9])/', '\\\\\\\\\1', $string); 895 $string = preg_replace('/([a-z])/i', '\\\\\1', $string); 896 return $string; 897 } 898 endif; 899 900 if ( !function_exists( 'trailingslashit' ) ) : 901 /** 902 * Appends a trailing slash. 903 * 904 * Will remove trailing slash if it exists already before adding a trailing 905 * slash. This prevents double slashing a string or path. 906 * 907 * The primary use of this is for paths and thus should be used for paths. It is 908 * not restricted to paths and offers no specific path support. 909 * 910 * @since 1.2.0 911 * @uses untrailingslashit() Unslashes string if it was slashed already. 912 * 913 * @param string $string What to add the trailing slash to. 914 * @return string String with trailing slash added. 915 */ 916 function trailingslashit($string) { 917 return untrailingslashit($string) . '/'; 918 } 919 endif; 920 921 if ( !function_exists( 'untrailingslashit' ) ) : 922 /** 923 * Removes trailing slash if it exists. 924 * 925 * The primary use of this is for paths and thus should be used for paths. It is 926 * not restricted to paths and offers no specific path support. 927 * 928 * @since 2.2.0 929 * 930 * @param string $string What to remove the trailing slash from. 931 * @return string String without the trailing slash. 932 */ 933 function untrailingslashit($string) { 934 return rtrim($string, '/'); 935 } 936 endif; 937 938 // ! function addslashes_gpc() 939 940 if ( !function_exists('stripslashes_deep') ) : 941 /** 942 * Navigates through an array and removes slashes from the values. 943 * 944 * If an array is passed, the array_map() function causes a callback to pass the 945 * value back to the function. The slashes from this value will removed. 946 * 947 * @since 2.0.0 948 * 949 * @param array|string $value The array or string to be striped. 950 * @return array|string Stripped array (or string in the callback). 951 */ 952 function stripslashes_deep($value) { 953 $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); 954 return $value; 955 } 956 endif; 957 958 if ( !function_exists( 'urlencode_deep' ) ) : 959 /** 960 * Navigates through an array and encodes the values to be used in a URL. 961 * 962 * Uses a callback to pass the value of the array back to the function as a 963 * string. 964 * 965 * @since 2.2.0 966 * 967 * @param array|string $value The array or string to be encoded. 968 * @return array|string $value The encoded array (or string from the callback). 969 */ 970 function urlencode_deep($value) { 971 $value = is_array($value) ? array_map('urlencode_deep', $value) : urlencode($value); 972 return $value; 973 } 974 endif; 975 976 // ! function antispambot() 977 978 if ( !function_exists( '_make_url_clickable_cb' ) ) : 979 /** 980 * Callback to convert URI match to HTML A element. 981 * 982 * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link 983 * make_clickable()}. 984 * 985 * @since 2.3.2 986 * @access private 987 * 988 * @param array $matches Single Regex Match. 989 * @return string HTML A element with URI address. 990 */ 991 function _make_url_clickable_cb($matches) { 992 $url = $matches[2]; 993 994 $url = esc_url($url); 995 if ( empty($url) ) 996 return $matches[0]; 997 998 return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>"; 999 } 1000 endif; 1001 1002 if ( !function_exists( '_make_web_ftp_clickable_cb' ) ) : 1003 /** 1004 * Callback to convert URL match to HTML A element. 1005 * 1006 * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link 1007 * make_clickable()}. 1008 * 1009 * @since 2.3.2 1010 * @access private 1011 * 1012 * @param array $matches Single Regex Match. 1013 * @return string HTML A element with URL address. 1014 */ 1015 function _make_web_ftp_clickable_cb($matches) { 1016 $ret = ''; 1017 $dest = $matches[2]; 1018 $dest = 'http://' . $dest; 1019 $dest = esc_url($dest); 1020 if ( empty($dest) ) 1021 return $matches[0]; 1022 1023 // removed trailing [.,;:)] from URL 1024 if ( in_array( substr($dest, -1), array('.', ',', ';', ':', ')') ) === true ) { 1025 $ret = substr($dest, -1); 1026 $dest = substr($dest, 0, strlen($dest)-1); 1027 } 1028 return $matches[1] . "<a href=\"$dest\" rel=\"nofollow\">$dest</a>$ret"; 1029 } 1030 endif; 1031 1032 if ( !function_exists( '_make_email_clickable_cb' ) ) : 1033 /** 1034 * Callback to convert email address match to HTML A element. 1035 * 1036 * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link 1037 * make_clickable()}. 1038 * 1039 * @since 2.3.2 1040 * @access private 1041 * 1042 * @param array $matches Single Regex Match. 1043 * @return string HTML A element with email address. 1044 */ 1045 function _make_email_clickable_cb($matches) { 1046 $email = $matches[2] . '@' . $matches[3]; 1047 return $matches[1] . "<a href=\"mailto:$email\">$email</a>"; 1048 } 1049 endif; 1050 1051 if ( !function_exists( 'make_clickable' ) ) : 1052 /** 1053 * Convert plaintext URI to HTML links. 1054 * 1055 * Converts URI, www and ftp, and email addresses. Finishes by fixing links 1056 * within links. 1057 * 1058 * @since 0.71 1059 * 1060 * @param string $ret Content to convert URIs. 1061 * @return string Content with converted URIs. 1062 */ 1063 function make_clickable($ret) { 1064 $ret = ' ' . $ret; 1065 // in testing, using arrays here was found to be faster 1066 $ret = preg_replace_callback('#(?<=[\s>])(\()?([\w]+?://(?:[\w\\x80-\\xff\#$%&~/=?@\[\](+-]|[.,;:](?![\s<]|(\))?([\s]|$))|(?(1)\)(?![\s<.,;:]|$)|\)))+)#is', '_make_url_clickable_cb', $ret); 1067 $ret = preg_replace_callback('#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $ret); 1068 $ret = preg_replace_callback('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret); 1069 // this one is not in an array because we need it to run last, for cleanup of accidental links within links 1070 $ret = preg_replace("#(<a( [^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i", "$1$3</a>", $ret); 1071 $ret = trim($ret); 1072 return $ret; 1073 } 1074 endif; 1075 1076 // ! function wp_rel_nofollow() 1077 // ! function wp_rel_nofollow_callback() 1078 // ! function translate_smiley() 1079 // ! function convert_smilies() 1080 1081 if ( !function_exists('is_email') ) : 1082 /** 1083 * Verifies that an email is valid. 1084 * 1085 * Does not grok i18n domains. Not RFC compliant. 1086 * 1087 * @since 0.71 1088 * 1089 * @param string $email Email address to verify. 1090 * @param boolean $check_dns Whether to check the DNS for the domain using checkdnsrr(). 1091 * @return string|bool Either false or the valid email address. 1092 */ 1093 function is_email( $email, $check_dns = false ) { 1094 // Test for the minimum length the email can be 1095 if ( strlen( $email ) < 3 ) { 1096 return apply_filters( 'is_email', false, $email, 'email_too_short' ); 1097 } 1098 1099 // Test for an @ character after the first position 1100 if ( strpos( $email, '@', 1 ) === false ) { 1101 return apply_filters( 'is_email', false, $email, 'email_no_at' ); 1102 } 1103 1104 // Split out the local and domain parts 1105 list( $local, $domain ) = explode( '@', $email, 2 ); 1106 1107 // LOCAL PART 1108 // Test for invalid characters 1109 if ( !preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) { 1110 return apply_filters( 'is_email', false, $email, 'local_invalid_chars' ); 1111 } 1112 1113 // DOMAIN PART 1114 // Test for sequences of periods 1115 if ( preg_match( '/\.{2,}/', $domain ) ) { 1116 return apply_filters( 'is_email', false, $email, 'domain_period_sequence' ); 1117 } 1118 1119 // Test for leading and trailing periods and whitespace 1120 if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) { 1121 return apply_filters( 'is_email', false, $email, 'domain_period_limits' ); 1122 } 1123 1124 // Split the domain into subs 1125 $subs = explode( '.', $domain ); 1126 1127 // Assume the domain will have at least two subs 1128 if ( 2 > count( $subs ) ) { 1129 return apply_filters( 'is_email', false, $email, 'domain_no_periods' ); 1130 } 1131 1132 // Loop through each sub 1133 foreach ( $subs as $sub ) { 1134 // Test for leading and trailing hyphens and whitespace 1135 if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) { 1136 return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' ); 1137 } 1138 1139 // Test for invalid characters 1140 if ( !preg_match('/^[a-z0-9-]+$/i', $sub ) ) { 1141 return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' ); 1142 } 1143 } 1144 1145 // DNS 1146 // Check the domain has a valid MX and A resource record 1147 if ( $check_dns && function_exists( 'checkdnsrr' ) && !( checkdnsrr( $domain . '.', 'MX' ) || checkdnsrr( $domain . '.', 'A' ) ) ) { 1148 return apply_filters( 'is_email', false, $email, 'dns_no_rr' ); 1149 } 1150 1151 // Congratulations your email made it! 1152 return apply_filters( 'is_email', $email, $email, null ); 1153 } 1154 endif; 1155 1156 // ! function wp_iso_descrambler() 1157 // ! function get_gmt_from_date() 1158 // ! function get_date_from_gmt() 1159 // ! function iso8601_timezone_to_offset() 1160 // ! function iso8601_to_datetime() 1161 // ! popuplinks() 1162 1163 if ( !function_exists('sanitize_email') ) : 1164 /** 1165 * Strips out all characters that are not allowable in an email. 1166 * 1167 * @since 1.5.0 1168 * 1169 * @param string $email Email address to filter. 1170 * @return string Filtered email address. 1171 */ 1172 function sanitize_email( $email ) { 1173 // Test for the minimum length the email can be 1174 if ( strlen( $email ) < 3 ) { 1175 return apply_filters( 'sanitize_email', '', $email, 'email_too_short' ); 1176 } 1177 1178 // Test for an @ character after the first position 1179 if ( strpos( $email, '@', 1 ) === false ) { 1180 return apply_filters( 'sanitize_email', '', $email, 'email_no_at' ); 1181 } 1182 1183 // Split out the local and domain parts 1184 list( $local, $domain ) = explode( '@', $email, 2 ); 1185 1186 // LOCAL PART 1187 // Test for invalid characters 1188 $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local ); 1189 if ( '' === $local ) { 1190 return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' ); 1191 } 1192 1193 // DOMAIN PART 1194 // Test for sequences of periods 1195 $domain = preg_replace( '/\.{2,}/', '', $domain ); 1196 if ( '' === $domain ) { 1197 return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' ); 1198 } 1199 1200 // Test for leading and trailing periods and whitespace 1201 $domain = trim( $domain, " \t\n\r\0\x0B." ); 1202 if ( '' === $domain ) { 1203 return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' ); 1204 } 1205 1206 // Split the domain into subs 1207 $subs = explode( '.', $domain ); 1208 1209 // Assume the domain will have at least two subs 1210 if ( 2 > count( $subs ) ) { 1211 return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' ); 1212 } 1213 1214 // Create an array that will contain valid subs 1215 $new_subs = array(); 1216 1217 // Loop through each sub 1218 foreach ( $subs as $sub ) { 1219 // Test for leading and trailing hyphens 1220 $sub = trim( $sub, " \t\n\r\0\x0B-" ); 1221 1222 // Test for invalid characters 1223 $sub = preg_replace( '/^[^a-z0-9-]+$/i', '', $sub ); 1224 1225 // If there's anything left, add it to the valid subs 1226 if ( '' !== $sub ) { 1227 $new_subs[] = $sub; 1228 } 1229 } 1230 1231 // If there aren't 2 or more valid subs 1232 if ( 2 > count( $new_subs ) ) { 1233 return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' ); 1234 } 1235 1236 // Join valid subs into the new domain 1237 $domain = join( '.', $new_subs ); 1238 1239 // Put the email back together 1240 $email = $local . '@' . $domain; 1241 1242 // Congratulations your email made it! 1243 return apply_filters( 'sanitize_email', $email, $email, null ); 1244 } 1245 endif; 1246 1247 // ! function human_time_diff() 1248 // ! function wp_trim_excerpt() 1249 1250 if ( !function_exists( 'ent2ncr' ) ) : // Current at [WP9840] 1251 /** 1252 * Converts named entities into numbered entities. 1253 * 1254 * @since 1.5.1 1255 * 1256 * @param string $text The text within which entities will be converted. 1257 * @return string Text with converted entities. 1258 */ 1259 function ent2ncr($text) { 1260 $to_ncr = array( 1261 '"' => '"', 1262 '&' => '&', 1263 '⁄' => '/', 1264 '<' => '<', 1265 '>' => '>', 1266 '|' => '|', 1267 ' ' => ' ', 1268 '¡' => '¡', 1269 '¢' => '¢', 1270 '£' => '£', 1271 '¤' => '¤', 1272 '¥' => '¥', 1273 '¦' => '¦', 1274 '&brkbar;' => '¦', 1275 '§' => '§', 1276 '¨' => '¨', 1277 '¨' => '¨', 1278 '©' => '©', 1279 'ª' => 'ª', 1280 '«' => '«', 1281 '¬' => '¬', 1282 '­' => '­', 1283 '®' => '®', 1284 '¯' => '¯', 1285 '&hibar;' => '¯', 1286 '°' => '°', 1287 '±' => '±', 1288 '²' => '²', 1289 '³' => '³', 1290 '´' => '´', 1291 'µ' => 'µ', 1292 '¶' => '¶', 1293 '·' => '·', 1294 '¸' => '¸', 1295 '¹' => '¹', 1296 'º' => 'º', 1297 '»' => '»', 1298 '¼' => '¼', 1299 '½' => '½', 1300 '¾' => '¾', 1301 '¿' => '¿', 1302 'À' => 'À', 1303 'Á' => 'Á', 1304 'Â' => 'Â', 1305 'Ã' => 'Ã', 1306 'Ä' => 'Ä', 1307 'Å' => 'Å', 1308 'Æ' => 'Æ', 1309 'Ç' => 'Ç', 1310 'È' => 'È', 1311 'É' => 'É', 1312 'Ê' => 'Ê', 1313 'Ë' => 'Ë', 1314 'Ì' => 'Ì', 1315 'Í' => 'Í', 1316 'Î' => 'Î', 1317 'Ï' => 'Ï', 1318 'Ð' => 'Ð', 1319 'Ñ' => 'Ñ', 1320 'Ò' => 'Ò', 1321 'Ó' => 'Ó', 1322 'Ô' => 'Ô', 1323 'Õ' => 'Õ', 1324 'Ö' => 'Ö', 1325 '×' => '×', 1326 'Ø' => 'Ø', 1327 'Ù' => 'Ù', 1328 'Ú' => 'Ú', 1329 'Û' => 'Û', 1330 'Ü' => 'Ü', 1331 'Ý' => 'Ý', 1332 'Þ' => 'Þ', 1333 'ß' => 'ß', 1334 'à' => 'à', 1335 'á' => 'á', 1336 'â' => 'â', 1337 'ã' => 'ã', 1338 'ä' => 'ä', 1339 'å' => 'å', 1340 'æ' => 'æ', 1341 'ç' => 'ç', 1342 'è' => 'è', 1343 'é' => 'é', 1344 'ê' => 'ê', 1345 'ë' => 'ë', 1346 'ì' => 'ì', 1347 'í' => 'í', 1348 'î' => 'î', 1349 'ï' => 'ï', 1350 'ð' => 'ð', 1351 'ñ' => 'ñ', 1352 'ò' => 'ò', 1353 'ó' => 'ó', 1354 'ô' => 'ô', 1355 'õ' => 'õ', 1356 'ö' => 'ö', 1357 '÷' => '÷', 1358 'ø' => 'ø', 1359 'ù' => 'ù', 1360 'ú' => 'ú', 1361 'û' => 'û', 1362 'ü' => 'ü', 1363 'ý' => 'ý', 1364 'þ' => 'þ', 1365 'ÿ' => 'ÿ', 1366 'Œ' => 'Œ', 1367 'œ' => 'œ', 1368 'Š' => 'Š', 1369 'š' => 'š', 1370 'Ÿ' => 'Ÿ', 1371 'ƒ' => 'ƒ', 1372 'ˆ' => 'ˆ', 1373 '˜' => '˜', 1374 'Α' => 'Α', 1375 'Β' => 'Β', 1376 'Γ' => 'Γ', 1377 'Δ' => 'Δ', 1378 'Ε' => 'Ε', 1379 'Ζ' => 'Ζ', 1380 'Η' => 'Η', 1381 'Θ' => 'Θ', 1382 'Ι' => 'Ι', 1383 'Κ' => 'Κ', 1384 'Λ' => 'Λ', 1385 'Μ' => 'Μ', 1386 'Ν' => 'Ν', 1387 'Ξ' => 'Ξ', 1388 'Ο' => 'Ο', 1389 'Π' => 'Π', 1390 'Ρ' => 'Ρ', 1391 'Σ' => 'Σ', 1392 'Τ' => 'Τ', 1393 'Υ' => 'Υ', 1394 'Φ' => 'Φ', 1395 'Χ' => 'Χ', 1396 'Ψ' => 'Ψ', 1397 'Ω' => 'Ω', 1398 'α' => 'α', 1399 'β' => 'β', 1400 'γ' => 'γ', 1401 'δ' => 'δ', 1402 'ε' => 'ε', 1403 'ζ' => 'ζ', 1404 'η' => 'η', 1405 'θ' => 'θ', 1406 'ι' => 'ι', 1407 'κ' => 'κ', 1408 'λ' => 'λ', 1409 'μ' => 'μ', 1410 'ν' => 'ν', 1411 'ξ' => 'ξ', 1412 'ο' => 'ο', 1413 'π' => 'π', 1414 'ρ' => 'ρ', 1415 'ς' => 'ς', 1416 'σ' => 'σ', 1417 'τ' => 'τ', 1418 'υ' => 'υ', 1419 'φ' => 'φ', 1420 'χ' => 'χ', 1421 'ψ' => 'ψ', 1422 'ω' => 'ω', 1423 'ϑ' => 'ϑ', 1424 'ϒ' => 'ϒ', 1425 'ϖ' => 'ϖ', 1426 ' ' => ' ', 1427 ' ' => ' ', 1428 ' ' => ' ', 1429 '‌' => '‌', 1430 '‍' => '‍', 1431 '‎' => '‎', 1432 '‏' => '‏', 1433 '–' => '–', 1434 '—' => '—', 1435 '‘' => '‘', 1436 '’' => '’', 1437 '‚' => '‚', 1438 '“' => '“', 1439 '”' => '”', 1440 '„' => '„', 1441 '†' => '†', 1442 '‡' => '‡', 1443 '•' => '•', 1444 '…' => '…', 1445 '‰' => '‰', 1446 '′' => '′', 1447 '″' => '″', 1448 '‹' => '‹', 1449 '›' => '›', 1450 '‾' => '‾', 1451 '⁄' => '⁄', 1452 '€' => '€', 1453 'ℑ' => 'ℑ', 1454 '℘' => '℘', 1455 'ℜ' => 'ℜ', 1456 '™' => '™', 1457 'ℵ' => 'ℵ', 1458 '↵' => '↵', 1459 '⇐' => '⇐', 1460 '⇑' => '⇑', 1461 '⇒' => '⇒', 1462 '⇓' => '⇓', 1463 '⇔' => '⇔', 1464 '∀' => '∀', 1465 '∂' => '∂', 1466 '∃' => '∃', 1467 '∅' => '∅', 1468 '∇' => '∇', 1469 '∈' => '∈', 1470 '∉' => '∉', 1471 '∋' => '∋', 1472 '∏' => '∏', 1473 '∑' => '∑', 1474 '−' => '−', 1475 '∗' => '∗', 1476 '√' => '√', 1477 '∝' => '∝', 1478 '∞' => '∞', 1479 '∠' => '∠', 1480 '∧' => '∧', 1481 '∨' => '∨', 1482 '∩' => '∩', 1483 '∪' => '∪', 1484 '∫' => '∫', 1485 '∴' => '∴', 1486 '∼' => '∼', 1487 '≅' => '≅', 1488 '≈' => '≈', 1489 '≠' => '≠', 1490 '≡' => '≡', 1491 '≤' => '≤', 1492 '≥' => '≥', 1493 '⊂' => '⊂', 1494 '⊃' => '⊃', 1495 '⊄' => '⊄', 1496 '⊆' => '⊆', 1497 '⊇' => '⊇', 1498 '⊕' => '⊕', 1499 '⊗' => '⊗', 1500 '⊥' => '⊥', 1501 '⋅' => '⋅', 1502 '⌈' => '⌈', 1503 '⌉' => '⌉', 1504 '⌊' => '⌊', 1505 '⌋' => '⌋', 1506 '⟨' => '〈', 1507 '⟩' => '〉', 1508 '←' => '←', 1509 '↑' => '↑', 1510 '→' => '→', 1511 '↓' => '↓', 1512 '↔' => '↔', 1513 '◊' => '◊', 1514 '♠' => '♠', 1515 '♣' => '♣', 1516 '♥' => '♥', 1517 '♦' => '♦' 1518 ); 1519 1520 return str_replace( array_keys($to_ncr), array_values($to_ncr), $text ); 1521 } 1522 endif; 1523 1524 // ! function wp_richedit_pre() 1525 // ! function wp_htmledit_pre() 1526 1527 if ( !function_exists('clean_url') ) : 1528 /** 1529 * Checks and cleans a URL. 1530 * 1531 * A number of characters are removed from the URL. If the URL is for displaying 1532 * (the default behaviour) amperstands are also replaced. The 'esc_url' filter 1533 * is applied to the returned cleaned URL. 1534 * 1535 * @since 1.2.0 1536 * @uses wp_kses_bad_protocol() To only permit protocols in the URL set 1537 * via $protocols or the common ones set in the function. 1538 * 1539 * @param string $url The URL to be cleaned. 1540 * @param array $protocols Optional. An array of acceptable protocols. 1541 * Defaults to 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn' if not set. 1542 * @param string $context Optional. How the URL will be used. Default is 'display'. 1543 * @return string The cleaned $url after the 'cleaned_url' filter is applied. 1544 */ 1545 function clean_url( $url, $protocols = null, $context = 'display' ) { 1546 $original_url = $url; 1547 1548 if ( '' == $url ) 1549 return $url; 1550 $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]|i', '', $url); 1551 $strip = array('%0d', '%0a', '%0D', '%0A'); 1552 $url = _deep_replace($strip, $url); 1553 $url = str_replace(';//', '://', $url); 1554 /* If the URL doesn't appear to contain a scheme, we 1555 * presume it needs http:// appended (unless a relative 1556 * link starting with / or a php file). 1557 */ 1558 if ( strpos($url, ':') === false && 1559 substr( $url, 0, 1 ) != '/' && substr( $url, 0, 1 ) != '#' && !preg_match('/^[a-z0-9-]+?\.php/i', $url) ) 1560 $url = 'http://' . $url; 1561 1562 // Replace ampersands and single quotes only when displaying. 1563 if ( 'display' == $context ) { 1564 $url = wp_kses_normalize_entities( $url ); 1565 $url = str_replace( '&', '&', $url ); 1566 $url = str_replace( "'", ''', $url ); 1567 } 1568 1569 if ( !is_array($protocols) ) 1570 $protocols = array ('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn'); 1571 if ( wp_kses_bad_protocol( $url, $protocols ) != $url ) 1572 return ''; 1573 1574 return apply_filters('clean_url', $url, $original_url, $context); 1575 } 1576 endif; 1577 1578 if ( !function_exists( '_deep_replace' ) ) : 1579 /** 1580 * Perform a deep string replace operation to ensure the values in $search are no longer present 1581 * 1582 * Repeats the replacement operation until it no longer replaces anything so as to remove "nested" values 1583 * e.g. $subject = '%0%0%0DDD', $search ='%0D', $result ='' rather than the '%0%0DD' that 1584 * str_replace would return 1585 * 1586 * @since 2.8.1 1587 * @access private 1588 * 1589 * @param string|array $search 1590 * @param string $subject 1591 * @return string The processed string 1592 */ 1593 function _deep_replace($search, $subject){ 1594 $found = true; 1595 while($found) { 1596 $found = false; 1597 foreach( (array) $search as $val ) { 1598 while(strpos($subject, $val) !== false) { 1599 $found = true; 1600 $subject = str_replace($val, '', $subject); 1601 } 1602 } 1603 } 1604 1605 return $subject; 1606 } 1607 endif; 1608 1609 if ( !function_exists( 'esc_sql' ) ) : 1610 /** 1611 * Escapes data for use in a MySQL query 1612 * 1613 * This is just a handy shortcut for $bpdb->escape(), for completeness' sake 1614 * 1615 * @since 2.8.0 1616 * @param string $sql Unescaped SQL data 1617 * @return string The cleaned $sql 1618 */ 1619 function esc_sql( $sql ) { 1620 global $bpdb; 1621 return $bpdb->escape( $sql ); 1622 } 1623 endif; 1624 1625 if ( !function_exists( 'esc_url' ) ) : 1626 /** 1627 * Checks and cleans a URL. 1628 * 1629 * A number of characters are removed from the URL. If the URL is for displaying 1630 * (the default behaviour) amperstands are also replaced. The 'esc_url' filter 1631 * is applied to the returned cleaned URL. 1632 * 1633 * @since 2.8.0 1634 * @uses esc_url() 1635 * @uses wp_kses_bad_protocol() To only permit protocols in the URL set 1636 * via $protocols or the common ones set in the function. 1637 * 1638 * @param string $url The URL to be cleaned. 1639 * @param array $protocols Optional. An array of acceptable protocols. 1640 * Defaults to 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet' if not set. 1641 * @return string The cleaned $url after the 'cleaned_url' filter is applied. 1642 */ 1643 function esc_url( $url, $protocols = null ) { 1644 return clean_url( $url, $protocols, 'display' ); 1645 } 1646 endif; 1647 1648 if ( !function_exists( 'esc_url_raw' ) ) : 1649 /** 1650 * Performs esc_url() for database usage. 1651 * 1652 * @see esc_url() 1653 * @see esc_url() 1654 * 1655 * @since 2.8.0 1656 * 1657 * @param string $url The URL to be cleaned. 1658 * @param array $protocols An array of acceptable protocols. 1659 * @return string The cleaned URL. 1660 */ 1661 function esc_url_raw( $url, $protocols = null ) { 1662 return clean_url( $url, $protocols, 'db' ); 1663 } 1664 endif; 1665 1666 // ! function sanitize_url() 1667 // ! function htmlentities2() 1668 1669 if ( !function_exists( 'esc_js' ) ) : 1670 /** 1671 * Escape single quotes, htmlspecialchar " < > &, and fix line endings. 1672 * 1673 * Escapes text strings for echoing in JS, both inline (for example in onclick="...") 1674 * and inside <script> tag. Note that the strings have to be in single quotes. 1675 * The filter 'js_escape' is also applied here. 1676 * 1677 * @since 2.8.0 1678 * 1679 * @param string $text The text to be escaped. 1680 * @return string Escaped text. 1681 */ 1682 function esc_js( $text ) { 1683 $safe_text = wp_check_invalid_utf8( $text ); 1684 $safe_text = _wp_specialchars( $safe_text, ENT_COMPAT ); 1685 $safe_text = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes( $safe_text ) ); 1686 $safe_text = str_replace( "\r", '', $safe_text ); 1687 $safe_text = str_replace( "\n", '\\n', addslashes( $safe_text ) ); 1688 return apply_filters( 'js_escape', $safe_text, $text ); 1689 } 1690 endif; 1691 1692 if ( !function_exists( 'js_escape' ) ) : 1693 /** 1694 * Escape single quotes, specialchar double quotes, and fix line endings. 1695 * 1696 * The filter 'js_escape' is also applied by esc_js() 1697 * 1698 * @since 2.0.4 1699 * 1700 * @deprecated 2.8.0 1701 * @see esc_js() 1702 * 1703 * @param string $text The text to be escaped. 1704 * @return string Escaped text. 1705 */ 1706 function js_escape( $text ) { 1707 return esc_js( $text ); 1708 } 1709 endif; 1710 1711 if ( !function_exists( 'esc_html' ) ) : 1712 /** 1713 * Escaping for HTML blocks. 1714 * 1715 * @since 2.8.0 1716 * 1717 * @param string $text 1718 * @return string 1719 */ 1720 function esc_html( $text ) { 1721 $safe_text = wp_check_invalid_utf8( $text ); 1722 $safe_text = _wp_specialchars( $safe_text, ENT_QUOTES ); 1723 return apply_filters( 'esc_html', $safe_text, $text ); 1724 return $text; 1725 } 1726 endif; 1727 1728 if ( !function_exists( 'wp_specialchars' ) ) : 1729 /** 1730 * Escaping for HTML blocks 1731 * @deprecated 2.8.0 1732 * @see esc_html() 1733 */ 1734 function wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) { 1735 if ( func_num_args() > 1 ) { // Maintain backwards compat for people passing additional args 1736 $args = func_get_args(); 1737 return call_user_func_array( '_wp_specialchars', $args ); 1738 } else { 1739 return esc_html( $string ); 1740 } 1741 } 1742 endif; 1743 1744 if ( !function_exists( 'esc_attr' ) ) : 1745 /** 1746 * Escaping for HTML attributes. 1747 * 1748 * @since 2.8.0 1749 * 1750 * @param string $text 1751 * @return string 1752 */ 1753 function esc_attr( $text ) { 1754 $safe_text = wp_check_invalid_utf8( $text ); 1755 $safe_text = _wp_specialchars( $safe_text, ENT_QUOTES ); 1756 return apply_filters( 'attribute_escape', $safe_text, $text ); 1757 } 1758 endif; 1759 1760 if ( !function_exists( 'attribute_escape' ) ) : 1761 /** 1762 * Escaping for HTML attributes. 1763 * 1764 * @since 2.0.6 1765 * 1766 * @deprecated 2.8.0 1767 * @see esc_attr() 1768 * 1769 * @param string $text 1770 * @return string 1771 */ 1772 function attribute_escape( $text ) { 1773 return esc_attr( $text ); 1774 } 1775 endif; 1776 1777 // ! function tag_escape() 1778 1779 if ( !function_exists('like_escape') ) : 1780 /** 1781 * Escapes text for SQL LIKE special characters % and _. 1782 * 1783 * @since 2.5.0 1784 * 1785 * @param string $text The text to be escaped. 1786 * @return string text, safe for inclusion in LIKE query. 1787 */ 1788 function like_escape($text) { 1789 return addcslashes($text, '\\%_'); 1790 } 1791 endif; 1792 1793 // ! function wp_make_link_relative() 1794 // ! function sanitize_option() 1795 1796 if ( !function_exists('wp_parse_str') ) : 1797 /** 1798 * Parses a string into variables to be stored in an array. 1799 * 1800 * Uses {@link http://www.php.net/parse_str parse_str()} and stripslashes if 1801 * {@link http://www.php.net/magic_quotes magic_quotes_gpc} is on. 1802 * 1803 * @since 2.2.1 1804 * @uses apply_filters() for the 'wp_parse_str' filter. 1805 * 1806 * @param string $string The string to be parsed. 1807 * @param array $array Variables will be stored in this array. 1808 */ 1809 function wp_parse_str( $string, &$array ) { 1810 parse_str( $string, $array ); 1811 if ( get_magic_quotes_gpc() ) 1812 $array = stripslashes_deep( $array ); 1813 $array = apply_filters( 'wp_parse_str', $array ); 1814 } 1815 endif; 1816 1817 if ( !function_exists('wp_pre_kses_less_than') ) : 1818 /** 1819 * Convert lone less than signs. 1820 * 1821 * KSES already converts lone greater than signs. 1822 * 1823 * @uses wp_pre_kses_less_than_callback in the callback function. 1824 * @since 2.3.0 1825 * 1826 * @param string $text Text to be converted. 1827 * @return string Converted text. 1828 */ 1829 function wp_pre_kses_less_than( $text ) { 1830 return preg_replace_callback('%<[^>]*?((?=<)|>|$)%', 'wp_pre_kses_less_than_callback', $text); 1831 } 1832 endif; 1833 if ( !function_exists('wp_pre_kses_less_than_callback') ) : 1834 /** 1835 * Callback function used by preg_replace. 1836 * 1837 * @uses esc_html to format the $matches text. 1838 * @since 2.3.0 1839 * 1840 * @param array $matches Populated by matches to preg_replace. 1841 * @return string The text returned after esc_html if needed. 1842 */ 1843 function wp_pre_kses_less_than_callback( $matches ) { 1844 if ( false === strpos($matches[0], '>') ) 1845 return esc_html($matches[0]); 1846 return $matches[0]; 1847 } 1848 endif; 1849 // ! function wp_sprintf() 1850 // ! function wp_sprintf_l() 1851 1852 if ( !function_exists('wp_html_excerpt') ) : 1853 /** 1854 * Safely extracts not more than the first $count characters from html string. 1855 * 1856 * UTF-8, tags and entities safe prefix extraction. Entities inside will *NOT* 1857 * be counted as one character. For example & will be counted as 4, < as 1858 * 3, etc. 1859 * 1860 * @since 2.5.0 1861 * 1862 * @param integer $str String to get the excerpt from. 1863 * @param integer $count Maximum number of characters to take. 1864 * @return string The excerpt. 1865 */ 1866 function wp_html_excerpt( $str, $count ) { 1867 $str = wp_strip_all_tags( $str, true ); 1868 $str = mb_substr( $str, 0, $count ); 1869 // remove part of an entity at the end 1870 $str = preg_replace( '/&[^;\s]{0,6}$/', '', $str ); 1871 return $str; 1872 } 1873 endif; 1874 1875 // ! function links_add_base_url() 1876 // ! function _links_add_base() 1877 // ! function links_add_target() 1878 // ! function _links_add_target() 1879 // ! function normalize_whitespace() 1880 1881 if ( !function_exists('wp_strip_all_tags') ) : 1882 /** 1883 * Properly strip all HTML tags including script and style 1884 * 1885 * @since 2.9.0 1886 * 1887 * @param string $string String containing HTML tags 1888 * @param bool $remove_breaks optional Whether to remove left over line breaks and white space chars 1889 * @return string The processed string. 1890 */ 1891 function wp_strip_all_tags($string, $remove_breaks = false) { 1892 $string = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $string ); 1893 $string = strip_tags($string); 1894 1895 if ( $remove_breaks ) 1896 $string = preg_replace('/[\r\n\t ]+/', ' ', $string); 1897 1898 return trim($string); 1899 } 1900 endif; 1901 1902 if ( !function_exists('sanitize_text_field') ) : 1903 /** 1904 * Sanitize a string from user input or from the db 1905 * 1906 * check for invalid UTF-8, 1907 * Convert single < characters to entity, 1908 * strip all tags, 1909 * remove line breaks, tabs and extra whitre space, 1910 * strip octets. 1911 * 1912 * @since 2.9 1913 * 1914 * @param string $str 1915 * @return string 1916 */ 1917 function sanitize_text_field($str) { 1918 $filtered = wp_check_invalid_utf8( $str ); 1919 1920 if ( strpos($filtered, '<') !== false ) { 1921 $filtered = wp_pre_kses_less_than( $filtered ); 1922 // This will strip extra whitespace for us. 1923 $filtered = wp_strip_all_tags( $filtered, true ); 1924 } else { 1925 $filtered = trim( preg_replace('/[\r\n\t ]+/', ' ', $filtered) ); 1926 } 1927 1928 $match = array(); 1929 $found = false; 1930 while ( preg_match('/%[a-f0-9]{2}/i', $filtered, $match) ) { 1931 $filtered = str_replace($match[0], '', $filtered); 1932 $found = true; 1933 } 1934 1935 if ( $found ) { 1936 // Strip out the whitespace that may now exist after removing the octets. 1937 $filtered = trim( preg_replace('/ +/', ' ', $filtered) ); 1938 } 1939 1940 return apply_filters('sanitize_text_field', $filtered, $str); 1941 } 1942 endif;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |