Code cleanups from markjaquith. fixes #1743

git-svn-id: https://develop.svn.wordpress.org/trunk@2941 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2005-10-10 09:25:38 +00:00
parent ab51dd291b
commit 9b7f201b11

View File

@ -213,8 +213,8 @@ function url_to_postid($url) {
if ( false === strpos($rewrite, 'index.php/') ) if ( false === strpos($rewrite, 'index.php/') )
$url = str_replace('index.php/', '', $url); $url = str_replace('index.php/', '', $url);
// Chop off http://domain.com
if ( false !== strpos($url, get_settings('home')) ) { if ( false !== strpos($url, get_settings('home')) ) {
// Chop off http://domain.com
$url = str_replace(get_settings('home'), '', $url); $url = str_replace(get_settings('home'), '', $url);
} else { } else {
// Chop off /path/to/blog // Chop off /path/to/blog
@ -253,7 +253,6 @@ function url_to_postid($url) {
return 0; return 0;
} }
} }
return 0; return 0;
} }
@ -324,9 +323,12 @@ function get_alloptions() {
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) $option->option_value = preg_replace('|/+$|', '', $option->option_value); if ( 'siteurl' == $option->option_name )
if ('home' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value); $option->option_value = preg_replace('|/+$|', '', $option->option_value);
if ('category_base' == $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); @ $value = unserialize($option->option_value);
if ( $value === FALSE ) if ( $value === FALSE )
$value = $option->option_value; $value = $option->option_value;
@ -415,10 +417,7 @@ function add_post_meta($post_id, $key, $value, $unique = false) {
if ( is_array($value) || is_object($value) ) if ( is_array($value) || is_object($value) )
$value = $wpdb->escape(serialize($value)); $value = $wpdb->escape(serialize($value));
$wpdb->query("INSERT INTO $wpdb->postmeta $wpdb->query("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value) VALUES ('$post_id','$key','$value')");
(post_id,meta_key,meta_value)
VALUES ('$post_id','$key','$value')
");
$post_meta_cache['$post_id'][$key][] = $original; $post_meta_cache['$post_id'][$key][] = $original;
@ -436,7 +435,8 @@ post_id = '$post_id' AND meta_key = '$key'");
post_id = '$post_id' AND meta_key = '$key' AND meta_value = '$value'"); 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' $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id'
@ -869,12 +869,12 @@ function debug_fclose($fp) {
function check_for_pings() { function check_for_pings() {
global $wpdb; global $wpdb;
$doping = false; $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; $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; $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>'; echo '<iframe id="pingcheck" src="' . get_settings('siteurl') .'/wp-admin/execute-pings.php?time=' . time() . '" style="border:none;width:1px;height:1px;"></iframe>';
} }
@ -1045,15 +1045,14 @@ function apply_filters($tag, $string) {
$function_name = $function['function']; $function_name = $function['function'];
$accepted_args = $function['accepted_args']; $accepted_args = $function['accepted_args'];
if($accepted_args == 1) { if ( $accepted_args == 1 )
$the_args = array($string); $the_args = array($string);
} elseif ($accepted_args > 1) { elseif ( $accepted_args > 1 )
$the_args = array_slice($all_args, 0, $accepted_args); $the_args = array_slice($all_args, 0, $accepted_args);
} elseif($accepted_args == 0) { elseif ( $accepted_args == 0 )
$the_args = NULL; $the_args = NULL;
} else { else
$the_args = $all_args; $the_args = $all_args;
}
$string = call_user_func_array($function_name, $the_args); $string = call_user_func_array($function_name, $the_args);
} }
@ -1150,9 +1149,8 @@ function get_page_uri($page_id) {
$uri = urldecode($page->post_name); $uri = urldecode($page->post_name);
// A page cannot be it's own parent. // A page cannot be it's own parent.
if ($page->post_parent == $page->ID) { if ( $page->post_parent == $page->ID )
return $uri; return $uri;
}
while ($page->post_parent != 0) { while ($page->post_parent != 0) {
$page = get_page($page->post_parent); $page = get_page($page->post_parent);
@ -1165,11 +1163,16 @@ function get_page_uri($page_id) {
function get_posts($args) { function get_posts($args) {
global $wpdb; global $wpdb;
parse_str($args, $r); parse_str($args, $r);
if (!isset($r['numberposts'])) $r['numberposts'] = 5; if ( !isset($r['numberposts']) )
if (!isset($r['offset'])) $r['offset'] = 0; $r['numberposts'] = 5;
if (!isset($r['category'])) $r['category'] = ''; if ( !isset($r['offset']) )
if (!isset($r['orderby'])) $r['orderby'] = 'post_date'; $r['offset'] = 0;
if (!isset($r['order'])) $r['order'] = 'DESC'; 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'); $now = current_time('mysql');
@ -1351,23 +1354,20 @@ function is_single ($post = '') {
function is_page ($page = '') { function is_page ($page = '') {
global $wp_query; global $wp_query;
if (! $wp_query->is_page) { if ( !$wp_query->is_page )
return false; return false;
}
if (empty($page)) { if ( empty($page) )
return true; return true;
}
$page_obj = $wp_query->get_queried_object(); $page_obj = $wp_query->get_queried_object();
if ($page == $page_obj->ID) { if ( $page == $page_obj->ID )
return true; return true;
} else if ($page == $page_obj->post_title) { elseif ( $page == $page_obj->post_title )
return true; return true;
} else if ($page == $page_obj->post_name) { else if ( $page == $page_obj->post_name )
return true; return true;
}
return false; return false;
} }
@ -1411,23 +1411,20 @@ function is_time () {
function is_author ($author = '') { function is_author ($author = '') {
global $wp_query; global $wp_query;
if (! $wp_query->is_author) { if ( !$wp_query->is_author )
return false; return false;
}
if (empty($author)) { if ( empty($author) )
return true; return true;
}
$author_obj = $wp_query->get_queried_object(); $author_obj = $wp_query->get_queried_object();
if ($author == $author_obj->ID) { if ( $author == $author_obj->ID )
return true; return true;
} else if ($author == $author_obj->nickname) { elseif ( $author == $author_obj->nickname )
return true; return true;
} else if ($author == $author_obj->user_nicename) { elseif ( $author == $author_obj->user_nicename )
return true; return true;
}
return false; return false;
} }
@ -1435,23 +1432,20 @@ function is_author ($author = '') {
function is_category ($category = '') { function is_category ($category = '') {
global $wp_query; global $wp_query;
if (! $wp_query->is_category) { if ( !$wp_query->is_category )
return false; return false;
}
if (empty($category)) { if ( empty($category) )
return true; return true;
}
$cat_obj = $wp_query->get_queried_object(); $cat_obj = $wp_query->get_queried_object();
if ($category == $cat_obj->cat_ID) { if ( $category == $cat_obj->cat_ID )
return true; return true;
} else if ($category == $cat_obj->cat_name) { else if ( $category == $cat_obj->cat_name )
return true; return true;
} else if ($category == $cat_obj->category_nicename) { elseif ( $category == $cat_obj->category_nicename )
return true; return true;
}
return false; return false;
} }
@ -1530,6 +1524,7 @@ function rewind_posts() {
function the_post() { function the_post() {
global $wp_query; global $wp_query;
$wp_query->the_post(); $wp_query->the_post();
} }
@ -1615,9 +1610,8 @@ function get_themes() {
global $wp_themes; global $wp_themes;
global $wp_broken_themes; global $wp_broken_themes;
if (isset($wp_themes)) { if ( isset($wp_themes) )
return $wp_themes; return $wp_themes;
}
$themes = array(); $themes = array();
$wp_broken_themes = array(); $wp_broken_themes = array();
@ -1712,8 +1706,10 @@ function get_themes() {
$template_dir = dirname($template_files[0]); $template_dir = dirname($template_files[0]);
$stylesheet_dir = dirname($stylesheet_files[0]); $stylesheet_dir = dirname($stylesheet_files[0]);
if (empty($template_dir)) $template_dir = '/'; if ( empty($template_dir) )
if (empty($stylesheet_dir)) $stylesheet_dir = '/'; $template_dir = '/';
if ( empty($stylesheet_dir) )
$stylesheet_dir = '/';
// Check for theme name collision. This occurs if a theme is copied to // 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 // a new theme directory and the theme header is not updated. Whichever
@ -1759,9 +1755,8 @@ function get_themes() {
function get_theme($theme) { function get_theme($theme) {
$themes = get_themes(); $themes = get_themes();
if (array_key_exists($theme, $themes)) { if ( array_key_exists($theme, $themes) )
return $themes[$theme]; return $themes[$theme];
}
return NULL; return NULL;
} }
@ -1883,9 +1878,8 @@ function htmlentities2($myHTML) {
function is_plugin_page() { function is_plugin_page() {
global $plugin_page; global $plugin_page;
if (isset($plugin_page)) { if ( isset($plugin_page) )
return true; return true;
}
return false; return false;
} }
@ -1904,22 +1898,19 @@ function add_query_arg() {
$ret = ''; $ret = '';
if ( is_array(func_get_arg(0)) ) { if ( is_array(func_get_arg(0)) ) {
$uri = @func_get_arg(1); $uri = @func_get_arg(1);
}
else {
if (@func_num_args() < 3) {
$uri = $_SERVER['REQUEST_URI'];
} else { } else {
if ( @func_num_args() < 3 )
$uri = $_SERVER['REQUEST_URI'];
else
$uri = @func_get_arg(2); $uri = @func_get_arg(2);
} }
}
if ( strstr($uri, '?') ) { if ( strstr($uri, '?') ) {
$parts = explode('?', $uri, 2); $parts = explode('?', $uri, 2);
if ( 1 == count($parts) ) { if ( 1 == count($parts) ) {
$base = '?'; $base = '?';
$query = $parts[0]; $query = $parts[0];
} } else {
else {
$base = $parts[0] . '?'; $base = $parts[0] . '?';
$query = $parts[1]; $query = $parts[1];
} }
@ -1936,17 +1927,14 @@ function add_query_arg() {
if ( is_array(func_get_arg(0)) ) { if ( is_array(func_get_arg(0)) ) {
$kayvees = func_get_arg(0); $kayvees = func_get_arg(0);
$qs = array_merge($qs, $kayvees); $qs = array_merge($qs, $kayvees);
} } else {
else
{
$qs[func_get_arg(0)] = func_get_arg(1); $qs[func_get_arg(0)] = func_get_arg(1);
} }
foreach($qs as $k => $v) foreach($qs as $k => $v) {
{ if ( $v != '' ) {
if($v != '') if ( $ret != '' )
{ $ret .= '&';
if($ret != '') $ret .= '&';
$ret .= "$k=$v"; $ret .= "$k=$v";
} }
} }
@ -2005,23 +1993,24 @@ 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 status_header( $header ) { function status_header( $header ) {
if ( 200 == $header ) { if ( 200 == $header )
$text = 'OK'; $text = 'OK';
} elseif ( 301 == $header ) { elseif ( 301 == $header )
$text = 'Moved Permanently'; $text = 'Moved Permanently';
} elseif ( 302 == $header ) { elseif ( 302 == $header )
$text = 'Moved Temporarily'; $text = 'Moved Temporarily';
} elseif ( 304 == $header ) { elseif ( 304 == $header )
$text = 'Not Modified'; $text = 'Not Modified';
} elseif ( 404 == $header ) { elseif ( 404 == $header )
$text = 'Not Found'; $text = 'Not Found';
} elseif ( 410 == $header ) { elseif ( 410 == $header )
$text = 'Gone'; $text = 'Gone';
}
if ( preg_match('/cgi/',php_sapi_name()) ) { if ( preg_match('/cgi/',php_sapi_name()) ) {
@header("Status: $header $text"); @header("Status: $header $text");
} else { } else {