Revision 36
Added by stefan about 20 years ago
| search.php | ||
|---|---|---|
| 1 | 1 |
<?php |
| 2 | 2 |
|
| 3 |
// $Id: search.php,v 1.9 2005/04/07 07:53:15 rdjurovich Exp $
|
|
| 3 |
// $Id$ |
|
| 4 | 4 |
|
| 5 | 5 |
/* |
| 6 | 6 |
|
| ... | ... | |
| 33 | 33 |
// Make pages_listed and items_listed blank arrays |
| 34 | 34 |
$pages_listed = array(); |
| 35 | 35 |
$items_listed = array(); |
| 36 |
|
|
| 36 |
|
|
| 37 | 37 |
// Get search string |
| 38 | 38 |
if(isset($_POST['string'])) {
|
| 39 |
$string = addslashes(str_replace(',', '', $_POST['string']));
|
|
| 40 |
$search_string = htmlspecialchars(stripslashes($string),ENT_QUOTES);
|
|
| 39 |
$string = addslashes(addslashes(str_replace(',', '', $_POST['string'])));
|
|
| 40 |
$search_string = htmlspecialchars($this->stripslashes(str_replace(',', '', $_POST['string'])),ENT_QUOTES);
|
|
| 41 | 41 |
} else {
|
| 42 |
$string = ''; |
|
| 42 |
$string = '';
|
|
| 43 | 43 |
$search_string = ''; |
| 44 | 44 |
} |
| 45 | 45 |
|
| ... | ... | |
| 81 | 81 |
$operator = 'LIKE'; |
| 82 | 82 |
$wildcard = '%'; |
| 83 | 83 |
$all_checked = ' checked'; |
| 84 |
} |
|
| 85 |
|
|
| 86 |
// Get list of usernames and display names |
|
| 87 |
$query_users = $database->query("SELECT user_id,username,display_name FROM ".TABLE_PREFIX."users");
|
|
| 88 |
$users = array('0' => array('display_name' => $TEXT['UNKNOWN'], 'username' => strtolower($TEXT['UNKNOWN'])));
|
|
| 89 |
if($query_users->numRows() > 0) {
|
|
| 90 |
while($user = $query_users->fetchRow()) {
|
|
| 91 |
$users[$user['user_id']] = array('display_name' => $user['display_name'], 'username' => $user['username']);
|
|
| 92 |
} |
|
| 93 | 84 |
} |
| 94 | 85 |
|
| 86 |
// Get list of usernames and display names |
|
| 87 |
$query_users = $database->query("SELECT user_id,username,display_name FROM ".TABLE_PREFIX."users");
|
|
| 88 |
$users = array('0' => array('display_name' => $TEXT['UNKNOWN'], 'username' => strtolower($TEXT['UNKNOWN'])));
|
|
| 89 |
if($query_users->numRows() > 0) {
|
|
| 90 |
while($user = $query_users->fetchRow()) {
|
|
| 91 |
$users[$user['user_id']] = array('display_name' => $user['display_name'], 'username' => $user['username']);
|
|
| 92 |
} |
|
| 93 |
} |
|
| 94 |
|
|
| 95 | 95 |
// Get search settings |
| 96 | 96 |
$query_header = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'header' LIMIT 1");
|
| 97 | 97 |
$fetch_header = $query_header->fetchRow(); |
| ... | ... | |
| 109 | 109 |
// Replace vars in search settings with values |
| 110 | 110 |
$vars = array('[SEARCH_STRING]', '[WB_URL]', '[PAGE_EXTENSION]', '[TEXT_RESULTS_FOR]');
|
| 111 | 111 |
$values = array($search_string, WB_URL, PAGE_EXTENSION, $TEXT['RESULTS_FOR']); |
| 112 |
$search_footer = str_replace($vars, $values, stripslashes($fetch_footer['value'])); |
|
| 113 |
$search_results_header = str_replace($vars, $values, stripslashes($fetch_results_header['value'])); |
|
| 114 |
$search_results_footer = str_replace($vars, $values, stripslashes($fetch_results_footer['value'])); |
|
| 112 |
$search_footer = str_replace($vars, $values, $this->stripslashes($fetch_footer['value']));
|
|
| 113 |
$search_results_header = str_replace($vars, $values, $this->stripslashes($fetch_results_header['value']));
|
|
| 114 |
$search_results_footer = str_replace($vars, $values, $this->stripslashes($fetch_results_footer['value']));
|
|
| 115 | 115 |
// Do extra vars/values replacement |
| 116 | 116 |
$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]');
|
| 117 | 117 |
$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); |
| 118 |
$search_header = str_replace($vars, $values, stripslashes($fetch_header['value'])); |
|
| 118 |
$search_header = str_replace($vars, $values, $this->stripslashes($fetch_header['value']));
|
|
| 119 | 119 |
|
| 120 | 120 |
// Insert js code |
| 121 | 121 |
?> |
| ... | ... | |
| 138 | 138 |
|
| 139 | 139 |
// Show search results_header |
| 140 | 140 |
echo $search_results_header; |
| 141 |
|
|
| 142 | 141 |
// Search page details only, such as description, keywords, etc. |
| 143 | 142 |
if($match == 'all' OR $match == 'exact') {
|
| 144 | 143 |
$query_pages = $database->query("SELECT page_id, page_title, menu_title, link, description, modified_when, modified_by FROM ".TABLE_PREFIX."pages".
|
| 145 |
" WHERE visibility != 'none' AND visibility != 'deleted' AND page_title $operator '$wildcard$string$wildcard' AND searching = '1' ". |
|
| 144 |
" WHERE visibility != 'none' AND visibility != 'deleted' AND page_title $operator '$wildcard$string$wildcard' AND searching = '1' ".
|
|
| 146 | 145 |
" OR visibility != 'none' AND visibility != 'deleted' AND menu_title $operator '$wildcard$string$wildcard' AND searching = '1'". |
| 147 |
" OR visibility != 'none' AND visibility != 'deleted' AND description $operator '$wildcard$string$wildcard' AND searching = '1'". |
|
| 146 |
" OR visibility != 'none' AND visibility != 'deleted' AND description $operator '$wildcard$string$wildcard' AND searching = '1'".
|
|
| 148 | 147 |
" OR visibility != 'none' AND visibility != 'deleted' AND keywords $operator '$wildcard$string$wildcard' AND searching = '1'"); |
| 149 | 148 |
} elseif($match == 'any') {
|
| 150 | 149 |
$query_pages = "SELECT page_id, page_title, menu_title, link, description, modified_when, modified_by FROM ".TABLE_PREFIX."pages WHERE "; |
| 151 | 150 |
$count = 0; |
| 152 | 151 |
foreach($string AS $each_string) {
|
| 153 | 152 |
if($count != 0) { $query_pages .= ' OR'; }
|
| 154 |
$query_pages .= " visibility != 'none' AND page_title $operator '$wildcard$each_string$wildcard' AND searching = '1'". |
|
| 153 |
$query_pages .= " visibility != 'none' AND page_title $operator '$wildcard$each_string$wildcard' AND searching = '1'".
|
|
| 155 | 154 |
" OR visibility != 'none' AND visibility != 'deleted' AND menu_title $operator '$wildcard$each_string$wildcard' AND searching = '1'". |
| 156 |
" OR visibility != 'none' AND visibility != 'deleted' AND description $operator '$wildcard$each_string$wildcard' AND searching = '1'". |
|
| 155 |
" OR visibility != 'none' AND visibility != 'deleted' AND description $operator '$wildcard$each_string$wildcard' AND searching = '1'".
|
|
| 157 | 156 |
" OR visibility != 'none' AND visibility != 'deleted' AND keywords $operator '$wildcard$each_string$wildcard' AND searching = '1'"; |
| 158 | 157 |
$count = $count+1; |
| 159 | 158 |
} |
| ... | ... | |
| 165 | 164 |
// Get page link |
| 166 | 165 |
$link = page_link($page['link']); |
| 167 | 166 |
// Set vars to be replaced by values |
| 168 |
$vars = array('[LINK]', '[TITLE]', '[DESCRIPTION]', '[USERNAME]','[DISPLAY_NAME]','[DATE]','[TIME]','[TEXT_LAST_UPDATED_BY]','[TEXT_ON]');
|
|
| 169 |
if($page['modified_when'] > 0) {
|
|
| 170 |
$date = gmdate(DATE_FORMAT, $page['modified_when']+TIMEZONE); |
|
| 171 |
$time = gmdate(TIME_FORMAT, $page['modified_when']+TIMEZONE); |
|
| 172 |
} else {
|
|
| 173 |
$date = $TEXT['UNKNOWN'].' '.$TEXT['DATE']; |
|
| 174 |
$time = $TEXT['UNKNOWN'].' '.$TEXT['TIME']; |
|
| 167 |
$vars = array('[LINK]', '[TITLE]', '[DESCRIPTION]', '[USERNAME]','[DISPLAY_NAME]','[DATE]','[TIME]','[TEXT_LAST_UPDATED_BY]','[TEXT_ON]');
|
|
| 168 |
if($page['modified_when'] > 0) {
|
|
| 169 |
$date = gmdate(DATE_FORMAT, $page['modified_when']+TIMEZONE);
|
|
| 170 |
$time = gmdate(TIME_FORMAT, $page['modified_when']+TIMEZONE);
|
|
| 171 |
} else {
|
|
| 172 |
$date = $TEXT['UNKNOWN'].' '.$TEXT['DATE'];
|
|
| 173 |
$time = $TEXT['UNKNOWN'].' '.$TEXT['TIME'];
|
|
| 175 | 174 |
} |
| 176 |
$values = array($link, stripslashes($page['page_title']),stripslashes($page['description']), $users[$page['modified_by']]['username'], $users[$page['modified_by']]['display_name'], $date, $time, $TEXT['LAST_UPDATED_BY'], strtolower($TEXT['ON']));
|
|
| 177 |
// Show loop code with vars replaced by values |
|
| 175 |
$values = array($link, $this->stripslashes($page['page_title']),$this->stripslashes($page['description']), $users[$page['modified_by']]['username'], $users[$page['modified_by']]['display_name'], $date, $time, $TEXT['LAST_UPDATED_BY'], strtolower($TEXT['ON']));
|
|
| 176 |
// Show loop code with vars replaced by values
|
|
| 178 | 177 |
if($values != array()) {
|
| 179 |
echo str_replace($vars, $values, stripslashes($fetch_results_loop['value']));
|
|
| 178 |
echo str_replace($vars, $values, $this->stripslashes($fetch_results_loop['value']));
|
|
| 180 | 179 |
} |
| 181 | 180 |
// Say that we have already listed this page id |
| 182 |
$pages_listed[$page['page_id']] = true; |
|
| 183 |
// Set values to blank |
|
| 181 |
$pages_listed[$page['page_id']] = true;
|
|
| 182 |
// Set values to blank
|
|
| 184 | 183 |
$value = array(); |
| 185 | 184 |
} |
| 186 | 185 |
} |
| ... | ... | |
| 199 | 198 |
// Fetch query start |
| 200 | 199 |
$fetch_query_start = $get_query_start->fetchRow(); |
| 201 | 200 |
// Prepare query start for execution by replacing {TP} with the TABLE_PREFIX
|
| 202 |
$query_start = str_replace('[TP]', TABLE_PREFIX, stripslashes($fetch_query_start['value']));
|
|
| 201 |
$query_start = str_replace('[TP]', TABLE_PREFIX, $this->stripslashes($fetch_query_start['value']));
|
|
| 203 | 202 |
// Get query end |
| 204 | 203 |
$get_query_end = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'query_end' AND extra = '$module_name' LIMIT 1");
|
| 205 | 204 |
if($get_query_end->numRows() > 0) {
|
| 206 | 205 |
// Fetch query start |
| 207 | 206 |
$fetch_query_end = $get_query_end->fetchRow(); |
| 208 | 207 |
// Set query end |
| 209 |
$query_end = stripslashes($fetch_query_end['value']); |
|
| 208 |
$query_end = $this->stripslashes($fetch_query_end['value']);
|
|
| 210 | 209 |
// Get query body |
| 211 | 210 |
$get_query_body = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'query_body' AND extra = '$module_name' LIMIT 1");
|
| 212 | 211 |
if($get_query_body->numRows() > 0) {
|
| 213 | 212 |
// Fetch query start |
| 214 | 213 |
$fetch_query_body = $get_query_body->fetchRow(); |
| 215 | 214 |
// Prepare query body for execution by replacing {STRING} with the correct one
|
| 216 |
$query_body = str_replace(array('[TP]','[O]','[W]'), array(TABLE_PREFIX,$operator,$wildcard), stripslashes($fetch_query_body['value']));
|
|
| 215 |
$query_body = str_replace(array('[TP]','[O]','[W]'), array(TABLE_PREFIX,$operator,$wildcard), $this->stripslashes($fetch_query_body['value']));
|
|
| 217 | 216 |
// If we need to match any of the words, loop through the body for each one then combine with start and end, otherwise just combine without looping |
| 218 | 217 |
if($match == 'any') {
|
| 219 | 218 |
// Loop through query body for each string, then combine with start and end |
| ... | ... | |
| 238 | 237 |
if(!isset($fields['page_id']) OR !isset($pages_listed[$page[$fields['page_id']]])) {
|
| 239 | 238 |
// Get page link |
| 240 | 239 |
$link = page_link($page[$fields['link']]); |
| 241 |
// Set vars to be replaced by values |
|
| 242 |
$vars = array('[LINK]', '[TITLE]', '[DESCRIPTION]', '[USERNAME]','[DISPLAY_NAME]','[DATE]','[TIME]','[TEXT_LAST_UPDATED_BY]','[TEXT_ON]');
|
|
| 243 |
if($page[$fields['modified_when']] > 0) {
|
|
| 244 |
$date = gmdate(DATE_FORMAT, $page[$fields['modified_when']]+TIMEZONE); |
|
| 245 |
$time = gmdate(TIME_FORMAT, $page[$fields['modified_when']]+TIMEZONE); |
|
| 246 |
} else {
|
|
| 247 |
$date = $TEXT['UNKNOWN'].' '.$TEXT['DATE']; |
|
| 248 |
$time = $TEXT['UNKNOWN'].' '.$TEXT['TIME']; |
|
| 240 |
// Set vars to be replaced by values
|
|
| 241 |
$vars = array('[LINK]', '[TITLE]', '[DESCRIPTION]', '[USERNAME]','[DISPLAY_NAME]','[DATE]','[TIME]','[TEXT_LAST_UPDATED_BY]','[TEXT_ON]');
|
|
| 242 |
if($page[$fields['modified_when']] > 0) {
|
|
| 243 |
$date = gmdate(DATE_FORMAT, $page[$fields['modified_when']]+TIMEZONE);
|
|
| 244 |
$time = gmdate(TIME_FORMAT, $page[$fields['modified_when']]+TIMEZONE);
|
|
| 245 |
} else {
|
|
| 246 |
$date = $TEXT['UNKNOWN'].' '.$TEXT['DATE'];
|
|
| 247 |
$time = $TEXT['UNKNOWN'].' '.$TEXT['TIME'];
|
|
| 249 | 248 |
} |
| 250 |
$values = array($link, stripslashes($page[$fields['title']]), stripslashes($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']));
|
|
| 249 |
$values = array($link, $this->stripslashes($page[$fields['title']]), $this->stripslashes($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']));
|
|
| 251 | 250 |
// Show loop code with vars replaced by values |
| 252 |
echo str_replace($vars, $values, stripslashes($fetch_results_loop['value'])); |
|
| 251 |
echo str_replace($vars, $values, $this->stripslashes($fetch_results_loop['value']));
|
|
| 253 | 252 |
// Say that this page or item has been listed if we can |
| 254 | 253 |
if(isset($fields['page_id'])) {
|
| 255 | 254 |
$pages_listed[$page[$fields['page_id']]] = true; |
Also available in: Unified diff
Created new stripslashes method in class wb. Changed stripslashes() calls to method calls.