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

@ -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
@ -253,7 +253,6 @@ function url_to_postid($url) {
return 0;
}
}
return 0;
}
@ -324,9 +323,12 @@ 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 )
$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) )
$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;
@ -436,7 +435,8 @@ 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) ) {
$wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id'
@ -869,12 +869,12 @@ 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 )
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'];
$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);
}
@ -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');
@ -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();
}
@ -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();
@ -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
@ -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;
}
@ -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;
}
@ -1904,22 +1898,19 @@ function add_query_arg() {
$ret = '';
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, '?') ) {
$parts = explode('?', $uri, 2);
if ( 1 == count($parts) ) {
$base = '?';
$query = $parts[0];
}
else {
} else {
$base = $parts[0] . '?';
$query = $parts[1];
}
@ -1936,17 +1927,14 @@ function add_query_arg() {
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";
}
}
@ -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 {