1
|
<?php
|
2
|
|
3
|
// $Id: search.php 848 2008-06-22 14:17:15Z thorn $
|
4
|
|
5
|
/*
|
6
|
|
7
|
Website Baker Project <http://www.websitebaker.org/>
|
8
|
Copyright (C) 2004-2008, Ryan Djurovich
|
9
|
|
10
|
Website Baker is free software; you can redistribute it and/or modify
|
11
|
it under the terms of the GNU General Public License as published by
|
12
|
the Free Software Foundation; either version 2 of the License, or
|
13
|
(at your option) any later version.
|
14
|
|
15
|
Website Baker is distributed in the hope that it will be useful,
|
16
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18
|
GNU General Public License for more details.
|
19
|
|
20
|
You should have received a copy of the GNU General Public License
|
21
|
along with Website Baker; if not, write to the Free Software
|
22
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23
|
|
24
|
*/
|
25
|
|
26
|
if(!defined('WB_URL')) {
|
27
|
header('Location: index.php');
|
28
|
exit(0);
|
29
|
}
|
30
|
|
31
|
// Check if search is enabled
|
32
|
if(SHOW_SEARCH != true) {
|
33
|
echo $TEXT['SEARCH'].' '.$TEXT['DISABLED'];
|
34
|
return;
|
35
|
}
|
36
|
|
37
|
// Include the WB functions file
|
38
|
require_once(WB_PATH.'/framework/functions.php');
|
39
|
|
40
|
// Get search settings
|
41
|
$table=TABLE_PREFIX.'search';
|
42
|
$query = $database->query("SELECT value FROM $table WHERE name = 'header' LIMIT 1");
|
43
|
$fetch_header = $query->fetchRow();
|
44
|
$query = $database->query("SELECT value FROM $table WHERE name = 'footer' LIMIT 1");
|
45
|
$fetch_footer = $query->fetchRow();
|
46
|
$query = $database->query("SELECT value FROM $table WHERE name = 'results_header' LIMIT 1");
|
47
|
$fetch_results_header = $query->fetchRow();
|
48
|
$query = $database->query("SELECT value FROM $table WHERE name = 'results_footer' LIMIT 1");
|
49
|
$fetch_results_footer = $query->fetchRow();
|
50
|
$query = $database->query("SELECT value FROM $table WHERE name = 'results_loop' LIMIT 1");
|
51
|
$fetch_results_loop = $query->fetchRow();
|
52
|
$query = $database->query("SELECT value FROM $table WHERE name = 'no_results' LIMIT 1");
|
53
|
$fetch_no_results = $query->fetchRow();
|
54
|
$query = $database->query("SELECT value FROM $table WHERE name = 'module_order' LIMIT 1");
|
55
|
if($query->numRows() > 0) { $res = $query->fetchRow(); } else { $res['value']='faqbaker,manual,wysiwyg'; }
|
56
|
$search_module_order = $res['value'];
|
57
|
$query = $database->query("SELECT value FROM $table WHERE name = 'max_excerpt' LIMIT 1");
|
58
|
if($query->numRows() > 0) { $res = $query->fetchRow(); } else { $res['value'] = '15'; }
|
59
|
$search_max_excerpt = (int)($res['value']);
|
60
|
if(!is_numeric($search_max_excerpt)) { $search_max_excerpt = 15; }
|
61
|
$query = $database->query("SELECT value FROM $table WHERE name = 'cfg_show_description' LIMIT 1");
|
62
|
if($query->numRows() > 0) { $res = $query->fetchRow(); } else { $res['value'] = 'true'; }
|
63
|
if($res['value'] == 'false') { $cfg_show_description = false; } else { $cfg_show_description = true; }
|
64
|
$query = $database->query("SELECT value FROM $table WHERE name = 'cfg_search_description' LIMIT 1");
|
65
|
if($query->numRows() > 0) { $res = $query->fetchRow(); } else { $res['value'] = 'true'; }
|
66
|
if($res['value'] == 'false') { $cfg_search_description = false; } else { $cfg_search_description = true; }
|
67
|
$query = $database->query("SELECT value FROM $table WHERE name = 'cfg_search_keywords' LIMIT 1");
|
68
|
if($query->numRows() > 0) { $res = $query->fetchRow(); } else { $res['value'] = 'true'; }
|
69
|
if($res['value'] == 'false') { $cfg_search_keywords = false; } else { $cfg_search_keywords = true; }
|
70
|
$query = $database->query("SELECT value FROM $table WHERE name = 'cfg_enable_old_search' LIMIT 1");
|
71
|
if($query->numRows() > 0) { $res = $query->fetchRow(); } else { $res['value'] = 'true'; }
|
72
|
if($res['value'] == 'false') { $cfg_enable_old_search = false; } else { $cfg_enable_old_search = true; }
|
73
|
$query = $database->query("SELECT value FROM $table WHERE name = 'cfg_enable_flush' LIMIT 1");
|
74
|
if($query->numRows() > 0) { $res = $query->fetchRow(); } else { $res['value'] = 'false'; }
|
75
|
if($res['value'] == 'false') { $cfg_enable_flush = false; } else { $cfg_enable_flush = true; }
|
76
|
$query = $database->query("SELECT value FROM $table WHERE name = 'time_limit' LIMIT 1"); // time-limit per module
|
77
|
if($query->numRows() > 0) { $res = $query->fetchRow(); } else { $res['value'] = '0'; }
|
78
|
$search_time_limit = (int)($res['value']);
|
79
|
if($search_time_limit < 1) $search_time_limit = 0;
|
80
|
|
81
|
// search-module-extension: get helper-functions
|
82
|
require_once(WB_PATH.'/search/search_modext.php');
|
83
|
// search-module-extension: Get "search.php" for each module, if present
|
84
|
// looks in modules/module/ and modules/module_searchext/
|
85
|
$search_funcs = array();$search_funcs['__before'] = array();$search_funcs['__after'] = array();
|
86
|
$query = $database->query("SELECT DISTINCT directory FROM ".TABLE_PREFIX."addons WHERE type = 'module' AND directory NOT LIKE '%_searchext'");
|
87
|
if($query->numRows() > 0) {
|
88
|
while($module = $query->fetchRow()) {
|
89
|
$file = WB_PATH.'/modules/'.$module['directory'].'/search.php';
|
90
|
if(!file_exists($file)) {
|
91
|
$file = WB_PATH.'/modules/'.$module['directory'].'_searchext/search.php';
|
92
|
if(!file_exists($file)) {
|
93
|
$file='';
|
94
|
}
|
95
|
}
|
96
|
if($file!='') {
|
97
|
include_once($file);
|
98
|
if(function_exists($module['directory']."_search")) {
|
99
|
$search_funcs[$module['directory']] = $module['directory']."_search";
|
100
|
}
|
101
|
if(function_exists($module['directory']."_search_before")) {
|
102
|
$search_funcs['__before'][] = $module['directory']."_search_before";
|
103
|
}
|
104
|
if(function_exists($module['directory']."_search_after")) {
|
105
|
$search_funcs['__after'][] = $module['directory']."_search_after";
|
106
|
}
|
107
|
}
|
108
|
}
|
109
|
}
|
110
|
|
111
|
// Get list of usernames and display names
|
112
|
$query = $database->query("SELECT user_id,username,display_name FROM ".TABLE_PREFIX."users");
|
113
|
$users = array('0' => array('display_name' => $TEXT['UNKNOWN'], 'username' => strtolower($TEXT['UNKNOWN'])));
|
114
|
if($query->numRows() > 0) {
|
115
|
while($user = $query->fetchRow()) {
|
116
|
$users[$user['user_id']] = array('display_name' => $user['display_name'], 'username' => $user['username']);
|
117
|
}
|
118
|
}
|
119
|
|
120
|
// Get the path to search into. Normally left blank
|
121
|
/* possible values:
|
122
|
* - a single path: "/en/" - search only pages whose link contains 'path' ("/en/machinery/bender-x09")
|
123
|
* - a bunch of alternative pathes: "/en/,/machinery/,docs/" - alternatives paths, seperated by comma
|
124
|
* - a bunch of paths to exclude: "-/about,/info,/jp/,/light" - search all, exclude these.
|
125
|
* These different styles can't be mixed.
|
126
|
*/
|
127
|
$search_path_SQL = "";
|
128
|
$search_path = "";
|
129
|
if(isset($_REQUEST['search_path'])) {
|
130
|
$search_path = $wb->add_slashes($_REQUEST['search_path']);
|
131
|
if(!preg_match('~^[-a-zA-Z0-9_,/ ]+$~', $search_path))
|
132
|
$search_path = '';
|
133
|
if($search_path != '') {
|
134
|
$search_path_SQL = "AND ( ";
|
135
|
$not = "";
|
136
|
$op = "OR";
|
137
|
if($search_path[0] == '-') {
|
138
|
$not = "NOT";
|
139
|
$op = "AND";
|
140
|
$paths = explode(',', substr($search_path, 1) );
|
141
|
} else {
|
142
|
$paths = explode(',',$search_path);
|
143
|
}
|
144
|
$i=0;
|
145
|
foreach($paths as $p) {
|
146
|
if($i++ > 0) {
|
147
|
$search_path_SQL .= " $op";
|
148
|
}
|
149
|
$search_path_SQL .= " link $not LIKE '%$p%'";
|
150
|
}
|
151
|
$search_path_SQL .= " )";
|
152
|
}
|
153
|
}
|
154
|
|
155
|
// Get the search type
|
156
|
$match = '';
|
157
|
if(isset($_REQUEST['match'])) {
|
158
|
if($_REQUEST['match']=='any') $match = 'any';
|
159
|
elseif($_REQUEST['match']=='all') $match = 'all';
|
160
|
elseif($_REQUEST['match']=='exact') $match = 'exact';
|
161
|
else $match = 'all';
|
162
|
} else {
|
163
|
$match = 'all';
|
164
|
}
|
165
|
|
166
|
// Get search string
|
167
|
$search_normal_string = '';
|
168
|
$search_entities_string = ''; // for SQL's LIKE
|
169
|
$search_display_string = ''; // for displaying
|
170
|
$search_url_string = ''; // for $_GET
|
171
|
$string = '';
|
172
|
if(isset($_REQUEST['string'])) {
|
173
|
if($match!='exact') {
|
174
|
$string=str_replace(',', '', $_REQUEST['string']);
|
175
|
} else {
|
176
|
$string=$_REQUEST['string']; // $string will be cleaned below
|
177
|
}
|
178
|
// redo possible magic quotes
|
179
|
$string = $wb->strip_slashes($string);
|
180
|
$string = preg_replace('/\s+/', ' ', $string);
|
181
|
$string = trim($string);
|
182
|
// remove some bad chars
|
183
|
$string = preg_replace('/(^|\s+)[|.]+(?=\s+|$)/', '', $string);
|
184
|
$search_display_string = htmlspecialchars($string);
|
185
|
$search_entities_string = addslashes(umlauts_to_entities(htmlspecialchars($string)));
|
186
|
// mySQL needs four backslashes to match one in LIKE comparisons)
|
187
|
$search_entities_string = str_replace('\\\\', '\\\\\\\\', $search_entities_string);
|
188
|
// convert string to utf-8
|
189
|
$string = entities_to_umlauts($string, 'UTF-8');
|
190
|
// quote ' " and / -we need quoted / for regex
|
191
|
$search_url_string = $string;
|
192
|
$string = preg_quote($string);
|
193
|
$search_normal_string = str_replace(array('\'','"','/'), array('\\\'','\"','\/'), $string);
|
194
|
}
|
195
|
// make arrays from the search_..._strings above
|
196
|
$search_url_array = explode(' ', $search_url_string);
|
197
|
$search_normal_array = array();
|
198
|
$search_entities_array = array();
|
199
|
if($match == 'exact') {
|
200
|
$search_normal_array[]=$search_normal_string;
|
201
|
$search_entities_array[]=$search_entities_string;
|
202
|
} else {
|
203
|
$exploded_string = explode(' ', $search_normal_string);
|
204
|
// Make sure there is no blank values in the array
|
205
|
foreach($exploded_string AS $each_exploded_string) {
|
206
|
if($each_exploded_string != '') {
|
207
|
$search_normal_array[] = $each_exploded_string;
|
208
|
}
|
209
|
}
|
210
|
$exploded_string = explode(' ', $search_entities_string);
|
211
|
// Make sure there is no blank values in the array
|
212
|
foreach($exploded_string AS $each_exploded_string) {
|
213
|
if($each_exploded_string != '') {
|
214
|
$search_entities_array[] = $each_exploded_string;
|
215
|
}
|
216
|
}
|
217
|
}
|
218
|
// make an extra copy of search_normal_array for use in regex
|
219
|
require_once(WB_PATH.'/search/search_convert.php');
|
220
|
$search_words = array();
|
221
|
foreach($search_normal_array AS $str) {
|
222
|
$str = strtr($str, $string_ul_umlauts);
|
223
|
// special-feature: '|' means word-boundary (\b). Searching for 'the|' will find the, but not thema.
|
224
|
// this doesn't(?) work correctly for unicode-chars: '|test' will work, but '|über' not.
|
225
|
$str = strtr($str, array('\\|'=>'\b'));
|
226
|
$search_words[] = $str;
|
227
|
}
|
228
|
|
229
|
// Work-out what to do (match all words, any words, or do exact match), and do relevant with query settings
|
230
|
$all_checked = '';
|
231
|
$any_checked = '';
|
232
|
$exact_checked = '';
|
233
|
if ($match == 'any') {
|
234
|
$any_checked = ' checked="checked"';
|
235
|
$logical_operator = ' OR';
|
236
|
} elseif($match == 'all') {
|
237
|
$all_checked = ' checked="checked"';
|
238
|
$logical_operator = ' AND';
|
239
|
} else {
|
240
|
$exact_checked = ' checked="checked"';
|
241
|
}
|
242
|
|
243
|
// Replace vars in search settings with values
|
244
|
$vars = array('[SEARCH_STRING]', '[WB_URL]', '[PAGE_EXTENSION]', '[TEXT_RESULTS_FOR]');
|
245
|
$values = array($search_display_string, WB_URL, PAGE_EXTENSION, $TEXT['RESULTS_FOR']);
|
246
|
$search_footer = str_replace($vars, $values, ($fetch_footer['value']));
|
247
|
$search_results_header = str_replace($vars, $values, ($fetch_results_header['value']));
|
248
|
$search_results_footer = str_replace($vars, $values, ($fetch_results_footer['value']));
|
249
|
|
250
|
// Do extra vars/values replacement
|
251
|
$vars = array('[SEARCH_STRING]', '[WB_URL]', '[PAGE_EXTENSION]', '[TEXT_SEARCH]', '[TEXT_ALL_WORDS]', '[TEXT_ANY_WORDS]', '[TEXT_EXACT_MATCH]', '[TEXT_MATCH]', '[TEXT_MATCHING]', '[ALL_CHECKED]', '[ANY_CHECKED]', '[EXACT_CHECKED]', '[REFERRER_ID]', '[SEARCH_PATH]');
|
252
|
$values = array($search_display_string, WB_URL, PAGE_EXTENSION, $TEXT['SEARCH'], $TEXT['ALL_WORDS'], $TEXT['ANY_WORDS'], $TEXT['EXACT_MATCH'], $TEXT['MATCH'], $TEXT['MATCHING'], $all_checked, $any_checked, $exact_checked, REFERRER_ID, $search_path);
|
253
|
$search_header = str_replace($vars, $values, ($fetch_header['value']));
|
254
|
$vars = array('[TEXT_NO_RESULTS]');
|
255
|
$values = array($TEXT['NO_RESULTS']);
|
256
|
$search_no_results = str_replace($vars, $values, ($fetch_no_results['value']));
|
257
|
|
258
|
/*
|
259
|
* Start of output
|
260
|
*/
|
261
|
|
262
|
// Show search header
|
263
|
echo $search_header;
|
264
|
// Show search results_header
|
265
|
echo $search_results_header;
|
266
|
|
267
|
// Work-out if the user has already entered their details or not
|
268
|
if($search_normal_string != '') {
|
269
|
|
270
|
// Get modules
|
271
|
$table = TABLE_PREFIX."sections";
|
272
|
$get_modules = $database->query("SELECT DISTINCT module FROM $table WHERE module != '' ");
|
273
|
$modules = array();
|
274
|
if($get_modules->numRows() > 0) {
|
275
|
while($module = $get_modules->fetchRow()) {
|
276
|
$modules[] = $module['module'];
|
277
|
}
|
278
|
}
|
279
|
// sort module search-order
|
280
|
// get the modules from $search_module_order first ...
|
281
|
$sorted_modules = array();
|
282
|
$m = count($modules);
|
283
|
$search_modules = explode(',', $search_module_order);
|
284
|
foreach($search_modules AS $item) {
|
285
|
$item = trim($item);
|
286
|
for($i=0; $i < $m; $i++) {
|
287
|
if(isset($modules[$i]) && $modules[$i] == $item) {
|
288
|
$sorted_modules[] = $modules[$i];
|
289
|
unset($modules[$i]);
|
290
|
break;
|
291
|
}
|
292
|
}
|
293
|
}
|
294
|
// ... then add the rest
|
295
|
foreach($modules AS $item) {
|
296
|
$sorted_modules[] = $item;
|
297
|
}
|
298
|
|
299
|
|
300
|
// Use the module's search-extensions.
|
301
|
// This is somewhat slower than the orginial method.
|
302
|
|
303
|
// call $search_funcs['__before'] first
|
304
|
$search_func_vars = array(
|
305
|
'database' => $database, // database-handle
|
306
|
'page_id' => 0,
|
307
|
'section_id' => 0,
|
308
|
'page_title' => '',
|
309
|
'page_menu_title' => '',
|
310
|
'page_description' => '',
|
311
|
'page_keywords' => '',
|
312
|
'page_link' => '',
|
313
|
'page_modified_when' => 0,
|
314
|
'page_modified_by' => 0,
|
315
|
'users' => $users, // array of known user-id/user-name
|
316
|
'search_words' => $search_words, // array of strings, prepared for regex
|
317
|
'search_match' => $match, // match-type
|
318
|
'search_url_array' => $search_url_array, // array of strings from the original search-string. ATTN: strings are not quoted!
|
319
|
'results_loop_string' => $fetch_results_loop['value'],
|
320
|
'default_max_excerpt' => $search_max_excerpt,
|
321
|
'time_limit' => $search_time_limit, // time-limit in secs
|
322
|
'search_path' => $search_path // see docu
|
323
|
);
|
324
|
foreach($search_funcs['__before'] as $func) {
|
325
|
$uf_res = call_user_func($func, $search_func_vars);
|
326
|
}
|
327
|
// now call module-based $search_funcs[]
|
328
|
$seen_pages = array(); // seen pages per module.
|
329
|
$pages_listed = array(); // seen pages.
|
330
|
foreach($sorted_modules AS $module_name) {
|
331
|
$start_time = time(); // get start-time to check time-limit; not very accurate, but ok
|
332
|
$seen_pages[$module_name] = array();
|
333
|
if(!isset($search_funcs[$module_name])) {
|
334
|
continue; // there is no search_func for this module
|
335
|
}
|
336
|
// get each section for $module_name
|
337
|
$table_s = TABLE_PREFIX."sections";
|
338
|
$table_p = TABLE_PREFIX."pages";
|
339
|
$sections_query = $database->query("
|
340
|
SELECT s.section_id, s.page_id, s.module, s.publ_start, s.publ_end,
|
341
|
p.page_title, p.menu_title, p.link, p.description, p.keywords, p.modified_when, p.modified_by,
|
342
|
p.visibility, p.viewing_groups, p.viewing_users
|
343
|
FROM $table_s AS s INNER JOIN $table_p AS p ON s.page_id = p.page_id
|
344
|
WHERE s.module = '$module_name' AND p.visibility NOT IN ('none','deleted') AND p.searching = '1' $search_path_SQL
|
345
|
ORDER BY s.section_id, s.position ASC
|
346
|
");
|
347
|
if($sections_query->numRows() > 0) {
|
348
|
while($res = $sections_query->fetchRow()) {
|
349
|
// check if time-limit is exceeded for this module
|
350
|
if($search_time_limit > 0 && (time()-$start_time > $search_time_limit)) {
|
351
|
break;
|
352
|
}
|
353
|
// Only show this section if it is not "out of publication-date"
|
354
|
$now = time();
|
355
|
if( !( $now<$res['publ_end'] && ($now>$res['publ_start'] || $res['publ_start']==0) ||
|
356
|
$now>$res['publ_start'] && $res['publ_end']==0) ) {
|
357
|
continue;
|
358
|
}
|
359
|
$search_func_vars = array(
|
360
|
'database' => $database,
|
361
|
'page_id' => $res['page_id'],
|
362
|
'section_id' => $res['section_id'],
|
363
|
'page_title' => $res['page_title'],
|
364
|
'page_menu_title' => $res['menu_title'],
|
365
|
'page_description' => ($cfg_show_description?$res['description']:""),
|
366
|
'page_keywords' => $res['keywords'],
|
367
|
'page_link' => $res['link'],
|
368
|
'page_modified_when' => $res['modified_when'],
|
369
|
'page_modified_by' => $res['modified_by'],
|
370
|
'users' => $users,
|
371
|
'search_words' => $search_words, // needed for preg_match
|
372
|
'search_match' => $match,
|
373
|
'search_url_array' => $search_url_array, // needed for url-string only
|
374
|
'results_loop_string' => $fetch_results_loop['value'],
|
375
|
'default_max_excerpt' => $search_max_excerpt,
|
376
|
'enable_flush' => $cfg_enable_flush
|
377
|
);
|
378
|
// Only show this page if we are allowed to see it
|
379
|
if($admin->page_is_visible($res) == false) {
|
380
|
if($res['visibility'] == 'registered') { // don't show excerpt
|
381
|
$search_func_vars['default_max_excerpt'] = 0;
|
382
|
$search_func_vars['page_description'] = $TEXT['REGISTERED'];
|
383
|
} else { // private
|
384
|
continue;
|
385
|
}
|
386
|
}
|
387
|
$uf_res = call_user_func($search_funcs[$module_name], $search_func_vars);
|
388
|
if($uf_res) {
|
389
|
$pages_listed[$res['page_id']] = true;
|
390
|
$seen_pages[$module_name][$res['page_id']] = true;
|
391
|
} else {
|
392
|
$seen_pages[$module_name][$res['page_id']] = true;
|
393
|
}
|
394
|
}
|
395
|
}
|
396
|
}
|
397
|
// now call $search_funcs['__after']
|
398
|
$search_func_vars = array(
|
399
|
'database' => $database, // database-handle
|
400
|
'page_id' => 0,
|
401
|
'section_id' => 0,
|
402
|
'page_title' => '',
|
403
|
'page_menu_title' => '',
|
404
|
'page_description' => '',
|
405
|
'page_keywords' => '',
|
406
|
'page_link' => '',
|
407
|
'page_modified_when' => 0,
|
408
|
'page_modified_by' => 0,
|
409
|
'users' => $users, // array of known user-id/user-name
|
410
|
'search_words' => $search_words, // array of strings, prepared for regex
|
411
|
'search_match' => $match, // match-type
|
412
|
'search_url_array' => $search_url_array, // array of strings from the original search-string. ATTN: strings are not quoted!
|
413
|
'results_loop_string' => $fetch_results_loop['value'],
|
414
|
'default_max_excerpt' => $search_max_excerpt,
|
415
|
'time_limit' => $search_time_limit, // time-limit in secs
|
416
|
'search_path' => $search_path // see docu
|
417
|
);
|
418
|
foreach($search_funcs['__after'] as $func) {
|
419
|
$uf_res = call_user_func($func, $search_func_vars);
|
420
|
}
|
421
|
|
422
|
|
423
|
// Search page details only, such as description, keywords, etc, but only of unseen pages.
|
424
|
$max_excerpt_num = 0; // we don't want excerpt here
|
425
|
$divider = ".";
|
426
|
$table = TABLE_PREFIX."pages";
|
427
|
$query_pages = $database->query("
|
428
|
SELECT page_id, page_title, menu_title, link, description, keywords, modified_when, modified_by,
|
429
|
visibility, viewing_groups, viewing_users
|
430
|
FROM $table
|
431
|
WHERE visibility NOT IN ('none','deleted') AND searching = '1' $search_path_SQL
|
432
|
");
|
433
|
if($query_pages->numRows() > 0) {
|
434
|
while($page = $query_pages->fetchRow()) {
|
435
|
if (isset($pages_listed[$page['page_id']])) {
|
436
|
continue;
|
437
|
}
|
438
|
$func_vars = array(
|
439
|
'database' => $database,
|
440
|
'page_id' => $page['page_id'],
|
441
|
'page_title' => $page['page_title'],
|
442
|
'page_menu_title' => $page['menu_title'],
|
443
|
'page_description' => ($cfg_show_description?$page['description']:""),
|
444
|
'page_keywords' => $page['keywords'],
|
445
|
'page_link' => $page['link'],
|
446
|
'page_modified_when' => $page['modified_when'],
|
447
|
'page_modified_by' => $page['modified_by'],
|
448
|
'users' => $users,
|
449
|
'search_words' => $search_words, // needed for preg_match_all
|
450
|
'search_match' => $match,
|
451
|
'search_url_array' => $search_url_array, // needed for url-string only
|
452
|
'results_loop_string' => $fetch_results_loop['value'],
|
453
|
'default_max_excerpt' => $max_excerpt_num,
|
454
|
'enable_flush' => $cfg_enable_flush
|
455
|
);
|
456
|
// Only show this page if we are allowed to see it
|
457
|
if($admin->page_is_visible($page) == false) {
|
458
|
if($page['visibility'] != 'registered') {
|
459
|
continue;
|
460
|
} else { // page: registered, user: access denied
|
461
|
$func_vars['page_description'] = 'registered';
|
462
|
}
|
463
|
}
|
464
|
if($admin->page_is_active($page) == false) {
|
465
|
continue;
|
466
|
}
|
467
|
$text = $func_vars['page_title'].$divider
|
468
|
.$func_vars['page_menu_title'].$divider
|
469
|
.($cfg_search_description?$func_vars['page_description']:"").$divider
|
470
|
.($cfg_search_keywords?$func_vars['page_keywords']:"").$divider;
|
471
|
$mod_vars = array(
|
472
|
'page_link' => $func_vars['page_link'],
|
473
|
'page_link_target' => "",
|
474
|
'page_title' => $func_vars['page_title'],
|
475
|
'page_description' => $func_vars['page_description'],
|
476
|
'page_modified_when' => $func_vars['page_modified_when'],
|
477
|
'page_modified_by' => $func_vars['page_modified_by'],
|
478
|
'text' => $text,
|
479
|
'max_excerpt_num' => $func_vars['default_max_excerpt']
|
480
|
);
|
481
|
if(print_excerpt2($mod_vars, $func_vars)) {
|
482
|
$pages_listed[$page['page_id']] = true;
|
483
|
}
|
484
|
}
|
485
|
}
|
486
|
|
487
|
// Now use the old method for pages not displayed by the new method above
|
488
|
// in case someone has old modules without search.php.
|
489
|
|
490
|
// Get modules
|
491
|
$table_search = TABLE_PREFIX."search";
|
492
|
$table_sections = TABLE_PREFIX."sections";
|
493
|
$get_modules = $database->query("
|
494
|
SELECT DISTINCT s.value, s.extra
|
495
|
FROM $table_search AS s INNER JOIN $table_sections AS sec
|
496
|
ON s.value = sec.module
|
497
|
WHERE s.name = 'module'
|
498
|
");
|
499
|
$modules = array();
|
500
|
if($get_modules->numRows() > 0) {
|
501
|
while($module = $get_modules->fetchRow()) {
|
502
|
$modules[] = $module; // $modules in an array of arrays
|
503
|
}
|
504
|
}
|
505
|
// sort module search-order
|
506
|
// get the modules from $search_module_order first ...
|
507
|
$sorted_modules = array();
|
508
|
$m = count($modules);
|
509
|
$search_modules = explode(',', $search_module_order);
|
510
|
foreach($search_modules AS $item) {
|
511
|
$item = trim($item);
|
512
|
for($i=0; $i < $m; $i++) {
|
513
|
if(isset($modules[$i]) && $modules[$i]['value'] == $item) {
|
514
|
$sorted_modules[] = $modules[$i];
|
515
|
unset($modules[$i]);
|
516
|
break;
|
517
|
}
|
518
|
}
|
519
|
}
|
520
|
// ... then add the rest
|
521
|
foreach($modules AS $item) {
|
522
|
$sorted_modules[] = $item;
|
523
|
}
|
524
|
|
525
|
if($cfg_enable_old_search) { // this is the old (wb <= 2.6.7) search-function
|
526
|
$search_path_SQL = str_replace(' link ', ' '.TABLE_PREFIX.'pages.link ', $search_path_SQL);
|
527
|
foreach($sorted_modules AS $module) {
|
528
|
$query_start = '';
|
529
|
$query_body = '';
|
530
|
$query_end = '';
|
531
|
$prepared_query = '';
|
532
|
// Get module name
|
533
|
$module_name = $module['value'];
|
534
|
if(!isset($seen_pages[$module_name])) {
|
535
|
$seen_pages[$module_name]=array();
|
536
|
}
|
537
|
// skip module 'code' - it doesn't make sense to search in a code section
|
538
|
if($module_name=="code")
|
539
|
continue;
|
540
|
// Get fields to use for title, link, etc.
|
541
|
$fields = unserialize($module['extra']);
|
542
|
// Get query start
|
543
|
$get_query_start = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'query_start' AND extra = '$module_name' LIMIT 1");
|
544
|
if($get_query_start->numRows() > 0) {
|
545
|
// Fetch query start
|
546
|
$fetch_query_start = $get_query_start->fetchRow();
|
547
|
// Prepare query start for execution by replacing {TP} with the TABLE_PREFIX
|
548
|
$query_start = str_replace('[TP]', TABLE_PREFIX, ($fetch_query_start['value']));
|
549
|
}
|
550
|
// Get query end
|
551
|
$get_query_end = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'query_end' AND extra = '$module_name' LIMIT 1");
|
552
|
if($get_query_end->numRows() > 0) {
|
553
|
// Fetch query end
|
554
|
$fetch_query_end = $get_query_end->fetchRow();
|
555
|
// Set query end
|
556
|
$query_end = ($fetch_query_end['value']);
|
557
|
}
|
558
|
// Get query body
|
559
|
$get_query_body = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'query_body' AND extra = '$module_name' LIMIT 1");
|
560
|
if($get_query_body->numRows() > 0) {
|
561
|
// Fetch query body
|
562
|
$fetch_query_body = $get_query_body->fetchRow();
|
563
|
// Prepare query body for execution by replacing {STRING} with the correct one
|
564
|
$query_body = str_replace(array('[TP]','[O]','[W]'), array(TABLE_PREFIX,'LIKE','%'), ($fetch_query_body['value']));
|
565
|
// Loop through query body for each string, then combine with start and end
|
566
|
$prepared_query = $query_start." ( ( ( ";
|
567
|
$count = 0;
|
568
|
foreach($search_normal_array AS $string) {
|
569
|
if($count != 0) {
|
570
|
$prepared_query .= " ) ".$logical_operator." ( ";
|
571
|
}
|
572
|
$prepared_query .= str_replace('[STRING]', $string, $query_body);
|
573
|
$count = $count+1;
|
574
|
}
|
575
|
$count=0;
|
576
|
$prepared_query .= ' ) ) OR ( ( ';
|
577
|
foreach($search_entities_array AS $string) {
|
578
|
if($count != 0) {
|
579
|
$prepared_query .= " ) ".$logical_operator." ( ";
|
580
|
}
|
581
|
$prepared_query .= str_replace('[STRING]', $string, $query_body);
|
582
|
$count = $count+1;
|
583
|
}
|
584
|
$prepared_query .= " ) ) ) ".$query_end;
|
585
|
// Execute query
|
586
|
$page_query = $database->query($prepared_query." ".$search_path_SQL);
|
587
|
|
588
|
// Loop through queried items
|
589
|
if($page_query->numRows() > 0) {
|
590
|
while($page = $page_query->fetchRow()) {
|
591
|
// Only show this page if it hasn't already been listed
|
592
|
if(isset($seen_pages[$module_name][$page['page_id']]) || isset($pages_listed[$page['page_id']])) {
|
593
|
continue;
|
594
|
}
|
595
|
|
596
|
// don't list pages with visibility == none|deleted and check if user is allowed to see the page
|
597
|
$p_table = TABLE_PREFIX."pages";
|
598
|
$viewquery = $database->query("
|
599
|
SELECT visibility, viewing_groups, viewing_users
|
600
|
FROM $p_table
|
601
|
WHERE page_id='{$page['page_id']}'
|
602
|
");
|
603
|
$visibility = 'none'; $viewing_groups="" ; $viewing_users="";
|
604
|
if($viewquery->numRows() > 0) {
|
605
|
if($res = $viewquery->fetchRow()) {
|
606
|
$visibility = $res['visibility'];
|
607
|
$viewing_groups = $res['viewing_groups'];
|
608
|
$viewing_users = $res['viewing_users'];
|
609
|
if($visibility == 'deleted' || $visibility == 'none') {
|
610
|
continue;
|
611
|
}
|
612
|
if($visibility == 'private') {
|
613
|
if($admin->page_is_visible(array(
|
614
|
'page_id'=>$page[$fields['page_id']],
|
615
|
'visibility' =>$visibility,
|
616
|
'viewing_groups'=>$viewing_groups,
|
617
|
'viewing_users'=>$viewing_users
|
618
|
)) == false) {
|
619
|
continue;
|
620
|
}
|
621
|
}
|
622
|
if($admin->page_is_active(array('page_id'=>$page[$fields['page_id']]))==false) {
|
623
|
continue;
|
624
|
}
|
625
|
}
|
626
|
}
|
627
|
|
628
|
// Get page link
|
629
|
$link = page_link($page['link']);
|
630
|
// Add search string for highlighting
|
631
|
if ($match!='exact') {
|
632
|
$sstring = implode(" ", $search_normal_array);
|
633
|
$link = $link."?searchresult=1&sstring=".urlencode($sstring);
|
634
|
} else {
|
635
|
$sstring = strtr($search_normal_array[0], " ", "_");
|
636
|
$link = $link."?searchresult=2&sstring=".urlencode($sstring);
|
637
|
}
|
638
|
// Set vars to be replaced by values
|
639
|
if(!isset($page['description'])) { $page['description'] = ""; }
|
640
|
if(!isset($page['modified_when'])) { $page['modified_when'] = 0; }
|
641
|
if(!isset($page['modified_by'])) { $page['modified_by'] = 0; }
|
642
|
$vars = array('[LINK]', '[TITLE]', '[DESCRIPTION]', '[USERNAME]','[DISPLAY_NAME]','[DATE]','[TIME]','[TEXT_LAST_UPDATED_BY]','[TEXT_ON]','[EXCERPT]');
|
643
|
if($page['modified_when'] > 0) {
|
644
|
$date = gmdate(DATE_FORMAT, $page['modified_when']+TIMEZONE);
|
645
|
$time = gmdate(TIME_FORMAT, $page['modified_when']+TIMEZONE);
|
646
|
} else {
|
647
|
$date = $TEXT['UNKNOWN'].' '.$TEXT['DATE'];
|
648
|
$time = $TEXT['UNKNOWN'].' '.$TEXT['TIME'];
|
649
|
}
|
650
|
$excerpt="";
|
651
|
if($cfg_show_description == 0) {
|
652
|
$page['description'] = "";
|
653
|
}
|
654
|
$values = array($link, $page['page_title'], $page['description'], $users[$page['modified_by']]['username'], $users[$page['modified_by']]['display_name'], $date, $time, $TEXT['LAST_UPDATED_BY'], strtolower($TEXT['ON']), $excerpt);
|
655
|
// Show loop code with vars replaced by values
|
656
|
echo str_replace($vars, $values, ($fetch_results_loop['value']));
|
657
|
// Say that this page has been listed
|
658
|
$seen_pages[$module_name][$page['page_id']] = true;
|
659
|
$pages_listed[$page['page_id']] = true;
|
660
|
}
|
661
|
}
|
662
|
}
|
663
|
}
|
664
|
}
|
665
|
|
666
|
// Say no items found if we should
|
667
|
if(count($pages_listed) == 0) {
|
668
|
echo $search_no_results;
|
669
|
}
|
670
|
} else {
|
671
|
echo $search_no_results;
|
672
|
}
|
673
|
|
674
|
// Show search results_footer
|
675
|
echo $search_results_footer;
|
676
|
// Show search footer
|
677
|
echo $search_footer;
|
678
|
|
679
|
?>
|