PageRenderTime 60ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/bb-includes/backpress/functions.formatting.php

https://bitbucket.org/iRonBot/bbpress-persian
PHP | 1942 lines | 1220 code | 154 blank | 568 comment | 173 complexity | 0af39249db48e6c5c274cb0a085b530d MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // Last sync [WP12504]
  3. /**
  4. * From WP wp-includes/formatting.php
  5. *
  6. * Missing functions are indicated in comments
  7. */
  8. /**
  9. * Main BackPress Formatting API.
  10. *
  11. * Handles many functions for formatting output.
  12. *
  13. * @package BackPress
  14. **/
  15. if ( !function_exists( 'wptexturize' ) ) :
  16. /**
  17. * Replaces common plain text characters into formatted entities
  18. *
  19. * As an example,
  20. * <code>
  21. * 'cause today's effort makes it worth tomorrow's "holiday"...
  22. * </code>
  23. * Becomes:
  24. * <code>
  25. * &#8217;cause today&#8217;s effort makes it worth tomorrow&#8217;s &#8220;holiday&#8221;&#8230;
  26. * </code>
  27. * Code within certain html blocks are skipped.
  28. *
  29. * @since 0.71
  30. * @uses $wp_cockneyreplace Array of formatted entities for certain common phrases
  31. *
  32. * @param string $text The text to be formatted
  33. * @return string The string replaced with html entities
  34. */
  35. function wptexturize($text) {
  36. global $wp_cockneyreplace;
  37. static $static_setup = false, $opening_quote, $closing_quote, $default_no_texturize_tags, $default_no_texturize_shortcodes, $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements;
  38. $output = '';
  39. $curl = '';
  40. $textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
  41. $stop = count($textarr);
  42. // No need to setup these variables more than once
  43. if (!$static_setup) {
  44. /* translators: opening curly quote */
  45. $opening_quote = _x('&#8220;', 'opening curly quote');
  46. /* translators: closing curly quote */
  47. $closing_quote = _x('&#8221;', 'closing curly quote');
  48. $default_no_texturize_tags = array('pre', 'code', 'kbd', 'style', 'script', 'tt');
  49. $default_no_texturize_shortcodes = array('code');
  50. // if a plugin has provided an autocorrect array, use it
  51. if ( isset($wp_cockneyreplace) ) {
  52. $cockney = array_keys($wp_cockneyreplace);
  53. $cockneyreplace = array_values($wp_cockneyreplace);
  54. } else {
  55. $cockney = array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round","'cause");
  56. $cockneyreplace = array("&#8217;tain&#8217;t","&#8217;twere","&#8217;twas","&#8217;tis","&#8217;twill","&#8217;til","&#8217;bout","&#8217;nuff","&#8217;round","&#8217;cause");
  57. }
  58. $static_characters = array_merge(array('---', ' -- ', '--', ' - ', 'xn&#8211;', '...', '``', '\'s', '\'\'', ' (tm)'), $cockney);
  59. $static_replacements = array_merge(array('&#8212;', ' &#8212; ', '&#8211;', ' &#8211; ', 'xn--', '&#8230;', $opening_quote, '&#8217;s', $closing_quote, ' &#8482;'), $cockneyreplace);
  60. $dynamic_characters = array('/\'(\d\d(?:&#8217;|\')?s)/', '/(\s|\A|[([{<]|")\'/', '/(\d+)"/', '/(\d+)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A|[([{<])"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/(\d+)x(\d+)/');
  61. $dynamic_replacements = array('&#8217;$1','$1&#8216;', '$1&#8243;', '$1&#8242;', '$1&#8217;$2', '$1' . $opening_quote . '$2', $closing_quote . '$1', '&#8217;$1', '$1&#215;$2');
  62. $static_setup = true;
  63. }
  64. // Transform into regexp sub-expression used in _wptexturize_pushpop_element
  65. // Must do this everytime in case plugins use these filters in a context sensitive manner
  66. $no_texturize_tags = '(' . implode('|', apply_filters('no_texturize_tags', $default_no_texturize_tags) ) . ')';
  67. $no_texturize_shortcodes = '(' . implode('|', apply_filters('no_texturize_shortcodes', $default_no_texturize_shortcodes) ) . ')';
  68. $no_texturize_tags_stack = array();
  69. $no_texturize_shortcodes_stack = array();
  70. for ( $i = 0; $i < $stop; $i++ ) {
  71. $curl = $textarr[$i];
  72. if ( !empty($curl) && '<' != $curl{0} && '[' != $curl{0}
  73. && empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack)) {
  74. // This is not a tag, nor is the texturization disabled
  75. // static strings
  76. $curl = str_replace($static_characters, $static_replacements, $curl);
  77. // regular expressions
  78. $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl);
  79. } elseif (!empty($curl)) {
  80. /*
  81. * Only call _wptexturize_pushpop_element if first char is correct
  82. * tag opening
  83. */
  84. if ('<' == $curl{0})
  85. _wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>');
  86. elseif ('[' == $curl{0})
  87. _wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']');
  88. }
  89. $curl = preg_replace('/&([^#])(?![a-zA-Z1-4]{1,8};)/', '&#038;$1', $curl);
  90. $output .= $curl;
  91. }
  92. return $output;
  93. }
  94. endif;
  95. if ( !function_exists( '_wptexturize_pushpop_element' ) ) :
  96. /**
  97. * Search for disabled element tags. Push element to stack on tag open and pop
  98. * on tag close. Assumes first character of $text is tag opening.
  99. *
  100. * @access private
  101. * @since 2.9.0
  102. *
  103. * @param string $text Text to check. First character is assumed to be $opening
  104. * @param array $stack Array used as stack of opened tag elements
  105. * @param string $disabled_elements Tags to match against formatted as regexp sub-expression
  106. * @param string $opening Tag opening character, assumed to be 1 character long
  107. * @param string $opening Tag closing character
  108. * @return object
  109. */
  110. function _wptexturize_pushpop_element($text, &$stack, $disabled_elements, $opening = '<', $closing = '>') {
  111. // Check if it is a closing tag -- otherwise assume opening tag
  112. if (strncmp($opening . '/', $text, 2)) {
  113. // Opening? Check $text+1 against disabled elements
  114. if (preg_match('/^' . $disabled_elements . '\b/', substr($text, 1), $matches)) {
  115. /*
  116. * This disables texturize until we find a closing tag of our type
  117. * (e.g. <pre>) even if there was invalid nesting before that
  118. *
  119. * Example: in the case <pre>sadsadasd</code>"baba"</pre>
  120. * "baba" won't be texturize
  121. */
  122. array_push($stack, $matches[1]);
  123. }
  124. } else {
  125. // Closing? Check $text+2 against disabled elements
  126. $c = preg_quote($closing, '/');
  127. if (preg_match('/^' . $disabled_elements . $c . '/', substr($text, 2), $matches)) {
  128. $last = array_pop($stack);
  129. // Make sure it matches the opening tag
  130. if ($last != $matches[1])
  131. array_push($stack, $last);
  132. }
  133. }
  134. }
  135. endif;
  136. if ( !function_exists( 'clean_pre' ) ) :
  137. /**
  138. * Accepts matches array from preg_replace_callback in wpautop() or a string.
  139. *
  140. * Ensures that the contents of a <<pre>>...<</pre>> HTML block are not
  141. * converted into paragraphs or line-breaks.
  142. *
  143. * @since 1.2.0
  144. *
  145. * @param array|string $matches The array or string
  146. * @return string The pre block without paragraph/line-break conversion.
  147. */
  148. function clean_pre($matches) {
  149. if ( is_array($matches) )
  150. $text = $matches[1] . $matches[2] . "</pre>";
  151. else
  152. $text = $matches;
  153. $text = str_replace('<br />', '', $text);
  154. $text = str_replace('<p>', "\n", $text);
  155. $text = str_replace('</p>', '', $text);
  156. return $text;
  157. }
  158. endif;
  159. // ! function wpautop()
  160. if ( !function_exists('seems_utf8') ) :
  161. /**
  162. * Checks to see if a string is utf8 encoded.
  163. *
  164. * NOTE: This function checks for 5-Byte sequences, UTF8
  165. * has Bytes Sequences with a maximum length of 4.
  166. *
  167. * @author bmorel at ssi dot fr (modified)
  168. * @since 1.2.1
  169. *
  170. * @param string $str The string to be checked
  171. * @return bool True if $str fits a UTF-8 model, false otherwise.
  172. */
  173. function seems_utf8($str) {
  174. $length = strlen($str);
  175. for ($i=0; $i < $length; $i++) {
  176. $c = ord($str[$i]);
  177. if ($c < 0x80) $n = 0; # 0bbbbbbb
  178. elseif (($c & 0xE0) == 0xC0) $n=1; # 110bbbbb
  179. elseif (($c & 0xF0) == 0xE0) $n=2; # 1110bbbb
  180. elseif (($c & 0xF8) == 0xF0) $n=3; # 11110bbb
  181. elseif (($c & 0xFC) == 0xF8) $n=4; # 111110bb
  182. elseif (($c & 0xFE) == 0xFC) $n=5; # 1111110b
  183. else return false; # Does not match any model
  184. for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
  185. if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80))
  186. return false;
  187. }
  188. }
  189. return true;
  190. }
  191. endif;
  192. if ( !function_exists('_wp_specialchars') ) :
  193. /**
  194. * Converts a number of special characters into their HTML entities.
  195. *
  196. * Specifically deals with: &, <, >, ", and '.
  197. *
  198. * $quote_style can be set to ENT_COMPAT to encode " to
  199. * &quot;, or ENT_QUOTES to do both. Default is ENT_NOQUOTES where no quotes are encoded.
  200. *
  201. * @since 1.2.2
  202. *
  203. * @param string $string The text which is to be encoded.
  204. * @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.
  205. * @param string $charset Optional. The character encoding of the string. Default is false.
  206. * @param boolean $double_encode Optional. Whether or not to encode existing html entities. Default is false.
  207. * @return string The encoded text with HTML entities.
  208. */
  209. function _wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) {
  210. $string = (string) $string;
  211. if ( 0 === strlen( $string ) ) {
  212. return '';
  213. }
  214. // Don't bother if there are no specialchars - saves some processing
  215. if ( !preg_match( '/[&<>"\']/', $string ) ) {
  216. return $string;
  217. }
  218. // Account for the previous behaviour of the function when the $quote_style is not an accepted value
  219. if ( empty( $quote_style ) ) {
  220. $quote_style = ENT_NOQUOTES;
  221. } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {
  222. $quote_style = ENT_QUOTES;
  223. }
  224. // Store the site charset as a static to avoid multiple calls to backpress_get_option()
  225. if ( !$charset ) {
  226. static $_charset;
  227. if ( !isset( $_charset ) ) {
  228. $_charset = backpress_get_option( 'charset' );
  229. }
  230. $charset = $_charset;
  231. }
  232. if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) ) {
  233. $charset = 'UTF-8';
  234. }
  235. $_quote_style = $quote_style;
  236. if ( $quote_style === 'double' ) {
  237. $quote_style = ENT_COMPAT;
  238. $_quote_style = ENT_COMPAT;
  239. } elseif ( $quote_style === 'single' ) {
  240. $quote_style = ENT_NOQUOTES;
  241. }
  242. // Handle double encoding ourselves
  243. if ( !$double_encode ) {
  244. $string = wp_specialchars_decode( $string, $_quote_style );
  245. $string = preg_replace( '/&(#?x?[0-9a-z]+);/i', '|wp_entity|$1|/wp_entity|', $string );
  246. }
  247. $string = @htmlspecialchars( $string, $quote_style, $charset );
  248. // Handle double encoding ourselves
  249. if ( !$double_encode ) {
  250. $string = str_replace( array( '|wp_entity|', '|/wp_entity|' ), array( '&', ';' ), $string );
  251. }
  252. // Backwards compatibility
  253. if ( 'single' === $_quote_style ) {
  254. $string = str_replace( "'", '&#039;', $string );
  255. }
  256. return $string;
  257. }
  258. endif;
  259. if ( !function_exists( 'wp_specialchars_decode' ) ) :
  260. /**
  261. * Converts a number of HTML entities into their special characters.
  262. *
  263. * Specifically deals with: &, <, >, ", and '.
  264. *
  265. * $quote_style can be set to ENT_COMPAT to decode " entities,
  266. * or ENT_QUOTES to do both " and '. Default is ENT_NOQUOTES where no quotes are decoded.
  267. *
  268. * @since 2.8
  269. *
  270. * @param string $string The text which is to be decoded.
  271. * @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.
  272. * @return string The decoded text without HTML entities.
  273. */
  274. function wp_specialchars_decode( $string, $quote_style = ENT_NOQUOTES ) {
  275. $string = (string) $string;
  276. if ( 0 === strlen( $string ) ) {
  277. return '';
  278. }
  279. // Don't bother if there are no entities - saves a lot of processing
  280. if ( strpos( $string, '&' ) === false ) {
  281. return $string;
  282. }
  283. // Match the previous behaviour of _wp_specialchars() when the $quote_style is not an accepted value
  284. if ( empty( $quote_style ) ) {
  285. $quote_style = ENT_NOQUOTES;
  286. } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {
  287. $quote_style = ENT_QUOTES;
  288. }
  289. // More complete than get_html_translation_table( HTML_SPECIALCHARS )
  290. $single = array( '&#039;' => '\'', '&#x27;' => '\'' );
  291. $single_preg = array( '/&#0*39;/' => '&#039;', '/&#x0*27;/i' => '&#x27;' );
  292. $double = array( '&quot;' => '"', '&#034;' => '"', '&#x22;' => '"' );
  293. $double_preg = array( '/&#0*34;/' => '&#034;', '/&#x0*22;/i' => '&#x22;' );
  294. $others = array( '&lt;' => '<', '&#060;' => '<', '&gt;' => '>', '&#062;' => '>', '&amp;' => '&', '&#038;' => '&', '&#x26;' => '&' );
  295. $others_preg = array( '/&#0*60;/' => '&#060;', '/&#0*62;/' => '&#062;', '/&#0*38;/' => '&#038;', '/&#x0*26;/i' => '&#x26;' );
  296. if ( $quote_style === ENT_QUOTES ) {
  297. $translation = array_merge( $single, $double, $others );
  298. $translation_preg = array_merge( $single_preg, $double_preg, $others_preg );
  299. } elseif ( $quote_style === ENT_COMPAT || $quote_style === 'double' ) {
  300. $translation = array_merge( $double, $others );
  301. $translation_preg = array_merge( $double_preg, $others_preg );
  302. } elseif ( $quote_style === 'single' ) {
  303. $translation = array_merge( $single, $others );
  304. $translation_preg = array_merge( $single_preg, $others_preg );
  305. } elseif ( $quote_style === ENT_NOQUOTES ) {
  306. $translation = $others;
  307. $translation_preg = $others_preg;
  308. }
  309. // Remove zero padding on numeric entities
  310. $string = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $string );
  311. // Replace characters according to translation table
  312. return strtr( $string, $translation );
  313. }
  314. endif;
  315. if ( !function_exists( 'wp_check_invalid_utf8' ) ) :
  316. /**
  317. * Checks for invalid UTF8 in a string.
  318. *
  319. * @since 2.8
  320. *
  321. * @param string $string The text which is to be checked.
  322. * @param boolean $strip Optional. Whether to attempt to strip out invalid UTF8. Default is false.
  323. * @return string The checked text.
  324. */
  325. function wp_check_invalid_utf8( $string, $strip = false ) {
  326. $string = (string) $string;
  327. if ( 0 === strlen( $string ) ) {
  328. return '';
  329. }
  330. // Store the site charset as a static to avoid multiple calls to backpress_get_option()
  331. static $is_utf8;
  332. if ( !isset( $is_utf8 ) ) {
  333. $is_utf8 = in_array( backpress_get_option( 'charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) );
  334. }
  335. if ( !$is_utf8 ) {
  336. return $string;
  337. }
  338. // Check for support for utf8 in the installed PCRE library once and store the result in a static
  339. static $utf8_pcre;
  340. if ( !isset( $utf8_pcre ) ) {
  341. $utf8_pcre = @preg_match( '/^./u', 'a' );
  342. }
  343. // We can't demand utf8 in the PCRE installation, so just return the string in those cases
  344. if ( !$utf8_pcre ) {
  345. return $string;
  346. }
  347. // preg_match fails when it encounters invalid UTF8 in $string
  348. if ( 1 === @preg_match( '/^./us', $string ) ) {
  349. return $string;
  350. }
  351. // Attempt to strip the bad chars if requested (not recommended)
  352. if ( $strip && function_exists( 'iconv' ) ) {
  353. return iconv( 'utf-8', 'utf-8', $string );
  354. }
  355. return '';
  356. }
  357. endif;
  358. if ( !function_exists('utf8_uri_encode') ) :
  359. /**
  360. * Encode the Unicode values to be used in the URI.
  361. *
  362. * @since 1.5.0
  363. *
  364. * @param string $utf8_string
  365. * @param int $length Max length of the string
  366. * @return string String with Unicode encoded for URI.
  367. */
  368. function utf8_uri_encode( $utf8_string, $length = 0 ) {
  369. $unicode = '';
  370. $values = array();
  371. $num_octets = 1;
  372. $unicode_length = 0;
  373. $string_length = strlen( $utf8_string );
  374. for ($i = 0; $i < $string_length; $i++ ) {
  375. $value = ord( $utf8_string[ $i ] );
  376. if ( $value < 128 ) {
  377. if ( $length && ( $unicode_length >= $length ) )
  378. break;
  379. $unicode .= chr($value);
  380. $unicode_length++;
  381. } else {
  382. if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3;
  383. $values[] = $value;
  384. if ( $length && ( $unicode_length + ($num_octets * 3) ) > $length )
  385. break;
  386. if ( count( $values ) == $num_octets ) {
  387. if ($num_octets == 3) {
  388. $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
  389. $unicode_length += 9;
  390. } else {
  391. $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
  392. $unicode_length += 6;
  393. }
  394. $values = array();
  395. $num_octets = 1;
  396. }
  397. }
  398. }
  399. return $unicode;
  400. }
  401. endif;
  402. if ( !function_exists('remove_accents') ) :
  403. /**
  404. * Converts all accent characters to ASCII characters.
  405. *
  406. * If there are no accent characters, then the string given is just returned.
  407. *
  408. * @since 1.2.1
  409. *
  410. * @param string $string Text that might have accent characters
  411. * @return string Filtered string with replaced "nice" characters.
  412. */
  413. function remove_accents($string) {
  414. if ( !preg_match('/[\x80-\xff]/', $string) )
  415. return $string;
  416. if (seems_utf8($string)) {
  417. $chars = array(
  418. // Decompositions for Latin-1 Supplement
  419. chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
  420. chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
  421. chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
  422. chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
  423. chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
  424. chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
  425. chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
  426. chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
  427. chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
  428. chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
  429. chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
  430. chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
  431. chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
  432. chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
  433. chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
  434. chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
  435. chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
  436. chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
  437. chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
  438. chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
  439. chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
  440. chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
  441. chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
  442. chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
  443. chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
  444. chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
  445. chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
  446. chr(195).chr(191) => 'y',
  447. // Decompositions for Latin Extended-A
  448. chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
  449. chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
  450. chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
  451. chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
  452. chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
  453. chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
  454. chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
  455. chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
  456. chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
  457. chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
  458. chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
  459. chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
  460. chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
  461. chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
  462. chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
  463. chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
  464. chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
  465. chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
  466. chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
  467. chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
  468. chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
  469. chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
  470. chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
  471. chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
  472. chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
  473. chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
  474. chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
  475. chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
  476. chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
  477. chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
  478. chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
  479. chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
  480. chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
  481. chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
  482. chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
  483. chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
  484. chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
  485. chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
  486. chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
  487. chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
  488. chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
  489. chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
  490. chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
  491. chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
  492. chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
  493. chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
  494. chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
  495. chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
  496. chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
  497. chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
  498. chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
  499. chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
  500. chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
  501. chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
  502. chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
  503. chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
  504. chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
  505. chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
  506. chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
  507. chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
  508. chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
  509. chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
  510. chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
  511. chr(197).chr(190) => 'z', chr(197).chr(191) => 's',
  512. // Euro Sign
  513. chr(226).chr(130).chr(172) => 'E',
  514. // GBP (Pound) Sign
  515. chr(194).chr(163) => '');
  516. $string = strtr($string, $chars);
  517. } else {
  518. // Assume ISO-8859-1 if not UTF-8
  519. $chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158)
  520. .chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194)
  521. .chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202)
  522. .chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210)
  523. .chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218)
  524. .chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227)
  525. .chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235)
  526. .chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243)
  527. .chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251)
  528. .chr(252).chr(253).chr(255);
  529. $chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy";
  530. $string = strtr($string, $chars['in'], $chars['out']);
  531. $double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254));
  532. $double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th');
  533. $string = str_replace($double_chars['in'], $double_chars['out'], $string);
  534. }
  535. return $string;
  536. }
  537. endif;
  538. // ! function sanitize_file_name()
  539. if ( !function_exists('sanitize_user') ) :
  540. /**
  541. * Sanitize username stripping out unsafe characters.
  542. *
  543. * If $strict is true, only alphanumeric characters (as well as _, space, ., -,
  544. * @) are returned.
  545. * Removes tags, octets, entities, and if strict is enabled, will remove all
  546. * non-ASCII characters. After sanitizing, it passes the username, raw username
  547. * (the username in the parameter), and the strict parameter as parameters for
  548. * the filter.
  549. *
  550. * @since 2.0.0
  551. * @uses apply_filters() Calls 'sanitize_user' hook on username, raw username,
  552. * and $strict parameter.
  553. *
  554. * @param string $username The username to be sanitized.
  555. * @param bool $strict If set limits $username to specific characters. Default false.
  556. * @return string The sanitized username, after passing through filters.
  557. */
  558. function sanitize_user( $username, $strict = false ) {
  559. $raw_username = $username;
  560. $username = wp_strip_all_tags($username);
  561. // Kill octets
  562. $username = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '', $username);
  563. $username = preg_replace('/&.+?;/', '', $username); // Kill entities
  564. // If strict, reduce to ASCII for max portability.
  565. if ( $strict )
  566. $username = preg_replace('|[^a-z0-9 _.\-@]|i', '', $username);
  567. // Consolidate contiguous whitespace
  568. $username = preg_replace('|\s+|', ' ', $username);
  569. return apply_filters('sanitize_user', $username, $raw_username, $strict);
  570. }
  571. endif;
  572. if ( !function_exists('sanitize_title') ) :
  573. /**
  574. * Sanitizes title or use fallback title.
  575. *
  576. * Specifically, HTML and PHP tags are stripped. Further actions can be added
  577. * via the plugin API. If $title is empty and $fallback_title is set, the latter
  578. * will be used.
  579. *
  580. * @since 1.0.0
  581. *
  582. * @param string $title The string to be sanitized.
  583. * @param string $fallback_title Optional. A title to use if $title is empty.
  584. * @return string The sanitized string.
  585. */
  586. function sanitize_title($title, $fallback_title = '') {
  587. $raw_title = $title;
  588. $title = strip_tags($title);
  589. $title = apply_filters('sanitize_title', $title, $raw_title);
  590. if ( '' === $title || false === $title )
  591. $title = $fallback_title;
  592. return $title;
  593. }
  594. endif;
  595. if ( !function_exists('sanitize_title_with_dashes') ) :
  596. /**
  597. * Sanitizes title, replacing whitespace with dashes.
  598. *
  599. * Limits the output to alphanumeric characters, underscore (_) and dash (-).
  600. * Whitespace becomes a dash.
  601. *
  602. * @since 1.2.0
  603. *
  604. * @param string $title The title to be sanitized.
  605. * @return string The sanitized title.
  606. */
  607. function sanitize_title_with_dashes($title) {
  608. $title = strip_tags($title);
  609. // Preserve escaped octets.
  610. $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
  611. // Remove percent signs that are not part of an octet.
  612. $title = str_replace('%', '', $title);
  613. // Restore octets.
  614. $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
  615. $title = remove_accents($title);
  616. if (seems_utf8($title)) {
  617. if (function_exists('mb_strtolower')) {
  618. $title = mb_strtolower($title, 'UTF-8');
  619. }
  620. $title = utf8_uri_encode($title, 200);
  621. }
  622. $title = strtolower($title);
  623. $title = preg_replace('/&.+?;/', '', $title); // kill entities
  624. $title = str_replace('.', '-', $title);
  625. $title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
  626. $title = preg_replace('/\s+/', '-', $title);
  627. $title = preg_replace('|-+|', '-', $title);
  628. $title = trim($title, '-');
  629. return $title;
  630. }
  631. endif;
  632. // ! function sanitize_sql_orderby()
  633. // ! function sanitize_html_class()
  634. // ! function convert_chars()
  635. // ! function funky_javascript_callback()
  636. // ! function funky_javascript_fix()
  637. // ! function balanceTags()
  638. if ( !function_exists( 'force_balance_tags' ) ) :
  639. /**
  640. * Balances tags of string using a modified stack.
  641. *
  642. * @since 2.0.4
  643. *
  644. * @author Leonard Lin <leonard@acm.org>
  645. * @license GPL v2.0
  646. * @copyright November 4, 2001
  647. * @version 1.1
  648. * @todo Make better - change loop condition to $text in 1.2
  649. * @internal Modified by Scott Reilly (coffee2code) 02 Aug 2004
  650. * 1.1 Fixed handling of append/stack pop order of end text
  651. * Added Cleaning Hooks
  652. * 1.0 First Version
  653. *
  654. * @param string $text Text to be balanced.
  655. * @return string Balanced text.
  656. */
  657. function force_balance_tags( $text ) {
  658. $tagstack = array(); $stacksize = 0; $tagqueue = ''; $newtext = '';
  659. $single_tags = array('br', 'hr', 'img', 'input'); //Known single-entity/self-closing tags
  660. $nestable_tags = array('blockquote', 'div', 'span'); //Tags that can be immediately nested within themselves
  661. # WP bug fix for comments - in case you REALLY meant to type '< !--'
  662. $text = str_replace('< !--', '< !--', $text);
  663. # WP bug fix for LOVE <3 (and other situations with '<' before a number)
  664. $text = preg_replace('#<([0-9]{1})#', '&lt;$1', $text);
  665. while (preg_match("/<(\/?\w*)\s*([^>]*)>/",$text,$regex)) {
  666. $newtext .= $tagqueue;
  667. $i = strpos($text,$regex[0]);
  668. $l = strlen($regex[0]);
  669. // clear the shifter
  670. $tagqueue = '';
  671. // Pop or Push
  672. if ( isset($regex[1][0]) && '/' == $regex[1][0] ) { // End Tag
  673. $tag = strtolower(substr($regex[1],1));
  674. // if too many closing tags
  675. if($stacksize <= 0) {
  676. $tag = '';
  677. //or close to be safe $tag = '/' . $tag;
  678. }
  679. // if stacktop value = tag close value then pop
  680. else if ($tagstack[$stacksize - 1] == $tag) { // found closing tag
  681. $tag = '</' . $tag . '>'; // Close Tag
  682. // Pop
  683. array_pop ($tagstack);
  684. $stacksize--;
  685. } else { // closing tag not at top, search for it
  686. for ($j=$stacksize-1;$j>=0;$j--) {
  687. if ($tagstack[$j] == $tag) {
  688. // add tag to tagqueue
  689. for ($k=$stacksize-1;$k>=$j;$k--){
  690. $tagqueue .= '</' . array_pop ($tagstack) . '>';
  691. $stacksize--;
  692. }
  693. break;
  694. }
  695. }
  696. $tag = '';
  697. }
  698. } else { // Begin Tag
  699. $tag = strtolower($regex[1]);
  700. // Tag Cleaning
  701. // If self-closing or '', don't do anything.
  702. if((substr($regex[2],-1) == '/') || ($tag == '')) {
  703. }
  704. // ElseIf it's a known single-entity tag but it doesn't close itself, do so
  705. elseif ( in_array($tag, $single_tags) ) {
  706. $regex[2] .= '/';
  707. } else { // Push the tag onto the stack
  708. // If the top of the stack is the same as the tag we want to push, close previous tag
  709. if (($stacksize > 0) && !in_array($tag, $nestable_tags) && ($tagstack[$stacksize - 1] == $tag)) {
  710. $tagqueue = '</' . array_pop ($tagstack) . '>';
  711. $stacksize--;
  712. }
  713. $stacksize = array_push ($tagstack, $tag);
  714. }
  715. // Attributes
  716. $attributes = $regex[2];
  717. if($attributes) {
  718. $attributes = ' '.$attributes;
  719. }
  720. $tag = '<'.$tag.$attributes.'>';
  721. //If already queuing a close tag, then put this tag on, too
  722. if ($tagqueue) {
  723. $tagqueue .= $tag;
  724. $tag = '';
  725. }
  726. }
  727. $newtext .= substr($text,0,$i) . $tag;
  728. $text = substr($text,$i+$l);
  729. }
  730. // Clear Tag Queue
  731. $newtext .= $tagqueue;
  732. // Add Remaining text
  733. $newtext .= $text;
  734. // Empty Stack
  735. while($x = array_pop($tagstack)) {
  736. $newtext .= '</' . $x . '>'; // Add remaining tags to close
  737. }
  738. // WP fix for the bug with HTML comments
  739. $newtext = str_replace("< !--","<!--",$newtext);
  740. $newtext = str_replace("< !--","< !--",$newtext);
  741. return $newtext;
  742. }
  743. endif;
  744. if ( !function_exists('format_to_edit') ) :
  745. /**
  746. * Acts on text which is about to be edited.
  747. *
  748. * Unless $richedit is set, it is simply a holder for the 'format_to_edit'
  749. * filter. If $richedit is set true htmlspecialchars() will be run on the
  750. * content, converting special characters to HTMl entities.
  751. *
  752. * @since 0.71
  753. *
  754. * @param string $content The text about to be edited.
  755. * @param bool $richedit Whether or not the $content should pass through htmlspecialchars(). Default false.
  756. * @return string The text after the filter (and possibly htmlspecialchars()) has been run.
  757. */
  758. function format_to_edit($content, $richedit = false) {
  759. $content = apply_filters('format_to_edit', $content);
  760. if (! $richedit )
  761. $content = htmlspecialchars($content);
  762. return $content;
  763. }
  764. endif;
  765. // !format_to_post()
  766. if ( !function_exists( 'zeroise' ) ) :
  767. /**
  768. * Add leading zeros when necessary.
  769. *
  770. * If you set the threshold to '4' and the number is '10', then you will get
  771. * back '0010'. If you set the number to '4' and the number is '5000', then you
  772. * will get back '5000'.
  773. *
  774. * Uses sprintf to append the amount of zeros based on the $threshold parameter
  775. * and the size of the number. If the number is large enough, then no zeros will
  776. * be appended.
  777. *
  778. * @since 0.71
  779. *
  780. * @param mixed $number Number to append zeros to if not greater than threshold.
  781. * @param int $threshold Digit places number needs to be to not have zeros added.
  782. * @return string Adds leading zeros to number if needed.
  783. */
  784. function zeroise($number, $threshold) {
  785. return sprintf('%0'.$threshold.'s', $number);
  786. }
  787. endif;
  788. if ( !function_exists( 'backslashit' ) ) :
  789. /**
  790. * Adds backslashes before letters and before a number at the start of a string.
  791. *
  792. * @since 0.71
  793. *
  794. * @param string $string Value to which backslashes will be added.
  795. * @return string String with backslashes inserted.
  796. */
  797. function backslashit($string) {
  798. $string = preg_replace('/^([0-9])/', '\\\\\\\\\1', $string);
  799. $string = preg_replace('/([a-z])/i', '\\\\\1', $string);
  800. return $string;
  801. }
  802. endif;
  803. if ( !function_exists( 'trailingslashit' ) ) :
  804. /**
  805. * Appends a trailing slash.
  806. *
  807. * Will remove trailing slash if it exists already before adding a trailing
  808. * slash. This prevents double slashing a string or path.
  809. *
  810. * The primary use of this is for paths and thus should be used for paths. It is
  811. * not restricted to paths and offers no specific path support.
  812. *
  813. * @since 1.2.0
  814. * @uses untrailingslashit() Unslashes string if it was slashed already.
  815. *
  816. * @param string $string What to add the trailing slash to.
  817. * @return string String with trailing slash added.
  818. */
  819. function trailingslashit($string) {
  820. return untrailingslashit($string) . '/';
  821. }
  822. endif;
  823. if ( !function_exists( 'untrailingslashit' ) ) :
  824. /**
  825. * Removes trailing slash if it exists.
  826. *
  827. * The primary use of this is for paths and thus should be used for paths. It is
  828. * not restricted to paths and offers no specific path support.
  829. *
  830. * @since 2.2.0
  831. *
  832. * @param string $string What to remove the trailing slash from.
  833. * @return string String without the trailing slash.
  834. */
  835. function untrailingslashit($string) {
  836. return rtrim($string, '/');
  837. }
  838. endif;
  839. // ! function addslashes_gpc()
  840. if ( !function_exists('stripslashes_deep') ) :
  841. /**
  842. * Navigates through an array and removes slashes from the values.
  843. *
  844. * If an array is passed, the array_map() function causes a callback to pass the
  845. * value back to the function. The slashes from this value will removed.
  846. *
  847. * @since 2.0.0
  848. *
  849. * @param array|string $value The array or string to be striped.
  850. * @return array|string Stripped array (or string in the callback).
  851. */
  852. function stripslashes_deep($value) {
  853. $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
  854. return $value;
  855. }
  856. endif;
  857. if ( !function_exists( 'urlencode_deep' ) ) :
  858. /**
  859. * Navigates through an array and encodes the values to be used in a URL.
  860. *
  861. * Uses a callback to pass the value of the array back to the function as a
  862. * string.
  863. *
  864. * @since 2.2.0
  865. *
  866. * @param array|string $value The array or string to be encoded.
  867. * @return array|string $value The encoded array (or string from the callback).
  868. */
  869. function urlencode_deep($value) {
  870. $value = is_array($value) ? array_map('urlencode_deep', $value) : urlencode($value);
  871. return $value;
  872. }
  873. endif;
  874. // ! function antispambot()
  875. if ( !function_exists( '_make_url_clickable_cb' ) ) :
  876. /**
  877. * Callback to convert URI match to HTML A element.
  878. *
  879. * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link
  880. * make_clickable()}.
  881. *
  882. * @since 2.3.2
  883. * @access private
  884. *
  885. * @param array $matches Single Regex Match.
  886. * @return string HTML A element with URI address.
  887. */
  888. function _make_url_clickable_cb($matches) {
  889. $url = $matches[2];
  890. $url = esc_url($url);
  891. if ( empty($url) )
  892. return $matches[0];
  893. return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>";
  894. }
  895. endif;
  896. if ( !function_exists( '_make_web_ftp_clickable_cb' ) ) :
  897. /**
  898. * Callback to convert URL match to HTML A element.
  899. *
  900. * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link
  901. * make_clickable()}.
  902. *
  903. * @since 2.3.2
  904. * @access private
  905. *
  906. * @param array $matches Single Regex Match.
  907. * @return string HTML A element with URL address.
  908. */
  909. function _make_web_ftp_clickable_cb($matches) {
  910. $ret = '';
  911. $dest = $matches[2];
  912. $dest = 'http://' . $dest;
  913. $dest = esc_url($dest);
  914. if ( empty($dest) )
  915. return $matches[0];
  916. // removed trailing [.,;:)] from URL
  917. if ( in_array( substr($dest, -1), array('.', ',', ';', ':', ')') ) === true ) {
  918. $ret = substr($dest, -1);
  919. $dest = substr($dest, 0, strlen($dest)-1);
  920. }
  921. return $matches[1] . "<a href=\"$dest\" rel=\"nofollow\">$dest</a>$ret";
  922. }
  923. endif;
  924. if ( !function_exists( '_make_email_clickable_cb' ) ) :
  925. /**
  926. * Callback to convert email address match to HTML A element.
  927. *
  928. * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link
  929. * make_clickable()}.
  930. *
  931. * @since 2.3.2
  932. * @access private
  933. *
  934. * @param array $matches Single Regex Match.
  935. * @return string HTML A element with email address.
  936. */
  937. function _make_email_clickable_cb($matches) {
  938. $email = $matches[2] . '@' . $matches[3];
  939. return $matches[1] . "<a href=\"mailto:$email\">$email</a>";
  940. }
  941. endif;
  942. if ( !function_exists( 'make_clickable' ) ) :
  943. /**
  944. * Convert plaintext URI to HTML links.
  945. *
  946. * Converts URI, www and ftp, and email addresses. Finishes by fixing links
  947. * within links.
  948. *
  949. * @since 0.71
  950. *
  951. * @param string $ret Content to convert URIs.
  952. * @return string Content with converted URIs.
  953. */
  954. function make_clickable($ret) {
  955. $ret = ' ' . $ret;
  956. // in testing, using arrays here was found to be faster
  957. $ret = preg_replace_callback('#(?<=[\s>])(\()?([\w]+?://(?:[\w\\x80-\\xff\#$%&~/=?@\[\](+-]|[.,;:](?![\s<]|(\))?([\s]|$))|(?(1)\)(?![\s<.,;:]|$)|\)))+)#is', '_make_url_clickable_cb', $ret);
  958. $ret = preg_replace_callback('#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $ret);
  959. $ret = preg_replace_callback('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret);
  960. // this one is not in an array because we need it to run last, for cleanup of accidental links within links
  961. $ret = preg_replace("#(<a( [^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i", "$1$3</a>", $ret);
  962. $ret = trim($ret);
  963. return $ret;
  964. }
  965. endif;
  966. // ! function wp_rel_nofollow()
  967. // ! function wp_rel_nofollow_callback()
  968. // ! function translate_smiley()
  969. // ! function convert_smilies()
  970. if ( !function_exists('is_email') ) :
  971. /**
  972. * Verifies that an email is valid.
  973. *
  974. * Does not grok i18n domains. Not RFC compliant.
  975. *
  976. * @since 0.71
  977. *
  978. * @param string $email Email address to verify.
  979. * @param boolean $check_dns Whether to check the DNS for the domain using checkdnsrr().
  980. * @return string|bool Either false or the valid email address.
  981. */
  982. function is_email( $email, $check_dns = false ) {
  983. // Test for the minimum length the email can be
  984. if ( strlen( $email ) < 3 ) {
  985. return apply_filters( 'is_email', false, $email, 'email_too_short' );
  986. }
  987. // Test for an @ character after the first position
  988. if ( strpos( $email, '@', 1 ) === false ) {
  989. return apply_filters( 'is_email', false, $email, 'email_no_at' );
  990. }
  991. // Split out the local and domain parts
  992. list( $local, $domain ) = explode( '@', $email, 2 );
  993. // LOCAL PART
  994. // Test for invalid characters
  995. if ( !preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) {
  996. return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );
  997. }
  998. // DOMAIN PART
  999. // Test for sequences of periods
  1000. if ( preg_match( '/\.{2,}/', $domain ) ) {
  1001. return apply_filters( 'is_email', false, $email, 'domain_period_sequence' );
  1002. }
  1003. // Test for leading and trailing periods and whitespace
  1004. if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) {
  1005. return apply_filters( 'is_email', false, $email, 'domain_period_limits' );
  1006. }
  1007. // Split the domain into subs
  1008. $subs = explode( '.', $domain );
  1009. // Assume the domain will have at least two subs
  1010. if ( 2 > count( $subs ) ) {
  1011. return apply_filters( 'is_email', false, $email, 'domain_no_periods' );
  1012. }
  1013. // Loop through each sub
  1014. foreach ( $subs as $sub ) {
  1015. // Test for leading and trailing hyphens and whitespace
  1016. if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) {
  1017. return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' );
  1018. }
  1019. // Test for invalid characters
  1020. if ( !preg_match('/^[a-z0-9-]+$/i', $sub ) ) {
  1021. return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' );
  1022. }
  1023. }
  1024. // DNS
  1025. // Check the domain has a valid MX and A resource record
  1026. if ( $check_dns && function_exists( 'checkdnsrr' ) && !( checkdnsrr( $domain . '.', 'MX' ) || checkdnsrr( $domain . '.', 'A' ) ) ) {
  1027. return apply_filters( 'is_email', false, $email, 'dns_no_rr' );
  1028. }
  1029. // Congratulations your email made it!
  1030. return apply_filters( 'is_email', $email, $email, null );
  1031. }
  1032. endif;
  1033. // ! function wp_iso_descrambler()
  1034. // ! function get_gmt_from_date()
  1035. // ! function get_date_from_gmt()
  1036. // ! function iso8601_timezone_to_offset()
  1037. // ! function iso8601_to_datetime()
  1038. // ! popuplinks()
  1039. if ( !function_exists('sanitize_email') ) :
  1040. /**
  1041. * Strips out all characters that are not allowable in an email.
  1042. *
  1043. * @since 1.5.0
  1044. *
  1045. * @param string $email Email address to filter.
  1046. * @return string Filtered email address.
  1047. */
  1048. function sanitize_email( $email ) {
  1049. // Test for the minimum length the email can be
  1050. if ( strlen( $email ) < 3 ) {
  1051. return apply_filters( 'sanitize_email', '', $email, 'email_too_short' );
  1052. }
  1053. // Test for an @ character after the first position
  1054. if ( strpos( $email, '@', 1 ) === false ) {
  1055. return apply_filters( 'sanitize_email', '', $email, 'email_no_at' );
  1056. }
  1057. // Split out the local and domain parts
  1058. list( $local, $domain ) = explode( '@', $email, 2 );
  1059. // LOCAL PART
  1060. // Test for invalid characters
  1061. $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local );
  1062. if ( '' === $local ) {
  1063. return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' );
  1064. }
  1065. // DOMAIN PART
  1066. // Test for sequences of periods
  1067. $domain = preg_replace( '/\.{2,}/', '', $domain );
  1068. if ( '' === $domain ) {
  1069. return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' );
  1070. }
  1071. // Test for leading and trailing periods and whitespace
  1072. $domain = trim( $domain, " \t\n\r\0\x0B." );
  1073. if ( '' === $domain ) {
  1074. return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' );
  1075. }
  1076. // Split the domain into subs
  1077. $subs = explode( '.', $domain );
  1078. // Assume the domain will have at least two subs
  1079. if ( 2 > count( $subs ) ) {
  1080. return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' );
  1081. }
  1082. // Create an array that will contain valid subs
  1083. $new_subs = array();
  1084. // Loop through each sub
  1085. foreach ( $subs as $sub ) {
  1086. // Test for leading and trailing hyphens
  1087. $sub = trim( $sub, " \t\n\r\0\x0B-" );
  1088. // Test for invalid characters
  1089. $sub = preg_replace( '/^[^a-z0-9-]+$/i', '', $sub );
  1090. // If there's anything left, add it to the valid subs
  1091. if ( '' !== $sub ) {
  1092. $new_subs[] = $sub;
  1093. }
  1094. }
  1095. // If there aren't 2 or more valid subs
  1096. if ( 2 > count( $new_subs ) ) {
  1097. return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' );
  1098. }
  1099. // Join valid subs into the new domain
  1100. $domain = join( '.', $new_subs );
  1101. // Put the email back together
  1102. $email = $local . '@' . $domain;
  1103. // Congratulations your email made it!
  1104. return apply_filters( 'sanitize_email', $email, $email, null );
  1105. }
  1106. endif;
  1107. // ! function human_time_diff()
  1108. // ! function wp_trim_excerpt()
  1109. if ( !function_exists( 'ent2ncr' ) ) : // Current at [WP9840]
  1110. /**
  1111. * Converts named entities into numbered entities.
  1112. *
  1113. * @since 1.5.1
  1114. *
  1115. * @param string $text The text within which entities will be converted.
  1116. * @return string Text with converted entities.
  1117. */
  1118. function ent2ncr($text) {
  1119. $to_ncr = array(
  1120. '&quot;' => '&#34;',
  1121. '&amp;' => '&#38;',
  1122. '&frasl;' => '&#47;',
  1123. '&lt;' => '&#60;',
  1124. '&gt;' => '&#62;',
  1125. '|' => '&#124;',
  1126. '&nbsp;' => '&#160;',
  1127. '&iexcl;' => '&#161;',
  1128. '&cent;' => '&#162;',
  1129. '&pound;' => '&#163;',
  1130. '&curren;' => '&#164;',
  1131. '&yen;' => '&#165;',
  1132. '&brvbar;' => '&#166;',
  1133. '&brkbar;' => '&#166;',
  1134. '&sect;' => '&#167;',
  1135. '&uml;' => '&#168;',
  1136. '&die;' => '&#168;',
  1137. '&copy;' => '&#169;',
  1138. '&ordf;' => '&#170;',
  1139. '&laquo;' => '&#171;',
  1140. '&not;' => '&#172;',
  1141. '&shy;' => '&#173;',
  1142. '&reg;' => '&#174;',
  1143. '&macr;' => '&#175;',
  1144. '&hibar;' => '&#175;',
  1145. '&deg;' => '&#176;',
  1146. '&plusmn;' => '&#177;',
  1147. '&sup2;' => '&#178;',
  1148. '&sup3;' => '&#179;',
  1149. '&acute;' => '&#180;',
  1150. '&micro;' => '&#181;',
  1151. '&para;' => '&#182;',
  1152. '&middot;' => '&#183;',
  1153. '&cedil;' => '&#184;',
  1154. '&sup1;' => '&#185;',
  1155. '&ordm;' => '&#186;',
  1156. '&raquo;' => '&#187;',
  1157. '&frac14;' => '&#188;',
  1158. '&frac12;' => '&#189;',
  1159. '&frac34;' => '&#190;',
  1160. '&iquest;' => '&#191;',
  1161. '&Agrave;' => '&#192;',
  1162. '&Aacute;' => '&#193;',
  1163. '&Acirc;' => '&#194;',
  1164. '&Atilde;' => '&#195;',
  1165. '&Auml;' => '&#196;',
  1166. '&Aring;' => '&#197;',
  1167. '&AElig;' => '&#198;',
  1168. '&Ccedil;' => '&#199;',
  1169. '&Egrave;' => '&#200;',
  1170. '&Eacute;' => '&#201;',
  1171. '&Ecirc;' => '&#202;',
  1172. '&Euml;' => '&#203;',
  1173. '&Igrave;' => '&#204;',
  1174. '&Iacute;' => '&#205;',
  1175. '&Icirc;' => '&#206;',
  1176. '&Iuml;' => '&#207;',
  1177. '&ETH;' => '&#208;',
  1178. '&Ntilde;' => '&#209;',
  1179. '&Ograve;' => '&#210;',
  1180. '&Oacute;' => '&#211;',
  1181. '&Ocirc;' => '&#212;',
  1182. '&Otilde;' => '&#213;',
  1183. '&Ouml;' => '&#214;',
  1184. '&times;' => '&#215;',
  1185. '&Oslash;' => '&#216;',
  1186. '&Ugrave;' => '&#217;',
  1187. '&Uacute;' => '&#218;',
  1188. '&Ucirc;' => '&#219;',
  1189. '&Uuml;' => '&#220;',
  1190. '&Yacute;' => '&#221;',
  1191. '&THORN;' => '&#222;',
  1192. '&szlig;' => '&#223;',
  1193. '&agrave;' => '&#224;',
  1194. '&aacute;' => '&#225;',
  1195. '&acirc;' => '&#226;',
  1196. '&atilde;' => '&#227;',
  1197. '&auml;' => '&#228;',
  1198. '&aring;' => '&#229;',
  1199. '&aelig;' => '&#230;',
  1200. '&ccedil;' => '&#231;',
  1201. '&egrave;' => '&#232;',
  1202. '&eacute;' => '&#233;',
  1203. '&ecirc;' => '&#234;',
  1204. '&euml;' => '&#235;',
  1205. '&igrave;' => '&#236;',
  1206. '&iacute;' => '&#237;',
  1207. '&icirc;' => '&#238;',
  1208. '&iuml;' => '&#239;',
  1209. '&eth;' => '&#240;',
  1210. '&ntilde;' => '&#241;',
  1211. '&ograve;' => '&#242;',
  1212. '&oacute;' => '&#243;',
  1213. '&ocirc;' => '&#244;',
  1214. '&otilde;' => '&#245;',
  1215. '&ouml;' => '&#246;',
  1216. '&divide;' => '&#247;',
  1217. '&oslash;' => '&#248;',
  1218. '&ugrave;' => '&#249;',
  1219. '&uacute;' => '&#250;',
  1220. '&ucirc;' => '&#251;',
  1221. '&uuml;' => '&#252;',
  1222. '&yacute;' => '&#253;',
  1223. '&thorn;' => '&#254;',
  1224. '&yuml;' => '&#255;',
  1225. '&OElig;' => '&#338;',
  1226. '&oelig;' => '&#339;',
  1227. '&Scaron;' => '&#352;',
  1228. '&scaron;' => '&#353;',
  1229. '&Yuml;' => '&#376;',
  1230. '&fnof;' => '&#402;',
  1231. '&circ;' => '&#710;',
  1232. '&tilde;' => '&#732;',
  1233. '&Alpha;' => '&#913;',
  1234. '&Beta;' => '&#914;',
  1235. '&Gamma;' => '&#915;',
  1236. '&Delta;' => '&#916;',
  1237. '&Epsilon;' => '&#917;',
  1238. '&Zeta;' => '&#918;',
  1239. '&Eta;' => '&#919;',
  1240. '&Theta;' => '&#920;',
  1241. '&Iota;' => '&#921;',
  1242. '&Kappa;' => '&#922;',
  1243. '&Lambda;' => '&#923;',
  1244. '&Mu;' => '&#924;',
  1245. '&Nu;' => '&#925;',
  1246. '&Xi;' => '&#926;',
  1247. '&Omicron;' => '&#927;',
  1248. '&Pi;' => '&#928;',
  1249. '&Rho;' => '&#929;',
  1250. '&Sigma;' => '&#931;',
  1251. '&Tau;' => '&#932;',
  1252. '&Upsilon;' => '&#933;',
  1253. '&Phi;' => '&#934;',
  1254. '&Chi;' => '&#935;',
  1255. '&Psi;' => '&#936;',
  1256. '&Omega;' => '&#937;',
  1257. '&alpha;' => '&#945;',
  1258. '&beta;' => '&#946;',
  1259. '&gamma;' => '&#947;',
  1260. '&delta;' => '&#948;',
  1261. '&epsilon;' => '&#949;',
  1262. '&zeta;' => '&#950;',
  1263. '&eta;' => '&#951;',
  1264. '&theta;' => '&#952;',
  1265. '&iota;' => '&#953;',
  1266. '&kappa;' => '&#954;',
  1267. '&lambda;' => '&#955;',
  1268. '&mu;' => '&#956;',
  1269. '&nu;' => '&#957;',
  1270. '&xi;' => '&#958;',
  1271. '&omicron;' => '&#959;',
  1272. '&pi;' => '&#960;',
  1273. '&rho;' => '&#961;',
  1274. '&sigmaf;' => '&#962;',
  1275. '&sigma;' => '&#963;',
  1276. '&tau;' => '&#964;',
  1277. '&upsilon;' => '&#965;',
  1278. '&phi;' => '&#966;',
  1279. '&chi;' => '&#967;',
  1280. '&psi;' => '&#968;',
  1281. '&omega;' => '&#969;',
  1282. '&thetasym;' => '&#977;',
  1283. '&upsih;' => '&#978;',
  1284. '&piv;' => '&#982;',
  1285. '&ensp;' => '&#8194;',
  1286. '&emsp;' => '&#8195;',
  1287. '&thinsp;' => '&#8201;',
  1288. '&zwnj;' => '&#8204;',
  1289. '&zwj;' => '&#8205;',
  1290. '&lrm;' => '&#8206;',
  1291. '&rlm;' => '&#8207;',
  1292. '&ndash;' => '&#8211;',
  1293. '&mdash;' => '&#8212;',
  1294. '&lsquo;' => '&#8216;',
  1295. '&rsquo;' => '&#8217;',
  1296. '&sbquo;' => '&#8218;',
  1297. '&ldquo;' => '&#8220;',
  1298. '&rdquo;' => '&#8221;',
  1299. '&bdquo;' => '&#8222;',
  1300. '&dagger;' => '&#8224;',
  1301. '&Dagger;' => '&#8225;',
  1302. '&bull;' => '&#8226;',
  1303. '&hellip;' => '&#8230;',
  1304. '&permil;' => '&#8240;',
  1305. '&prime;' => '&#8242;',
  1306. '&Prime;' => '&#8243;',
  1307. '&lsaquo;' => '&#8249;',
  1308. '&rsaquo;' => '&#8250;',
  1309. '&oline;' => '&#8254;',
  1310. '&frasl;' => '&#8260;',
  1311. '&euro;' => '&#8364;',
  1312. '&image;' => '&#8465;',
  1313. '&weierp;' => '&#8472;',
  1314. '&real;' => '&#8476;',
  1315. '&trade;' => '&#8482;',
  1316. '&alefsym;' => '&#8501;',
  1317. '&crarr;' => '&#8629;',
  1318. '&lArr;' => '&#8656;',
  1319. '&uArr;' => '&#8657;',
  1320. '&rArr;' => '&#8658;',
  1321. '&dArr;' => '&#8659;',
  1322. '&hArr;' => '&#8660;',
  1323. '&forall;' => '&#8704;',
  1324. '&part;' => '&#8706;',
  1325. '&exist;' => '&#8707;',
  1326. '&empty;' => '&#8709;',
  1327. '&nabla;' => '&#8711;',
  1328. '&isin;' => '&#8712;',
  1329. '&notin;' => '&#8713;',
  1330. '&ni;' => '&#8715;',
  1331. '&prod;' => '&#8719;',
  1332. '&sum;' => '&#8721;',
  1333. '&minus;' => '&#8722;',
  1334. '&lowast;' => '&#8727;',
  1335. '&radic;' => '&#8730;',
  1336. '&prop;' => '&#8733;',
  1337. '&infin;' => '&#8734;',
  1338. '&ang;' => '&#8736;',
  1339. '&and;' => '&#8743;',
  1340. '&or;' => '&#8744;',
  1341. '&cap;' => '&#8745;',
  1342. '&cup;' => '&#8746;',
  1343. '&int;' => '&#8747;',
  1344. '&there4;' => '&#8756;',
  1345. '&sim;' => '&#8764;',
  1346. '&cong;' => '&#8773;',
  1347. '&asymp;' => '&#8776;',
  1348. '&ne;' => '&#8800;',
  1349. '&equiv;' => '&#8801;',
  1350. '&le;' => '&#8804;',
  1351. '&ge;' => '&#8805;',
  1352. '&sub;' => '&#8834;',
  1353. '&sup;' => '&#8835;',
  1354. '&nsub;' => '&#8836;',
  1355. '&sube;' => '&#8838;',
  1356. '&supe;' => '&#8839;',
  1357. '&oplus;' => '&#8853;',
  1358. '&otimes;' => '&#8855;',
  1359. '&perp;' => '&#8869;',
  1360. '&sdot;' => '&#8901;',
  1361. '&lceil;' => '&#8968;',
  1362. '&rceil;' => '&#8969;',
  1363. '&lfloor;' => '&#8970;',
  1364. '&rfloor;' => '&#8971;',
  1365. '&lang;' => '&#9001;',
  1366. '&rang;' => '&#9002;',
  1367. '&larr;' => '&#8592;',
  1368. '&uarr;' => '&#8593;',
  1369. '&rarr;' => '&#8594;',
  1370. '&darr;' => '&#8595;',
  1371. '&harr;' => '&#8596;',
  1372. '&loz;' => '&#9674;',
  1373. '&spades;' => '&#9824;',
  1374. '&clubs;' => '&#9827;',
  1375. '&hearts;' => '&#9829;',
  1376. '&diams;' => '&#9830;'
  1377. );
  1378. return str_replace( array_keys($to_ncr), array_values($to_ncr), $text );
  1379. }
  1380. endif;
  1381. // ! function wp_richedit_pre()
  1382. // ! function wp_htmledit_pre()
  1383. if ( !function_exists('clean_url') ) :
  1384. /**
  1385. * Checks and cleans a URL.
  1386. *
  1387. * A number of characters are removed from the URL. If the URL is for displaying
  1388. * (the default behaviour) amperstands are also replaced. The 'esc_url' filter
  1389. * is applied to the returned cleaned URL.
  1390. *
  1391. * @since 1.2.0
  1392. * @uses wp_kses_bad_protocol() To only permit protocols in the URL set
  1393. * via $protocols or the common ones set in the function.
  1394. *
  1395. * @param string $url The URL to be cleaned.
  1396. * @param array $protocols Optional. An array of acceptable protocols.
  1397. * Defaults to 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp…

Large files files are truncated, but you can click here to view the full file