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