Search Meter - Version 2.9

Version Description

  • Add a Search Meter dashboard widget.
  • Add Search Meter settings link on the Plugins page for convenient configuration.
  • Many small improvements.
Download this release

Release Info

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

Code changes from version 2.8 to 2.9

Files changed (3) hide show
  1. admin.php +609 -0
  2. readme.txt +10 -5
  3. search-meter.php +13 -538
admin.php ADDED
@@ -0,0 +1,609 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
7
+ License as published by the Free Software Foundation.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details, available at
13
+ http://www.gnu.org/copyleft/gpl.html
14
+ */
15
+
16
+ //////// Parameters
17
+
18
+
19
+ define('TGUY_SM_DEFAULT_VIEW_STATS_CAPABILITY', 'publish_posts');
20
+ // Default capability users must have in order to see stats.
21
+
22
+ define('TGUY_SM_OPTIONS_CAPABILITY', 'manage_options');
23
+ // Capability users must have in order to set options.
24
+
25
+
26
+ //////// General admin
27
+
28
+
29
+ add_action('admin_head', 'tguy_sm_stats_css');
30
+
31
+ function tguy_sm_stats_css() {
32
+ ?>
33
+ <style type="text/css">
34
+ #search_meter_menu {
35
+ line-height: 1.4em;
36
+ margin: 5px 0 0 0;
37
+ padding: 0;
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 {
58
+ padding: 0 5px;
59
+ text-decoration: none;
60
+ }
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;
70
+ padding-bottom: 1.5em;
71
+ }
72
+ div.sm-stats-table th, div.sm-stats-table td {
73
+ padding-right: 0.5em;
74
+ }
75
+ 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 {
86
+ clear: both;
87
+ }
88
+
89
+ /* Dashboard widget overrides */
90
+ #dashboard_search_meter h4 {
91
+ line-height: 1.7em;
92
+ }
93
+ #dashboard_search_meter div.sm-stats-table {
94
+ float: none;
95
+ padding-bottom: 0;
96
+ padding-right: 0;
97
+ }
98
+ #dashboard_search_meter div.sm-stats-table th {
99
+ color: #8F8F8F;
100
+ }
101
+ #dashboard_search_meter ul.subsubsub {
102
+ float: none;
103
+ }
104
+
105
+ </style>
106
+ <?php
107
+ }
108
+
109
+
110
+ //////// Initialisation
111
+
112
+
113
+ function tguy_sm_init() {
114
+ tguy_sm_create_summary_table();
115
+ tguy_sm_create_recent_table();
116
+ }
117
+
118
+ function tguy_sm_create_summary_table() {
119
+ // Create the table if not already there.
120
+ global $wpdb;
121
+ $table_name = $wpdb->prefix . "searchmeter";
122
+ if ($wpdb->get_var("show tables like '$table_name'") != $table_name) {
123
+ require_once(ABSPATH . '/wp-admin/includes/upgrade.php');
124
+ dbDelta("
125
+ CREATE TABLE `{$table_name}` (
126
+ `terms` VARCHAR(50) NOT NULL,
127
+ `date` DATE NOT NULL,
128
+ `count` INT(11) NOT NULL,
129
+ `last_hits` INT(11) NOT NULL,
130
+ PRIMARY KEY (`terms`,`date`)
131
+ )
132
+ CHARACTER SET utf8 COLLATE utf8_general_ci;
133
+ ");
134
+ }
135
+ }
136
+
137
+ function tguy_sm_create_recent_table() {
138
+ // Create the table if not already there.
139
+ global $wpdb;
140
+ $table_name = $wpdb->prefix . "searchmeter_recent";
141
+ if ($wpdb->get_var("show tables like '$table_name'") != $table_name) {
142
+ require_once(ABSPATH . '/wp-admin/includes/upgrade.php');
143
+ dbDelta("
144
+ CREATE TABLE `{$table_name}` (
145
+ `terms` VARCHAR(50) NOT NULL,
146
+ `datetime` DATETIME NOT NULL,
147
+ `hits` INT(11) NOT NULL,
148
+ `details` TEXT NOT NULL,
149
+ KEY `datetimeindex` (`datetime`)
150
+ )
151
+ CHARACTER SET utf8 COLLATE utf8_general_ci;
152
+ ");
153
+ }
154
+ }
155
+
156
+
157
+ //////// Permissions
158
+
159
+
160
+ function smcln_sm_can_view_stats() {
161
+ $options = get_option('tguy_search_meter');
162
+ $view_stats_capability = tguy_sm_array_value($options, 'sm_view_stats_capability');
163
+ if ($view_stats_capability == '') {
164
+ $view_stats_capability = TGUY_SM_DEFAULT_VIEW_STATS_CAPABILITY;
165
+ }
166
+ return current_user_can($view_stats_capability);
167
+ }
168
+
169
+
170
+ //////// Dashboard widget
171
+
172
+ add_action('wp_dashboard_setup', 'smcln_sm_dashboard');
173
+
174
+ // Add the widget to the dashboard
175
+ function smcln_sm_dashboard() {
176
+ if (smcln_sm_can_view_stats()) {
177
+ wp_add_dashboard_widget( 'dashboard_search_meter', 'Search Meter', 'smcln_sm_summary');
178
+ }
179
+ }
180
+
181
+ // Render the summary widget
182
+ function smcln_sm_summary() {
183
+ ?>
184
+ <div class="sm-stats-table">
185
+ <h4>Searches in the Last 7 Days</h4>
186
+ <?php tguy_sm_summary_table(7); ?>
187
+ </div>
188
+ <ul class="subsubsub">
189
+ <li><a href="index.php?page=<?php echo plugin_basename(__FILE__); ?>">Full Dashboard</a> |</li>
190
+ <?php if (current_user_can(TGUY_SM_OPTIONS_CAPABILITY)) : ?>
191
+ <li><a href="options-general.php?page=<?php echo plugin_basename(__FILE__); ?>">Settings</a> |</li>
192
+ <?php endif; ?>
193
+ <li><a href="http://thunderguy.com/semicolon/donate/">Donate</a></li>
194
+ </ul>
195
+ <?php
196
+ }
197
+
198
+
199
+ //////// Admin pages
200
+
201
+
202
+ add_action('admin_menu', 'tguy_sm_add_admin_pages');
203
+
204
+ function tguy_sm_add_admin_pages() {
205
+ $options = get_option('tguy_search_meter');
206
+ $view_stats_capability = tguy_sm_array_value($options, 'sm_view_stats_capability');
207
+ if ($view_stats_capability == '') {
208
+ $view_stats_capability = TGUY_SM_DEFAULT_VIEW_STATS_CAPABILITY;
209
+ }
210
+ add_submenu_page('index.php', 'Search Meter', 'Search Meter', $view_stats_capability, __FILE__, 'tguy_sm_stats_page');
211
+ add_options_page('Search Meter', 'Search Meter', TGUY_SM_OPTIONS_CAPABILITY, __FILE__, 'tguy_sm_options_page');
212
+ }
213
+
214
+
215
+ //////// Statistics pages
216
+
217
+
218
+ function tguy_sm_stats_page() {
219
+ if (array_key_exists('recent', $_GET)) {
220
+ $recent_count = intval($_GET['recent']);
221
+ $do_show_details = array_key_exists('details', $_GET) && $_GET['details'];
222
+ tguy_sm_recent_page($recent_count, $do_show_details);
223
+ } else {
224
+ tguy_sm_summary_page();
225
+ }
226
+ }
227
+
228
+ function tguy_sm_summary_page() {
229
+ global $wpdb;
230
+
231
+ $options = get_option('tguy_search_meter');
232
+ $is_disable_donation = $options['sm_disable_donation'];
233
+
234
+ // Delete old records
235
+ $result = $wpdb->query(
236
+ "DELETE FROM `{$wpdb->prefix}searchmeter`
237
+ WHERE `date` < DATE_SUB( CURDATE() , INTERVAL 30 DAY)");
238
+ echo "<!-- Search Meter: deleted $result old rows -->\n";
239
+ ?>
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>
247
+
248
+ <h2>Search summary</h2>
249
+
250
+ <p>These tables show the most popular searches on your blog for the given time periods. <strong>Term</strong> is the text that was searched for; you can click it to see which posts contain that term. (This won't be counted as another search.) <strong>Searches</strong> is the number of times the term was searched for. <strong>Results</strong> is the number of posts that were returned from the <em>last</em> search for that term.</p>
251
+
252
+ <div class="sm-stats-table">
253
+ <h3>Yesterday and today</h3>
254
+ <?php tguy_sm_summary_table(1); ?>
255
+ </div>
256
+ <div class="sm-stats-table">
257
+ <h3>Last 7 days</h3>
258
+ <?php tguy_sm_summary_table(7); ?>
259
+ </div>
260
+ <div class="sm-stats-table">
261
+ <h3>Last 30 days</h3>
262
+ <?php tguy_sm_summary_table(30); ?>
263
+ </div>
264
+ <div class="sm-stats-clear"></div>
265
+
266
+ <h2>Unsuccessful search summary</h2>
267
+
268
+ <p>These tables show only the search terms for which the last search yielded no results. People are searching your blog for these terms; maybe you should give them what they want.</p>
269
+
270
+ <div class="sm-stats-table">
271
+ <h3>Yesterday and today</h3>
272
+ <?php tguy_sm_summary_table(1, false); ?>
273
+ </div>
274
+ <div class="sm-stats-table">
275
+ <h3>Last 7 days</h3>
276
+ <?php tguy_sm_summary_table(7, false); ?>
277
+ </div>
278
+ <div class="sm-stats-table">
279
+ <h3>Last 30 days</h3>
280
+ <?php tguy_sm_summary_table(30, false); ?>
281
+ </div>
282
+ <div class="sm-stats-clear"></div>
283
+
284
+ <h2>Notes</h2>
285
+
286
+ <?php if (current_user_can(TGUY_SM_OPTIONS_CAPABILITY)) : ?>
287
+ <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>
288
+ <?php endif; ?>
289
+
290
+ <p>For information and updates, see the <a href="http://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>
291
+
292
+ <?php if (!$options['sm_disable_donation']) { tguy_sm_show_donation_message(); } ?>
293
+
294
+ </div>
295
+ <?php
296
+ }
297
+
298
+ function tguy_sm_summary_table($days, $do_include_successes = true) {
299
+ global $wpdb;
300
+ // Explanation of the query:
301
+ // We group by terms, because we want all rows for a term to be combined.
302
+ // For the search count, we simply SUM the count of all searches for the term.
303
+ // For the result count, we only want the number of results for the latest search. Each row
304
+ // contains the result for the latest search on that row's date. So for each date,
305
+ // CONCAT the date with the number of results, and take the MAX. This gives us the
306
+ // latest date combined with its hit count. Then strip off the date with SUBSTRING.
307
+ // This Rube Goldberg-esque procedure should work in older MySQL versions that
308
+ // don't allow subqueries. It's inefficient, but that doesn't matter since it's
309
+ // only used in admin pages and the tables involved won't be too big.
310
+ $hits_selector = $do_include_successes ? '' : 'HAVING hits = 0';
311
+ $results = $wpdb->get_results(
312
+ "SELECT `terms`,
313
+ SUM( `count` ) AS countsum,
314
+ SUBSTRING( MAX( CONCAT( `date` , ' ', `last_hits` ) ) , 12 ) AS hits
315
+ FROM `{$wpdb->prefix}searchmeter`
316
+ WHERE DATE_SUB( CURDATE( ) , INTERVAL $days DAY ) <= `date`
317
+ GROUP BY `terms`
318
+ $hits_selector
319
+ ORDER BY countsum DESC, `terms` ASC
320
+ LIMIT 20");
321
+ if (count($results)) {
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
329
+ }
330
+ ?></tr><?php
331
+ $class= '';
332
+ foreach ($results as $result) {
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' : '');
344
+ }
345
+ ?>
346
+ </tbody>
347
+ </table>
348
+ <?php
349
+ } else {
350
+ ?><p><em>No searches recorded for this period.</em></p><?php
351
+ }
352
+ }
353
+
354
+ function tguy_sm_recent_page($max_lines, $do_show_details) {
355
+ global $wpdb;
356
+
357
+ $options = get_option('tguy_search_meter');
358
+ $is_details_available = $options['sm_details_verbose'];
359
+ $is_disable_donation = $options['sm_disable_donation'];
360
+ $this_url_base = 'index.php?page=' . plugin_basename(__FILE__);
361
+ $this_url_recent_arg = '&amp;recent=' . $max_lines;
362
+ ?>
363
+ <div class="wrap">
364
+
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 ?>
377
+ </ul>
378
+
379
+ <h2>Recent searches</h2>
380
+
381
+ <p>This table shows the last <?php echo $max_lines; ?> searches on this blog. <strong>Term</strong> is the text that was searched for; you can click it to see which posts contain that term. (This won't be counted as another search.) <strong>Results</strong> is the number of posts that were returned from the search.
382
+ </p>
383
+
384
+ <div class="sm-stats-table">
385
+ <?php
386
+ $query =
387
+ "SELECT `datetime`, `terms`, `hits`, `details`
388
+ FROM `{$wpdb->prefix}searchmeter_recent`
389
+ ORDER BY `datetime` DESC, `terms` ASC
390
+ LIMIT $max_lines";
391
+ $results = $wpdb->get_results($query);
392
+ if (count($results)) {
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
404
+ $class= '';
405
+ foreach ($results as $result) {
406
+ ?>
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 ?>
414
+ </tr>
415
+ <?php
416
+ $class = ($class == '' ? 'alternate' : '');
417
+ }
418
+ ?>
419
+ </tbody>
420
+ </table>
421
+ <?php
422
+ } else {
423
+ ?><p>No searches recorded.</p><?php
424
+ }
425
+ ?>
426
+ </div>
427
+ <div class="sm-stats-clear"></div>
428
+
429
+ <h2>Notes</h2>
430
+
431
+ <?php if (current_user_can(TGUY_SM_OPTIONS_CAPABILITY)) : ?>
432
+ <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>
433
+ <?php endif; ?>
434
+
435
+ <p>For information and updates, see the <a href="http://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>
436
+
437
+ <?php if (!$options['sm_disable_donation']) { tguy_sm_show_donation_message(); } ?>
438
+
439
+ </div>
440
+ <?php
441
+ }
442
+
443
+
444
+ //////// Plugins page
445
+
446
+
447
+ // Add settings link on plugin page
448
+ add_filter('plugin_action_links_'.plugin_basename(dirname(__FILE__).'/search-meter.php'), 'tguy_sm_settings_link' );
449
+
450
+ function tguy_sm_settings_link($links) {
451
+ if (current_user_can(TGUY_SM_OPTIONS_CAPABILITY)) {
452
+ $settings_link = '<a href="options-general.php?page='.plugin_basename(__FILE__).'">Settings</a>';
453
+ array_unshift($links, $settings_link);
454
+ }
455
+ return $links;
456
+ }
457
+
458
+
459
+ //////// Options page
460
+
461
+
462
+ function tguy_sm_options_page() {
463
+ if (isset($_POST['submitted'])) {
464
+ check_admin_referer('search-meter-update-options_all');
465
+ $options = get_option('tguy_search_meter');
466
+ $options['sm_view_stats_capability'] = ($_POST['sm_view_stats_capability']);
467
+ $sm_filter_words = $_POST['sm_filter_words'];
468
+ if (get_magic_quotes_gpc()) {
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);
475
+ echo '<div id="message" class="updated fade"><p><strong>Plugin settings saved.</strong></p></div>';
476
+ } else if (isset($_POST['tguy_sm_reset'])) {
477
+ check_admin_referer('search-meter-reset-stats');
478
+ tguy_sm_reset_stats();
479
+ echo '<div id="message" class="updated fade"><p><strong>Statistics have been reset.</strong></p></div>';
480
+ }
481
+ $options = get_option('tguy_search_meter');
482
+ $view_stats_capability = tguy_sm_array_value($options, 'sm_view_stats_capability');
483
+ if ($view_stats_capability == '') {
484
+ $view_stats_capability = TGUY_SM_DEFAULT_VIEW_STATS_CAPABILITY;
485
+ }
486
+ ?>
487
+ <div class="wrap">
488
+
489
+ <h2>Search Meter Settings</h2>
490
+
491
+ <form name="searchmeter" action="" method="post">
492
+ <?php
493
+ if (function_exists('wp_nonce_field')) {
494
+ wp_nonce_field('search-meter-update-options_all');
495
+ }
496
+ ?>
497
+
498
+ <input type="hidden" name="submitted" value="1" />
499
+
500
+ <table class="form-table">
501
+ <tr>
502
+ <th scope="row">Show statistics to</th>
503
+ <td>
504
+ <fieldset>
505
+ <label title='Users with "read" capability'>
506
+ <input type="radio" name="sm_view_stats_capability" value="read"
507
+ <?php echo ($view_stats_capability=='read'?"checked=\"checked\"":"") ?> />
508
+ All logged-in users</label><br>
509
+ <label title='Users with "publish_posts" capability'>
510
+ <input type="radio" name="sm_view_stats_capability" value="publish_posts"
511
+ <?php echo ($view_stats_capability=='publish_posts'?"checked=\"checked\"":"") ?> />
512
+ Post authors and administrators</label><br>
513
+ <label title='Users with "manage_options" capability'>
514
+ <input type="radio" name="sm_view_stats_capability" value="manage_options"
515
+ <?php echo ($view_stats_capability=='manage_options'?"checked=\"checked\"":"") ?> />
516
+ Administrators only</label>
517
+ </fieldset>
518
+ </td>
519
+ </tr>
520
+ <tr valign="top">
521
+ <th scope="row">Search filter</th>
522
+ <td>
523
+ <fieldset>
524
+ <label for="sm_filter_words">When a search term contains any of these words, it will be filtered
525
+ and will not show up in the Recent Searches or Popular Searches widgets. This will match inside words,
526
+ so &#8220;press&#8221; will match &#8220;WordPress&#8221;.</label>
527
+ <textarea name="sm_filter_words" rows="3" cols="40" id="sm_filter_words" class="large-text code"><?php echo esc_html(tguy_sm_array_value($options, 'sm_filter_words')); ?></textarea>
528
+ </fieldset>
529
+ </td>
530
+ </tr>
531
+ <tr>
532
+ <th class="th-full" scope="row" colspan="2">
533
+ <label for="sm_details_verbose">
534
+ <input type="checkbox" id="sm_details_verbose" name="sm_details_verbose" <?php echo (tguy_sm_array_value($options, 'sm_details_verbose') ? 'checked="checked"' : '') ?> />
535
+ Keep detailed information about recent searches (taken from HTTP headers)
536
+ </label>
537
+ </th>
538
+ </tr>
539
+ <tr>
540
+ <th class="th-full" scope="row" colspan="2">
541
+ <label for="sm_disable_donation">
542
+ <input type="checkbox" id="sm_disable_donation" name="sm_disable_donation" <?php echo (tguy_sm_array_value($options, 'sm_disable_donation') ? 'checked="checked"' : '') ?> />
543
+ Hide the &#8220;Do you find this plugin useful?&#8221; box
544
+ </label>
545
+ </th>
546
+ </tr>
547
+ </table>
548
+
549
+ <p class="submit">
550
+ <input name="Submit" class="button-primary" value="Save Changes" type="submit">
551
+ </p>
552
+ </form>
553
+
554
+ <h3>Reset statistics</h3>
555
+
556
+ <p>Click this button to reset all search statistics. This will delete all information about previous searches.</p>
557
+
558
+ <form name="tguy_sm_admin" action="" method="post">
559
+ <?php
560
+ if (function_exists('wp_nonce_field')) {
561
+ wp_nonce_field('search-meter-reset-stats');
562
+ }
563
+ ?>
564
+ <p class="submit">
565
+ <input name="tguy_sm_reset" class="button-secondary delete" value="Reset Statistics" type="submit" onclick="return confirm('You are about to delete all saved search statistics.\n \'Cancel\' to stop, \'OK\' to delete.');" />
566
+ </p>
567
+ </form>
568
+
569
+ <h3>Notes</h3>
570
+
571
+ <p>To see your search statistics, go to the <a href="index.php?page=<?php echo plugin_basename(__FILE__); ?>">Search Meter Dashboard</a>.</p>
572
+
573
+ <p>For information and updates, see the <a href="http://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>
574
+
575
+ <?php if ( ! tguy_sm_array_value($options, 'sm_disable_donation')) { tguy_sm_show_donation_message(); } ?>
576
+
577
+ </div>
578
+ <?php
579
+ }
580
+
581
+ function tguy_sm_reset_stats() {
582
+ global $wpdb;
583
+ // Delete all records
584
+ $wpdb->query("DELETE FROM `{$wpdb->prefix}searchmeter`");
585
+ $wpdb->query("DELETE FROM `{$wpdb->prefix}searchmeter_recent`");
586
+ }
587
+
588
+ function tguy_sm_show_donation_message() {
589
+ ?>
590
+ <p><div style="margin: 0; padding: 0 2ex 0.25ex 0; float: left;">
591
+ <?php tguy_sm_show_donation_button() ?>
592
+ </div>
593
+ <strong>Do you find this plugin useful?</strong><br />
594
+ I write WordPress plugins because I enjoy doing it, but it does take up a lot
595
+ of my time. If you think this plugin is useful, please consider donating some appropriate
596
+ amount by clicking the <strong>Donate</strong> button. You can also send <strong>Bitcoins</strong>
597
+ to address <tt>1542gqyprvQd7gwvtZZ4x25cPeGWVKg45x</tt>. Thanks!</p>
598
+ <?php
599
+ }
600
+
601
+ function tguy_sm_show_donation_button() {
602
+ // I wish PayPal offered a simple little REST-style URL instead of this monstrosity
603
+ ?><form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="margin:0; padding:0;"
604
+ ><input name="cmd" value="_s-xclick" type="hidden" style="margin:0; padding:0;"
605
+ /><input src="https://www.paypal.com/en_US/i/btn/x-click-but04.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!" border="0" type="image" style="margin:0; padding:0;"
606
+ /><input name="encrypted" value="-----BEGIN PKCS7-----MIIHXwYJKoZIhvcNAQcEoIIHUDCCB0wCAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJKoZIhvcNAQEBBQAEgYA7BglQn0K1FJvdqm+zAop0IFZb02mJnn56wpZYpbqWE6go360iySXAwUS8eMEMSxp2/OUmWh6VQzm07kEP0buqLG0wwi4yOwawTYB2cahVUPadwYA+KyE78xQI4plMGO1LRchjNdVPkjF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 " type="hidden" style="margin:0; padding:0;"
608
+ /></form><?php
609
+ }
readme.txt CHANGED
@@ -1,9 +1,9 @@
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.
@@ -18,7 +18,7 @@ Search Meter installs easily and requires no configuration. Just install it, act
18
 
19
  = View Statistics =
20
 
21
- To see your search statistics, Log in to WordPress Admin, go to the Dashboard section and click Search Meter. You'll see the most popular searches in the last day, week and month. Click "Last 100 Searches" or "Last 500 Searches" to see lists of all recent searches.
22
 
23
  = Manage Statistics =
24
 
@@ -65,11 +65,11 @@ Show a simple list of the 5 most recent successful search terms, hyperlinked to
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.
73
 
74
  == Screenshots ==
75
 
@@ -77,6 +77,11 @@ The [Search Meter home page](http://www.thunderguy.com/semicolon/wordpress/searc
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.
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: 3.4.1
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.
18
 
19
  = View Statistics =
20
 
21
+ To see your search statistics, Log in to WordPress Admin. On your dashboard you will see a Search Meter widget listing search statistics from the last seven days. For more details, go to the Dashboard menu on the left and click Search Meter. You'll see the most popular searches in the last day, week and month. Click "Last 100 Searches" or "Last 500 Searches" to see lists of all recent searches.
22
 
23
  = Manage Statistics =
24
 
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://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://thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/) has more information and a form to submit comments and questions.
73
 
74
  == Screenshots ==
75
 
77
 
78
  == Changelog ==
79
 
80
+ = 2.9 =
81
+ * Add a Search Meter dashboard widget.
82
+ * Add Search Meter settings link on the Plugins page for convenient configuration.
83
+ * Many small improvements.
84
+
85
  = 2.8 =
86
  * Fix option for permission level, which was not being saved correctly.
87
  * Allow Search Meter to work with Multisite WordPress.
search-meter.php CHANGED
@@ -1,14 +1,14 @@
1
  <?php
2
  /*
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
@@ -25,12 +25,12 @@ INSTRUCTIONS
25
  * To display recent and popular searches, use the Recent Searches and
26
  Popular Searches widgets, or the sm_list_popular_searches() and
27
  sm_list_recent_searches() template tags.
28
- * For full details, see http://www.thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/
29
 
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
@@ -45,16 +45,12 @@ or by writing to the Free Software Foundation, Inc.,
45
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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
-
58
  // Parameters (you can change these if you know what you're doing)
59
 
60
  define('TGUY_SM_HISTORY_SIZE', 500);
@@ -73,12 +69,11 @@ define('TGUY_SM_ALLOW_DUPLICATE_SAVES', false);
73
  // in the details). This will mess up the stats, but could be useful
74
  // for troubleshooting.
75
 
76
- define('TGUY_SM_DEFAULT_VIEW_STATS_CAPABILITY', 'publish_posts');
77
- // Default capability users must have in order to see stats.
78
-
79
- define('TGUY_SM_OPTIONS_CAPABILITY', 'manage_options');
80
- // Capability users must have in order to set options.
81
 
 
 
 
 
82
 
83
  // Template Tags
84
 
@@ -175,24 +170,12 @@ $sm_escaped_filter_regex = null;
175
  // Hooks
176
 
177
 
178
- if (function_exists('register_activation_hook')) {
179
- register_activation_hook(__FILE__, 'tguy_sm_init');
180
- } else {
181
- add_action('init', 'tguy_sm_init');
182
- }
183
  add_filter('the_posts', 'tguy_sm_save_search', 20); // run after other plugins
184
- add_action('admin_head', 'tguy_sm_stats_css');
185
- add_action('admin_menu', 'tguy_sm_add_admin_pages');
186
 
187
 
188
  // Functionality
189
 
190
 
191
- function tguy_sm_init() {
192
- tguy_sm_create_summary_table();
193
- tguy_sm_create_recent_table();
194
- }
195
-
196
  // Widgets
197
 
198
  add_action('widgets_init', 'tguy_sm_register_widgets');
@@ -299,7 +282,7 @@ function tguy_sm_save_search($posts) {
299
  && !is_paged() // not the second or subsequent page of a previously-counted search
300
  && !is_admin() // not using the administration console
301
  && (1 == $tguy_sm_action_count || TGUY_SM_ALLOW_DUPLICATE_SAVES)
302
- && ($_SERVER['HTTP_REFERER'] || TGUY_SM_ALLOW_EMPTY_REFERER) // proper referrer (otherwise could be search engine, cache...)
303
  ) {
304
  // Get all details of this search
305
  // search string is the raw query
@@ -321,7 +304,7 @@ function tguy_sm_save_search($posts) {
321
  }
322
  foreach (array('REQUEST_URI','REQUEST_METHOD','QUERY_STRING','REMOTE_ADDR','HTTP_USER_AGENT','HTTP_REFERER')
323
  as $header) {
324
- $details .= $header . ': ' . $_SERVER[$header] . "\n";
325
  }
326
  }
327
 
@@ -367,511 +350,3 @@ function tguy_sm_save_search($posts) {
367
  return $posts;
368
  }
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');
377
- } else { // Wordpress 2.2 or earlier
378
- require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
379
- }
380
- dbDelta("
381
- CREATE TABLE `{$table_name}` (
382
- `terms` VARCHAR(50) NOT NULL,
383
- `date` DATE NOT NULL,
384
- `count` INT(11) NOT NULL,
385
- `last_hits` INT(11) NOT NULL,
386
- PRIMARY KEY (`terms`,`date`)
387
- )
388
- CHARACTER SET utf8 COLLATE utf8_general_ci;
389
- ");
390
- }
391
- }
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');
400
- } else { // Wordpress 2.2 or earlier
401
- require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
402
- }
403
- dbDelta("
404
- CREATE TABLE `{$table_name}` (
405
- `terms` VARCHAR(50) NOT NULL,
406
- `datetime` DATETIME NOT NULL,
407
- `hits` INT(11) NOT NULL,
408
- `details` TEXT NOT NULL,
409
- KEY `datetimeindex` (`datetime`)
410
- )
411
- CHARACTER SET utf8 COLLATE utf8_general_ci;
412
- ");
413
- }
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() {
424
- $options = get_option('tguy_search_meter');
425
- $view_stats_capability = tguy_sm_array_value($options, 'sm_view_stats_capability');
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
445
-
446
-
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;
497
- }
498
- div.sm-stats-table .right {
499
- text-align: right;
500
- }
501
- div.sm-stats-clear {
502
- clear: both;
503
- }
504
- </style>
505
- <?php
506
- }
507
-
508
- function tguy_sm_stats_page() {
509
- if (array_key_exists('recent', $_GET)) {
510
- $recent_count = intval($_GET['recent']);
511
- $do_show_details = array_key_exists('details', $_GET) && $_GET['details'];
512
- tguy_sm_recent_page($recent_count, $do_show_details);
513
- } else {
514
- tguy_sm_summary_page();
515
- }
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>
539
-
540
- <p>These tables show the most popular searches on your blog for the given time periods. <strong>Term</strong> is the text that was searched for; you can click it to see which posts contain that term. (This won't be counted as another search.) <strong>Searches</strong> is the number of times the term was searched for. <strong>Results</strong> is the number of posts that were returned from the <em>last</em> search for that term.</p>
541
-
542
- <div class="sm-stats-table">
543
- <h3>Yesterday and today</h3>
544
- <?php tguy_sm_summary_table($results, 1, true); ?>
545
- </div>
546
- <div class="sm-stats-table">
547
- <h3>Last 7 days</h3>
548
- <?php tguy_sm_summary_table($results, 7, true); ?>
549
- </div>
550
- <div class="sm-stats-table">
551
- <h3>Last 30 days</h3>
552
- <?php tguy_sm_summary_table($results, 30, true); ?>
553
- </div>
554
- <div class="sm-stats-clear"></div>
555
-
556
- <h2>Unsuccessful search summary</h2>
557
-
558
- <p>These tables show only the search terms for which the last search yielded no results. People are searching your blog for these terms; maybe you should give them what they want.</p>
559
-
560
- <div class="sm-stats-table">
561
- <h3>Yesterday and today</h3>
562
- <?php tguy_sm_summary_table($results, 1, false); ?>
563
- </div>
564
- <div class="sm-stats-table">
565
- <h3>Last 7 days</h3>
566
- <?php tguy_sm_summary_table($results, 7,false); ?>
567
- </div>
568
- <div class="sm-stats-table">
569
- <h3>Last 30 days</h3>
570
- <?php tguy_sm_summary_table($results, 30, false); ?>
571
- </div>
572
- <div class="sm-stats-clear"></div>
573
-
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>
581
-
582
- <?php if (!$options['sm_disable_donation']) { tguy_sm_show_donation_message(); } ?>
583
-
584
- </div>
585
- <?php
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.
593
- // For the result count, we only want the number of results for the latest search. Each row
594
- // contains the result for the latest search on that row's date. So for each date,
595
- // CONCAT the date with the number of results, and take the MAX. This gives us the
596
- // latest date combined with its hit count. Then strip off the date with SUBSTRING.
597
- // This Rube Goldberg-esque procedure should work in older MySQL versions that
598
- // don't allow subqueries. It's inefficient, but that doesn't matter since it's
599
- // only used in admin pages and the tables involved won't be too big.
600
- $hits_selector = $do_include_successes ? '' : 'HAVING hits = 0';
601
- $results = $wpdb->get_results(
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
609
- ORDER BY countsum DESC, `terms` ASC
610
- LIMIT 20");
611
- if (count($results)) {
612
- ?>
613
- <table cellpadding="3" cellspacing="2">
614
- <tbody>
615
- <tr class="alternate"><th class="left">Term</th><th>Searches</th>
616
- <?php
617
- if ($do_include_successes) {
618
- ?><th>Results</th><?php
619
- }
620
- ?></tr><?php
621
- $class= '';
622
- foreach ($results as $result) {
623
- ?>
624
- <tr class="<?php echo $class ?>">
625
- <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>
626
- <td class="right"><?php echo $result->countsum ?></td>
627
- <?php
628
- if ($do_include_successes) {
629
- ?>
630
- <td class="right"><?php echo $result->hits ?></td></tr>
631
- <?php
632
- }
633
- $class = ($class == '' ? 'alternate' : '');
634
- }
635
- ?>
636
- </tbody>
637
- </table>
638
- <?php
639
- } else {
640
- ?><p>No searches recorded for this period.</p><?php
641
- }
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">
654
-
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
-
669
- <h2>Recent searches</h2>
670
-
671
- <p>This table shows the last <?php echo $max_lines; ?> searches on this blog. <strong>Term</strong> is the text that was searched for; you can click it to see which posts contain that term. (This won't be counted as another search.) <strong>Results</strong> is the number of posts that were returned from the search.
672
- </p>
673
-
674
- <div class="sm-stats-table">
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);
682
- if (count($results)) {
683
- ?>
684
- <table cellpadding="3" cellspacing="2">
685
- <tbody>
686
- <tr class="alternate"><th class="left">Date &amp; time</th><th class="left">Term</th><th class="right">Results</th>
687
- <?php if ($do_show_details) { ?>
688
- <th class="left">Details</th>
689
- <?php } else if ($is_details_available) { ?>
690
- <th class="left"><a href="<?php echo $this_url_base . $this_url_recent_arg . '&amp;details=1' ?>">Show details</a></th>
691
- <?php } ?>
692
- </tr>
693
- <?php
694
- $class= '';
695
- foreach ($results as $result) {
696
- ?>
697
- <tr valign="top" class="<?php echo $class ?>">
698
- <td><?php echo $result->datetime ?></td>
699
- <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>
700
- <td class="right"><?php echo $result->hits ?></td>
701
- <?php if ($do_show_details) : ?>
702
- <td><?php echo str_replace("\n", "<br />", htmlspecialchars($result->details)) ?></td>
703
- <?php endif ?>
704
- </tr>
705
- <?php
706
- $class = ($class == '' ? 'alternate' : '');
707
- }
708
- ?>
709
- </tbody>
710
- </table>
711
- <?php
712
- } else {
713
- ?><p>No searches recorded.</p><?php
714
- }
715
- ?>
716
- </div>
717
- <div class="sm-stats-clear"></div>
718
-
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>
726
-
727
- <?php if (!$options['sm_disable_donation']) { tguy_sm_show_donation_message(); } ?>
728
-
729
- </div>
730
- <?php
731
- }
732
-
733
-
734
- endif; // if (!is_plugin_page())
735
-
736
-
737
- function tguy_sm_options_page() {
738
- if (isset($_POST['submitted'])) {
739
- check_admin_referer('search-meter-update-options_all');
740
- $options = get_option('tguy_search_meter');
741
- $options['sm_view_stats_capability'] = ($_POST['sm_view_stats_capability']);
742
- $sm_filter_words = $_POST['sm_filter_words'];
743
- if (get_magic_quotes_gpc()) {
744
- $sm_filter_words = stripslashes($sm_filter_words);
745
- }
746
- $options['sm_filter_words'] = preg_replace('/\\s+/', ' ', trim($sm_filter_words));
747
- $options['sm_details_verbose'] = (bool)($_POST['sm_details_verbose']);
748
- $options['sm_disable_donation'] = (bool)($_POST['sm_disable_donation']);
749
- update_option('tguy_search_meter', $options);
750
- echo '<div id="message" class="updated fade"><p><strong>Plugin settings saved.</strong></p></div>';
751
- } else if (isset($_POST['tguy_sm_reset'])) {
752
- check_admin_referer('search-meter-reset-stats');
753
- tguy_sm_reset_stats();
754
- echo '<div id="message" class="updated fade"><p><strong>Statistics have been reset.</strong></p></div>';
755
- }
756
- $options = get_option('tguy_search_meter');
757
- $view_stats_capability = tguy_sm_array_value($options, 'sm_view_stats_capability');
758
- if ($view_stats_capability == '') {
759
- $view_stats_capability = TGUY_SM_DEFAULT_VIEW_STATS_CAPABILITY;
760
- }
761
- ?>
762
- <div class="wrap">
763
-
764
- <h2>Search Meter Options</h2>
765
-
766
- <form name="searchmeter" action="" method="post">
767
- <?php
768
- if (function_exists('wp_nonce_field')) {
769
- wp_nonce_field('search-meter-update-options_all');
770
- }
771
- ?>
772
-
773
- <input type="hidden" name="submitted" value="1" />
774
-
775
- <table class="form-table">
776
- <tr>
777
- <th scope="row">Show statistics to</th>
778
- <td>
779
- <fieldset>
780
- <label title='Users with "read" capability'>
781
- <input type="radio" name="sm_view_stats_capability" value="read"
782
- <?php echo ($view_stats_capability=='read'?"checked=\"checked\"":"") ?> />
783
- All logged-in users</label><br>
784
- <label title='Users with "publish_posts" capability'>
785
- <input type="radio" name="sm_view_stats_capability" value="publish_posts"
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>
793
- </td>
794
- </tr>
795
- <tr valign="top">
796
- <th scope="row">Search filter</th>
797
- <td>
798
- <fieldset>
799
- <label for="sm_filter_words">When a search term contains any of these words, it will be filtered
800
- and will not show up in the Recent Searches or Popular Searches widgets. This will match inside words,
801
- so &#8220;press&#8221; will match &#8220;WordPress&#8221;.</label>
802
- <textarea name="sm_filter_words" rows="3" cols="40" id="sm_filter_words" class="large-text code"><?php echo esc_html(tguy_sm_array_value($options, 'sm_filter_words')); ?></textarea>
803
- </fieldset>
804
- </td>
805
- </tr>
806
- <tr>
807
- <th class="th-full" scope="row" colspan="2">
808
- <label for="sm_details_verbose">
809
- <input type="checkbox" id="sm_details_verbose" name="sm_details_verbose" <?php echo (tguy_sm_array_value($options, 'sm_details_verbose') ? 'checked="checked"' : '') ?> />
810
- Keep detailed information about recent searches (taken from HTTP headers)
811
- </label>
812
- </th>
813
- </tr>
814
- <tr>
815
- <th class="th-full" scope="row" colspan="2">
816
- <label for="sm_disable_donation">
817
- <input type="checkbox" id="sm_disable_donation" name="sm_disable_donation" <?php echo (tguy_sm_array_value($options, 'sm_disable_donation') ? 'checked="checked"' : '') ?> />
818
- Hide the &#8220;Do you find this plugin useful?&#8221; box
819
- </label>
820
- </th>
821
- </tr>
822
- </table>
823
-
824
- <p class="submit">
825
- <input name="Submit" class="button-primary" value="Save Changes" type="submit">
826
- </p>
827
- </form>
828
-
829
- <h3>Reset statistics</h3>
830
-
831
- <p>Click this button to reset all search statistics. This will delete all information about previous searches.</p>
832
-
833
- <form name="tguy_sm_admin" action="" method="post">
834
- <?php
835
- if (function_exists('wp_nonce_field')) {
836
- wp_nonce_field('search-meter-reset-stats');
837
- }
838
- ?>
839
- <p class="submit">
840
- <input name="tguy_sm_reset" class="button-secondary delete" value="Reset Statistics" type="submit" onclick="return confirm('You are about to delete all saved search statistics.\n \'Cancel\' to stop, \'OK\' to delete.');" />
841
- </p>
842
- </form>
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
-
850
- <?php if ( ! tguy_sm_array_value($options, 'sm_disable_donation')) { tguy_sm_show_donation_message(); } ?>
851
-
852
- </div>
853
- <?php
854
- }
855
-
856
- function tguy_sm_show_donation_message() {
857
- ?>
858
- <p><div style="margin: 0; padding: 0 2ex 0.25ex 0; float: left;">
859
- <?php tguy_sm_show_donation_button() ?>
860
- </div>
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
-
869
- function tguy_sm_show_donation_button() {
870
- // I wish PayPal offered a simple little REST-style URL instead of this monstrosity
871
- ?><form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="margin:0; padding:0;"
872
- ><input name="cmd" value="_s-xclick" type="hidden" style="margin:0; padding:0;"
873
- /><input src="https://www.paypal.com/en_US/i/btn/x-click-but04.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!" border="0" type="image" style="margin:0; padding:0;"
874
- /><input name="encrypted" value="-----BEGIN PKCS7-----MIIHXwYJKoZIhvcNAQcEoIIHUDCCB0wCAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQ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MjA3MTEyOTQ5WjAjBgkqhkiG9w0BCQQxFgQUO31wm3aCiCMdh2XIXxIAeS8LfBIwDQYJKoZIhvcNAQEBBQAEgYB3CtAsDm+ZRBkd/XLEhUx0IbaeyK9ymOT8R5EQfSZnoJ+QP05XWBc8zi21wSOiQ8nH9LtN2MtS4GRBAQFU1vbvGxw6bG2gJfggJ1pDPUOtkFgf1YA8At+m2I6G2E+YWx2/QHdfMo3BpTJWQOUka52wjuTmIX9X6+CFMPokF91f0w==-----END PKCS7-----
875
- " type="hidden" style="margin:0; padding:0;"
876
- /></form><?php
877
- }
1
  <?php
2
  /*
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
7
  Author: Bennett McElwee
8
+ Author URI: http://thunderguy.com/semicolon/
9
+ Donate link: http://thunderguy.com/semicolon/donate/
10
 
11
+ $Revision: 594693 $
12
 
13
 
14
  INSTRUCTIONS
25
  * To display recent and popular searches, use the Recent Searches and
26
  Popular Searches widgets, or the sm_list_popular_searches() and
27
  sm_list_recent_searches() template tags.
28
+ * For full details, see http://thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/
29
 
30
  Thanks to Kaufman (http://www.terrik.com/wordpress/) and the many others who have offered suggestions.
31
 
32
 
33
+ Copyright (C) 2005-12 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
45
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
46
  */
47
 
 
48
  // This is here to avoid E_NOTICE when indexing nonexistent array keys. There's probably a better solution. Suggestions are welcome.
49
  function tguy_sm_array_value(&$array, $key) {
50
  return (is_array($array) && array_key_exists($key, $array)) ? $array[$key] : null;
51
  }
52
 
53
 
 
 
 
54
  // Parameters (you can change these if you know what you're doing)
55
 
56
  define('TGUY_SM_HISTORY_SIZE', 500);
69
  // in the details). This will mess up the stats, but could be useful
70
  // for troubleshooting.
71
 
 
 
 
 
 
72
 
73
+ if (is_admin()) {
74
+ require_once dirname(__FILE__) . '/admin.php';
75
+ register_activation_hook(__FILE__, 'tguy_sm_init');
76
+ }
77
 
78
  // Template Tags
79
 
170
  // Hooks
171
 
172
 
 
 
 
 
 
173
  add_filter('the_posts', 'tguy_sm_save_search', 20); // run after other plugins
 
 
174
 
175
 
176
  // Functionality
177
 
178
 
 
 
 
 
 
179
  // Widgets
180
 
181
  add_action('widgets_init', 'tguy_sm_register_widgets');
282
  && !is_paged() // not the second or subsequent page of a previously-counted search
283
  && !is_admin() // not using the administration console
284
  && (1 == $tguy_sm_action_count || TGUY_SM_ALLOW_DUPLICATE_SAVES)
285
+ && (tguy_sm_array_value($_SERVER, 'HTTP_REFERER') || TGUY_SM_ALLOW_EMPTY_REFERER) // proper referrer (otherwise could be search engine, cache...)
286
  ) {
287
  // Get all details of this search
288
  // search string is the raw query
304
  }
305
  foreach (array('REQUEST_URI','REQUEST_METHOD','QUERY_STRING','REMOTE_ADDR','HTTP_USER_AGENT','HTTP_REFERER')
306
  as $header) {
307
+ $details .= $header . ': ' . tguy_sm_array_value($_SERVER, $header) . "\n";
308
  }
309
  }
310
 
350
  return $posts;
351
  }
352