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