X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/f9001779751f83dc8a10e478bfecb4d8dd5f964c..bf5c68485ef07868ad0a91168ecd0092af7661ae:/wp-includes/functions.php
diff --git a/wp-includes/functions.php b/wp-includes/functions.php
index 65ee33ea..521b0dd0 100644
--- a/wp-includes/functions.php
+++ b/wp-includes/functions.php
@@ -20,7 +20,7 @@
* @param string $dateformatstring Either 'G', 'U', or php date format.
* @param string $mysqlstring Time from mysql DATETIME field.
* @param bool $translate Optional. Default is true. Will switch format to locale.
- * @return string Date formated by $dateformatstring or locale (if available).
+ * @return string Date formatted by $dateformatstring or locale (if available).
*/
function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) {
$m = $mysqlstring;
@@ -84,8 +84,8 @@ function current_time( $type, $gmt = 0 ) {
function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) {
global $wp_locale;
$i = $unixtimestamp;
- // Sanity check for PHP 5.1.0-
- if ( false === $i || intval($i) < 0 ) {
+
+ if ( false === $i ) {
if ( ! $gmt )
$i = current_time( 'timestamp' );
else
@@ -120,7 +120,7 @@ function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) {
}
$timezone_formats = array( 'P', 'I', 'O', 'T', 'Z', 'e' );
$timezone_formats_re = implode( '|', $timezone_formats );
- if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) && wp_timezone_supported() ) {
+ if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) ) {
$timezone_string = get_option( 'timezone_string' );
if ( $timezone_string ) {
$timezone_object = timezone_open( $timezone_string );
@@ -288,9 +288,19 @@ function is_serialized_string( $data ) {
if ( !is_string( $data ) )
return false;
$data = trim( $data );
- if ( preg_match( '/^s:[0-9]+:.*;$/s', $data ) ) // this should fetch all serialized strings
+ $length = strlen( $data );
+ if ( $length < 4 )
+ return false;
+ elseif ( ':' !== $data[1] )
+ return false;
+ elseif ( ';' !== $data[$length-1] )
+ return false;
+ elseif ( $data[0] !== 's' )
+ return false;
+ elseif ( '"' !== $data[$length-2] )
+ return false;
+ else
return true;
- return false;
}
/**
@@ -314,6 +324,7 @@ function is_serialized_string( $data ) {
* the option value.
*
* @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
+ * @param mixed $default Optional. Default value to return if the option does not exist.
* @return mixed Value set for the option.
*/
function get_option( $option, $default = false ) {
@@ -444,7 +455,7 @@ function wp_load_alloptions() {
}
/**
- * Loads and caches certain often requested site options if is_multisite() and a peristent cache is not being used.
+ * Loads and caches certain often requested site options if is_multisite() and a persistent cache is not being used.
*
* @since 3.0.0
* @package WordPress
@@ -509,7 +520,7 @@ function update_option( $option, $newvalue ) {
wp_protect_special_option( $option );
if ( is_object($newvalue) )
- $newvalue = wp_clone($newvalue);
+ $newvalue = clone $newvalue;
$newvalue = sanitize_option( $option, $newvalue );
$oldvalue = get_option( $option );
@@ -559,11 +570,10 @@ function update_option( $option, $newvalue ) {
* it will be serialized before it is inserted into the database. Remember,
* resources can not be serialized or added as an option.
*
- * You can create options without values and then add values later. Does not
- * check whether the option has already been added, but does check that you
+ * You can create options without values and then update the values later.
+ * Existing options will not be updated and checks are performed to ensure that you
* aren't adding a protected WordPress option. Care should be taken to not name
- * options the same as the ones which are protected and to not add options
- * that were already added.
+ * options the same as the ones which are protected.
*
* @package WordPress
* @subpackage Option
@@ -576,7 +586,7 @@ function update_option( $option, $newvalue ) {
* @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped.
* @param mixed $deprecated Optional. Description. Not used anymore.
* @param bool $autoload Optional. Default is enabled. Whether to load the option when WordPress starts up.
- * @return null returns when finished.
+ * @return bool False if option was not added and true if option was added.
*/
function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) {
global $wpdb;
@@ -591,7 +601,7 @@ function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' )
wp_protect_special_option( $option );
if ( is_object($value) )
- $value = wp_clone($value);
+ $value = clone $value;
$value = sanitize_option( $option, $value );
@@ -599,7 +609,7 @@ function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' )
$notoptions = wp_cache_get( 'notoptions', 'options' );
if ( !is_array( $notoptions ) || !isset( $notoptions[$option] ) )
if ( false !== get_option( $option ) )
- return;
+ return false;
$_value = $value;
$value = maybe_serialize( $value );
@@ -676,7 +686,7 @@ function delete_option( $option ) {
}
/**
- * Delete a transient
+ * Delete a transient.
*
* @since 2.8.0
* @package WordPress
@@ -709,7 +719,7 @@ function delete_transient( $transient ) {
}
/**
- * Get the value of a transient
+ * Get the value of a transient.
*
* If the transient does not exist or does not have a value, then the return value
* will be false.
@@ -758,7 +768,7 @@ function get_transient( $transient ) {
}
/**
- * Set/update the value of a transient
+ * Set/update the value of a transient.
*
* You do not need to serialize values. If the value needs to be serialized, then
* it will be serialized before it is set.
@@ -1027,6 +1037,8 @@ function maybe_serialize( $data ) {
if ( is_array( $data ) || is_object( $data ) )
return serialize( $data );
+ // Double serialization is required for backward compatibility.
+ // See http://core.trac.wordpress.org/ticket/12930
if ( is_serialized( $data ) )
return serialize( $data );
@@ -1291,7 +1303,7 @@ function wp_get_http( $url, $file_path = false, $red = 1 ) {
return false;
$headers = wp_remote_retrieve_headers( $response );
- $headers['response'] = $response['response']['code'];
+ $headers['response'] = wp_remote_retrieve_response_code( $response );
// WP_HTTP no longer follows redirects for HEAD requests.
if ( 'HEAD' == $options['method'] && in_array($headers['response'], array(301, 302)) && isset( $headers['location'] ) ) {
@@ -1306,7 +1318,7 @@ function wp_get_http( $url, $file_path = false, $red = 1 ) {
if ( !$out_fp )
return $headers;
- fwrite( $out_fp, $response['body']);
+ fwrite( $out_fp, wp_remote_retrieve_body( $response ) );
fclose($out_fp);
clearstatcache();
@@ -1370,6 +1382,36 @@ function build_query( $data ) {
return _http_build_query( $data, null, '&', '', false );
}
+// from php.net (modified by Mark Jaquith to behave like the native PHP5 function)
+function _http_build_query($data, $prefix=null, $sep=null, $key='', $urlencode=true) {
+ $ret = array();
+
+ foreach ( (array) $data as $k => $v ) {
+ if ( $urlencode)
+ $k = urlencode($k);
+ if ( is_int($k) && $prefix != null )
+ $k = $prefix.$k;
+ if ( !empty($key) )
+ $k = $key . '%5B' . $k . '%5D';
+ if ( $v === NULL )
+ continue;
+ elseif ( $v === FALSE )
+ $v = '0';
+
+ if ( is_array($v) || is_object($v) )
+ array_push($ret,_http_build_query($v, '', $sep, $k, $urlencode));
+ elseif ( $urlencode )
+ array_push($ret, $k.'='.urlencode($v));
+ else
+ array_push($ret, $k.'='.$v);
+ }
+
+ if ( NULL === $sep )
+ $sep = ini_get('arg_separator.output');
+
+ return implode($sep, $ret);
+}
+
/**
* Retrieve a modified URL query string.
*
@@ -1377,8 +1419,9 @@ function build_query( $data ) {
* using this function. You can also retrieve the full URL with query data.
*
* Adding a single key & value or an associative array. Setting a key value to
- * emptystring removes the key. Omitting oldquery_or_uri uses the $_SERVER
- * value.
+ * an empty string removes the key. Omitting oldquery_or_uri uses the $_SERVER
+ * value. Additional values provided are expected to be encoded appropriately
+ * with urlencode() or rawurlencode().
*
* @since 1.5.0
*
@@ -1512,7 +1555,7 @@ function wp_remote_fopen( $uri ) {
if ( is_wp_error( $response ) )
return false;
- return $response['body'];
+ return wp_remote_retrieve_body( $response );
}
/**
@@ -1754,7 +1797,7 @@ function do_feed_rdf() {
}
/**
- * Load the RSS 1.0 Feed Template
+ * Load the RSS 1.0 Feed Template.
*
* @since 2.1.0
*/
@@ -1791,27 +1834,28 @@ function do_feed_atom( $for_comments ) {
}
/**
- * Display the robot.txt file content.
+ * Display the robots.txt file content.
*
* The echo content should be with usage of the permalinks or for creating the
- * robot.txt file.
+ * robots.txt file.
*
* @since 2.1.0
- * @uses do_action() Calls 'do_robotstxt' hook for displaying robot.txt rules.
+ * @uses do_action() Calls 'do_robotstxt' hook for displaying robots.txt rules.
*/
function do_robots() {
header( 'Content-Type: text/plain; charset=utf-8' );
do_action( 'do_robotstxt' );
- $output = '';
+ $output = "User-agent: *\n";
$public = get_option( 'blog_public' );
- if ( '0' == $public ) {
- $output .= "User-agent: *\n";
+ if ( '0' == $public ) {
$output .= "Disallow: /\n";
} else {
- $output .= "User-agent: *\n";
- $output .= "Disallow:\n";
+ $site_url = parse_url( site_url() );
+ $path = ( !empty( $site_url['path'] ) ) ? $site_url['path'] : '';
+ $output .= "Disallow: $path/wp-admin/\n";
+ $output .= "Disallow: $path/wp-includes/\n";
}
echo apply_filters('robots_txt', $output, $public);
@@ -1855,32 +1899,35 @@ function is_blog_installed() {
if ( $installed )
return true;
+ // If visiting repair.php, return true and let it take over.
+ if ( defined( 'WP_REPAIRING' ) )
+ return true;
+
$suppress = $wpdb->suppress_errors();
- $tables = $wpdb->get_col('SHOW TABLES');
- $wpdb->suppress_errors( $suppress );
- $wp_tables = $wpdb->tables();
// Loop over the WP tables. If none exist, then scratch install is allowed.
// If one or more exist, suggest table repair since we got here because the options
// table could not be accessed.
+ $wp_tables = $wpdb->tables();
foreach ( $wp_tables as $table ) {
- // If one of the WP tables exist, then we are in an insane state.
- if ( in_array( $table, $tables ) ) {
- // The existence of custom user tables shouldn't suggest an insane state or prevent a clean install.
- if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE == $table )
- continue;
- if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE == $table )
- continue;
+ // The existence of custom user tables shouldn't suggest an insane state or prevent a clean install.
+ if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE == $table )
+ continue;
+ if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE == $table )
+ continue;
- // If visiting repair.php, return true and let it take over.
- if ( defined('WP_REPAIRING') )
- return true;
- // Die with a DB error.
- $wpdb->error = sprintf( /*WP_I18N_NO_TABLES*/'One or more database tables are unavailable. The database may need to be repaired.'/*/WP_I18N_NO_TABLES*/, 'maint/repair.php?referrer=is_blog_installed' );
- dead_db();
- }
+ if ( ! $wpdb->get_results( "DESCRIBE $table;" ) )
+ continue;
+
+ // One or more tables exist. We are insane.
+
+ // Die with a DB error.
+ $wpdb->error = sprintf( /*WP_I18N_NO_TABLES*/'One or more database tables are unavailable. The database may need to be repaired.'/*/WP_I18N_NO_TABLES*/, 'maint/repair.php?referrer=is_blog_installed' );
+ dead_db();
}
+ $wpdb->suppress_errors( $suppress );
+
wp_cache_set( 'is_blog_installed', false );
return false;
@@ -1910,11 +1957,6 @@ function wp_nonce_url( $actionurl, $action = -1 ) {
* offer absolute protection, but should protect against most cases. It is very
* important to use nonce field in forms.
*
- * If you set $echo to true and set $referer to true, then you will need to
- * retrieve the {@link wp_referer_field() wp referer field}. If you have the
- * $referer set to true and are echoing the nonce field, it will also echo the
- * referer field.
- *
* The $action and $name are optional, but if you want to have better security,
* it is strongly suggested to set those two parameters. It is easier to just
* call the function without any parameters, because validation of the nonce
@@ -1938,11 +1980,12 @@ function wp_nonce_url( $actionurl, $action = -1 ) {
function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $echo = true ) {
$name = esc_attr( $name );
$nonce_field = '';
- if ( $echo )
- echo $nonce_field;
if ( $referer )
- wp_referer_field( $echo );
+ $nonce_field .= wp_referer_field( false );
+
+ if ( $echo )
+ echo $nonce_field;
return $nonce_field;
}
@@ -1994,7 +2037,8 @@ function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) {
}
/**
- * Retrieve referer from '_wp_http_referer', HTTP referer, or current page respectively.
+ * Retrieve referer from '_wp_http_referer' or HTTP referer. If it's the same
+ * as the current request URL, will return false.
*
* @package WordPress
* @subpackage Security
@@ -2003,13 +2047,13 @@ function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) {
* @return string|bool False on failure. Referer URL on success.
*/
function wp_get_referer() {
- $ref = '';
+ $ref = false;
if ( ! empty( $_REQUEST['_wp_http_referer'] ) )
$ref = $_REQUEST['_wp_http_referer'];
else if ( ! empty( $_SERVER['HTTP_REFERER'] ) )
$ref = $_SERVER['HTTP_REFERER'];
- if ( $ref !== $_SERVER['REQUEST_URI'] )
+ if ( $ref && $ref !== $_SERVER['REQUEST_URI'] )
return $ref;
return false;
}
@@ -2089,7 +2133,7 @@ function path_is_absolute( $path ) {
return true;
// a path starting with / or \ is absolute; anything else is relative
- return (bool) preg_match('#^[/\\\\]#', $path);
+ return ( $path[0] == '/' || $path[0] == '\\' );
}
/**
@@ -2110,6 +2154,42 @@ function path_join( $base, $path ) {
return rtrim($base, '/') . '/' . ltrim($path, '/');
}
+/**
+ * Determines a writable directory for temporary files.
+ * Function's preference is to WP_CONTENT_DIR followed by the return value of sys_get_temp_dir()
, before finally defaulting to /tmp/
+ *
+ * In the event that this function does not find a writable location, It may be overridden by the WP_TEMP_DIR
constant in your wp-config.php
file.
+ *
+ * @since 2.5.0
+ *
+ * @return string Writable temporary directory
+ */
+function get_temp_dir() {
+ static $temp;
+ if ( defined('WP_TEMP_DIR') )
+ return trailingslashit(WP_TEMP_DIR);
+
+ if ( $temp )
+ return trailingslashit($temp);
+
+ $temp = WP_CONTENT_DIR . '/';
+ if ( is_dir($temp) && @is_writable($temp) )
+ return $temp;
+
+ if ( function_exists('sys_get_temp_dir') ) {
+ $temp = sys_get_temp_dir();
+ if ( @is_writable($temp) )
+ return trailingslashit($temp);
+ }
+
+ $temp = ini_get('upload_tmp_dir');
+ if ( is_dir($temp) && @is_writable($temp) )
+ return trailingslashit($temp);
+
+ $temp = '/tmp/';
+ return $temp;
+}
+
/**
* Get an array containing the current upload directory's path and url.
*
@@ -2360,7 +2440,7 @@ function wp_ext2type( $ext ) {
'spreadsheet' => array( 'numbers', 'ods', 'xls', 'xlsx', 'xlsb', 'xlsm' ),
'interactive' => array( 'key', 'ppt', 'pptx', 'pptm', 'odp', 'swf' ),
'text' => array( 'asc', 'csv', 'tsv', 'txt' ),
- 'archive' => array( 'bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip' ),
+ 'archive' => array( 'bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip', '7z' ),
'code' => array( 'css', 'htm', 'html', 'php', 'js' ),
));
foreach ( $ext2type as $type => $exts )
@@ -2493,6 +2573,7 @@ function get_allowed_mime_types() {
'txt|asc|c|cc|h' => 'text/plain',
'csv' => 'text/csv',
'tsv' => 'text/tab-separated-values',
+ 'ics' => 'text/calendar',
'rtx' => 'text/richtext',
'css' => 'text/css',
'htm|html' => 'text/html',
@@ -2525,6 +2606,8 @@ function get_allowed_mime_types() {
'tar' => 'application/x-tar',
'zip' => 'application/zip',
'gz|gzip' => 'application/x-gzip',
+ 'rar' => 'application/rar',
+ '7z' => 'application/x-7z-compressed',
'exe' => 'application/x-msdownload',
// openoffice formats
'odt' => 'application/vnd.oasis.opendocument.text',
@@ -2671,13 +2754,13 @@ function wp_nonce_ays( $action ) {
* HTML will be displayed to the user. It is recommended to use this function
* only, when the execution should not continue any further. It is not
* recommended to call this function very often and try to handle as many errors
- * as possible siliently.
+ * as possible silently.
*
* @since 2.0.4
*
* @param string $message Error message.
* @param string $title Error title.
- * @param string|array $args Optional arguements to control behaviour.
+ * @param string|array $args Optional arguments to control behavior.
*/
function wp_die( $message, $title = '', $args = array() ) {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
@@ -2703,7 +2786,7 @@ function wp_die( $message, $title = '', $args = array() ) {
*
* @param string $message Error message.
* @param string $title Error title.
- * @param string|array $args Optional arguements to control behaviour.
+ * @param string|array $args Optional arguments to control behavior.
*/
function _default_wp_die_handler( $message, $title = '', $args = array() ) {
$defaults = array( 'response' => 500 );
@@ -2735,48 +2818,114 @@ function _default_wp_die_handler( $message, $title = '', $args = array() ) {
if ( isset( $r['back_link'] ) && $r['back_link'] ) {
$back_text = $have_gettext? __('« Back') : '« Back';
- $message .= "\n