Code cleanups from markjaquith. fixes #1743

git-svn-id: http://svn.automattic.com/wordpress/trunk@2941 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-10-10 09:25:38 +00:00
parent ef2049566f
commit e1140b014d
1 changed files with 299 additions and 310 deletions

View File

@ -2,7 +2,7 @@
require_once(dirname(__FILE__).'/functions-compat.php');
if (!function_exists('_')) {
if ( !function_exists('_') ) {
function _($string) {
return $string;
}
@ -10,7 +10,7 @@ if (!function_exists('_')) {
function get_profile($field, $user = false) {
global $wpdb;
if (!$user)
if ( !$user )
$user = $wpdb->escape($_COOKIE[USER_COOKIE]);
return $wpdb->get_var("SELECT $field FROM $wpdb->users WHERE user_login = '$user'");
}
@ -18,11 +18,11 @@ function get_profile($field, $user = false) {
function mysql2date($dateformatstring, $mysqlstring, $translate = true) {
global $month, $weekday, $month_abbrev, $weekday_abbrev;
$m = $mysqlstring;
if (empty($m)) {
if ( empty($m) ) {
return false;
}
$i = mktime(substr($m,11,2),substr($m,14,2),substr($m,17,2),substr($m,5,2),substr($m,8,2),substr($m,0,4));
if (!empty($month) && !empty($weekday) && $translate) {
if ( !empty($month) && !empty($weekday) && $translate ) {
$datemonth = $month[date('m', $i)];
$datemonth_abbrev = $month_abbrev[$datemonth];
$dateweekday = $weekday[date('w', $i)];
@ -36,7 +36,7 @@ function mysql2date($dateformatstring, $mysqlstring, $translate = true) {
$dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring)-1);
}
$j = @date($dateformatstring, $i);
if (!$j) {
if ( !$j ) {
// for debug purposes
// echo $i." ".$mysqlstring;
}
@ -46,12 +46,12 @@ function mysql2date($dateformatstring, $mysqlstring, $translate = true) {
function current_time($type, $gmt = 0) {
switch ($type) {
case 'mysql':
if ($gmt) $d = gmdate('Y-m-d H:i:s');
if ( $gmt ) $d = gmdate('Y-m-d H:i:s');
else $d = gmdate('Y-m-d H:i:s', (time() + (get_settings('gmt_offset') * 3600)));
return $d;
break;
case 'timestamp':
if ($gmt) $d = time();
if ( $gmt ) $d = time();
else $d = time() + (get_settings('gmt_offset') * 3600);
return $d;
break;
@ -61,7 +61,7 @@ function current_time($type, $gmt = 0) {
function date_i18n($dateformatstring, $unixtimestamp) {
global $month, $weekday, $month_abbrev, $weekday_abbrev;
$i = $unixtimestamp;
if ((!empty($month)) && (!empty($weekday))) {
if ( (!empty($month)) && (!empty($weekday)) ) {
$datemonth = $month[date('m', $i)];
$datemonth_abbrev = $month_abbrev[$datemonth];
$dateweekday = $weekday[date('w', $i)];
@ -85,19 +85,19 @@ function get_weekstartend($mysqlstring, $start_of_week) {
$weekday = date('w',$day);
$i = 86400;
if ($weekday < get_settings('start_of_week'))
if ( $weekday < get_settings('start_of_week') )
$weekday = 7 - (get_settings('start_of_week') - $weekday);
while ($weekday > get_settings('start_of_week')) {
$weekday = date('w',$day);
if ($weekday < get_settings('start_of_week'))
if ( $weekday < get_settings('start_of_week') )
$weekday = 7 - (get_settings('start_of_week') - $weekday);
$day = $day - 86400;
$i = 0;
}
$week['start'] = $day + 86400 - $i;
//$week['end'] = $day - $i + 691199;
// $week['end'] = $day - $i + 691199;
$week['end'] = $week['start'] + 604799;
return $week;
}
@ -144,7 +144,7 @@ function get_lastpostmodified($timezone = 'server') {
break;
}
$lastpostdate = get_lastpostdate($timezone);
if ($lastpostdate > $lastpostmodified) {
if ( $lastpostdate > $lastpostmodified ) {
$lastpostmodified = $lastpostdate;
}
$cache_lastpostmodified[$timezone] = $lastpostmodified;
@ -179,7 +179,7 @@ function url_to_postid($url) {
// First, check to see if there is a 'p=N' or 'page_id=N' to match against
preg_match('#[?&](p|page_id)=(\d+)#', $url, $values);
$id = intval($values[2]);
if ($id) return $id;
if ( $id ) return $id;
// Check to see if we are using rewrite rules
$rewrite = $wp_rewrite->wp_rewrite_rules();
@ -213,8 +213,8 @@ function url_to_postid($url) {
if ( false === strpos($rewrite, 'index.php/') )
$url = str_replace('index.php/', '', $url);
// Chop off http://domain.com
if ( false !== strpos($url, get_settings('home')) ) {
// Chop off http://domain.com
$url = str_replace(get_settings('home'), '', $url);
} else {
// Chop off /path/to/blog
@ -235,11 +235,11 @@ function url_to_postid($url) {
foreach ($rewrite as $match => $query) {
// If the requesting file is the anchor of the match, prepend it
// to the path info.
if ((! empty($url)) && (strpos($match, $url) === 0)) {
if ( (! empty($url)) && (strpos($match, $url) === 0) ) {
$request_match = $url . '/' . $request;
}
if (preg_match("!^$match!", $request_match, $matches)) {
if ( preg_match("!^$match!", $request_match, $matches) ) {
// Got a match.
// Trim the query of everything up to the '?'.
$query = preg_replace("!^.+\?!", '', $query);
@ -253,7 +253,6 @@ function url_to_postid($url) {
return 0;
}
}
return 0;
}
@ -271,7 +270,7 @@ function get_settings($setting) {
if ( empty($cache_nonexistantoptions) )
$cache_nonexistantoptions = array();
if ('home' == $setting && '' == $cache_settings->home)
if ( 'home' == $setting && '' == $cache_settings->home )
return apply_filters('option_' . $setting, $cache_settings->siteurl);
if ( isset($cache_settings->$setting) ) :
@ -289,7 +288,7 @@ function get_settings($setting) {
endif;
@ $kellogs = unserialize($option);
if ($kellogs !== FALSE)
if ( $kellogs !== FALSE )
return apply_filters('option_' . $setting, $kellogs);
else return apply_filters('option_' . $setting, $option);
endif;
@ -316,7 +315,7 @@ function form_option($option) {
function get_alloptions() {
global $wpdb, $wp_queries;
$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");
}
$wpdb->show_errors();
@ -324,11 +323,14 @@ function get_alloptions() {
foreach ($options as $option) {
// "When trying to design a foolproof system,
// never underestimate the ingenuity of the fools :)" -- Dougal
if ('siteurl' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $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);
if ( 'siteurl' == $option->option_name )
$option->option_value = preg_replace('|/+$|', '', $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 = unserialize($option->option_value);
if ($value === FALSE)
if ( $value === FALSE )
$value = $option->option_value;
$all_options->{$option->option_name} = apply_filters('pre_option_' . $option->option_name, $value);
}
@ -378,13 +380,13 @@ function add_option($name, $value = '', $description = '', $autoload = 'yes') {
if ( is_array($value) || is_object($value) )
$value = serialize($value);
if( !$wpdb->get_var("SELECT option_name FROM $wpdb->options WHERE option_name = '$name'") ) {
if ( !$wpdb->get_var("SELECT option_name FROM $wpdb->options WHERE option_name = '$name'") ) {
$name = $wpdb->escape($name);
$value = $wpdb->escape($value);
$description = $wpdb->escape($description);
$wpdb->query("INSERT INTO $wpdb->options (option_name, option_value, option_description, autoload) VALUES ('$name', '$value', '$description', '$autoload')");
if($wpdb->insert_id) {
if ( $wpdb->insert_id ) {
global $cache_settings;
$cache_settings->{$name} = $original;
}
@ -396,7 +398,7 @@ function delete_option($name) {
global $wpdb;
// Get the ID, if no ID then return
$option_id = $wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = '$name'");
if (!$option_id) return false;
if ( !$option_id ) return false;
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name = '$name'");
return true;
}
@ -404,8 +406,8 @@ function delete_option($name) {
function add_post_meta($post_id, $key, $value, $unique = false) {
global $wpdb, $post_meta_cache;
if ($unique) {
if( $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key
if ( $unique ) {
if ( $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key
= '$key' AND post_id = '$post_id'") ) {
return false;
}
@ -415,10 +417,7 @@ function add_post_meta($post_id, $key, $value, $unique = false) {
if ( is_array($value) || is_object($value) )
$value = $wpdb->escape(serialize($value));
$wpdb->query("INSERT INTO $wpdb->postmeta
(post_id,meta_key,meta_value)
VALUES ('$post_id','$key','$value')
");
$wpdb->query("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value) VALUES ('$post_id','$key','$value')");
$post_meta_cache['$post_id'][$key][] = $original;
@ -428,7 +427,7 @@ function add_post_meta($post_id, $key, $value, $unique = false) {
function delete_post_meta($post_id, $key, $value = '') {
global $wpdb, $post_meta_cache;
if (empty($value)) {
if ( empty($value) ) {
$meta_id = $wpdb->get_var("SELECT meta_id FROM $wpdb->postmeta WHERE
post_id = '$post_id' AND meta_key = '$key'");
} else {
@ -436,9 +435,10 @@ post_id = '$post_id' AND meta_key = '$key'");
post_id = '$post_id' AND meta_key = '$key' AND meta_value = '$value'");
}
if (!$meta_id) return false;
if ( !$meta_id )
return false;
if (empty($value)) {
if ( empty($value) ) {
$wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id'
AND meta_key = '$key'");
unset($post_meta_cache['$post_id'][$key]);
@ -459,8 +459,8 @@ AND meta_key = '$key' AND meta_value = '$value'");
function get_post_meta($post_id, $key, $single = false) {
global $wpdb, $post_meta_cache;
if (isset($post_meta_cache[$post_id][$key])) {
if ($single) {
if ( isset($post_meta_cache[$post_id][$key]) ) {
if ( $single ) {
return $post_meta_cache[$post_id][$key][0];
} else {
return $post_meta_cache[$post_id][$key];
@ -470,14 +470,14 @@ function get_post_meta($post_id, $key, $single = false) {
$metalist = $wpdb->get_results("SELECT meta_value FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key'", ARRAY_N);
$values = array();
if ($metalist) {
if ( $metalist ) {
foreach ($metalist as $metarow) {
$values[] = $metarow[0];
}
}
if ($single) {
if (count($values)) {
if ( $single ) {
if ( count($values) ) {
$return = $values[0];
} else {
return '';
@ -487,7 +487,7 @@ function get_post_meta($post_id, $key, $single = false) {
}
@ $kellogs = unserialize($return);
if ($kellogs !== FALSE)
if ( $kellogs !== FALSE )
return $kellogs;
else return $return;
}
@ -503,12 +503,12 @@ function update_post_meta($post_id, $key, $value, $prev_value = '') {
if ( is_array($prev_value) || is_object($prev_value) )
$prev_value = serialize($value);
if(! $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key
if (! $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key
= '$key' AND post_id = '$post_id'") ) {
return false;
}
if (empty($prev_value)) {
if ( empty($prev_value) ) {
$wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE
meta_key = '$key' AND post_id = '$post_id'");
$cache_key = $post_meta_cache['$post_id'][$key];
@ -560,12 +560,12 @@ function &get_post(&$post, $output = OBJECT) {
$_post = & $GLOBALS['post'];
else
$_post = null;
} elseif (is_object($post) ) {
if (! isset($post_cache[$post->ID]))
} elseif ( is_object($post) ) {
if ( !isset($post_cache[$post->ID]) )
$post_cache[$post->ID] = &$post;
$_post = & $post_cache[$post->ID];
} else {
if (isset($post_cache[$post]))
if ( isset($post_cache[$post]) )
$_post = & $post_cache[$post];
else {
$query = "SELECT * FROM $wpdb->posts WHERE ID = '$post'";
@ -595,14 +595,14 @@ function &get_page(&$page, $output = OBJECT) {
$_page = & $GLOBALS['page'];
else
$_page = null;
} elseif (is_object($page) ) {
if (! isset($page_cache[$page->ID]))
} elseif ( is_object($page) ) {
if ( !isset($page_cache[$page->ID]) )
$page_cache[$page->ID] = &$page;
$_page = & $page_cache[$page->ID];
} else {
if ( isset($GLOBALS['page']) && ($page == $GLOBALS['page']->ID) )
$_page = & $GLOBALS['page'];
elseif (isset($page_cache[$page]))
elseif ( isset($page_cache[$page]) )
$_page = & $page_cache[$page];
else {
$query = "SELECT * FROM $wpdb->posts WHERE ID= '$page'";
@ -630,11 +630,11 @@ function &get_category(&$category, $output = OBJECT) {
if ( empty($category) )
return null;
if ( ! isset($cache_categories))
if ( !isset($cache_categories) )
update_category_cache();
if (is_object($category)) {
if ( ! isset($cache_categories[$category->cat_ID]))
if ( is_object($category) ) {
if ( !isset($cache_categories[$category->cat_ID]) )
$cache_categories[$category->cat_ID] = &$category;
$_category = & $cache_categories[$category->cat_ID];
} else {
@ -665,8 +665,8 @@ function &get_comment(&$comment, $output = OBJECT) {
if ( empty($comment) )
return null;
if (is_object($comment)) {
if ( ! isset($comment_cache[$comment->comment_ID]))
if ( is_object($comment) ) {
if ( !isset($comment_cache[$comment->comment_ID]) )
$comment_cache[$comment->comment_ID] = &$comment;
$_comment = & $comment_cache[$comment->comment_ID];
} else {
@ -698,7 +698,7 @@ function gzip_compression() {
if ( strstr($_SERVER['PHP_SELF'], 'wp-admin') ) return false;
if ( !get_settings('gzipcompression') ) return false;
if( extension_loaded('zlib') ) {
if ( extension_loaded('zlib') ) {
ob_start('ob_gzhandler');
}
}
@ -714,7 +714,7 @@ function timer_stop($display = 0, $precision = 3) { //if called like timer_stop(
$mtime = $mtime[1] + $mtime[0];
$timeend = $mtime;
$timetotal = $timeend-$timestart;
if ($display)
if ( $display )
echo number_format($timetotal,$precision);
return $timetotal;
}
@ -739,7 +739,7 @@ function generic_ping($post_id = 0) {
$services = get_settings('ping_sites');
$services = preg_replace("|(\s)+|", '$1', $services); // Kill dupe lines
$services = trim($services);
if ('' != $services) {
if ( '' != $services ) {
$services = explode("\n", $services);
foreach ($services as $service) {
weblog_ping($service);
@ -753,7 +753,7 @@ function generic_ping($post_id = 0) {
function trackback($trackback_url, $title, $excerpt, $ID) {
global $wpdb, $wp_version;
if (empty($trackback_url))
if ( empty($trackback_url) )
return;
$title = urlencode($title);
@ -814,7 +814,7 @@ function make_url_footnote($content) {
function xmlrpc_getposttitle($content) {
global $post_default_title;
if (preg_match('/<title>(.+?)<\/title>/is', $content, $matchtitle)) {
if ( preg_match('/<title>(.+?)<\/title>/is', $content, $matchtitle) ) {
$post_title = $matchtitle[0];
$post_title = preg_replace('/<title>/si', '', $post_title);
$post_title = preg_replace('/<\/title>/si', '', $post_title);
@ -826,7 +826,7 @@ function xmlrpc_getposttitle($content) {
function xmlrpc_getpostcategory($content) {
global $post_default_category;
if (preg_match('/<category>(.+?)<\/category>/is', $content, $matchcat)) {
if ( preg_match('/<category>(.+?)<\/category>/is', $content, $matchcat) ) {
$post_category = trim($matchcat[1], ',');
$post_category = explode(',', $post_category);
} else {
@ -844,7 +844,7 @@ function xmlrpc_removepostdata($content) {
function debug_fopen($filename, $mode) {
global $debug;
if ($debug == 1) {
if ( $debug == 1 ) {
$fp = fopen($filename, $mode);
return $fp;
} else {
@ -854,14 +854,14 @@ function debug_fopen($filename, $mode) {
function debug_fwrite($fp, $string) {
global $debug;
if ($debug == 1) {
if ( $debug == 1 ) {
fwrite($fp, $string);
}
}
function debug_fclose($fp) {
global $debug;
if ($debug == 1) {
if ( $debug == 1 ) {
fclose($fp);
}
}
@ -869,13 +869,13 @@ function debug_fclose($fp) {
function check_for_pings() {
global $wpdb;
$doping = false;
if($wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE TRIM(to_ping) != '' LIMIT 1")) {
if ( $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE TRIM(to_ping) != '' LIMIT 1") )
$doping = true;
}
if($wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pingme' OR meta_key = '_encloseme' LIMIT 1")) {
if ( $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pingme' OR meta_key = '_encloseme' LIMIT 1") )
$doping = true;
}
if($doping)
if ( $doping )
echo '<iframe id="pingcheck" src="' . get_settings('siteurl') .'/wp-admin/execute-pings.php?time=' . time() . '" style="border:none;width:1px;height:1px;"></iframe>';
}
@ -902,9 +902,9 @@ function do_enclose( $content, $post_ID ) {
foreach($post_links_temp[0] as $link_test) :
if ( !in_array($link_test, $pung) ) : // If we haven't pung it already
$test = parse_url($link_test);
if (isset($test['query']))
if ( isset($test['query']) )
$post_links[] = $link_test;
elseif(($test['path'] != '/') && ($test['path'] != ''))
elseif (($test['path'] != '/') && ($test['path'] != ''))
$post_links[] = $link_test;
endif;
endforeach;
@ -915,7 +915,7 @@ function do_enclose( $content, $post_ID ) {
$len = (int) $headers['content-length'];
$type = $wpdb->escape( $headers['content-type'] );
$allowed_types = array( 'video', 'audio' );
if( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
$meta_value = "$url\n$len\n$type\n";
$wpdb->query( "INSERT INTO `$wpdb->postmeta` ( `post_id` , `meta_key` , `meta_value` )
VALUES ( '$post_ID', 'enclosure' , '$meta_value')" );
@ -979,13 +979,13 @@ function setup_postdata($post) {
$currentmonth = mysql2date('m', $post->post_date);
$numpages = 1;
$page = get_query_var('page');
if (!$page)
if ( !$page )
$page = 1;
if (is_single() || is_page())
if ( is_single() || is_page() )
$more = 1;
$content = $post->post_content;
if (preg_match('/<!--nextpage-->/', $content)) {
if ($page > 1)
if ( preg_match('/<!--nextpage-->/', $content) ) {
if ( $page > 1 )
$more = 1;
$multipage = 1;
$content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content);
@ -1002,7 +1002,7 @@ function setup_postdata($post) {
function is_new_day() {
global $day, $previousday;
if ($day != $previousday) {
if ( $day != $previousday ) {
return(1);
} else {
return(0);
@ -1013,9 +1013,9 @@ function is_new_day() {
function merge_filters($tag) {
global $wp_filter;
if (isset($wp_filter['all'])) {
if ( isset($wp_filter['all']) ) {
foreach ($wp_filter['all'] as $priority => $functions) {
if (isset($wp_filter[$tag][$priority]))
if ( isset($wp_filter[$tag][$priority]) )
$wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], $wp_filter[$tag][$priority]);
else
$wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], array());
@ -1034,26 +1034,25 @@ function apply_filters($tag, $string) {
merge_filters($tag);
if (!isset($wp_filter[$tag])) {
if ( !isset($wp_filter[$tag]) ) {
return $string;
}
foreach ($wp_filter[$tag] as $priority => $functions) {
if (!is_null($functions)) {
if ( !is_null($functions) ) {
foreach($functions as $function) {
$all_args = array_merge(array($string), $args);
$function_name = $function['function'];
$accepted_args = $function['accepted_args'];
if($accepted_args == 1) {
if ( $accepted_args == 1 )
$the_args = array($string);
} elseif ($accepted_args > 1) {
elseif ( $accepted_args > 1 )
$the_args = array_slice($all_args, 0, $accepted_args);
} elseif($accepted_args == 0) {
elseif ( $accepted_args == 0 )
$the_args = NULL;
} else {
else
$the_args = $all_args;
}
$string = call_user_func_array($function_name, $the_args);
}
@ -1066,11 +1065,11 @@ function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1)
global $wp_filter;
// check that we don't already have the same filter at the same priority
if (isset($wp_filter[$tag]["$priority"])) {
if ( isset($wp_filter[$tag]["$priority"]) ) {
foreach($wp_filter[$tag]["$priority"] as $filter) {
// uncomment if we want to match function AND accepted_args
//if ($filter == array($function, $accepted_args)) {
if ($filter['function'] == $function_to_add) {
// if ( $filter == array($function, $accepted_args) ) {
if ( $filter['function'] == $function_to_add ) {
return true;
}
}
@ -1085,9 +1084,9 @@ function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args
global $wp_filter;
// rebuild the list of filters
if (isset($wp_filter[$tag]["$priority"])) {
if ( isset($wp_filter[$tag]["$priority"]) ) {
foreach($wp_filter[$tag]["$priority"] as $filter) {
if ($filter['function'] != $function_to_remove) {
if ( $filter['function'] != $function_to_remove ) {
$new_function_list[] = $filter;
}
}
@ -1108,24 +1107,24 @@ function do_action($tag, $arg = '') {
merge_filters($tag);
if (!isset($wp_filter[$tag])) {
if ( !isset($wp_filter[$tag]) ) {
return;
}
foreach ($wp_filter[$tag] as $priority => $functions) {
if (!is_null($functions)) {
if ( !is_null($functions) ) {
foreach($functions as $function) {
$function_name = $function['function'];
$accepted_args = $function['accepted_args'];
if($accepted_args == 1) {
if ( $accepted_args == 1 ) {
if ( is_array($arg) )
$the_args = $arg;
else
$the_args = array($arg);
} elseif ($accepted_args > 1) {
} elseif ( $accepted_args > 1 ) {
$the_args = array_slice($args, 0, $accepted_args);
} elseif($accepted_args == 0) {
} elseif ( $accepted_args == 0 ) {
$the_args = NULL;
} else {
$the_args = $args;
@ -1150,9 +1149,8 @@ function get_page_uri($page_id) {
$uri = urldecode($page->post_name);
// A page cannot be it's own parent.
if ($page->post_parent == $page->ID) {
if ( $page->post_parent == $page->ID )
return $uri;
}
while ($page->post_parent != 0) {
$page = get_page($page->post_parent);
@ -1165,11 +1163,16 @@ function get_page_uri($page_id) {
function get_posts($args) {
global $wpdb;
parse_str($args, $r);
if (!isset($r['numberposts'])) $r['numberposts'] = 5;
if (!isset($r['offset'])) $r['offset'] = 0;
if (!isset($r['category'])) $r['category'] = '';
if (!isset($r['orderby'])) $r['orderby'] = 'post_date';
if (!isset($r['order'])) $r['order'] = 'DESC';
if ( !isset($r['numberposts']) )
$r['numberposts'] = 5;
if ( !isset($r['offset']) )
$r['offset'] = 0;
if ( !isset($r['category']) )
$r['category'] = '';
if ( !isset($r['orderby']) )
$r['orderby'] = 'post_date';
if ( !isset($r['order']) )
$r['order'] = 'DESC';
$now = current_time('mysql');
@ -1230,17 +1233,17 @@ function clean_page_cache($id) {
function update_post_category_cache($post_ids) {
global $wpdb, $category_cache, $cache_categories;
if (empty($post_ids))
if ( empty($post_ids) )
return;
if (is_array($post_ids))
if ( is_array($post_ids) )
$post_ids = implode(',', $post_ids);
$dogs = $wpdb->get_results("SELECT DISTINCT
post_id, cat_ID FROM $wpdb->categories, $wpdb->post2cat
WHERE category_id = cat_ID AND post_id IN ($post_ids)");
if (! isset($cache_categories))
if ( !isset($cache_categories) )
update_category_cache();
if ( !empty($dogs) ) {
@ -1275,7 +1278,7 @@ function update_post_caches(&$posts) {
WHERE ID IN ($post_id_list)
GROUP BY ID");
if ($comment_counts) {
if ( $comment_counts ) {
foreach ($comment_counts as $comment_count)
$comment_count_cache["$comment_count->ID"] = $comment_count->ccount;
}
@ -1290,9 +1293,9 @@ function update_post_caches(&$posts) {
$mval = $metarow['meta_value'];
// Force subkeys to be array type:
if (!isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]))
if ( !isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]) )
$post_meta_cache[$mpid] = array();
if (!isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]))
if ( !isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]) )
$post_meta_cache[$mpid]["$mkey"] = array();
// Add a value to the current pid/key:
@ -1303,7 +1306,7 @@ function update_post_caches(&$posts) {
function update_category_cache() {
global $cache_categories, $wpdb;
if($dogs = $wpdb->get_results("SELECT * FROM $wpdb->categories")):
if ( $dogs = $wpdb->get_results("SELECT * FROM $wpdb->categories") ):
foreach ($dogs as $catt)
$cache_categories[$catt->cat_ID] = $catt;
return true;
@ -1351,23 +1354,20 @@ function is_single ($post = '') {
function is_page ($page = '') {
global $wp_query;
if (! $wp_query->is_page) {
if ( !$wp_query->is_page )
return false;
}
if (empty($page)) {
if ( empty($page) )
return true;
}
$page_obj = $wp_query->get_queried_object();
if ($page == $page_obj->ID) {
if ( $page == $page_obj->ID )
return true;
} else if ($page == $page_obj->post_title) {
elseif ( $page == $page_obj->post_title )
return true;
} else if ($page == $page_obj->post_name) {
else if ( $page == $page_obj->post_name )
return true;
}
return false;
}
@ -1411,23 +1411,20 @@ function is_time () {
function is_author ($author = '') {
global $wp_query;
if (! $wp_query->is_author) {
if ( !$wp_query->is_author )
return false;
}
if (empty($author)) {
if ( empty($author) )
return true;
}
$author_obj = $wp_query->get_queried_object();
if ($author == $author_obj->ID) {
if ( $author == $author_obj->ID )
return true;
} else if ($author == $author_obj->nickname) {
elseif ( $author == $author_obj->nickname )
return true;
} else if ($author == $author_obj->user_nicename) {
elseif ( $author == $author_obj->user_nicename )
return true;
}
return false;
}
@ -1435,23 +1432,20 @@ function is_author ($author = '') {
function is_category ($category = '') {
global $wp_query;
if (! $wp_query->is_category) {
if ( !$wp_query->is_category )
return false;
}
if (empty($category)) {
if ( empty($category) )
return true;
}
$cat_obj = $wp_query->get_queried_object();
if ($category == $cat_obj->cat_ID) {
if ( $category == $cat_obj->cat_ID )
return true;
} else if ($category == $cat_obj->cat_name) {
else if ( $category == $cat_obj->cat_name )
return true;
} else if ($category == $cat_obj->category_nicename) {
elseif ( $category == $cat_obj->category_nicename )
return true;
}
return false;
}
@ -1530,6 +1524,7 @@ function rewind_posts() {
function the_post() {
global $wp_query;
$wp_query->the_post();
}
@ -1602,7 +1597,7 @@ function get_theme_data($theme_file) {
$name = trim($name);
$theme = $name;
if ('' == $author_uri[1]) {
if ( '' == $author_uri[1] ) {
$author = $author_name[1];
} else {
$author = '<a href="' . $author_uri[1] . '" title="' . __('Visit author homepage') . '">' . $author_name[1] . '</a>';
@ -1615,9 +1610,8 @@ function get_themes() {
global $wp_themes;
global $wp_broken_themes;
if (isset($wp_themes)) {
if ( isset($wp_themes) )
return $wp_themes;
}
$themes = array();
$wp_broken_themes = array();
@ -1626,29 +1620,29 @@ function get_themes() {
// Files in wp-content/themes directory
$themes_dir = @ dir($theme_root);
if ($themes_dir) {
if ( $themes_dir ) {
while(($theme_dir = $themes_dir->read()) !== false) {
if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) {
if ($theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS') {
if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' ) {
continue;
}
$stylish_dir = @ dir($theme_root . '/' . $theme_dir);
$found_stylesheet = false;
while(($theme_file = $stylish_dir->read()) !== false) {
while (($theme_file = $stylish_dir->read()) !== false) {
if ( $theme_file == 'style.css' ) {
$theme_files[] = $theme_dir . '/' . $theme_file;
$found_stylesheet = true;
break;
}
}
if (!$found_stylesheet) {
if ( !$found_stylesheet ) {
$wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.'));
}
}
}
}
if (!$themes_dir || !$theme_files) {
if ( !$themes_dir || !$theme_files ) {
return $themes;
}
@ -1671,13 +1665,13 @@ function get_themes() {
else
$screenshot = false;
if (empty($name)) {
if ( empty($name) ) {
$name = dirname($theme_file);
$title = $name;
}
if (empty($template)) {
if (file_exists(dirname("$theme_root/$theme_file/index.php"))) {
if ( empty($template) ) {
if ( file_exists(dirname("$theme_root/$theme_file/index.php")) ) {
$template = dirname($theme_file);
} else {
continue;
@ -1686,14 +1680,14 @@ function get_themes() {
$template = trim($template);
if (! file_exists("$theme_root/$template/index.php")) {
if ( !file_exists("$theme_root/$template/index.php") ) {
$wp_broken_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => __('Template is missing.'));
continue;
}
$stylesheet_files = array();
$stylesheet_dir = @ dir("$theme_root/$stylesheet");
if ($stylesheet_dir) {
if ( $stylesheet_dir ) {
while(($file = $stylesheet_dir->read()) !== false) {
if ( !preg_match('|^\.+$|', $file) && preg_match('|\.css$|', $file) )
$stylesheet_files[] = "$theme_loc/$stylesheet/$file";
@ -1702,7 +1696,7 @@ function get_themes() {
$template_files = array();
$template_dir = @ dir("$theme_root/$template");
if ($template_dir) {
if ( $template_dir ) {
while(($file = $template_dir->read()) !== false) {
if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) )
$template_files[] = "$theme_loc/$template/$file";
@ -1712,8 +1706,10 @@ function get_themes() {
$template_dir = dirname($template_files[0]);
$stylesheet_dir = dirname($stylesheet_files[0]);
if (empty($template_dir)) $template_dir = '/';
if (empty($stylesheet_dir)) $stylesheet_dir = '/';
if ( empty($template_dir) )
$template_dir = '/';
if ( empty($stylesheet_dir) )
$stylesheet_dir = '/';
// Check for theme name collision. This occurs if a theme is copied to
// a new theme directory and the theme header is not updated. Whichever
@ -1741,9 +1737,9 @@ function get_themes() {
foreach ($theme_names as $theme_name) {
$themes[$theme_name]['Parent Theme'] = '';
if ($themes[$theme_name]['Stylesheet'] != $themes[$theme_name]['Template']) {
if ( $themes[$theme_name]['Stylesheet'] != $themes[$theme_name]['Template'] ) {
foreach ($theme_names as $parent_theme_name) {
if (($themes[$parent_theme_name]['Stylesheet'] == $themes[$parent_theme_name]['Template']) && ($themes[$parent_theme_name]['Template'] == $themes[$theme_name]['Template'])) {
if ( ($themes[$parent_theme_name]['Stylesheet'] == $themes[$parent_theme_name]['Template']) && ($themes[$parent_theme_name]['Template'] == $themes[$theme_name]['Template']) ) {
$themes[$theme_name]['Parent Theme'] = $themes[$parent_theme_name]['Name'];
break;
}
@ -1759,9 +1755,8 @@ function get_themes() {
function get_theme($theme) {
$themes = get_themes();
if (array_key_exists($theme, $themes)) {
if ( array_key_exists($theme, $themes) )
return $themes[$theme];
}
return NULL;
}
@ -1773,10 +1768,10 @@ function get_current_theme() {
$current_stylesheet = get_settings('stylesheet');
$current_theme = 'WordPress Default';
if ($themes) {
if ( $themes ) {
foreach ($theme_names as $theme_name) {
if ($themes[$theme_name]['Stylesheet'] == $current_stylesheet &&
$themes[$theme_name]['Template'] == $current_template) {
if ( $themes[$theme_name]['Stylesheet'] == $current_stylesheet &&
$themes[$theme_name]['Template'] == $current_template ) {
$current_theme = $themes[$theme_name]['Name'];
break;
}
@ -1883,9 +1878,8 @@ function htmlentities2($myHTML) {
function is_plugin_page() {
global $plugin_page;
if (isset($plugin_page)) {
if ( isset($plugin_page) )
return true;
}
return false;
}
@ -1902,29 +1896,26 @@ add_query_arg(associative_array, oldquery_or_uri)
*/
function add_query_arg() {
$ret = '';
if(is_array(func_get_arg(0))) {
if ( is_array(func_get_arg(0)) ) {
$uri = @func_get_arg(1);
}
else {
if (@func_num_args() < 3) {
$uri = $_SERVER['REQUEST_URI'];
} else {
if ( @func_num_args() < 3 )
$uri = $_SERVER['REQUEST_URI'];
else
$uri = @func_get_arg(2);
}
}
if (strstr($uri, '?')) {
if ( strstr($uri, '?') ) {
$parts = explode('?', $uri, 2);
if (1 == count($parts)) {
if ( 1 == count($parts) ) {
$base = '?';
$query = $parts[0];
}
else {
} else {
$base = $parts[0] . '?';
$query = $parts[1];
}
}
else if (strstr($uri, '/')) {
else if ( strstr($uri, '/') ) {
$base = $uri . '?';
$query = '';
} else {
@ -1933,20 +1924,17 @@ function add_query_arg() {
}
parse_str($query, $qs);
if (is_array(func_get_arg(0))) {
if ( is_array(func_get_arg(0)) ) {
$kayvees = func_get_arg(0);
$qs = array_merge($qs, $kayvees);
}
else
{
} else {
$qs[func_get_arg(0)] = func_get_arg(1);
}
foreach($qs as $k => $v)
{
if($v != '')
{
if($ret != '') $ret .= '&';
foreach($qs as $k => $v) {
if ( $v != '' ) {
if ( $ret != '' )
$ret .= '&';
$ret .= "$k=$v";
}
}
@ -1971,7 +1959,7 @@ function add_magic_quotes($array) {
global $wpdb;
foreach ($array as $k => $v) {
if (is_array($v)) {
if ( is_array($v) ) {
$array[$k] = add_magic_quotes($v);
} else {
$array[$k] = $wpdb->escape($v);
@ -2005,23 +1993,24 @@ function wp_remote_fopen( $uri ) {
function wp($query_vars = '') {
global $wp;
$wp->main($query_vars);
}
function status_header( $header ) {
if ( 200 == $header ) {
if ( 200 == $header )
$text = 'OK';
} elseif ( 301 == $header ) {
elseif ( 301 == $header )
$text = 'Moved Permanently';
} elseif ( 302 == $header ) {
elseif ( 302 == $header )
$text = 'Moved Temporarily';
} elseif ( 304 == $header ) {
elseif ( 304 == $header )
$text = 'Not Modified';
} elseif ( 404 == $header ) {
elseif ( 404 == $header )
$text = 'Not Found';
} elseif ( 410 == $header ) {
elseif ( 410 == $header )
$text = 'Gone';
}
if ( preg_match('/cgi/',php_sapi_name()) ) {
@header("Status: $header $text");
} else {
@ -2059,7 +2048,7 @@ function get_usermeta( $user_id, $meta_key = '') {
foreach ($metas as $index => $meta) {
@ $value = unserialize($meta->meta_value);
if ($value === FALSE)
if ( $value === FALSE )
$value = $meta->meta_value;
$values[] = $value;