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

  1. <?php 
  2. // Last sync [WP11544] 
  3.  
  4. /** 
  5. * From WP wp-includes/functions.php 
  6. * 
  7. * Missing functions are indicated in comments 
  8. */ 
  9.  
  10. /** 
  11. * Main BackPress API 
  12. * 
  13. * @package BackPress 
  14. */ 
  15.  
  16. // ! function mysql2date() 
  17.  
  18. if ( !function_exists('current_time') ) : 
  19. /** 
  20. * Retrieve the current time based on specified type. 
  21. * 
  22. * The 'mysql' type will return the time in the format for MySQL DATETIME field. 
  23. * The 'timestamp' type will return the current timestamp. 
  24. * 
  25. * If $gmt is set to either '1' or 'true', then both types will use GMT time. 
  26. * if $gmt is false, the output is adjusted with the GMT offset in the WordPress option. 
  27. * 
  28. * @since 1.0.0 
  29. * 
  30. * @param string $type Either 'mysql' or 'timestamp'. 
  31. * @param int|bool $gmt Optional. Whether to use GMT timezone. Default is false. 
  32. * @return int|string String if $type is 'gmt', int if $type is 'timestamp'. 
  33. */ 
  34. function current_time( $type, $gmt = 0 ) { 
  35. switch ( $type ) { 
  36. case 'mysql': 
  37. return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( backpress_get_option( 'gmt_offset' ) * 3600 ) ) ); 
  38. break; 
  39. case 'timestamp': 
  40. return ( $gmt ) ? time() : time() + ( backpress_get_option( 'gmt_offset' ) * 3600 ); 
  41. break; 
  42. endif; 
  43.  
  44. // ! function date_i18n() 
  45. // ! function number_format_i18n() 
  46. // ! function size_format() 
  47. // ! function get_weekstartend() 
  48.  
  49. if ( !function_exists('maybe_unserialize') ) : 
  50. /** 
  51. * Unserialize value only if it was serialized. 
  52. * 
  53. * @since 2.0.0 
  54. * 
  55. * @param string $original Maybe unserialized original, if is needed. 
  56. * @return mixed Unserialized data can be any type. 
  57. */ 
  58. function maybe_unserialize( $original ) { 
  59. if ( is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in 
  60. return @unserialize( $original ); 
  61. return $original; 
  62. endif; 
  63.  
  64. if ( !function_exists('is_serialized') ) : 
  65. /** 
  66. * Check value to find if it was serialized. 
  67. * 
  68. * If $data is not an string, then returned value will always be false. 
  69. * Serialized data is always a string. 
  70. * 
  71. * @since 2.0.5 
  72. * 
  73. * @param mixed $data Value to check to see if was serialized. 
  74. * @return bool False if not serialized and true if it was. 
  75. */ 
  76. function is_serialized( $data ) { 
  77. // if it isn't a string, it isn't serialized 
  78. if ( !is_string( $data ) ) 
  79. return false; 
  80. $data = trim( $data ); 
  81. if ( 'N;' == $data ) 
  82. return true; 
  83. if ( !preg_match( '/^([adObis]):/', $data, $badions ) ) 
  84. return false; 
  85. switch ( $badions[1] ) { 
  86. case 'a' : 
  87. case 'O' : 
  88. case 's' : 
  89. if ( preg_match( "/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data ) ) 
  90. return true; 
  91. break; 
  92. case 'b' : 
  93. case 'i' : 
  94. case 'd' : 
  95. if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) ) 
  96. return true; 
  97. break; 
  98. return false; 
  99. endif; 
  100.  
  101. if ( !function_exists('is_serialized_string') ) : 
  102. /** 
  103. * Check whether serialized data is of string type. 
  104. * 
  105. * @since 2.0.5 
  106. * 
  107. * @param mixed $data Serialized data 
  108. * @return bool False if not a serialized string, true if it is. 
  109. */ 
  110. function is_serialized_string( $data ) { 
  111. // if it isn't a string, it isn't a serialized string 
  112. if ( !is_string( $data ) ) 
  113. return false; 
  114. $data = trim( $data ); 
  115. if ( preg_match( '/^s:[0-9]+:.*;$/s', $data ) ) // this should fetch all serialized strings 
  116. return true; 
  117. return false; 
  118. endif; 
  119.  
  120. // ! function get_option() 
  121. // ! function wp_protect_special_option() 
  122. // ! function form_option() 
  123. // ! function get_alloptions() 
  124. // ! function wp_load_alloptions() 
  125. // ! function update_option() 
  126. // ! function add_option() 
  127. // ! function delete_option() 
  128. // ! function delete_transient() 
  129. // ! function get_transient() 
  130. // ! function set_transient() 
  131. // ! function wp_user_settings() 
  132. // ! function get_user_setting() 
  133. // ! function set_user_setting() 
  134. // ! function delete_user_setting() 
  135. // ! function get_all_user_settings() 
  136. // ! function wp_set_all_user_settings() 
  137. // ! function delete_all_user_settings() 
  138.  
  139. if ( !function_exists('maybe_serialize') ) : 
  140. /** 
  141. * Serialize data, if needed. 
  142. * 
  143. * @since 2.0.5 
  144. * 
  145. * @param mixed $data Data that might be serialized. 
  146. * @return mixed A scalar data 
  147. */ 
  148. function maybe_serialize( $data ) { 
  149. if ( is_array( $data ) || is_object( $data ) ) 
  150. return serialize( $data ); 
  151.  
  152. if ( is_serialized( $data ) ) 
  153. return serialize( $data ); 
  154.  
  155. return $data; 
  156. endif; 
  157.  
  158. // ! function make_url_footnote() 
  159. // ! function xmlrpc_getposttitle() 
  160. // ! function xmlrpc_getpostcategory() 
  161. // ! function xmlrpc_removepostdata() 
  162. // ! function debug_fopen() 
  163. // ! function debug_fwrite() 
  164. // ! function debug_fclose() 
  165. // ! function do_enclose() 
  166. // ! function wp_get_http() 
  167. // ! function wp_get_http_headers() 
  168. // ! function is_new_day() 
  169.  
  170. if ( !function_exists( 'build_query' ) ) : 
  171. /** 
  172. * Build URL query based on an associative and, or indexed array. 
  173. * 
  174. * This is a convenient function for easily building url queries. It sets the 
  175. * separator to '&' and uses _http_build_query() function. 
  176. * 
  177. * @see _http_build_query() Used to build the query 
  178. * @link http://us2.php.net/manual/en/function.http-build-query.php more on what 
  179. * http_build_query() does. 
  180. * 
  181. * @since 2.3.0 
  182. * 
  183. * @param array $data URL-encode key/value pairs. 
  184. * @return string URL encoded string 
  185. */ 
  186. function build_query( $data ) { 
  187. return _http_build_query( $data, null, '&', '', false ); 
  188. endif; 
  189.  
  190. if ( !function_exists( 'add_query_arg' ) ) : 
  191. /** 
  192. * Retrieve a modified URL query string. 
  193. * 
  194. * You can rebuild the URL and append a new query variable to the URL query by 
  195. * using this function. You can also retrieve the full URL with query data. 
  196. * 
  197. * Adding a single key & value or an associative array. Setting a key value to 
  198. * emptystring removes the key. Omitting oldquery_or_uri uses the $_SERVER 
  199. * value. 
  200. * 
  201. * @since 1.5.0 
  202. * 
  203. * @param mixed $param1 Either newkey or an associative_array 
  204. * @param mixed $param2 Either newvalue or oldquery or uri 
  205. * @param mixed $param3 Optional. Old query or uri 
  206. * @return string New URL query string. 
  207. */ 
  208. function add_query_arg() { 
  209. $args = func_get_args(); 
  210. if ( is_array( $args[0] ) ) { 
  211. if ( count( $args ) < 2 || false === $args[1] ) 
  212. $uri = $_SERVER['REQUEST_URI']; 
  213. else 
  214. $uri = $args[1]; 
  215. } else { 
  216. if ( count( $args ) < 3 || false === $args[2] ) 
  217. $uri = $_SERVER['REQUEST_URI']; 
  218. else 
  219. $uri = $args[2]; 
  220.  
  221. if ( $frag = strstr( $uri, '#' ) ) 
  222. $uri = substr( $uri, 0, -strlen( $frag ) ); 
  223. else 
  224. $frag = ''; 
  225.  
  226. if ( 0 === stripos( $uri, 'http://' ) ) { 
  227. $protocol = 'http://'; 
  228. $uri = substr( $uri, 7 ); 
  229. } elseif ( 0 === stripos( $uri, 'https://' ) ) { 
  230. $protocol = 'https://'; 
  231. $uri = substr( $uri, 8 ); 
  232. } else { 
  233. $protocol = ''; 
  234.  
  235. if ( strpos( $uri, '?' ) !== false ) { 
  236. list( $base, $query ) = explode( '?', $uri, 2 ); 
  237. $base .= '?'; 
  238. } elseif ( $protocol || strpos( $uri, '=' ) === false ) { 
  239. $base = $uri . '?'; 
  240. $query = ''; 
  241. } else { 
  242. $base = ''; 
  243. $query = $uri; 
  244.  
  245. wp_parse_str( $query, $qs ); 
  246. $qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string 
  247. if ( is_array( $args[0] ) ) { 
  248. foreach ( $args[0] as $k => $v ) { 
  249. $qs[ $k ] = $v; 
  250. } else { 
  251. $qs[ $args[0] ] = $args[1]; 
  252.  
  253. foreach ( $qs as $k => $v ) { 
  254. if ( $v === false ) 
  255. unset( $qs[$k] ); 
  256.  
  257. $ret = build_query( $qs ); 
  258. $ret = trim( $ret, '?' ); 
  259. $ret = preg_replace( '#=(&|$)#', '$1', $ret ); 
  260. $ret = $protocol . $base . $ret . $frag; 
  261. $ret = rtrim( $ret, '?' ); 
  262. return $ret; 
  263. endif; 
  264.  
  265. if ( !function_exists( 'remove_query_arg' ) ) : 
  266. /** 
  267. * Removes an item or list from the query string. 
  268. * 
  269. * @since 1.5.0 
  270. * 
  271. * @param string|array $key Query key or keys to remove. 
  272. * @param bool $query When false uses the $_SERVER value. 
  273. * @return string New URL query string. 
  274. */ 
  275. function remove_query_arg( $key, $query=false ) { 
  276. if ( is_array( $key ) ) { // removing multiple keys 
  277. foreach ( $key as $k ) 
  278. $query = add_query_arg( $k, false, $query ); 
  279. return $query; 
  280. return add_query_arg( $key, false, $query ); 
  281. endif; 
  282.  
  283. // ! function add_magic_quotes() 
  284.  
  285. if ( !function_exists( 'wp_remote_fopen' ) ) : 
  286. /** 
  287. * HTTP request for URI to retrieve content. 
  288. * 
  289. * @since 1.5.1 
  290. * @uses wp_remote_get() 
  291. * 
  292. * @param string $uri URI/URL of web page to retrieve. 
  293. * @return bool|string HTTP content. False on failure. 
  294. */ 
  295. function wp_remote_fopen( $uri ) { 
  296. $parsed_url = @parse_url( $uri ); 
  297.  
  298. if ( !$parsed_url || !is_array( $parsed_url ) ) 
  299. return false; 
  300.  
  301. $options = array(); 
  302. $options['timeout'] = 10; 
  303.  
  304. $response = wp_remote_get( $uri, $options ); 
  305.  
  306. if ( is_wp_error( $response ) ) 
  307. return false; 
  308.  
  309. return $response['body']; 
  310. endif; 
  311.  
  312. // ! function wp() 
  313.  
  314. if ( !function_exists( 'get_status_header_desc' ) ) : 
  315. /** 
  316. * Retrieve the description for the HTTP status. 
  317. * 
  318. * @since 2.3.0 
  319. * 
  320. * @param int $code HTTP status code. 
  321. * @return string Empty string if not found, or description if found. 
  322. */ 
  323. function get_status_header_desc( $code ) { 
  324. global $wp_header_to_desc; 
  325.  
  326. $code = absint( $code ); 
  327.  
  328. if ( !isset( $wp_header_to_desc ) ) { 
  329. $wp_header_to_desc = array( 
  330. 100 => 'Continue',  
  331. 101 => 'Switching Protocols',  
  332. 102 => 'Processing',  
  333.  
  334. 200 => 'OK',  
  335. 201 => 'Created',  
  336. 202 => 'Accepted',  
  337. 203 => 'Non-Authoritative Information',  
  338. 204 => 'No Content',  
  339. 205 => 'Reset Content',  
  340. 206 => 'Partial Content',  
  341. 207 => 'Multi-Status',  
  342. 226 => 'IM Used',  
  343.  
  344. 300 => 'Multiple Choices',  
  345. 301 => 'Moved Permanently',  
  346. 302 => 'Found',  
  347. 303 => 'See Other',  
  348. 304 => 'Not Modified',  
  349. 305 => 'Use Proxy',  
  350. 306 => 'Reserved',  
  351. 307 => 'Temporary Redirect',  
  352.  
  353. 400 => 'Bad Request',  
  354. 401 => 'Unauthorized',  
  355. 402 => 'Payment Required',  
  356. 403 => 'Forbidden',  
  357. 404 => 'Not Found',  
  358. 405 => 'Method Not Allowed',  
  359. 406 => 'Not Acceptable',  
  360. 407 => 'Proxy Authentication Required',  
  361. 408 => 'Request Timeout',  
  362. 409 => 'Conflict',  
  363. 410 => 'Gone',  
  364. 411 => 'Length Required',  
  365. 412 => 'Precondition Failed',  
  366. 413 => 'Request Entity Too Large',  
  367. 414 => 'Request-URI Too Long',  
  368. 415 => 'Unsupported Media Type',  
  369. 416 => 'Requested Range Not Satisfiable',  
  370. 417 => 'Expectation Failed',  
  371. 422 => 'Unprocessable Entity',  
  372. 423 => 'Locked',  
  373. 424 => 'Failed Dependency',  
  374. 426 => 'Upgrade Required',  
  375.  
  376. 500 => 'Internal Server Error',  
  377. 501 => 'Not Implemented',  
  378. 502 => 'Bad Gateway',  
  379. 503 => 'Service Unavailable',  
  380. 504 => 'Gateway Timeout',  
  381. 505 => 'HTTP Version Not Supported',  
  382. 506 => 'Variant Also Negotiates',  
  383. 507 => 'Insufficient Storage',  
  384. 510 => 'Not Extended' 
  385. ); 
  386.  
  387. if ( isset( $wp_header_to_desc[$code] ) ) 
  388. return $wp_header_to_desc[$code]; 
  389. else 
  390. return ''; 
  391. endif; 
  392.  
  393. if ( !function_exists( 'status_header' ) ) : 
  394. /** 
  395. * Set HTTP status header. 
  396. * 
  397. * @since 2.0.0 
  398. * @uses apply_filters() Calls 'status_header' on status header string, HTTP 
  399. * HTTP code, HTTP code description, and protocol string as separate 
  400. * parameters. 
  401. * 
  402. * @param int $header HTTP status code 
  403. * @return null Does not return anything. 
  404. */ 
  405. function status_header( $header ) { 
  406. $text = get_status_header_desc( $header ); 
  407.  
  408. if ( empty( $text ) ) 
  409. return false; 
  410.  
  411. $protocol = $_SERVER["SERVER_PROTOCOL"]; 
  412. if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol ) 
  413. $protocol = 'HTTP/1.0'; 
  414. $status_header = "$protocol $header $text"; 
  415. if ( function_exists( 'apply_filters' ) ) 
  416. $status_header = apply_filters( 'status_header', $status_header, $header, $text, $protocol ); 
  417.  
  418. return @header( $status_header, true, $header ); 
  419. endif; 
  420.  
  421. if ( !function_exists( 'wp_get_nocache_headers' ) ) : 
  422. /** 
  423. * Gets the header information to prevent caching. 
  424. * 
  425. * The several different headers cover the different ways cache prevention is handled 
  426. * by different browsers 
  427. * 
  428. * @since 2.8 
  429. * 
  430. * @uses apply_filters() 
  431. * @return array The associative array of header names and field values. 
  432. */ 
  433. function wp_get_nocache_headers() { 
  434. $headers = array( 
  435. 'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT',  
  436. 'Last-Modified' => gmdate( 'D, d M Y H:i:s' ) . ' GMT',  
  437. 'Cache-Control' => 'no-cache, must-revalidate, max-age=0',  
  438. 'Pragma' => 'no-cache',  
  439. ); 
  440.  
  441. if ( function_exists('apply_filters') ) { 
  442. $headers = apply_filters('nocache_headers', $headers); 
  443. return $headers; 
  444. endif; 
  445.  
  446. if ( !function_exists( 'nocache_headers' ) ) : 
  447. /** 
  448. * Sets the headers to prevent caching for the different browsers. 
  449. * 
  450. * Different browsers support different nocache headers, so several headers must 
  451. * be sent so that all of them get the point that no caching should occur. 
  452. * 
  453. * @since 2.0.0 
  454. * @uses wp_get_nocache_headers() 
  455. */ 
  456. function nocache_headers() { 
  457. $headers = wp_get_nocache_headers(); 
  458. foreach( (array) $headers as $name => $field_value ) 
  459. @header("{$name}: {$field_value}"); 
  460. endif; 
  461.  
  462. if ( !function_exists( 'cache_javascript_headers' ) ) : 
  463. /** 
  464. * Set the headers for caching for 10 days with JavaScript content type. 
  465. * 
  466. * @since 2.1.0 
  467. */ 
  468. function cache_javascript_headers() { 
  469. $expiresOffset = 864000; // 10 days 
  470. header( "Content-Type: text/javascript; charset=" . backpress_get_option( 'charset' ) ); 
  471. header( "Vary: Accept-Encoding" ); // Handle proxies 
  472. header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + $expiresOffset ) . " GMT" ); 
  473. endif; 
  474.  
  475. // ! function get_num_queries() 
  476. // ! function bool_from_yn() 
  477. // ! function do_feed() 
  478. // ! function do_feed_rdf() 
  479. // ! function do_feed_rss() 
  480. // ! function do_feed_rss2() 
  481. // ! function do_feed_atom() 
  482. // ! function do_robots() 
  483. // ! function is_blog_installed() 
  484. // ! function wp_nonce_url() 
  485. // ! function wp_nonce_field() 
  486.  
  487. if ( !function_exists( 'wp_referer_field' ) ) : 
  488. /** 
  489. * Retrieve or display referer hidden field for forms. 
  490. * 
  491. * The referer link is the current Request URI from the server super global. The 
  492. * input name is '_wp_http_referer', in case you wanted to check manually. 
  493. * 
  494. * @package WordPress 
  495. * @subpackage Security 
  496. * @since 2.0.4 
  497. * 
  498. * @param bool $echo Whether to echo or return the referer field. 
  499. * @return string Referer field. 
  500. */ 
  501. function wp_referer_field( $echo = true) { 
  502. $ref = esc_attr( $_SERVER['REQUEST_URI'] ); 
  503. $referer_field = '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />'; 
  504.  
  505. if ( $echo ) 
  506. echo $referer_field; 
  507. return $referer_field; 
  508. endif; 
  509.  
  510. if ( !function_exists( 'wp_original_referer_field' ) ) : 
  511. /** 
  512. * Retrieve or display original referer hidden field for forms. 
  513. * 
  514. * The input name is '_wp_original_http_referer' and will be either the same 
  515. * value of {@link wp_referer_field()}, if that was posted already or it will 
  516. * be the current page, if it doesn't exist. 
  517. * 
  518. * @package WordPress 
  519. * @subpackage Security 
  520. * @since 2.0.4 
  521. * 
  522. * @param bool $echo Whether to echo the original http referer 
  523. * @param string $jump_back_to Optional, default is 'current'. Can be 'previous' or page you want to jump back to. 
  524. * @return string Original referer field. 
  525. */ 
  526. function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) { 
  527. $jump_back_to = ( 'previous' == $jump_back_to ) ? wp_get_referer() : $_SERVER['REQUEST_URI']; 
  528. $ref = ( wp_get_original_referer() ) ? wp_get_original_referer() : $jump_back_to; 
  529. $orig_referer_field = '<input type="hidden" name="_wp_original_http_referer" value="' . esc_attr( stripslashes( $ref ) ) . '" />'; 
  530. if ( $echo ) 
  531. echo $orig_referer_field; 
  532. return $orig_referer_field; 
  533. endif; 
  534.  
  535. if ( !function_exists( 'wp_get_referer' ) ) : 
  536. /** 
  537. * Retrieve referer from '_wp_http_referer', HTTP referer, or current page respectively. 
  538. * 
  539. * @package WordPress 
  540. * @subpackage Security 
  541. * @since 2.0.4 
  542. * 
  543. * @return string|bool False on failure. Referer URL on success. 
  544. */ 
  545. function wp_get_referer() { 
  546. $ref = ''; 
  547. if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) 
  548. $ref = $_REQUEST['_wp_http_referer']; 
  549. else if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) 
  550. $ref = $_SERVER['HTTP_REFERER']; 
  551.  
  552. if ( $ref !== $_SERVER['REQUEST_URI'] ) 
  553. return $ref; 
  554. return false; 
  555. endif; 
  556.  
  557. if ( !function_exists( 'wp_get_original_referer' ) ) : 
  558. /** 
  559. * Retrieve original referer that was posted, if it exists. 
  560. * 
  561. * @package WordPress 
  562. * @subpackage Security 
  563. * @since 2.0.4 
  564. * 
  565. * @return string|bool False if no original referer or original referer if set. 
  566. */ 
  567. function wp_get_original_referer() { 
  568. if ( !empty( $_REQUEST['_wp_original_http_referer'] ) ) 
  569. return $_REQUEST['_wp_original_http_referer']; 
  570. return false; 
  571. endif; 
  572.  
  573. // ! function wp_mkdir_p() 
  574. // ! function path_is_absolute() 
  575. // ! function path_join() 
  576. // ! function wp_upload_dir() 
  577. // ! function wp_unique_filename() 
  578. // ! function wp_upload_bits() 
  579. // ! function wp_ext2type() 
  580. // ! function wp_check_filetype() 
  581. // ! function wp_explain_nonce() 
  582. // ! function wp_nonce_ays() 
  583. // ! function wp_die() 
  584. // ! function _config_wp_home() 
  585. // ! function _config_wp_siteurl() 
  586. // ! function _mce_set_direction() 
  587. // ! function smilies_init() 
  588.  
  589. if ( !function_exists('wp_parse_args') ) : 
  590. /** 
  591. * Merge user defined arguments into defaults array. 
  592. * 
  593. * This function is used throughout WordPress to allow for both string or array 
  594. * to be merged into another array. 
  595. * 
  596. * @since 2.2.0 
  597. * 
  598. * @param string|array $args Value to merge with $defaults 
  599. * @param array $defaults Array that serves as the defaults. 
  600. * @return array Merged user defined values with defaults. 
  601. */ 
  602. function wp_parse_args( $args, $defaults = '' ) { 
  603. if ( is_object( $args ) ) 
  604. $r = get_object_vars( $args ); 
  605. elseif ( is_array( $args ) ) 
  606. $r =& $args; 
  607. else 
  608. wp_parse_str( $args, $r ); 
  609.  
  610. if ( is_array( $defaults ) ) 
  611. return array_merge( $defaults, $r ); 
  612. return $r; 
  613. endif; 
  614.  
  615. // ! function wp_maybe_load_widgets() 
  616. // ! function wp_widgets_add_menu() 
  617. // ! function wp_ob_end_flush_all() 
  618. // ! function require_wp_db() 
  619. // ! function dead_db() 
  620.  
  621. if ( !function_exists('absint') ) : 
  622. /** 
  623. * Converts value to nonnegative integer. 
  624. * 
  625. * @since 2.5.0 
  626. * 
  627. * @param mixed $maybeint Data you wish to have convered to an nonnegative integer 
  628. * @return int An nonnegative integer 
  629. */ 
  630. function absint( $maybeint ) { 
  631. return abs( intval( $maybeint ) ); 
  632. endif; 
  633.  
  634. // ! function url_is_accessable_via_ssl() 
  635. // ! function atom_service_url_filter() 
  636. // ! function _deprecated_function() 
  637. // ! function _deprecated_file() 
  638.  
  639. if ( !function_exists('is_lighttpd_before_150') ) : 
  640. /** 
  641. * Is the server running earlier than 1.5.0 version of lighttpd 
  642. * 
  643. * @since 2.5.0 
  644. * 
  645. * @return bool Whether the server is running lighttpd < 1.5.0 
  646. */ 
  647. function is_lighttpd_before_150() { 
  648. $server_parts = explode( '/', isset( $_SERVER['SERVER_SOFTWARE'] )? $_SERVER['SERVER_SOFTWARE'] : '' ); 
  649. $server_parts[1] = isset( $server_parts[1] )? $server_parts[1] : ''; 
  650. return 'lighttpd' == $server_parts[0] && -1 == version_compare( $server_parts[1], '1.5.0' ); 
  651. endif; 
  652.  
  653. if ( !function_exists('apache_mod_loaded') ) : 
  654. /** 
  655. * Does the specified module exist in the apache config? 
  656. * 
  657. * @since 2.5.0 
  658. * 
  659. * @param string $mod e.g. mod_rewrite 
  660. * @param bool $default The default return value if the module is not found 
  661. * @return bool 
  662. */ 
  663. function apache_mod_loaded($mod, $default = false) { 
  664. global $is_apache; 
  665.  
  666. if ( !$is_apache ) 
  667. return false; 
  668.  
  669. if ( function_exists('apache_get_modules') ) { 
  670. $mods = apache_get_modules(); 
  671. if ( in_array($mod, $mods) ) 
  672. return true; 
  673. } elseif ( function_exists('phpinfo') ) { 
  674. ob_start(); 
  675. phpinfo(8); 
  676. $phpinfo = ob_get_clean(); 
  677. if ( false !== strpos($phpinfo, $mod) ) 
  678. return true; 
  679. return $default; 
  680. endif; 
  681.  
  682. if ( !function_exists('validate_file') ) : 
  683. /** 
  684. * File validates against allowed set of defined rules. 
  685. * 
  686. * A return value of '1' means that the $file contains either '..' or './'. A 
  687. * return value of '2' means that the $file contains ':' after the first 
  688. * character. A return value of '3' means that the file is not in the allowed 
  689. * files list. 
  690. * 
  691. * @since 1.2.0 
  692. * 
  693. * @param string $file File path. 
  694. * @param array $allowed_files List of allowed files. 
  695. * @return int 0 means nothing is wrong, greater than 0 means something was wrong. 
  696. */ 
  697. function validate_file( $file, $allowed_files = '' ) { 
  698. if ( false !== strpos( $file, '..' )) 
  699. return 1; 
  700.  
  701. if ( false !== strpos( $file, './' )) 
  702. return 1; 
  703.  
  704. if (':' == substr( $file, 1, 1 )) 
  705. return 2; 
  706.  
  707. if (!empty ( $allowed_files ) && (!in_array( $file, $allowed_files ) ) ) 
  708. return 3; 
  709.  
  710. return 0; 
  711. endif; 
  712.  
  713. if ( !function_exists('is_ssl') ) : 
  714. /** 
  715. * Determine if SSL is used. 
  716. * 
  717. * @since 2.6.0 
  718. * 
  719. * @return bool True if SSL, false if not used. 
  720. */ 
  721. function is_ssl() { 
  722. if ( isset($_SERVER['HTTPS']) ) { 
  723. if ( 'on' == strtolower($_SERVER['HTTPS']) ) 
  724. return true; 
  725. if ( '1' == $_SERVER['HTTPS'] ) 
  726. return true; 
  727. } elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) { 
  728. return true; 
  729. return false; 
  730. endif; 
  731.  
  732. if ( !function_exists('force_ssl_login') ) : 
  733. /** 
  734. * Whether SSL login should be forced. 
  735. * 
  736. * @since 2.6.0 
  737. * 
  738. * @param string|bool $force Optional. 
  739. * @return bool True if forced, false if not forced. 
  740. */ 
  741. function force_ssl_login($force = '') { 
  742. static $forced; 
  743.  
  744. if ( '' != $force ) { 
  745. $old_forced = $forced; 
  746. $forced = $force; 
  747. return $old_forced; 
  748.  
  749. return $forced; 
  750. endif; 
  751.  
  752. if ( !function_exists('force_ssl_admin') ) : 
  753. /** 
  754. * Whether to force SSL used for the Administration Panels. 
  755. * 
  756. * @since 2.6.0 
  757. * 
  758. * @param string|bool $force 
  759. * @return bool True if forced, false if not forced. 
  760. */ 
  761. function force_ssl_admin($force = '') { 
  762. static $forced; 
  763.  
  764. if ( '' != $force ) { 
  765. $old_forced = $forced; 
  766. $forced = $force; 
  767. return $old_forced; 
  768.  
  769. return $forced; 
  770. endif; 
  771.  
  772. // ! function wp_guess_url() 
  773. // ! function wp_suspend_cache_invalidation() 
  774. // ! function get_site_option() 
  775. // ! function add_site_option() 
  776. // ! function update_site_option() 
  777.  
  778. if ( !function_exists('wp_timezone_override_offset') ) : 
  779. /** 
  780. * gmt_offset modification for smart timezone handling 
  781. * 
  782. * Overrides the gmt_offset option if we have a timezone_string available 
  783. */ 
  784. function wp_timezone_override_offset() { 
  785. if ( !wp_timezone_supported() ) { 
  786. return false; 
  787. if ( !$timezone_string = backpress_get_option( 'timezone_string' ) ) { 
  788. return false; 
  789.  
  790. @date_default_timezone_set( $timezone_string ); 
  791. $timezone_object = timezone_open( $timezone_string ); 
  792. $datetime_object = date_create(); 
  793. if ( false === $timezone_object || false === $datetime_object ) { 
  794. return false; 
  795. return round( timezone_offset_get( $timezone_object, $datetime_object ) / 3600, 2 ); 
  796. endif; 
  797.  
  798. if ( !function_exists('wp_timezone_supported') ) : 
  799. /** 
  800. * Check for PHP timezone support 
  801. */ 
  802. function wp_timezone_supported() { 
  803. $support = false; 
  804. if ( 
  805. function_exists( 'date_default_timezone_set' ) && 
  806. function_exists( 'timezone_identifiers_list' ) && 
  807. function_exists( 'timezone_open' ) && 
  808. function_exists( 'timezone_offset_get' ) 
  809. ) { 
  810. $support = true; 
  811. return apply_filters( 'timezone_support', $support ); 
  812. endif; 
  813.  
  814. if ( !function_exists('_wp_timezone_choice_usort_callback') ) : 
  815. function _wp_timezone_choice_usort_callback( $a, $b ) { 
  816. // Don't use translated versions of Etc 
  817. if ( 'Etc' === $a['continent'] && 'Etc' === $b['continent'] ) { 
  818. // Make the order of these more like the old dropdown 
  819. if ( 'GMT+' === substr( $a['city'], 0, 4 ) && 'GMT+' === substr( $b['city'], 0, 4 ) ) { 
  820. return -1 * ( strnatcasecmp( $a['city'], $b['city'] ) ); 
  821. if ( 'UTC' === $a['city'] ) { 
  822. if ( 'GMT+' === substr( $b['city'], 0, 4 ) ) { 
  823. return 1; 
  824. return -1; 
  825. if ( 'UTC' === $b['city'] ) { 
  826. if ( 'GMT+' === substr( $a['city'], 0, 4 ) ) { 
  827. return -1; 
  828. return 1; 
  829. return strnatcasecmp( $a['city'], $b['city'] ); 
  830. if ( $a['t_continent'] == $b['t_continent'] ) { 
  831. if ( $a['t_city'] == $b['t_city'] ) { 
  832. return strnatcasecmp( $a['t_subcity'], $b['t_subcity'] ); 
  833. return strnatcasecmp( $a['t_city'], $b['t_city'] ); 
  834. } else { 
  835. // Force Etc to the bottom of the list 
  836. if ( 'Etc' === $a['continent'] ) { 
  837. return 1; 
  838. if ( 'Etc' === $b['continent'] ) { 
  839. return -1; 
  840. return strnatcasecmp( $a['t_continent'], $b['t_continent'] ); 
  841. endif; 
  842.  
  843. if ( !function_exists('wp_timezone_choice') ) : 
  844. /** 
  845. * Gives a nicely formatted list of timezone strings // temporary! Not in final 
  846. * 
  847. * @param $selected_zone string Selected Zone 
  848. * 
  849. */ 
  850. function wp_timezone_choice( $selected_zone ) { 
  851. static $mo_loaded = false; 
  852.  
  853. $continents = array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific', 'Etc' ); 
  854.  
  855. // Load translations for continents and cities 
  856. if ( !$mo_loaded ) { 
  857. $locale = backpress_get_option( 'language_locale' ); 
  858. $mofile = backpress_get_option( 'language_directory' ) . 'continents-cities-' . $locale . '.mo'; 
  859. load_textdomain( 'continents-cities', $mofile ); 
  860. $mo_loaded = true; 
  861.  
  862. $zonen = array(); 
  863. foreach ( timezone_identifiers_list() as $zone ) { 
  864. $zone = explode( '/', $zone ); 
  865. if ( !in_array( $zone[0], $continents ) ) { 
  866. continue; 
  867. if ( 'Etc' === $zone[0] && in_array( $zone[1], array( 'UCT', 'GMT', 'GMT0', 'GMT+0', 'GMT-0', 'Greenwich', 'Universal', 'Zulu' ) ) ) { 
  868. continue; 
  869.  
  870. // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later 
  871. $exists = array( 
  872. 0 => ( isset( $zone[0] ) && $zone[0] ) ? true : false,  
  873. 1 => ( isset( $zone[1] ) && $zone[1] ) ? true : false,  
  874. 2 => ( isset( $zone[2] ) && $zone[2] ) ? true : false 
  875. ); 
  876. $exists[3] = ( $exists[0] && 'Etc' !== $zone[0] ) ? true : false; 
  877. $exists[4] = ( $exists[1] && $exists[3] ) ? true : false; 
  878. $exists[5] = ( $exists[2] && $exists[3] ) ? true : false; 
  879.  
  880. $zonen[] = array( 
  881. 'continent' => ( $exists[0] ? $zone[0] : '' ),  
  882. 'city' => ( $exists[1] ? $zone[1] : '' ),  
  883. 'subcity' => ( $exists[2] ? $zone[2] : '' ),  
  884. 't_continent' => ( $exists[3] ? translate( str_replace( '_', ' ', $zone[0] ), 'continents-cities' ) : '' ),  
  885. 't_city' => ( $exists[4] ? translate( str_replace( '_', ' ', $zone[1] ), 'continents-cities' ) : '' ),  
  886. 't_subcity' => ( $exists[5] ? translate( str_replace( '_', ' ', $zone[2] ), 'continents-cities' ) : '' ) 
  887. ); 
  888. usort( $zonen, '_wp_timezone_choice_usort_callback' ); 
  889.  
  890. $structure = array(); 
  891.  
  892. if ( empty( $selected_zone ) ) { 
  893. $structure[] = '<option selected="selected" value="">' . __( 'Select a city' ) . '</option>'; 
  894.  
  895. foreach ( $zonen as $key => $zone ) { 
  896. // Build value in an array to join later 
  897. $value = array( $zone['continent'] ); 
  898.  
  899. if ( empty( $zone['city'] ) ) { 
  900. // It's at the continent level (generally won't happen) 
  901. $display = $zone['t_continent']; 
  902. } else { 
  903. // It's inside a continent group 
  904.  
  905. // Continent optgroup 
  906. if ( !isset( $zonen[$key - 1] ) || $zonen[$key - 1]['continent'] !== $zone['continent'] ) { 
  907. $label = ( 'Etc' === $zone['continent'] ) ? __( 'Manual offsets' ) : $zone['t_continent']; 
  908. $structure[] = '<optgroup label="'. esc_attr( $label ) .'">'; 
  909.  
  910. // Add the city to the value 
  911. $value[] = $zone['city']; 
  912. if ( 'Etc' === $zone['continent'] ) { 
  913. if ( 'UTC' === $zone['city'] ) { 
  914. $display = ''; 
  915. } else { 
  916. $display = str_replace( 'GMT', '', $zone['city'] ); 
  917. $display = strtr( $display, '+-', '-+' ) . ':00'; 
  918. $display = sprintf( __( 'UTC %s' ), $display ); 
  919. } else { 
  920. $display = $zone['t_city']; 
  921. if ( !empty( $zone['subcity'] ) ) { 
  922. // Add the subcity to the value 
  923. $value[] = $zone['subcity']; 
  924. $display .= ' - ' . $zone['t_subcity']; 
  925.  
  926. // Build the value 
  927. $value = join( '/', $value ); 
  928. $selected = ''; 
  929. if ( $value === $selected_zone ) { 
  930. $selected = 'selected="selected" '; 
  931. $structure[] = '<option ' . $selected . 'value="' . esc_attr( $value ) . '">' . esc_html( $display ) . "</option>"; 
  932.  
  933. // Close continent optgroup 
  934. if ( !empty( $zone['city'] ) && ( !isset($zonen[$key + 1]) || (isset( $zonen[$key + 1] ) && $zonen[$key + 1]['continent'] !== $zone['continent']) ) ) { 
  935. $structure[] = '</optgroup>'; 
  936.  
  937. return join( "\n", $structure ); 
  938. endif; 
  939.  
  940. if ( !function_exists('_cleanup_header_comment') ) : 
  941. /** 
  942. * Strip close comment and close php tags from file headers used by WP 
  943. * See http://core.trac.wordpress.org/ticket/8497 
  944. * 
  945. * @since 2.8 
  946. */ 
  947. function _cleanup_header_comment($str) { 
  948. return trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $str)); 
  949. endif; 
  950.  
  951.  
  952.  
  953. /** 
  954. * From WP wp-settings.php 
  955. */ 
  956.  
  957. if ( !function_exists( 'wp_clone' ) ) : 
  958. /** 
  959. * Copy an object. 
  960. * 
  961. * Returns a cloned copy of an object. 
  962. * 
  963. * @since 2.7.0 
  964. * 
  965. * @param object $object The object to clone 
  966. * @return object The cloned object 
  967. */ 
  968. function wp_clone( $object ) { 
  969. static $can_clone; 
  970. if ( !isset( $can_clone ) ) { 
  971. $can_clone = version_compare( phpversion(), '5.0', '>=' ); 
  972. return $can_clone ? clone( $object ) : $object; 
  973. endif; 
  974.  
  975.  
  976.  
  977. /** 
  978. * BackPress only below 
  979. */ 
  980.  
  981. if ( !function_exists('backpress_gmt_strtotime') ) : 
  982. function backpress_gmt_strtotime( $string ) { 
  983. if ( is_numeric($string) ) 
  984. return $string; 
  985. if ( !is_string($string) ) 
  986. return -1; 
  987.  
  988. if ( stristr($string, 'utc') || stristr($string, 'gmt') || stristr($string, '+0000') ) 
  989. return strtotime($string); 
  990.  
  991. if ( -1 == $time = strtotime($string . ' +0000') ) 
  992. return strtotime($string); 
  993.  
  994. return $time; 
  995. endif; 
  996.  
  997. if ( !function_exists('backpress_convert_object') ) : 
  998. function backpress_convert_object( &$object, $output ) { 
  999. if ( is_array( $object ) ) { 
  1000. foreach ( array_keys( $object ) as $key ) 
  1001. backpress_convert_object( $object[$key], $output ); 
  1002. } else { 
  1003. switch ( $output ) { 
  1004. case OBJECT : break; 
  1005. case ARRAY_A : $object = get_object_vars($object); break; 
  1006. case ARRAY_N : $object = array_values(get_object_vars($object)); break; 
  1007. endif; 
  1008.  
  1009. if ( !function_exists('backpress_die') ) : 
  1010. /** 
  1011. * Kill BackPress execution and display HTML message with error message. 
  1012. * 
  1013. * This function calls the die() PHP function. The difference is that a message 
  1014. * in HTML will be displayed to the user. It is recommended to use this function 
  1015. * only when the execution should not continue any further. It is not 
  1016. * recommended to call this function very often and normally you should try to 
  1017. * handle as many errors as possible silently. 
  1018. * 
  1019. * @param string $message Error message. 
  1020. * @param string $title Error title. 
  1021. * @param string|array $args Optional arguments to control behaviour. 
  1022. */ 
  1023. function backpress_die( $message, $title = '', $args = array() ) 
  1024. $defaults = array( 'response' => 500, 'language' => 'en-US', 'text_direction' => 'ltr' ); 
  1025. $r = wp_parse_args( $args, $defaults ); 
  1026.  
  1027. if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) { 
  1028. if ( empty( $title ) ) { 
  1029. $error_data = $message->get_error_data(); 
  1030. if ( is_array( $error_data ) && isset( $error_data['title'] ) ) { 
  1031. $title = $error_data['title']; 
  1032. $errors = $message->get_error_messages(); 
  1033. switch ( count( $errors ) ) { 
  1034. case 0: 
  1035. $message = ''; 
  1036. break; 
  1037. case 1: 
  1038. $message = '<p>' . $errors[0] . '</p>'; 
  1039. break; 
  1040. default: 
  1041. $message = "<ul>\n\t\t<li>" . join( "</li>\n\t\t<li>", $errors ) . "</li>\n\t</ul>"; 
  1042. break; 
  1043. } elseif ( is_string( $message ) ) { 
  1044. $message = '<p>' . $message . '</p>'; 
  1045.  
  1046. if ( !headers_sent() ) { 
  1047. status_header( $r['response'] ); 
  1048. nocache_headers(); 
  1049. header( 'Content-Type: text/html; charset=utf-8' ); 
  1050.  
  1051. if ( empty( $title ) ) { 
  1052. if ( function_exists( '__' ) ) { 
  1053. $title = __( 'BackPress › Error' ); 
  1054. } else { 
  1055. $title = 'BackPress › Error'; 
  1056.  
  1057. if ( $r['text_direction'] ) { 
  1058. $language_attributes = ' dir="' . $r['text_direction'] . '"'; 
  1059.  
  1060. if ( $r['language'] ) { 
  1061. // Always XHTML 1.1 style 
  1062. $language_attributes .= ' lang="' . $r['language'] . '"'; 
  1063. ?> 
  1064. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
  1065. <html xmlns="http://www.w3.org/1999/xhtml"<?php echo $language_attributes; ?>> 
  1066. <head> 
  1067. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  1068. <title><?php echo $title ?></title> 
  1069. <style type="text/css" media="screen"> 
  1070. html { background: #f7f7f7; } 
  1071.  
  1072. body { 
  1073. background: #fff; 
  1074. color: #333; 
  1075. font-family: "Lucida Grande", Verdana, Arial, "Bitstream Vera Sans", sans-serif; 
  1076. margin: 2em auto 0 auto; 
  1077. width: 700px; 
  1078. padding: 1em 2em; 
  1079. -moz-border-radius: 11px; 
  1080. -khtml-border-radius: 11px; 
  1081. -webkit-border-radius: 11px; 
  1082. border-radius: 11px; 
  1083. border: 1px solid #dfdfdf; 
  1084.  
  1085. a { color: #2583ad; text-decoration: none; } 
  1086.  
  1087. a:hover { color: #d54e21; } 
  1088.  
  1089. h1 { 
  1090. border-bottom: 1px solid #dadada; 
  1091. clear: both; 
  1092. color: #666; 
  1093. font: 24px Georgia, "Times New Roman", Times, serif; 
  1094. margin: 5px 0 0 -4px; 
  1095. padding: 0; 
  1096. padding-bottom: 7px; 
  1097.  
  1098. h2 { font-size: 16px; } 
  1099.  
  1100. p, li { 
  1101. padding-bottom: 2px; 
  1102. font-size: 12px; 
  1103. line-height: 18px; 
  1104.  
  1105. code { font-size: 13px; } 
  1106.  
  1107. ul, ol { padding: 5px 5px 5px 22px; } 
  1108.  
  1109. #error-page { margin-top: 50px; } 
  1110.  
  1111. #error-page p { 
  1112. font-size: 12px; 
  1113. line-height: 18px; 
  1114. margin: 25px 0 20px; 
  1115.  
  1116. #error-page code { font-family: Consolas, Monaco, Courier, monospace; } 
  1117. <?php 
  1118. if ( $r['text_direction'] === 'rtl') { 
  1119. ?> 
  1120. body { 
  1121. font-family: Tahoma, "Times New Roman"; 
  1122.  
  1123. h1 { 
  1124. font-family: Tahoma, "Times New Roman"; 
  1125. margin: 5px -4px 0 0; 
  1126.  
  1127. ul, ol { padding: 5px 22px 5px 5px; } 
  1128. <?php 
  1129. ?> 
  1130. </style> 
  1131. </head> 
  1132. <body id="error-page"> 
  1133. <?php echo $message; ?> 
  1134. </body> 
  1135. </html> 
  1136. <?php 
  1137. die(); 
  1138. endif; 
  1139.  
  1140. /** 
  1141. * Acts the same as core PHP setcookie() but its arguments are run through the backpress_set_cookie filter. 
  1142. *  
  1143. * If the filter returns false, setcookie() isn't called. 
  1144. */ 
  1145. function backpress_set_cookie() { 
  1146. $args = func_get_args(); 
  1147. $args = apply_filters( 'backpress_set_cookie', $args ); 
  1148. if ( $args === false ) return; 
  1149. call_user_func_array( 'setcookie', $args ); 
.