Skip to content

Commit 4efb6bb

Browse files
committed
Missing querycount
git-svn-id: https://develop.svn.wordpress.org/trunk@558 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 6c8852b commit 4efb6bb

27 files changed

Lines changed: 95 additions & 31 deletions

b2-include/b2functions.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ function get_usernumposts($userid) {
478478
// examine a url (supposedly from this blog) and try to
479479
// determine the post ID it represents.
480480
function url_to_postid($url = '') {
481-
global $wpdb, $tableposts, $siteurl;
481+
global $wpdb, $querycount, $tableposts, $siteurl;
482482

483483
// Take a link like 'http://example.com/blog/something'
484484
// and extract just the '/something':
@@ -536,7 +536,8 @@ function url_to_postid($url = '') {
536536
if ($postname) $where .= " AND post_name = '" . $wpdb->escape($postname) . "' ";
537537

538538
// Run the query to get the post ID:
539-
return intval($wpdb->get_var("SELECT ID FROM $tableposts WHERE 1 = 1 " . $where));
539+
++$querycount;
540+
return intval($wpdb->get_var("SELECT ID FROM $tableposts WHERE 1 = 1 " . $where));
540541
}
541542

542543

@@ -681,6 +682,7 @@ function dropdown_categories($blog_ID=1, $default=1) {
681682
if ($postdata["Category"] != '') {
682683
$default = $postdata["Category"];
683684
}
685+
++$querycount;
684686
foreach($results as $post) {
685687
echo "<option value=\"".$post->cat_ID."\"";
686688
if ($post->cat_ID == $default)
@@ -1439,28 +1441,32 @@ function wp_set_comment_status($comment_id, $comment_status) {
14391441
a (boolean) false signals an error
14401442
*/
14411443
function wp_get_comment_status($comment_id) {
1442-
global $wpdb, $tablecomments;
1444+
global $wpdb, $querycount, $tablecomments;
14431445

14441446
$result = $wpdb->get_var("SELECT comment_approved FROM $tablecomments WHERE comment_ID='$comment_id' LIMIT 1");
1447+
++$querycount;
14451448
if ($result == NULL) {
1446-
return "deleted";
1449+
return "deleted";
14471450
} else if ($result == "1") {
1448-
return "approved";
1451+
return "approved";
14491452
} else if ($result == "0") {
1450-
return "unapproved";
1453+
return "unapproved";
14511454
} else {
1452-
return false;
1455+
return false;
14531456
}
14541457
}
14551458

14561459
function wp_notify_postauthor($comment_id, $comment_type) {
1457-
global $wpdb, $tablecomments, $tableposts, $tableusers;
1460+
global $wpdb, $querycount, $tablecomments, $tableposts, $tableusers;
14581461
global $querystring_start, $querystring_equal, $querystring_separator;
14591462
global $blogfilename, $blogname, $siteurl;
14601463

14611464
$comment = $wpdb->get_row("SELECT * FROM $tablecomments WHERE comment_ID='$comment_id' LIMIT 1");
1465+
++$querycount;
14621466
$post = $wpdb->get_row("SELECT * FROM $tableposts WHERE ID='$comment->comment_post_ID' LIMIT 1");
1467+
++$querycount;
14631468
$user = $wpdb->get_row("SELECT * FROM $tableusers WHERE ID='$post->post_author' LIMIT 1");
1469+
++$querycount;
14641470

14651471
if ('' == $user->user_email) return false; // If there's no email to send the comment to
14661472

@@ -1511,16 +1517,20 @@ function wp_notify_postauthor($comment_id, $comment_type) {
15111517
always returns true
15121518
*/
15131519
function wp_notify_moderator($comment_id) {
1514-
global $wpdb, $tablecomments, $tableposts, $tableusers;
1520+
global $wpdb, $querycount, $tablecomments, $tableposts, $tableusers;
15151521
global $querystring_start, $querystring_equal, $querystring_separator;
15161522
global $blogfilename, $blogname, $siteurl;
15171523

15181524
$comment = $wpdb->get_row("SELECT * FROM $tablecomments WHERE comment_ID='$comment_id' LIMIT 1");
1525+
++$querycount;
15191526
$post = $wpdb->get_row("SELECT * FROM $tableposts WHERE ID='$comment->comment_post_ID' LIMIT 1");
1527+
++$querycount;
15201528
$user = $wpdb->get_row("SELECT * FROM $tableusers WHERE ID='$post->post_author' LIMIT 1");
1529+
++$querycount;
15211530

15221531
$comment_author_domain = gethostbyaddr($comment->comment_author_IP);
15231532
$comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $tablecomments WHERE comment_approved = '0'");
1533+
++$querycount;
15241534

15251535
$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";
15261536
$notify_message .= "Author : $comment->comment_author (IP: $comment->comment_author_IP , $comment_author_domain)\r\n";

b2-include/b2template.functions.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,12 @@ function get_archives($type='', $limit='', $format='html', $before = "", $after
232232
}
233233

234234
function get_calendar($daylength = 1) {
235-
global $wpdb, $HTTP_GET_VARS, $m, $monthnum, $year, $timedifference, $month, $weekday, $tableposts, $posts;
235+
global $wpdb, $HTTP_GET_VARS, $m, $monthnum, $year, $timedifference, $month, $weekday, $tableposts, $posts, $querycount;
236236

237237
// Quick check. If we have no posts at all, abort!
238238
if (!$posts) {
239239
$gotsome = $wpdb->get_var("SELECT ID from $tableposts WHERE post_status = 'publish' AND post_category > 0 ORDER BY post_date DESC LIMIT 1");
240+
++$querycount;
240241
if (!$gotsome)
241242
return;
242243
}
@@ -253,6 +254,7 @@ function get_calendar($daylength = 1) {
253254
$thisyear = ''.intval(substr($m, 0, 4));
254255
$d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
255256
$thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')");
257+
++$querycount;
256258
} elseif (!empty($m)) {
257259
$calendar = substr($m, 0, 6);
258260
$thisyear = ''.intval(substr($m, 0, 4));
@@ -275,13 +277,15 @@ function get_calendar($daylength = 1) {
275277
AND post_status = 'publish'
276278
ORDER BY post_date DESC
277279
LIMIT 1");
280+
++$querycount;
278281
$next = $wpdb->get_row("SELECT DISTINCT MONTH( post_date ) AS month, YEAR( post_date ) AS year
279282
FROM $tableposts
280283
WHERE post_date > '$thisyear-$thismonth-01'
281284
AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
282285
AND post_status = 'publish'
283286
ORDER BY post_date ASC
284287
LIMIT 1");
288+
++$querycount;
285289

286290
echo '<table id="wp-calendar">
287291
<caption>' . $month[zeroise($thismonth, 2)] . ' ' . date('Y', $unixmonth) . '</caption>
@@ -329,7 +333,7 @@ function get_calendar($daylength = 1) {
329333
AND YEAR(post_date) = $thisyear
330334
AND post_status = 'publish'
331335
AND post_date < '" . date("Y-m-d H:i:s", (time() + ($time_difference * 3600)))."'", ARRAY_N);
332-
336+
++$querycount;
333337
if ($dayswithposts) {
334338
foreach ($dayswithposts as $daywith) {
335339
$daywithpost[] = $daywith[0];
@@ -355,6 +359,7 @@ function get_calendar($daylength = 1) {
355359
."AND post_date < '".date("Y-m-d H:i:s", (time() + ($time_difference * 3600)))."' "
356360
."AND post_status = 'publish'"
357361
);
362+
++$querycount;
358363
if ($ak_post_titles) {
359364
foreach ($ak_post_titles as $ak_post_title) {
360365
if (empty($ak_titles_for_day["$ak_post_title->dom"])) { // first one
@@ -405,7 +410,8 @@ function get_calendar($daylength = 1) {
405410
/***** Links *****/
406411
function get_permalink($id=false) {
407412
global $post, $wpdb, $tableposts;
408-
global $siteurl, $blogfilename, $querystring_start, $querystring_equal;
413+
global $siteurl, $blogfilename, $querystring_start, $querystring_equal, $querycount;
414+
409415
$rewritecode = array(
410416
'%year%',
411417
'%monthnum%',
@@ -427,6 +433,7 @@ function get_permalink($id=false) {
427433
}
428434
} else { // if an ID is given
429435
$idpost = $wpdb->get_row("SELECT post_date, post_name FROM $tableposts WHERE ID = $id");
436+
++$querycount;
430437
if ('' != get_settings('permalink_structure')) {
431438
$unixtime = strtotime($idpost->post_date);
432439
$rewritereplace = array(
@@ -1350,7 +1357,7 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde
13501357
$query .= " ORDER BY $sort_column $sort_order, post_date DESC";
13511358

13521359
$categories = $wpdb->get_results($query);
1353-
1360+
++$querycount;
13541361
if (!$categories) {
13551362
if ($list) {
13561363
$before = '<li>';
@@ -1359,7 +1366,6 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde
13591366
echo $before . "No categories" . $after . "\n";
13601367
return;
13611368
}
1362-
++$querycount;
13631369
if (intval($optionall) == 1) {
13641370
$all = apply_filters('list_cats', $all);
13651371
$link = "<a href=\"".$file.$querystring_start.'cat'.$querystring_equal.'all">'.$all."</a>";
@@ -1405,11 +1411,12 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde
14051411

14061412
function comments_number($zero='No Comments', $one='1 Comment', $more='% Comments', $include_unapproved = false) {
14071413
global $id, $comment, $tablecomments, $querycount, $wpdb;
1408-
$query = "SELECT COUNT(*) FROM $tablecomments WHERE comment_post_ID = '$id'";
1414+
$query = "SELECT COUNT(*) FROM $tablecomments WHERE comment_post_ID = $id";
14091415
if (false == $include_unapproved) {
14101416
$query .= " AND comment_approved = '1'";
14111417
}
14121418
$number = $wpdb->get_var($query);
1419+
++$querycount;
14131420
if ($number == 0) {
14141421
$blah = $zero;
14151422
} elseif ($number == 1) {
@@ -1438,9 +1445,10 @@ function comments_popup_script($width=400, $height=400, $file='b2commentspopup.p
14381445
}
14391446

14401447
function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') {
1441-
global $id, $b2commentspopupfile, $b2commentsjavascript, $post, $wpdb, $tablecomments, $HTTP_COOKIE_VARS, $cookiehash;
1448+
global $id, $b2commentspopupfile, $b2commentsjavascript, $post, $wpdb, $querycount, $tablecomments, $HTTP_COOKIE_VARS, $cookiehash;
14421449
global $querystring_start, $querystring_equal, $querystring_separator, $siteurl;
14431450
$number = $wpdb->get_var("SELECT COUNT(*) FROM $tablecomments WHERE comment_post_ID = $id AND comment_approved = '1'");
1451+
++$querycount;
14441452
if (0 == $number && 'closed' == $post->comment_status) {
14451453
echo $none;
14461454
return;

b2comments.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
$comment_author_url = trim($HTTP_COOKIE_VARS["comment_author_url_".$cookiehash]);
1616

1717
$comments = $wpdb->get_results("SELECT * FROM $tablecomments WHERE comment_post_ID = $id AND comment_approved = '1' ORDER BY comment_date");
18+
++$querycount;
1819
?>
1920

2021
<!-- You can start editing here. -->

b2comments.post.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function add_magic_quotes($array) {
3939
$user_domain = gethostbyaddr($user_ip);
4040

4141
$commentstatus = $wpdb->get_var("SELECT comment_status FROM $tableposts WHERE ID = $comment_post_ID");
42-
42+
++$querycount;
4343
if ('closed' == $commentstatus)
4444
die('Sorry, comments are closed for this item.');
4545

@@ -68,6 +68,7 @@ function add_magic_quotes($array) {
6868

6969
/* Flood-protection */
7070
$lasttime = $wpdb->get_var("SELECT comment_date FROM $tablecomments WHERE comment_author_IP = '$user_ip' ORDER BY comment_date DESC LIMIT 1");
71+
++$querycount;
7172
$ok = true;
7273
if (!empty($lasttime)) {
7374
$time_lastcomment= mysql2date('U', $lasttime);
@@ -100,6 +101,7 @@ function add_magic_quotes($array) {
100101
");
101102

102103
$comment_ID = $wpdb->get_var('SELECT last_insert_id()');
104+
++$querycount;
103105

104106
if (($moderation_notify) && (!$approved)) {
105107
wp_notify_moderator($comment_ID);

b2commentspopup.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
<?php
3131
// this line is WordPress' motor, do not delete it.
3232
$comments = $wpdb->get_results("SELECT * FROM $tablecomments WHERE comment_post_ID = $id AND comment_approved = '1' ORDER BY comment_date");
33+
++$querycount;
3334
$commentstatus = $wpdb->get_row("SELECT comment_status, post_password FROM $tableposts WHERE ID = $id");
35+
++$querycount;
3436
if (!empty($commentstatus->post_password) && $HTTP_COOKIE_VARS['wp-postpass_'.$cookiehash] != $commentstatus->post_password) { // and it doesn't match the cookie
3537
echo(get_the_password_form());
3638
} else { ?>

b2login.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function add_magic_quotes($array) {
6666
$pwd = $HTTP_POST_VARS["pwd"];
6767
$redirect_to = $HTTP_POST_VARS["redirect_to"];
6868
}
69-
69+
7070
function login() {
7171
global $wpdb, $log, $pwd, $error, $user_ID;
7272
global $tableusers, $pass_is_md5;
@@ -86,9 +86,11 @@ function login() {
8686
$pass_is_md5 = 1;
8787
$password = substr($password, 4, strlen($password));
8888
$query = "SELECT ID, user_login, user_pass FROM $tableusers WHERE user_login = '$user_login' AND MD5(user_pass) = '$password'";
89+
++$querycount;
8990
} else {
9091
$pass_is_md5 = 0;
9192
$query = "SELECT ID, user_login, user_pass FROM $tableusers WHERE user_login = '$user_login' AND user_pass = '$password'";
93+
++$querycount;
9294
}
9395
$login = $wpdb->get_row($query);
9496

b2mail.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204

205205
$sql = "SELECT ID, user_level FROM $tableusers WHERE user_login='$user_login' AND user_pass='$user_pass' ORDER BY ID DESC LIMIT 1";
206206
$result = $wpdb->get_row($sql);
207+
++$querycount;
207208

208209
if (!$result) {
209210
echo '<p><b>Wrong login or password.</b></p></div>';

b2register.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ function filter($value) {
8080

8181
/* checking the login isn't already used by another user */
8282
$result = $wpdb->get_results("SELECT user_login FROM $tableusers WHERE user_login = '$user_login'");
83-
if (count($result) >= 1) {
83+
++$querycount;
84+
if (count($result) >= 1) {
8485
die ('<strong>ERROR</strong>: This login is already registered, please choose another one.');
8586
}
8687

b2trackback.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
trackback_response(1, 'Sorry, this weblog does not allow you to trackback its posts.');
3232

3333
$pingstatus = $wpdb->get_var("SELECT ping_status FROM $tableposts WHERE ID = $tb_id");
34+
++$querycount;
3435

3536
if ('closed' == $pingstatus)
3637
trackback_response(1, 'Sorry, trackbacks are closed for this item.');
@@ -86,6 +87,7 @@
8687
die ("There is an error with the database, it can't store your comment...<br />Please contact the <a href='mailto:$admin_email'>webmaster</a>.");
8788
} else {
8889
$comment_ID = $wpdb->get_var('SELECT last_insert_id()');
90+
++$querycount;
8991
if ($comments_notify)
9092
wp_notify_postauthor($comment_ID, 'trackback');
9193
trackback_response(0);

blog.header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@
304304
// error_log("$request");
305305
// echo $request;
306306
$posts = $wpdb->get_results($request);
307-
307+
++$querycount;
308308
if (1 == count($posts)) {
309309
if ($p || $name) {
310310
$more = 1;

0 commit comments

Comments
 (0)