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

@ -2,7 +2,7 @@
require_once(dirname(__FILE__).'/functions-compat.php'); require_once(dirname(__FILE__).'/functions-compat.php');
if (!function_exists('_')) { if ( !function_exists('_') ) {
function _($string) { function _($string) {
return $string; return $string;
} }
@ -10,7 +10,7 @@ if (!function_exists('_')) {
function get_profile($field, $user = false) { function get_profile($field, $user = false) {
global $wpdb; global $wpdb;
if (!$user) if ( !$user )
$user = $wpdb->escape($_COOKIE[USER_COOKIE]); $user = $wpdb->escape($_COOKIE[USER_COOKIE]);
return $wpdb->get_var("SELECT $field FROM $wpdb->users WHERE user_login = '$user'"); 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) { function mysql2date($dateformatstring, $mysqlstring, $translate = true) {
global $month, $weekday, $month_abbrev, $weekday_abbrev; global $month, $weekday, $month_abbrev, $weekday_abbrev;
$m = $mysqlstring; $m = $mysqlstring;
if (empty($m)) { if ( empty($m) ) {
return false; 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)); $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 = $month[date('m', $i)];
$datemonth_abbrev = $month_abbrev[$datemonth]; $datemonth_abbrev = $month_abbrev[$datemonth];
$dateweekday = $weekday[date('w', $i)]; $dateweekday = $weekday[date('w', $i)];
@ -36,7 +36,7 @@ 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) { if ( !$j ) {
// for debug purposes // for debug purposes
// echo $i." ".$mysqlstring; // echo $i." ".$mysqlstring;
} }
@ -46,12 +46,12 @@ function mysql2date($dateformatstring, $mysqlstring, $translate = true) {
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'); 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))); else $d = gmdate('Y-m-d H:i:s', (time() + (get_settings('gmt_offset') * 3600)));
return $d; return $d;
break; break;
case 'timestamp': case 'timestamp':
if ($gmt) $d = time(); if ( $gmt ) $d = time();
else $d = time() + (get_settings('gmt_offset') * 3600); else $d = time() + (get_settings('gmt_offset') * 3600);
return $d; return $d;
break; break;
@ -61,7 +61,7 @@ function current_time($type, $gmt = 0) {
function date_i18n($dateformatstring, $unixtimestamp) { function date_i18n($dateformatstring, $unixtimestamp) {
global $month, $weekday, $month_abbrev, $weekday_abbrev; global $month, $weekday, $month_abbrev, $weekday_abbrev;
$i = $unixtimestamp; $i = $unixtimestamp;
if ((!empty($month)) && (!empty($weekday))) { if ( (!empty($month)) && (!empty($weekday)) ) {
$datemonth = $month[date('m', $i)]; $datemonth = $month[date('m', $i)];
$datemonth_abbrev = $month_abbrev[$datemonth]; $datemonth_abbrev = $month_abbrev[$datemonth];
$dateweekday = $weekday[date('w', $i)]; $dateweekday = $weekday[date('w', $i)];
@ -85,19 +85,19 @@ function get_weekstartend($mysqlstring, $start_of_week) {
$weekday = date('w',$day); $weekday = date('w',$day);
$i = 86400; $i = 86400;
if ($weekday < get_settings('start_of_week')) if ( $weekday < get_settings('start_of_week') )
$weekday = 7 - (get_settings('start_of_week') - $weekday); $weekday = 7 - (get_settings('start_of_week') - $weekday);
while ($weekday > get_settings('start_of_week')) { while ($weekday > get_settings('start_of_week')) {
$weekday = date('w',$day); $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); $weekday = 7 - (get_settings('start_of_week') - $weekday);
$day = $day - 86400; $day = $day - 86400;
$i = 0; $i = 0;
} }
$week['start'] = $day + 86400 - $i; $week['start'] = $day + 86400 - $i;
//$week['end'] = $day - $i + 691199; // $week['end'] = $day - $i + 691199;
$week['end'] = $week['start'] + 604799; $week['end'] = $week['start'] + 604799;
return $week; return $week;
} }
@ -144,7 +144,7 @@ function get_lastpostmodified($timezone = 'server') {
break; break;
} }
$lastpostdate = get_lastpostdate($timezone); $lastpostdate = get_lastpostdate($timezone);
if ($lastpostdate > $lastpostmodified) { if ( $lastpostdate > $lastpostmodified ) {
$lastpostmodified = $lastpostdate; $lastpostmodified = $lastpostdate;
} }
$cache_lastpostmodified[$timezone] = $lastpostmodified; $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 // 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); preg_match('#[?&](p|page_id)=(\d+)#', $url, $values);
$id = intval($values[2]); $id = intval($values[2]);
if ($id) return $id; if ( $id ) return $id;
// Check to see if we are using rewrite rules // Check to see if we are using rewrite rules
$rewrite = $wp_rewrite->wp_rewrite_rules(); $rewrite = $wp_rewrite->wp_rewrite_rules();
@ -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
@ -235,11 +235,11 @@ function url_to_postid($url) {
foreach ($rewrite as $match => $query) { foreach ($rewrite as $match => $query) {
// If the requesting file is the anchor of the match, prepend it // If the requesting file is the anchor of the match, prepend it
// to the path info. // to the path info.
if ((! empty($url)) && (strpos($match, $url) === 0)) { if ( (! empty($url)) && (strpos($match, $url) === 0) ) {
$request_match = $url . '/' . $request; $request_match = $url . '/' . $request;
} }
if (preg_match("!^$match!", $request_match, $matches)) { if ( preg_match("!^$match!", $request_match, $matches) ) {
// Got a match. // Got a match.
// Trim the query of everything up to the '?'. // Trim the query of everything up to the '?'.
$query = preg_replace("!^.+\?!", '', $query); $query = preg_replace("!^.+\?!", '', $query);
@ -253,7 +253,6 @@ function url_to_postid($url) {
return 0; return 0;
} }
} }
return 0; return 0;
} }
@ -271,7 +270,7 @@ function get_settings($setting) {
if ( empty($cache_nonexistantoptions) ) if ( empty($cache_nonexistantoptions) )
$cache_nonexistantoptions = array(); $cache_nonexistantoptions = array();
if ('home' == $setting && '' == $cache_settings->home) if ( 'home' == $setting && '' == $cache_settings->home )
return apply_filters('option_' . $setting, $cache_settings->siteurl); return apply_filters('option_' . $setting, $cache_settings->siteurl);
if ( isset($cache_settings->$setting) ) : if ( isset($cache_settings->$setting) ) :
@ -289,7 +288,7 @@ function get_settings($setting) {
endif; endif;
@ $kellogs = unserialize($option); @ $kellogs = unserialize($option);
if ($kellogs !== FALSE) if ( $kellogs !== FALSE )
return apply_filters('option_' . $setting, $kellogs); return apply_filters('option_' . $setting, $kellogs);
else return apply_filters('option_' . $setting, $option); else return apply_filters('option_' . $setting, $option);
endif; endif;
@ -316,7 +315,7 @@ 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();
@ -324,11 +323,14 @@ 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;
$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);
} }
@ -378,13 +380,13 @@ function add_option($name, $value = '', $description = '', $autoload = 'yes') {
if ( is_array($value) || is_object($value) ) if ( is_array($value) || is_object($value) )
$value = serialize($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); $name = $wpdb->escape($name);
$value = $wpdb->escape($value); $value = $wpdb->escape($value);
$description = $wpdb->escape($description); $description = $wpdb->escape($description);
$wpdb->query("INSERT INTO $wpdb->options (option_name, option_value, option_description, autoload) VALUES ('$name', '$value', '$description', '$autoload')"); $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; global $cache_settings;
$cache_settings->{$name} = $original; $cache_settings->{$name} = $original;
} }
@ -396,7 +398,7 @@ function delete_option($name) {
global $wpdb; global $wpdb;
// Get the ID, if no ID then return // Get the ID, if no ID then return
$option_id = $wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = '$name'"); $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'"); $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = '$name'");
return true; return true;
} }
@ -404,8 +406,8 @@ function delete_option($name) {
function add_post_meta($post_id, $key, $value, $unique = false) { function add_post_meta($post_id, $key, $value, $unique = false) {
global $wpdb, $post_meta_cache; global $wpdb, $post_meta_cache;
if ($unique) { if ( $unique ) {
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'") ) { = '$key' AND post_id = '$post_id'") ) {
return false; return false;
} }
@ -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;
@ -428,7 +427,7 @@ function add_post_meta($post_id, $key, $value, $unique = false) {
function delete_post_meta($post_id, $key, $value = '') { function delete_post_meta($post_id, $key, $value = '') {
global $wpdb, $post_meta_cache; global $wpdb, $post_meta_cache;
if (empty($value)) { if ( empty($value) ) {
$meta_id = $wpdb->get_var("SELECT meta_id FROM $wpdb->postmeta WHERE $meta_id = $wpdb->get_var("SELECT meta_id FROM $wpdb->postmeta WHERE
post_id = '$post_id' AND meta_key = '$key'"); post_id = '$post_id' AND meta_key = '$key'");
} else { } 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'"); 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'
AND meta_key = '$key'"); AND meta_key = '$key'");
unset($post_meta_cache['$post_id'][$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) { function get_post_meta($post_id, $key, $single = false) {
global $wpdb, $post_meta_cache; global $wpdb, $post_meta_cache;
if (isset($post_meta_cache[$post_id][$key])) { if ( isset($post_meta_cache[$post_id][$key]) ) {
if ($single) { if ( $single ) {
return $post_meta_cache[$post_id][$key][0]; return $post_meta_cache[$post_id][$key][0];
} else { } else {
return $post_meta_cache[$post_id][$key]; 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); $metalist = $wpdb->get_results("SELECT meta_value FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key'", ARRAY_N);
$values = array(); $values = array();
if ($metalist) { if ( $metalist ) {
foreach ($metalist as $metarow) { foreach ($metalist as $metarow) {
$values[] = $metarow[0]; $values[] = $metarow[0];
} }
} }
if ($single) { if ( $single ) {
if (count($values)) { if ( count($values) ) {
$return = $values[0]; $return = $values[0];
} else { } else {
return ''; return '';
@ -487,7 +487,7 @@ function get_post_meta($post_id, $key, $single = false) {
} }
@ $kellogs = unserialize($return); @ $kellogs = unserialize($return);
if ($kellogs !== FALSE) if ( $kellogs !== FALSE )
return $kellogs; return $kellogs;
else return $return; 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) ) if ( is_array($prev_value) || is_object($prev_value) )
$prev_value = serialize($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'") ) { = '$key' AND post_id = '$post_id'") ) {
return false; return false;
} }
if (empty($prev_value)) { if ( empty($prev_value) ) {
$wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE
meta_key = '$key' AND post_id = '$post_id'"); meta_key = '$key' AND post_id = '$post_id'");
$cache_key = $post_meta_cache['$post_id'][$key]; $cache_key = $post_meta_cache['$post_id'][$key];
@ -560,12 +560,12 @@ function &get_post(&$post, $output = OBJECT) {
$_post = & $GLOBALS['post']; $_post = & $GLOBALS['post'];
else else
$_post = null; $_post = null;
} elseif (is_object($post) ) { } elseif ( is_object($post) ) {
if (! isset($post_cache[$post->ID])) if ( !isset($post_cache[$post->ID]) )
$post_cache[$post->ID] = &$post; $post_cache[$post->ID] = &$post;
$_post = & $post_cache[$post->ID]; $_post = & $post_cache[$post->ID];
} else { } else {
if (isset($post_cache[$post])) if ( isset($post_cache[$post]) )
$_post = & $post_cache[$post]; $_post = & $post_cache[$post];
else { else {
$query = "SELECT * FROM $wpdb->posts WHERE ID = '$post'"; $query = "SELECT * FROM $wpdb->posts WHERE ID = '$post'";
@ -595,14 +595,14 @@ function &get_page(&$page, $output = OBJECT) {
$_page = & $GLOBALS['page']; $_page = & $GLOBALS['page'];
else else
$_page = null; $_page = null;
} elseif (is_object($page) ) { } elseif ( is_object($page) ) {
if (! isset($page_cache[$page->ID])) if ( !isset($page_cache[$page->ID]) )
$page_cache[$page->ID] = &$page; $page_cache[$page->ID] = &$page;
$_page = & $page_cache[$page->ID]; $_page = & $page_cache[$page->ID];
} else { } else {
if ( isset($GLOBALS['page']) && ($page == $GLOBALS['page']->ID) ) if ( isset($GLOBALS['page']) && ($page == $GLOBALS['page']->ID) )
$_page = & $GLOBALS['page']; $_page = & $GLOBALS['page'];
elseif (isset($page_cache[$page])) elseif ( isset($page_cache[$page]) )
$_page = & $page_cache[$page]; $_page = & $page_cache[$page];
else { else {
$query = "SELECT * FROM $wpdb->posts WHERE ID= '$page'"; $query = "SELECT * FROM $wpdb->posts WHERE ID= '$page'";
@ -630,11 +630,11 @@ function &get_category(&$category, $output = OBJECT) {
if ( empty($category) ) if ( empty($category) )
return null; return null;
if ( ! isset($cache_categories)) if ( !isset($cache_categories) )
update_category_cache(); update_category_cache();
if (is_object($category)) { if ( is_object($category) ) {
if ( ! isset($cache_categories[$category->cat_ID])) if ( !isset($cache_categories[$category->cat_ID]) )
$cache_categories[$category->cat_ID] = &$category; $cache_categories[$category->cat_ID] = &$category;
$_category = & $cache_categories[$category->cat_ID]; $_category = & $cache_categories[$category->cat_ID];
} else { } else {
@ -665,8 +665,8 @@ function &get_comment(&$comment, $output = OBJECT) {
if ( empty($comment) ) if ( empty($comment) )
return null; return null;
if (is_object($comment)) { if ( is_object($comment) ) {
if ( ! isset($comment_cache[$comment->comment_ID])) if ( !isset($comment_cache[$comment->comment_ID]) )
$comment_cache[$comment->comment_ID] = &$comment; $comment_cache[$comment->comment_ID] = &$comment;
$_comment = & $comment_cache[$comment->comment_ID]; $_comment = & $comment_cache[$comment->comment_ID];
} else { } else {
@ -698,7 +698,7 @@ function gzip_compression() {
if ( strstr($_SERVER['PHP_SELF'], 'wp-admin') ) return false; if ( strstr($_SERVER['PHP_SELF'], 'wp-admin') ) return false;
if ( !get_settings('gzipcompression') ) return false; if ( !get_settings('gzipcompression') ) return false;
if( extension_loaded('zlib') ) { if ( extension_loaded('zlib') ) {
ob_start('ob_gzhandler'); 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]; $mtime = $mtime[1] + $mtime[0];
$timeend = $mtime; $timeend = $mtime;
$timetotal = $timeend-$timestart; $timetotal = $timeend-$timestart;
if ($display) if ( $display )
echo number_format($timetotal,$precision); echo number_format($timetotal,$precision);
return $timetotal; return $timetotal;
} }
@ -739,7 +739,7 @@ function generic_ping($post_id = 0) {
$services = get_settings('ping_sites'); $services = get_settings('ping_sites');
$services = preg_replace("|(\s)+|", '$1', $services); // Kill dupe lines $services = preg_replace("|(\s)+|", '$1', $services); // Kill dupe lines
$services = trim($services); $services = trim($services);
if ('' != $services) { if ( '' != $services ) {
$services = explode("\n", $services); $services = explode("\n", $services);
foreach ($services as $service) { foreach ($services as $service) {
weblog_ping($service); weblog_ping($service);
@ -753,7 +753,7 @@ function generic_ping($post_id = 0) {
function trackback($trackback_url, $title, $excerpt, $ID) { function trackback($trackback_url, $title, $excerpt, $ID) {
global $wpdb, $wp_version; global $wpdb, $wp_version;
if (empty($trackback_url)) if ( empty($trackback_url) )
return; return;
$title = urlencode($title); $title = urlencode($title);
@ -814,7 +814,7 @@ function make_url_footnote($content) {
function xmlrpc_getposttitle($content) { function xmlrpc_getposttitle($content) {
global $post_default_title; 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 = $matchtitle[0];
$post_title = preg_replace('/<title>/si', '', $post_title); $post_title = preg_replace('/<title>/si', '', $post_title);
$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) { 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) ) {
$post_category = trim($matchcat[1], ','); $post_category = trim($matchcat[1], ',');
$post_category = explode(',', $post_category); $post_category = explode(',', $post_category);
} else { } else {
@ -844,7 +844,7 @@ function xmlrpc_removepostdata($content) {
function debug_fopen($filename, $mode) { function debug_fopen($filename, $mode) {
global $debug; global $debug;
if ($debug == 1) { if ( $debug == 1 ) {
$fp = fopen($filename, $mode); $fp = fopen($filename, $mode);
return $fp; return $fp;
} else { } else {
@ -854,14 +854,14 @@ function debug_fopen($filename, $mode) {
function debug_fwrite($fp, $string) { function debug_fwrite($fp, $string) {
global $debug; global $debug;
if ($debug == 1) { if ( $debug == 1 ) {
fwrite($fp, $string); fwrite($fp, $string);
} }
} }
function debug_fclose($fp) { function debug_fclose($fp) {
global $debug; global $debug;
if ($debug == 1) { if ( $debug == 1 ) {
fclose($fp); fclose($fp);
} }
} }
@ -869,13 +869,13 @@ 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>';
} }
@ -902,9 +902,9 @@ function do_enclose( $content, $post_ID ) {
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; endif;
endforeach; endforeach;
@ -915,7 +915,7 @@ function do_enclose( $content, $post_ID ) {
$len = (int) $headers['content-length']; $len = (int) $headers['content-length'];
$type = $wpdb->escape( $headers['content-type'] ); $type = $wpdb->escape( $headers['content-type'] );
$allowed_types = array( 'video', 'audio' ); $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"; $meta_value = "$url\n$len\n$type\n";
$wpdb->query( "INSERT INTO `$wpdb->postmeta` ( `post_id` , `meta_key` , `meta_value` ) $wpdb->query( "INSERT INTO `$wpdb->postmeta` ( `post_id` , `meta_key` , `meta_value` )
VALUES ( '$post_ID', 'enclosure' , '$meta_value')" ); VALUES ( '$post_ID', 'enclosure' , '$meta_value')" );
@ -979,13 +979,13 @@ function setup_postdata($post) {
$currentmonth = mysql2date('m', $post->post_date); $currentmonth = mysql2date('m', $post->post_date);
$numpages = 1; $numpages = 1;
$page = get_query_var('page'); $page = get_query_var('page');
if (!$page) if ( !$page )
$page = 1; $page = 1;
if (is_single() || is_page()) if ( is_single() || is_page() )
$more = 1; $more = 1;
$content = $post->post_content; $content = $post->post_content;
if (preg_match('/<!--nextpage-->/', $content)) { if ( preg_match('/<!--nextpage-->/', $content) ) {
if ($page > 1) if ( $page > 1 )
$more = 1; $more = 1;
$multipage = 1; $multipage = 1;
$content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content); $content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content);
@ -1002,7 +1002,7 @@ function setup_postdata($post) {
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);
@ -1013,9 +1013,9 @@ function is_new_day() {
function merge_filters($tag) { function merge_filters($tag) {
global $wp_filter; global $wp_filter;
if (isset($wp_filter['all'])) { if ( isset($wp_filter['all']) ) {
foreach ($wp_filter['all'] as $priority => $functions) { 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]); $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], $wp_filter[$tag][$priority]);
else else
$wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], array()); $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], array());
@ -1034,26 +1034,25 @@ function apply_filters($tag, $string) {
merge_filters($tag); merge_filters($tag);
if (!isset($wp_filter[$tag])) { if ( !isset($wp_filter[$tag]) ) {
return $string; return $string;
} }
foreach ($wp_filter[$tag] as $priority => $functions) { foreach ($wp_filter[$tag] as $priority => $functions) {
if (!is_null($functions)) { if ( !is_null($functions) ) {
foreach($functions as $function) { foreach($functions as $function) {
$all_args = array_merge(array($string), $args); $all_args = array_merge(array($string), $args);
$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);
} }
@ -1066,11 +1065,11 @@ function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1)
global $wp_filter; global $wp_filter;
// check that we don't already have the same filter at the same priority // 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) { foreach($wp_filter[$tag]["$priority"] as $filter) {
// uncomment if we want to match function AND accepted_args // uncomment if we want to match function AND accepted_args
//if ($filter == array($function, $accepted_args)) { // if ( $filter == array($function, $accepted_args) ) {
if ($filter['function'] == $function_to_add) { if ( $filter['function'] == $function_to_add ) {
return true; return true;
} }
} }
@ -1085,9 +1084,9 @@ function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args
global $wp_filter; global $wp_filter;
// rebuild the list of filters // rebuild the list of filters
if (isset($wp_filter[$tag]["$priority"])) { if ( isset($wp_filter[$tag]["$priority"]) ) {
foreach($wp_filter[$tag]["$priority"] as $filter) { foreach($wp_filter[$tag]["$priority"] as $filter) {
if ($filter['function'] != $function_to_remove) { if ( $filter['function'] != $function_to_remove ) {
$new_function_list[] = $filter; $new_function_list[] = $filter;
} }
} }
@ -1108,24 +1107,24 @@ function do_action($tag, $arg = '') {
merge_filters($tag); merge_filters($tag);
if (!isset($wp_filter[$tag])) { if ( !isset($wp_filter[$tag]) ) {
return; return;
} }
foreach ($wp_filter[$tag] as $priority => $functions) { foreach ($wp_filter[$tag] as $priority => $functions) {
if (!is_null($functions)) { if ( !is_null($functions) ) {
foreach($functions as $function) { foreach($functions as $function) {
$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 ) {
if ( is_array($arg) ) if ( is_array($arg) )
$the_args = $arg; $the_args = $arg;
else else
$the_args = array($arg); $the_args = array($arg);
} elseif ($accepted_args > 1) { } elseif ( $accepted_args > 1 ) {
$the_args = array_slice($args, 0, $accepted_args); $the_args = array_slice($args, 0, $accepted_args);
} elseif($accepted_args == 0) { } elseif ( $accepted_args == 0 ) {
$the_args = NULL; $the_args = NULL;
} else { } else {
$the_args = $args; $the_args = $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');
@ -1230,17 +1233,17 @@ function clean_page_cache($id) {
function update_post_category_cache($post_ids) { function update_post_category_cache($post_ids) {
global $wpdb, $category_cache, $cache_categories; global $wpdb, $category_cache, $cache_categories;
if (empty($post_ids)) if ( empty($post_ids) )
return; return;
if (is_array($post_ids)) if ( is_array($post_ids) )
$post_ids = implode(',', $post_ids); $post_ids = implode(',', $post_ids);
$dogs = $wpdb->get_results("SELECT DISTINCT $dogs = $wpdb->get_results("SELECT DISTINCT
post_id, cat_ID FROM $wpdb->categories, $wpdb->post2cat post_id, cat_ID FROM $wpdb->categories, $wpdb->post2cat
WHERE category_id = cat_ID AND post_id IN ($post_ids)"); WHERE category_id = cat_ID AND post_id IN ($post_ids)");
if (! isset($cache_categories)) if ( !isset($cache_categories) )
update_category_cache(); update_category_cache();
if ( !empty($dogs) ) { if ( !empty($dogs) ) {
@ -1275,7 +1278,7 @@ function update_post_caches(&$posts) {
WHERE ID IN ($post_id_list) WHERE ID IN ($post_id_list)
GROUP BY ID"); GROUP BY ID");
if ($comment_counts) { if ( $comment_counts ) {
foreach ($comment_counts as $comment_count) foreach ($comment_counts as $comment_count)
$comment_count_cache["$comment_count->ID"] = $comment_count->ccount; $comment_count_cache["$comment_count->ID"] = $comment_count->ccount;
} }
@ -1290,9 +1293,9 @@ function update_post_caches(&$posts) {
$mval = $metarow['meta_value']; $mval = $metarow['meta_value'];
// Force subkeys to be array type: // 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(); $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(); $post_meta_cache[$mpid]["$mkey"] = array();
// Add a value to the current pid/key: // Add a value to the current pid/key:
@ -1303,7 +1306,7 @@ function update_post_caches(&$posts) {
function update_category_cache() { function update_category_cache() {
global $cache_categories, $wpdb; 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) foreach ($dogs as $catt)
$cache_categories[$catt->cat_ID] = $catt; $cache_categories[$catt->cat_ID] = $catt;
return true; return true;
@ -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();
} }
@ -1602,7 +1597,7 @@ function get_theme_data($theme_file) {
$name = trim($name); $name = trim($name);
$theme = $name; $theme = $name;
if ('' == $author_uri[1]) { if ( '' == $author_uri[1] ) {
$author = $author_name[1]; $author = $author_name[1];
} else { } else {
$author = '<a href="' . $author_uri[1] . '" title="' . __('Visit author homepage') . '">' . $author_name[1] . '</a>'; $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_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();
@ -1626,29 +1620,29 @@ function get_themes() {
// Files in wp-content/themes directory // Files in wp-content/themes directory
$themes_dir = @ dir($theme_root); $themes_dir = @ dir($theme_root);
if ($themes_dir) { if ( $themes_dir ) {
while(($theme_dir = $themes_dir->read()) !== false) { while(($theme_dir = $themes_dir->read()) !== false) {
if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) { 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; continue;
} }
$stylish_dir = @ dir($theme_root . '/' . $theme_dir); $stylish_dir = @ dir($theme_root . '/' . $theme_dir);
$found_stylesheet = false; $found_stylesheet = false;
while(($theme_file = $stylish_dir->read()) !== false) { while (($theme_file = $stylish_dir->read()) !== false) {
if ( $theme_file == 'style.css' ) { if ( $theme_file == 'style.css' ) {
$theme_files[] = $theme_dir . '/' . $theme_file; $theme_files[] = $theme_dir . '/' . $theme_file;
$found_stylesheet = true; $found_stylesheet = true;
break; break;
} }
} }
if (!$found_stylesheet) { if ( !$found_stylesheet ) {
$wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.')); $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; return $themes;
} }
@ -1671,13 +1665,13 @@ function get_themes() {
else else
$screenshot = false; $screenshot = false;
if (empty($name)) { if ( empty($name) ) {
$name = dirname($theme_file); $name = dirname($theme_file);
$title = $name; $title = $name;
} }
if (empty($template)) { if ( empty($template) ) {
if (file_exists(dirname("$theme_root/$theme_file/index.php"))) { if ( file_exists(dirname("$theme_root/$theme_file/index.php")) ) {
$template = dirname($theme_file); $template = dirname($theme_file);
} else { } else {
continue; continue;
@ -1686,14 +1680,14 @@ function get_themes() {
$template = trim($template); $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.')); $wp_broken_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => __('Template is missing.'));
continue; continue;
} }
$stylesheet_files = array(); $stylesheet_files = array();
$stylesheet_dir = @ dir("$theme_root/$stylesheet"); $stylesheet_dir = @ dir("$theme_root/$stylesheet");
if ($stylesheet_dir) { if ( $stylesheet_dir ) {
while(($file = $stylesheet_dir->read()) !== false) { while(($file = $stylesheet_dir->read()) !== false) {
if ( !preg_match('|^\.+$|', $file) && preg_match('|\.css$|', $file) ) if ( !preg_match('|^\.+$|', $file) && preg_match('|\.css$|', $file) )
$stylesheet_files[] = "$theme_loc/$stylesheet/$file"; $stylesheet_files[] = "$theme_loc/$stylesheet/$file";
@ -1702,7 +1696,7 @@ function get_themes() {
$template_files = array(); $template_files = array();
$template_dir = @ dir("$theme_root/$template"); $template_dir = @ dir("$theme_root/$template");
if ($template_dir) { if ( $template_dir ) {
while(($file = $template_dir->read()) !== false) { while(($file = $template_dir->read()) !== false) {
if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) ) if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) )
$template_files[] = "$theme_loc/$template/$file"; $template_files[] = "$theme_loc/$template/$file";
@ -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
@ -1741,9 +1737,9 @@ function get_themes() {
foreach ($theme_names as $theme_name) { foreach ($theme_names as $theme_name) {
$themes[$theme_name]['Parent Theme'] = ''; $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) { 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']; $themes[$theme_name]['Parent Theme'] = $themes[$parent_theme_name]['Name'];
break; break;
} }
@ -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;
} }
@ -1773,10 +1768,10 @@ function get_current_theme() {
$current_stylesheet = get_settings('stylesheet'); $current_stylesheet = get_settings('stylesheet');
$current_theme = 'WordPress Default'; $current_theme = 'WordPress Default';
if ($themes) { if ( $themes ) {
foreach ($theme_names as $theme_name) { foreach ($theme_names as $theme_name) {
if ($themes[$theme_name]['Stylesheet'] == $current_stylesheet && if ( $themes[$theme_name]['Stylesheet'] == $current_stylesheet &&
$themes[$theme_name]['Template'] == $current_template) { $themes[$theme_name]['Template'] == $current_template ) {
$current_theme = $themes[$theme_name]['Name']; $current_theme = $themes[$theme_name]['Name'];
break; break;
} }
@ -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;
} }
@ -1902,29 +1896,26 @@ add_query_arg(associative_array, oldquery_or_uri)
*/ */
function add_query_arg() { 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];
} }
} }
else if (strstr($uri, '/')) { else if ( strstr($uri, '/') ) {
$base = $uri . '?'; $base = $uri . '?';
$query = ''; $query = '';
} else { } else {
@ -1933,20 +1924,17 @@ function add_query_arg() {
} }
parse_str($query, $qs); parse_str($query, $qs);
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";
} }
} }
@ -1971,7 +1959,7 @@ function add_magic_quotes($array) {
global $wpdb; global $wpdb;
foreach ($array as $k => $v) { foreach ($array as $k => $v) {
if (is_array($v)) { if ( is_array($v) ) {
$array[$k] = add_magic_quotes($v); $array[$k] = add_magic_quotes($v);
} else { } else {
$array[$k] = $wpdb->escape($v); $array[$k] = $wpdb->escape($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 {
@ -2059,7 +2048,7 @@ function get_usermeta( $user_id, $meta_key = '') {
foreach ($metas as $index => $meta) { foreach ($metas as $index => $meta) {
@ $value = unserialize($meta->meta_value); @ $value = unserialize($meta->meta_value);
if ($value === FALSE) if ( $value === FALSE )
$value = $meta->meta_value; $value = $meta->meta_value;
$values[] = $value; $values[] = $value;