PageRenderTime 68ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/www/forum/bb-includes/wp-functions.php

https://github.com/micz/elencode
PHP | 1455 lines | 1211 code | 148 blank | 96 comment | 241 complexity | e30f3f08432c4e4af420badef502f118 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. if ( !function_exists('stripslashes_deep') ) :
  3. function stripslashes_deep($value) { // [5261]
  4. return is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
  5. }
  6. endif;
  7. /* Formatting */
  8. if ( !function_exists( 'clean_url' ) ) : // [WP6182]
  9. function clean_url( $url, $protocols = null, $context = 'display' ) {
  10. $original_url = $url;
  11. if ('' == $url) return $url;
  12. $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@]|i', '', $url);
  13. $strip = array('%0d', '%0a');
  14. $url = str_replace($strip, '', $url);
  15. $url = str_replace(';//', '://', $url);
  16. /* If the URL doesn't appear to contain a scheme, we
  17. * presume it needs http:// appended (unless a relative
  18. * link starting with / or a php file).
  19. */
  20. if ( strpos($url, ':') === false &&
  21. substr( $url, 0, 1 ) != '/' && !preg_match('/^[a-z0-9-]+?\.php/i', $url) )
  22. $url = 'http://' . $url;
  23. // Replace ampersands ony when displaying.
  24. if ( 'display' == $context )
  25. $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $url);
  26. if ( !is_array($protocols) )
  27. $protocols = array('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet');
  28. if ( wp_kses_bad_protocol( $url, $protocols ) != $url )
  29. return '';
  30. return apply_filters('clean_url', $url, $original_url, $context);
  31. }
  32. endif;
  33. if ( !function_exists('clean_pre') ) : // [WP6102]
  34. // Accepts matches array from preg_replace_callback in wpautop()
  35. // or a string
  36. function clean_pre($matches) {
  37. if ( is_array($matches) )
  38. $text = $matches[1] . $matches[2] . "</pre>";
  39. else
  40. $text = $matches;
  41. $text = str_replace('<br />', '', $text);
  42. $text = str_replace('<p>', "\n", $text);
  43. $text = str_replace('</p>', '', $text);
  44. return $text;
  45. }
  46. endif;
  47. if ( !function_exists('wp_specialchars') ) :
  48. function wp_specialchars( $text, $quotes = 0 ) { // [WP4451]
  49. // Like htmlspecialchars except don't double-encode HTML entities
  50. $text = str_replace('&&', '&#038;&', $text);
  51. $text = str_replace('&&', '&#038;&', $text);
  52. $text = preg_replace('/&(?:$|([^#])(?![a-z1-4]{1,8};))/', '&#038;$1', $text);
  53. $text = str_replace('<', '&lt;', $text);
  54. $text = str_replace('>', '&gt;', $text);
  55. if ( 'double' === $quotes ) {
  56. $text = str_replace('"', '&quot;', $text);
  57. } elseif ( 'single' === $quotes ) {
  58. $text = str_replace("'", '&#039;', $text);
  59. } elseif ( $quotes ) {
  60. $text = str_replace('"', '&quot;', $text);
  61. $text = str_replace("'", '&#039;', $text);
  62. }
  63. return $text;
  64. }
  65. endif;
  66. if ( !function_exists( 'wp_entities' ) ) :
  67. /**
  68. * Converts all special characters into their HTML entities.
  69. *
  70. * $quote_style can be set to ENT_COMPAT to encode " to
  71. * &quot;, or ENT_QUOTES to do both. Default is ENT_NOQUOTES where no quotes are encoded.
  72. *
  73. * @since 2.8
  74. *
  75. * @param string $string The text which is to be encoded.
  76. * @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. Default is ENT_NOQUOTES.
  77. * @param string $charset Optional. The character encoding of the string. Default is false.
  78. * @param boolean $double_encode Optional. Whether or not to encode existing html entities. Default is false.
  79. * @return string The encoded text with HTML entities.
  80. */
  81. function wp_entities( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false )
  82. {
  83. if ( 0 === strlen( $string ) ) {
  84. return '';
  85. }
  86. if ( !$charset ) {
  87. $charset = bb_get_option( 'charset' );
  88. }
  89. if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) ) {
  90. $charset = 'UTF-8';
  91. }
  92. if ( version_compare( PHP_VERSION, '5.2.3', '>=' ) ) {
  93. $string = htmlentities( $string, $quote_style, $charset, $double_encode );
  94. } else {
  95. // Handle double encoding for PHP versions that don't support it in htmlentities()
  96. if ( !$double_encode ) {
  97. // Multi-byte charsets are not supported below PHP 5.0.0
  98. // 'cp866', 'cp1251', 'KOI8-R' charsets are not supported below PHP 4.3.2
  99. $string = html_entity_decode( $string, $quote_style, $charset );
  100. }
  101. // 'cp866', 'cp1251', 'KOI8-R' charsets are not supported below PHP 4.3.2
  102. $string = htmlentities( $string, $quote_style, $charset );
  103. }
  104. return $string;
  105. }
  106. endif;
  107. if ( !function_exists( 'wp_check_invalid_utf8' ) ) :
  108. /**
  109. * Checks for invalid UTF8 in a string.
  110. *
  111. * @since 2.8
  112. *
  113. * @param string $string The text which is to be checked.
  114. * @param boolean $strip Optional. Whether to attempt to strip out invalid UTF8. Default is false.
  115. * @return string The checked text.
  116. */
  117. function wp_check_invalid_utf8( $string, $strip = false )
  118. {
  119. if ( 0 === strlen( $string ) ) {
  120. return '';
  121. }
  122. if ( !in_array( bb_get_option( 'charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) {
  123. return $string;
  124. }
  125. // preg_match fails when it encounters invalid UTF8 in $str
  126. if ( 1 === @preg_match( '@^.@us', $string ) ) {
  127. return $string;
  128. }
  129. if ( $strip && function_exists( 'iconv' ) ) {
  130. return iconv( 'utf-8', 'utf-8', $string );
  131. } else {
  132. return '';
  133. }
  134. }
  135. endif;
  136. if ( !function_exists('utf8_uri_encode') ) : // [WP6314]
  137. function utf8_uri_encode( $utf8_string, $length = 0 ) {
  138. $unicode = '';
  139. $values = array();
  140. $num_octets = 1;
  141. $unicode_length = 0;
  142. $string_length = strlen( $utf8_string );
  143. for ($i = 0; $i < $string_length; $i++ ) {
  144. $value = ord( $utf8_string[ $i ] );
  145. if ( $value < 128 ) {
  146. if ( $length && ( $unicode_length >= $length ) )
  147. break;
  148. $unicode .= chr($value);
  149. $unicode_length++;
  150. } else {
  151. if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3;
  152. $values[] = $value;
  153. if ( $length && ( $unicode_length + ($num_octets * 3) ) > $length )
  154. break;
  155. if ( count( $values ) == $num_octets ) {
  156. if ($num_octets == 3) {
  157. $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
  158. $unicode_length += 9;
  159. } else {
  160. $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
  161. $unicode_length += 6;
  162. }
  163. $values = array();
  164. $num_octets = 1;
  165. }
  166. }
  167. }
  168. return $unicode;
  169. }
  170. endif;
  171. if ( !function_exists('sanitize_user') ) : // [WP3795]
  172. function sanitize_user( $username, $strict = false ) {
  173. $raw_username = $username;
  174. $username = strip_tags($username);
  175. // Kill octets
  176. $username = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '', $username);
  177. $username = preg_replace('/&.+?;/', '', $username); // Kill entities
  178. // If strict, reduce to ASCII for max portability.
  179. if ( $strict )
  180. $username = preg_replace('|[^a-z0-9 _.\-@]|i', '', $username);
  181. return apply_filters('sanitize_user', $username, $raw_username, $strict);
  182. }
  183. endif;
  184. // Escape single quotes, specialchar double quotes, and fix line endings.
  185. if ( !function_exists('js_escape') ) : // [WP5734]
  186. function js_escape($text) {
  187. $safe_text = wp_specialchars($text, 'double');
  188. $safe_text = preg_replace('/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes($safe_text));
  189. $safe_text = preg_replace("/\r?\n/", "\\n", addslashes($safe_text));
  190. return apply_filters('js_escape', $safe_text, $text);
  191. }
  192. endif;
  193. // Escaping for HTML attributes
  194. if ( !function_exists('attribute_escape') ) :
  195. function attribute_escape($text) { // Not like WordPress - uses wp_check_invalid_utf8() and wp_entities()
  196. $safe_text = wp_check_invalid_utf8( $text );
  197. $safe_text = wp_entities( $safe_text, ENT_QUOTES );
  198. return apply_filters('attribute_escape', $safe_text, $text);
  199. }
  200. endif;
  201. /*
  202. force_balance_tags
  203. Balances Tags of string using a modified stack.
  204. @param text Text to be balanced
  205. @param force Forces balancing, ignoring the value of the option
  206. @return Returns balanced text
  207. @author Leonard Lin (leonard@acm.org)
  208. @version v1.1
  209. @date November 4, 2001
  210. @license GPL v2.0
  211. @notes
  212. @changelog
  213. --- Modified by Scott Reilly (coffee2code) 02 Aug 2004
  214. 1.2 ***TODO*** Make better - change loop condition to $text
  215. 1.1 Fixed handling of append/stack pop order of end text
  216. Added Cleaning Hooks
  217. 1.0 First Version
  218. */
  219. if ( !function_exists( 'force_balance_tags' ) ) : // [WP5805]
  220. function force_balance_tags( $text ) {
  221. $tagstack = array(); $stacksize = 0; $tagqueue = ''; $newtext = '';
  222. $single_tags = array('br', 'hr', 'img', 'input'); //Known single-entity/self-closing tags
  223. $nestable_tags = array('blockquote', 'div', 'span'); //Tags that can be immediately nested within themselves
  224. # WP bug fix for comments - in case you REALLY meant to type '< !--'
  225. $text = str_replace('< !--', '< !--', $text);
  226. # WP bug fix for LOVE <3 (and other situations with '<' before a number)
  227. $text = preg_replace('#<([0-9]{1})#', '&lt;$1', $text);
  228. while (preg_match("/<(\/?\w*)\s*([^>]*)>/",$text,$regex)) {
  229. $newtext .= $tagqueue;
  230. $i = strpos($text,$regex[0]);
  231. $l = strlen($regex[0]);
  232. // clear the shifter
  233. $tagqueue = '';
  234. // Pop or Push
  235. if ($regex[1][0] == "/") { // End Tag
  236. $tag = strtolower(substr($regex[1],1));
  237. // if too many closing tags
  238. if($stacksize <= 0) {
  239. $tag = '';
  240. //or close to be safe $tag = '/' . $tag;
  241. }
  242. // if stacktop value = tag close value then pop
  243. else if ($tagstack[$stacksize - 1] == $tag) { // found closing tag
  244. $tag = '</' . $tag . '>'; // Close Tag
  245. // Pop
  246. array_pop ($tagstack);
  247. $stacksize--;
  248. } else { // closing tag not at top, search for it
  249. for ($j=$stacksize-1;$j>=0;$j--) {
  250. if ($tagstack[$j] == $tag) {
  251. // add tag to tagqueue
  252. for ($k=$stacksize-1;$k>=$j;$k--){
  253. $tagqueue .= '</' . array_pop ($tagstack) . '>';
  254. $stacksize--;
  255. }
  256. break;
  257. }
  258. }
  259. $tag = '';
  260. }
  261. } else { // Begin Tag
  262. $tag = strtolower($regex[1]);
  263. // Tag Cleaning
  264. // If self-closing or '', don't do anything.
  265. if((substr($regex[2],-1) == '/') || ($tag == '')) {
  266. }
  267. // ElseIf it's a known single-entity tag but it doesn't close itself, do so
  268. elseif ( in_array($tag, $single_tags) ) {
  269. $regex[2] .= '/';
  270. } else { // Push the tag onto the stack
  271. // If the top of the stack is the same as the tag we want to push, close previous tag
  272. if (($stacksize > 0) && !in_array($tag, $nestable_tags) && ($tagstack[$stacksize - 1] == $tag)) {
  273. $tagqueue = '</' . array_pop ($tagstack) . '>';
  274. $stacksize--;
  275. }
  276. $stacksize = array_push ($tagstack, $tag);
  277. }
  278. // Attributes
  279. $attributes = $regex[2];
  280. if($attributes) {
  281. $attributes = ' '.$attributes;
  282. }
  283. $tag = '<'.$tag.$attributes.'>';
  284. //If already queuing a close tag, then put this tag on, too
  285. if ($tagqueue) {
  286. $tagqueue .= $tag;
  287. $tag = '';
  288. }
  289. }
  290. $newtext .= substr($text,0,$i) . $tag;
  291. $text = substr($text,$i+$l);
  292. }
  293. // Clear Tag Queue
  294. $newtext .= $tagqueue;
  295. // Add Remaining text
  296. $newtext .= $text;
  297. // Empty Stack
  298. while($x = array_pop($tagstack)) {
  299. $newtext .= '</' . $x . '>'; // Add remaining tags to close
  300. }
  301. // WP fix for the bug with HTML comments
  302. $newtext = str_replace("< !--","<!--",$newtext);
  303. $newtext = str_replace("< !--","< !--",$newtext);
  304. return $newtext;
  305. }
  306. endif;
  307. if ( !function_exists('make_clickable') ) : // [WP4387]
  308. function make_clickable($ret) {
  309. $ret = ' ' . $ret;
  310. // in testing, using arrays here was found to be faster
  311. $ret = preg_replace(
  312. array(
  313. '#([\s>])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is',
  314. '#([\s>])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is',
  315. '#([\s>])([a-z0-9\-_.]+)@([^,< \n\r]+)#i'),
  316. array(
  317. '$1<a href="$2" rel="nofollow">$2</a>',
  318. '$1<a href="http://$2" rel="nofollow">$2</a>',
  319. '$1<a href="mailto:$2@$3">$2@$3</a>'),$ret);
  320. // this one is not in an array because we need it to run last, for cleanup of accidental links within links
  321. $ret = preg_replace("#(<a( [^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i", "$1$3</a>", $ret);
  322. $ret = trim($ret);
  323. return $ret;
  324. }
  325. endif;
  326. if ( !function_exists('seems_utf8') ) : // [WP6314]
  327. function seems_utf8($Str) { # by bmorel at ssi dot fr
  328. $length = strlen($Str);
  329. for ($i=0; $i < $length; $i++) {
  330. if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb
  331. elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb
  332. elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb
  333. elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb
  334. elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb
  335. elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b
  336. else return false; # Does not match any model
  337. for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
  338. if ((++$i == $length) || ((ord($Str[$i]) & 0xC0) != 0x80))
  339. return false;
  340. }
  341. }
  342. return true;
  343. }
  344. endif;
  345. if ( !function_exists('remove_accents') ) : // [WP6150]
  346. function remove_accents($string) {
  347. if ( !preg_match('/[\x80-\xff]/', $string) )
  348. return $string;
  349. if (seems_utf8($string)) {
  350. $chars = array(
  351. // Decompositions for Latin-1 Supplement
  352. chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
  353. chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
  354. chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
  355. chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
  356. chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
  357. chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
  358. chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
  359. chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
  360. chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
  361. chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
  362. chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
  363. chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
  364. chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
  365. chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
  366. chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
  367. chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
  368. chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
  369. chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
  370. chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
  371. chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
  372. chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
  373. chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
  374. chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
  375. chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
  376. chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
  377. chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
  378. chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
  379. chr(195).chr(191) => 'y',
  380. // Decompositions for Latin Extended-A
  381. chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
  382. chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
  383. chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
  384. chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
  385. chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
  386. chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
  387. chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
  388. chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
  389. chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
  390. chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
  391. chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
  392. chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
  393. chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
  394. chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
  395. chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
  396. chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
  397. chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
  398. chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
  399. chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
  400. chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
  401. chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
  402. chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
  403. chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
  404. chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
  405. chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
  406. chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
  407. chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
  408. chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
  409. chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
  410. chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
  411. chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
  412. chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
  413. chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
  414. chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
  415. chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
  416. chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
  417. chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
  418. chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
  419. chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
  420. chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
  421. chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
  422. chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
  423. chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
  424. chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
  425. chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
  426. chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
  427. chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
  428. chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
  429. chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
  430. chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
  431. chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
  432. chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
  433. chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
  434. chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
  435. chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
  436. chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
  437. chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
  438. chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
  439. chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
  440. chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
  441. chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
  442. chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
  443. chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
  444. chr(197).chr(190) => 'z', chr(197).chr(191) => 's',
  445. // Euro Sign
  446. chr(226).chr(130).chr(172) => 'E',
  447. // GBP (Pound) Sign
  448. chr(194).chr(163) => '');
  449. $string = strtr($string, $chars);
  450. } else {
  451. // Assume ISO-8859-1 if not UTF-8
  452. $chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158)
  453. .chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194)
  454. .chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202)
  455. .chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210)
  456. .chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218)
  457. .chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227)
  458. .chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235)
  459. .chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243)
  460. .chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251)
  461. .chr(252).chr(253).chr(255);
  462. $chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy";
  463. $string = strtr($string, $chars['in'], $chars['out']);
  464. $double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254));
  465. $double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th');
  466. $string = str_replace($double_chars['in'], $double_chars['out'], $string);
  467. }
  468. return $string;
  469. }
  470. endif;
  471. /* Forms */
  472. if ( !function_exists('wp_referer_field') ) :
  473. function wp_referer_field() { // [WP4656]
  474. $ref = attribute_escape($_SERVER['REQUEST_URI']);
  475. echo '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />';
  476. if ( wp_get_original_referer() ) {
  477. $original_ref = attribute_escape(stripslashes(wp_get_original_referer()));
  478. echo '<input type="hidden" name="_wp_original_http_referer" value="'. $original_ref . '" />';
  479. }
  480. }
  481. endif;
  482. if ( !function_exists('wp_original_referer_field') ) :
  483. function wp_original_referer_field() { // [WP4656]
  484. echo '<input type="hidden" name="_wp_original_http_referer" value="' . attribute_escape(stripslashes($_SERVER['REQUEST_URI'])) . '" />';
  485. }
  486. endif;
  487. if ( !function_exists('wp_get_referer') ) :
  488. function wp_get_referer() { // [WP3908]
  489. foreach ( array($_REQUEST['_wp_http_referer'], $_SERVER['HTTP_REFERER']) as $ref )
  490. if ( !empty($ref) )
  491. return $ref;
  492. return false;
  493. }
  494. endif;
  495. if ( !function_exists('wp_get_original_referer') ) :
  496. function wp_get_original_referer() { // [WP3908]
  497. if ( !empty($_REQUEST['_wp_original_http_referer']) )
  498. return $_REQUEST['_wp_original_http_referer'];
  499. return false;
  500. }
  501. endif;
  502. /* Plugin API */
  503. if ( !function_exists('add_filter') ) : // [WP5936]
  504. function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
  505. global $wp_filter, $merged_filters;
  506. // So the format is wp_filter['tag']['array of priorities']['array of functions serialized']['array of ['array (functions, accepted_args)]']
  507. $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority);
  508. $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
  509. //$wp_filter[$tag][$priority][serialize($function_to_add)] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
  510. unset( $merged_filters[ $tag ] );
  511. return true;
  512. }
  513. endif;
  514. if ( !function_exists('apply_filters') ) : // [WP5857]
  515. function apply_filters($tag, $string) {
  516. global $wp_filter, $merged_filters;
  517. if ( !isset( $merged_filters[ $tag ] ) )
  518. merge_filters($tag);
  519. if ( !isset($wp_filter[$tag]) )
  520. return $string;
  521. reset( $wp_filter[ $tag ] );
  522. $args = func_get_args();
  523. do{
  524. foreach( (array) current($wp_filter[$tag]) as $the_ )
  525. if ( !is_null($the_['function']) ){
  526. $args[1] = $string;
  527. $string = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
  528. }
  529. } while ( next($wp_filter[$tag]) !== false );
  530. return $string;
  531. }
  532. endif;
  533. if ( !function_exists('merge_filters') ) : // [WP5202]
  534. function merge_filters($tag) {
  535. global $wp_filter, $merged_filters;
  536. if ( isset($wp_filter['all']) && is_array($wp_filter['all']) )
  537. $wp_filter[$tag] = array_merge($wp_filter['all'], (array) $wp_filter[$tag]);
  538. if ( isset($wp_filter[$tag]) ){
  539. reset($wp_filter[$tag]);
  540. uksort($wp_filter[$tag], "strnatcasecmp");
  541. }
  542. $merged_filters[ $tag ] = true;
  543. }
  544. endif;
  545. if ( !function_exists('remove_filter') ) : // [WP5936]
  546. function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
  547. $function_to_remove = _wp_filter_build_unique_id($tag, $function_to_remove, $priority);
  548. $r = isset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]);
  549. unset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]);
  550. unset($GLOBALS['merged_filters'][$tag]);
  551. return $r;
  552. }
  553. endif;
  554. if ( !function_exists('add_action') ) : // [WP3893]
  555. function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
  556. add_filter($tag, $function_to_add, $priority, $accepted_args);
  557. }
  558. endif;
  559. if ( !function_exists('do_action') ) : // [WP5857]
  560. function do_action($tag, $arg = '') {
  561. global $wp_filter, $wp_actions;
  562. if ( is_array($wp_actions) )
  563. $wp_actions[] = $tag;
  564. else
  565. $wp_actions = array($tag);
  566. $args = array();
  567. if ( is_array($arg) && 1 == count($arg) && is_object($arg[0]) ) // array(&$this)
  568. $args[] =& $arg[0];
  569. else
  570. $args[] = $arg;
  571. for ( $a = 2; $a < func_num_args(); $a++ )
  572. $args[] = func_get_arg($a);
  573. merge_filters($tag);
  574. if ( !isset($wp_filter[$tag]) )
  575. return;
  576. do{
  577. foreach( (array) current($wp_filter[$tag]) as $the_ )
  578. if ( !is_null($the_['function']) )
  579. call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
  580. } while ( next($wp_filter[$tag]) !== false );
  581. }
  582. endif;
  583. if ( !function_exists('do_action_ref_array') ) : // [WP5958]
  584. function do_action_ref_array($tag, $args) {
  585. global $wp_filter, $wp_actions;
  586. if ( !is_array($wp_actions) )
  587. $wp_actions = array($tag);
  588. else
  589. $wp_actions[] = $tag;
  590. merge_filters($tag);
  591. if ( !isset($wp_filter[$tag]) )
  592. return;
  593. do{
  594. foreach( (array) current($wp_filter[$tag]) as $the_ )
  595. if ( !is_null($the_['function']) )
  596. call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
  597. } while ( next($wp_filter[$tag]) !== false );
  598. }
  599. endif;
  600. if ( !function_exists('did_action') ) : // [WP5413]
  601. function did_action($tag) {
  602. global $wp_actions;
  603. if ( empty($wp_actions) )
  604. return 0;
  605. return count(array_keys($wp_actions, $tag));
  606. }
  607. endif;
  608. if ( !function_exists('remove_action') ) : // [WP5393]
  609. function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
  610. return remove_filter($tag, $function_to_remove, $priority, $accepted_args);
  611. }
  612. endif;
  613. if ( !function_exists('_wp_filter_build_unique_id') ) : // [WP6025]
  614. function _wp_filter_build_unique_id($tag, $function, $priority = 10)
  615. {
  616. global $wp_filter;
  617. // If function then just skip all of the tests and not overwrite the following.
  618. // Static Calling
  619. if( is_string($function) )
  620. return $function;
  621. // Object Class Calling
  622. else if(is_object($function[0]) )
  623. {
  624. $obj_idx = get_class($function[0]).$function[1];
  625. if( is_null($function[0]->wp_filter_id) ) {
  626. $count = count((array)$wp_filter[$tag][$priority]);
  627. $function[0]->wp_filter_id = $count;
  628. $obj_idx .= $count;
  629. unset($count);
  630. } else
  631. $obj_idx .= $function[0]->wp_filter_id;
  632. return $obj_idx;
  633. }
  634. else if( is_string($function[0]) )
  635. return $function[0].$function[1];
  636. }
  637. endif;
  638. /*
  639. add_query_arg: Returns a modified querystring by adding
  640. a single key & value or an associative array.
  641. Setting a key value to emptystring removes the key.
  642. Omitting oldquery_or_uri uses the $_SERVER value.
  643. Parameters:
  644. add_query_arg(newkey, newvalue, oldquery_or_uri) or
  645. add_query_arg(associative_array, oldquery_or_uri)
  646. */
  647. if ( !function_exists('add_query_arg') ) : // [WP6064]
  648. function add_query_arg() {
  649. $ret = '';
  650. if ( is_array(func_get_arg(0)) ) {
  651. if ( @func_num_args() < 2 || false === @func_get_arg(1) )
  652. $uri = $_SERVER['REQUEST_URI'];
  653. else
  654. $uri = @func_get_arg(1);
  655. } else {
  656. if ( @func_num_args() < 3 || false === @func_get_arg(2) )
  657. $uri = $_SERVER['REQUEST_URI'];
  658. else
  659. $uri = @func_get_arg(2);
  660. }
  661. if ( $frag = strstr($uri, '#') )
  662. $uri = substr($uri, 0, -strlen($frag));
  663. else
  664. $frag = '';
  665. if ( preg_match('|^https?://|i', $uri, $matches) ) {
  666. $protocol = $matches[0];
  667. $uri = substr($uri, strlen($protocol));
  668. } else {
  669. $protocol = '';
  670. }
  671. if (strpos($uri, '?') !== false) {
  672. $parts = explode('?', $uri, 2);
  673. if ( 1 == count($parts) ) {
  674. $base = '?';
  675. $query = $parts[0];
  676. } else {
  677. $base = $parts[0] . '?';
  678. $query = $parts[1];
  679. }
  680. } elseif (!empty($protocol) || strpos($uri, '=') === false ) {
  681. $base = $uri . '?';
  682. $query = '';
  683. } else {
  684. $base = '';
  685. $query = $uri;
  686. }
  687. wp_parse_str($query, $qs);
  688. $qs = urlencode_deep($qs); // this re-URL-encodes things that were already in the query string
  689. if ( is_array(func_get_arg(0)) ) {
  690. $kayvees = func_get_arg(0);
  691. $qs = array_merge($qs, $kayvees);
  692. } else {
  693. $qs[func_get_arg(0)] = func_get_arg(1);
  694. }
  695. foreach ( $qs as $k => $v ) {
  696. if ( $v === false )
  697. unset($qs[$k]);
  698. }
  699. $ret = build_query($qs);
  700. $ret = trim($ret, '?');
  701. $ret = preg_replace('#=(&|$)#', '$1', $ret);
  702. $ret = $protocol . $base . $ret . $frag;
  703. $ret = rtrim($ret, '?');
  704. return $ret;
  705. }
  706. endif;
  707. /*
  708. remove_query_arg: Returns a modified querystring by removing
  709. a single key or an array of keys.
  710. Omitting oldquery_or_uri uses the $_SERVER value.
  711. Parameters:
  712. remove_query_arg(removekey, [oldquery_or_uri]) or
  713. remove_query_arg(removekeyarray, [oldquery_or_uri])
  714. */
  715. if ( !function_exists('remove_query_arg') ) : // [WP5705]
  716. function remove_query_arg($key, $query=FALSE) {
  717. if ( is_array($key) ) { // removing multiple keys
  718. foreach ( (array) $key as $k )
  719. $query = add_query_arg($k, FALSE, $query);
  720. return $query;
  721. }
  722. return add_query_arg($key, FALSE, $query);
  723. }
  724. endif;
  725. if ( !function_exists( 'build_query' ) ) : // [WP6064]
  726. function build_query($data) {
  727. return _http_build_query($data, NULL, '&', '', false);
  728. }
  729. endif;
  730. if ( !function_exists( '_http_build_query' ) ) : // [WP6070]
  731. // from php.net (modified by Mark Jaquith to behave like the native PHP5 function)
  732. function _http_build_query($data, $prefix=null, $sep=null, $key='', $urlencode=true) {
  733. $ret = array();
  734. foreach ( (array) $data as $k => $v ) {
  735. if ( $urlencode)
  736. $k = urlencode($k);
  737. if ( is_int($k) && $prefix != null )
  738. $k = $prefix.$k;
  739. if ( !empty($key) )
  740. $k = $key . '%5B' . $k . '%5D';
  741. if ( $v === NULL )
  742. continue;
  743. elseif ( $v === FALSE )
  744. $v = '0';
  745. if ( is_array($v) || is_object($v) )
  746. array_push($ret,_http_build_query($v, '', $sep, $k, $urlencode));
  747. elseif ( $urlencode )
  748. array_push($ret, $k.'='.urlencode($v));
  749. else
  750. array_push($ret, $k.'='.$v);
  751. }
  752. if ( NULL === $sep )
  753. $sep = ini_get('arg_separator.output');
  754. return implode($sep, $ret);
  755. }
  756. endif;
  757. if ( !function_exists('get_status_header_desc') ) : // [WP6104]
  758. function get_status_header_desc( $code ) {
  759. global $wp_header_to_desc;
  760. $code = (int) $code;
  761. if ( !isset($wp_header_to_desc) ) {
  762. $wp_header_to_desc = array(
  763. 100 => 'Continue',
  764. 101 => 'Switching Protocols',
  765. 200 => 'OK',
  766. 201 => 'Created',
  767. 202 => 'Accepted',
  768. 203 => 'Non-Authoritative Information',
  769. 204 => 'No Content',
  770. 205 => 'Reset Content',
  771. 206 => 'Partial Content',
  772. 300 => 'Multiple Choices',
  773. 301 => 'Moved Permanently',
  774. 302 => 'Found',
  775. 303 => 'See Other',
  776. 304 => 'Not Modified',
  777. 305 => 'Use Proxy',
  778. 307 => 'Temporary Redirect',
  779. 400 => 'Bad Request',
  780. 401 => 'Unauthorized',
  781. 403 => 'Forbidden',
  782. 404 => 'Not Found',
  783. 405 => 'Method Not Allowed',
  784. 406 => 'Not Acceptable',
  785. 407 => 'Proxy Authentication Required',
  786. 408 => 'Request Timeout',
  787. 409 => 'Conflict',
  788. 410 => 'Gone',
  789. 411 => 'Length Required',
  790. 412 => 'Precondition Failed',
  791. 413 => 'Request Entity Too Large',
  792. 414 => 'Request-URI Too Long',
  793. 415 => 'Unsupported Media Type',
  794. 416 => 'Requested Range Not Satisfiable',
  795. 417 => 'Expectation Failed',
  796. 500 => 'Internal Server Error',
  797. 501 => 'Not Implemented',
  798. 502 => 'Bad Gateway',
  799. 503 => 'Service Unavailable',
  800. 504 => 'Gateway Timeout',
  801. 505 => 'HTTP Version Not Supported'
  802. );
  803. }
  804. if ( isset( $wp_header_to_desc[$code] ) ) {
  805. return $wp_header_to_desc[$code];
  806. } else {
  807. return '';
  808. }
  809. }
  810. endif;
  811. if ( !function_exists('status_header') ) : // [WP6107]
  812. function status_header( $header ) {
  813. $text = get_status_header_desc( $header );
  814. if ( empty( $text ) )
  815. return false;
  816. $protocol = $_SERVER["SERVER_PROTOCOL"];
  817. if ( ('HTTP/1.1' != $protocol) && ('HTTP/1.0' != $protocol) )
  818. $protocol = 'HTTP/1.0';
  819. $status_header = "$protocol $header $text";
  820. if ( function_exists('apply_filters') )
  821. $status_header = apply_filters('status_header', $status_header, $header, $text, $protocol);
  822. if ( version_compare( phpversion(), '4.3.0', '>=' ) ) {
  823. return @header( $status_header, true, $header );
  824. } else {
  825. return @header( $status_header );
  826. }
  827. }
  828. endif;
  829. if ( !function_exists('nocache_headers') ) :
  830. function nocache_headers() { // [WP2623]
  831. @ header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
  832. @ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  833. @ header('Cache-Control: no-cache, must-revalidate, max-age=0');
  834. @ header('Pragma: no-cache');
  835. }
  836. endif;
  837. if ( !function_exists('cache_javascript_headers') ) :
  838. function cache_javascript_headers() { // [WP5640] Not verbatim WP. Charset hardcoded.
  839. $expiresOffset = 864000; // 10 days
  840. header("Content-Type: text/javascript; charset=utf-8");
  841. header("Vary: Accept-Encoding"); // Handle proxies
  842. header("Expires: " . gmdate("D, d M Y H:i:s", time() + $expiresOffset) . " GMT");
  843. }
  844. endif;
  845. /* Templates */
  846. if ( !function_exists('paginate_links') ) : // [6026]
  847. function paginate_links( $args = '' ) {
  848. $defaults = array(
  849. 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
  850. 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
  851. 'total' => 1,
  852. 'current' => 0,
  853. 'show_all' => false,
  854. 'prev_next' => true,
  855. 'prev_text' => __('&laquo; Previous'),
  856. 'next_text' => __('Next &raquo;'),
  857. 'end_size' => 1, // How many numbers on either end including the end
  858. 'mid_size' => 2, // How many numbers to either side of current not including current
  859. 'type' => 'plain',
  860. 'add_args' => false // array of query args to aadd
  861. );
  862. $args = wp_parse_args( $args, $defaults );
  863. extract($args, EXTR_SKIP);
  864. // Who knows what else people pass in $args
  865. $total = (int) $total;
  866. if ( $total < 2 )
  867. return;
  868. $current = (int) $current;
  869. $end_size = 0 < (int) $end_size ? (int) $end_size : 1; // Out of bounds? Make it the default.
  870. $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
  871. $add_args = is_array($add_args) ? $add_args : false;
  872. $r = '';
  873. $page_links = array();
  874. $n = 0;
  875. $dots = false;
  876. if ( $prev_next && $current && 1 < $current ) :
  877. $link = str_replace('%_%', 2 == $current ? '' : $format, $base);
  878. $link = str_replace('%#%', $current - 1, $link);
  879. if ( $add_args )
  880. $link = add_query_arg( $add_args, $link );
  881. $page_links[] = "<a class='prev page-numbers' href='" . clean_url($link) . "'>$prev_text</a>";
  882. endif;
  883. for ( $n = 1; $n <= $total; $n++ ) :
  884. if ( $n == $current ) :
  885. $page_links[] = "<span class='page-numbers current'>$n</span>";
  886. $dots = true;
  887. else :
  888. if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
  889. $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
  890. $link = str_replace('%#%', $n, $link);
  891. if ( $add_args )
  892. $link = add_query_arg( $add_args, $link );
  893. $page_links[] = "<a class='page-numbers' href='" . clean_url($link) . "'>$n</a>";
  894. $dots = true;
  895. elseif ( $dots && !$show_all ) :
  896. $page_links[] = "<span class='page-numbers dots'>...</span>";
  897. $dots = false;
  898. endif;
  899. endif;
  900. endfor;
  901. if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
  902. $link = str_replace('%_%', $format, $base);
  903. $link = str_replace('%#%', $current + 1, $link);
  904. if ( $add_args )
  905. $link = add_query_arg( $add_args, $link );
  906. $page_links[] = "<a class='next page-numbers' href='" . clean_url($link) . "'>$next_text</a>";
  907. endif;
  908. switch ( $type ) :
  909. case 'array' :
  910. return $page_links;
  911. break;
  912. case 'list' :
  913. $r .= "<ul class='page-numbers'>\n\t<li>";
  914. $r .= join("</li>\n\t<li>", $page_links);
  915. $r .= "</li>\n</ul>\n";
  916. break;
  917. default :
  918. $r = join("\n", $page_links);
  919. break;
  920. endswitch;
  921. return $r;
  922. }
  923. endif;
  924. if ( !function_exists('is_serialized') ) : // [WP4438]
  925. function is_serialized($data) {
  926. // if it isn't a string, it isn't serialized
  927. if ( !is_string($data) )
  928. return false;
  929. $data = trim($data);
  930. if ( 'N;' == $data )
  931. return true;
  932. if ( !preg_match('/^([adObis]):/', $data, $badions) )
  933. return false;
  934. switch ( $badions[1] ) :
  935. case 'a' :
  936. case 'O' :
  937. case 's' :
  938. if ( preg_match("/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data) )
  939. return true;
  940. break;
  941. case 'b' :
  942. case 'i' :
  943. case 'd' :
  944. if ( preg_match("/^{$badions[1]}:[0-9.E-]+;\$/", $data) )
  945. return true;
  946. break;
  947. endswitch;
  948. return false;
  949. }
  950. endif;
  951. if ( !function_exists('is_serialized_string') ) : // [WP4438]
  952. function is_serialized_string($data) {
  953. // if it isn't a string, it isn't a serialized string
  954. if ( !is_string($data) )
  955. return false;
  956. $data = trim($data);
  957. if ( preg_match('/^s:[0-9]+:.*;$/s',$data) ) // this should fetch all serialized strings
  958. return true;
  959. return false;
  960. }
  961. endif;
  962. if ( !function_exists('ent2ncr') ) : // [WP3641]
  963. function ent2ncr($text) {
  964. $to_ncr = array(
  965. '&quot;' => '&#34;',
  966. '&amp;' => '&#38;',
  967. '&frasl;' => '&#47;',
  968. '&lt;' => '&#60;',
  969. '&gt;' => '&#62;',
  970. '|' => '&#124;',
  971. '&nbsp;' => '&#160;',
  972. '&iexcl;' => '&#161;',
  973. '&cent;' => '&#162;',
  974. '&pound;' => '&#163;',
  975. '&curren;' => '&#164;',
  976. '&yen;' => '&#165;',
  977. '&brvbar;' => '&#166;',
  978. '&brkbar;' => '&#166;',
  979. '&sect;' => '&#167;',
  980. '&uml;' => '&#168;',
  981. '&die;' => '&#168;',
  982. '&copy;' => '&#169;',
  983. '&ordf;' => '&#170;',
  984. '&laquo;' => '&#171;',
  985. '&not;' => '&#172;',
  986. '&shy;' => '&#173;',
  987. '&reg;' => '&#174;',
  988. '&macr;' => '&#175;',
  989. '&hibar;' => '&#175;',
  990. '&deg;' => '&#176;',
  991. '&plusmn;' => '&#177;',
  992. '&sup2;' => '&#178;',
  993. '&sup3;' => '&#179;',
  994. '&acute;' => '&#180;',
  995. '&micro;' => '&#181;',
  996. '&para;' => '&#182;',
  997. '&middot;' => '&#183;',
  998. '&cedil;' => '&#184;',
  999. '&sup1;' => '&#185;',
  1000. '&ordm;' => '&#186;',
  1001. '&raquo;' => '&#187;',
  1002. '&frac14;' => '&#188;',
  1003. '&frac12;' => '&#189;',
  1004. '&frac34;' => '&#190;',
  1005. '&iquest;' => '&#191;',
  1006. '&Agrave;' => '&#192;',
  1007. '&Aacute;' => '&#193;',
  1008. '&Acirc;' => '&#194;',
  1009. '&Atilde;' => '&#195;',
  1010. '&Auml;' => '&#196;',
  1011. '&Aring;' => '&#197;',
  1012. '&AElig;' => '&#198;',
  1013. '&Ccedil;' => '&#199;',
  1014. '&Egrave;' => '&#200;',
  1015. '&Eacute;' => '&#201;',
  1016. '&Ecirc;' => '&#202;',
  1017. '&Euml;' => '&#203;',
  1018. '&Igrave;' => '&#204;',
  1019. '&Iacute;' => '&#205;',
  1020. '&Icirc;' => '&#206;',
  1021. '&Iuml;' => '&#207;',
  1022. '&ETH;' => '&#208;',
  1023. '&Ntilde;' => '&#209;',
  1024. '&Ograve;' => '&#210;',
  1025. '&Oacute;' => '&#211;',
  1026. '&Ocirc;' => '&#212;',
  1027. '&Otilde;' => '&#213;',
  1028. '&Ouml;' => '&#214;',
  1029. '&times;' => '&#215;',
  1030. '&Oslash;' => '&#216;',
  1031. '&Ugrave;' => '&#217;',
  1032. '&Uacute;' => '&#218;',
  1033. '&Ucirc;' => '&#219;',
  1034. '&Uuml;' => '&#220;',
  1035. '&Yacute;' => '&#221;',
  1036. '&THORN;' => '&#222;',
  1037. '&szlig;' => '&#223;',
  1038. '&agrave;' => '&#224;',
  1039. '&aacute;' => '&#225;',
  1040. '&acirc;' => '&#226;',
  1041. '&atilde;' => '&#227;',
  1042. '&auml;' => '&#228;',
  1043. '&aring;' => '&#229;',
  1044. '&aelig;' => '&#230;',
  1045. '&ccedil;' => '&#231;',
  1046. '&egrave;' => '&#232;',
  1047. '&eacute;' => '&#233;',
  1048. '&ecirc;' => '&#234;',
  1049. '&euml;' => '&#235;',
  1050. '&igrave;' => '&#236;',
  1051. '&iacute;' => '&#237;',
  1052. '&icirc;' => '&#238;',
  1053. '&iuml;' => '&#239;',
  1054. '&eth;' => '&#240;',
  1055. '&ntilde;' => '&#241;',
  1056. '&ograve;' => '&#242;',
  1057. '&oacute;' => '&#243;',
  1058. '&ocirc;' => '&#244;',
  1059. '&otilde;' => '&#245;',
  1060. '&ouml;' => '&#246;',
  1061. '&divide;' => '&#247;',
  1062. '&oslash;' => '&#248;',
  1063. '&ugrave;' => '&#249;',
  1064. '&uacute;' => '&#250;',
  1065. '&ucirc;' => '&#251;',
  1066. '&uuml;' => '&#252;',
  1067. '&yacute;' => '&#253;',
  1068. '&thorn;' => '&#254;',
  1069. '&yuml;' => '&#255;',
  1070. '&OElig;' => '&#338;',
  1071. '&oelig;' => '&#339;',
  1072. '&Scaron;' => '&#352;',
  1073. '&scaron;' => '&#353;',
  1074. '&Yuml;' => '&#376;',
  1075. '&fnof;' => '&#402;',
  1076. '&circ;' => '&#710;',
  1077. '&tilde;' => '&#732;',
  1078. '&Alpha;' => '&#913;',
  1079. '&Beta;' => '&#914;',
  1080. '&Gamma;' => '&#915;',
  1081. '&Delta;' => '&#916;',
  1082. '&Epsilon;' => '&#917;',
  1083. '&Zeta;' => '&#918;',
  1084. '&Eta;' => '&#919;',
  1085. '&Theta;' => '&#920;',
  1086. '&Iota;' => '&#921;',
  1087. '&Kappa;' => '&#922;',
  1088. '&Lambda;' => '&#923;',
  1089. '&Mu;' => '&#924;',
  1090. '&Nu;' => '&#925;',
  1091. '&Xi;' => '&#926;',
  1092. '&Omicron;' => '&#927;',
  1093. '&Pi;' => '&#928;',
  1094. '&Rho;' => '&#929;',
  1095. '&Sigma;' => '&#931;',
  1096. '&Tau;' => '&#932;',
  1097. '&Upsilon;' => '&#933;',
  1098. '&Phi;' => '&#934;',
  1099. '&Chi;' => '&#935;',
  1100. '&Psi;' => '&#936;',
  1101. '&Omega;' => '&#937;',
  1102. '&alpha;' => '&#945;',
  1103. '&beta;' => '&#946;',
  1104. '&gamma;' => '&#947;',
  1105. '&delta;' => '&#948;',
  1106. '&epsilon;' => '&#949;',
  1107. '&zeta;' => '&#950;',
  1108. '&eta;' => '&#951;',
  1109. '&theta;' => '&#952;',
  1110. '&iota;' => '&#953;',
  1111. '&kappa;' => '&#954;',
  1112. '&lambda;' => '&#955;',
  1113. '&mu;' => '&#956;',
  1114. '&nu;' => '&#957;',
  1115. '&xi;' => '&#958;',
  1116. '&omicron;' => '&#959;',
  1117. '&pi;' => '&#960;',
  1118. '&rho;' => '&#961;',
  1119. '&sigmaf;' => '&#962;',
  1120. '&sigma;' => '&#963;',
  1121. '&tau;' => '&#964;',
  1122. '&upsilon;' => '&#965;',
  1123. '&phi;' => '&#966;',
  1124. '&chi;' => '&#967;',
  1125. '&psi;' => '&#968;',
  1126. '&omega;' => '&#969;',
  1127. '&thetasym;' => '&#977;',
  1128. '&upsih;' => '&#978;',
  1129. '&piv;' => '&#982;',
  1130. '&ensp;' => '&#8194;',
  1131. '&emsp;' => '&#8195;',
  1132. '&thinsp;' => '&#8201;',
  1133. '&zwnj;' => '&#8204;',
  1134. '&zwj;' => '&#8205;',
  1135. '&lrm;' => '&#8206;',
  1136. '&rlm;' => '&#8207;',
  1137. '&ndash;' => '&#8211;',
  1138. '&mdash;' => '&#8212;',
  1139. '&lsquo;' => '&#8216;',
  1140. '&rsquo;' => '&#8217;',
  1141. '&sbquo;' => '&#8218;',
  1142. '&ldquo;' => '&#8220;',
  1143. '&rdquo;' => '&#8221;',
  1144. '&bdquo;' => '&#8222;',
  1145. '&dagger;' => '&#8224;',
  1146. '&Dagger;' => '&#8225;',
  1147. '&bull;' => '&#8226;',
  1148. '&hellip;' => '&#8230;',
  1149. '&permil;' => '&#8240;',
  1150. '&prime;' => '&#8242;',
  1151. '&Prime;' => '&#8243;',
  1152. '&lsaquo;' => '&#8249;',
  1153. '&rsaquo;' => '&#8250;',
  1154. '&oline;' => '&#8254;',
  1155. '&frasl;' => '&#8260;',
  1156. '&euro;' => '&#8364;',
  1157. '&image;' => '&#8465;',
  1158. '&weierp;' => '&#8472;',
  1159. '&real;' => '&#8476;',
  1160. '&trade;' => '&#8482;',
  1161. '&alefsym;' => '&#8501;',
  1162. '&crarr;' => '&#8629;',
  1163. '&lArr;' => '&#8656;',
  1164. '&uArr;' => '&#8657;',
  1165. '&rArr;' => '&#8658;',
  1166. '&dArr;' => '&#8659;',
  1167. '&hArr;' => '&#8660;',
  1168. '&forall;' => '&#8704;',
  1169. '&part;' => '&#8706;',
  1170. '&exist;' => '&#8707;',
  1171. '&empty;' => '&#8709;',
  1172. '&nabla;' => '&#8711;',
  1173. '&isin;' => '&#8712;',
  1174. '&notin;' => '&#8713;',
  1175. '&ni;' => '&#8715;',
  1176. '&prod;' => '&#8719;',
  1177. '&sum;' => '&#8721;',
  1178. '&minus;' => '&#8722;',
  1179. '&lowast;' => '&#8727;',
  1180. '&radic;' => '&#8730;',
  1181. '&prop;' => '&#8733;',
  1182. '&infin;' => '&#8734;',
  1183. '&ang;' => '&#8736;',
  1184. '&and;' => '&#8743;',
  1185. '&or;' => '&#8744;',
  1186. '&cap;' => '&#8745;',
  1187. '&cup;' => '&#8746;',
  1188. '&int;' => '&#8747;',
  1189. '&there4;' => '&#8756;',
  1190. '&sim;' => '&#8764;',
  1191. '&cong;' => '&#8773;',
  1192. '&asymp;' => '&#8776;',
  1193. '&ne;' => '&#8800;',
  1194. '&equiv;' => '&#8801;',
  1195. '&le;' => '&#8804;',
  1196. '&ge;' => '&#8805;',
  1197. '&sub;' => '&#8834;',
  1198. '&sup;' => '&#8835;',
  1199. '&nsub;' => '&#8836;',
  1200. '&sube;' => '&#8838;',
  1201. '&supe;' => '&#8839;',
  1202. '&oplus;' => '&#8853;',
  1203. '&otimes;' => '&#8855;',
  1204. '&perp;' => '&#8869;',
  1205. '&sdot;' => '&#8901;',
  1206. '&lceil;' => '&#8968;',
  1207. '&rceil;' => '&#8969;',
  1208. '&lfloor;' => '&#8970;',
  1209. '&rfloor;' => '&#8971;',
  1210. '&lang;' => '&#9001;',
  1211. '&rang;' => '&#9002;',
  1212. '&larr;' => '&#8592;',
  1213. '&uarr;' => '&#8593;',
  1214. '&rarr;' => '&#8594;',
  1215. '&darr;' => '&#8595;',
  1216. '&harr;' => '&#8596;',
  1217. '&loz;' => '&#9674;',
  1218. '&spades;' => '&#9824;',
  1219. '&clubs;' => '&#9827;',
  1220. '&hearts;' => '&#9829;',
  1221. '&diams;' => '&#9830;'
  1222. );
  1223. return str_replace( array_keys($to_ncr), array_values($to_ncr), $text );
  1224. }
  1225. endif;
  1226. if ( !function_exists('wp_parse_args') ) : // [WP5796]
  1227. function wp_parse_args( $args, $defaults = '' ) {
  1228. if ( is_object($args) )
  1229. $r = get_object_vars($args);
  1230. else if ( is_array( $args ) )
  1231. $r =& $args;
  1232. else
  1233. wp_parse_str( $args, $r );
  1234. if ( is_array( $defaults ) )
  1235. return array_merge( $defaults, $r );
  1236. else
  1237. return $r;
  1238. }
  1239. endif;
  1240. if ( !function_exists('urlencode_deep') ) : // [WP5261]
  1241. function urlencode_deep($value) {
  1242. $value = is_array($value) ?
  1243. array_map('urlencode_deep', $value) :
  1244. urlencode($value);
  1245. return $value;
  1246. }
  1247. endif;
  1248. if ( !function_exists( 'zeroise' ) ) : // [WP3855]
  1249. function zeroise($number,$threshold) { // function to add leading zeros when necessary
  1250. return sprintf('%0'.$threshold.'s', $number);
  1251. }
  1252. endif;
  1253. if ( !function_exists( 'backslashit' ) ) : // [WP3855]
  1254. function backslashit($string) {
  1255. $string = preg_replace('/^([0-9])/', '\\\\\\\\\1', $string);
  1256. $string = preg_replace('/([a-z])/i', '\\\\\1', $string);
  1257. return $string;
  1258. }
  1259. endif;
  1260. if ( !function_exists( 'wp_parse_str' ) ) : // [WP5709]
  1261. function wp_parse_str( $string, &$array ) {
  1262. parse_str( $string, $array );
  1263. if ( get_magic_quotes_gpc() )
  1264. $array = stripslashes_deep( $array ); // parse_str() adds slashes if magicquotes is on. See: http://php.net/parse_str
  1265. $array = apply_filters( 'wp_parse_str', $array );
  1266. }
  1267. endif;
  1268. if ( !function_exists( 'wp_remote_fopen' ) ) : // [WP4752]
  1269. function wp_remote_fopen( $uri ) {
  1270. $timeout = 10;
  1271. $parsed_url = @parse_url($uri);
  1272. if ( !$parsed_url || !is_array($parsed_url) )
  1273. return false;
  1274. if ( !isset($parsed_url['scheme']) || !in_array($parsed_url['scheme'], array('http','https')) )
  1275. $uri = 'http://' . $uri;
  1276. if ( ini_get('allow_url_fopen') ) {
  1277. $fp = @fopen( $uri, 'r' );
  1278. if ( !$fp )
  1279. return false;
  1280. //stream_set_timeout($fp, $timeout); // Requires php 4.3
  1281. $linea = '';
  1282. while( $remote_read = fread($fp, 4096) )
  1283. $linea .= $remote_read;
  1284. fclose($fp);
  1285. return $linea;
  1286. } else if ( function_exists('curl_init') ) {
  1287. $handle = curl_init();
  1288. curl_setopt ($handle, CURLOPT_URL, $uri);
  1289. curl_setopt ($handle, CURLOPT_CONNECTTIMEOUT, 1);
  1290. curl_setopt ($handle, CURLOPT_RETURNTRANSFER, 1);
  1291. curl_setopt ($handle, CURLOPT_TIMEOUT, $timeout);
  1292. $buffer = curl_exec($handle);
  1293. curl_close($handle);
  1294. return $buffer;
  1295. } else {
  1296. return false;
  1297. }
  1298. }
  1299. endif;
  1300. ?>