/bp-forums/bbpress/bb-includes/backpress/functions.formatting.php

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