PageRenderTime 168ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/buddypress/bp-forums/bbpress/bb-includes/backpress/functions.formatting.php

https://bitbucket.org/openfarmtech/weblog-content
PHP | 1795 lines | 1113 code | 146 blank | 536 comment | 168 complexity | c2cf8acd0b3b1f99d59da49396a2e5c8 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.0, LGPL-3.0, BSD-3-Clause, GPL-3.0, LGPL-2.1, AGPL-3.0, CC-BY-SA-3.0

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

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

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