Search Meter - Version 2.8

Version Description

  • Fix option for permission level, which was not being saved correctly.
  • Allow Search Meter to work with Multisite WordPress.
  • Add convenient links between Settings and Dashboard pages.
  • Clean up dashboard tabs and table layout.
  • Add Bitcoin donation address in case you're feeling generous.
Download this release

Release Info

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

Code changes from version 2.7.3 to 2.8

Files changed (3) hide show
  1. readme.txt +36 -25
  2. screenshot-1.gif +0 -0
  3. search-meter.php +89 -68
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Search Meter ===
2
  Contributors: bennettmcelwee
3
- Donate link: http://www.thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/
4
- Tags: search, meter, search-meter, statistics, widget, admin
5
  Requires at least: 2.8
6
- Tested up to: 3.0
7
- Stable tag: 2.7.2
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.
10
 
@@ -30,7 +30,7 @@ Use the Reset Statistics button to clear all past search statistics; Search Mete
30
 
31
  You can find, download and install Search Meter directly from the **Plugins** section in WordPress.
32
 
33
- If you have an older version of WordPress, download and unzip the search-meter.zip file and upload to the `/wp-content/plugins/search-meter` directory. Then activate the plugin through the **Plugins** section in WordPress.
34
 
35
  = Widgets: Popular and Recent Searches =
36
 
@@ -63,6 +63,10 @@ Show a simple list of the 5 most recent successful search terms, hyperlinked to
63
 
64
  == Frequently Asked Questions ==
65
 
 
 
 
 
66
  = Where can I find out more information? =
67
 
68
  The [Search Meter home page](http://www.thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/) has more information and a form to submit comments and questions.
@@ -73,6 +77,13 @@ The [Search Meter home page](http://www.thunderguy.com/semicolon/wordpress/searc
73
 
74
  == Changelog ==
75
 
 
 
 
 
 
 
 
76
  = 2.7.3 =
77
  * Remove another warning message.
78
 
@@ -82,44 +93,44 @@ The [Search Meter home page](http://www.thunderguy.com/semicolon/wordpress/searc
82
  * Remove notice messages when debugging.
83
 
84
  = 2.7 =
85
- * Don't show duplicated recent searches
86
- * Add filter list so that search terms with certain words will not show up in recent and popular search lists
87
- * Search links work whether or not fancy permalinks are enabled
88
- * Administrator can decide who is allowed to see full statistics
89
- * Requires WordPress 2.3 or later
90
 
91
  = 2.6 =
92
- * Use UTF8 when creating tables
93
- * Fix PHP 5.3 incompatibility
94
- * Widgets now conform to WordPress 2.8 standards
95
 
96
  = 2.5 =
97
- * Improve formatting on the Options page
98
- * Fix database error caused by duplicate searches
99
  * Users of Search Meter version 1 will need to deactivate and reactivate the plugin to use version 2.5.
100
 
101
  = 2.4 =
102
  * Fix the links to the Statistics and Options pages, which broke in WordPress 2.7.
103
 
104
  = 2.3 =
105
- * Improve widget display and add controls to specify the number of searches to show
106
- * Add option to hide donation buttons
107
 
108
  = 2.2 =
109
- * Add widgets for Recent Searches and Popular Searches
110
- * Fix table creation problem on WordPress 2.2.1
111
- * Add donation buttons (thanks for your consideration)
112
 
113
  = 2.1 =
114
- * Improve search count accuracy
115
 
116
  = 2.0 =
117
- * Add Recent Searches page and template tag
118
- * Make search counts more accurate: correctly count multi-page searches and searches with no referer [sic]
119
  * Popular Searches tag allows number of results to be specified.
120
 
121
  = 1.1 =
122
- * Various improvements
123
 
124
  = 1.0 =
125
- * Initial public release
1
  === Search Meter ===
2
  Contributors: bennettmcelwee
3
+ Donate link: http://www.thunderguy.com/semicolon/donate/
4
+ Tags: search, meter, search-meter, statistics, widget, admin, keywords
5
  Requires at least: 2.8
6
+ Tested up to: 3.1.3
7
+ Stable tag: 2.8
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.
10
 
30
 
31
  You can find, download and install Search Meter directly from the **Plugins** section in WordPress.
32
 
33
+ If you want to install manually, download and unzip the search-meter.zip file and upload to the `/wp-content/plugins/search-meter` directory. Then activate the plugin through the **Plugins** section in WordPress.
34
 
35
  = Widgets: Popular and Recent Searches =
36
 
63
 
64
  == Frequently Asked Questions ==
65
 
66
+ = Why don't search terms with spaces work? =
67
+
68
+ There is a [bug](http://core.trac.wordpress.org/ticket/13961) in the way WordPress handles spaces in pretty permalinks. The WordPress developers will fix this at some point. Until then, I have written a plugin called [Search Fixer](http://www.thunderguy.com/semicolon/2011/06/08/search-fixer-wordpress-plugin/) which should improve things.
69
+
70
  = Where can I find out more information? =
71
 
72
  The [Search Meter home page](http://www.thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/) has more information and a form to submit comments and questions.
77
 
78
  == Changelog ==
79
 
80
+ = 2.8 =
81
+ * Fix option for permission level, which was not being saved correctly.
82
+ * Allow Search Meter to work with Multisite WordPress.
83
+ * Add convenient links between Settings and Dashboard pages.
84
+ * Clean up dashboard tabs and table layout.
85
+ * Add Bitcoin donation address in case you're feeling generous.
86
+
87
  = 2.7.3 =
88
  * Remove another warning message.
89
 
93
  * Remove notice messages when debugging.
94
 
95
  = 2.7 =
96
+ * Don't show duplicated recent searches.
97
+ * Add filter list so that search terms with certain words will not show up in recent and popular search lists.
98
+ * Search links work whether or not fancy permalinks are enabled.
99
+ * Administrator can decide who is allowed to see full statistics.
100
+ * Requires WordPress 2.3 or later.
101
 
102
  = 2.6 =
103
+ * Use UTF8 when creating tables.
104
+ * Fix PHP 5.3 incompatibility.
105
+ * Widgets now conform to WordPress 2.8 standards.
106
 
107
  = 2.5 =
108
+ * Improve formatting on the Options page.
109
+ * Fix database error caused by duplicate searches.
110
  * Users of Search Meter version 1 will need to deactivate and reactivate the plugin to use version 2.5.
111
 
112
  = 2.4 =
113
  * Fix the links to the Statistics and Options pages, which broke in WordPress 2.7.
114
 
115
  = 2.3 =
116
+ * Improve widget display and add controls to specify the number of searches to show.
117
+ * Add option to hide donation buttons.
118
 
119
  = 2.2 =
120
+ * Add widgets for Recent Searches and Popular Searches.
121
+ * Fix table creation problem on WordPress 2.2.1.
122
+ * Add donation buttons (thanks for your consideration).
123
 
124
  = 2.1 =
125
+ * Improve search count accuracy.
126
 
127
  = 2.0 =
128
+ * Add Recent Searches page and template tag.
129
+ * Make search counts more accurate: correctly count multi-page searches and searches with no referer [sic].
130
  * Popular Searches tag allows number of results to be specified.
131
 
132
  = 1.1 =
133
+ * Various improvements.
134
 
135
  = 1.0 =
136
+ * Initial public release.
screenshot-1.gif CHANGED
Binary file
search-meter.php CHANGED
@@ -3,11 +3,12 @@
3
  Plugin Name: Search Meter
4
  Plugin URI: http://www.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.7.3
7
  Author: Bennett McElwee
8
  Author URI: http://www.thunderguy.com/semicolon/
 
9
 
10
- $Revision: 261770 $
11
 
12
 
13
  INSTRUCTIONS
@@ -29,7 +30,7 @@ INSTRUCTIONS
29
  Thanks to Kaufman (http://www.terrik.com/wordpress/) and the many others who have offered suggestions.
30
 
31
 
32
- Copyright (C) 2005-10 Bennett McElwee (bennett at thunderguy dotcom)
33
 
34
  This program is free software; you can redistribute it and/or
35
  modify it under the terms of version 2 of the GNU General Public
@@ -45,6 +46,12 @@ or by writing to the Free Software Foundation, Inc.,
45
  */
46
 
47
 
 
 
 
 
 
 
48
  if (!is_plugin_page()) :
49
 
50
 
@@ -78,7 +85,7 @@ define('TGUY_SM_OPTIONS_CAPABILITY', 'manage_options');
78
 
79
  function sm_list_popular_searches($before = '', $after = '', $count = 5) {
80
  // List the most popular searches in the last month in decreasing order of popularity.
81
- global $wpdb, $table_prefix, $wp_rewrite;
82
  $count = intval($count);
83
  $escaped_filter_regex = sm_get_escaped_filter_regex();
84
  $filter_term = ($escaped_filter_regex == "" ? "" : "AND NOT `terms` REGEXP '{$escaped_filter_regex}'");
@@ -89,7 +96,7 @@ function sm_list_popular_searches($before = '', $after = '', $count = 5) {
89
  // function will be used in a sidebar.
90
  $results = $wpdb->get_results(
91
  "SELECT `terms`, SUM(`count`) AS countsum
92
- FROM `{$table_prefix}searchmeter`
93
  WHERE DATE_SUB( CURDATE( ) , INTERVAL 30 DAY ) <= `date`
94
  AND 0 < `last_hits`
95
  {$filter_term}
@@ -108,13 +115,13 @@ function sm_list_popular_searches($before = '', $after = '', $count = 5) {
108
 
109
  function sm_list_recent_searches($before = '', $after = '', $count = 5) {
110
  // List the most recent successful searches, ignoring duplicates
111
- global $wpdb, $table_prefix;
112
  $count = intval($count);
113
  $escaped_filter_regex = sm_get_escaped_filter_regex();
114
  $filter_term = ($escaped_filter_regex == "" ? "" : "AND NOT `terms` REGEXP '{$escaped_filter_regex}'");
115
  $results = $wpdb->get_results(
116
  "SELECT `terms`, MAX(`datetime`) `maxdatetime`
117
- FROM `{$table_prefix}searchmeter_recent`
118
  WHERE 0 < `hits`
119
  {$filter_term}
120
  GROUP BY `terms`
@@ -285,7 +292,7 @@ $tguy_sm_action_count = 0;
285
  function tguy_sm_save_search($posts) {
286
  // Check if the request is a search, and if so then save details.
287
  // This is a filter but does not change the posts.
288
- global $wpdb, $wp_query, $table_prefix, $tguy_sm_action_count;
289
 
290
  ++$tguy_sm_action_count;
291
  if (is_search()
@@ -324,33 +331,33 @@ function tguy_sm_save_search($posts) {
324
  $details = $wpdb->escape($details);
325
 
326
  // Save the individual search to the DB
327
- $query = "INSERT INTO `{$table_prefix}searchmeter_recent` (`terms`,`datetime`,`hits`,`details`)
328
  VALUES ('$search_string',NOW(),$hit_count,'$details')";
329
  $success = $wpdb->query($query);
330
  if ($success) {
331
  // Ensure table never grows larger than TGUY_SM_HISTORY_SIZE + 100
332
  $rowcount = $wpdb->get_var(
333
  "SELECT count(`datetime`) as rowcount
334
- FROM `{$table_prefix}searchmeter_recent`");
335
  if ((TGUY_SM_HISTORY_SIZE + 100) < $rowcount) {
336
  // find time of (TGUY_SM_HISTORY_SIZE)th entry
337
  $dateZero = $wpdb->get_var(
338
  "SELECT `datetime`
339
- FROM `{$table_prefix}searchmeter_recent`
340
  ORDER BY `datetime` DESC LIMIT ".TGUY_SM_HISTORY_SIZE.", 1");
341
- $query = "DELETE FROM `{$table_prefix}searchmeter_recent` WHERE `datetime` < '$dateZero'";
342
  $success = $wpdb->query($query);
343
  }
344
  }
345
  // Save search summary into the DB. Usually this will be a new row, so try to insert first
346
- $query = "INSERT INTO `{$table_prefix}searchmeter` (`terms`,`date`,`count`,`last_hits`)
347
  VALUES ('$search_terms',CURDATE(),1,$hit_count)";
348
  // Temporarily suppress errors, as this query is expected to fail on duplicate searches in a single day. Thanks to James Collins.
349
  $suppress = $wpdb->suppress_errors();
350
  $success = $wpdb->query($query);
351
  $wpdb->suppress_errors($suppress);
352
  if (!$success) {
353
- $query = "UPDATE `{$table_prefix}searchmeter` SET
354
  `count` = `count` + 1,
355
  `last_hits` = $hit_count
356
  WHERE `terms` = '$search_terms' AND `date` = CURDATE()";
@@ -362,8 +369,8 @@ function tguy_sm_save_search($posts) {
362
 
363
  function tguy_sm_create_summary_table() {
364
  // Create the table if not already there.
365
- global $wpdb, $table_prefix;
366
- $table_name = $table_prefix . "searchmeter";
367
  if ($wpdb->get_var("show tables like '$table_name'") != $table_name) {
368
  if (file_exists(ABSPATH . 'wp-admin/includes/upgrade.php')) {
369
  require_once(ABSPATH . '/wp-admin/includes/upgrade.php');
@@ -385,8 +392,8 @@ function tguy_sm_create_summary_table() {
385
 
386
  function tguy_sm_create_recent_table() {
387
  // Create the table if not already there.
388
- global $wpdb, $table_prefix;
389
- $table_name = $table_prefix . "searchmeter_recent";
390
  if ($wpdb->get_var("show tables like '$table_name'") != $table_name) {
391
  if (file_exists(ABSPATH . 'wp-admin/includes/upgrade.php')) {
392
  require_once(ABSPATH . '/wp-admin/includes/upgrade.php');
@@ -407,10 +414,10 @@ function tguy_sm_create_recent_table() {
407
  }
408
 
409
  function tguy_sm_reset_stats() {
410
- global $wpdb, $table_prefix;
411
  // Delete all records
412
- $wpdb->query("DELETE FROM `{$table_prefix}searchmeter`");
413
- $wpdb->query("DELETE FROM `{$table_prefix}searchmeter_recent`");
414
  }
415
 
416
  function tguy_sm_add_admin_pages() {
@@ -419,14 +426,19 @@ function tguy_sm_add_admin_pages() {
419
  if ($view_stats_capability == '') {
420
  $view_stats_capability = TGUY_SM_DEFAULT_VIEW_STATS_CAPABILITY;
421
  }
422
- add_submenu_page('index.php', 'Search Meter Statistics', 'Search Meter', $view_stats_capability, __FILE__, 'tguy_sm_stats_page');
423
  add_options_page('Search Meter', 'Search Meter', TGUY_SM_OPTIONS_CAPABILITY, __FILE__, 'tguy_sm_options_page');
424
  }
425
 
426
- // This is here to avoid E_NOTICE when indexing nonexistent array keys. There's probably a better solution. Suggestions are welcome.
427
- function tguy_sm_array_value(&$array, $key) {
428
- return (is_array($array) && array_key_exists($key, $array)) ? $array[$key] : null;
 
 
 
 
429
  }
 
430
 
431
 
432
  // Display information
@@ -435,42 +447,50 @@ function tguy_sm_array_value(&$array, $key) {
435
  function tguy_sm_stats_css() {
436
  ?>
437
  <style type="text/css">
438
- #search_meter_menu {
439
- margin: 0;
440
- padding: 0;
 
 
441
  }
442
  #search_meter_menu li {
443
- display: inline; list-style-type: none; list-style-image: none; list-style-position: outside; text-align: center;
444
- margin: 0;
445
- line-height: 170%;
446
- }
447
- #search_meter_menu li.current {
448
- font-weight: bold;
449
- background-color: #fff;
450
- color: #000;
451
- padding: 5px;
452
- }
453
- #search_meter_menu a {
454
- background-color: #fff;
455
- color: #69c;
456
- padding: 4px;
457
- font-size: 12px;
458
  border-bottom: none;
459
- }
460
- #search_meter_menu a:hover {
461
- background-color: #69c;
462
- color: #fff;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
463
  }
464
  #search_meter_menu + .wrap {
465
  margin-top: 0;
466
  }
467
  div.sm-stats-table {
468
  float: left;
469
- padding-right: 5em;
470
- padding-bottom: 3ex;
 
 
 
471
  }
472
  div.sm-stats-table h3 {
473
  margin-top: 0;
 
474
  }
475
  div.sm-stats-table .left {
476
  text-align: left;
@@ -496,23 +516,23 @@ function tguy_sm_stats_page() {
496
  }
497
 
498
  function tguy_sm_summary_page() {
499
- global $wpdb, $table_prefix;
500
 
501
  $options = get_option('tguy_search_meter');
502
  $is_disable_donation = $options['sm_disable_donation'];
503
 
504
  // Delete old records
505
  $result = $wpdb->query(
506
- "DELETE FROM `{$table_prefix}searchmeter`
507
  WHERE `date` < DATE_SUB( CURDATE() , INTERVAL 30 DAY)");
508
  echo "<!-- Search Meter: deleted $result old rows -->\n";
509
  ?>
510
  <div class="wrap">
511
 
512
  <ul id="search_meter_menu">
513
- <li class="current">Summary</li>
514
- <li><a href="<?php echo $_SERVER['PHP_SELF'] . "?page=" . $_REQUEST['page'] . "&amp;recent=100" ?>">Last 100 Searches</a></li>
515
- <li><a href="<?php echo $_SERVER['PHP_SELF'] . "?page=" . $_REQUEST['page'] . "&amp;recent=500" ?>">Last 500 Searches</a></li>
516
  </ul>
517
 
518
  <h2>Search summary</h2>
@@ -554,7 +574,7 @@ function tguy_sm_summary_page() {
554
  <h2>Notes</h2>
555
 
556
  <?php if (current_user_can(TGUY_SM_OPTIONS_CAPABILITY)) : ?>
557
- <p>To manage your search statistics, go to the <strong>Settings</strong> section and choose <strong>Search Meter</strong>.</p>
558
  <?php endif; ?>
559
 
560
  <p>For information and updates, see the <a href="http://www.thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/">Search Meter home page</a>. You can also offer suggestions, request new features or report problems.</p>
@@ -566,7 +586,7 @@ function tguy_sm_summary_page() {
566
  }
567
 
568
  function tguy_sm_summary_table($results, $days, $do_include_successes = false) {
569
- global $wpdb, $table_prefix;
570
  // Explanation of the query:
571
  // We group by terms, because we want all rows for a term to be combined.
572
  // For the search count, we simply SUM the count of all searches for the term.
@@ -582,7 +602,7 @@ function tguy_sm_summary_table($results, $days, $do_include_successes = false) {
582
  "SELECT `terms`,
583
  SUM( `count` ) AS countsum,
584
  SUBSTRING( MAX( CONCAT( `date` , ' ', `last_hits` ) ) , 12 ) AS hits
585
- FROM `{$table_prefix}searchmeter`
586
  WHERE DATE_SUB( CURDATE( ) , INTERVAL $days DAY ) <= `date`
587
  GROUP BY `terms`
588
  $hits_selector
@@ -622,12 +642,12 @@ function tguy_sm_summary_table($results, $days, $do_include_successes = false) {
622
  }
623
 
624
  function tguy_sm_recent_page($max_lines, $do_show_details) {
625
- global $wpdb, $table_prefix;
626
 
627
  $options = get_option('tguy_search_meter');
628
  $is_details_available = $options['sm_details_verbose'];
629
  $is_disable_donation = $options['sm_disable_donation'];
630
- $this_url_base = $_SERVER['PHP_SELF'] . '?page=' . $_REQUEST['page'];
631
  $this_url_recent_arg = '&amp;recent=' . $max_lines;
632
  ?>
633
  <div class="wrap">
@@ -635,14 +655,14 @@ function tguy_sm_recent_page($max_lines, $do_show_details) {
635
  <ul id="search_meter_menu">
636
  <li><a href="<?php echo $this_url_base ?>">Summary</a></li>
637
  <?php if (100 == $max_lines) : ?>
638
- <li class="current">Last 100 Searches</li>
639
  <?php else : ?>
640
- <li><a href="<?php echo $this_url_base . '&amp;recent=100' ?>">Last 100 Searches</a></li>
641
  <?php endif ?>
642
  <?php if (500 == $max_lines) : ?>
643
- <li class="current">Last 500 Searches</li>
644
  <?php else : ?>
645
- <li><a href="<?php echo $this_url_base . '&amp;recent=500' ?>">Last 500 Searches</a></li>
646
  <?php endif ?>
647
  </ul>
648
 
@@ -655,7 +675,7 @@ function tguy_sm_recent_page($max_lines, $do_show_details) {
655
  <?php
656
  $query =
657
  "SELECT `datetime`, `terms`, `hits`, `details`
658
- FROM `{$table_prefix}searchmeter_recent`
659
  ORDER BY `datetime` DESC, `terms` ASC
660
  LIMIT $max_lines";
661
  $results = $wpdb->get_results($query);
@@ -699,7 +719,7 @@ function tguy_sm_recent_page($max_lines, $do_show_details) {
699
  <h2>Notes</h2>
700
 
701
  <?php if (current_user_can(TGUY_SM_OPTIONS_CAPABILITY)) : ?>
702
- <p>To manage your search statistics, go to the <strong>Settings</strong> section and choose <strong>Search Meter</strong>.</p>
703
  <?php endif; ?>
704
 
705
  <p>For information and updates, see the <a href="http://www.thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/">Search Meter home page</a>. You can also offer suggestions, request new features or report problems.</p>
@@ -766,7 +786,7 @@ function tguy_sm_options_page() {
766
  <?php echo ($view_stats_capability=='publish_posts'?"checked=\"checked\"":"") ?> />
767
  Post authors and administrators</label><br>
768
  <label title='Users with "manage_options" capability'>
769
- <input type="radio" name="sm_view_stats_capability" value="activate_plugins"
770
  <?php echo ($view_stats_capability=='manage_options'?"checked=\"checked\"":"") ?> />
771
  Administrators only</label>
772
  </fieldset>
@@ -823,7 +843,7 @@ function tguy_sm_options_page() {
823
 
824
  <h3>Notes</h3>
825
 
826
- <p>To see your search statistics, go to the <strong>Dashboard</strong> and choose <strong>Search Meter</strong>.</p>
827
 
828
  <p>For information and updates, see the <a href="http://www.thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/">Search Meter home page</a>. At that page, you can also offer suggestions, request new features or report problems.</p>
829
 
@@ -841,7 +861,8 @@ function tguy_sm_show_donation_message() {
841
  <strong>Do you find this plugin useful?</strong><br />
842
  I write WordPress plugins because I enjoy doing it, but it does take up a lot
843
  of my time. If you think this plugin is useful, please consider donating some appropriate
844
- amount by clicking the Donate button. Thank you.</p>
 
845
  <?php
846
  }
847
 
3
  Plugin Name: Search Meter
4
  Plugin URI: http://www.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.8
7
  Author: Bennett McElwee
8
  Author URI: http://www.thunderguy.com/semicolon/
9
+ Donate link: http://www.thunderguy.com/semicolon/donate/
10
 
11
+ $Revision: 396366 $
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-11 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
46
  */
47
 
48
 
49
+ // This is here to avoid E_NOTICE when indexing nonexistent array keys. There's probably a better solution. Suggestions are welcome.
50
+ function tguy_sm_array_value(&$array, $key) {
51
+ return (is_array($array) && array_key_exists($key, $array)) ? $array[$key] : null;
52
+ }
53
+
54
+
55
  if (!is_plugin_page()) :
56
 
57
 
85
 
86
  function sm_list_popular_searches($before = '', $after = '', $count = 5) {
87
  // List the most popular searches in the last month in decreasing order of popularity.
88
+ global $wpdb, $wp_rewrite;
89
  $count = intval($count);
90
  $escaped_filter_regex = sm_get_escaped_filter_regex();
91
  $filter_term = ($escaped_filter_regex == "" ? "" : "AND NOT `terms` REGEXP '{$escaped_filter_regex}'");
96
  // function will be used in a sidebar.
97
  $results = $wpdb->get_results(
98
  "SELECT `terms`, SUM(`count`) AS countsum
99
+ FROM `{$wpdb->prefix}searchmeter`
100
  WHERE DATE_SUB( CURDATE( ) , INTERVAL 30 DAY ) <= `date`
101
  AND 0 < `last_hits`
102
  {$filter_term}
115
 
116
  function sm_list_recent_searches($before = '', $after = '', $count = 5) {
117
  // List the most recent successful searches, ignoring duplicates
118
+ global $wpdb;
119
  $count = intval($count);
120
  $escaped_filter_regex = sm_get_escaped_filter_regex();
121
  $filter_term = ($escaped_filter_regex == "" ? "" : "AND NOT `terms` REGEXP '{$escaped_filter_regex}'");
122
  $results = $wpdb->get_results(
123
  "SELECT `terms`, MAX(`datetime`) `maxdatetime`
124
+ FROM `{$wpdb->prefix}searchmeter_recent`
125
  WHERE 0 < `hits`
126
  {$filter_term}
127
  GROUP BY `terms`
292
  function tguy_sm_save_search($posts) {
293
  // Check if the request is a search, and if so then save details.
294
  // This is a filter but does not change the posts.
295
+ global $wpdb, $wp_query, $tguy_sm_action_count;
296
 
297
  ++$tguy_sm_action_count;
298
  if (is_search()
331
  $details = $wpdb->escape($details);
332
 
333
  // Save the individual search to the DB
334
+ $query = "INSERT INTO `{$wpdb->prefix}searchmeter_recent` (`terms`,`datetime`,`hits`,`details`)
335
  VALUES ('$search_string',NOW(),$hit_count,'$details')";
336
  $success = $wpdb->query($query);
337
  if ($success) {
338
  // Ensure table never grows larger than TGUY_SM_HISTORY_SIZE + 100
339
  $rowcount = $wpdb->get_var(
340
  "SELECT count(`datetime`) as rowcount
341
+ FROM `{$wpdb->prefix}searchmeter_recent`");
342
  if ((TGUY_SM_HISTORY_SIZE + 100) < $rowcount) {
343
  // find time of (TGUY_SM_HISTORY_SIZE)th entry
344
  $dateZero = $wpdb->get_var(
345
  "SELECT `datetime`
346
+ FROM `{$wpdb->prefix}searchmeter_recent`
347
  ORDER BY `datetime` DESC LIMIT ".TGUY_SM_HISTORY_SIZE.", 1");
348
+ $query = "DELETE FROM `{$wpdb->prefix}searchmeter_recent` WHERE `datetime` < '$dateZero'";
349
  $success = $wpdb->query($query);
350
  }
351
  }
352
  // Save search summary into the DB. Usually this will be a new row, so try to insert first
353
+ $query = "INSERT INTO `{$wpdb->prefix}searchmeter` (`terms`,`date`,`count`,`last_hits`)
354
  VALUES ('$search_terms',CURDATE(),1,$hit_count)";
355
  // Temporarily suppress errors, as this query is expected to fail on duplicate searches in a single day. Thanks to James Collins.
356
  $suppress = $wpdb->suppress_errors();
357
  $success = $wpdb->query($query);
358
  $wpdb->suppress_errors($suppress);
359
  if (!$success) {
360
+ $query = "UPDATE `{$wpdb->prefix}searchmeter` SET
361
  `count` = `count` + 1,
362
  `last_hits` = $hit_count
363
  WHERE `terms` = '$search_terms' AND `date` = CURDATE()";
369
 
370
  function tguy_sm_create_summary_table() {
371
  // Create the table if not already there.
372
+ global $wpdb;
373
+ $table_name = $wpdb->prefix . "searchmeter";
374
  if ($wpdb->get_var("show tables like '$table_name'") != $table_name) {
375
  if (file_exists(ABSPATH . 'wp-admin/includes/upgrade.php')) {
376
  require_once(ABSPATH . '/wp-admin/includes/upgrade.php');
392
 
393
  function tguy_sm_create_recent_table() {
394
  // Create the table if not already there.
395
+ global $wpdb;
396
+ $table_name = $wpdb->prefix . "searchmeter_recent";
397
  if ($wpdb->get_var("show tables like '$table_name'") != $table_name) {
398
  if (file_exists(ABSPATH . 'wp-admin/includes/upgrade.php')) {
399
  require_once(ABSPATH . '/wp-admin/includes/upgrade.php');
414
  }
415
 
416
  function tguy_sm_reset_stats() {
417
+ global $wpdb;
418
  // Delete all records
419
+ $wpdb->query("DELETE FROM `{$wpdb->prefix}searchmeter`");
420
+ $wpdb->query("DELETE FROM `{$wpdb->prefix}searchmeter_recent`");
421
  }
422
 
423
  function tguy_sm_add_admin_pages() {
426
  if ($view_stats_capability == '') {
427
  $view_stats_capability = TGUY_SM_DEFAULT_VIEW_STATS_CAPABILITY;
428
  }
429
+ add_submenu_page('index.php', 'Search Meter', 'Search Meter', $view_stats_capability, __FILE__, 'tguy_sm_stats_page');
430
  add_options_page('Search Meter', 'Search Meter', TGUY_SM_OPTIONS_CAPABILITY, __FILE__, 'tguy_sm_options_page');
431
  }
432
 
433
+ // Add settings link on plugin page
434
+ function tguy_sm_settings_link($links) {
435
+ if (current_user_can(TGUY_SM_OPTIONS_CAPABILITY)) {
436
+ $settings_link = '<a href="options-general.php?page='.plugin_basename(__FILE__).'">Settings</a>';
437
+ array_unshift($links, $settings_link);
438
+ }
439
+ return $links;
440
  }
441
+ add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'tguy_sm_settings_link' );
442
 
443
 
444
  // Display information
447
  function tguy_sm_stats_css() {
448
  ?>
449
  <style type="text/css">
450
+ #search_meter_menu {
451
+ line-height: 1.4em;
452
+ margin: 5px 0 0 0;
453
+ padding: 0;
454
+ border-bottom: 1px solid #aaaaaa;
455
  }
456
  #search_meter_menu li {
457
+ border: 1px solid #aaaaaa;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
458
  border-bottom: none;
459
+ line-height: 1.4em;
460
+ display: inline-block;
461
+ margin: 0 5px 0 0;
462
+ padding: 0;
463
+ list-style-type: none;
464
+ list-style-image: none;
465
+ list-style-position: outside;
466
+ }
467
+ #search_meter_menu li.current span {
468
+ background-color: #ffffff;
469
+ font-weight: bold;
470
+ padding: 0 5px 3px 5px;
471
+ }
472
+ #search_meter_menu li a,
473
+ #search_meter_menu li a:visited {
474
+ padding: 0 5px;
475
+ text-decoration: none;
476
+ }
477
+ #search_meter_menu li a:hover {
478
+ background-color: #eaf2fa;
479
  }
480
  #search_meter_menu + .wrap {
481
  margin-top: 0;
482
  }
483
  div.sm-stats-table {
484
  float: left;
485
+ padding-right: 3em;
486
+ padding-bottom: 1.5em;
487
+ }
488
+ div.sm-stats-table th, div.sm-stats-table td {
489
+ padding-right: 0.5em;
490
  }
491
  div.sm-stats-table h3 {
492
  margin-top: 0;
493
+ margin-bottom: 0.5em;
494
  }
495
  div.sm-stats-table .left {
496
  text-align: left;
516
  }
517
 
518
  function tguy_sm_summary_page() {
519
+ global $wpdb;
520
 
521
  $options = get_option('tguy_search_meter');
522
  $is_disable_donation = $options['sm_disable_donation'];
523
 
524
  // Delete old records
525
  $result = $wpdb->query(
526
+ "DELETE FROM `{$wpdb->prefix}searchmeter`
527
  WHERE `date` < DATE_SUB( CURDATE() , INTERVAL 30 DAY)");
528
  echo "<!-- Search Meter: deleted $result old rows -->\n";
529
  ?>
530
  <div class="wrap">
531
 
532
  <ul id="search_meter_menu">
533
+ <li class="current"><span>Summary</span></li>
534
+ <li><a href="index.php?page=<?php echo plugin_basename(__FILE__); ?>&amp;recent=100">Last 100 Searches</a></li>
535
+ <li><a href="index.php?page=<?php echo plugin_basename(__FILE__); ?>&amp;recent=500">Last 500 Searches</a></li>
536
  </ul>
537
 
538
  <h2>Search summary</h2>
574
  <h2>Notes</h2>
575
 
576
  <?php if (current_user_can(TGUY_SM_OPTIONS_CAPABILITY)) : ?>
577
+ <p>To manage your search statistics, go to the <a href="options-general.php?page=<?php echo plugin_basename(__FILE__); ?>">Search Meter Settings</a> page.</p>
578
  <?php endif; ?>
579
 
580
  <p>For information and updates, see the <a href="http://www.thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/">Search Meter home page</a>. You can also offer suggestions, request new features or report problems.</p>
586
  }
587
 
588
  function tguy_sm_summary_table($results, $days, $do_include_successes = false) {
589
+ global $wpdb;
590
  // Explanation of the query:
591
  // We group by terms, because we want all rows for a term to be combined.
592
  // For the search count, we simply SUM the count of all searches for the term.
602
  "SELECT `terms`,
603
  SUM( `count` ) AS countsum,
604
  SUBSTRING( MAX( CONCAT( `date` , ' ', `last_hits` ) ) , 12 ) AS hits
605
+ FROM `{$wpdb->prefix}searchmeter`
606
  WHERE DATE_SUB( CURDATE( ) , INTERVAL $days DAY ) <= `date`
607
  GROUP BY `terms`
608
  $hits_selector
642
  }
643
 
644
  function tguy_sm_recent_page($max_lines, $do_show_details) {
645
+ global $wpdb;
646
 
647
  $options = get_option('tguy_search_meter');
648
  $is_details_available = $options['sm_details_verbose'];
649
  $is_disable_donation = $options['sm_disable_donation'];
650
+ $this_url_base = 'index.php?page=' . plugin_basename(__FILE__);
651
  $this_url_recent_arg = '&amp;recent=' . $max_lines;
652
  ?>
653
  <div class="wrap">
655
  <ul id="search_meter_menu">
656
  <li><a href="<?php echo $this_url_base ?>">Summary</a></li>
657
  <?php if (100 == $max_lines) : ?>
658
+ <li class="current"><span>Last 100 Searches</span></li>
659
  <?php else : ?>
660
+ <li><a href="<?php echo $this_url_base ?>&amp;recent=100">Last 100 Searches</a></li>
661
  <?php endif ?>
662
  <?php if (500 == $max_lines) : ?>
663
+ <li class="current"><span>Last 500 Searches</span></li>
664
  <?php else : ?>
665
+ <li><a href="<?php echo $this_url_base ?>&amp;recent=500">Last 500 Searches</a></li>
666
  <?php endif ?>
667
  </ul>
668
 
675
  <?php
676
  $query =
677
  "SELECT `datetime`, `terms`, `hits`, `details`
678
+ FROM `{$wpdb->prefix}searchmeter_recent`
679
  ORDER BY `datetime` DESC, `terms` ASC
680
  LIMIT $max_lines";
681
  $results = $wpdb->get_results($query);
719
  <h2>Notes</h2>
720
 
721
  <?php if (current_user_can(TGUY_SM_OPTIONS_CAPABILITY)) : ?>
722
+ <p>To manage your search statistics, go to the <a href="options-general.php?page=<?php echo plugin_basename(__FILE__); ?>">Search Meter Settings</a> page.</p>
723
  <?php endif; ?>
724
 
725
  <p>For information and updates, see the <a href="http://www.thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/">Search Meter home page</a>. You can also offer suggestions, request new features or report problems.</p>
786
  <?php echo ($view_stats_capability=='publish_posts'?"checked=\"checked\"":"") ?> />
787
  Post authors and administrators</label><br>
788
  <label title='Users with "manage_options" capability'>
789
+ <input type="radio" name="sm_view_stats_capability" value="manage_options"
790
  <?php echo ($view_stats_capability=='manage_options'?"checked=\"checked\"":"") ?> />
791
  Administrators only</label>
792
  </fieldset>
843
 
844
  <h3>Notes</h3>
845
 
846
+ <p>To see your search statistics, go to the <a href="index.php?page=<?php echo plugin_basename(__FILE__); ?>">Search Meter Dashboard</a>.</p>
847
 
848
  <p>For information and updates, see the <a href="http://www.thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/">Search Meter home page</a>. At that page, you can also offer suggestions, request new features or report problems.</p>
849
 
861
  <strong>Do you find this plugin useful?</strong><br />
862
  I write WordPress plugins because I enjoy doing it, but it does take up a lot
863
  of my time. If you think this plugin is useful, please consider donating some appropriate
864
+ amount by clicking the <strong>Donate</strong> button. You can also send <strong>Bitcoins</strong>
865
+ to address <tt>1542gqyprvQd7gwvtZZ4x25cPeGWVKg45x</tt>. Thanks!</p>
866
  <?php
867
  }
868