Giant commit, sorry mailing list people. Move all table names to new $wpdb versions. Works but the whole app needs thorough testing now.
git-svn-id: http://svn.automattic.com/wordpress/trunk@1355 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* generic function for inserting data into the posts table.
|
||||
*/
|
||||
function wp_insert_post($postarr = array()) {
|
||||
global $wpdb, $tableposts, $post_default_category;
|
||||
global $wpdb, $post_default_category;
|
||||
|
||||
// export array as variables
|
||||
extract($postarr);
|
||||
@@ -31,7 +31,7 @@ function wp_insert_post($postarr = array()) {
|
||||
if (empty($post_date_gmt))
|
||||
$post_date_gmt = get_gmt_from_date($post_date);
|
||||
|
||||
$sql = "INSERT INTO $tableposts
|
||||
$sql = "INSERT INTO $wpdb->posts
|
||||
(post_author, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, post_title, post_excerpt, post_category, post_status, post_name)
|
||||
VALUES ('$post_author', '$post_date', '$post_date_gmt', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '$post_excerpt', '$post_cat', '$post_status', '$post_name')";
|
||||
|
||||
@@ -49,9 +49,9 @@ function wp_insert_post($postarr = array()) {
|
||||
}
|
||||
|
||||
function wp_get_single_post($postid = 0, $mode = OBJECT) {
|
||||
global $wpdb, $tableposts;
|
||||
global $wpdb;
|
||||
|
||||
$sql = "SELECT * FROM $tableposts WHERE ID=$postid";
|
||||
$sql = "SELECT * FROM $wpdb->posts WHERE ID=$postid";
|
||||
$result = $wpdb->get_row($sql, $mode);
|
||||
|
||||
// Set categories
|
||||
@@ -61,21 +61,21 @@ function wp_get_single_post($postid = 0, $mode = OBJECT) {
|
||||
}
|
||||
|
||||
function wp_get_recent_posts($num = 10) {
|
||||
global $wpdb, $tableposts;
|
||||
global $wpdb;
|
||||
|
||||
// Set the limit clause, if we got a limit
|
||||
if ($num) {
|
||||
$limit = "LIMIT $num";
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM $tableposts ORDER BY post_date DESC $limit";
|
||||
$sql = "SELECT * FROM $wpdb->posts ORDER BY post_date DESC $limit";
|
||||
$result = $wpdb->get_results($sql,ARRAY_A);
|
||||
|
||||
return $result?$result:array();
|
||||
}
|
||||
|
||||
function wp_update_post($postarr = array()) {
|
||||
global $wpdb, $tableposts;
|
||||
global $wpdb;
|
||||
|
||||
// First get all of the original fields
|
||||
extract(wp_get_single_post($postarr['ID'],ARRAY_A));
|
||||
@@ -96,7 +96,7 @@ function wp_update_post($postarr = array()) {
|
||||
$post_modified = current_time('mysql');
|
||||
$post_modified_gmt = current_time('mysql', 1);
|
||||
|
||||
$sql = "UPDATE $tableposts
|
||||
$sql = "UPDATE $wpdb->posts
|
||||
SET post_content = '$post_content',
|
||||
post_title = '$post_title',
|
||||
post_category = $post_category[0],
|
||||
@@ -118,10 +118,10 @@ function wp_update_post($postarr = array()) {
|
||||
}
|
||||
|
||||
function wp_get_post_cats($blogid = '1', $post_ID = 0) {
|
||||
global $wpdb, $tablepost2cat;
|
||||
global $wpdb;
|
||||
|
||||
$sql = "SELECT category_id
|
||||
FROM $tablepost2cat
|
||||
FROM $wpdb->post2cat
|
||||
WHERE post_id = $post_ID
|
||||
ORDER BY category_id";
|
||||
|
||||
@@ -131,7 +131,7 @@ function wp_get_post_cats($blogid = '1', $post_ID = 0) {
|
||||
}
|
||||
|
||||
function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array()) {
|
||||
global $wpdb, $tablepost2cat;
|
||||
global $wpdb;
|
||||
// If $post_categories isn't already an array, make it one:
|
||||
if (!is_array($post_categories)) {
|
||||
if (!$post_categories) {
|
||||
@@ -145,7 +145,7 @@ function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array(
|
||||
// First the old categories
|
||||
$old_categories = $wpdb->get_col("
|
||||
SELECT category_id
|
||||
FROM $tablepost2cat
|
||||
FROM $wpdb->post2cat
|
||||
WHERE post_id = $post_ID");
|
||||
|
||||
if (!$old_categories) {
|
||||
@@ -168,7 +168,7 @@ function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array(
|
||||
if ($delete_cats) {
|
||||
foreach ($delete_cats as $del) {
|
||||
$wpdb->query("
|
||||
DELETE FROM $tablepost2cat
|
||||
DELETE FROM $wpdb->post2cat
|
||||
WHERE category_id = $del
|
||||
AND post_id = $post_ID
|
||||
");
|
||||
@@ -185,7 +185,7 @@ function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array(
|
||||
if ($add_cats) {
|
||||
foreach ($add_cats as $new_cat) {
|
||||
$wpdb->query("
|
||||
INSERT INTO $tablepost2cat (post_id, category_id)
|
||||
INSERT INTO $wpdb->post2cat (post_id, category_id)
|
||||
VALUES ($post_ID, $new_cat)");
|
||||
|
||||
logio("O","adding post/cat: $post_ID, $new_cat");
|
||||
@@ -194,12 +194,12 @@ function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array(
|
||||
} // wp_set_post_cats()
|
||||
|
||||
function wp_delete_post($postid = 0) {
|
||||
global $wpdb, $tableposts, $tablepost2cat;
|
||||
global $wpdb;
|
||||
|
||||
$sql = "DELETE FROM $tablepost2cat WHERE post_id = $postid";
|
||||
$sql = "DELETE FROM $wpdb->post2cat WHERE post_id = $postid";
|
||||
$wpdb->query($sql);
|
||||
|
||||
$sql = "DELETE FROM $tableposts WHERE ID = $postid";
|
||||
$sql = "DELETE FROM $wpdb->posts WHERE ID = $postid";
|
||||
|
||||
$wpdb->query($sql);
|
||||
|
||||
@@ -215,7 +215,6 @@ function wp_delete_post($postid = 0) {
|
||||
// get permalink from post ID
|
||||
function post_permalink($post_ID=0, $mode = 'id') {
|
||||
global $wpdb;
|
||||
global $tableposts;
|
||||
global $querystring_start, $querystring_equal, $querystring_separator;
|
||||
|
||||
$blog_URL = get_settings('home') .'/'. get_settings('blogfilename');
|
||||
@@ -265,19 +264,19 @@ function post_permalink($post_ID=0, $mode = 'id') {
|
||||
|
||||
// Get the name of a category from its ID
|
||||
function get_cat_name($cat_id) {
|
||||
global $wpdb,$tablecategories;
|
||||
global $wpdb;
|
||||
|
||||
$cat_id -= 0; // force numeric
|
||||
$name = $wpdb->get_var("SELECT cat_name FROM $tablecategories WHERE cat_ID=$cat_id");
|
||||
$name = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE cat_ID=$cat_id");
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
// Get the ID of a category from its name
|
||||
function get_cat_ID($cat_name='General') {
|
||||
global $wpdb,$tablecategories;
|
||||
global $wpdb;
|
||||
|
||||
$cid = $wpdb->get_var("SELECT cat_ID FROM $tablecategories WHERE cat_name='$cat_name'");
|
||||
$cid = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$cat_name'");
|
||||
|
||||
return $cid?$cid:1; // default to cat 1
|
||||
}
|
||||
|
||||
@@ -95,20 +95,20 @@ function get_weekstartend($mysqlstring, $start_of_week) {
|
||||
}
|
||||
|
||||
function get_lastpostdate($timezone = 'server') {
|
||||
global $tableposts, $cache_lastpostdate, $pagenow, $wpdb;
|
||||
global $cache_lastpostdate, $pagenow, $wpdb;
|
||||
$add_seconds_blog = get_settings('gmt_offset') * 3600;
|
||||
$add_seconds_server = date('Z');
|
||||
$now = current_time('mysql', 1);
|
||||
if ( !isset($cache_lastpostdate[$timezone]) ) {
|
||||
switch(strtolower($timezone)) {
|
||||
case 'gmt':
|
||||
$lastpostdate = $wpdb->get_var("SELECT post_date_gmt FROM $tableposts WHERE post_date_gmt <= '$now' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
|
||||
$lastpostdate = $wpdb->get_var("SELECT post_date_gmt FROM $wpdb->posts WHERE post_date_gmt <= '$now' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
|
||||
break;
|
||||
case 'blog':
|
||||
$lastpostdate = $wpdb->get_var("SELECT post_date FROM $tableposts WHERE post_date_gmt <= '$now' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
|
||||
$lastpostdate = $wpdb->get_var("SELECT post_date FROM $wpdb->posts WHERE post_date_gmt <= '$now' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
|
||||
break;
|
||||
case 'server':
|
||||
$lastpostdate = $wpdb->get_var("SELECT DATE_ADD(post_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $tableposts WHERE post_date_gmt <= '$now' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
|
||||
$lastpostdate = $wpdb->get_var("SELECT DATE_ADD(post_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_date_gmt <= '$now' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
|
||||
break;
|
||||
}
|
||||
$cache_lastpostdate[$timezone] = $lastpostdate;
|
||||
@@ -119,20 +119,20 @@ function get_lastpostdate($timezone = 'server') {
|
||||
}
|
||||
|
||||
function get_lastpostmodified($timezone = 'server') {
|
||||
global $tableposts, $cache_lastpostmodified, $pagenow, $wpdb;
|
||||
global $cache_lastpostmodified, $pagenow, $wpdb;
|
||||
$add_seconds_blog = get_settings('gmt_offset') * 3600;
|
||||
$add_seconds_server = date('Z');
|
||||
$now = current_time('mysql', 1);
|
||||
if ( !isset($cache_lastpostmodified[$timezone]) ) {
|
||||
switch(strtolower($timezone)) {
|
||||
case 'gmt':
|
||||
$lastpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $tableposts WHERE post_modified_gmt <= '$now' AND post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
|
||||
$lastpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_modified_gmt <= '$now' AND post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
|
||||
break;
|
||||
case 'blog':
|
||||
$lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $tableposts WHERE post_modified_gmt <= '$now' AND post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
|
||||
$lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_modified_gmt <= '$now' AND post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
|
||||
break;
|
||||
case 'server':
|
||||
$lastpostmodified = $wpdb->get_var("SELECT DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $tableposts WHERE post_modified_gmt <= '$now' AND post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
|
||||
$lastpostmodified = $wpdb->get_var("SELECT DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_modified_gmt <= '$now' AND post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
|
||||
break;
|
||||
}
|
||||
$lastpostdate = get_lastpostdate($timezone);
|
||||
@@ -172,9 +172,9 @@ function get_currentuserinfo() { // a bit like get_userdata(), on steroids
|
||||
}
|
||||
|
||||
function get_userdata($userid) {
|
||||
global $wpdb, $cache_userdata, $tableusers;
|
||||
global $wpdb, $cache_userdata;
|
||||
if ( empty($cache_userdata[$userid]) ) {
|
||||
$user = $wpdb->get_row("SELECT * FROM $tableusers WHERE ID = '$userid'");
|
||||
$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = '$userid'");
|
||||
$user->user_nickname = stripslashes($user->user_nickname);
|
||||
$user->user_firstname = stripslashes($user->user_firstname);
|
||||
$user->user_lastname = stripslashes($user->user_lastname);
|
||||
@@ -187,9 +187,9 @@ function get_userdata($userid) {
|
||||
}
|
||||
|
||||
function get_userdatabylogin($user_login) {
|
||||
global $tableusers, $cache_userdata, $wpdb;
|
||||
global $cache_userdata, $wpdb;
|
||||
if ( empty($cache_userdata["$user_login"]) ) {
|
||||
$user = $wpdb->get_row("SELECT * FROM $tableusers WHERE user_login = '$user_login'");
|
||||
$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login = '$user_login'");
|
||||
$cache_userdata["$user_login"] = $user;
|
||||
} else {
|
||||
$user = $cache_userdata["$user_login"];
|
||||
@@ -198,9 +198,9 @@ function get_userdatabylogin($user_login) {
|
||||
}
|
||||
|
||||
function get_userid($user_login) {
|
||||
global $tableusers, $cache_userdata, $wpdb;
|
||||
global $cache_userdata, $wpdb;
|
||||
if ( empty($cache_userdata["$user_login"]) ) {
|
||||
$user_id = $wpdb->get_var("SELECT ID FROM $tableusers WHERE user_login = '$user_login'");
|
||||
$user_id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$user_login'");
|
||||
|
||||
$cache_userdata["$user_login"] = $user_id;
|
||||
} else {
|
||||
@@ -210,14 +210,14 @@ function get_userid($user_login) {
|
||||
}
|
||||
|
||||
function get_usernumposts($userid) {
|
||||
global $tableposts, $tablecomments, $wpdb;
|
||||
return $wpdb->get_var("SELECT COUNT(*) FROM $tableposts WHERE post_author = '$userid'");
|
||||
global $wpdb;
|
||||
return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '$userid'");
|
||||
}
|
||||
|
||||
// examine a url (supposedly from this blog) and try to
|
||||
// determine the post ID it represents.
|
||||
function url_to_postid($url = '') {
|
||||
global $wpdb, $tableposts;
|
||||
global $wpdb;
|
||||
|
||||
$siteurl = get_settings('home');
|
||||
// Take a link like 'http://example.com/blog/something'
|
||||
@@ -290,7 +290,7 @@ function url_to_postid($url = '') {
|
||||
if ($postname) $where .= " AND post_name = '" . $wpdb->escape($postname) . "' ";
|
||||
|
||||
// Run the query to get the post ID:
|
||||
$id = intval($wpdb->get_var("SELECT ID FROM $tableposts WHERE 1 = 1 " . $where));
|
||||
$id = intval($wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE 1 = 1 " . $where));
|
||||
|
||||
return $id;
|
||||
}
|
||||
@@ -321,8 +321,8 @@ function get_settings($setting) {
|
||||
}
|
||||
|
||||
function get_alloptions() {
|
||||
global $tableoptions, $wpdb;
|
||||
$options = $wpdb->get_results("SELECT option_name, option_value FROM $tableoptions");
|
||||
global $wpdb;
|
||||
$options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options");
|
||||
if ($options) {
|
||||
foreach ($options as $option) {
|
||||
// "When trying to design a foolproof system,
|
||||
@@ -338,11 +338,11 @@ function get_alloptions() {
|
||||
}
|
||||
|
||||
function update_option($option_name, $newvalue) {
|
||||
global $wpdb, $tableoptions, $cache_settings;
|
||||
global $wpdb, $cache_settings;
|
||||
$newvalue = stripslashes($newvalue);
|
||||
$newvalue = trim($newvalue); // I can't think of any situation we wouldn't want to trim
|
||||
$newvalue = $wpdb->escape($newvalue);
|
||||
$wpdb->query("UPDATE $tableoptions SET option_value = '$newvalue' WHERE option_name = '$option_name'");
|
||||
$wpdb->query("UPDATE $wpdb->options SET option_value = '$newvalue' WHERE option_name = '$option_name'");
|
||||
$cache_settings = get_alloptions(); // Re cache settings
|
||||
return true;
|
||||
}
|
||||
@@ -351,11 +351,11 @@ function update_option($option_name, $newvalue) {
|
||||
// thx Alex Stapleton, http://alex.vort-x.net/blog/
|
||||
function add_option($name, $value='') {
|
||||
// Adds an option if it doesn't already exist
|
||||
global $wpdb, $tableoptions;
|
||||
global $wpdb;
|
||||
if(!get_settings($name)) {
|
||||
$name = $wpdb->escape($name);
|
||||
$value = $wpdb->escape($value);
|
||||
$wpdb->query("INSERT INTO $tableoptions (option_name, option_value) VALUES ('$name', '$value')");
|
||||
$wpdb->query("INSERT INTO $wpdb->options (option_name, option_value) VALUES ('$name', '$value')");
|
||||
|
||||
if($wpdb->insert_id) {
|
||||
global $cache_settings;
|
||||
@@ -366,19 +366,19 @@ function add_option($name, $value='') {
|
||||
}
|
||||
|
||||
function delete_option($name) {
|
||||
global $wpdb, $tableoptions, $tableoptiongroup_options;
|
||||
global $wpdb;
|
||||
// Get the ID, if no ID then return
|
||||
$option_id = $wpdb->get_var("SELECT option_id FROM $tableoptions WHERE option_name = '$name'");
|
||||
$option_id = $wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = '$name'");
|
||||
if (!$option_id) return false;
|
||||
$wpdb->query("DELETE FROM $tableoptiongroup_options WHERE option_id = '$option_id'");
|
||||
$wpdb->query("DELETE FROM $tableoptions WHERE option_name = '$name'");
|
||||
$wpdb->query("DELETE FROM $wpdb->optiongroup_options WHERE option_id = '$option_id'");
|
||||
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name = '$name'");
|
||||
return true;
|
||||
}
|
||||
|
||||
function get_postdata($postid) {
|
||||
global $post, $tableposts, $wpdb;
|
||||
global $post, $wpdb;
|
||||
|
||||
$post = $wpdb->get_row("SELECT * FROM $tableposts WHERE ID = '$postid'");
|
||||
$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = '$postid'");
|
||||
|
||||
$postdata = array (
|
||||
'ID' => $post->ID,
|
||||
@@ -402,9 +402,9 @@ function get_postdata($postid) {
|
||||
}
|
||||
|
||||
function get_commentdata($comment_ID,$no_cache=0,$include_unapproved=false) { // less flexible, but saves DB queries
|
||||
global $postc,$id,$commentdata,$tablecomments, $wpdb;
|
||||
global $postc,$id,$commentdata, $wpdb;
|
||||
if ($no_cache) {
|
||||
$query = "SELECT * FROM $tablecomments WHERE comment_ID = '$comment_ID'";
|
||||
$query = "SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_ID'";
|
||||
if (false == $include_unapproved) {
|
||||
$query .= " AND comment_approved = '1'";
|
||||
}
|
||||
@@ -431,9 +431,9 @@ function get_commentdata($comment_ID,$no_cache=0,$include_unapproved=false) { //
|
||||
}
|
||||
|
||||
function get_catname($cat_ID) {
|
||||
global $tablecategories, $cache_catnames, $wpdb;
|
||||
global $cache_catnames, $wpdb;
|
||||
if ( !$cache_catnames ) {
|
||||
$results = $wpdb->get_results("SELECT * FROM $tablecategories") or die('Oops, couldn\'t query the db for categories.');
|
||||
$results = $wpdb->get_results("SELECT * FROM $wpdb->categories") or die('Oops, couldn\'t query the db for categories.');
|
||||
foreach ($results as $post) {
|
||||
$cache_catnames[$post->cat_ID] = $post->cat_name;
|
||||
}
|
||||
@@ -544,7 +544,7 @@ add_action('publish_post', 'generic_ping');
|
||||
|
||||
// Send a Trackback
|
||||
function trackback($trackback_url, $title, $excerpt, $ID) {
|
||||
global $wpdb, $tableposts;
|
||||
global $wpdb;
|
||||
$title = urlencode(stripslashes($title));
|
||||
$excerpt = urlencode(stripslashes($excerpt));
|
||||
$blog_name = urlencode(stripslashes(get_settings('blogname')));
|
||||
@@ -572,8 +572,8 @@ function trackback($trackback_url, $title, $excerpt, $ID) {
|
||||
*/
|
||||
@fclose($fs);
|
||||
|
||||
$wpdb->query("UPDATE $tableposts SET pinged = CONCAT(pinged, '\n', '$tb_url') WHERE ID = '$ID'");
|
||||
$wpdb->query("UPDATE $tableposts SET to_ping = REPLACE(to_ping, '$tb_url', '') WHERE ID = '$ID'");
|
||||
$wpdb->query("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', '$tb_url') WHERE ID = '$ID'");
|
||||
$wpdb->query("UPDATE $wpdb->posts SET to_ping = REPLACE(to_ping, '$tb_url', '') WHERE ID = '$ID'");
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -898,17 +898,17 @@ function pingGeoURL($blog_ID) {
|
||||
returns false on database error or invalid value for $comment_status
|
||||
*/
|
||||
function wp_set_comment_status($comment_id, $comment_status) {
|
||||
global $wpdb, $tablecomments;
|
||||
global $wpdb;
|
||||
|
||||
switch($comment_status) {
|
||||
case 'hold':
|
||||
$query = "UPDATE $tablecomments SET comment_approved='0' WHERE comment_ID='$comment_id' LIMIT 1";
|
||||
$query = "UPDATE $wpdb->comments SET comment_approved='0' WHERE comment_ID='$comment_id' LIMIT 1";
|
||||
break;
|
||||
case 'approve':
|
||||
$query = "UPDATE $tablecomments SET comment_approved='1' WHERE comment_ID='$comment_id' LIMIT 1";
|
||||
$query = "UPDATE $wpdb->comments SET comment_approved='1' WHERE comment_ID='$comment_id' LIMIT 1";
|
||||
break;
|
||||
case 'delete':
|
||||
$query = "DELETE FROM $tablecomments WHERE comment_ID='$comment_id' LIMIT 1";
|
||||
$query = "DELETE FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1";
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
@@ -934,9 +934,9 @@ function wp_set_comment_status($comment_id, $comment_status) {
|
||||
a (boolean) false signals an error
|
||||
*/
|
||||
function wp_get_comment_status($comment_id) {
|
||||
global $wpdb, $tablecomments;
|
||||
global $wpdb;
|
||||
|
||||
$result = $wpdb->get_var("SELECT comment_approved FROM $tablecomments WHERE comment_ID='$comment_id' LIMIT 1");
|
||||
$result = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
|
||||
if ($result == NULL) {
|
||||
return "deleted";
|
||||
} else if ($result == "1") {
|
||||
@@ -949,12 +949,12 @@ function wp_get_comment_status($comment_id) {
|
||||
}
|
||||
|
||||
function wp_notify_postauthor($comment_id, $comment_type='comment') {
|
||||
global $wpdb, $tablecomments, $tableposts, $tableusers;
|
||||
global $wpdb;
|
||||
global $querystring_start, $querystring_equal, $querystring_separator;
|
||||
|
||||
$comment = $wpdb->get_row("SELECT * FROM $tablecomments WHERE comment_ID='$comment_id' LIMIT 1");
|
||||
$post = $wpdb->get_row("SELECT * FROM $tableposts WHERE ID='$comment->comment_post_ID' LIMIT 1");
|
||||
$user = $wpdb->get_row("SELECT * FROM $tableusers WHERE ID='$post->post_author' LIMIT 1");
|
||||
$comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
|
||||
$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1");
|
||||
$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID='$post->post_author' LIMIT 1");
|
||||
|
||||
if ('' == $user->user_email) return false; // If there's no email to send the comment to
|
||||
|
||||
@@ -1009,15 +1009,15 @@ function wp_notify_postauthor($comment_id, $comment_type='comment') {
|
||||
always returns true
|
||||
*/
|
||||
function wp_notify_moderator($comment_id) {
|
||||
global $wpdb, $tablecomments, $tableposts, $tableusers;
|
||||
global $wpdb;
|
||||
global $querystring_start, $querystring_equal, $querystring_separator;
|
||||
|
||||
$comment = $wpdb->get_row("SELECT * FROM $tablecomments WHERE comment_ID='$comment_id' LIMIT 1");
|
||||
$post = $wpdb->get_row("SELECT * FROM $tableposts WHERE ID='$comment->comment_post_ID' LIMIT 1");
|
||||
$user = $wpdb->get_row("SELECT * FROM $tableusers WHERE ID='$post->post_author' LIMIT 1");
|
||||
$comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
|
||||
$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1");
|
||||
$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID='$post->post_author' LIMIT 1");
|
||||
|
||||
$comment_author_domain = gethostbyaddr($comment->comment_author_IP);
|
||||
$comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $tablecomments WHERE comment_approved = '0'");
|
||||
$comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'");
|
||||
|
||||
$notify_message = "A new comment on the post #$comment->comment_post_ID \"".stripslashes($post->post_title)."\" is waiting for your approval\r\n\r\n";
|
||||
$notify_message .= "Author : $comment->comment_author (IP: $comment->comment_author_IP , $comment_author_domain)\r\n";
|
||||
@@ -1316,7 +1316,7 @@ function rewrite_rules($matches = '', $permalink_structure = '') {
|
||||
}
|
||||
|
||||
function get_posts($args) {
|
||||
global $wpdb, $tableposts;
|
||||
global $wpdb;
|
||||
parse_str($args, $r);
|
||||
if (!isset($r['numberposts'])) $r['numberposts'] = 5;
|
||||
if (!isset($r['offset'])) $r['offset'] = 0;
|
||||
@@ -1327,7 +1327,7 @@ function get_posts($args) {
|
||||
|
||||
$now = current_time('mysql');
|
||||
|
||||
$posts = $wpdb->get_results("SELECT DISTINCT * FROM $tableposts WHERE post_date <= '$now' AND (post_status = 'publish') GROUP BY $tableposts.ID ORDER BY post_date DESC LIMIT " . $r['offset'] . ',' . $r['numberposts']);
|
||||
$posts = $wpdb->get_results("SELECT DISTINCT * FROM $wpdb->posts WHERE post_date <= '$now' AND (post_status = 'publish') GROUP BY $wpdb->posts.ID ORDER BY post_date DESC LIMIT " . $r['offset'] . ',' . $r['numberposts']);
|
||||
|
||||
return $posts;
|
||||
}
|
||||
@@ -1354,7 +1354,7 @@ function check_comment($author, $email, $url, $comment, $user_ip) {
|
||||
}
|
||||
|
||||
function query_posts($query) {
|
||||
global $wpdb, $tablepost2cat, $tableposts, $tablecategories, $tableusers,
|
||||
global $wpdb,
|
||||
$pagenow;
|
||||
|
||||
parse_str($query);
|
||||
@@ -1485,7 +1485,7 @@ function query_posts($query) {
|
||||
$eq = '=';
|
||||
$andor = 'OR';
|
||||
}
|
||||
$join = " LEFT JOIN $tablepost2cat ON ($tableposts.ID = $tablepost2cat.post_id) ";
|
||||
$join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) ";
|
||||
$cat_array = explode(' ',$cat);
|
||||
$whichcat .= ' AND (category_id '.$eq.' '.intval($cat_array[0]);
|
||||
$whichcat .= get_category_children($cat_array[0], ' '.$andor.' category_id '.$eq.' ');
|
||||
@@ -1511,10 +1511,10 @@ function query_posts($query) {
|
||||
}
|
||||
}
|
||||
$category_name = preg_replace('|[^a-z0-9-_]|i', '', $category_name);
|
||||
$tables = ", $tablepost2cat, $tablecategories";
|
||||
$join = " LEFT JOIN $tablepost2cat ON ($tableposts.ID = $tablepost2cat.post_id) LEFT JOIN $tablecategories ON ($tablepost2cat.category_id = $tablecategories.cat_ID) ";
|
||||
$tables = ", $wpdb->post2cat, $wpdb->categories";
|
||||
$join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) LEFT JOIN $wpdb->categories ON ($wpdb->post2cat.category_id = $wpdb->categories.cat_ID) ";
|
||||
$whichcat = " AND (category_nicename = '$category_name'";
|
||||
$cat = $wpdb->get_var("SELECT cat_ID FROM $tablecategories WHERE category_nicename = '$category_name'");
|
||||
$cat = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$category_name'");
|
||||
$whichcat .= get_category_children($cat, " OR category_id = ");
|
||||
$whichcat .= ")";
|
||||
}
|
||||
@@ -1555,7 +1555,7 @@ function query_posts($query) {
|
||||
}
|
||||
}
|
||||
$author_name = preg_replace('|[^a-z0-9-_]|', '', strtolower($author_name));
|
||||
$author = $wpdb->get_var("SELECT ID FROM $tableusers WHERE user_nicename='".$author_name."'");
|
||||
$author = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_nicename='".$author_name."'");
|
||||
$whichauthor .= ' AND (post_author = '.intval($author).')';
|
||||
}
|
||||
|
||||
@@ -1662,8 +1662,8 @@ function query_posts($query) {
|
||||
$where .= " OR post_author = $user_ID AND post_status != 'draft')";
|
||||
else
|
||||
$where .= ')';
|
||||
$where .= " GROUP BY $tableposts.ID";
|
||||
$request = " SELECT $distinct * FROM $tableposts $join WHERE 1=1".$where." ORDER BY post_$orderby $limits";
|
||||
$where .= " GROUP BY $wpdb->posts.ID";
|
||||
$request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1".$where." ORDER BY post_$orderby $limits";
|
||||
|
||||
|
||||
if ($preview) {
|
||||
@@ -1682,8 +1682,7 @@ function query_posts($query) {
|
||||
|
||||
function update_post_caches($posts) {
|
||||
global $category_cache, $comment_count_cache, $post_meta_cache;
|
||||
global $tablecategories, $tablepost2cat, $tableposts, $tablecomments,
|
||||
$tablepostmeta, $wpdb;
|
||||
global $wpdb;
|
||||
|
||||
// No point in doing all this work if we didn't match any posts.
|
||||
if (! $posts) {
|
||||
@@ -1698,7 +1697,7 @@ function update_post_caches($posts) {
|
||||
|
||||
$dogs = $wpdb->get_results("SELECT DISTINCT
|
||||
ID, category_id, cat_name, category_nicename, category_description, category_parent
|
||||
FROM $tablecategories, $tablepost2cat, $tableposts
|
||||
FROM $wpdb->categories, $wpdb->post2cat, $wpdb->posts
|
||||
WHERE category_id = cat_ID AND post_id = ID AND post_id IN ($post_id_list)");
|
||||
|
||||
foreach ($dogs as $catt) {
|
||||
@@ -1707,8 +1706,8 @@ function update_post_caches($posts) {
|
||||
|
||||
// Do the same for comment numbers
|
||||
$comment_counts = $wpdb->get_results("SELECT ID, COUNT( comment_ID ) AS ccount
|
||||
FROM $tableposts
|
||||
LEFT JOIN $tablecomments ON ( comment_post_ID = ID AND comment_approved = '1')
|
||||
FROM $wpdb->posts
|
||||
LEFT JOIN $wpdb->comments ON ( comment_post_ID = ID AND comment_approved = '1')
|
||||
WHERE post_status = 'publish' AND ID IN ($post_id_list)
|
||||
GROUP BY ID");
|
||||
|
||||
@@ -1721,7 +1720,7 @@ function update_post_caches($posts) {
|
||||
// Get post-meta info
|
||||
if ( $meta_list = $wpdb->get_results("
|
||||
SELECT post_id,meta_key,meta_value
|
||||
FROM $tablepostmeta
|
||||
FROM $wpdb->postmeta
|
||||
WHERE post_id IN($post_id_list)
|
||||
ORDER BY post_id,meta_key
|
||||
", ARRAY_A) ) {
|
||||
@@ -1746,17 +1745,17 @@ function update_post_caches($posts) {
|
||||
}
|
||||
|
||||
function update_category_cache() {
|
||||
global $cache_categories, $tablecategories, $wpdb;
|
||||
$dogs = $wpdb->get_results("SELECT * FROM $tablecategories WHERE 1=1");
|
||||
global $cache_categories, $wpdb;
|
||||
$dogs = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE 1=1");
|
||||
foreach ($dogs as $catt) {
|
||||
$cache_categories[$catt->cat_ID] = $catt;
|
||||
}
|
||||
}
|
||||
|
||||
function update_user_cache() {
|
||||
global $cache_userdata, $tableusers, $wpdb;
|
||||
global $cache_userdata, $wpdb;
|
||||
|
||||
$users = $wpdb->get_results("SELECT * FROM $tableusers WHERE user_level > 0");
|
||||
$users = $wpdb->get_results("SELECT * FROM $wpdb->users WHERE user_level > 0");
|
||||
foreach ($users as $user) {
|
||||
$cache_userdata[$user->ID] = $user;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ $all_links = array();
|
||||
** the db) the ones which have been updated (on weblogs.com).
|
||||
**/
|
||||
function preload_links() {
|
||||
global $tablelinks, $all_links, $wpdb;
|
||||
$links = $wpdb->get_results("SELECT link_id, link_url FROM $tablelinks WHERE link_visible = 'Y' AND link_url <> ''");
|
||||
global $all_links, $wpdb;
|
||||
$links = $wpdb->get_results("SELECT link_id, link_url FROM $wpdb->links WHERE link_visible = 'Y' AND link_url <> ''");
|
||||
foreach ($links as $link) {
|
||||
$link_url = transform_url($link->link_url);
|
||||
$all_links[$link_url] = array($link->link_id, 0);
|
||||
@@ -32,11 +32,11 @@ function preload_links() {
|
||||
** Update in the db the links which have been updated ($all_links[url][1] != 0)
|
||||
**/
|
||||
function update_links() {
|
||||
global $tablelinks, $all_links, $wpdb;
|
||||
global $all_links, $wpdb;
|
||||
reset($all_links);
|
||||
while (list($id, $val) = each($all_links)) {
|
||||
if ($val[1]) {
|
||||
$wpdb->query("UPDATE $tablelinks SET link_updated = '$val[1]' WHERE link_id = $val[0]");
|
||||
$wpdb->query("UPDATE $wpdb->links SET link_updated = '$val[1]' WHERE link_id = $val[0]");
|
||||
}
|
||||
} // end while
|
||||
}
|
||||
|
||||
@@ -26,9 +26,9 @@ function get_linksbyname($cat_name = "noname", $before = '', $after = '<br />',
|
||||
$between = " ", $show_images = true, $orderby = 'id',
|
||||
$show_description = true, $show_rating = false,
|
||||
$limit = -1, $show_updated = 0) {
|
||||
global $tablelinkcategories, $wpdb;
|
||||
global $wpdb;
|
||||
$cat_id = -1;
|
||||
$results = $wpdb->get_results("SELECT cat_id FROM $tablelinkcategories WHERE cat_name='$cat_name'");
|
||||
$results = $wpdb->get_results("SELECT cat_id FROM $wpdb->linkcategories WHERE cat_name='$cat_name'");
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
$cat_id = $result->cat_id;
|
||||
@@ -49,11 +49,11 @@ function bool_from_yn($yn) {
|
||||
** category (no default) - The category to use.
|
||||
**/
|
||||
function wp_get_linksbyname($category) {
|
||||
global $wpdb, $tablelinkcategories;
|
||||
global $wpdb;
|
||||
|
||||
$cat = $wpdb->get_row("SELECT cat_id, cat_name, auto_toggle, show_images, show_description, "
|
||||
. " show_rating, show_updated, sort_order, sort_desc, text_before_link, text_after_link, "
|
||||
. " text_after_all, list_limit FROM $tablelinkcategories WHERE cat_name='$category'");
|
||||
. " text_after_all, list_limit FROM $wpdb->linkcategories WHERE cat_name='$category'");
|
||||
if ($cat) {
|
||||
if ($cat->sort_desc == 'Y') {
|
||||
$cat->sort_order = '_'.$cat->sort_order;
|
||||
@@ -71,11 +71,11 @@ function wp_get_linksbyname($category) {
|
||||
** category (no default) - The category to use.
|
||||
**/
|
||||
function wp_get_links($category) {
|
||||
global $wpdb, $tablelinkcategories;
|
||||
global $wpdb;
|
||||
|
||||
$cat = $wpdb->get_row("SELECT cat_id, cat_name, auto_toggle, show_images, show_description, "
|
||||
. " show_rating, show_updated, sort_order, sort_desc, text_before_link, text_after_link, "
|
||||
. " text_after_all, list_limit FROM $tablelinkcategories WHERE cat_id=$category");
|
||||
. " text_after_all, list_limit FROM $wpdb->linkcategories WHERE cat_id=$category");
|
||||
if ($cat) {
|
||||
if ($cat->sort_desc == 'Y') {
|
||||
$cat->sort_order = '_'.$cat->sort_order;
|
||||
@@ -114,7 +114,7 @@ function get_links($category = -1, $before = '', $after = '<br />',
|
||||
$show_description = true, $show_rating = false,
|
||||
$limit = -1, $show_updated = 1, $echo = true) {
|
||||
|
||||
global $tablelinks, $wpdb;
|
||||
global $wpdb;
|
||||
|
||||
$direction = ' ASC';
|
||||
$category_query = "";
|
||||
@@ -155,7 +155,7 @@ function get_links($category = -1, $before = '', $after = '<br />',
|
||||
|
||||
$sql = "SELECT link_url, link_name, link_image, link_target,
|
||||
link_description, link_rating, link_rel $length $recently_updated_test $get_updated
|
||||
FROM $tablelinks
|
||||
FROM $wpdb->links
|
||||
WHERE link_visible = 'Y' " .
|
||||
$category_query;
|
||||
$sql .= ' ORDER BY ' . $orderby;
|
||||
@@ -277,9 +277,9 @@ function get_links($category = -1, $before = '', $after = '<br />',
|
||||
** }
|
||||
**/
|
||||
function get_linkobjectsbyname($cat_name = "noname" , $orderby = 'name', $limit = -1) {
|
||||
global $tablelinkcategories, $wpdb;
|
||||
global $wpdb;
|
||||
$cat_id = -1;
|
||||
$results = $wpdb->get_results("SELECT cat_id FROM $tablelinkcategories WHERE cat_name='$cat_name'");
|
||||
$results = $wpdb->get_results("SELECT cat_id FROM $wpdb->linkcategories WHERE cat_name='$cat_name'");
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
$cat_id = $result->cat_id;
|
||||
@@ -324,9 +324,9 @@ function get_linkobjectsbyname($cat_name = "noname" , $orderby = 'name', $limit
|
||||
** link_notes
|
||||
**/
|
||||
function get_linkobjects($category = -1, $orderby = 'name', $limit = -1) {
|
||||
global $tablelinks, $wpdb;
|
||||
global $wpdb;
|
||||
|
||||
$sql = "SELECT * FROM $tablelinks WHERE link_visible = 'Y'";
|
||||
$sql = "SELECT * FROM $wpdb->links WHERE link_visible = 'Y'";
|
||||
if ($category != -1) {
|
||||
$sql .= " AND link_category = $category ";
|
||||
}
|
||||
@@ -459,10 +459,10 @@ function get_links_withrating($category = -1, $before = '', $after = '<br />',
|
||||
** uses 0
|
||||
*/
|
||||
function get_linkcatname($id = 0) {
|
||||
global $tablelinkcategories, $wpdb;
|
||||
global $wpdb;
|
||||
$cat_name = '';
|
||||
if ('' != $id) {
|
||||
$cat_name = $wpdb->get_var("SELECT cat_name FROM $tablelinkcategories WHERE cat_id=$id");
|
||||
$cat_name = $wpdb->get_var("SELECT cat_name FROM $wpdb->linkcategories WHERE cat_id=$id");
|
||||
}
|
||||
return stripslashes($cat_name);
|
||||
}
|
||||
@@ -473,8 +473,8 @@ function get_linkcatname($id = 0) {
|
||||
** uses 0
|
||||
*/
|
||||
function get_autotoggle($id = 0) {
|
||||
global $tablelinkcategories, $wpdb;
|
||||
$auto_toggle = $wpdb->get_var("SELECT auto_toggle FROM $tablelinkcategories WHERE cat_id=$id");
|
||||
global $wpdb;
|
||||
$auto_toggle = $wpdb->get_var("SELECT auto_toggle FROM $wpdb->linkcategories WHERE cat_id=$id");
|
||||
if ('' == $auto_toggle)
|
||||
$auto_toggle = 'N';
|
||||
return $auto_toggle;
|
||||
@@ -492,9 +492,8 @@ function get_autotoggle($id = 0) {
|
||||
*/
|
||||
function links_popup_script($text = 'Links', $width=400, $height=400,
|
||||
$file='links.all.php', $count = true) {
|
||||
global $tablelinks;
|
||||
if ($count == true) {
|
||||
$counts = $wpdb->get_var("SELECT count(*) FROM $tablelinks");
|
||||
$counts = $wpdb->get_var("SELECT count(*) FROM $wpdb->links");
|
||||
}
|
||||
|
||||
$javascript = "<a href=\"#\" " .
|
||||
@@ -518,7 +517,7 @@ function links_popup_script($text = 'Links', $width=400, $height=400,
|
||||
* added by Dougal
|
||||
*
|
||||
* Output a list of all links, listed by category, using the
|
||||
* settings in $tablelinkcategories and output it as a nested
|
||||
* settings in $wpdb->linkcategories and output it as a nested
|
||||
* HTML unordered list.
|
||||
*
|
||||
* Parameters:
|
||||
@@ -526,7 +525,7 @@ function links_popup_script($text = 'Links', $width=400, $height=400,
|
||||
* hide_if_empty (default true) - Supress listing empty link categories
|
||||
*/
|
||||
function get_links_list($order = 'name', $hide_if_empty = 'obsolete') {
|
||||
global $tablelinkcategories, $tablelinks, $wpdb;
|
||||
global $wpdb;
|
||||
|
||||
$order = strtolower($order);
|
||||
|
||||
@@ -545,8 +544,8 @@ function get_links_list($order = 'name', $hide_if_empty = 'obsolete') {
|
||||
SELECT DISTINCT link_category, cat_name, show_images,
|
||||
show_description, show_rating, show_updated, sort_order,
|
||||
sort_desc, list_limit
|
||||
FROM `$tablelinks`
|
||||
LEFT JOIN `$tablelinkcategories` ON (link_category = cat_id)
|
||||
FROM `$wpdb->links`
|
||||
LEFT JOIN `$wpdb->linkcategories` ON (link_category = cat_id)
|
||||
WHERE link_visible = 'Y'
|
||||
AND list_limit <> 0
|
||||
ORDER BY $cat_order $direction ", ARRAY_A);
|
||||
|
||||
@@ -77,7 +77,7 @@ function the_author_posts_link($idmode='') {
|
||||
|
||||
|
||||
function get_author_link($echo = false, $author_id, $author_nicename) {
|
||||
global $wpdb, $tableusers, $post, $querystring_start, $querystring_equal, $cache_userdata;
|
||||
global $wpdb, $post, $querystring_start, $querystring_equal, $cache_userdata;
|
||||
$auth_ID = $author_id;
|
||||
$permalink_structure = get_settings('permalink_structure');
|
||||
|
||||
@@ -126,9 +126,9 @@ function wp_list_authors($args = '') {
|
||||
}
|
||||
|
||||
function list_authors($optioncount = false, $exclude_admin = true, $show_fullname = false, $hide_empty = true, $feed = '', $feed_image = '') {
|
||||
global $tableusers, $wpdb, $blogfilename;
|
||||
global $wpdb, $blogfilename;
|
||||
|
||||
$query = "SELECT ID, user_nickname, user_firstname, user_lastname, user_nicename from $tableusers " . ($exclude_admin ? "WHERE user_nickname <> 'admin' " : '') . "ORDER BY user_nickname";
|
||||
$query = "SELECT ID, user_nickname, user_firstname, user_lastname, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_nickname <> 'admin' " : '') . "ORDER BY user_nickname";
|
||||
$authors = $wpdb->get_results($query);
|
||||
|
||||
foreach($authors as $author) {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<?php
|
||||
|
||||
function get_the_category() {
|
||||
global $post, $tablecategories, $tablepost2cat, $wpdb, $category_cache;
|
||||
global $post, $wpdb, $category_cache;
|
||||
if ($category_cache[$post->ID]) {
|
||||
return $category_cache[$post->ID];
|
||||
} else {
|
||||
$categories = $wpdb->get_results("
|
||||
SELECT category_id, cat_name, category_nicename, category_description, category_parent
|
||||
FROM $tablecategories, $tablepost2cat
|
||||
WHERE $tablepost2cat.category_id = cat_ID AND $tablepost2cat.post_id = $post->ID
|
||||
FROM $wpdb->categories, $wpdb->post2cat
|
||||
WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = $post->ID
|
||||
");
|
||||
|
||||
return $categories;
|
||||
@@ -16,7 +16,7 @@ function get_the_category() {
|
||||
}
|
||||
|
||||
function get_category_link($echo = false, $category_id, $category_nicename) {
|
||||
global $wpdb, $tablecategories, $post, $querystring_start, $querystring_equal, $cache_categories;
|
||||
global $wpdb, $post, $querystring_start, $querystring_equal, $cache_categories;
|
||||
$cat_ID = $category_id;
|
||||
$permalink_structure = get_settings('permalink_structure');
|
||||
|
||||
@@ -123,9 +123,9 @@ function the_category_rss($type = 'rss') {
|
||||
}
|
||||
|
||||
function get_the_category_by_ID($cat_ID) {
|
||||
global $tablecategories, $cache_categories, $wpdb;
|
||||
global $cache_categories, $wpdb;
|
||||
if ( !$cache_categories[$cat_ID] ) {
|
||||
$cat_name = $wpdb->get_var("SELECT cat_name FROM $tablecategories WHERE cat_ID = '$cat_ID'");
|
||||
$cat_name = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE cat_ID = '$cat_ID'");
|
||||
$cache_categories[$cat_ID]->cat_name = $cat_name;
|
||||
} else {
|
||||
$cat_name = $cache_categories[$cat_ID]->cat_name;
|
||||
@@ -134,8 +134,8 @@ function get_the_category_by_ID($cat_ID) {
|
||||
}
|
||||
|
||||
function get_category_parents($id, $link = FALSE, $separator = '/', $nicename = FALSE){
|
||||
global $tablecategories, $cache_categories;
|
||||
$chain = "";
|
||||
global $cache_categories;
|
||||
$chain = '';
|
||||
$parent = $cache_categories[$id];
|
||||
if ($nicename) {
|
||||
$name = $parent->category_nicename;
|
||||
@@ -152,7 +152,7 @@ function get_category_parents($id, $link = FALSE, $separator = '/', $nicename =
|
||||
}
|
||||
|
||||
function get_category_children($id, $before = '/', $after = '') {
|
||||
global $tablecategories, $cache_categories;
|
||||
global $cache_categories;
|
||||
$c_cache = $cache_categories; // Can't do recursive foreach on a global, have to make a copy
|
||||
$chain = '';
|
||||
foreach ($c_cache as $category){
|
||||
@@ -184,7 +184,7 @@ function the_category_head($before='', $after='') {
|
||||
}
|
||||
|
||||
function category_description($category = 0) {
|
||||
global $cat, $wpdb, $tablecategories, $cache_categories;
|
||||
global $cat, $wpdb, $cache_categories;
|
||||
if (!$category) $category = $cat;
|
||||
$category_description = $cache_categories[$category]->category_description;
|
||||
$category_description = apply_filters('category_description', $category_description);
|
||||
@@ -195,7 +195,7 @@ function category_description($category = 0) {
|
||||
function dropdown_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc',
|
||||
$optiondates = 0, $optioncount = 0, $hide_empty = 1, $optionnone=FALSE,
|
||||
$selected=0, $hide=0) {
|
||||
global $tablecategories, $tableposts, $tablepost2cat, $wpdb;
|
||||
global $wpdb;
|
||||
global $querystring_start, $querystring_equal, $querystring_separator;
|
||||
if (($file == 'blah') || ($file == '')) $file = get_settings('home') . '/' . get_settings('blogfilename');
|
||||
if (!$selected) $selected=$cat;
|
||||
@@ -203,10 +203,10 @@ function dropdown_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_
|
||||
|
||||
$query = "
|
||||
SELECT cat_ID, cat_name, category_nicename,category_parent,
|
||||
COUNT($tablepost2cat.post_id) AS cat_count,
|
||||
COUNT($wpdb->post2cat.post_id) AS cat_count,
|
||||
DAYOFMONTH(MAX(post_date)) AS lastday, MONTH(MAX(post_date)) AS lastmonth
|
||||
FROM $tablecategories LEFT JOIN $tablepost2cat ON (cat_ID = category_id)
|
||||
LEFT JOIN $tableposts ON (ID = post_id)
|
||||
FROM $wpdb->categories LEFT JOIN $wpdb->post2cat ON (cat_ID = category_id)
|
||||
LEFT JOIN $wpdb->posts ON (ID = post_id)
|
||||
WHERE cat_ID > 0
|
||||
";
|
||||
if ($hide) {
|
||||
@@ -265,7 +265,7 @@ function wp_list_cats($args = '') {
|
||||
}
|
||||
|
||||
function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = '', $list = true, $optiondates = 0, $optioncount = 0, $hide_empty = 1, $use_desc_for_title = 1, $children=FALSE, $child_of=0, $categories=0, $recurse=0, $feed = '', $feed_image = '', $exclude = '') {
|
||||
global $tablecategories, $tableposts, $tablepost2cat, $wpdb, $category_posts;
|
||||
global $wpdb, $category_posts;
|
||||
global $querystring_start, $querystring_equal, $querystring_separator;
|
||||
// Optiondates now works
|
||||
if ('' == $file) {
|
||||
@@ -287,7 +287,7 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde
|
||||
|
||||
$query = "
|
||||
SELECT cat_ID, cat_name, category_nicename, category_description, category_parent
|
||||
FROM $tablecategories
|
||||
FROM $wpdb->categories
|
||||
WHERE cat_ID > 0 $exclusions
|
||||
ORDER BY $sort_column $sort_order";
|
||||
|
||||
@@ -295,10 +295,10 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde
|
||||
}
|
||||
if (!count($category_posts)) {
|
||||
$cat_counts = $wpdb->get_results(" SELECT cat_ID,
|
||||
COUNT($tablepost2cat.post_id) AS cat_count
|
||||
FROM $tablecategories
|
||||
INNER JOIN $tablepost2cat ON (cat_ID = category_id)
|
||||
INNER JOIN $tableposts ON (ID = post_id)
|
||||
COUNT($wpdb->post2cat.post_id) AS cat_count
|
||||
FROM $wpdb->categories
|
||||
INNER JOIN $wpdb->post2cat ON (cat_ID = category_id)
|
||||
INNER JOIN $wpdb->posts ON (ID = post_id)
|
||||
WHERE post_status = 'publish' $exclusions
|
||||
GROUP BY category_id");
|
||||
foreach ($cat_counts as $cat_count) {
|
||||
@@ -311,9 +311,9 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde
|
||||
if (intval($optiondates) == 1) {
|
||||
$cat_dates = $wpdb->get_results(" SELECT cat_ID,
|
||||
DAYOFMONTH(MAX(post_date)) AS lastday, MONTH(MAX(post_date)) AS lastmonth
|
||||
FROM $tablecategories
|
||||
LEFT JOIN $tablepost2cat ON (cat_ID = category_id)
|
||||
LEFT JOIN $tableposts ON (ID = post_id)
|
||||
FROM $wpdb->categories
|
||||
LEFT JOIN $wpdb->post2cat ON (cat_ID = category_id)
|
||||
LEFT JOIN $wpdb->posts ON (ID = post_id)
|
||||
WHERE post_status = 'publish' $exclusions
|
||||
GROUP BY category_id");
|
||||
foreach ($cat_dates as $cat_date) {
|
||||
|
||||
@@ -26,8 +26,8 @@ function clean_url($url) {
|
||||
}
|
||||
|
||||
function comments_number($zero='No Comments', $one='1 Comment', $more='% Comments', $number='') {
|
||||
global $id, $comment, $tablecomments, $wpdb, $comment_count_cache;
|
||||
if ('' == $comment_count_cache["$id"]) $number = $wpdb->get_var("SELECT COUNT(*) FROM $tablecomments WHERE comment_post_ID = $id AND comment_approved = '1'");
|
||||
global $id, $comment, $wpdb, $comment_count_cache;
|
||||
if ('' == $comment_count_cache["$id"]) $number = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved = '1'");
|
||||
else $number = $comment_count_cache["$id"];
|
||||
if ($number == 0) {
|
||||
$blah = $zero;
|
||||
@@ -56,12 +56,12 @@ function comments_popup_script($width=400, $height=400, $file='wp-comments-popup
|
||||
}
|
||||
|
||||
function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') {
|
||||
global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post, $wpdb, $tablecomments, $cookiehash;
|
||||
global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post, $wpdb, $cookiehash;
|
||||
global $querystring_start, $querystring_equal, $querystring_separator;
|
||||
global $comment_count_cache, $single;
|
||||
if (!$single) {
|
||||
if ('' == $comment_count_cache["$id"]) {
|
||||
$number = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $tablecomments WHERE comment_post_ID = $id AND comment_approved = '1';");
|
||||
$number = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved = '1';");
|
||||
} else {
|
||||
$number = $comment_count_cache["$id"];
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ function get_bloginfo($show='') {
|
||||
}
|
||||
|
||||
function wp_title($sep = '»', $display = true) {
|
||||
global $wpdb, $tableposts, $tablecategories;
|
||||
global $wpdb;
|
||||
global $year, $monthnum, $day, $cat, $p, $name, $month, $posts, $single;
|
||||
|
||||
// If there's a category
|
||||
@@ -101,7 +101,7 @@ function wp_title($sep = '»', $display = true) {
|
||||
}
|
||||
}
|
||||
if (!empty($category_name)) {
|
||||
$title = stripslashes($wpdb->get_var("SELECT cat_name FROM $tablecategories WHERE category_nicename = '$category_name'"));
|
||||
$title = stripslashes($wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE category_nicename = '$category_name'"));
|
||||
}
|
||||
|
||||
// If there's a month
|
||||
@@ -136,10 +136,10 @@ function wp_title($sep = '»', $display = true) {
|
||||
}
|
||||
|
||||
function single_post_title($prefix = '', $display = true) {
|
||||
global $p, $name, $wpdb, $tableposts;
|
||||
global $p, $name, $wpdb;
|
||||
if (intval($p) || '' != $name) {
|
||||
if (!$p) {
|
||||
$p = $wpdb->get_var("SELECT ID FROM $tableposts WHERE post_name = '$name'");
|
||||
$p = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '$name'");
|
||||
}
|
||||
$post_data = get_postdata($p);
|
||||
$title = $post_data['Title'];
|
||||
@@ -202,7 +202,6 @@ function wp_get_archives($args = '') {
|
||||
}
|
||||
|
||||
function get_archives($type='', $limit='', $format='html', $before = '', $after = '', $show_post_count = false) {
|
||||
global $tableposts;
|
||||
global $querystring_start, $querystring_equal, $querystring_separator, $month, $wpdb;
|
||||
|
||||
if ('' == $type) {
|
||||
@@ -243,7 +242,7 @@ function get_archives($type='', $limit='', $format='html', $before = '', $after
|
||||
$now = current_time('mysql');
|
||||
|
||||
if ('monthly' == $type) {
|
||||
$arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $tableposts WHERE post_date < '$now' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" . $limit);
|
||||
$arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" . $limit);
|
||||
if ($arcresults) {
|
||||
$afterafter = $after;
|
||||
foreach ($arcresults as $arcresult) {
|
||||
@@ -258,7 +257,7 @@ function get_archives($type='', $limit='', $format='html', $before = '', $after
|
||||
}
|
||||
}
|
||||
} elseif ('daily' == $type) {
|
||||
$arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth` FROM $tableposts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
|
||||
$arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth` FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
|
||||
if ($arcresults) {
|
||||
foreach ($arcresults as $arcresult) {
|
||||
$url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
|
||||
@@ -269,7 +268,7 @@ function get_archives($type='', $limit='', $format='html', $before = '', $after
|
||||
}
|
||||
} elseif ('weekly' == $type) {
|
||||
$start_of_week = get_settings('start_of_week');
|
||||
$arcresults = $wpdb->get_results("SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd FROM $tableposts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
|
||||
$arcresults = $wpdb->get_results("SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
|
||||
$arc_w_last = '';
|
||||
if ($arcresults) {
|
||||
foreach ($arcresults as $arcresult) {
|
||||
@@ -288,7 +287,7 @@ function get_archives($type='', $limit='', $format='html', $before = '', $after
|
||||
}
|
||||
}
|
||||
} elseif ('postbypost' == $type) {
|
||||
$arcresults = $wpdb->get_results("SELECT ID, post_date, post_title FROM $tableposts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
|
||||
$arcresults = $wpdb->get_results("SELECT ID, post_date, post_title FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
|
||||
if ($arcresults) {
|
||||
foreach ($arcresults as $arcresult) {
|
||||
if ($arcresult->post_date != '0000-00-00 00:00:00') {
|
||||
@@ -307,11 +306,11 @@ function get_archives($type='', $limit='', $format='html', $before = '', $after
|
||||
}
|
||||
|
||||
function get_calendar($daylength = 1) {
|
||||
global $wpdb, $m, $monthnum, $year, $timedifference, $month, $month_abbrev, $weekday, $weekday_initial, $weekday_abbrev, $tableposts, $posts;
|
||||
global $wpdb, $m, $monthnum, $year, $timedifference, $month, $month_abbrev, $weekday, $weekday_initial, $weekday_abbrev, $posts;
|
||||
|
||||
// Quick check. If we have no posts at all, abort!
|
||||
if (!$posts) {
|
||||
$gotsome = $wpdb->get_var("SELECT ID from $tableposts WHERE post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
|
||||
$gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
|
||||
if (!$gotsome)
|
||||
return;
|
||||
}
|
||||
@@ -349,13 +348,13 @@ function get_calendar($daylength = 1) {
|
||||
|
||||
// Get the next and previous month and year with at least one post
|
||||
$previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
|
||||
FROM $tableposts
|
||||
FROM $wpdb->posts
|
||||
WHERE post_date < '$thisyear-$thismonth-01'
|
||||
AND post_status = 'publish'
|
||||
ORDER BY post_date DESC
|
||||
LIMIT 1");
|
||||
$next = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
|
||||
FROM $tableposts
|
||||
FROM $wpdb->posts
|
||||
WHERE post_date > '$thisyear-$thismonth-01'
|
||||
AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
|
||||
AND post_status = 'publish'
|
||||
@@ -409,7 +408,7 @@ function get_calendar($daylength = 1) {
|
||||
|
||||
// Get days with posts
|
||||
$dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
|
||||
FROM $tableposts WHERE MONTH(post_date) = $thismonth
|
||||
FROM $wpdb->posts WHERE MONTH(post_date) = $thismonth
|
||||
AND YEAR(post_date) = $thisyear
|
||||
AND post_status = 'publish'
|
||||
AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
|
||||
@@ -433,7 +432,7 @@ function get_calendar($daylength = 1) {
|
||||
|
||||
$ak_titles_for_day = array();
|
||||
$ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom "
|
||||
."FROM $tableposts "
|
||||
."FROM $wpdb->posts "
|
||||
."WHERE YEAR(post_date) = '$thisyear' "
|
||||
."AND MONTH(post_date) = '$thismonth' "
|
||||
."AND post_date < '".current_time('mysql')."' "
|
||||
|
||||
@@ -27,7 +27,7 @@ function permalink_single_rss($file = '') {
|
||||
}
|
||||
|
||||
function get_permalink($id=false) {
|
||||
global $post, $wpdb, $tableposts;
|
||||
global $post, $wpdb;
|
||||
global $querystring_start, $querystring_equal;
|
||||
|
||||
$rewritecode = array(
|
||||
@@ -58,7 +58,7 @@ function get_permalink($id=false) {
|
||||
return get_settings('home') . '/' . get_settings('blogfilename').$querystring_start.'p'.$querystring_equal.$post->ID;
|
||||
}
|
||||
} else { // if an ID is given
|
||||
$idpost = $wpdb->get_row("SELECT post_date, post_name FROM $tableposts WHERE ID = $id");
|
||||
$idpost = $wpdb->get_row("SELECT post_date, post_name FROM $wpdb->posts WHERE ID = $id");
|
||||
if ('' != get_settings('permalink_structure')) {
|
||||
$unixtime = strtotime($idpost->post_date);
|
||||
$rewritereplace = array(
|
||||
|
||||
@@ -275,7 +275,7 @@ function link_pages($before='<br />', $after='<br />', $next_or_number='number',
|
||||
|
||||
|
||||
function previous_post($format='%', $previous='previous post: ', $title='yes', $in_same_cat='no', $limitprev=1, $excluded_categories='') {
|
||||
global $tableposts, $id, $post, $wpdb;
|
||||
global $id, $post, $wpdb;
|
||||
global $p, $posts, $posts_per_page, $s, $single;
|
||||
global $querystring_start, $querystring_equal, $querystring_separator;
|
||||
|
||||
@@ -299,7 +299,7 @@ function previous_post($format='%', $previous='previous post: ', $title='yes', $
|
||||
}
|
||||
|
||||
$limitprev--;
|
||||
$lastpost = @$wpdb->get_row("SELECT ID, post_title FROM $tableposts WHERE post_date < '$current_post_date' AND post_status = 'publish' $sqlcat $sql_exclude_cats ORDER BY post_date DESC LIMIT $limitprev, 1");
|
||||
$lastpost = @$wpdb->get_row("SELECT ID, post_title FROM $wpdb->posts WHERE post_date < '$current_post_date' AND post_status = 'publish' $sqlcat $sql_exclude_cats ORDER BY post_date DESC LIMIT $limitprev, 1");
|
||||
if ($lastpost) {
|
||||
$string = '<a href="'.get_permalink($lastpost->ID).'">'.$previous;
|
||||
if ($title == 'yes') {
|
||||
@@ -313,7 +313,7 @@ function previous_post($format='%', $previous='previous post: ', $title='yes', $
|
||||
}
|
||||
|
||||
function next_post($format='%', $next='next post: ', $title='yes', $in_same_cat='no', $limitnext=1, $excluded_categories='') {
|
||||
global $tableposts, $posts_per_page, $post, $wpdb, $single;
|
||||
global $posts_per_page, $post, $wpdb, $single;
|
||||
if(1 == $posts_per_page || 1 == $single) {
|
||||
|
||||
$current_post_date = $post->post_date;
|
||||
@@ -337,7 +337,7 @@ function next_post($format='%', $next='next post: ', $title='yes', $in_same_cat=
|
||||
|
||||
$limitnext--;
|
||||
|
||||
$nextpost = @$wpdb->get_row("SELECT ID,post_title FROM $tableposts WHERE post_date > '$current_post_date' AND post_date < '$now' AND post_status = 'publish' $sqlcat $sql_exclude_cats AND ID != $post->ID ORDER BY post_date ASC LIMIT $limitnext,1");
|
||||
$nextpost = @$wpdb->get_row("SELECT ID,post_title FROM $wpdb->posts WHERE post_date > '$current_post_date' AND post_date < '$now' AND post_status = 'publish' $sqlcat $sql_exclude_cats AND ID != $post->ID ORDER BY post_date ASC LIMIT $limitnext,1");
|
||||
if ($nextpost) {
|
||||
$string = '<a href="'.get_permalink($nextpost->ID).'">'.$next;
|
||||
if ($title=='yes') {
|
||||
|
||||
@@ -19,6 +19,21 @@ class wpdb {
|
||||
var $last_query;
|
||||
var $col_info;
|
||||
|
||||
// Our tables
|
||||
var $posts;
|
||||
var $users;
|
||||
var $categories;
|
||||
var $post2cat;
|
||||
var $comments;
|
||||
var $links;
|
||||
var $linkcategories;
|
||||
var $options;
|
||||
var $optiontypes;
|
||||
var $optionvalues;
|
||||
var $optiongroups;
|
||||
var $optiongroup_options;
|
||||
var $postmeta;
|
||||
|
||||
// ==================================================================
|
||||
// DB Constructor - connects to the server and selects a database
|
||||
|
||||
|
||||
Reference in New Issue
Block a user