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