~canonical-sysadmins/wordpress/3.9.x

« back to all changes in this revision

Viewing changes to wp-includes/functions.php

  • Committer: Paul Collins
  • Date: 2011-07-13 02:31:10 UTC
  • Revision ID: paul.collins@canonical.com-20110713023110-rvp7cjj31rsaomkr
import Wordpress 3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) {
85
85
        global $wp_locale;
86
86
        $i = $unixtimestamp;
87
 
        // Sanity check for PHP 5.1.0-
88
 
        if ( false === $i || intval($i) < 0 ) {
 
87
 
 
88
        if ( false === $i ) {
89
89
                if ( ! $gmt )
90
90
                        $i = current_time( 'timestamp' );
91
91
                else
120
120
        }
121
121
        $timezone_formats = array( 'P', 'I', 'O', 'T', 'Z', 'e' );
122
122
        $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 ) ) {
124
124
                $timezone_string = get_option( 'timezone_string' );
125
125
                if ( $timezone_string ) {
126
126
                        $timezone_object = timezone_open( $timezone_string );
288
288
        if ( !is_string( $data ) )
289
289
                return false;
290
290
        $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
292
303
                return true;
293
 
        return false;
294
304
}
295
305
 
296
306
/**
509
519
        wp_protect_special_option( $option );
510
520
 
511
521
        if ( is_object($newvalue) )
512
 
                $newvalue = wp_clone($newvalue);
 
522
                $newvalue = clone $newvalue;
513
523
 
514
524
        $newvalue = sanitize_option( $option, $newvalue );
515
525
        $oldvalue = get_option( $option );
591
601
        wp_protect_special_option( $option );
592
602
 
593
603
        if ( is_object($value) )
594
 
                $value = wp_clone($value);
 
604
                $value = clone $value;
595
605
 
596
606
        $value = sanitize_option( $option, $value );
597
607
 
1291
1301
                return false;
1292
1302
 
1293
1303
        $headers = wp_remote_retrieve_headers( $response );
1294
 
        $headers['response'] = $response['response']['code'];
 
1304
        $headers['response'] = wp_remote_retrieve_response_code( $response );
1295
1305
 
1296
1306
        // WP_HTTP no longer follows redirects for HEAD requests.
1297
1307
        if ( 'HEAD' == $options['method'] && in_array($headers['response'], array(301, 302)) && isset( $headers['location'] ) ) {
1306
1316
        if ( !$out_fp )
1307
1317
                return $headers;
1308
1318
 
1309
 
        fwrite( $out_fp,  $response['body']);
 
1319
        fwrite( $out_fp,  wp_remote_retrieve_body( $response ) );
1310
1320
        fclose($out_fp);
1311
1321
        clearstatcache();
1312
1322
 
1370
1380
        return _http_build_query( $data, null, '&', '', false );
1371
1381
}
1372
1382
 
 
1383
// from php.net (modified by Mark Jaquith to behave like the native PHP5 function)
 
1384
function _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);
 
1411
}
 
1412
 
1373
1413
/**
1374
1414
 * Retrieve a modified URL query string.
1375
1415
 *
1512
1552
        if ( is_wp_error( $response ) )
1513
1553
                return false;
1514
1554
 
1515
 
        return $response['body'];
 
1555
        return wp_remote_retrieve_body( $response );
1516
1556
}
1517
1557
 
1518
1558
/**
1910
1950
 * offer absolute protection, but should protect against most cases. It is very
1911
1951
 * important to use nonce field in forms.
1912
1952
 *
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
 
 *
1918
1953
 * The $action and $name are optional, but if you want to have better security,
1919
1954
 * it is strongly suggested to set those two parameters. It is easier to just
1920
1955
 * call the function without any parameters, because validation of the nonce
1938
1973
function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $echo = true ) {
1939
1974
        $name = esc_attr( $name );
1940
1975
        $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
 
1941
1980
        if ( $echo )
1942
1981
                echo $nonce_field;
1943
1982
 
1944
 
        if ( $referer )
1945
 
                wp_referer_field( $echo );
1946
 
 
1947
1983
        return $nonce_field;
1948
1984
}
1949
1985
 
2111
2147
}
2112
2148
 
2113
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
 */
 
2159
function 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;
 
2183
}
 
2184
 
 
2185
/**
2114
2186
 * Get an array containing the current upload directory's path and url.
2115
2187
 *
2116
2188
 * Checks the 'upload_path' option, which should be from the web root folder,
2493
2565
                'txt|asc|c|cc|h' => 'text/plain',
2494
2566
                'csv' => 'text/csv',
2495
2567
                'tsv' => 'text/tab-separated-values',
 
2568
                'ics' => 'text/calendar',
2496
2569
                'rtx' => 'text/richtext',
2497
2570
                'css' => 'text/css',
2498
2571
                'htm|html' => 'text/html',
2785
2858
}
2786
2859
 
2787
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
 */
 
2872
function _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
 */
 
2891
function _xmlrpc_wp_die_filter() {
 
2892
        return '_xmlrpc_wp_die_handler';
 
2893
}
 
2894
 
 
2895
 
 
2896
/**
2788
2897
 * Retrieve the WordPress home page URL.
2789
2898
 *
2790
2899
 * If the constant named 'WP_HOME' exists, then it willl be used and returned by
3101
3210
}
3102
3211
 
3103
3212
/**
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
 
/**
3118
3213
 * Determines if Widgets library should be loaded.
3119
3214
 *
3120
3215
 * Checks to make sure that the widgets library hasn't already been loaded. If
3253
3348
}
3254
3349
 
3255
3350
/**
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;
3269
 
}
3270
 
 
3271
 
/**
3272
3351
 * Marks a function as deprecated and informs when it has been used.
3273
3352
 *
3274
3353
 * There is a hook deprecated_function_run that will be called that can be used
3563
3642
}
3564
3643
 
3565
3644
/**
3566
 
 * Whether to force SSL used for the Administration Panels.
 
3645
 * Whether to force SSL used for the Administration Screens.
3567
3646
 *
3568
3647
 * @since 2.6.0
3569
3648
 *
3992
4071
 * @return float|bool
3993
4072
 */
3994
4073
function wp_timezone_override_offset() {
3995
 
        if ( !wp_timezone_supported() ) {
3996
 
                return false;
3997
 
        }
3998
4074
        if ( !$timezone_string = get_option( 'timezone_string' ) ) {
3999
4075
                return false;
4000
4076
        }
4008
4084
}
4009
4085
 
4010
4086
/**
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 );
4029
 
}
4030
 
 
4031
 
/**
4032
4087
 * {@internal Missing Short Description}}
4033
4088
 *
4034
4089
 * @since 2.9.0