[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-forums/bbpress/bb-includes/backpress/ -> functions.core.php (source)

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


Generated: Sat Apr 27 01:00:55 2024 Cross-referenced by PHPXref 0.7.1