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