Changeset 1355 for trunk/wp-includes/functions.php
- Timestamp:
- 05/24/2004 08:22:18 AM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r1354 r1355 96 96 97 97 function get_lastpostdate($timezone = 'server') { 98 global $ tableposts, $cache_lastpostdate, $pagenow, $wpdb;98 global $cache_lastpostdate, $pagenow, $wpdb; 99 99 $add_seconds_blog = get_settings('gmt_offset') * 3600; 100 100 $add_seconds_server = date('Z'); … … 103 103 switch(strtolower($timezone)) { 104 104 case 'gmt': 105 $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");105 $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"); 106 106 break; 107 107 case 'blog': 108 $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");108 $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"); 109 109 break; 110 110 case 'server': 111 $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");111 $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"); 112 112 break; 113 113 } … … 120 120 121 121 function get_lastpostmodified($timezone = 'server') { 122 global $ tableposts, $cache_lastpostmodified, $pagenow, $wpdb;122 global $cache_lastpostmodified, $pagenow, $wpdb; 123 123 $add_seconds_blog = get_settings('gmt_offset') * 3600; 124 124 $add_seconds_server = date('Z'); … … 127 127 switch(strtolower($timezone)) { 128 128 case 'gmt': 129 $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");129 $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"); 130 130 break; 131 131 case 'blog': 132 $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");132 $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"); 133 133 break; 134 134 case 'server': 135 $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");135 $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"); 136 136 break; 137 137 } … … 173 173 174 174 function get_userdata($userid) { 175 global $wpdb, $cache_userdata , $tableusers;175 global $wpdb, $cache_userdata; 176 176 if ( empty($cache_userdata[$userid]) ) { 177 $user = $wpdb->get_row("SELECT * FROM $ tableusers WHERE ID = '$userid'");177 $user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = '$userid'"); 178 178 $user->user_nickname = stripslashes($user->user_nickname); 179 179 $user->user_firstname = stripslashes($user->user_firstname); … … 188 188 189 189 function get_userdatabylogin($user_login) { 190 global $ tableusers, $cache_userdata, $wpdb;190 global $cache_userdata, $wpdb; 191 191 if ( empty($cache_userdata["$user_login"]) ) { 192 $user = $wpdb->get_row("SELECT * FROM $ tableusers WHERE user_login = '$user_login'");192 $user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login = '$user_login'"); 193 193 $cache_userdata["$user_login"] = $user; 194 194 } else { … … 199 199 200 200 function get_userid($user_login) { 201 global $ tableusers, $cache_userdata, $wpdb;201 global $cache_userdata, $wpdb; 202 202 if ( empty($cache_userdata["$user_login"]) ) { 203 $user_id = $wpdb->get_var("SELECT ID FROM $ tableusers WHERE user_login = '$user_login'");203 $user_id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$user_login'"); 204 204 205 205 $cache_userdata["$user_login"] = $user_id; … … 211 211 212 212 function get_usernumposts($userid) { 213 global $ tableposts, $tablecomments, $wpdb;214 return $wpdb->get_var("SELECT COUNT(*) FROM $ tableposts WHERE post_author = '$userid'");213 global $wpdb; 214 return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '$userid'"); 215 215 } 216 216 … … 218 218 // determine the post ID it represents. 219 219 function url_to_postid($url = '') { 220 global $wpdb , $tableposts;220 global $wpdb; 221 221 222 222 $siteurl = get_settings('home'); … … 291 291 292 292 // Run the query to get the post ID: 293 $id = intval($wpdb->get_var("SELECT ID FROM $ tableposts WHERE 1 = 1 " . $where));293 $id = intval($wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE 1 = 1 " . $where)); 294 294 295 295 return $id; … … 322 322 323 323 function get_alloptions() { 324 global $ tableoptions, $wpdb;325 $options = $wpdb->get_results("SELECT option_name, option_value FROM $ tableoptions");324 global $wpdb; 325 $options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options"); 326 326 if ($options) { 327 327 foreach ($options as $option) { … … 339 339 340 340 function update_option($option_name, $newvalue) { 341 global $wpdb, $ tableoptions, $cache_settings;341 global $wpdb, $cache_settings; 342 342 $newvalue = stripslashes($newvalue); 343 343 $newvalue = trim($newvalue); // I can't think of any situation we wouldn't want to trim 344 344 $newvalue = $wpdb->escape($newvalue); 345 $wpdb->query("UPDATE $ tableoptions SET option_value = '$newvalue' WHERE option_name = '$option_name'");345 $wpdb->query("UPDATE $wpdb->options SET option_value = '$newvalue' WHERE option_name = '$option_name'"); 346 346 $cache_settings = get_alloptions(); // Re cache settings 347 347 return true; … … 352 352 function add_option($name, $value='') { 353 353 // Adds an option if it doesn't already exist 354 global $wpdb , $tableoptions;354 global $wpdb; 355 355 if(!get_settings($name)) { 356 356 $name = $wpdb->escape($name); 357 357 $value = $wpdb->escape($value); 358 $wpdb->query("INSERT INTO $ tableoptions (option_name, option_value) VALUES ('$name', '$value')");358 $wpdb->query("INSERT INTO $wpdb->options (option_name, option_value) VALUES ('$name', '$value')"); 359 359 360 360 if($wpdb->insert_id) { … … 367 367 368 368 function delete_option($name) { 369 global $wpdb , $tableoptions, $tableoptiongroup_options;369 global $wpdb; 370 370 // Get the ID, if no ID then return 371 $option_id = $wpdb->get_var("SELECT option_id FROM $ tableoptions WHERE option_name = '$name'");371 $option_id = $wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = '$name'"); 372 372 if (!$option_id) return false; 373 $wpdb->query("DELETE FROM $ tableoptiongroup_options WHERE option_id = '$option_id'");374 $wpdb->query("DELETE FROM $ tableoptions WHERE option_name = '$name'");373 $wpdb->query("DELETE FROM $wpdb->optiongroup_options WHERE option_id = '$option_id'"); 374 $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = '$name'"); 375 375 return true; 376 376 } 377 377 378 378 function get_postdata($postid) { 379 global $post, $ tableposts, $wpdb;380 381 $post = $wpdb->get_row("SELECT * FROM $ tableposts WHERE ID = '$postid'");379 global $post, $wpdb; 380 381 $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = '$postid'"); 382 382 383 383 $postdata = array ( … … 403 403 404 404 function get_commentdata($comment_ID,$no_cache=0,$include_unapproved=false) { // less flexible, but saves DB queries 405 global $postc,$id,$commentdata, $tablecomments,$wpdb;405 global $postc,$id,$commentdata, $wpdb; 406 406 if ($no_cache) { 407 $query = "SELECT * FROM $ tablecomments WHERE comment_ID = '$comment_ID'";407 $query = "SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_ID'"; 408 408 if (false == $include_unapproved) { 409 409 $query .= " AND comment_approved = '1'"; … … 432 432 433 433 function get_catname($cat_ID) { 434 global $ tablecategories, $cache_catnames, $wpdb;434 global $cache_catnames, $wpdb; 435 435 if ( !$cache_catnames ) { 436 $results = $wpdb->get_results("SELECT * FROM $ tablecategories") or die('Oops, couldn\'t query the db for categories.');436 $results = $wpdb->get_results("SELECT * FROM $wpdb->categories") or die('Oops, couldn\'t query the db for categories.'); 437 437 foreach ($results as $post) { 438 438 $cache_catnames[$post->cat_ID] = $post->cat_name; … … 545 545 // Send a Trackback 546 546 function trackback($trackback_url, $title, $excerpt, $ID) { 547 global $wpdb , $tableposts;547 global $wpdb; 548 548 $title = urlencode(stripslashes($title)); 549 549 $excerpt = urlencode(stripslashes($excerpt)); … … 573 573 @fclose($fs); 574 574 575 $wpdb->query("UPDATE $ tableposts SET pinged = CONCAT(pinged, '\n', '$tb_url') WHERE ID = '$ID'");576 $wpdb->query("UPDATE $ tableposts SET to_ping = REPLACE(to_ping, '$tb_url', '') WHERE ID = '$ID'");575 $wpdb->query("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', '$tb_url') WHERE ID = '$ID'"); 576 $wpdb->query("UPDATE $wpdb->posts SET to_ping = REPLACE(to_ping, '$tb_url', '') WHERE ID = '$ID'"); 577 577 return $result; 578 578 } … … 899 899 */ 900 900 function wp_set_comment_status($comment_id, $comment_status) { 901 global $wpdb , $tablecomments;901 global $wpdb; 902 902 903 903 switch($comment_status) { 904 904 case 'hold': 905 $query = "UPDATE $ tablecomments SET comment_approved='0' WHERE comment_ID='$comment_id' LIMIT 1";905 $query = "UPDATE $wpdb->comments SET comment_approved='0' WHERE comment_ID='$comment_id' LIMIT 1"; 906 906 break; 907 907 case 'approve': 908 $query = "UPDATE $ tablecomments SET comment_approved='1' WHERE comment_ID='$comment_id' LIMIT 1";908 $query = "UPDATE $wpdb->comments SET comment_approved='1' WHERE comment_ID='$comment_id' LIMIT 1"; 909 909 break; 910 910 case 'delete': 911 $query = "DELETE FROM $ tablecomments WHERE comment_ID='$comment_id' LIMIT 1";911 $query = "DELETE FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1"; 912 912 break; 913 913 default: … … 935 935 */ 936 936 function wp_get_comment_status($comment_id) { 937 global $wpdb , $tablecomments;937 global $wpdb; 938 938 939 $result = $wpdb->get_var("SELECT comment_approved FROM $ tablecomments WHERE comment_ID='$comment_id' LIMIT 1");939 $result = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1"); 940 940 if ($result == NULL) { 941 941 return "deleted"; … … 950 950 951 951 function wp_notify_postauthor($comment_id, $comment_type='comment') { 952 global $wpdb , $tablecomments, $tableposts, $tableusers;952 global $wpdb; 953 953 global $querystring_start, $querystring_equal, $querystring_separator; 954 954 955 $comment = $wpdb->get_row("SELECT * FROM $ tablecomments WHERE comment_ID='$comment_id' LIMIT 1");956 $post = $wpdb->get_row("SELECT * FROM $ tableposts WHERE ID='$comment->comment_post_ID' LIMIT 1");957 $user = $wpdb->get_row("SELECT * FROM $ tableusers WHERE ID='$post->post_author' LIMIT 1");955 $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1"); 956 $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1"); 957 $user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID='$post->post_author' LIMIT 1"); 958 958 959 959 if ('' == $user->user_email) return false; // If there's no email to send the comment to … … 1010 1010 */ 1011 1011 function wp_notify_moderator($comment_id) { 1012 global $wpdb , $tablecomments, $tableposts, $tableusers;1012 global $wpdb; 1013 1013 global $querystring_start, $querystring_equal, $querystring_separator; 1014 1014 1015 $comment = $wpdb->get_row("SELECT * FROM $ tablecomments WHERE comment_ID='$comment_id' LIMIT 1");1016 $post = $wpdb->get_row("SELECT * FROM $ tableposts WHERE ID='$comment->comment_post_ID' LIMIT 1");1017 $user = $wpdb->get_row("SELECT * FROM $ tableusers WHERE ID='$post->post_author' LIMIT 1");1015 $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1"); 1016 $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1"); 1017 $user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID='$post->post_author' LIMIT 1"); 1018 1018 1019 1019 $comment_author_domain = gethostbyaddr($comment->comment_author_IP); 1020 $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $ tablecomments WHERE comment_approved = '0'");1020 $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'"); 1021 1021 1022 1022 $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"; … … 1317 1317 1318 1318 function get_posts($args) { 1319 global $wpdb , $tableposts;1319 global $wpdb; 1320 1320 parse_str($args, $r); 1321 1321 if (!isset($r['numberposts'])) $r['numberposts'] = 5; … … 1328 1328 $now = current_time('mysql'); 1329 1329 1330 $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']);1330 $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']); 1331 1331 1332 1332 return $posts; … … 1355 1355 1356 1356 function query_posts($query) { 1357 global $wpdb, $tablepost2cat, $tableposts, $tablecategories, $tableusers,1357 global $wpdb, 1358 1358 $pagenow; 1359 1359 … … 1486 1486 $andor = 'OR'; 1487 1487 } 1488 $join = " LEFT JOIN $ tablepost2cat ON ($tableposts.ID = $tablepost2cat.post_id) ";1488 $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) "; 1489 1489 $cat_array = explode(' ',$cat); 1490 1490 $whichcat .= ' AND (category_id '.$eq.' '.intval($cat_array[0]); … … 1512 1512 } 1513 1513 $category_name = preg_replace('|[^a-z0-9-_]|i', '', $category_name); 1514 $tables = ", $ tablepost2cat, $tablecategories";1515 $join = " LEFT JOIN $ tablepost2cat ON ($tableposts.ID = $tablepost2cat.post_id) LEFT JOIN $tablecategories ON ($tablepost2cat.category_id = $tablecategories.cat_ID) ";1514 $tables = ", $wpdb->post2cat, $wpdb->categories"; 1515 $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) "; 1516 1516 $whichcat = " AND (category_nicename = '$category_name'"; 1517 $cat = $wpdb->get_var("SELECT cat_ID FROM $ tablecategories WHERE category_nicename = '$category_name'");1517 $cat = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$category_name'"); 1518 1518 $whichcat .= get_category_children($cat, " OR category_id = "); 1519 1519 $whichcat .= ")"; … … 1556 1556 } 1557 1557 $author_name = preg_replace('|[^a-z0-9-_]|', '', strtolower($author_name)); 1558 $author = $wpdb->get_var("SELECT ID FROM $ tableusers WHERE user_nicename='".$author_name."'");1558 $author = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_nicename='".$author_name."'"); 1559 1559 $whichauthor .= ' AND (post_author = '.intval($author).')'; 1560 1560 } … … 1663 1663 else 1664 1664 $where .= ')'; 1665 $where .= " GROUP BY $ tableposts.ID";1666 $request = " SELECT $distinct * FROM $ tableposts $join WHERE 1=1".$where." ORDER BY post_$orderby $limits";1665 $where .= " GROUP BY $wpdb->posts.ID"; 1666 $request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1".$where." ORDER BY post_$orderby $limits"; 1667 1667 1668 1668 … … 1683 1683 function update_post_caches($posts) { 1684 1684 global $category_cache, $comment_count_cache, $post_meta_cache; 1685 global $tablecategories, $tablepost2cat, $tableposts, $tablecomments, 1686 $tablepostmeta, $wpdb; 1685 global $wpdb; 1687 1686 1688 1687 // No point in doing all this work if we didn't match any posts. … … 1699 1698 $dogs = $wpdb->get_results("SELECT DISTINCT 1700 1699 ID, category_id, cat_name, category_nicename, category_description, category_parent 1701 FROM $ tablecategories, $tablepost2cat, $tableposts1700 FROM $wpdb->categories, $wpdb->post2cat, $wpdb->posts 1702 1701 WHERE category_id = cat_ID AND post_id = ID AND post_id IN ($post_id_list)"); 1703 1702 … … 1708 1707 // Do the same for comment numbers 1709 1708 $comment_counts = $wpdb->get_results("SELECT ID, COUNT( comment_ID ) AS ccount 1710 FROM $ tableposts1711 LEFT JOIN $ tablecomments ON ( comment_post_ID = ID AND comment_approved = '1')1709 FROM $wpdb->posts 1710 LEFT JOIN $wpdb->comments ON ( comment_post_ID = ID AND comment_approved = '1') 1712 1711 WHERE post_status = 'publish' AND ID IN ($post_id_list) 1713 1712 GROUP BY ID"); … … 1722 1721 if ( $meta_list = $wpdb->get_results(" 1723 1722 SELECT post_id,meta_key,meta_value 1724 FROM $ tablepostmeta1723 FROM $wpdb->postmeta 1725 1724 WHERE post_id IN($post_id_list) 1726 1725 ORDER BY post_id,meta_key … … 1747 1746 1748 1747 function update_category_cache() { 1749 global $cache_categories, $ tablecategories, $wpdb;1750 $dogs = $wpdb->get_results("SELECT * FROM $ tablecategories WHERE 1=1");1748 global $cache_categories, $wpdb; 1749 $dogs = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE 1=1"); 1751 1750 foreach ($dogs as $catt) { 1752 1751 $cache_categories[$catt->cat_ID] = $catt; … … 1755 1754 1756 1755 function update_user_cache() { 1757 global $cache_userdata, $ tableusers, $wpdb;1758 1759 $users = $wpdb->get_results("SELECT * FROM $ tableusers WHERE user_level > 0");1756 global $cache_userdata, $wpdb; 1757 1758 $users = $wpdb->get_results("SELECT * FROM $wpdb->users WHERE user_level > 0"); 1760 1759 foreach ($users as $user) { 1761 1760 $cache_userdata[$user->ID] = $user;
Note: See TracChangeset
for help on using the changeset viewer.