Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r18031 r18130  
    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 );
     
    591601    wp_protect_special_option( $option );
    592602
     603    /*
     604     * FIXME the next two lines of code are not necessary and should be removed.
     605     * @see http://core.trac.wordpress.org/ticket/13480
     606     */
    593607    if ( is_object($value) )
    594         $value = wp_clone($value);
     608        $value = clone $value;
    595609
    596610    $value = sanitize_option( $option, $value );
     
    12921306
    12931307    $headers = wp_remote_retrieve_headers( $response );
    1294     $headers['response'] = $response['response']['code'];
     1308    $headers['response'] = wp_remote_retrieve_response_code( $response );
    12951309
    12961310    // WP_HTTP no longer follows redirects for HEAD requests.
     
    13071321        return $headers;
    13081322
    1309     fwrite( $out_fp,  $response['body']);
     1323    fwrite( $out_fp,  wp_remote_retrieve_body( $response ) );
    13101324    fclose($out_fp);
    13111325    clearstatcache();
     
    13691383function build_query( $data ) {
    13701384    return _http_build_query( $data, null, '&', '', false );
     1385}
     1386
     1387// from php.net (modified by Mark Jaquith to behave like the native PHP5 function)
     1388function _http_build_query($data, $prefix=null, $sep=null, $key='', $urlencode=true) {
     1389    $ret = array();
     1390
     1391    foreach ( (array) $data as $k => $v ) {
     1392        if ( $urlencode)
     1393            $k = urlencode($k);
     1394        if ( is_int($k) && $prefix != null )
     1395            $k = $prefix.$k;
     1396        if ( !empty($key) )
     1397            $k = $key . '%5B' . $k . '%5D';
     1398        if ( $v === NULL )
     1399            continue;
     1400        elseif ( $v === FALSE )
     1401            $v = '0';
     1402
     1403        if ( is_array($v) || is_object($v) )
     1404            array_push($ret,_http_build_query($v, '', $sep, $k, $urlencode));
     1405        elseif ( $urlencode )
     1406            array_push($ret, $k.'='.urlencode($v));
     1407        else
     1408            array_push($ret, $k.'='.$v);
     1409    }
     1410
     1411    if ( NULL === $sep )
     1412        $sep = ini_get('arg_separator.output');
     1413
     1414    return implode($sep, $ret);
    13711415}
    13721416
     
    15131557        return false;
    15141558
    1515     return $response['body'];
     1559    return wp_remote_retrieve_body( $response );
    15161560}
    15171561
     
    19111955 * important to use nonce field in forms.
    19121956 *
    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  *
    19181957 * The $action and $name are optional, but if you want to have better security,
    19191958 * it is strongly suggested to set those two parameters. It is easier to just
     
    19391978    $name = esc_attr( $name );
    19401979    $nonce_field = '<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />';
     1980
     1981    if ( $referer )
     1982        $nonce_field .= wp_referer_field( false );
     1983
    19411984    if ( $echo )
    19421985        echo $nonce_field;
    1943 
    1944     if ( $referer )
    1945         wp_referer_field( $echo );
    19461986
    19471987    return $nonce_field;
     
    21092149
    21102150    return rtrim($base, '/') . '/' . ltrim($path, '/');
     2151}
     2152
     2153/**
     2154 * Determines a writable directory for temporary files.
     2155 * 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/
     2156 *
     2157 * 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.
     2158 *
     2159 * @since 2.5.0
     2160 *
     2161 * @return string Writable temporary directory
     2162 */
     2163function get_temp_dir() {
     2164    static $temp;
     2165    if ( defined('WP_TEMP_DIR') )
     2166        return trailingslashit(WP_TEMP_DIR);
     2167
     2168    if ( $temp )
     2169        return trailingslashit($temp);
     2170
     2171    $temp = WP_CONTENT_DIR . '/';
     2172    if ( is_dir($temp) && @is_writable($temp) )
     2173        return $temp;
     2174
     2175    if  ( function_exists('sys_get_temp_dir') ) {
     2176        $temp = sys_get_temp_dir();
     2177        if ( @is_writable($temp) )
     2178            return trailingslashit($temp);
     2179    }
     2180
     2181    $temp = ini_get('upload_tmp_dir');
     2182    if ( is_dir($temp) && @is_writable($temp) )
     2183        return trailingslashit($temp);
     2184
     2185    $temp = '/tmp/';
     2186    return $temp;
    21112187}
    21122188
     
    24942570        'csv' => 'text/csv',
    24952571        'tsv' => 'text/tab-separated-values',
     2572        'ics' => 'text/calendar',
    24962573        'rtx' => 'text/richtext',
    24972574        'css' => 'text/css',
     
    27842861    die();
    27852862}
     2863
     2864/**
     2865 * Kill WordPress execution and display XML message with error message.
     2866 *
     2867 * This is the handler for wp_die when processing XMLRPC requests.
     2868 *
     2869 * @since 3.2.0
     2870 * @access private
     2871 *
     2872 * @param string $message Error message.
     2873 * @param string $title Error title.
     2874 * @param string|array $args Optional arguements to control behaviour.
     2875 */
     2876function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) {
     2877    global $wp_xmlrpc_server;
     2878    $defaults = array( 'response' => 500 );
     2879
     2880    $r = wp_parse_args($args, $defaults);
     2881
     2882    if ( $wp_xmlrpc_server ) {
     2883        $error = new IXR_Error( $r['response'] , $message);
     2884        $wp_xmlrpc_server->output( $error->getXml() );
     2885    }
     2886    die();
     2887}
     2888
     2889/**
     2890 * Filter to enable special wp_die handler for xmlrpc requests.
     2891 *
     2892 * @since 3.2.0
     2893 * @access private
     2894 */
     2895function _xmlrpc_wp_die_filter() {
     2896    return '_xmlrpc_wp_die_handler';
     2897}
     2898
    27862899
    27872900/**
     
    31023215
    31033216/**
    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 /**
    31183217 * Determines if Widgets library should be loaded.
    31193218 *
     
    32513350    }
    32523351    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;
    32693352}
    32703353
     
    35643647
    35653648/**
    3566  * Whether to force SSL used for the Administration Panels.
     3649 * Whether to force SSL used for the Administration Screens.
    35673650 *
    35683651 * @since 2.6.0
     
    39934076 */
    39944077function wp_timezone_override_offset() {
    3995     if ( !wp_timezone_supported() ) {
    3996         return false;
    3997     }
    39984078    if ( !$timezone_string = get_option( 'timezone_string' ) ) {
    39994079        return false;
     
    40064086    }
    40074087    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 );
    40294088}
    40304089
Note: See TracChangeset for help on using the changeset viewer.