Search Meter - Version 2.6

Version Description

  • Use UTF8 when creating tables
  • Fix PHP 5.3 incompatibility
  • Widgets now conform to WordPress 2.8 standards
Download this release

Release Info

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

Code changes from version 2.5 to 2.6

Files changed (2) hide show
  1. readme.txt +31 -7
  2. search-meter.php +144 -52
readme.txt CHANGED
@@ -3,8 +3,8 @@ 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: 1.5
6
- Tested up to: 2.8
7
- Stable tag: 2.5
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
 
@@ -32,9 +32,9 @@ If you have an older version of WordPress, download and unzip the search-meter.z
32
 
33
  = Widgets: Popular and Recent Searches =
34
 
35
- The Popular Searches widget displays a list of the most popular successful search terms on your blog during the last 30 days. The Recent Searches widget displays a simple list of the most recent successful search terms. In both cases, the search terms in the lists are hyperlinked to the actual search results; readers can click the search term to show the results for that search. Also, you can configure the maximum number of searches that each widget will display.
36
 
37
- To add these widgets to your sidebar, log in to WordPress Admin, go to the Appearance section and click Widgets. You can drag the appropriate widget to the sidebar of your choice, and click the Edit button to set the number of searches to display.
38
 
39
  = Template Tags =
40
 
@@ -69,6 +69,11 @@ The [Search Meter home page](http://www.thunderguy.com/semicolon/wordpress/searc
69
 
70
  == Changelog ==
71
 
 
 
 
 
 
72
  = 2.5 =
73
  * Improve formatting on the Options page
74
  * Fix database error caused by duplicate searches
@@ -76,7 +81,26 @@ The [Search Meter home page](http://www.thunderguy.com/semicolon/wordpress/searc
76
 
77
  = 2.4 =
78
  * Fix the links to the Statistics and Options pages, which broke in WordPress 2.7.
79
- * Add donation buttons, with an option to hide them. (Thanks for your consideration.)
80
 
81
- = Earlier versions =
82
- * [Contact the author](http://www.thunderguy.com/semicolon/contact/) for details
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: 1.5
6
+ Tested up to: 2.8.4
7
+ Stable tag: 2.6
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
 
32
 
33
  = Widgets: Popular and Recent Searches =
34
 
35
+ The Popular Searches widget displays a list of the most popular successful search terms on your blog during the last 30 days. The Recent Searches widget displays a simple list of the most recent successful search terms. In both cases, the search terms in the lists are hyperlinked to the actual search results; readers can click the search term to show the results for that search. You can configure the title of each widget, and the maximum number of searches that each widget will display.
36
 
37
+ To add these widgets to your sidebar, log in to WordPress Admin, go to the Appearance section and click Widgets. You can drag the appropriate widget to the sidebar of your choice, and set the title and the number of searches to display.
38
 
39
  = Template Tags =
40
 
69
 
70
  == Changelog ==
71
 
72
+ = 2.6 =
73
+ * Use UTF8 when creating tables
74
+ * Fix PHP 5.3 incompatibility
75
+ * Widgets now conform to WordPress 2.8 standards
76
+
77
  = 2.5 =
78
  * Improve formatting on the Options page
79
  * Fix database error caused by duplicate searches
81
 
82
  = 2.4 =
83
  * Fix the links to the Statistics and Options pages, which broke in WordPress 2.7.
 
84
 
85
+ = 2.3 =
86
+ * Improve widget display and add controls to specify the number of searches to show
87
+ * Add option to hide donation buttons
88
+
89
+ = 2.2 =
90
+ * Add widgets for Recent Searches and Popular Searches
91
+ * Fix table creation problem on WordPress 2.2.1
92
+ * Add donation buttons (thanks for your consideration)
93
+
94
+ = 2.1 =
95
+ * Improve search count accuracy
96
+
97
+ = 2.0 =
98
+ * Add Recent Searches page and template tag
99
+ * Make search counts more accurate: correctly count multi-page searches and searches with no referer [sic]
100
+ * Popular Searches tag allows number of results to be specified.
101
+
102
+ = 1.1 =
103
+ * Various improvements
104
+
105
+ = 1.0 =
106
+ * Initial public release
search-meter.php CHANGED
@@ -3,11 +3,11 @@
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.5
7
  Author: Bennett McElwee
8
  Author URI: http://www.thunderguy.com/semicolon/
9
 
10
- $Revision: 93952 $
11
 
12
 
13
  INSTRUCTIONS
@@ -131,7 +131,6 @@ if (function_exists('register_activation_hook')) {
131
  } else {
132
  add_action('init', 'tguy_sm_init');
133
  }
134
- add_action('init', 'tguy_sm_register_widgets');
135
  add_filter('the_posts', 'tguy_sm_save_search', 20); // run after other plugins
136
  add_action('admin_head', 'tguy_sm_stats_css');
137
  add_action('admin_menu', 'tguy_sm_add_admin_pages');
@@ -147,66 +146,155 @@ function tguy_sm_init() {
147
 
148
  // Widgets
149
 
150
- function sm_list_popular_searches_widget($args) {
151
- $options = get_option('tguy_search_meter');
152
- $number = sm_constrain_widget_search_count((int)$options['popular-searches-number']);
153
- sm_list_popular_searches('<h2 class="widgettitle">Popular Searches</h2>', '', $number);
154
- }
 
155
 
156
- function sm_list_popular_searches_control() {
157
- $options = get_option('tguy_search_meter');
158
- if ($_POST["popular-searches-submit"]) {
159
- $options['popular-searches-number'] = (int) $_POST["popular-searches-number"];
160
- update_option('tguy_search_meter', $options);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  }
162
- $number = sm_constrain_widget_search_count((int)$options['popular-searches-number']);
163
- ?>
164
- <p>This widget shows the most popular successful search terms in the last month.</p>
165
- <p><label for="popular-searches-number"><?php _e('Number of searches to show:'); ?> <input style="width: 5ex; text-align: center;" id="popular-searches-number" name="popular-searches-number" type="text" value="<?php echo $number; ?>" /></label></p>
166
- <p><em>Powered by Search Meter</em></p>
167
- <input type="hidden" id="popular-searches-submit" name="popular-searches-submit" value="1" />
168
- <?php
169
- }
170
 
171
- function sm_list_recent_searches_widget($args) {
172
- $options = get_option('tguy_search_meter');
173
- $number = sm_constrain_widget_search_count((int)$options['recent-searches-number']);
174
- sm_list_recent_searches('<h2 class="widgettitle">Recent Searches</h2>', '', $number);
175
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
 
177
- function sm_list_recent_searches_control() {
178
- $options = get_option('tguy_search_meter');
179
- if ($_POST["recent-searches-submit"]) {
180
- $options['recent-searches-number'] = (int) $_POST["recent-searches-number"];
181
- update_option('tguy_search_meter', $options);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  }
183
- $number = sm_constrain_widget_search_count((int)$options['recent-searches-number']);
184
- ?>
185
- <p>This widget shows the most recent successful search terms.</p>
186
- <p><label for="recent-searches-number"><?php _e('Number of searches to show:'); ?> <input style="width: 5ex; text-align: center;" id="recent-searches-number" name="recent-searches-number" type="text" value="<?php echo $number; ?>" /></label></p>
187
- <p><em>Powered by Search Meter</em></p>
188
- <input type="hidden" id="recent-searches-submit" name="recent-searches-submit" value="1" />
189
- <?php
190
  }
191
 
192
  function sm_constrain_widget_search_count($number) {
193
  return max(1, min((int)$number, 100));
194
  }
195
 
196
- function tguy_sm_register_widgets() {
197
- if (function_exists('register_sidebar_widget') ) {
198
- register_sidebar_widget('Recent Searches', 'sm_list_recent_searches_widget', 'recent_searches');
199
- register_sidebar_widget('Popular Searches', 'sm_list_popular_searches_widget', 'popular_searches');
200
- register_widget_control('Recent Searches', 'sm_list_recent_searches_control', '', '120px');
201
- register_widget_control('Popular Searches', 'sm_list_popular_searches_control', '', '120px');
202
- }
203
- }
204
-
205
  // Keep track of how many times SM has been called for this request.
206
  // Normally we only record the first time.
207
  $tguy_sm_action_count = 0;
208
 
209
- function tguy_sm_save_search(&$posts) {
210
  // Check if the request is a search, and if so then save details.
211
  // This is a filter but does not change the posts.
212
  global $wpdb, $wp_query, $table_prefix, $tguy_sm_action_count;
@@ -294,13 +382,15 @@ function tguy_sm_create_summary_table() {
294
  } else { // Wordpress 2.2 or earlier
295
  require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
296
  }
297
- dbDelta("CREATE TABLE `{$table_name}` (
 
298
  `terms` VARCHAR(50) NOT NULL,
299
  `date` DATE NOT NULL,
300
  `count` INT(11) NOT NULL,
301
  `last_hits` INT(11) NOT NULL,
302
  PRIMARY KEY (`terms`,`date`)
303
- );
 
304
  ");
305
  }
306
  }
@@ -315,13 +405,15 @@ function tguy_sm_create_recent_table() {
315
  } else { // Wordpress 2.2 or earlier
316
  require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
317
  }
318
- dbDelta("CREATE TABLE `{$table_name}` (
 
319
  `terms` VARCHAR(50) NOT NULL,
320
  `datetime` DATETIME NOT NULL,
321
  `hits` INT(11) NOT NULL,
322
  `details` TEXT NOT NULL,
323
  KEY `datetimeindex` (`datetime`)
324
- );
 
325
  ");
326
  }
327
  }
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.6
7
  Author: Bennett McElwee
8
  Author URI: http://www.thunderguy.com/semicolon/
9
 
10
+ $Revision: 159273 $
11
 
12
 
13
  INSTRUCTIONS
131
  } else {
132
  add_action('init', 'tguy_sm_init');
133
  }
 
134
  add_filter('the_posts', 'tguy_sm_save_search', 20); // run after other plugins
135
  add_action('admin_head', 'tguy_sm_stats_css');
136
  add_action('admin_menu', 'tguy_sm_add_admin_pages');
146
 
147
  // Widgets
148
 
149
+ if (version_compare($wp_version, '2.8', '>=')) {
150
+ add_action('widgets_init', 'tguy_sm_register_widgets');
151
+ function tguy_sm_register_widgets() {
152
+ register_widget('SM_Popular_Searches_Widget');
153
+ register_widget('SM_Recent_Searches_Widget');
154
+ }
155
 
156
+ class SM_Popular_Searches_Widget extends WP_Widget {
157
+ function SM_Popular_Searches_Widget() {
158
+ $widget_ops = array('classname' => 'widget_search_meter', 'description' => __( "A list of the most popular successful searches in the last month"));
159
+ $this->WP_Widget('popular_searches', __('Popular Searches'), $widget_ops);
160
+ }
161
+
162
+ function widget($args, $instance) {
163
+ extract($args);
164
+ $title = apply_filters('widget_title', empty($instance['popular-searches-title']) ? __('Popular Searches') : $instance['popular-searches-title']);
165
+ $count = (int) (empty($instance['popular-searches-number']) ? 5 : $instance['popular-searches-number']);
166
+
167
+ echo $before_widget;
168
+ if ($title) {
169
+ echo $before_title . $title . $after_title;
170
+ }
171
+ sm_list_popular_searches('', '', sm_constrain_widget_search_count($count));
172
+ echo $after_widget;
173
+ }
174
+
175
+ function update($new_instance, $old_instance){
176
+ $instance = $old_instance;
177
+ $instance['popular-searches-title'] = strip_tags(stripslashes($new_instance['popular-searches-title']));
178
+ $instance['popular-searches-number'] = (int) ($new_instance['popular-searches-number']);
179
+ return $instance;
180
+ }
181
+
182
+ function form($instance){
183
+ //Defaults
184
+ $instance = wp_parse_args((array) $instance, array('popular-searches-title' => 'Popular Searches', 'popular-searches-number' => 5));
185
+
186
+ $title = htmlspecialchars($instance['popular-searches-title']);
187
+ $count = htmlspecialchars($instance['popular-searches-number']);
188
+
189
+ # Output the options
190
+ echo '<p><label for="' . $this->get_field_name('popular-searches-title') . '">' . __('Title:') . ' <input class="widefat" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('popular-searches-title') . '" type="text" value="' . $title . '" /></label></p>';
191
+ echo '<p><label for="' . $this->get_field_name('popular-searches-number') . '">' . __('Number of searches to show:') . ' <input id="' . $this->get_field_id('popular-searches-number') . '" name="' . $this->get_field_name('popular-searches-number') . '" type="text" value="' . $count . '" size="3" /></label></p>';
192
+ echo '<p><small>Powered by Search Meter</small></p>';
193
+ }
194
  }
 
 
 
 
 
 
 
 
195
 
196
+ class SM_Recent_Searches_Widget extends WP_Widget {
197
+ function SM_Recent_Searches_Widget() {
198
+ $widget_ops = array('classname' => 'widget_search_meter', 'description' => __( "A list of the most recent successful searches on your blog"));
199
+ $this->WP_Widget('recent_searches', __('Recent Searches'), $widget_ops);
200
+ }
201
+
202
+ function widget($args, $instance) {
203
+ extract($args);
204
+ $title = apply_filters('widget_title', empty($instance['recent-searches-title']) ? __('Recent Searches') : $instance['recent-searches-title']);
205
+ $count = (int) (empty($instance['recent-searches-number']) ? 5 : $instance['recent-searches-number']);
206
+
207
+ echo $before_widget;
208
+ if ($title) {
209
+ echo $before_title . $title . $after_title;
210
+ }
211
+ sm_list_recent_searches('', '', sm_constrain_widget_search_count($count));
212
+ echo $after_widget;
213
+ }
214
+
215
+ function update($new_instance, $old_instance){
216
+ $instance = $old_instance;
217
+ $instance['recent-searches-title'] = strip_tags(stripslashes($new_instance['recent-searches-title']));
218
+ $instance['recent-searches-number'] = (int) ($new_instance['recent-searches-number']);
219
+ return $instance;
220
+ }
221
+
222
+ function form($instance){
223
+ //Defaults
224
+ $instance = wp_parse_args((array) $instance, array('recent-searches-title' => 'Recent Searches', 'recent-searches-number' => 5));
225
+
226
+ $title = htmlspecialchars($instance['recent-searches-title']);
227
+ $count = htmlspecialchars($instance['recent-searches-number']);
228
+
229
+ # Output the options
230
+ echo '<p><label for="' . $this->get_field_name('recent-searches-title') . '">' . __('Title:') . ' <input class="widefat" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('recent-searches-title') . '" type="text" value="' . $title . '" /></label></p>';
231
+ echo '<p><label for="' . $this->get_field_name('recent-searches-number') . '">' . __('Number of searches to show:') . ' <input id="' . $this->get_field_id('recent-searches-number') . '" name="' . $this->get_field_name('recent-searches-number') . '" type="text" value="' . $count . '" size="3" /></label></p>';
232
+ echo '<p><small>Powered by Search Meter</small></p>';
233
+ }
234
+ }
235
+ } else {
236
+ add_action('init', 'tguy_sm_register_widgets');
237
+ function tguy_sm_register_widgets() {
238
+ if (function_exists('register_sidebar_widget') ) {
239
+ register_sidebar_widget('Recent Searches', 'sm_list_recent_searches_widget', 'recent_searches');
240
+ register_sidebar_widget('Popular Searches', 'sm_list_popular_searches_widget', 'popular_searches');
241
+ register_widget_control('Recent Searches', 'sm_list_recent_searches_control', '', '120px');
242
+ register_widget_control('Popular Searches', 'sm_list_popular_searches_control', '', '120px');
243
+ }
244
+ }
245
 
246
+ function sm_list_popular_searches_widget($args) {
247
+ $options = get_option('tguy_search_meter');
248
+ $number = sm_constrain_widget_search_count((int)$options['popular-searches-number']);
249
+ sm_list_popular_searches('<h2 class="widgettitle">Popular Searches</h2>', '', $number);
250
+ }
251
+
252
+ function sm_list_popular_searches_control() {
253
+ $options = get_option('tguy_search_meter');
254
+ if ($_POST["popular-searches-submit"]) {
255
+ $options['popular-searches-number'] = (int) $_POST["popular-searches-number"];
256
+ update_option('tguy_search_meter', $options);
257
+ }
258
+ $number = sm_constrain_widget_search_count((int)$options['popular-searches-number']);
259
+ ?>
260
+ <p>This widget shows the most popular searches in the last month. Only successful searches are listed.</p>
261
+ <p><label for="popular-searches-number"><?php _e('Number of searches to show:'); ?> <input style="width: 5ex; text-align: center;" id="popular-searches-number" name="popular-searches-number" type="text" value="<?php echo $number; ?>" /></label></p>
262
+ <p><em>Powered by Search Meter</em></p>
263
+ <input type="hidden" id="popular-searches-submit" name="popular-searches-submit" value="1" />
264
+ <?php
265
+ }
266
+
267
+ function sm_list_recent_searches_widget($args) {
268
+ $options = get_option('tguy_search_meter');
269
+ $number = sm_constrain_widget_search_count((int)$options['recent-searches-number']);
270
+ sm_list_recent_searches('<h2 class="widgettitle">Recent Searches</h2>', '', $number);
271
+ }
272
+
273
+ function sm_list_recent_searches_control() {
274
+ $options = get_option('tguy_search_meter');
275
+ if ($_POST["recent-searches-submit"]) {
276
+ $options['recent-searches-number'] = (int) $_POST["recent-searches-number"];
277
+ update_option('tguy_search_meter', $options);
278
+ }
279
+ $number = sm_constrain_widget_search_count((int)$options['recent-searches-number']);
280
+ ?>
281
+ <p>This widget shows what people have recently searched for. Only successful searches are listed.</p>
282
+ <p><label for="recent-searches-number"><?php _e('Number of searches to show:'); ?> <input style="width: 5ex; text-align: center;" id="recent-searches-number" name="recent-searches-number" type="text" value="<?php echo $number; ?>" /></label></p>
283
+ <p><em>Powered by Search Meter</em></p>
284
+ <input type="hidden" id="recent-searches-submit" name="recent-searches-submit" value="1" />
285
+ <?php
286
  }
 
 
 
 
 
 
 
287
  }
288
 
289
  function sm_constrain_widget_search_count($number) {
290
  return max(1, min((int)$number, 100));
291
  }
292
 
 
 
 
 
 
 
 
 
 
293
  // Keep track of how many times SM has been called for this request.
294
  // Normally we only record the first time.
295
  $tguy_sm_action_count = 0;
296
 
297
+ function tguy_sm_save_search($posts) {
298
  // Check if the request is a search, and if so then save details.
299
  // This is a filter but does not change the posts.
300
  global $wpdb, $wp_query, $table_prefix, $tguy_sm_action_count;
382
  } else { // Wordpress 2.2 or earlier
383
  require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
384
  }
385
+ dbDelta("
386
+ CREATE TABLE `{$table_name}` (
387
  `terms` VARCHAR(50) NOT NULL,
388
  `date` DATE NOT NULL,
389
  `count` INT(11) NOT NULL,
390
  `last_hits` INT(11) NOT NULL,
391
  PRIMARY KEY (`terms`,`date`)
392
+ )
393
+ CHARACTER SET utf8 COLLATE utf8_general_ci;
394
  ");
395
  }
396
  }
405
  } else { // Wordpress 2.2 or earlier
406
  require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
407
  }
408
+ dbDelta("
409
+ CREATE TABLE `{$table_name}` (
410
  `terms` VARCHAR(50) NOT NULL,
411
  `datetime` DATETIME NOT NULL,
412
  `hits` INT(11) NOT NULL,
413
  `details` TEXT NOT NULL,
414
  KEY `datetimeindex` (`datetime`)
415
+ )
416
+ CHARACTER SET utf8 COLLATE utf8_general_ci;
417
  ");
418
  }
419
  }