Revision 452
Added by Matthias over 17 years ago
search.php | ||
---|---|---|
28 | 28 |
exit(0); |
29 | 29 |
} |
30 | 30 |
|
31 |
// Include the WB functions file |
|
32 |
require_once(WB_PATH.'/framework/functions.php'); |
|
33 |
|
|
31 | 34 |
// Check if search is enabled |
32 | 35 |
if(SHOW_SEARCH != true) { |
33 | 36 |
echo $TEXT['SEARCH'].' '.$TEXT['DISABLED']; |
... | ... | |
39 | 42 |
|
40 | 43 |
// Get the search type |
41 | 44 |
$match = 'all'; |
42 |
if(isset($_REQUEST['match'])) {
|
|
43 |
$match = $_REQUEST['match'];
|
|
44 |
}
|
|
45 |
if(isset($_REQUEST['match'])) {
|
|
46 |
$match = $_REQUEST['match'];
|
|
47 |
}
|
|
45 | 48 |
|
46 | 49 |
// Get search string |
47 | 50 |
if(isset($_REQUEST['string'])) { |
... | ... | |
54 | 57 |
$original_string=$wb->strip_slashes($string); |
55 | 58 |
// Double backslashes (mySQL needs doubly escaped backslashes in LIKE comparisons) |
56 | 59 |
$string = addslashes($wb->escape_backslashes($original_string)); |
57 |
// then escape for mySQL query |
|
58 |
$search_string = htmlspecialchars($original_string,ENT_QUOTES); |
|
60 |
// convert a copy of $string to HTML-ENTITIES |
|
61 |
$string_entities = umlauts_to_entities($string); |
|
62 |
// and do some convertion to both |
|
63 |
require(WB_PATH.'/search/search_convert.php'); |
|
64 |
$string = strtr($string,$string_conv_all); |
|
65 |
$string_entities = strtr($string_entities,$string_entities_conv_all); |
|
66 |
$search_string = $string_entities; |
|
59 | 67 |
} else { |
60 | 68 |
$string = ''; |
61 | 69 |
$search_string = ''; |
... | ... | |
75 | 83 |
$string[] = $each_exploded_string; |
76 | 84 |
} |
77 | 85 |
} |
86 |
// Split $string_entities, too |
|
87 |
$exploded_string = explode(' ', $string_entities); |
|
88 |
// Make sure there is no blank values in the array |
|
89 |
$string_entities = array(); |
|
90 |
foreach($exploded_string AS $each_exploded_string) { |
|
91 |
if($each_exploded_string != '') { |
|
92 |
$string_entities[] = $each_exploded_string; |
|
93 |
} |
|
94 |
} |
|
78 | 95 |
if ($match == 'any') { |
79 | 96 |
$any_checked = ' checked="checked"'; |
80 | 97 |
$logical_operator = ' OR'; |
... | ... | |
87 | 104 |
$exact_string=$string; |
88 | 105 |
$string=array(); |
89 | 106 |
$string[]=$exact_string; |
107 |
$exact_string=$string_entities; |
|
108 |
$string_entities=array(); |
|
109 |
$string_entities[]=$exact_string; |
|
90 | 110 |
} |
91 | 111 |
// Get list of usernames and display names |
92 | 112 |
$query_users = $database->query("SELECT user_id,username,display_name FROM ".TABLE_PREFIX."users"); |
... | ... | |
121 | 141 |
$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]'); |
122 | 142 |
$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); |
123 | 143 |
$search_header = str_replace($vars, $values, ($fetch_header['value'])); |
144 |
$vars = array('[TEXT_NO_RESULTS]'); |
|
145 |
$values = array($TEXT['NO_RESULTS']); |
|
146 |
$search_no_results = str_replace($vars, $values, ($fetch_no_results['value'])); |
|
124 | 147 |
|
125 | 148 |
// Show search header |
126 | 149 |
echo $search_header; |
... | ... | |
131 | 154 |
// Show search results_header |
132 | 155 |
echo $search_results_header; |
133 | 156 |
// Search page details only, such as description, keywords, etc. |
134 |
$query_pages = "SELECT page_id, page_title, menu_title, link, description, modified_when, modified_by FROM ".TABLE_PREFIX."pages WHERE "; |
|
135 |
$count = 0; |
|
136 |
foreach($string AS $each_string) { |
|
137 |
if($count != 0) { $query_pages .= $logical_operator; } |
|
138 |
$query_pages .= " visibility != 'none' AND page_title LIKE '%$each_string%' AND searching = '1'". |
|
139 |
" OR visibility != 'none' AND visibility != 'deleted' AND menu_title LIKE '%$each_string%' AND searching = '1'". |
|
140 |
" OR visibility != 'none' AND visibility != 'deleted' AND description LIKE '%$each_string%' AND searching = '1'". |
|
141 |
" OR visibility != 'none' AND visibility != 'deleted' AND keywords LIKE '%$each_string%' AND searching = '1'"; |
|
142 |
$count = $count+1; |
|
157 |
$query_pages = "SELECT page_id, page_title, menu_title, link, description, modified_when, modified_by FROM ".TABLE_PREFIX."pages WHERE "; |
|
158 |
$count = 0; |
|
159 |
foreach($string AS $each_string) { |
|
160 |
if($count != 0) { |
|
161 |
$query_pages .= $logical_operator; |
|
143 | 162 |
} |
144 |
$query_pages = $database->query($query_pages); |
|
163 |
$query_pages .= " visibility != 'none' AND visibility != 'deleted' AND searching = '1'". |
|
164 |
" AND (page_title LIKE '%$each_string%' OR menu_title LIKE '%$each_string%' OR description LIKE '%$each_string%' OR keywords LIKE '%$each_string%')"; |
|
165 |
$count = $count+1; |
|
166 |
} |
|
167 |
$count = 0; |
|
168 |
$query_pages .= ' OR'; |
|
169 |
foreach($string_entities AS $each_string) { |
|
170 |
if($count != 0) { |
|
171 |
$query_pages .= $logical_operator; |
|
172 |
} |
|
173 |
$query_pages .= " visibility != 'none' AND visibility != 'deleted' AND searching = '1'". |
|
174 |
" AND (page_title LIKE '%$each_string%' OR menu_title LIKE '%$each_string%' OR description LIKE '%$each_string%' OR keywords LIKE '%$each_string%')"; |
|
175 |
$count = $count+1; |
|
176 |
} |
|
177 |
$query_pages = $database->query($query_pages); |
|
145 | 178 |
// Loop through pages |
146 | 179 |
if($query_pages->numRows() > 0) { |
147 | 180 |
while($page = $query_pages->fetchRow()) { |
148 | 181 |
// Get page link |
149 | 182 |
$link = page_link($page['link']); |
183 |
|
|
184 |
//Add search string for highlighting |
|
185 |
if ($match!='exact') { |
|
186 |
$sstring = implode(" ", $string); |
|
187 |
$link = $link."?searchresult=1&sstring=".urlencode($sstring); |
|
188 |
} |
|
189 |
else { |
|
190 |
$sstring = strtr($string[0], " ", "_"); |
|
191 |
$link = $link."?searchresult=2&sstring=".urlencode($sstring); |
|
192 |
} |
|
193 |
|
|
150 | 194 |
// Set vars to be replaced by values |
151 | 195 |
$vars = array('[LINK]', '[TITLE]', '[DESCRIPTION]', '[USERNAME]','[DISPLAY_NAME]','[DATE]','[TIME]','[TEXT_LAST_UPDATED_BY]','[TEXT_ON]'); |
152 | 196 |
if($page['modified_when'] > 0) { |
... | ... | |
201 | 245 |
$prepared_query = $query_start; |
202 | 246 |
$count = 0; |
203 | 247 |
foreach($string AS $each_string) { |
204 |
if($count != 0) { $prepared_query .= $logical_operator; } |
|
248 |
if($count != 0) { |
|
249 |
$prepared_query .= $logical_operator; |
|
250 |
} |
|
205 | 251 |
$prepared_query .= str_replace('[STRING]', $each_string, $query_body); |
206 | 252 |
$count = $count+1; |
207 | 253 |
} |
254 |
$count=0; |
|
255 |
$prepared_query .= ' OR '; |
|
256 |
foreach($string_entities AS $each_string) { |
|
257 |
if($count != 0) { |
|
258 |
$prepared_query .= $logical_operator; |
|
259 |
} |
|
260 |
$prepared_query .= str_replace('[STRING]', $each_string, $query_body); |
|
261 |
$count = $count+1; |
|
262 |
} |
|
263 |
|
|
208 | 264 |
$prepared_query .= $query_end; |
265 |
|
|
209 | 266 |
// Execute query |
210 | 267 |
$query = $database->query($prepared_query); |
211 | 268 |
// Loop though queried items |
... | ... | |
215 | 272 |
if(!isset($fields['page_id']) OR !isset($pages_listed[$page[$fields['page_id']]])) { |
216 | 273 |
// Get page link |
217 | 274 |
$link = page_link($page[$fields['link']]); |
275 |
|
|
276 |
//Add search string for highlighting |
|
277 |
if ($match!='exact') { |
|
278 |
$sstring = implode(" ", $string); |
|
279 |
$link = $link."?searchresult=1&sstring=".urlencode($sstring); |
|
280 |
} |
|
281 |
else { |
|
282 |
$sstring = strtr($string[0], " ", "_"); |
|
283 |
$link = $link."?searchresult=2&sstring=".urlencode($sstring); |
|
284 |
} |
|
285 |
|
|
218 | 286 |
// Set vars to be replaced by values |
219 | 287 |
$vars = array('[LINK]', '[TITLE]', '[DESCRIPTION]', '[USERNAME]','[DISPLAY_NAME]','[DATE]','[TIME]','[TEXT_LAST_UPDATED_BY]','[TEXT_ON]'); |
220 | 288 |
if($page[$fields['modified_when']] > 0) { |
... | ... | |
236 | 304 |
} |
237 | 305 |
} |
238 | 306 |
} |
239 |
|
|
240 | 307 |
} |
241 | 308 |
} |
242 | 309 |
} |
... | ... | |
247 | 314 |
|
248 | 315 |
} |
249 | 316 |
|
250 |
// Say no items found if we should |
|
251 |
if($pages_listed == array() AND $items_listed == array()) { |
|
252 |
echo $fetch_no_results['value'];
|
|
253 |
} |
|
317 |
// Say no items found if we should
|
|
318 |
if($pages_listed == array() AND $items_listed == array()) {
|
|
319 |
echo $search_no_results;
|
|
320 |
}
|
|
254 | 321 |
|
255 | 322 |
} |
256 | 323 |
|
Also available in: Unified diff
again copied all changes for WB 2.6.6 from trunk to branches