Skip to content

Commit

Permalink
Giant commit, sorry mailing list people. Move all table names to new …
Browse files Browse the repository at this point in the history
…$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
  • Loading branch information
saxmatt committed May 24, 2004
1 parent 89d5a6f commit 25ae03e
Show file tree
Hide file tree
Showing 52 changed files with 1,107 additions and 1,104 deletions.
44 changes: 22 additions & 22 deletions wp-admin/admin-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ function checked($checked, $current) {
}

function get_nested_categories($default = 0) {
global $post_ID, $tablecategories, $tablepost2cat, $mode, $wpdb;
global $post_ID, $mode, $wpdb;

if ($post_ID) {
$checked_categories = $wpdb->get_col("
SELECT category_id
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'
");
} else {
$checked_categories[] = $default;
}

$categories = $wpdb->get_results("SELECT * FROM $tablecategories ORDER BY category_parent DESC, cat_name ASC");
$categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY category_parent DESC, cat_name ASC");
$result = array();
foreach($categories as $category) {
$array_category = get_object_vars($category);
Expand Down Expand Up @@ -66,14 +66,14 @@ function dropdown_categories($default = 0) {

// Dandy new recursive multiple category stuff.
function cat_rows($parent = 0, $level = 0, $categories = 0) {
global $wpdb, $tablecategories, $tablepost2cat, $bgcolor;
global $wpdb, $bgcolor;
if (!$categories) {
$categories = $wpdb->get_results("SELECT * FROM $tablecategories ORDER BY cat_name");
$categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_name");
}
if ($categories) {
foreach ($categories as $category) {
if ($category->category_parent == $parent) {
$count = $wpdb->get_var("SELECT COUNT(post_id) FROM $tablepost2cat WHERE category_id = $category->cat_ID");
$count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID");
$pad = str_repeat('— ', $level);

$bgcolor = ('#eee' == $bgcolor) ? 'none' : '#eee';
Expand All @@ -91,13 +91,13 @@ function cat_rows($parent = 0, $level = 0, $categories = 0) {
}

function wp_dropdown_cats($currentcat, $currentparent = 0, $parent = 0, $level = 0, $categories = 0) {
global $wpdb, $tablecategories, $tablepost2cat, $bgcolor;
global $wpdb, $bgcolor;
if (!$categories) {
$categories = $wpdb->get_results("SELECT * FROM $tablecategories ORDER BY cat_name");
$categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_name");
}
if ($categories) {
foreach ($categories as $category) { if ($currentcat != $category->cat_ID && $parent == $category->category_parent) {
$count = $wpdb->get_var("SELECT COUNT(post_id) FROM $tablepost2cat WHERE category_id = $category->cat_ID");
$count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID");
$pad = str_repeat('– ', $level);
echo "\n\t<option value='$category->cat_ID'";
if ($currentparent == $category->cat_ID)
Expand Down Expand Up @@ -199,11 +199,11 @@ function wp_create_thumbnail($file, $max_side, $effect = '') {

// Some postmeta stuff
function has_meta($postid) {
global $wpdb, $tablepostmeta;
global $wpdb;

return $wpdb->get_results("
SELECT meta_key, meta_value, meta_id, post_id
FROM $tablepostmeta
FROM $wpdb->postmeta
WHERE post_id = '$postid'
ORDER BY meta_key,meta_id",ARRAY_A);

Expand Down Expand Up @@ -240,22 +240,22 @@ function list_meta($meta) {

// Get a list of previously defined keys
function get_meta_keys() {
global $wpdb, $tablepostmeta;
global $wpdb;

$keys = $wpdb->get_col("
SELECT meta_key
FROM $tablepostmeta
FROM $wpdb->postmeta
GROUP BY meta_key
ORDER BY meta_key");

return $keys;
}

function meta_form() {
global $wpdb, $tablepostmeta;
global $wpdb;
$keys = $wpdb->get_col("
SELECT meta_key
FROM $tablepostmeta
FROM $wpdb->postmeta
GROUP BY meta_key
ORDER BY meta_id DESC
LIMIT 10");
Expand Down Expand Up @@ -289,7 +289,7 @@ function meta_form() {
}

function add_meta($post_ID) {
global $wpdb, $tablepostmeta;
global $wpdb;

$metakeyselect = $wpdb->escape( stripslashes( trim($_POST['metakeyselect']) ) );
$metakeyinput = $wpdb->escape( stripslashes( trim($_POST['metakeyinput']) ) );
Expand All @@ -306,23 +306,23 @@ function add_meta($post_ID) {
$metakey = $metakeyinput; // default

$result = $wpdb->query("
INSERT INTO $tablepostmeta
INSERT INTO $wpdb->postmeta
(post_id,meta_key,meta_value)
VALUES ('$post_ID','$metakey','$metavalue')
");
}
} // add_meta

function delete_meta($mid) {
global $wpdb, $tablepostmeta;
global $wpdb;

$result = $wpdb->query("DELETE FROM $tablepostmeta WHERE meta_id = '$mid'");
$result = $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'");
}

function update_meta($mid, $mkey, $mvalue) {
global $wpdb, $tablepostmeta;
global $wpdb;

return $wpdb->query("UPDATE $tablepostmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'");
return $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'");
}

function touch_time($edit = 1) {
Expand Down
2 changes: 1 addition & 1 deletion wp-admin/admin-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function gethelp_link($this_file, $helptag) {
if (!isset($debug)) $debug=0;
timer_start();

$dogs = $wpdb->get_results("SELECT * FROM $tablecategories WHERE 1=1");
$dogs = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE 1=1");
foreach ($dogs as $catt) {
$cache_categories[$catt->cat_ID] = $catt;
}
Expand Down
4 changes: 2 additions & 2 deletions wp-admin/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* Checking login & pass in the database */
function veriflog() {
global $cookiehash;
global $tableusers, $wpdb;
global $wpdb;

if (!empty($_COOKIE['wordpressuser_' . $cookiehash])) {
$user_login = $_COOKIE['wordpressuser_' . $cookiehash];
Expand All @@ -19,7 +19,7 @@ function veriflog() {
if (!$user_pass_md5)
return false;

$login = $wpdb->get_row("SELECT user_login, user_pass FROM $tableusers WHERE user_login = '$user_login'");
$login = $wpdb->get_row("SELECT user_login, user_pass FROM $wpdb->users WHERE user_login = '$user_login'");

if (!$login) {
return false;
Expand Down
14 changes: 7 additions & 7 deletions wp-admin/categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function add_magic_quotes($array) {
$category_description = addslashes(stripslashes(stripslashes($_POST['category_description'])));
$cat = intval($_POST['cat']);

$wpdb->query("INSERT INTO $tablecategories (cat_ID, cat_name, category_nicename, category_description, category_parent) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$cat')");
$wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$cat')");

header('Location: categories.php?message=1#addcat');

Expand All @@ -67,7 +67,7 @@ function add_magic_quotes($array) {
$cat_ID = intval($_GET["cat_ID"]);
$cat_name = get_catname($cat_ID);
$cat_name = addslashes($cat_name);
$category = $wpdb->get_row("SELECT * FROM $tablecategories WHERE cat_ID = '$cat_ID'");
$category = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID = '$cat_ID'");
$cat_parent = $category->category_parent;

if (1 == $cat_ID)
Expand All @@ -76,9 +76,9 @@ function add_magic_quotes($array) {
if ($user_level < 3)
die (__('Cheatin&#8217; uh?'));

$wpdb->query("DELETE FROM $tablecategories WHERE cat_ID = '$cat_ID'");
$wpdb->query("UPDATE $tablecategories SET category_parent = '$cat_parent' WHERE category_parent = '$cat_ID'");
$wpdb->query("UPDATE $tablepost2cat SET category_id='1' WHERE category_id='$cat_ID'");
$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'");
$wpdb->query("UPDATE $wpdb->categories SET category_parent = '$cat_parent' WHERE category_parent = '$cat_ID'");
$wpdb->query("UPDATE $wpdb->post2cat SET category_id='1' WHERE category_id='$cat_ID'");

header('Location: categories.php?message=2');

Expand All @@ -88,7 +88,7 @@ function add_magic_quotes($array) {

require_once ('admin-header.php');
$cat_ID = intval($_GET['cat_ID']);
$category = $wpdb->get_row("SELECT * FROM $tablecategories WHERE cat_ID = '$cat_ID'");
$category = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID = '$cat_ID'");
$cat_name = stripslashes($category->cat_name);
?>

Expand Down Expand Up @@ -129,7 +129,7 @@ function add_magic_quotes($array) {
$category_nicename = sanitize_title($cat_name);
$category_description = $wpdb->escape(stripslashes($_POST['category_description']));

$wpdb->query("UPDATE $tablecategories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$cat' WHERE cat_ID = '$cat_ID'");
$wpdb->query("UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$cat' WHERE cat_ID = '$cat_ID'");

header('Location: categories.php?message=3');

Expand Down
16 changes: 8 additions & 8 deletions wp-admin/edit-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ function checkAll(form)
$del_comments = ''; $safe_delete_commeents = ''; $i = 0;
foreach ($delete_comments as $comment) { // Check the permissions on each
$comment = intval($comment);
$post_id = $wpdb->get_var("SELECT comment_post_ID FROM $tablecomments WHERE comment_ID = $comment");
$authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $tableposts WHERE ID = $post_id"));
$post_id = $wpdb->get_var("SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = $comment");
$authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $post_id"));
if (($user_level > $authordata->user_level) or ($user_login == $authordata->user_login)) {
$wpdb->query("DELETE FROM $tablecomments WHERE comment_ID = $comment");
$wpdb->query("DELETE FROM $wpdb->comments WHERE comment_ID = $comment");
++$i;
}
}
Expand All @@ -57,21 +57,21 @@ function checkAll(form)

if (isset($_GET['s'])) {
$s = $wpdb->escape($_GET['s']);
$comments = $wpdb->get_results("SELECT * FROM $tablecomments WHERE
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE
comment_author LIKE '%$s%' OR
comment_author_email LIKE '%$s%' OR
comment_author_url LIKE ('%$s%') OR
comment_author_IP LIKE ('%$s%') OR
comment_content LIKE ('%$s%')
ORDER BY comment_date DESC");
} else {
$comments = $wpdb->get_results("SELECT * FROM $tablecomments ORDER BY comment_date DESC LIMIT 20");
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments ORDER BY comment_date DESC LIMIT 20");
}
if ('view' == $mode) {
if ($comments) {
echo '<ol>';
foreach ($comments as $comment) {
$authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $tableposts WHERE ID = $comment->comment_post_ID"));
$authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
$comment_status = wp_get_comment_status($comment->comment_ID);
if ('unapproved' == $comment_status) {
echo '<li class="unapproved" style="border-bottom: 1px solid #ccc;">';
Expand All @@ -89,7 +89,7 @@ function checkAll(form)
echo " | <a href=\"post.php?action=deletecomment&amp;p=".$comment->comment_post_ID."&amp;comment=".$comment->comment_ID."\" onclick=\"return confirm('" . sprintf(__("You are about to delete this comment by \'%s\'\\n \'Cancel\' to stop, \'OK\' to delete."), $comment->comment_author) . "')\">" . __('Delete Comment') . "</a> &#8212; ";
} // end if any comments to show
// Get post title
$post_title = $wpdb->get_var("SELECT post_title FROM $tableposts WHERE ID = $comment->comment_post_ID");
$post_title = $wpdb->get_var("SELECT post_title FROM $wpdb->posts WHERE ID = $comment->comment_post_ID");
$post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title;
?> <a href="post.php?action=edit&amp;post=<?php echo $comment->comment_post_ID; ?>"><?php printf(__('Edit Post &#8220;%s&#8221;'), stripslashes($post_title)); ?></a> | <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"><?php _e('View Post') ?></a></p>
</li>
Expand Down Expand Up @@ -119,7 +119,7 @@ function checkAll(form)
<th scope="col" colspan="3">' . __('Actions') . '</th>
</tr>';
foreach ($comments as $comment) {
$authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $tableposts WHERE ID = $comment->comment_post_ID"));
$authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
$bgcolor = ('#eee' == $bgcolor) ? 'none' : '#eee';
?>
<tr style='background-color: <?php echo $bgcolor; ?>'>
Expand Down
6 changes: 3 additions & 3 deletions wp-admin/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ul>
<?php
get_currentuserinfo();
$drafts = $wpdb->get_results("SELECT ID, post_title FROM $tableposts WHERE post_status = 'draft' AND post_author = $user_ID");
$drafts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'draft' AND post_author = $user_ID");
if ($drafts) {
?>
<div class="wrap">
Expand Down Expand Up @@ -47,7 +47,7 @@
<legend><?php _e('Show Posts From Month of...') ?></legend>
<select name='m'>
<?php
$arc_result=$wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $tableposts ORDER BY post_date DESC");
$arc_result=$wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts ORDER BY post_date DESC");
foreach ($arc_result as $arc_row) {
$arc_year = $arc_row->yyear;
$arc_month = $arc_row->mmonth;
Expand Down Expand Up @@ -125,7 +125,7 @@
<?php
if ( 1 == count($posts) ) {

$comments = $wpdb->get_results("SELECT * FROM $tablecomments WHERE comment_post_ID = $id ORDER BY comment_date");
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = $id ORDER BY comment_date");
if ($comments) {
?>
<h3><?php _e('Comments') ?></h3>
Expand Down
Loading

0 comments on commit 25ae03e

Please sign in to comment.