Search Meter - Version 2.10

Version Description

  • Add an option to ignore searches made by logged-in administrators, so administrators can test searches without cluttering up the search stats.
  • Requires WP 3.2.
  • Upgrade deprecated code. Minor restyling.
Download this release

Release Info

Developer bennettmcelwee
Plugin Icon 128x128 Search Meter
Version 2.10
Comparing to
See all releases

Code changes from version 2.9.1 to 2.10

Files changed (3) hide show
  1. admin.php +29 -20
  2. readme.txt +11 -4
  3. search-meter.php +38 -28
admin.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- Copyright (C) 2005-12 Bennett McElwee (bennett at thunderguy dotcom)
4
 
5
  This program is free software; you can redistribute it and/or
6
  modify it under the terms of version 2 of the GNU General Public
@@ -38,20 +38,23 @@ function tguy_sm_stats_css() {
38
  border-bottom: 1px solid #aaaaaa;
39
  }
40
  #search_meter_menu li {
41
- border: 1px solid #aaaaaa;
42
  border-bottom: none;
43
  line-height: 1.4em;
44
  display: inline-block;
45
- margin: 0 5px 0 0;
46
  padding: 0;
47
  list-style-type: none;
48
  list-style-image: none;
49
  list-style-position: outside;
50
  }
51
- #search_meter_menu li.current span {
 
 
 
52
  background-color: #ffffff;
53
  font-weight: bold;
54
- padding: 0 5px 3px 5px;
55
  }
56
  #search_meter_menu li a,
57
  #search_meter_menu li a:visited {
@@ -61,9 +64,6 @@ function tguy_sm_stats_css() {
61
  #search_meter_menu li a:hover {
62
  background-color: #eaf2fa;
63
  }
64
- #search_meter_menu + .wrap {
65
- margin-top: 0;
66
- }
67
  div.sm-stats-table {
68
  float: left;
69
  padding-right: 3em;
@@ -76,10 +76,10 @@ div.sm-stats-table h3 {
76
  margin-top: 0;
77
  margin-bottom: 0.5em;
78
  }
79
- div.sm-stats-table .left {
80
  text-align: left;
81
  }
82
- div.sm-stats-table .right {
83
  text-align: right;
84
  }
85
  div.sm-stats-clear {
@@ -240,7 +240,7 @@ function tguy_sm_summary_page() {
240
  <div class="wrap">
241
 
242
  <ul id="search_meter_menu">
243
- <li class="current"><span>Summary</span></li>
244
  <li><a href="index.php?page=<?php echo plugin_basename(__FILE__); ?>&amp;recent=100">Last 100 Searches</a></li>
245
  <li><a href="index.php?page=<?php echo plugin_basename(__FILE__); ?>&amp;recent=500">Last 500 Searches</a></li>
246
  </ul>
@@ -322,7 +322,7 @@ function tguy_sm_summary_table($days, $do_include_successes = true) {
322
  ?>
323
  <table cellpadding="3" cellspacing="2">
324
  <tbody>
325
- <tr class="alternate"><th class="left">Term</th><th>Searches</th>
326
  <?php
327
  if ($do_include_successes) {
328
  ?><th>Results</th><?php
@@ -333,11 +333,11 @@ function tguy_sm_summary_table($days, $do_include_successes = true) {
333
  ?>
334
  <tr class="<?php echo $class ?>">
335
  <td><a href="<?php echo get_bloginfo('wpurl').'/wp-admin/edit.php?s='.urlencode($result->terms).'&submit=Search' ?>"><?php echo htmlspecialchars($result->terms) ?></a></td>
336
- <td class="right"><?php echo $result->countsum ?></td>
337
  <?php
338
  if ($do_include_successes) {
339
  ?>
340
- <td class="right"><?php echo $result->hits ?></td></tr>
341
  <?php
342
  }
343
  $class = ($class == '' ? 'alternate' : '');
@@ -365,12 +365,12 @@ function tguy_sm_recent_page($max_lines, $do_show_details) {
365
  <ul id="search_meter_menu">
366
  <li><a href="<?php echo $this_url_base ?>">Summary</a></li>
367
  <?php if (100 == $max_lines) : ?>
368
- <li class="current"><span>Last 100 Searches</span></li>
369
  <?php else : ?>
370
  <li><a href="<?php echo $this_url_base ?>&amp;recent=100">Last 100 Searches</a></li>
371
  <?php endif ?>
372
  <?php if (500 == $max_lines) : ?>
373
- <li class="current"><span>Last 500 Searches</span></li>
374
  <?php else : ?>
375
  <li><a href="<?php echo $this_url_base ?>&amp;recent=500">Last 500 Searches</a></li>
376
  <?php endif ?>
@@ -393,11 +393,11 @@ function tguy_sm_recent_page($max_lines, $do_show_details) {
393
  ?>
394
  <table cellpadding="3" cellspacing="2">
395
  <tbody>
396
- <tr class="alternate"><th class="left">Date &amp; time</th><th class="left">Term</th><th class="right">Results</th>
397
  <?php if ($do_show_details) { ?>
398
- <th class="left">Details</th>
399
  <?php } else if ($is_details_available) { ?>
400
- <th class="left"><a href="<?php echo $this_url_base . $this_url_recent_arg . '&amp;details=1' ?>">Show details</a></th>
401
  <?php } ?>
402
  </tr>
403
  <?php
@@ -407,7 +407,7 @@ function tguy_sm_recent_page($max_lines, $do_show_details) {
407
  <tr valign="top" class="<?php echo $class ?>">
408
  <td><?php echo $result->datetime ?></td>
409
  <td><a href="<?php echo get_bloginfo('wpurl').'/wp-admin/edit.php?s='.urlencode($result->terms).'&submit=Search' ?>"><?php echo htmlspecialchars($result->terms) ?></a></td>
410
- <td class="right"><?php echo $result->hits ?></td>
411
  <?php if ($do_show_details) : ?>
412
  <td><?php echo str_replace("\n", "<br />", htmlspecialchars($result->details)) ?></td>
413
  <?php endif ?>
@@ -469,6 +469,7 @@ function tguy_sm_options_page() {
469
  $sm_filter_words = stripslashes($sm_filter_words);
470
  }
471
  $options['sm_filter_words'] = preg_replace('/\\s+/', ' ', trim($sm_filter_words));
 
472
  $options['sm_details_verbose'] = (bool)($_POST['sm_details_verbose']);
473
  $options['sm_disable_donation'] = (bool)($_POST['sm_disable_donation']);
474
  update_option('tguy_search_meter', $options);
@@ -528,6 +529,14 @@ function tguy_sm_options_page() {
528
  </fieldset>
529
  </td>
530
  </tr>
 
 
 
 
 
 
 
 
531
  <tr>
532
  <th class="th-full" scope="row" colspan="2">
533
  <label for="sm_details_verbose">
1
  <?php
2
  /*
3
+ Copyright (C) 2005-15 Bennett McElwee (bennett at thunderguy dotcom)
4
 
5
  This program is free software; you can redistribute it and/or
6
  modify it under the terms of version 2 of the GNU General Public
38
  border-bottom: 1px solid #aaaaaa;
39
  }
40
  #search_meter_menu li {
41
+ border: 1px solid #cccccc;
42
  border-bottom: none;
43
  line-height: 1.4em;
44
  display: inline-block;
45
+ margin: 0 10px 0 0;
46
  padding: 0;
47
  list-style-type: none;
48
  list-style-image: none;
49
  list-style-position: outside;
50
  }
51
+ #search_meter_menu li.sm-current {
52
+ border-color: #aaaaaa;
53
+ }
54
+ #search_meter_menu li.sm-current span {
55
  background-color: #ffffff;
56
  font-weight: bold;
57
+ padding: 0 5px 1px 5px;
58
  }
59
  #search_meter_menu li a,
60
  #search_meter_menu li a:visited {
64
  #search_meter_menu li a:hover {
65
  background-color: #eaf2fa;
66
  }
 
 
 
67
  div.sm-stats-table {
68
  float: left;
69
  padding-right: 3em;
76
  margin-top: 0;
77
  margin-bottom: 0.5em;
78
  }
79
+ div.sm-stats-table .sm-text {
80
  text-align: left;
81
  }
82
+ div.sm-stats-table .sm-number {
83
  text-align: right;
84
  }
85
  div.sm-stats-clear {
240
  <div class="wrap">
241
 
242
  <ul id="search_meter_menu">
243
+ <li class="sm-current"><span>Summary</span></li>
244
  <li><a href="index.php?page=<?php echo plugin_basename(__FILE__); ?>&amp;recent=100">Last 100 Searches</a></li>
245
  <li><a href="index.php?page=<?php echo plugin_basename(__FILE__); ?>&amp;recent=500">Last 500 Searches</a></li>
246
  </ul>
322
  ?>
323
  <table cellpadding="3" cellspacing="2">
324
  <tbody>
325
+ <tr class="alternate"><th class="sm-text">Term</th><th>Searches</th>
326
  <?php
327
  if ($do_include_successes) {
328
  ?><th>Results</th><?php
333
  ?>
334
  <tr class="<?php echo $class ?>">
335
  <td><a href="<?php echo get_bloginfo('wpurl').'/wp-admin/edit.php?s='.urlencode($result->terms).'&submit=Search' ?>"><?php echo htmlspecialchars($result->terms) ?></a></td>
336
+ <td class="sm-number"><?php echo $result->countsum ?></td>
337
  <?php
338
  if ($do_include_successes) {
339
  ?>
340
+ <td class="sm-number"><?php echo $result->hits ?></td></tr>
341
  <?php
342
  }
343
  $class = ($class == '' ? 'alternate' : '');
365
  <ul id="search_meter_menu">
366
  <li><a href="<?php echo $this_url_base ?>">Summary</a></li>
367
  <?php if (100 == $max_lines) : ?>
368
+ <li class="sm-current"><span>Last 100 Searches</span></li>
369
  <?php else : ?>
370
  <li><a href="<?php echo $this_url_base ?>&amp;recent=100">Last 100 Searches</a></li>
371
  <?php endif ?>
372
  <?php if (500 == $max_lines) : ?>
373
+ <li class="sm-current"><span>Last 500 Searches</span></li>
374
  <?php else : ?>
375
  <li><a href="<?php echo $this_url_base ?>&amp;recent=500">Last 500 Searches</a></li>
376
  <?php endif ?>
393
  ?>
394
  <table cellpadding="3" cellspacing="2">
395
  <tbody>
396
+ <tr class="alternate"><th class="sm-text">Date &amp; time</th><th class="sm-text">Term</th><th class="sm-number">Results</th>
397
  <?php if ($do_show_details) { ?>
398
+ <th class="sm-text">Details</th>
399
  <?php } else if ($is_details_available) { ?>
400
+ <th class="sm-text"><a href="<?php echo $this_url_base . $this_url_recent_arg . '&amp;details=1' ?>">Show details</a></th>
401
  <?php } ?>
402
  </tr>
403
  <?php
407
  <tr valign="top" class="<?php echo $class ?>">
408
  <td><?php echo $result->datetime ?></td>
409
  <td><a href="<?php echo get_bloginfo('wpurl').'/wp-admin/edit.php?s='.urlencode($result->terms).'&submit=Search' ?>"><?php echo htmlspecialchars($result->terms) ?></a></td>
410
+ <td class="sm-number"><?php echo $result->hits ?></td>
411
  <?php if ($do_show_details) : ?>
412
  <td><?php echo str_replace("\n", "<br />", htmlspecialchars($result->details)) ?></td>
413
  <?php endif ?>
469
  $sm_filter_words = stripslashes($sm_filter_words);
470
  }
471
  $options['sm_filter_words'] = preg_replace('/\\s+/', ' ', trim($sm_filter_words));
472
+ $options['sm_ignore_admin_search'] = (bool)($_POST['sm_ignore_admin_search']);
473
  $options['sm_details_verbose'] = (bool)($_POST['sm_details_verbose']);
474
  $options['sm_disable_donation'] = (bool)($_POST['sm_disable_donation']);
475
  update_option('tguy_search_meter', $options);
529
  </fieldset>
530
  </td>
531
  </tr>
532
+ <tr>
533
+ <th class="th-full" scope="row" colspan="2">
534
+ <label for="sm_ignore_admin_search" title='Administrators are users with "manage_options" capability'>
535
+ <input type="checkbox" id="sm_ignore_admin_search" name="sm_ignore_admin_search" <?php echo (tguy_sm_array_value($options, 'sm_ignore_admin_search') ? 'checked="checked"' : '') ?> />
536
+ Ignore searches made by logged-in administrators
537
+ </label>
538
+ </th>
539
+ </tr>
540
  <tr>
541
  <th class="th-full" scope="row" colspan="2">
542
  <label for="sm_details_verbose">
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === Search Meter ===
2
  Contributors: bennettmcelwee
3
  Donate link: http://thunderguy.com/semicolon/donate/
4
- Tags: search, meter, search-meter, statistics, widget, admin, keywords
5
- Requires at least: 2.8
6
- Tested up to: 4.2.1
7
  Stable tag: 2.9.1
8
 
9
  Search Meter tracks what your readers are searching for on your blog. View full details of recent searches or stats for the last day, week or month.
@@ -24,7 +24,9 @@ To see your search statistics, Log in to WordPress Admin. On your dashboard you
24
 
25
  There are a few options available if you go to the Settings section and click Search Meter. Use the radio buttons to determine who will be allowed to see the full search statistics. You can also type in a list of filter words; any search terms containing these words will not show up in the Recent Searches and Popular Searches widgets.
26
 
27
- Use the Reset Statistics button to clear all past search statistics; Search Meter will immediately start gathering fresh statistics. If you're technically-minded, you might want to check the "Keep detailed information" checkbox to make Search Meter save technical information about every search (the information is taken from the HTTP headers).
 
 
28
 
29
  == Installation ==
30
 
@@ -77,6 +79,11 @@ The [Search Meter home page](http://thunderguy.com/semicolon/wordpress/search-me
77
 
78
  == Changelog ==
79
 
 
 
 
 
 
80
  = 2.9.1 =
81
  * Ensure Search Meter can save searches even if other plugins trigger a query before the main WordPress loop.
82
 
1
  === Search Meter ===
2
  Contributors: bennettmcelwee
3
  Donate link: http://thunderguy.com/semicolon/donate/
4
+ Tags: search, meter, search-meter, statistics, widget, admin, keywords, terms, search terms
5
+ Requires at least: 3.2
6
+ Tested up to: 4.3
7
  Stable tag: 2.9.1
8
 
9
  Search Meter tracks what your readers are searching for on your blog. View full details of recent searches or stats for the last day, week or month.
24
 
25
  There are a few options available if you go to the Settings section and click Search Meter. Use the radio buttons to determine who will be allowed to see the full search statistics. You can also type in a list of filter words; any search terms containing these words will not show up in the Recent Searches and Popular Searches widgets.
26
 
27
+ *Advanced users*: You can check the "Ignore" box to tell Search Meter to ignore searches made by logged-in administrators, so you can test things without cluttering your search statistics. You can also check the "Keep detailed information" checkbox to make Search Meter save technical information about every search (the information is taken from the HTTP headers).
28
+
29
+ Use the Reset Statistics button to clear all past search statistics; Search Meter will immediately start gathering fresh statistics.
30
 
31
  == Installation ==
32
 
79
 
80
  == Changelog ==
81
 
82
+ = 2.10 =
83
+ * Add an option to ignore searches made by logged-in administrators, so administrators can test searches without cluttering up the search stats.
84
+ * Requires WP 3.2.
85
+ * Upgrade deprecated code. Minor restyling.
86
+
87
  = 2.9.1 =
88
  * Ensure Search Meter can save searches even if other plugins trigger a query before the main WordPress loop.
89
 
search-meter.php CHANGED
@@ -3,12 +3,12 @@
3
  Plugin Name: Search Meter
4
  Plugin URI: http://thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/
5
  Description: Keeps track of what your visitors are searching for. After you have activated this plugin, you can check the Search Meter section in the Dashboard to see what your visitors are searching for on your blog.
6
- Version: 2.9.1
7
  Author: Bennett McElwee
8
  Author URI: http://thunderguy.com/semicolon/
9
  Donate link: http://thunderguy.com/semicolon/donate/
10
 
11
- $Revision: 751330 $
12
 
13
 
14
  INSTRUCTIONS
@@ -30,7 +30,7 @@ INSTRUCTIONS
30
  Thanks to Kaufman (http://www.terrik.com/wordpress/) and the many others who have offered suggestions.
31
 
32
 
33
- Copyright (C) 2005-13 Bennett McElwee (bennett at thunderguy dotcom)
34
 
35
  This program is free software; you can redistribute it and/or
36
  modify it under the terms of version 2 of the GNU General Public
@@ -100,7 +100,7 @@ function sm_list_popular_searches($before = '', $after = '', $count = 5) {
100
  LIMIT $count");
101
  if (count($results)) {
102
  echo "$before\n<ul>\n";
103
- $home_url_slash = get_settings('home') . '/';
104
  foreach ($results as $result) {
105
  echo '<li><a href="'. $home_url_slash . sm_get_relative_search_url($result->terms) . '">'. htmlspecialchars($result->terms) .'</a></li>'."\n";
106
  }
@@ -124,7 +124,7 @@ function sm_list_recent_searches($before = '', $after = '', $count = 5) {
124
  LIMIT $count");
125
  if (count($results)) {
126
  echo "$before\n<ul>\n";
127
- $home_url_slash = get_settings('home') . '/';
128
  foreach ($results as $result) {
129
  echo '<li><a href="'. $home_url_slash . sm_get_relative_search_url($result->terms) . '">'. htmlspecialchars($result->terms) .'</a></li>'."\n";
130
  }
@@ -185,9 +185,9 @@ function tguy_sm_register_widgets() {
185
  }
186
 
187
  class SM_Popular_Searches_Widget extends WP_Widget {
188
- function SM_Popular_Searches_Widget() {
189
  $widget_ops = array('classname' => 'widget_search_meter', 'description' => __( "A list of the most popular successful searches in the last month"));
190
- $this->WP_Widget('popular_searches', __('Popular Searches'), $widget_ops);
191
  }
192
 
193
  function widget($args, $instance) {
@@ -225,9 +225,9 @@ class SM_Popular_Searches_Widget extends WP_Widget {
225
  }
226
 
227
  class SM_Recent_Searches_Widget extends WP_Widget {
228
- function SM_Recent_Searches_Widget() {
229
  $widget_ops = array('classname' => 'widget_search_meter', 'description' => __( "A list of the most recent successful searches on your blog"));
230
- $this->WP_Widget('recent_searches', __('Recent Searches'), $widget_ops);
231
  }
232
 
233
  function widget($args, $instance) {
@@ -283,6 +283,13 @@ function tguy_sm_save_search($posts) {
283
  && (0 === $tguy_sm_save_count || TGUY_SM_ALLOW_DUPLICATE_SAVES)
284
  && (tguy_sm_array_value($_SERVER, 'HTTP_REFERER') || TGUY_SM_ALLOW_EMPTY_REFERER) // proper referrer (otherwise could be search engine, cache...)
285
  ) {
 
 
 
 
 
 
 
286
  // Get all details of this search
287
  // search string is the raw query
288
  $search_string = $wp_query->query_vars['s'];
@@ -296,8 +303,7 @@ function tguy_sm_save_search($posts) {
296
  $hit_count = $wp_query->found_posts; // Thanks to Will for this line
297
  // Other useful details of the search
298
  $details = '';
299
- $options = get_option('tguy_search_meter');
300
- if ($options['sm_details_verbose']) {
301
  if (TGUY_SM_ALLOW_DUPLICATE_SAVES) {
302
  $details .= "Search Meter save count: $tguy_sm_save_count\n";
303
  }
@@ -307,15 +313,14 @@ function tguy_sm_save_search($posts) {
307
  }
308
  }
309
 
310
- // Sanitise as necessary
311
- $search_string = $wpdb->escape($search_string);
312
- $search_terms = $wpdb->escape($search_terms);
313
- $details = $wpdb->escape($details);
314
-
315
  // Save the individual search to the DB
316
- $query = "INSERT INTO `{$wpdb->prefix}searchmeter_recent` (`terms`,`datetime`,`hits`,`details`)
317
- VALUES ('$search_string',NOW(),$hit_count,'$details')";
318
- $success = $wpdb->query($query);
 
 
 
 
319
  if ($success) {
320
  // Ensure table never grows larger than TGUY_SM_HISTORY_SIZE + 100
321
  $rowcount = $wpdb->get_var(
@@ -332,21 +337,26 @@ function tguy_sm_save_search($posts) {
332
  }
333
  }
334
  // Save search summary into the DB. Usually this will be a new row, so try to insert first
335
- $query = "INSERT INTO `{$wpdb->prefix}searchmeter` (`terms`,`date`,`count`,`last_hits`)
336
- VALUES ('$search_terms',CURDATE(),1,$hit_count)";
337
  // Temporarily suppress errors, as this query is expected to fail on duplicate searches in a single day. Thanks to James Collins.
338
  $suppress = $wpdb->suppress_errors();
339
- $success = $wpdb->query($query);
 
 
 
 
 
340
  $wpdb->suppress_errors($suppress);
341
  if (!$success) {
342
- $query = "UPDATE `{$wpdb->prefix}searchmeter` SET
343
- `count` = `count` + 1,
344
- `last_hits` = $hit_count
345
- WHERE `terms` = '$search_terms' AND `date` = CURDATE()";
346
- $success = $wpdb->query($query);
 
 
 
347
  }
348
  ++$tguy_sm_save_count;
349
  }
350
  return $posts;
351
  }
352
-
3
  Plugin Name: Search Meter
4
  Plugin URI: http://thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/
5
  Description: Keeps track of what your visitors are searching for. After you have activated this plugin, you can check the Search Meter section in the Dashboard to see what your visitors are searching for on your blog.
6
+ Version: 2.10
7
  Author: Bennett McElwee
8
  Author URI: http://thunderguy.com/semicolon/
9
  Donate link: http://thunderguy.com/semicolon/donate/
10
 
11
+ $Revision: 1232710 $
12
 
13
 
14
  INSTRUCTIONS
30
  Thanks to Kaufman (http://www.terrik.com/wordpress/) and the many others who have offered suggestions.
31
 
32
 
33
+ Copyright (C) 2005-15 Bennett McElwee (bennett at thunderguy dotcom)
34
 
35
  This program is free software; you can redistribute it and/or
36
  modify it under the terms of version 2 of the GNU General Public
100
  LIMIT $count");
101
  if (count($results)) {
102
  echo "$before\n<ul>\n";
103
+ $home_url_slash = get_option('home') . '/';
104
  foreach ($results as $result) {
105
  echo '<li><a href="'. $home_url_slash . sm_get_relative_search_url($result->terms) . '">'. htmlspecialchars($result->terms) .'</a></li>'."\n";
106
  }
124
  LIMIT $count");
125
  if (count($results)) {
126
  echo "$before\n<ul>\n";
127
+ $home_url_slash = get_option('home') . '/';
128
  foreach ($results as $result) {
129
  echo '<li><a href="'. $home_url_slash . sm_get_relative_search_url($result->terms) . '">'. htmlspecialchars($result->terms) .'</a></li>'."\n";
130
  }
185
  }
186
 
187
  class SM_Popular_Searches_Widget extends WP_Widget {
188
+ function __construct() {
189
  $widget_ops = array('classname' => 'widget_search_meter', 'description' => __( "A list of the most popular successful searches in the last month"));
190
+ parent::__construct('popular_searches', __('Popular Searches'), $widget_ops);
191
  }
192
 
193
  function widget($args, $instance) {
225
  }
226
 
227
  class SM_Recent_Searches_Widget extends WP_Widget {
228
+ function __construct() {
229
  $widget_ops = array('classname' => 'widget_search_meter', 'description' => __( "A list of the most recent successful searches on your blog"));
230
+ parent::__construct('recent_searches', __('Recent Searches'), $widget_ops);
231
  }
232
 
233
  function widget($args, $instance) {
283
  && (0 === $tguy_sm_save_count || TGUY_SM_ALLOW_DUPLICATE_SAVES)
284
  && (tguy_sm_array_value($_SERVER, 'HTTP_REFERER') || TGUY_SM_ALLOW_EMPTY_REFERER) // proper referrer (otherwise could be search engine, cache...)
285
  ) {
286
+ $options = get_option('tguy_search_meter');
287
+
288
+ // Break out if we're supposed to ignore admin searches
289
+ if (tguy_sm_array_value($options, 'sm_ignore_admin_search') && current_user_can("manage_options")) {
290
+ return $posts; // EARLY EXIT
291
+ }
292
+
293
  // Get all details of this search
294
  // search string is the raw query
295
  $search_string = $wp_query->query_vars['s'];
303
  $hit_count = $wp_query->found_posts; // Thanks to Will for this line
304
  // Other useful details of the search
305
  $details = '';
306
+ if (tguy_sm_array_value($options, 'sm_details_verbose')) {
 
307
  if (TGUY_SM_ALLOW_DUPLICATE_SAVES) {
308
  $details .= "Search Meter save count: $tguy_sm_save_count\n";
309
  }
313
  }
314
  }
315
 
 
 
 
 
 
316
  // Save the individual search to the DB
317
+ $success = $wpdb->query($wpdb->prepare("
318
+ INSERT INTO `{$wpdb->prefix}searchmeter_recent` (`terms`,`datetime`,`hits`,`details`)
319
+ VALUES (%s, NOW(), %d, %s)",
320
+ $search_string,
321
+ $search_terms,
322
+ $details
323
+ ));
324
  if ($success) {
325
  // Ensure table never grows larger than TGUY_SM_HISTORY_SIZE + 100
326
  $rowcount = $wpdb->get_var(
337
  }
338
  }
339
  // Save search summary into the DB. Usually this will be a new row, so try to insert first
 
 
340
  // Temporarily suppress errors, as this query is expected to fail on duplicate searches in a single day. Thanks to James Collins.
341
  $suppress = $wpdb->suppress_errors();
342
+ $success = $wpdb->query($wpdb->prepare("
343
+ INSERT INTO `{$wpdb->prefix}searchmeter` (`terms`,`date`,`count`,`last_hits`)
344
+ VALUES (%s, CURDATE(), 1, %d)",
345
+ $search_terms,
346
+ $hit_count
347
+ ));
348
  $wpdb->suppress_errors($suppress);
349
  if (!$success) {
350
+ $success = $wpdb->query($wpdb->prepare("
351
+ UPDATE `{$wpdb->prefix}searchmeter` SET
352
+ `count` = `count` + 1,
353
+ `last_hits` = %d
354
+ WHERE `terms` = %s AND `date` = CURDATE()",
355
+ $hit_count,
356
+ $search_terms
357
+ ));
358
  }
359
  ++$tguy_sm_save_count;
360
  }
361
  return $posts;
362
  }