Search Everything - Version 4.0

Version Description

Download this release

Release Info

Developer dancameron
Plugin Icon wp plugin Search Everything
Version 4.0
Comparing to
See all releases

Code changes from version 3.9.9.5 to 4.0

Files changed (5) hide show
  1. options.jpg +0 -0
  2. readme.txt +20 -6
  3. screenshot-1.jpg +0 -0
  4. screenshot-1.jpg.jpg +0 -0
  5. search_everything.php +151 -293
options.jpg DELETED
Binary file
readme.txt CHANGED
@@ -1,16 +1,30 @@
1
  === Plugin Name ===
2
- Contributors: dancameron, few others
3
  Donate link: http://www.amazon.com/gp/registry/wishlist/3EM84J7FVHE6S/ref=wl_web/
4
  Tags: search, comment search, page search, admin, seo
5
- Requires at least: 1.5
6
- Tested up to: 2.2
7
- Stable tag: 3.9.9
8
 
9
  Adds search functionality with little setup. Including options to search pages, excerpts, attachments, drafts, comments and custom fields (metadata).
10
 
11
  == Description ==
12
 
13
- Adds search functionality for almost everything on your site. Including options for searching pages, excerpts, attachments, drafts, comments and custom fields (metadata).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
 
16
 
@@ -39,7 +53,7 @@ Open up a thread in the support forums tagged 'searcheverything' and 'dancameron
39
 
40
  == Screenshots ==
41
 
42
- Screenshot of the options panel ![options panel](/options.jpg "Options")
43
 
44
  == Help ==
45
 
1
  === Plugin Name ===
2
+ Contributors: dancameron
3
  Donate link: http://www.amazon.com/gp/registry/wishlist/3EM84J7FVHE6S/ref=wl_web/
4
  Tags: search, comment search, page search, admin, seo
5
+ Requires at least: 2.1
6
+ Tested up to: 2.3
7
+ Stable tag: 4.0
8
 
9
  Adds search functionality with little setup. Including options to search pages, excerpts, attachments, drafts, comments and custom fields (metadata).
10
 
11
  == Description ==
12
 
13
+ Search Everything increases the ability of the default Wordpress Search, options included:
14
+
15
+ * Search Every Page
16
+ * Search non-password protected pages only
17
+ * Search Every Comment
18
+ * Search only approved comments
19
+ * Search Every Draft
20
+ * Search Every Excerpt
21
+ * Search Every Attachment
22
+ * Search Every Custom Field (metadata)
23
+ * Exclude Posts from search
24
+ * Exclude Categories from search (WP 2.2 only)
25
+
26
+ ... tagging support and category exclusion for WordPress 2.3 coming soon.
27
+
28
 
29
 
30
 
53
 
54
  == Screenshots ==
55
 
56
+ 1. Screenshot of the options panel
57
 
58
  == Help ==
59
 
screenshot-1.jpg CHANGED
Binary file
screenshot-1.jpg.jpg DELETED
Binary file
search_everything.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Search Everything
4
  Plugin URI: http://dancameron.org/wordpress/
5
  Description: Adds search functionality with little setup. Including options to search pages, excerpts, attachments, drafts, comments, tags and custom fields (metadata). Also offers the ability to exclude specific pages and posts. Does not search password-protected content.
6
- Version: 3.9.9.5
7
  Author: Dan Cameron
8
  Author URI: http://dancameron.org/
9
  */
@@ -22,9 +22,9 @@ $logging = 0;
22
  // Load language file
23
  $locale = get_locale();
24
  if ( !empty($locale) )
25
- load_textdomain('SearchEverything', ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) .'/' . 'SE3'.$locale.'.mo');
26
 
27
- function SE3_log($msg) {
28
  global $logging;
29
  if ($logging) {
30
  $fp = fopen("logfile.log","a+");
@@ -37,61 +37,61 @@ function SE3_log($msg) {
37
  }
38
 
39
  //add filters based upon option settings
40
- if ("true" == get_option('SE3_use_page_search')) {
41
- add_filter('posts_where', 'SE3_search_pages');
42
- SE3_log("searching pages");
43
  }
44
 
45
- if ("true" == get_option('SE3_use_excerpt_search')) {
46
- add_filter('posts_where', 'SE3_search_excerpt');
47
- SE3_log("searching excerpts");
48
  }
49
 
50
- if ("true" == get_option('SE3_use_comment_search')) {
51
- add_filter('posts_where', 'SE3_search_comments');
52
- add_filter('posts_join', 'SE3_comments_join');
53
- SE3_log("searching comments");
54
  }
55
 
56
- if ("true" == get_option('SE3_use_draft_search')) {
57
- add_filter('posts_where', 'SE3_search_draft_posts');
58
- SE3_log("searching drafts");
59
  }
60
 
61
- if ("true" == get_option('SE3_use_attachment_search')) {
62
- add_filter('posts_where', 'SE3_search_attachments');
63
- SE3_log("searching attachments");
64
  }
65
 
66
- if ("true" == get_option('SE3_use_metadata_search')) {
67
- add_filter('posts_where', 'SE3_search_metadata');
68
- add_filter('posts_join', 'SE3_search_metadata_join');
69
- SE3_log("searching metadata");
70
  }
71
 
72
- if ("true" == get_option('SE3_exclude_posts')) {
73
- add_filter('posts_where', 'SE3_exclude_posts');
74
- SE3_log("searching excluding posts");
75
  }
76
 
77
 
78
-
79
- if ("true" == get_option('SE3_exclude_categories')) {
80
- add_filter('posts_where', 'SE3_exclude_categories');
81
- add_filter('posts_join', 'SE3_exclude_categories_join');
82
- SE3_log("searching excluding categories");
83
  }
84
 
85
- //Tag Search provided by Thu Tu
86
- if ("true" == get_option('SE3_use_tag_search')) {
87
- add_filter('posts_where', 'SE3_search_tag');
88
- add_filter('posts_join', 'SE3_search_tag_join');
89
- SE3_log("searching tag");
90
  }
91
 
92
  //Duplicate fix provided by Tiago.Pocinho
93
- add_filter('posts_request', 'SE3_distinct');
94
- function SE3_distinct($query){
95
  global $wp_query;
96
  if (!empty($wp_query->query_vars['s'])) {
97
  if (strstr($where, 'DISTINCT')) {}
@@ -102,70 +102,71 @@ function SE3_distinct($query){
102
  return $query;
103
  }
104
 
105
- //exlude some posts from search
106
- function SE3_exclude_posts($where) {
107
  global $wp_query;
108
  if (!empty($wp_query->query_vars['s'])) {
109
- $excl_list = implode(',', explode(',', trim(get_option('SE3_exclude_posts_list'))));
110
  $where = str_replace('"', '\'', $where);
111
  $where = 'AND ('.substr($where, strpos($where, 'AND')+3).' )';
112
  $where .= ' AND (ID NOT IN ( '.$excl_list.' ))';
113
  }
114
 
115
- SE3_log("ex posts where: ".$where);
116
  return $where;
117
  }
118
 
119
 
120
 
121
- //exlude some categories from search
122
- function SE3_exclude_categories($where) {
 
123
  global $wp_query;
124
  if (!empty($wp_query->query_vars['s'])) {
125
- $excl_list = implode(',', explode(',', trim(get_option('SE3_exclude_categories_list'))));
126
  $where = str_replace('"', '\'', $where);
127
  $where = 'AND ('.substr($where, strpos($where, 'AND')+3).' )';
128
  $where .= ' AND (c.category_id NOT IN ( '.$excl_list.' ))';
129
  }
130
 
131
- SE3_log("ex cats where: ".$where);
132
  return $where;
133
  }
134
 
135
- //join for excluding categories
136
- function SE3_exclude_categories_join($join) {
137
  global $wp_query, $wpdb;
138
 
139
  if (!empty($wp_query->query_vars['s'])) {
140
 
141
  $join .= "LEFT JOIN $wpdb->post2cat AS c ON $wpdb->posts.ID = c.post_id";
142
  }
143
- SE3_log("category join: ".$join);
144
  return $join;
145
  }
146
 
147
 
148
  //search pages (except password protected pages provided by loops)
149
- function SE3_search_pages($where) {
150
  global $wp_query;
151
  if (!empty($wp_query->query_vars['s'])) {
 
152
  $where = str_replace('"', '\'', $where);
153
- if (strstr($where, 'post_type')) { // >= v 2.1
154
  $where = str_replace('post_type = \'post\' AND ', 'post_password = \'\' AND ', $where);
155
  }
156
  else { // < v 2.1
157
- $where = str_replace(' AND (post_status = \'publish\'', ' AND (post_status = \'publish\' or post_status = \'static\'', $where);
158
  }
159
  }
160
 
161
- SE3_log("pages where: ".$where);
162
  return $where;
163
  }
164
 
165
 
166
-
167
  //search excerpts provided by Dennis Turner
168
- function SE3_search_excerpt($where) {
169
  global $wp_query;
170
  if (!empty($wp_query->query_vars['s'])) {
171
  $where = str_replace('"', '\'', $where);
@@ -175,25 +176,25 @@ $wp_query->query_vars['s'] . '%\') OR (post_excerpt LIKE \'%' .
175
  $wp_query->query_vars['s'] . '%\'', $where);
176
  }
177
 
178
- SE3_log("excerpts where: ".$where);
179
  return $where;
180
  }
181
 
182
 
183
  //search drafts
184
- function SE3_search_draft_posts($where) {
185
  global $wp_query;
186
  if (!empty($wp_query->query_vars['s'])) {
187
  $where = str_replace('"', '\'', $where);
188
  $where = str_replace(' AND (post_status = \'publish\'', ' AND (post_status = \'publish\' or post_status = \'draft\'', $where);
189
  }
190
 
191
- SE3_log("drafts where: ".$where);
192
  return $where;
193
  }
194
 
195
  //search attachments
196
- function SE3_search_attachments($where) {
197
  global $wp_query;
198
  if (!empty($wp_query->query_vars['s'])) {
199
  $where = str_replace('"', '\'', $where);
@@ -201,29 +202,29 @@ function SE3_search_attachments($where) {
201
  $where = str_replace('AND post_status != \'attachment\'','',$where);
202
  }
203
 
204
- SE3_log("attachments where: ".$where);
205
  return $where;
206
  }
207
 
208
  //search comments
209
- function SE3_search_comments($where) {
210
  global $wp_query, $wpdb;
211
  if (!empty($wp_query->query_vars['s'])) {
212
  $where .= " OR (comment_content LIKE '%" . $wpdb->escape($wp_query->query_vars['s']) . "%') ";
213
  }
214
 
215
- SE3_log("comments where: ".$where);
216
 
217
  return $where;
218
  }
219
 
220
  //join for searching comments
221
- function SE3_comments_join($join) {
222
  global $wp_query, $wpdb;
223
 
224
  if (!empty($wp_query->query_vars['s'])) {
225
 
226
- if ('true' == get_option('SE3_approved_comments_only')) {
227
  $comment_approved = " AND comment_approved = '1'";
228
  } else {
229
  $comment_approved = '';
@@ -231,275 +232,131 @@ function SE3_comments_join($join) {
231
 
232
  $join .= "LEFT JOIN $wpdb->comments ON ( comment_post_ID = ID " . $comment_approved . ") ";
233
  }
234
- SE3_log("comments join: ".$join);
235
  return $join;
236
  }
237
 
238
  //search metadata
239
- function SE3_search_metadata($where) {
240
  global $wp_query, $wpdb;
241
  if (!empty($wp_query->query_vars['s'])) {
242
  $where .= " OR meta_value LIKE '%" . $wpdb->escape($wp_query->query_vars['s']) . "%' ";
243
  }
244
 
245
- SE3_log("metadata where: ".$where);
246
 
247
  return $where;
248
  }
249
 
250
  //join for searching metadata
251
- function SE3_search_metadata_join($join) {
252
  global $wp_query, $wpdb;
253
 
254
  if (!empty($wp_query->query_vars['s'])) {
255
 
256
  $join .= "LEFT JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id ";
257
  }
258
- SE3_log("metadata join: ".$join);
259
  return $join;
260
  }
261
 
262
- //search tag
263
- function SE3_search_tag($where) {
264
- global $wp_query, $wpdb;
265
- if (!empty($wp_query->query_vars['s'])) {
266
- $where .= " OR tag_name LIKE '%" . $wpdb->escape($wp_query->query_vars['s']) . "%' ";
267
- }
268
-
269
- SE3_log("tag where: ".$where);
270
-
271
- return $where;
272
- }
273
-
274
- //join for searching tag on Jerome's Keywords Plugin
275
- function SE3_search_tag_join($join) {
276
- global $wp_query, $wpdb;
277
 
278
- if (!empty($wp_query->query_vars['s'])) {
279
-
280
- $join .= "LEFT JOIN wp_jkeywords ON $wpdb->posts.ID = wp_jkeywords.post_id ";
281
- }
282
- SE3_log("tag join: ".$join);
283
- return $join;
284
- }
285
 
286
  //build admin interface
287
- function SE3_option_page() {
288
-
289
- global $wpdb, $table_prefix;
290
-
291
- if ( isset($_POST['SE3_update_options']) ) {
292
-
293
- $errs = array();
294
-
295
- if ( !empty($_POST['exclude_categories']) ) {
296
- update_option('SE3_exclude_categories', "true");
297
- } else {
298
- update_option('SE3_exclude_categories', "false");
299
- }
300
-
301
- if ( !empty($_POST['exclude_categories_list']) ) {
302
- update_option('SE3_exclude_categories_list', $_POST['exclude_categories_list']);
303
- } else {
304
- update_option('SE3_exclude_categories_list', "");
305
- }
306
-
307
- if ( !empty($_POST['exclude_posts']) ) {
308
- update_option('SE3_exclude_posts', "true");
309
- } else {
310
- update_option('SE3_exclude_posts', "false");
311
- }
312
-
313
- if ( !empty($_POST['exclude_posts_list']) ) {
314
- update_option('SE3_exclude_posts_list', $_POST['exclude_posts_list']);
315
- } else {
316
- update_option('SE3_exclude_posts_list', "");
317
- }
318
-
319
- if ( !empty($_POST['search_pages']) ) {
320
- update_option('SE3_use_page_search', "true");
321
- } else {
322
- update_option('SE3_use_page_search', "false");
323
- }
324
-
325
- if ( !empty($_POST['search_comments']) ) {
326
- update_option('SE3_use_comment_search', "true");
327
- } else {
328
- update_option('SE3_use_comment_search', "false");
329
- }
330
-
331
- if ( !empty($_POST['appvd_comments']) ) {
332
- update_option('SE3_approved_comments_only', "true");
333
- } else {
334
- update_option('SE3_approved_comments_only', "false");
335
- }
336
 
337
- if ( !empty($_POST['search_excerpt']) ) {
338
- update_option('SE3_use_excerpt_search', "true");
339
- } else {
340
- update_option('SE3_use_excerpt_search', "false");
341
- }
342
-
343
- if ( !empty($_POST['search_drafts']) ) {
344
- update_option('SE3_use_draft_search', "true");
345
- } else {
346
- update_option('SE3_use_draft_search', "false");
347
- }
348
-
349
- if ( !empty($_POST['search_attachments']) ) {
350
- update_option('SE3_use_attachment_search', "true");
351
- } else {
352
- update_option('SE3_use_attachment_search', "false");
353
- }
354
 
355
- if ( !empty($_POST['search_metadata']) ) {
356
- update_option('SE3_use_metadata_search', "true");
357
- } else {
358
- update_option('SE3_use_metadata_search', "false");
359
  }
360
-
361
- if ( !empty($_POST['search_tag']) ) {
362
- update_option('SE3_use_tag_search', "true");
363
- } else {
364
- update_option('SE3_use_tag_search', "false");
365
- }
366
-
367
- if ( empty($errs) ) {
368
- echo '<div id="message" class="updated fade"><p>Search Options Saved!</p></div>';
369
- } else {
370
- echo '<div id="message" class="error fade"><ul>';
371
- foreach ( $errs as $name => $msg ) {
372
- echo '<li>'.wptexturize($msg).'</li>';
373
- }
374
- echo '</ul></div>';
375
- }
376
- } // End if update
377
-
378
- //set up option checkbox values
379
- if ('true' == get_option('SE3_exclude_categories')) {
380
- $exclude_categories = 'checked="true"';
381
- } else {
382
- $exclude_categories = '';
383
- }
384
-
385
- if ('true' == get_option('SE3_exclude_posts')) {
386
- $exclude_posts = 'checked="true"';
387
- } else {
388
- $exclude_posts = '';
389
- }
390
-
391
-
392
- ### NEW with v.3.9.1 ##################################
393
- if ('true' == get_option('SE3_exclude_pages')) {
394
- $exclude_pages = 'checked="true"';
395
- } else {
396
- $exclude_pages = '';
397
- }
398
- ### NEW with v.3.9.1 ##################################
399
-
400
-
401
- if ('true' == get_option('SE3_use_page_search')) {
402
- $page_search = 'checked="true"';
403
- } else {
404
- $page_search = '';
405
- }
406
-
407
- if ('true' == get_option('SE3_use_comment_search')) {
408
- $comment_search = 'checked="true"';
409
- } else {
410
- $comment_search = '';
411
- }
412
-
413
- if ('true' == get_option('SE3_approved_comments_only')) {
414
- $appvd_comment = 'checked="true"';
415
- } else {
416
- $appvd_comment = '';
417
- }
418
-
419
- if ('true' == get_option('SE3_use_excerpt_search')) {
420
- $excerpt_search = 'checked="true"';
421
- } else {
422
- $excerpt_search = '';
423
- }
424
-
425
- if ('true' == get_option('SE3_use_draft_search')) {
426
- $draft_search = 'checked="true"';
427
- } else {
428
- $draft_search = '';
429
- }
430
-
431
- if ('true' == get_option('SE3_use_attachment_search')) {
432
- $attachment_search = 'checked="true"';
433
- } else {
434
- $attachment_search = '';
435
- }
436
-
437
- if ('true' == get_option('SE3_use_metadata_search')) {
438
- $metadata_search = 'checked="true"';
439
- } else {
440
- $metadata_search = '';
441
- }
442
-
443
- if ('true' == get_option('SE3_use_tag_search')) {
444
- $tag_search = 'checked="true"';
445
- } else {
446
- $tag_search = '';
447
- }
448
-
449
  ?>
450
 
451
- <div class="wrap" id="SE3_options_panel">
452
- <h2>Search Everything (SE) Version: 3.9.9</h2>
453
  <p><?php _e('The options selected below will be used in every search query on this site; in addition to the built-in post search.','SearchEverything'); ?></p>
454
 
455
  </div>
456
 
457
- <div class="wrap SE3">
458
  <h2>SE Search Options</h2>
459
  <p>Use this form to configure your search options.</p>
460
- <form id="SE_form" method="post" action="">
461
- <fieldset>
462
  <legend>Search Options Form</legend>
463
- <p><input type="checkbox" id="exclude_posts" name="exclude_posts" value="<?php echo get_option('SE3_exclude_posts'); ?>" <?php echo $exclude_posts; ?> />
464
  <label for="exclude_posts"><?php _e('Exclude some post or page IDs','SearchEverything'); ?></label><br />
465
- <label for="exclude_posts_list" class="SE_text_label"><?php _e('List of IDs to exclude (example: 1, 5, 9)','SearchEverything'); ?></label><br />
466
- <input type="text" size="40" class="SE_text_input" id="exclude_posts_list" name="exclude_posts_list" value="<?php echo get_option('SE3_exclude_posts_list');?>" /></p>
467
 
468
- <p><input type="checkbox" id="exclude_categories" name="exclude_categories" value="<?php echo get_option('SE3_exclude_categories'); ?>" <?php echo $exclude_categories; ?> />
469
- <label for="exclude_categories"><?php _e('Exclude some category IDs','SearchEverything'); ?></label><br />
470
- <label for="exclude_categories_list" class="SE_text_label"><?php _e('List of category IDs to exclude (example: 1, 4)','SearchEverything'); ?></label><br />
471
- <input type="text" size="40" class="SE_text_input" id="exclude_categories_list" name="exclude_categories_list" value="<?php echo get_option('SE3_exclude_categories_list');?>" /></p>
 
472
 
473
- <p><input type="checkbox" id="search_pages" name="search_pages" value="<?php echo get_option('SE3_use_page_search'); ?>" <?php echo $page_search; ?> />
 
474
  <label for="search_pages"><?php _e('Search every page (non-password protected)','SearchEverything'); ?></label></p>
475
-
476
- <p><input type="checkbox" id="search_comments" name="search_comments" value="<?php echo get_option('SE3_use_comment_search'); ?>" <?php echo $comment_search; ?> />
477
- <label for="search_comments"><?php _e('Search every comment','SearchEverything'); ?></label><br />
478
- <input type="checkbox" class="SE_text_input" id="appvd_comments" name="appvd_comments" value="<?php echo get_option('SE3_approved_comments_only'); ?>" <?php echo $appvd_comment; ?> />
 
 
 
 
479
  <label for="appvd_comments"><?php _e('Search approved comments only?','SearchEverything'); ?></label></p>
480
 
481
- <p><input type="checkbox" id="search_excerpt" name="search_excerpt" value="<?php echo get_option('SE3_use_excerpt_search'); ?>" <?php echo $excerpt_search; ?> />
482
  <label for="search_excerpt"><?php _e('Search every excerpt','SearchEverything'); ?></label></p>
483
 
484
- <p><input type="checkbox" id="search_drafts" name="search_drafts" value="<?php echo get_option('SE3_use_draft_search'); ?>" <?php echo $draft_search; ?> />
485
  <label for="search_drafts"><?php _e('Search every draft','SearchEverything'); ?></label></p>
486
 
487
- <p><input type="checkbox" id="search_attachments" name="search_attachments" value="<?php echo get_option('SE3_use_attachment_search'); ?>" <?php echo $attachment_search; ?> />
488
  <label for="search_attachments"><?php _e('Search every attachment','SearchEverything'); ?></label></p>
489
 
490
- <p><input type="checkbox" id="search_metadata" name="search_metadata" value="<?php echo get_option('SE3_use_metadata_search'); ?>" <?php echo $metadata_search; ?> />
491
- <label for="search_metadata"><?php _e('Search custom fields (metadata)','SearchEverything'); ?></label></p>
492
-
493
- <p><input type="checkbox" id="search_tag" name="search_tag" value="<?php echo get_option('SE3_use_tag_search'); ?>" <?php echo $tag_search; ?> />
494
- <label for="search_tag"><?php _e('Search keywords/tags - <small>Jerome\'s Keywords only</small>','SearchEverything'); ?></label></p>
495
-
496
- <p class="submit"><input type="submit" name="SE3_update_options" class="SE3_btn" value="Save Search Options"/><br />
497
- <span class="SE_notice">Important:</span> <?php _e('You may have to click Save Search Options twice before it sticks.','SearchEverything'); ?></p>
498
 
499
- </fieldset>
 
 
 
 
 
 
500
  </form>
501
  </div>
502
- <div class="wrap SE3">
503
  <h2>SE Search Form</h2>
504
  <p>Use this search form to run a live search test.</p>
505
 
@@ -508,7 +365,7 @@ global $wpdb, $table_prefix;
508
  <form method="get" id="searchform" action="<?php bloginfo('home'); ?>"><p class="srch submit">
509
  <label for="s">Enter search terms<br /></label>
510
  <input type="text" class="srch-txt" value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s" />
511
- <input type="submit" class="SE3_btn" id="searchsubmit" value="Run Test Search" /></p>
512
  </form>
513
  </fieldset>
514
  </div>
@@ -527,9 +384,9 @@ global $wpdb, $table_prefix;
527
  </ul>
528
  <p>If you&#8217;d like to contribute there&#8217;s a lot to do:</p>
529
  <ul class="SE_lists">
530
- <li><strong>2.3 Compatibility</strong></li>
531
- <li>More meta data fuctions.</li>
532
- <li>Search WP 2.3 tags.</li>
533
  <li>Search Bookmarks.</li>
534
  <li>&#8230;anything else you want to add.</li>
535
  </ul>
@@ -539,21 +396,22 @@ global $wpdb, $table_prefix;
539
  </div>
540
 
541
  <?php
542
- } //end SE3_option_page
543
 
544
- function SE3_add_options_panel() {
545
- add_options_page('Search', 'Search Everything', 'edit_plugins', 'SE3_options_page', 'SE3_option_page');
 
546
  }
547
- add_action('admin_menu', 'SE3_add_options_panel');
548
 
549
  //styling options page
550
- function SE3_options_style() {
551
  ?>
552
  <style type="text/css" media="screen">
553
- div.SE3 p.submit, div.SE3 form p.submit, div.SE3 p.submit input { text-align:left; }
554
- #SE3_options_panel p.submit { text-align:left; }
555
  form#searchform label, form#searchform input, form#SE_form label, form#SE_form input { margin-left:10px; }
556
- input.SE3_btn { cursor:pointer; margin-left:5px; }
557
  form legend { font-weight:bold; color:navy; }
558
  p.srch { margin:0; margin-bottom:20px; }
559
  p.submit input.srch-txt { background-color:#f4f4f4; background-image:none; border:1px solid #999; padding:6px; }
@@ -567,6 +425,6 @@ function SE3_options_style() {
567
  <?php
568
  }
569
 
570
- add_action('admin_head', 'SE3_options_style');
571
 
572
  ?>
3
  Plugin Name: Search Everything
4
  Plugin URI: http://dancameron.org/wordpress/
5
  Description: Adds search functionality with little setup. Including options to search pages, excerpts, attachments, drafts, comments, tags and custom fields (metadata). Also offers the ability to exclude specific pages and posts. Does not search password-protected content.
6
+ Version: 4.0
7
  Author: Dan Cameron
8
  Author URI: http://dancameron.org/
9
  */
22
  // Load language file
23
  $locale = get_locale();
24
  if ( !empty($locale) )
25
+ load_textdomain('SearchEverything', ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) .'/' . 'SE4'.$locale.'.mo');
26
 
27
+ function SE4_log($msg) {
28
  global $logging;
29
  if ($logging) {
30
  $fp = fopen("logfile.log","a+");
37
  }
38
 
39
  //add filters based upon option settings
40
+ if ("true" == get_option('SE4_use_page_search')) {
41
+ add_filter('posts_where', 'SE4_search_pages');
42
+ SE4_log("searching pages");
43
  }
44
 
45
+ if ("true" == get_option('SE4_use_excerpt_search')) {
46
+ add_filter('posts_where', 'SE4_search_excerpt');
47
+ SE4_log("searching excerpts");
48
  }
49
 
50
+ if ("true" == get_option('SE4_use_comment_search')) {
51
+ add_filter('posts_where', 'SE4_search_comments');
52
+ add_filter('posts_join', 'SE4_comments_join');
53
+ SE4_log("searching comments");
54
  }
55
 
56
+ if ("true" == get_option('SE4_use_draft_search')) {
57
+ add_filter('posts_where', 'SE4_search_draft_posts');
58
+ SE4_log("searching drafts");
59
  }
60
 
61
+ if ("true" == get_option('SE4_use_attachment_search')) {
62
+ add_filter('posts_where', 'SE4_search_attachments');
63
+ SE4_log("searching attachments");
64
  }
65
 
66
+ if ("true" == get_option('SE4_use_metadata_search')) {
67
+ add_filter('posts_where', 'SE4_search_metadata');
68
+ add_filter('posts_join', 'SE4_search_metadata_join');
69
+ SE4_log("searching metadata");
70
  }
71
 
72
+ if ("true" == get_option('SE4_exclude_posts')) {
73
+ add_filter('posts_where', 'SE4_exclude_posts');
74
+ SE4_log("searching excluding posts");
75
  }
76
 
77
 
78
+ // - Depracated in 2.3
79
+ if ("true" == get_option('SE4_exclude_categories')) {
80
+ add_filter('posts_where', 'SE4_exclude_categories');
81
+ add_filter('posts_join', 'SE4_exclude_categories_join');
82
+ SE4_log("searching excluding categories");
83
  }
84
 
85
+ // - Depracated
86
+ if ("true" == get_option('SE4_use_tag_search')) {
87
+ add_filter('posts_where', 'SE4_search_tag');
88
+ add_filter('posts_join', 'SE4_search_tag_join');
89
+ SE4_log("searching tag");
90
  }
91
 
92
  //Duplicate fix provided by Tiago.Pocinho
93
+ add_filter('posts_request', 'SE4_distinct');
94
+ function SE4_distinct($query){
95
  global $wp_query;
96
  if (!empty($wp_query->query_vars['s'])) {
97
  if (strstr($where, 'DISTINCT')) {}
102
  return $query;
103
  }
104
 
105
+
106
+ function SE4_exclude_posts($where) {
107
  global $wp_query;
108
  if (!empty($wp_query->query_vars['s'])) {
109
+ $excl_list = implode(',', explode(',', trim(get_option('SE4_exclude_posts_list'))));
110
  $where = str_replace('"', '\'', $where);
111
  $where = 'AND ('.substr($where, strpos($where, 'AND')+3).' )';
112
  $where .= ' AND (ID NOT IN ( '.$excl_list.' ))';
113
  }
114
 
115
+ SE4_log("ex posts where: ".$where);
116
  return $where;
117
  }
118
 
119
 
120
 
121
+
122
+ //exlude some categories from search - Depracated in 2.3
123
+ function SE4_exclude_categories($where) {
124
  global $wp_query;
125
  if (!empty($wp_query->query_vars['s'])) {
126
+ $excl_list = implode(',', explode(',', trim(get_option('SE4_exclude_categories_list'))));
127
  $where = str_replace('"', '\'', $where);
128
  $where = 'AND ('.substr($where, strpos($where, 'AND')+3).' )';
129
  $where .= ' AND (c.category_id NOT IN ( '.$excl_list.' ))';
130
  }
131
 
132
+ SE4_log("ex cats where: ".$where);
133
  return $where;
134
  }
135
 
136
+ //join for excluding categories - Depracated in 2.3
137
+ function SE4_exclude_categories_join($join) {
138
  global $wp_query, $wpdb;
139
 
140
  if (!empty($wp_query->query_vars['s'])) {
141
 
142
  $join .= "LEFT JOIN $wpdb->post2cat AS c ON $wpdb->posts.ID = c.post_id";
143
  }
144
+ SE4_log("category join: ".$join);
145
  return $join;
146
  }
147
 
148
 
149
  //search pages (except password protected pages provided by loops)
150
+ function SE4_search_pages($where) {
151
  global $wp_query;
152
  if (!empty($wp_query->query_vars['s'])) {
153
+
154
  $where = str_replace('"', '\'', $where);
155
+ if ('true' == get_option('SE4_approved_pages_only')) {
156
  $where = str_replace('post_type = \'post\' AND ', 'post_password = \'\' AND ', $where);
157
  }
158
  else { // < v 2.1
159
+ $where = str_replace('post_type = \'post\' AND ', '', $where);
160
  }
161
  }
162
 
163
+ SE4_log("pages where: ".$where);
164
  return $where;
165
  }
166
 
167
 
 
168
  //search excerpts provided by Dennis Turner
169
+ function SE4_search_excerpt($where) {
170
  global $wp_query;
171
  if (!empty($wp_query->query_vars['s'])) {
172
  $where = str_replace('"', '\'', $where);
176
  $wp_query->query_vars['s'] . '%\'', $where);
177
  }
178
 
179
+ SE4_log("excerpts where: ".$where);
180
  return $where;
181
  }
182
 
183
 
184
  //search drafts
185
+ function SE4_search_draft_posts($where) {
186
  global $wp_query;
187
  if (!empty($wp_query->query_vars['s'])) {
188
  $where = str_replace('"', '\'', $where);
189
  $where = str_replace(' AND (post_status = \'publish\'', ' AND (post_status = \'publish\' or post_status = \'draft\'', $where);
190
  }
191
 
192
+ SE4_log("drafts where: ".$where);
193
  return $where;
194
  }
195
 
196
  //search attachments
197
+ function SE4_search_attachments($where) {
198
  global $wp_query;
199
  if (!empty($wp_query->query_vars['s'])) {
200
  $where = str_replace('"', '\'', $where);
202
  $where = str_replace('AND post_status != \'attachment\'','',$where);
203
  }
204
 
205
+ SE4_log("attachments where: ".$where);
206
  return $where;
207
  }
208
 
209
  //search comments
210
+ function SE4_search_comments($where) {
211
  global $wp_query, $wpdb;
212
  if (!empty($wp_query->query_vars['s'])) {
213
  $where .= " OR (comment_content LIKE '%" . $wpdb->escape($wp_query->query_vars['s']) . "%') ";
214
  }
215
 
216
+ SE4_log("comments where: ".$where);
217
 
218
  return $where;
219
  }
220
 
221
  //join for searching comments
222
+ function SE4_comments_join($join) {
223
  global $wp_query, $wpdb;
224
 
225
  if (!empty($wp_query->query_vars['s'])) {
226
 
227
+ if ('true' == get_option('SE4_approved_comments_only')) {
228
  $comment_approved = " AND comment_approved = '1'";
229
  } else {
230
  $comment_approved = '';
232
 
233
  $join .= "LEFT JOIN $wpdb->comments ON ( comment_post_ID = ID " . $comment_approved . ") ";
234
  }
235
+ SE4_log("comments join: ".$join);
236
  return $join;
237
  }
238
 
239
  //search metadata
240
+ function SE4_search_metadata($where) {
241
  global $wp_query, $wpdb;
242
  if (!empty($wp_query->query_vars['s'])) {
243
  $where .= " OR meta_value LIKE '%" . $wpdb->escape($wp_query->query_vars['s']) . "%' ";
244
  }
245
 
246
+ SE4_log("metadata where: ".$where);
247
 
248
  return $where;
249
  }
250
 
251
  //join for searching metadata
252
+ function SE4_search_metadata_join($join) {
253
  global $wp_query, $wpdb;
254
 
255
  if (!empty($wp_query->query_vars['s'])) {
256
 
257
  $join .= "LEFT JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id ";
258
  }
259
+ SE4_log("metadata join: ".$join);
260
  return $join;
261
  }
262
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
 
 
 
 
 
 
 
 
264
 
265
  //build admin interface
266
+ function SE4_option_page() {
267
+ global $wpdb, $table_prefix;
268
+ if($_POST['action'] == "save") {
269
+ echo "<div class=\"updated fade\" id=\"limitcatsupdatenotice\"><p>" . __("Search Everything Options <strong>Updated</strong>.") . "</p></div>";
270
+
271
+ update_option("SE4_exclude_categories", $_POST["exclude_categories"]);
272
+ update_option("SE4_exclude_categories_list", $_POST["exclude_categories_list"]);
273
+ update_option("SE4_exclude_posts", $_POST["exclude_posts"]);
274
+ update_option("SE4_exclude_posts_list", $_POST["exclude_posts_list"]);
275
+ update_option("SE4_use_page_search", $_POST["search_pages"]);
276
+ update_option("SE4_use_comment_search", $_POST["search_comments"]);
277
+ update_option("SE4_approved_comments_only", $_POST["appvd_comments"]);
278
+ update_option("SE4_approved_pages_only", $_POST["appvd_pages"]);
279
+ update_option("SE4_use_excerpt_search", $_POST["search_excerpt"]);
280
+ update_option("SE4_use_draft_search", $_POST["search_drafts"]);
281
+ update_option("SE4_use_attachment_search", $_POST["search_attachments"]);
282
+ update_option("SE4_use_metadata_search", $_POST["search_metadata"]);
283
+ update_option("search_tag", $_POST["SE4_use_tag_search"]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
 
285
+ $SE4_exclude_categories = get_option("SE4_exclude_categories");
286
+ $SE4_exclude_categories_list = get_option("SE4_exclude_categories_list");
287
+ $SE4_exclude_posts = get_option("SE4_exclude_posts");
288
+ $SE4_exclude_posts_list = get_option("SE4_exclude_posts_list");
289
+ $SE4_use_page_search = get_option("SE4_use_page_search");
290
+ $SE4_use_comment_search = get_option("SE4_use_comment_search");
291
+ $SE4_approved_comments_only = get_option("SE4_approved_comments_only");
292
+ $SE4_approved_pages_only = get_option("SE4_approved_pages_only");
293
+ $SE4_use_excerpt_search = get_option("SE4_use_excerpt_search");
294
+ $SE4_use_draft_search = get_option("SE4_use_draft_search");
295
+ $SE4_use_attachment_search = get_option("SE4_use_attachment_search");
296
+ $SE4_use_metadata_search = get_option("SE4_use_metadata_search");
297
+ $search_tag = get_option("search_tag");
 
 
 
 
298
 
 
 
 
 
299
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
  ?>
301
 
302
+ <div class="wrap" id="SE4_options_panel">
303
+ <h2>Search Everything (SE) Version: 4</h2>
304
  <p><?php _e('The options selected below will be used in every search query on this site; in addition to the built-in post search.','SearchEverything'); ?></p>
305
 
306
  </div>
307
 
308
+ <div class="wrap SE4">
309
  <h2>SE Search Options</h2>
310
  <p>Use this form to configure your search options.</p>
311
+ <form method="post">
312
+ <fieldset class="options">
313
  <legend>Search Options Form</legend>
314
+ <p><input type="checkbox" id="exclude_posts" name="exclude_posts" value="true" <?php if(get_option('SE4_exclude_posts') == 'true') { echo 'checked="true"'; } ?> />
315
  <label for="exclude_posts"><?php _e('Exclude some post or page IDs','SearchEverything'); ?></label><br />
316
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="exclude_posts_list" class="SE_text_label"><?php _e('Comma separated Post IDs (example: 1, 5, 9)','SearchEverything'); ?></label><br />
317
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" size="50" class="SE_text_input" id="exclude_posts_list" name="exclude_posts_list" value="<?php echo get_option('SE4_exclude_posts_list');?>" /></p>
318
 
319
+ <p><input type="checkbox" id="exclude_categories" name="exclude_categories"
320
+ value="true" <?php if(get_option('SE4_exclude_categories') == 'true') { echo 'checked="true"'; } ?> />
321
+ <label for="exclude_categories"><?php _e('Exclude some category IDs (Wordpress 2.2 Only)','SearchEverything'); ?></label><br />
322
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="exclude_categories_list" class="SE_text_label"><?php _e('Comma separated category IDs (example: 1, 4)','SearchEverything'); ?></label><br />
323
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" size="50" class="SE_text_input" id="exclude_categories_list" name="exclude_categories_list" value="<?php echo get_option('SE4_exclude_categories_list');?>" /></p>
324
 
325
+ <p><input type="checkbox" id="search_pages" name="search_pages"
326
+ value="true" <?php if(get_option('SE4_use_page_search') == 'true') { echo 'checked="true"'; } ?> />
327
  <label for="search_pages"><?php _e('Search every page (non-password protected)','SearchEverything'); ?></label></p>
328
+ <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" class="SE_text_input" id="appvd_pages" name="appvd_pages" value="true" <?php if(get_option('SE4_approved_pages_only') == 'true') { echo 'checked="true"'; } ?>
329
+ <label for="appvd_pages"><?php _e('Search approved pages only?','SearchEverything'); ?></label></p>
330
+
331
+ <p><input type="checkbox" id="search_comments" name="search_comments"
332
+ value="true" <?php if(get_option('SE4_use_comment_search') == 'true') { echo 'checked="true"'; } ?> />
333
+ <label for="search_comments"><?php _e('Search every comment','SearchEverything'); ?></label></p>
334
+
335
+ <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" class="SE_text_input" id="appvd_comments" name="appvd_comments" value="true" <?php if(get_option('SE4_approved_comments_only') == 'true') { echo 'checked="true"'; } ?>
336
  <label for="appvd_comments"><?php _e('Search approved comments only?','SearchEverything'); ?></label></p>
337
 
338
+ <p><input type="checkbox" id="search_excerpt" name="search_excerpt" value="true" <?php if(get_option('SE4_use_excerpt_search') == 'true') { echo 'checked="true"'; } ?> />
339
  <label for="search_excerpt"><?php _e('Search every excerpt','SearchEverything'); ?></label></p>
340
 
341
+ <p><input type="checkbox" id="search_drafts" name="search_drafts" value="true" <?php if(get_option('SE4_use_draft_search') == 'true') { echo 'checked="true"'; } ?>
342
  <label for="search_drafts"><?php _e('Search every draft','SearchEverything'); ?></label></p>
343
 
344
+ <p><input type="checkbox" id="search_attachments" name="search_attachments" value="true" <?php if(get_option('SE4_use_attachment_search') == 'true') { echo 'checked="true"'; } ?> />
345
  <label for="search_attachments"><?php _e('Search every attachment','SearchEverything'); ?></label></p>
346
 
347
+ <p><input type="checkbox" id="search_metadata" name="search_metadata" value="true" <?php if(get_option('SE4_use_metadata_search') == 'true') { echo 'checked="true"'; } ?> />
348
+ <label for="search_metadata"><?php _e('Search every custom field (metadata)','SearchEverything'); ?></label></p>
 
 
 
 
 
 
349
 
350
+ </fieldset>
351
+ <fieldset class="options">
352
+ <div class="submit">
353
+ <input type="hidden" name="action" value="save" />
354
+ <input type="submit" value="<?php _e('Update Options »') ?>" />
355
+ </div>
356
+ </fieldset>
357
  </form>
358
  </div>
359
+ <div class="wrap SE4">
360
  <h2>SE Search Form</h2>
361
  <p>Use this search form to run a live search test.</p>
362
 
365
  <form method="get" id="searchform" action="<?php bloginfo('home'); ?>"><p class="srch submit">
366
  <label for="s">Enter search terms<br /></label>
367
  <input type="text" class="srch-txt" value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s" />
368
+ <input type="submit" class="SE4_btn" id="searchsubmit" value="Run Test Search" /></p>
369
  </form>
370
  </fieldset>
371
  </div>
384
  </ul>
385
  <p>If you&#8217;d like to contribute there&#8217;s a lot to do:</p>
386
  <ul class="SE_lists">
387
+ <li><strong>Category Exclusion for new 2.3 Taxonomy Schema</strong></li>
388
+ <li>More meta data functions.</li>
389
+ <li>Searching tags (WP 2.3).</li>
390
  <li>Search Bookmarks.</li>
391
  <li>&#8230;anything else you want to add.</li>
392
  </ul>
396
  </div>
397
 
398
  <?php
399
+ } //end SE4_option_page
400
 
401
+ function SE4_add_options_panel() {
402
+ add_management_page('Search Everything', 'Manage Search', 7, 'manage_search', 'SE4_option_page');
403
+ add_options_page('Search', 'Search Everything', 7, 'manage_search', 'SE4_options_page', 'SE4_option_page');
404
  }
405
+ add_action('admin_menu', 'SE4_add_options_panel');
406
 
407
  //styling options page
408
+ function SE4_options_style() {
409
  ?>
410
  <style type="text/css" media="screen">
411
+ div.SE4 p.submit, div.SE4 form p.submit, div.SE4 p.submit input { text-align:left; }
412
+ #SE4_options_panel p.submit { text-align:left; }
413
  form#searchform label, form#searchform input, form#SE_form label, form#SE_form input { margin-left:10px; }
414
+ input.SE4_btn { cursor:pointer; margin-left:5px; }
415
  form legend { font-weight:bold; color:navy; }
416
  p.srch { margin:0; margin-bottom:20px; }
417
  p.submit input.srch-txt { background-color:#f4f4f4; background-image:none; border:1px solid #999; padding:6px; }
425
  <?php
426
  }
427
 
428
+ add_action('admin_head', 'SE4_options_style');
429
 
430
  ?>