Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r18031 r18321  
    8585    global $wp_locale;
    8686    $i = $unixtimestamp;
    87     // Sanity check for PHP 5.1.0-
    88     if ( false === $i || intval($i) < 0 ) {
     87
     88    if ( false === $i ) {
    8989        if ( ! $gmt )
    9090            $i = current_time( 'timestamp' );
     
    121121    $timezone_formats = array( 'P', 'I', 'O', 'T', 'Z', 'e' );
    122122    $timezone_formats_re = implode( '|', $timezone_formats );
    123     if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) && wp_timezone_supported() ) {
     123    if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) ) {
    124124        $timezone_string = get_option( 'timezone_string' );
    125125        if ( $timezone_string ) {
     
    289289        return false;
    290290    $data = trim( $data );
    291     if ( preg_match( '/^s:[0-9]+:.*;$/s', $data ) ) // this should fetch all serialized strings
     291    $length = strlen( $data );
     292    if ( $length < 4 )
     293        return false;
     294    elseif ( ':' !== $data[1] )
     295        return false;
     296    elseif ( ';' !== $data[$length-1] )
     297        return false;
     298    elseif ( $data[0] !== 's' )
     299        return false;
     300    elseif ( '"' !== $data[$length-2] )
     301        return false;
     302    else
    292303        return true;
    293     return false;
    294304}
    295305
     
    510520
    511521    if ( is_object($newvalue) )
    512         $newvalue = wp_clone($newvalue);
     522        $newvalue = clone $newvalue;
    513523
    514524    $newvalue = sanitize_option( $option, $newvalue );
     
    592602
    593603    if ( is_object($value) )
    594         $value = wp_clone($value);
     604        $value = clone $value;
    595605
    596606    $value = sanitize_option( $option, $value );
     
    12921302
    12931303    $headers = wp_remote_retrieve_headers( $response );
    1294     $headers['response'] = $response['response']['code'];
     1304    $headers['response'] = wp_remote_retrieve_response_code( $response );
    12951305
    12961306    // WP_HTTP no longer follows redirects for HEAD requests.
     
    13071317        return $headers;
    13081318
    1309     fwrite( $out_fp,  $response['body']);
     1319    fwrite( $out_fp,  wp_remote_retrieve_body( $response ) );
    13101320    fclose($out_fp);
    13111321    clearstatcache();
     
    13691379function build_query( $data ) {
    13701380    return _http_build_query( $data, null, '&', '', false );
     1381}
     1382
     1383// from php.net (modified by Mark Jaquith to behave like the native PHP5 function)
     1384function _http_build_query($data, $prefix=null, $sep=null, $key='', $urlencode=true) {
     1385    $ret = array();
     1386
     1387    foreach ( (array) $data as $k => $v ) {
     1388        if ( $urlencode)
     1389            $k = urlencode($k);
     1390        if ( is_int($k) && $prefix != null )
     1391            $k = $prefix.$k;
     1392        if ( !empty($key) )
     1393            $k = $key . '%5B' . $k . '%5D';
     1394        if ( $v === NULL )
     1395            continue;
     1396        elseif ( $v === FALSE )
     1397            $v = '0';
     1398
     1399        if ( is_array($v) || is_object($v) )
     1400            array_push($ret,_http_build_query($v, '', $sep, $k, $urlencode));
     1401        elseif ( $urlencode )
     1402            array_push($ret, $k.'='.urlencode($v));
     1403        else
     1404            array_push($ret, $k.'='.$v);
     1405    }
     1406
     1407    if ( NULL === $sep )
     1408        $sep = ini_get('arg_separator.output');
     1409
     1410    return implode($sep, $ret);
    13711411}
    13721412
     
    15131553        return false;
    15141554
    1515     return $response['body'];
     1555    return wp_remote_retrieve_body( $response );
    15161556}
    15171557
     
    19111951 * important to use nonce field in forms.
    19121952 *
    1913  * If you set $echo to true and set $referer to true, then you will need to
    1914  * retrieve the {@link wp_referer_field() wp referer field}. If you have the
    1915  * $referer set to true and are echoing the nonce field, it will also echo the
    1916  * referer field.
    1917  *
    19181953 * The $action and $name are optional, but if you want to have better security,
    19191954 * it is strongly suggested to set those two parameters. It is easier to just
     
    19391974    $name = esc_attr( $name );
    19401975    $nonce_field = '<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />';
     1976
     1977    if ( $referer )
     1978        $nonce_field .= wp_referer_field( false );
     1979
    19411980    if ( $echo )
    19421981        echo $nonce_field;
    1943 
    1944     if ( $referer )
    1945         wp_referer_field( $echo );
    19461982
    19471983    return $nonce_field;
     
    21092145
    21102146    return rtrim($base, '/') . '/' . ltrim($path, '/');
     2147}
     2148
     2149/**
     2150 * Determines a writable directory for temporary files.
     2151 * Function's preference is to WP_CONTENT_DIR followed by the return value of <code>sys_get_temp_dir()</code>, before finally defaulting to /tmp/
     2152 *
     2153 * In the event that this function does not find a writable location, It may be overridden by the <code>WP_TEMP_DIR</code> constant in your <code>wp-config.php</code> file.
     2154 *
     2155 * @since 2.5.0
     2156 *
     2157 * @return string Writable temporary directory
     2158 */
     2159function get_temp_dir() {
     2160    static $temp;
     2161    if ( defined('WP_TEMP_DIR') )
     2162        return trailingslashit(WP_TEMP_DIR);
     2163
     2164    if ( $temp )
     2165        return trailingslashit($temp);
     2166
     2167    $temp = WP_CONTENT_DIR . '/';
     2168    if ( is_dir($temp) && @is_writable($temp) )
     2169        return $temp;
     2170
     2171    if  ( function_exists('sys_get_temp_dir') ) {
     2172        $temp = sys_get_temp_dir();
     2173        if ( @is_writable($temp) )
     2174            return trailingslashit($temp);
     2175    }
     2176
     2177    $temp = ini_get('upload_tmp_dir');
     2178    if ( is_dir($temp) && @is_writable($temp) )
     2179        return trailingslashit($temp);
     2180
     2181    $temp = '/tmp/';
     2182    return $temp;
    21112183}
    21122184
     
    24942566        'csv' => 'text/csv',
    24952567        'tsv' => 'text/tab-separated-values',
     2568        'ics' => 'text/calendar',
    24962569        'rtx' => 'text/richtext',
    24972570        'css' => 'text/css',
     
    27842857    die();
    27852858}
     2859
     2860/**
     2861 * Kill WordPress execution and display XML message with error message.
     2862 *
     2863 * This is the handler for wp_die when processing XMLRPC requests.
     2864 *
     2865 * @since 3.2.0
     2866 * @access private
     2867 *
     2868 * @param string $message Error message.
     2869 * @param string $title Error title.
     2870 * @param string|array $args Optional arguements to control behaviour.
     2871 */
     2872function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) {
     2873    global $wp_xmlrpc_server;
     2874    $defaults = array( 'response' => 500 );
     2875
     2876    $r = wp_parse_args($args, $defaults);
     2877
     2878    if ( $wp_xmlrpc_server ) {
     2879        $error = new IXR_Error( $r['response'] , $message);
     2880        $wp_xmlrpc_server->output( $error->getXml() );
     2881    }
     2882    die();
     2883}
     2884
     2885/**
     2886 * Filter to enable special wp_die handler for xmlrpc requests.
     2887 *
     2888 * @since 3.2.0
     2889 * @access private
     2890 */
     2891function _xmlrpc_wp_die_filter() {
     2892    return '_xmlrpc_wp_die_handler';
     2893}
     2894
    27862895
    27872896/**
     
    31023211
    31033212/**
    3104  * Determines if default embed handlers should be loaded.
    3105  *
    3106  * Checks to make sure that the embeds library hasn't already been loaded. If
    3107  * it hasn't, then it will load the embeds library.
    3108  *
    3109  * @since 2.9.0
    3110  */
    3111 function wp_maybe_load_embeds() {
    3112     if ( ! apply_filters('load_default_embeds', true) )
    3113         return;
    3114     require_once( ABSPATH . WPINC . '/default-embeds.php' );
    3115 }
    3116 
    3117 /**
    31183213 * Determines if Widgets library should be loaded.
    31193214 *
     
    32513346    }
    32523347    return false;
    3253 }
    3254 
    3255 /**
    3256  * Secure URL, if available or the given URL.
    3257  *
    3258  * @since 2.5.0
    3259  *
    3260  * @param string $url Complete URL path with transport.
    3261  * @return string Secure or regular URL path.
    3262  */
    3263 function atom_service_url_filter($url)
    3264 {
    3265     if ( url_is_accessable_via_ssl($url) )
    3266         return preg_replace( '/^http:\/\//', 'https://',  $url );
    3267     else
    3268         return $url;
    32693348}
    32703349
     
    35643643
    35653644/**
    3566  * Whether to force SSL used for the Administration Panels.
     3645 * Whether to force SSL used for the Administration Screens.
    35673646 *
    35683647 * @since 2.6.0
     
    39934072 */
    39944073function wp_timezone_override_offset() {
    3995     if ( !wp_timezone_supported() ) {
    3996         return false;
    3997     }
    39984074    if ( !$timezone_string = get_option( 'timezone_string' ) ) {
    39994075        return false;
     
    40064082    }
    40074083    return round( timezone_offset_get( $timezone_object, $datetime_object ) / 3600, 2 );
    4008 }
    4009 
    4010 /**
    4011  * Check for PHP timezone support
    4012  *
    4013  * @since 2.9.0
    4014  *
    4015  * @return bool
    4016  */
    4017 function wp_timezone_supported() {
    4018     $support = false;
    4019     if (
    4020         function_exists( 'date_create' ) &&
    4021         function_exists( 'date_default_timezone_set' ) &&
    4022         function_exists( 'timezone_identifiers_list' ) &&
    4023         function_exists( 'timezone_open' ) &&
    4024         function_exists( 'timezone_offset_get' )
    4025     ) {
    4026         $support = true;
    4027     }
    4028     return apply_filters( 'timezone_support', $support );
    40294084}
    40304085
Note: See TracChangeset for help on using the changeset viewer.