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