Code cleanup and standardization for functions.php

git-svn-id: http://svn.automattic.com/wordpress/trunk@6223 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
markjaquith 2007-10-11 05:46:57 +00:00
parent c23352bedf
commit a30ed0ded5
1 changed files with 549 additions and 517 deletions

View File

@ -3,9 +3,8 @@
function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) { function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) {
global $wp_locale; global $wp_locale;
$m = $mysqlstring; $m = $mysqlstring;
if ( empty($m) ) { if ( empty( $m ) )
return false; return false;
}
$i = mktime( $i = mktime(
(int) substr( $m, 11, 2 ), (int) substr( $m, 14, 2 ), (int) substr( $m, 17, 2 ), (int) substr( $m, 11, 2 ), (int) substr( $m, 14, 2 ), (int) substr( $m, 17, 2 ),
(int) substr( $m, 5, 2 ), (int) substr( $m, 8, 2 ), (int) substr( $m, 0, 4 ) (int) substr( $m, 5, 2 ), (int) substr( $m, 8, 2 ), (int) substr( $m, 0, 4 )
@ -35,28 +34,28 @@ function mysql2date($dateformatstring, $mysqlstring, $translate = true) {
$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 ); $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
} }
$j = @date( $dateformatstring, $i ); $j = @date( $dateformatstring, $i );
if ( !$j ) {
// for debug purposes /*
// echo $i." ".$mysqlstring; if ( !$j ) // for debug purposes
} echo $i." ".$mysqlstring;
*/
return $j; return $j;
} }
function current_time( $type, $gmt = 0 ) { function current_time( $type, $gmt = 0 ) {
switch ( $type ) { switch ( $type ) {
case 'mysql': case 'mysql':
if ( $gmt ) $d = gmdate('Y-m-d H:i:s'); return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) );
else $d = gmdate('Y-m-d H:i:s', (time() + (get_option('gmt_offset') * 3600)));
return $d;
break; break;
case 'timestamp': case 'timestamp':
if ( $gmt ) $d = time(); return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * 3600 );
else $d = time() + (get_option('gmt_offset') * 3600);
return $d;
break; break;
} }
} }
function date_i18n( $dateformatstring, $unixtimestamp ) { function date_i18n( $dateformatstring, $unixtimestamp ) {
global $wp_locale; global $wp_locale;
$i = $unixtimestamp; $i = $unixtimestamp;
@ -81,23 +80,26 @@ function date_i18n($dateformatstring, $unixtimestamp) {
return $j; return $j;
} }
function number_format_i18n( $number, $decimals = null ) { function number_format_i18n( $number, $decimals = null ) {
global $wp_locale; global $wp_locale;
// let the user override the precision only // let the user override the precision only
$decimals = is_null($decimals)? $wp_locale->number_format['decimals'] : intval($decimals); $decimals = ( is_null( $decimals ) ) ? $wp_locale->number_format['decimals'] : intval( $decimals );
return number_format( $number, $decimals, $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] ); return number_format( $number, $decimals, $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] );
} }
function size_format( $bytes, $decimals = null ) { function size_format( $bytes, $decimals = null ) {
// technically the correct unit names for powers of 1024 are KiB, MiB etc // technically the correct unit names for powers of 1024 are KiB, MiB etc
// see http://en.wikipedia.org/wiki/Byte // see http://en.wikipedia.org/wiki/Byte
$quant = array( $quant = array(
'TB' => pow(1024, 4), // ========================= Origin ====
'GB' => pow(1024, 3), 'TB' => 1099511627776, // pow( 1024, 4)
'MB' => pow(1024, 2), 'GB' => 1073741824, // pow( 1024, 3)
'kB' => pow(1024, 1), 'MB' => 1048576, // pow( 1024, 2)
'B' => pow(1024, 0), 'kB' => 1024, // pow( 1024, 1)
'B ' => 1, // pow( 1024, 0)
); );
foreach ( $quant as $unit => $mag ) foreach ( $quant as $unit => $mag )
@ -105,6 +107,7 @@ function size_format($bytes, $decimals = null) {
return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit; return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit;
} }
function get_weekstartend( $mysqlstring, $start_of_week ) { function get_weekstartend( $mysqlstring, $start_of_week ) {
$my = substr( $mysqlstring, 0, 4 ); $my = substr( $mysqlstring, 0, 4 );
$mm = substr( $mysqlstring, 8, 2 ); $mm = substr( $mysqlstring, 8, 2 );
@ -125,11 +128,11 @@ function get_weekstartend($mysqlstring, $start_of_week) {
$i = 0; $i = 0;
} }
$week['start'] = $day + 86400 - $i; $week['start'] = $day + 86400 - $i;
// $week['end'] = $day - $i + 691199;
$week['end'] = $week['start'] + 604799; $week['end'] = $week['start'] + 604799;
return $week; return $week;
} }
function maybe_unserialize( $original ) { function maybe_unserialize( $original ) {
if ( is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in if ( is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in
if ( false !== $gm = @unserialize( $original ) ) if ( false !== $gm = @unserialize( $original ) )
@ -137,6 +140,7 @@ function maybe_unserialize($original) {
return $original; return $original;
} }
function is_serialized( $data ) { function is_serialized( $data ) {
// if it isn't a string, it isn't serialized // if it isn't a string, it isn't serialized
if ( !is_string( $data ) ) if ( !is_string( $data ) )
@ -146,7 +150,7 @@ function is_serialized($data) {
return true; return true;
if ( !preg_match( '/^([adObis]):/', $data, $badions ) ) if ( !preg_match( '/^([adObis]):/', $data, $badions ) )
return false; return false;
switch ( $badions[1] ) : switch ( $badions[1] ) {
case 'a' : case 'a' :
case 'O' : case 'O' :
case 's' : case 's' :
@ -159,10 +163,11 @@ function is_serialized($data) {
if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) ) if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) )
return true; return true;
break; break;
endswitch; }
return false; return false;
} }
function is_serialized_string( $data ) { function is_serialized_string( $data ) {
// if it isn't a string, it isn't a serialized string // if it isn't a string, it isn't a serialized string
if ( !is_string( $data ) ) if ( !is_string( $data ) )
@ -173,6 +178,7 @@ function is_serialized_string($data) {
return false; return false;
} }
/* Options functions */ /* Options functions */
// expects $setting to already be SQL-escaped // expects $setting to already be SQL-escaped
@ -225,6 +231,7 @@ function get_option($setting) {
return apply_filters( 'option_' . $setting, maybe_unserialize( $value ) ); return apply_filters( 'option_' . $setting, maybe_unserialize( $value ) );
} }
function wp_protect_special_option( $option ) { function wp_protect_special_option( $option ) {
$protected = array( 'alloptions', 'notoptions' ); $protected = array( 'alloptions', 'notoptions' );
if ( in_array( $option, $protected ) ) if ( in_array( $option, $protected ) )
@ -238,26 +245,22 @@ function form_option($option) {
function get_alloptions() { function get_alloptions() {
global $wpdb, $wp_queries; global $wpdb, $wp_queries;
$wpdb->hide_errors(); $wpdb->hide_errors();
if ( !$options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'") ) { if ( !$options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) )
$options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" ); $options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
}
$wpdb->show_errors(); $wpdb->show_errors();
foreach ( $options as $option ) { foreach ( $options as $option ) {
// "When trying to design a foolproof system, // "When trying to design a foolproof system,
// never underestimate the ingenuity of the fools :)" -- Dougal // never underestimate the ingenuity of the fools :)" -- Dougal
if ( 'siteurl' == $option->option_name ) if ( in_array( $option->option_name, array( 'siteurl', 'home', 'category_base' ) ) )
$option->option_value = preg_replace('|/+$|', '', $option->option_value); $option->option_value = untrailingslashit( $option->option_value );
if ( 'home' == $option->option_name )
$option->option_value = preg_replace('|/+$|', '', $option->option_value);
if ( 'category_base' == $option->option_name )
$option->option_value = preg_replace('|/+$|', '', $option->option_value);
$value = maybe_unserialize( $option->option_value ); $value = maybe_unserialize( $option->option_value );
$all_options->{$option->option_name} = apply_filters( 'pre_option_' . $option->option_name, $value ); $all_options->{$option->option_name} = apply_filters( 'pre_option_' . $option->option_name, $value );
} }
return apply_filters( 'all_options', $all_options ); return apply_filters( 'all_options', $all_options );
} }
function wp_load_alloptions() { function wp_load_alloptions() {
global $wpdb; global $wpdb;
@ -276,6 +279,7 @@ function wp_load_alloptions() {
return $alloptions; return $alloptions;
} }
// expects $option_name to NOT be SQL-escaped // expects $option_name to NOT be SQL-escaped
function update_option( $option_name, $newvalue ) { function update_option( $option_name, $newvalue ) {
global $wpdb; global $wpdb;
@ -285,14 +289,14 @@ function update_option($option_name, $newvalue) {
$safe_option_name = $wpdb->escape( $option_name ); $safe_option_name = $wpdb->escape( $option_name );
$newvalue = sanitize_option( $option_name, $newvalue ); $newvalue = sanitize_option( $option_name, $newvalue );
// Likely legacy -- can we drop this?
if ( is_string( $newvalue ) ) if ( is_string( $newvalue ) )
$newvalue = trim( $newvalue ); $newvalue = trim( $newvalue );
// If the new and old values are the same, no need to update. // If the new and old values are the same, no need to update.
$oldvalue = get_option( $safe_option_name ); $oldvalue = get_option( $safe_option_name );
if ( $newvalue === $oldvalue ) { if ( $newvalue === $oldvalue )
return false; return false;
}
if ( false === $oldvalue ) { if ( false === $oldvalue ) {
add_option( $option_name, $newvalue ); add_option( $option_name, $newvalue );
@ -324,6 +328,7 @@ function update_option($option_name, $newvalue) {
return false; return false;
} }
// thx Alex Stapleton, http://alex.vort-x.net/blog/ // thx Alex Stapleton, http://alex.vort-x.net/blog/
// expects $name to NOT be SQL-escaped // expects $name to NOT be SQL-escaped
function add_option( $name, $value = '', $deprecated = '', $autoload = 'yes' ) { function add_option( $name, $value = '', $deprecated = '', $autoload = 'yes' ) {
@ -361,6 +366,7 @@ function add_option($name, $value = '', $deprecated = '', $autoload = 'yes') {
return; return;
} }
function delete_option( $name ) { function delete_option( $name ) {
global $wpdb; global $wpdb;
@ -369,7 +375,8 @@ function delete_option($name) {
// Get the ID, if no ID then return // Get the ID, if no ID then return
// expected_slashed ($name) // expected_slashed ($name)
$option = $wpdb->get_row( "SELECT option_id, autoload FROM $wpdb->options WHERE option_name = '$name'" ); $option = $wpdb->get_row( "SELECT option_id, autoload FROM $wpdb->options WHERE option_name = '$name'" );
if ( !$option->option_id ) return false; if ( !$option->option_id )
return false;
// expected_slashed ($name) // expected_slashed ($name)
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$name'" ); $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$name'" );
if ( 'yes' == $option->autoload ) { if ( 'yes' == $option->autoload ) {
@ -384,6 +391,7 @@ function delete_option($name) {
return true; return true;
} }
function maybe_serialize( $data ) { function maybe_serialize( $data ) {
if ( is_string( $data ) ) if ( is_string( $data ) )
$data = trim( $data ); $data = trim( $data );
@ -394,19 +402,13 @@ function maybe_serialize($data) {
return $data; return $data;
} }
function gzip_compression() { function gzip_compression() {
if ( !get_option( 'gzipcompression' ) ) { if ( !get_option( 'gzipcompression' ) || ini_get( 'zlib.output_compression' ) == 'On' || ini_get( 'zlib.output_compression_level' ) > 0 || ini_get( 'output_handler' ) == 'ob_gzhandler' || !extension_loaded( 'zlib' ) )
return false; return false;
}
if ( ( ini_get( 'zlib.output_compression' ) == 'On' || ini_get( 'zlib.output_compression_level' ) > 0 ) || ini_get( 'output_handler' ) == 'ob_gzhandler' ) {
return false;
}
if ( extension_loaded( 'zlib' ) ) {
ob_start( 'ob_gzhandler' ); ob_start( 'ob_gzhandler' );
} }
}
function make_url_footnote( $content ) { function make_url_footnote( $content ) {
preg_match_all( '/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches ); preg_match_all( '/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches );
@ -440,6 +442,7 @@ function xmlrpc_getposttitle($content) {
return $post_title; return $post_title;
} }
function xmlrpc_getpostcategory( $content ) { function xmlrpc_getpostcategory( $content ) {
global $post_default_category; global $post_default_category;
if ( preg_match( '/<category>(.+?)<\/category>/is', $content, $matchcat ) ) { if ( preg_match( '/<category>(.+?)<\/category>/is', $content, $matchcat ) ) {
@ -451,6 +454,7 @@ function xmlrpc_getpostcategory($content) {
return $post_category; return $post_category;
} }
function xmlrpc_removepostdata( $content ) { function xmlrpc_removepostdata( $content ) {
$content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content ); $content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content );
$content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content ); $content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content );
@ -458,9 +462,10 @@ function xmlrpc_removepostdata($content) {
return $content; return $content;
} }
function debug_fopen( $filename, $mode ) { function debug_fopen( $filename, $mode ) {
global $debug; global $debug;
if ( $debug == 1 ) { if ( 1 == $debug ) {
$fp = fopen( $filename, $mode ); $fp = fopen( $filename, $mode );
return $fp; return $fp;
} else { } else {
@ -468,19 +473,19 @@ function debug_fopen($filename, $mode) {
} }
} }
function debug_fwrite( $fp, $string ) { function debug_fwrite( $fp, $string ) {
global $debug; global $debug;
if ( $debug == 1 ) { if ( 1 == $debug )
fwrite( $fp, $string ); fwrite( $fp, $string );
} }
}
function debug_fclose( $fp ) { function debug_fclose( $fp ) {
global $debug; global $debug;
if ( $debug == 1 ) { if ( 1 == $debug )
fclose( $fp ); fclose( $fp );
} }
}
function do_enclose( $content, $post_ID ) { function do_enclose( $content, $post_ID ) {
global $wp_version, $wpdb; global $wp_version, $wpdb;
@ -502,17 +507,17 @@ function do_enclose( $content, $post_ID ) {
debug_fwrite( $log, 'Post contents:' ); debug_fwrite( $log, 'Post contents:' );
debug_fwrite( $log, $content . "\n" ); debug_fwrite( $log, $content . "\n" );
foreach($post_links_temp[0] as $link_test) : foreach ( $post_links_temp[0] as $link_test ) {
if ( !in_array($link_test, $pung) ) : // If we haven't pung it already if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already
$test = parse_url( $link_test ); $test = parse_url( $link_test );
if ( isset( $test['query'] ) ) if ( isset( $test['query'] ) )
$post_links[] = $link_test; $post_links[] = $link_test;
elseif (($test['path'] != '/') && ($test['path'] != '')) elseif ( $test['path'] != '/' && $test['path'] != '' )
$post_links[] = $link_test; $post_links[] = $link_test;
endif; }
endforeach; }
foreach ($post_links as $url) : foreach ( $post_links as $url ) {
if ( $url != '' && !$wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $url . '%' ) ) ) { if ( $url != '' && !$wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $url . '%' ) ) ) {
if ( $headers = wp_get_http_headers( $url) ) { if ( $headers = wp_get_http_headers( $url) ) {
$len = (int) $headers['content-length']; $len = (int) $headers['content-length'];
@ -525,8 +530,9 @@ function do_enclose( $content, $post_ID ) {
} }
} }
} }
endforeach;
} }
}
function wp_get_http_headers( $url, $red = 1 ) { function wp_get_http_headers( $url, $red = 1 ) {
global $wp_version; global $wp_version;
@ -536,7 +542,7 @@ function wp_get_http_headers( $url, $red = 1 ) {
return false; return false;
$parts = parse_url( $url ); $parts = parse_url( $url );
$file = $parts['path'] . ($parts['query'] ? '?'.$parts['query'] : ''); $file = $parts['path'] . ( ( $parts['query'] ) ? '?' . $parts['query'] : '' );
$host = $parts['host']; $host = $parts['host'];
if ( !isset( $parts['port'] ) ) if ( !isset( $parts['port'] ) )
$parts['port'] = 80; $parts['port'] = 80;
@ -569,19 +575,21 @@ function wp_get_http_headers( $url, $red = 1 ) {
return $headers; return $headers;
} }
function is_new_day() { function is_new_day() {
global $day, $previousday; global $day, $previousday;
if ( $day != $previousday ) { if ( $day != $previousday )
return(1); return 1;
} else { else
return(0); return 0;
}
} }
function build_query( $data ) { function build_query( $data ) {
return _http_build_query( $data, NULL, '&', '', false ); return _http_build_query( $data, NULL, '&', '', false );
} }
/* /*
add_query_arg: Returns a modified querystring by adding add_query_arg: Returns a modified querystring by adding
a single key & value or an associative array. a single key & value or an associative array.
@ -657,6 +665,7 @@ function add_query_arg() {
return $ret; return $ret;
} }
/* /*
remove_query_arg: Returns a modified querystring by removing remove_query_arg: Returns a modified querystring by removing
a single key or an array of keys. a single key or an array of keys.
@ -676,6 +685,7 @@ function remove_query_arg($key, $query=FALSE) {
return add_query_arg( $key, FALSE, $query ); return add_query_arg( $key, FALSE, $query );
} }
function add_magic_quotes( $array ) { function add_magic_quotes( $array ) {
global $wpdb; global $wpdb;
@ -724,16 +734,17 @@ function wp_remote_fopen( $uri ) {
} }
} }
function wp( $query_vars = '' ) { function wp( $query_vars = '' ) {
global $wp; global $wp;
$wp->main( $query_vars ); $wp->main( $query_vars );
} }
function get_status_header_desc( $code ) { function get_status_header_desc( $code ) {
global $wp_header_to_desc; global $wp_header_to_desc;
$code = (int) $code; $code = absint( $code );
if ( !isset( $wp_header_to_desc ) ) { if ( !isset( $wp_header_to_desc ) ) {
$wp_header_to_desc = array( $wp_header_to_desc = array(
@ -783,12 +794,12 @@ function get_status_header_desc( $code ) {
); );
} }
if ( isset( $wp_header_to_desc[$code] ) ) { if ( isset( $wp_header_to_desc[$code] ) )
return $wp_header_to_desc[$code]; return $wp_header_to_desc[$code];
} else { else
return ''; return '';
} }
}
function status_header( $header ) { function status_header( $header ) {
$text = get_status_header_desc( $header ); $text = get_status_header_desc( $header );
@ -797,26 +808,28 @@ function status_header( $header ) {
return false; return false;
$protocol = $_SERVER["SERVER_PROTOCOL"]; $protocol = $_SERVER["SERVER_PROTOCOL"];
if ( ('HTTP/1.1' != $protocol) && ('HTTP/1.0' != $protocol) ) if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol )
$protocol = 'HTTP/1.0'; $protocol = 'HTTP/1.0';
$status_header = "$protocol $header $text"; $status_header = "$protocol $header $text";
if ( function_exists( 'apply_filters' ) ) if ( function_exists( 'apply_filters' ) )
$status_header = apply_filters( 'status_header', $status_header, $header, $text, $protocol ); $status_header = apply_filters( 'status_header', $status_header, $header, $text, $protocol );
if ( version_compare( phpversion(), '4.3.0', '>=' ) ) { if ( version_compare( phpversion(), '4.3.0', '>=' ) )
return @header( $status_header, true, $header ); return @header( $status_header, true, $header );
} else { else
return @header( $status_header ); return @header( $status_header );
} }
}
function nocache_headers() { function nocache_headers() {
// why are these @-silenced when other header calls aren't?
@header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' ); @header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
@header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' ); @header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
@header( 'Cache-Control: no-cache, must-revalidate, max-age=0' ); @header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
@header( 'Pragma: no-cache' ); @header( 'Pragma: no-cache' );
} }
function cache_javascript_headers() { function cache_javascript_headers() {
$expiresOffset = 864000; // 10 days $expiresOffset = 864000; // 10 days
header( "Content-Type: text/javascript; charset=" . get_bloginfo( 'charset' ) ); header( "Content-Type: text/javascript; charset=" . get_bloginfo( 'charset' ) );
@ -824,15 +837,18 @@ function cache_javascript_headers() {
header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + $expiresOffset ) . " GMT" ); header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + $expiresOffset ) . " GMT" );
} }
function get_num_queries() { function get_num_queries() {
global $wpdb; global $wpdb;
return $wpdb->num_queries; return $wpdb->num_queries;
} }
function bool_from_yn( $yn ) { function bool_from_yn( $yn ) {
return ( strtolower( $yn ) == 'y' ); return ( strtolower( $yn ) == 'y' );
} }
function do_feed() { function do_feed() {
global $wp_query; global $wp_query;
@ -848,29 +864,31 @@ function do_feed() {
do_action( $hook, $wp_query->is_comment_feed ); do_action( $hook, $wp_query->is_comment_feed );
} }
function do_feed_rdf() { function do_feed_rdf() {
load_template( ABSPATH . WPINC . '/feed-rdf.php' ); load_template( ABSPATH . WPINC . '/feed-rdf.php' );
} }
function do_feed_rss() { function do_feed_rss() {
load_template( ABSPATH . WPINC . '/feed-rss.php' ); load_template( ABSPATH . WPINC . '/feed-rss.php' );
} }
function do_feed_rss2( $for_comments ) { function do_feed_rss2( $for_comments ) {
if ( $for_comments ) { if ( $for_comments )
load_template( ABSPATH . WPINC . '/feed-rss2-comments.php' ); load_template( ABSPATH . WPINC . '/feed-rss2-comments.php' );
} else { else
load_template( ABSPATH . WPINC . '/feed-rss2.php' ); load_template( ABSPATH . WPINC . '/feed-rss2.php' );
} }
}
function do_feed_atom( $for_comments ) { function do_feed_atom( $for_comments ) {
if ($for_comments) { if ($for_comments)
load_template( ABSPATH . WPINC . '/feed-atom-comments.php'); load_template( ABSPATH . WPINC . '/feed-atom-comments.php');
} else { else
load_template( ABSPATH . WPINC . '/feed-atom.php' ); load_template( ABSPATH . WPINC . '/feed-atom.php' );
} }
}
function do_robots() { function do_robots() {
header( 'Content-Type: text/plain; charset=utf-8' ); header( 'Content-Type: text/plain; charset=utf-8' );
@ -886,21 +904,23 @@ function do_robots() {
} }
} }
function is_blog_installed() { function is_blog_installed() {
global $wpdb; global $wpdb;
$wpdb->hide_errors(); $wpdb->hide_errors();
$installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" ); $installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" );
$wpdb->show_errors(); $wpdb->show_errors();
$install_status = !empty( $installed ) ? TRUE : FALSE; return !empty( $installed );
return $install_status;
} }
function wp_nonce_url( $actionurl, $action = -1 ) { function wp_nonce_url( $actionurl, $action = -1 ) {
$actionurl = str_replace( '&amp;', '&', $actionurl ); $actionurl = str_replace( '&amp;', '&', $actionurl );
return wp_specialchars( add_query_arg( '_wpnonce', wp_create_nonce( $action ), $actionurl ) ); return wp_specialchars( add_query_arg( '_wpnonce', wp_create_nonce( $action ), $actionurl ) );
} }
function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true ) { function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true ) {
$name = attribute_escape( $name ); $name = attribute_escape( $name );
echo '<input type="hidden" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />'; echo '<input type="hidden" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />';
@ -908,6 +928,7 @@ function wp_nonce_field($action = -1, $name = "_wpnonce", $referer = true) {
wp_referer_field(); wp_referer_field();
} }
function wp_referer_field() { function wp_referer_field() {
$ref = attribute_escape( $_SERVER['REQUEST_URI'] ); $ref = attribute_escape( $_SERVER['REQUEST_URI'] );
echo '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />'; echo '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />';
@ -917,10 +938,12 @@ function wp_referer_field() {
} }
} }
function wp_original_referer_field() { function wp_original_referer_field() {
echo '<input type="hidden" name="_wp_original_http_referer" value="' . attribute_escape( stripslashes( $_SERVER['REQUEST_URI'] ) ) . '" />'; echo '<input type="hidden" name="_wp_original_http_referer" value="' . attribute_escape( stripslashes( $_SERVER['REQUEST_URI'] ) ) . '" />';
} }
function wp_get_referer() { function wp_get_referer() {
foreach ( array( $_REQUEST['_wp_http_referer'], $_SERVER['HTTP_REFERER'] ) as $ref ) foreach ( array( $_REQUEST['_wp_http_referer'], $_SERVER['HTTP_REFERER'] ) as $ref )
if ( !empty( $ref ) ) if ( !empty( $ref ) )
@ -928,20 +951,18 @@ function wp_get_referer() {
return false; return false;
} }
function wp_get_original_referer() { function wp_get_original_referer() {
if ( !empty( $_REQUEST['_wp_original_http_referer'] ) ) if ( !empty( $_REQUEST['_wp_original_http_referer'] ) )
return $_REQUEST['_wp_original_http_referer']; return $_REQUEST['_wp_original_http_referer'];
return false; return false;
} }
function wp_mkdir_p( $target ) { function wp_mkdir_p( $target ) {
// from php.net/mkdir user contributed notes // from php.net/mkdir user contributed notes
if (file_exists($target)) { if ( file_exists( $target ) )
if (! @ is_dir($target)) return @is_dir( $target );
return false;
else
return true;
}
// Attempting to create the directory may clutter up our display. // Attempting to create the directory may clutter up our display.
if ( @mkdir( $target ) ) { if ( @mkdir( $target ) ) {
@ -949,8 +970,7 @@ function wp_mkdir_p($target) {
$dir_perms = $stat['mode'] & 0007777; // Get the permission bits. $dir_perms = $stat['mode'] & 0007777; // Get the permission bits.
@chmod( $target, $dir_perms ); @chmod( $target, $dir_perms );
return true; return true;
} else { } elseif ( is_dir( dirname( $target ) ) ) {
if ( is_dir(dirname($target)) )
return false; return false;
} }
@ -961,6 +981,7 @@ function wp_mkdir_p($target) {
return false; return false;
} }
// Returns an array containing the current upload directory's path and url, or an error message. // Returns an array containing the current upload directory's path and url, or an error message.
function wp_upload_dir() { function wp_upload_dir() {
$siteurl = get_option( 'siteurl' ); $siteurl = get_option( 'siteurl' );
@ -969,9 +990,8 @@ function wp_upload_dir() {
$dir = ABSPATH . $path; $dir = ABSPATH . $path;
$url = trailingslashit( $siteurl ) . $path; $url = trailingslashit( $siteurl ) . $path;
if ( $dir == ABSPATH ) { //the option was empty if ( $dir == ABSPATH ) // the option was empty
$dir = ABSPATH . 'wp-content/uploads'; $dir = ABSPATH . 'wp-content/uploads';
}
if ( defined('UPLOADS') ) { if ( defined('UPLOADS') ) {
$dir = ABSPATH . UPLOADS; $dir = ABSPATH . UPLOADS;
@ -1049,9 +1069,10 @@ function wp_upload_bits($name, $type, $bits) {
return array( 'file' => $new_file, 'url' => $url, 'error' => false ); return array( 'file' => $new_file, 'url' => $url, 'error' => false );
} }
function wp_check_filetype( $filename, $mimes = null ) { function wp_check_filetype( $filename, $mimes = null ) {
// Accepted MIME types are set here as PCRE unless provided. // Accepted MIME types are set here as PCRE unless provided.
$mimes = is_array($mimes) ? $mimes : apply_filters('upload_mimes', array ( $mimes = ( is_array( $mimes ) ) ? $mimes : apply_filters( 'upload_mimes', array(
'jpg|jpeg|jpe' => 'image/jpeg', 'jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif', 'gif' => 'image/gif',
'png' => 'image/png', 'png' => 'image/png',
@ -1095,8 +1116,8 @@ function wp_check_filetype($filename, $mimes = null) {
'odc' => 'application/vnd.oasis.opendocument.chart', 'odc' => 'application/vnd.oasis.opendocument.chart',
'odb' => 'application/vnd.oasis.opendocument.database', 'odb' => 'application/vnd.oasis.opendocument.database',
'odf' => 'application/vnd.oasis.opendocument.formula', 'odf' => 'application/vnd.oasis.opendocument.formula',
)
)); );
$type = false; $type = false;
$ext = false; $ext = false;
@ -1177,6 +1198,7 @@ function wp_explain_nonce($action) {
return apply_filters( 'explain_nonce_' . $verb . '-' . $noun, __( 'Are you sure you want to do this?' ), $matches[4] ); return apply_filters( 'explain_nonce_' . $verb . '-' . $noun, __( 'Are you sure you want to do this?' ), $matches[4] );
} }
function wp_nonce_ays( $action ) { function wp_nonce_ays( $action ) {
global $pagenow, $menu, $submenu, $parent_file, $submenu_file; global $pagenow, $menu, $submenu, $parent_file, $submenu_file;
@ -1205,6 +1227,7 @@ function wp_nonce_ays($action) {
wp_die( $html, $title ); wp_die( $html, $title );
} }
function wp_die( $message, $title = '' ) { function wp_die( $message, $title = '' ) {
global $wp_locale; global $wp_locale;
@ -1276,18 +1299,21 @@ if ( ( $wp_locale ) && ('rtl' == $wp_locale->text_direction) ) : ?>
die(); die();
} }
function _config_wp_home( $url = '' ) { function _config_wp_home( $url = '' ) {
if ( defined( 'WP_HOME' ) ) if ( defined( 'WP_HOME' ) )
return WP_HOME; return WP_HOME;
else return $url; return $url;
} }
function _config_wp_siteurl( $url = '' ) { function _config_wp_siteurl( $url = '' ) {
if ( defined( 'WP_SITEURL' ) ) if ( defined( 'WP_SITEURL' ) )
return WP_SITEURL; return WP_SITEURL;
else return $url; return $url;
} }
function _mce_set_direction() { function _mce_set_direction() {
global $wp_locale; global $wp_locale;
@ -1297,6 +1323,7 @@ function _mce_set_direction() {
} }
} }
function _mce_load_rtl_plugin( $input ) { function _mce_load_rtl_plugin( $input ) {
global $wp_locale; global $wp_locale;
@ -1306,6 +1333,7 @@ function _mce_load_rtl_plugin($input) {
return $input; return $input;
} }
function _mce_add_direction_buttons( $input ) { function _mce_add_direction_buttons( $input ) {
global $wp_locale; global $wp_locale;
@ -1317,6 +1345,7 @@ function _mce_add_direction_buttons($input) {
return $input; return $input;
} }
function smilies_init() { function smilies_init() {
global $wpsmiliestrans, $wp_smiliessearch, $wp_smiliesreplace; global $wpsmiliestrans, $wp_smiliessearch, $wp_smiliesreplace;
@ -1376,11 +1405,12 @@ function smilies_init() {
$siteurl = get_option( 'siteurl' ); $siteurl = get_option( 'siteurl' );
foreach ( (array) $wpsmiliestrans as $smiley => $img ) { foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
$wp_smiliessearch[] = '/(\s|^)' . preg_quote( $smiley, '/' ) . '(\s|$)/'; $wp_smiliessearch[] = '/(\s|^)' . preg_quote( $smiley, '/' ) . '(\s|$)/';
$smiley_masked = htmlspecialchars(trim($smiley), ENT_QUOTES); $smiley_masked = attribute_escape( trim( $smiley ) );
$wp_smiliesreplace[] = " <img src='$siteurl/wp-includes/images/smilies/$img' alt='$smiley_masked' class='wp-smiley' /> "; $wp_smiliesreplace[] = " <img src='$siteurl/wp-includes/images/smilies/$img' alt='$smiley_masked' class='wp-smiley' /> ";
} }
} }
function wp_parse_args( $args, $defaults = '' ) { function wp_parse_args( $args, $defaults = '' ) {
if ( is_object( $args ) ) if ( is_object( $args ) )
$r = get_object_vars( $args ); $r = get_object_vars( $args );
@ -1391,30 +1421,32 @@ function wp_parse_args( $args, $defaults = '' ) {
if ( is_array( $defaults ) ) if ( is_array( $defaults ) )
return array_merge( $defaults, $r ); return array_merge( $defaults, $r );
else
return $r; return $r;
} }
function wp_maybe_load_widgets() { function wp_maybe_load_widgets() {
if ( !function_exists( 'dynamic_sidebar' ) ) { if ( !function_exists( 'dynamic_sidebar' ) ) {
require_once ABSPATH . WPINC . '/widgets.php'; require_once( ABSPATH . WPINC . '/widgets.php' );
add_action( '_admin_menu', 'wp_widgets_add_menu' ); add_action( '_admin_menu', 'wp_widgets_add_menu' );
} }
} }
function wp_widgets_add_menu() { function wp_widgets_add_menu() {
global $submenu; global $submenu;
$submenu['themes.php'][7] = array( __( 'Widgets' ), 'switch_themes', 'widgets.php' ); $submenu['themes.php'][7] = array( __( 'Widgets' ), 'switch_themes', 'widgets.php' );
ksort( $submenu['themes.php'], SORT_NUMERIC ); ksort( $submenu['themes.php'], SORT_NUMERIC );
} }
// For PHP 5.2, make sure all output buffers are flushed // For PHP 5.2, make sure all output buffers are flushed
// before our singletons our destroyed. // before our singletons our destroyed.
function wp_ob_end_flush_all() function wp_ob_end_flush_all() {
{
while ( @ob_end_flush() ); while ( @ob_end_flush() );
} }
/* /*
* require_wp_db() - require_once the correct database class file. * require_wp_db() - require_once the correct database class file.
* *
@ -1423,8 +1455,7 @@ function wp_ob_end_flush_all()
* *
* @global $wpdb * @global $wpdb
*/ */
function require_wp_db() function require_wp_db() {
{
global $wpdb; global $wpdb;
if ( file_exists( ABSPATH . 'wp-content/db.php' ) ) if ( file_exists( ABSPATH . 'wp-content/db.php' ) )
require_once( ABSPATH . 'wp-content/db.php' ); require_once( ABSPATH . 'wp-content/db.php' );
@ -1432,6 +1463,7 @@ function require_wp_db()
require_once( ABSPATH . WPINC . '/wp-db.php' ); require_once( ABSPATH . WPINC . '/wp-db.php' );
} }
/** /**
* Converts input to an absolute integer * Converts input to an absolute integer
* @param mixed $maybeint data you wish to have convered to an absolute integer * @param mixed $maybeint data you wish to have convered to an absolute integer