root / tags / release_2_0_2 / phpBB / search.php
History | View | Annotate | Download (39.5 kB)
| 1 | 1350 | psotfx | <?php
|
|---|---|---|---|
| 2 | 368 | psotfx | /***************************************************************************
|
| 3 | 368 | psotfx | * search.php |
| 4 | 368 | psotfx | * ------------------- |
| 5 | 368 | psotfx | * begin : Saturday, Feb 13, 2001 |
| 6 | 368 | psotfx | * copyright : (C) 2001 The phpBB Group |
| 7 | 368 | psotfx | * email : support@phpbb.com |
| 8 | 368 | psotfx | * |
| 9 | 368 | psotfx | * $Id$ |
| 10 | 368 | psotfx | * |
| 11 | 368 | psotfx | * |
| 12 | 368 | psotfx | ***************************************************************************/ |
| 13 | 368 | psotfx | |
| 14 | 943 | thefinn | /***************************************************************************
|
| 15 | 943 | thefinn | * |
| 16 | 943 | thefinn | * This program is free software; you can redistribute it and/or modify |
| 17 | 943 | thefinn | * it under the terms of the GNU General Public License as published by |
| 18 | 943 | thefinn | * the Free Software Foundation; either version 2 of the License, or |
| 19 | 943 | thefinn | * (at your option) any later version. |
| 20 | 943 | thefinn | * |
| 21 | 943 | thefinn | ***************************************************************************/ |
| 22 | 943 | thefinn | |
| 23 | 2305 | psotfx | define('IN_PHPBB', true); |
| 24 | 2448 | psotfx | $phpbb_root_path = './'; |
| 25 | 646 | psotfx | include($phpbb_root_path . 'extension.inc'); |
| 26 | 646 | psotfx | include($phpbb_root_path . 'common.'.$phpEx); |
| 27 | 1051 | psotfx | include($phpbb_root_path . 'includes/bbcode.'.$phpEx); |
| 28 | 2305 | psotfx | include($phpbb_root_path . 'includes/functions_search.'.$phpEx); |
| 29 | 368 | psotfx | |
| 30 | 368 | psotfx | //
|
| 31 | 368 | psotfx | // Start session management
|
| 32 | 368 | psotfx | //
|
| 33 | 2205 | psotfx | $userdata = session_pagestart($user_ip, PAGE_SEARCH); |
| 34 | 368 | psotfx | init_userprefs($userdata);
|
| 35 | 368 | psotfx | //
|
| 36 | 368 | psotfx | // End session management
|
| 37 | 368 | psotfx | //
|
| 38 | 368 | psotfx | |
| 39 | 1051 | psotfx | //
|
| 40 | 1051 | psotfx | // Define initial vars
|
| 41 | 1051 | psotfx | //
|
| 42 | 2448 | psotfx | if ( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) ) |
| 43 | 1190 | psotfx | {
|
| 44 | 1190 | psotfx | $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode']; |
| 45 | 1190 | psotfx | } |
| 46 | 1190 | psotfx | else
|
| 47 | 1190 | psotfx | {
|
| 48 | 2205 | psotfx | $mode = ''; |
| 49 | 1190 | psotfx | } |
| 50 | 1190 | psotfx | |
| 51 | 2448 | psotfx | if ( isset($HTTP_POST_VARS['search_keywords']) || isset($HTTP_GET_VARS['search_keywords']) ) |
| 52 | 1051 | psotfx | {
|
| 53 | 2205 | psotfx | $search_keywords = ( isset($HTTP_POST_VARS['search_keywords']) ) ? $HTTP_POST_VARS['search_keywords'] : $HTTP_GET_VARS['search_keywords']; |
| 54 | 1051 | psotfx | } |
| 55 | 1051 | psotfx | else
|
| 56 | 1051 | psotfx | {
|
| 57 | 2205 | psotfx | $search_keywords = ''; |
| 58 | 1051 | psotfx | } |
| 59 | 368 | psotfx | |
| 60 | 2448 | psotfx | if ( isset($HTTP_POST_VARS['search_author']) || isset($HTTP_GET_VARS['search_author'])) |
| 61 | 1051 | psotfx | {
|
| 62 | 2205 | psotfx | $search_author = ( isset($HTTP_POST_VARS['search_author']) ) ? $HTTP_POST_VARS['search_author'] : $HTTP_GET_VARS['search_author']; |
| 63 | 1051 | psotfx | } |
| 64 | 1051 | psotfx | else
|
| 65 | 1051 | psotfx | {
|
| 66 | 2205 | psotfx | $search_author = ''; |
| 67 | 1051 | psotfx | } |
| 68 | 368 | psotfx | |
| 69 | 2452 | psotfx | $search_id = ( isset($HTTP_GET_VARS['search_id']) ) ? $HTTP_GET_VARS['search_id'] : ''; |
| 70 | 368 | psotfx | |
| 71 | 2326 | psotfx | $show_results = ( isset($HTTP_POST_VARS['show_results']) ) ? $HTTP_POST_VARS['show_results'] : 'posts'; |
| 72 | 1938 | psotfx | |
| 73 | 2448 | psotfx | if ( isset($HTTP_POST_VARS['search_terms']) ) |
| 74 | 1051 | psotfx | {
|
| 75 | 2326 | psotfx | $search_terms = ( $HTTP_POST_VARS['search_terms'] == 'all' ) ? 1 : 0; |
| 76 | 1051 | psotfx | } |
| 77 | 1051 | psotfx | else
|
| 78 | 1051 | psotfx | {
|
| 79 | 2205 | psotfx | $search_terms = 0; |
| 80 | 1051 | psotfx | } |
| 81 | 1051 | psotfx | |
| 82 | 2448 | psotfx | if ( isset($HTTP_POST_VARS['search_fields']) ) |
| 83 | 1851 | psotfx | {
|
| 84 | 2326 | psotfx | $search_fields = ( $HTTP_POST_VARS['search_fields'] == 'all' ) ? 1 : 0; |
| 85 | 1851 | psotfx | } |
| 86 | 1851 | psotfx | else
|
| 87 | 1851 | psotfx | {
|
| 88 | 2205 | psotfx | $search_fields = 0; |
| 89 | 1851 | psotfx | } |
| 90 | 1851 | psotfx | |
| 91 | 2205 | psotfx | $return_chars = ( isset($HTTP_POST_VARS['return_chars']) ) ? intval($HTTP_POST_VARS['return_chars']) : 200; |
| 92 | 1051 | psotfx | |
| 93 | 2205 | psotfx | $search_cat = ( isset($HTTP_POST_VARS['search_cat']) ) ? intval($HTTP_POST_VARS['search_cat']) : -1; |
| 94 | 2205 | psotfx | $search_forum = ( isset($HTTP_POST_VARS['search_forum']) ) ? intval($HTTP_POST_VARS['search_forum']) : -1; |
| 95 | 1051 | psotfx | |
| 96 | 2205 | psotfx | $sort_by = ( isset($HTTP_POST_VARS['sort_by']) ) ? intval($HTTP_POST_VARS['sort_by']) : 0; |
| 97 | 1089 | psotfx | |
| 98 | 2448 | psotfx | if ( isset($HTTP_POST_VARS['sort_dir']) ) |
| 99 | 1051 | psotfx | {
|
| 100 | 2326 | psotfx | $sort_dir = ( $HTTP_POST_VARS['sort_dir'] == 'DESC' ) ? 'DESC' : 'ASC'; |
| 101 | 1051 | psotfx | } |
| 102 | 1051 | psotfx | else
|
| 103 | 1051 | psotfx | {
|
| 104 | 2326 | psotfx | $sort_dir = 'DESC'; |
| 105 | 1051 | psotfx | } |
| 106 | 1051 | psotfx | |
| 107 | 2448 | psotfx | if ( !empty($HTTP_POST_VARS['search_time']) || !empty($HTTP_GET_VARS['search_time'])) |
| 108 | 1051 | psotfx | {
|
| 109 | 2448 | psotfx | $search_time = time() - ( ( ( !empty($HTTP_POST_VARS['search_time']) ) ? intval($HTTP_POST_VARS['search_time']) : intval($HTTP_GET_VARS['search_time']) ) * 86400 ); |
| 110 | 1051 | psotfx | } |
| 111 | 1051 | psotfx | else
|
| 112 | 1051 | psotfx | {
|
| 113 | 1051 | psotfx | $search_time = 0; |
| 114 | 1051 | psotfx | } |
| 115 | 1051 | psotfx | |
| 116 | 1644 | psotfx | $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0; |
| 117 | 1051 | psotfx | |
| 118 | 2205 | psotfx | $sort_by_types = array($lang['Sort_Time'], $lang['Sort_Post_Subject'], $lang['Sort_Topic_Title'], $lang['Sort_Author'], $lang['Sort_Forum']); |
| 119 | 368 | psotfx | |
| 120 | 1051 | psotfx | //
|
| 121 | 2572 | psotfx | // encoding match for workaround
|
| 122 | 2572 | psotfx | //
|
| 123 | 2572 | psotfx | $multibyte_charset = 'utf-8, big5, shift_jis, euc-kr, gb2312'; |
| 124 | 2572 | psotfx | |
| 125 | 2572 | psotfx | //
|
| 126 | 1051 | psotfx | // Begin core code
|
| 127 | 1051 | psotfx | //
|
| 128 | 2448 | psotfx | if ( $mode == 'searchuser' ) |
| 129 | 368 | psotfx | {
|
| 130 | 1224 | psotfx | //
|
| 131 | 2448 | psotfx | // This handles the simple windowed user search functions called from various other scripts
|
| 132 | 1224 | psotfx | //
|
| 133 | 2448 | psotfx | if ( isset($HTTP_POST_VARS['search_username']) ) |
| 134 | 1224 | psotfx | {
|
| 135 | 2448 | psotfx | username_search($HTTP_POST_VARS['search_username']); |
| 136 | 1224 | psotfx | } |
| 137 | 1224 | psotfx | else
|
| 138 | 1224 | psotfx | {
|
| 139 | 2448 | psotfx | username_search('');
|
| 140 | 1224 | psotfx | } |
| 141 | 368 | psotfx | |
| 142 | 1224 | psotfx | exit;
|
| 143 | 1224 | psotfx | } |
| 144 | 2448 | psotfx | else if ( $search_keywords != '' || $search_author != '' || $search_id ) |
| 145 | 1224 | psotfx | {
|
| 146 | 2205 | psotfx | $store_vars = array('search_results', 'total_match_count', 'split_search', 'sort_by', 'sort_dir', 'show_results', 'return_chars'); |
| 147 | 2205 | psotfx | |
| 148 | 1511 | psotfx | //
|
| 149 | 1511 | psotfx | // Cycle through options ...
|
| 150 | 1511 | psotfx | //
|
| 151 | 2205 | psotfx | if ( $search_id == 'newposts' || $search_id == 'egosearch' || $search_id == 'unanswered' || $search_keywords != '' || $search_author != '' ) |
| 152 | 1051 | psotfx | {
|
| 153 | 2205 | psotfx | if ( $search_id == 'newposts' || $search_id == 'egosearch' || ( $search_author != '' && $search_keywords == '' ) ) |
| 154 | 1051 | psotfx | {
|
| 155 | 2205 | psotfx | if ( $search_id == 'newposts' ) |
| 156 | 1566 | psotfx | {
|
| 157 | 2205 | psotfx | if ( $userdata['session_logged_in'] ) |
| 158 | 2205 | psotfx | {
|
| 159 | 2205 | psotfx | $sql = "SELECT post_id |
| 160 | 2205 | psotfx | FROM " . POSTS_TABLE . " |
| 161 | 2205 | psotfx | WHERE post_time >= " . $userdata['user_lastvisit']; |
| 162 | 2205 | psotfx | } |
| 163 | 2205 | psotfx | else
|
| 164 | 2205 | psotfx | {
|
| 165 | 2506 | psotfx | header("Location: login.$phpEx?redirect=search.$phpEx&search_id=newposts", true); |
| 166 | 2205 | psotfx | exit;
|
| 167 | 2205 | psotfx | } |
| 168 | 2205 | psotfx | |
| 169 | 2326 | psotfx | $show_results = 'topics'; |
| 170 | 2205 | psotfx | $sort_by = 0; |
| 171 | 2326 | psotfx | $sort_dir = 'DESC'; |
| 172 | 1566 | psotfx | } |
| 173 | 2205 | psotfx | else if ( $search_id == 'egosearch' ) |
| 174 | 1566 | psotfx | {
|
| 175 | 2205 | psotfx | if ( $userdata['session_logged_in'] ) |
| 176 | 2205 | psotfx | {
|
| 177 | 2205 | psotfx | $sql = "SELECT post_id |
| 178 | 2205 | psotfx | FROM " . POSTS_TABLE . " |
| 179 | 2205 | psotfx | WHERE poster_id = " . $userdata['user_id'];; |
| 180 | 2205 | psotfx | } |
| 181 | 2205 | psotfx | else
|
| 182 | 2205 | psotfx | {
|
| 183 | 2506 | psotfx | header("Location: login.$phpEx?redirect=search.$phpEx&search_id=egosearch", true); |
| 184 | 2205 | psotfx | exit;
|
| 185 | 2205 | psotfx | } |
| 186 | 2205 | psotfx | |
| 187 | 2326 | psotfx | $show_results = 'topics'; |
| 188 | 2205 | psotfx | $sort_by = 0; |
| 189 | 2326 | psotfx | $sort_dir = 'DESC'; |
| 190 | 1566 | psotfx | } |
| 191 | 2205 | psotfx | else
|
| 192 | 2205 | psotfx | {
|
| 193 | 2326 | psotfx | $search_author = str_replace('*', '%', trim($search_author)); |
| 194 | 2205 | psotfx | |
| 195 | 2205 | psotfx | $sql = "SELECT user_id |
| 196 | 2205 | psotfx | FROM " . USERS_TABLE . " |
| 197 | 2205 | psotfx | WHERE username LIKE '" . str_replace("\'", "''", $search_author) . "'"; |
| 198 | 2205 | psotfx | if ( !($result = $db->sql_query($sql)) ) |
| 199 | 2205 | psotfx | {
|
| 200 | 2205 | psotfx | message_die(GENERAL_ERROR, "Couldn't obtain list of matching users (searching for: $search_author)", "", __LINE__, __FILE__, $sql); |
| 201 | 2205 | psotfx | } |
| 202 | 1644 | psotfx | |
| 203 | 2205 | psotfx | $matching_userids = ''; |
| 204 | 2205 | psotfx | if ( $row = $db->sql_fetchrow($result) ) |
| 205 | 2205 | psotfx | {
|
| 206 | 2205 | psotfx | do
|
| 207 | 2205 | psotfx | {
|
| 208 | 2205 | psotfx | $matching_userids .= ( ( $matching_userids != '' ) ? ', ' : '' ) . $row['user_id']; |
| 209 | 2205 | psotfx | } |
| 210 | 2205 | psotfx | while( $row = $db->sql_fetchrow($result) ); |
| 211 | 2205 | psotfx | } |
| 212 | 2205 | psotfx | else
|
| 213 | 2205 | psotfx | {
|
| 214 | 2205 | psotfx | message_die(GENERAL_MESSAGE, $lang['No_search_match']); |
| 215 | 2205 | psotfx | } |
| 216 | 1644 | psotfx | |
| 217 | 2205 | psotfx | $sql = "SELECT post_id |
| 218 | 2205 | psotfx | FROM " . POSTS_TABLE . " |
| 219 | 2205 | psotfx | WHERE poster_id IN ($matching_userids)"; |
| 220 | 1586 | bartvb | } |
| 221 | 2205 | psotfx | |
| 222 | 2205 | psotfx | if ( !($result = $db->sql_query($sql)) ) |
| 223 | 1586 | bartvb | {
|
| 224 | 2326 | psotfx | message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql); |
| 225 | 1586 | bartvb | } |
| 226 | 2205 | psotfx | |
| 227 | 2205 | psotfx | $search_ids = array(); |
| 228 | 1586 | bartvb | while( $row = $db->sql_fetchrow($result) ) |
| 229 | 1586 | bartvb | {
|
| 230 | 2205 | psotfx | $search_ids[] = $row['post_id']; |
| 231 | 2205 | psotfx | } |
| 232 | 2205 | psotfx | $db->sql_freeresult($result); |
| 233 | 1511 | psotfx | |
| 234 | 2205 | psotfx | $total_match_count = count($search_ids); |
| 235 | 1644 | psotfx | |
| 236 | 1511 | psotfx | } |
| 237 | 2205 | psotfx | else if ( $search_keywords != '' ) |
| 238 | 1511 | psotfx | {
|
| 239 | 2326 | psotfx | $stopword_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_stopwords.txt'); |
| 240 | 2326 | psotfx | $synonym_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_synonyms.txt'); |
| 241 | 2205 | psotfx | |
| 242 | 2205 | psotfx | $split_search = array(); |
| 243 | 2572 | psotfx | $split_search = ( !strstr($multibyte_charset, $lang['ENCODING']) ) ? split_words(clean_words('search', stripslashes($search_keywords), $stopword_array, $synonym_array), 'search') : split(' ', $search_keywords); |
| 244 | 1511 | psotfx | |
| 245 | 2572 | psotfx | $search_msg_only = ( !$search_fields ) ? "AND m.title_match = 0" : ( ( strstr($multibyte_charset, $lang['ENCODING']) ) ? '' : '' ); |
| 246 | 1511 | psotfx | |
| 247 | 2205 | psotfx | $word_count = 0; |
| 248 | 2326 | psotfx | $current_match_type = 'or'; |
| 249 | 1511 | psotfx | |
| 250 | 2205 | psotfx | $word_match = array(); |
| 251 | 2205 | psotfx | $result_list = array(); |
| 252 | 1511 | psotfx | |
| 253 | 2205 | psotfx | for($i = 0; $i < count($split_search); $i++) |
| 254 | 1293 | psotfx | {
|
| 255 | 2205 | psotfx | switch ( $split_search[$i] ) |
| 256 | 1293 | psotfx | {
|
| 257 | 2205 | psotfx | case 'and': |
| 258 | 2205 | psotfx | $current_match_type = 'and'; |
| 259 | 2205 | psotfx | break;
|
| 260 | 1293 | psotfx | |
| 261 | 2205 | psotfx | case 'or': |
| 262 | 2205 | psotfx | $current_match_type = 'or'; |
| 263 | 2205 | psotfx | break;
|
| 264 | 1412 | psotfx | |
| 265 | 2205 | psotfx | case 'not': |
| 266 | 2205 | psotfx | $current_match_type = 'not'; |
| 267 | 2205 | psotfx | break;
|
| 268 | 1293 | psotfx | |
| 269 | 2205 | psotfx | default:
|
| 270 | 2448 | psotfx | if ( !empty($search_terms) ) |
| 271 | 2205 | psotfx | {
|
| 272 | 2326 | psotfx | $current_match_type = 'and'; |
| 273 | 2205 | psotfx | } |
| 274 | 1412 | psotfx | |
| 275 | 2572 | psotfx | if ( !strstr($multibyte_charset, $lang['ENCODING']) ) |
| 276 | 2572 | psotfx | {
|
| 277 | 2572 | psotfx | $match_word = str_replace('*', '%', $split_search[$i]); |
| 278 | 2572 | psotfx | $sql = "SELECT m.post_id |
| 279 | 2572 | psotfx | FROM " . SEARCH_WORD_TABLE . " w, " . SEARCH_MATCH_TABLE . " m |
| 280 | 2572 | psotfx | WHERE w.word_text LIKE '$match_word' |
| 281 | 2572 | psotfx | AND m.word_id = w.word_id |
| 282 | 2572 | psotfx | AND w.word_common <> 1 |
| 283 | 2572 | psotfx | $search_msg_only"; |
| 284 | 2572 | psotfx | } |
| 285 | 2572 | psotfx | else
|
| 286 | 2572 | psotfx | {
|
| 287 | 2572 | psotfx | $match_word = addslashes('%' . str_replace('*', '', $split_search[$i]) . '%'); |
| 288 | 2572 | psotfx | $search_msg_only = ( $search_fields ) ? "OR post_subject LIKE '$match_word'" : ''; |
| 289 | 2572 | psotfx | $sql = "SELECT post_id |
| 290 | 2572 | psotfx | FROM " . POSTS_TEXT_TABLE . " |
| 291 | 2572 | psotfx | WHERE post_text LIKE '$match_word' |
| 292 | 2205 | psotfx | $search_msg_only"; |
| 293 | 2572 | psotfx | } |
| 294 | 2205 | psotfx | if ( !($result = $db->sql_query($sql)) ) |
| 295 | 2205 | psotfx | {
|
| 296 | 2326 | psotfx | message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql); |
| 297 | 2205 | psotfx | } |
| 298 | 1398 | psotfx | |
| 299 | 2205 | psotfx | $row = array(); |
| 300 | 2205 | psotfx | while( $temp_row = $db->sql_fetchrow($result) ) |
| 301 | 1398 | psotfx | {
|
| 302 | 2205 | psotfx | $row[$temp_row['post_id']] = 1; |
| 303 | 2205 | psotfx | |
| 304 | 2205 | psotfx | if ( !$word_count ) |
| 305 | 2205 | psotfx | {
|
| 306 | 2205 | psotfx | $result_list[$temp_row['post_id']] = 1; |
| 307 | 2205 | psotfx | } |
| 308 | 2326 | psotfx | else if ( $current_match_type == 'or' ) |
| 309 | 2205 | psotfx | {
|
| 310 | 2205 | psotfx | $result_list[$temp_row['post_id']] = 1; |
| 311 | 2205 | psotfx | } |
| 312 | 2326 | psotfx | else if ( $current_match_type == 'not' ) |
| 313 | 2205 | psotfx | {
|
| 314 | 2205 | psotfx | $result_list[$temp_row['post_id']] = 0; |
| 315 | 2205 | psotfx | } |
| 316 | 1293 | psotfx | } |
| 317 | 1867 | psotfx | |
| 318 | 2326 | psotfx | if ( $current_match_type == 'and' && $word_count ) |
| 319 | 2205 | psotfx | {
|
| 320 | 2205 | psotfx | @reset($result_list); |
| 321 | 2205 | psotfx | while( list($post_id, $match_count) = @each($result_list) ) |
| 322 | 2205 | psotfx | {
|
| 323 | 2205 | psotfx | if ( !$row[$post_id] ) |
| 324 | 2205 | psotfx | {
|
| 325 | 2205 | psotfx | $result_list[$post_id] = 0; |
| 326 | 2205 | psotfx | } |
| 327 | 2205 | psotfx | } |
| 328 | 2205 | psotfx | } |
| 329 | 1867 | psotfx | |
| 330 | 2205 | psotfx | $word_count++;
|
| 331 | 1867 | psotfx | |
| 332 | 2205 | psotfx | $db->sql_freeresult($result); |
| 333 | 2205 | psotfx | } |
| 334 | 1293 | psotfx | } |
| 335 | 2205 | psotfx | |
| 336 | 2205 | psotfx | @reset($result_list); |
| 337 | 2205 | psotfx | |
| 338 | 2205 | psotfx | $search_ids = array(); |
| 339 | 2205 | psotfx | while( list($post_id, $matches) = each($result_list) ) |
| 340 | 2205 | psotfx | {
|
| 341 | 2205 | psotfx | if ( $matches ) |
| 342 | 2205 | psotfx | {
|
| 343 | 2205 | psotfx | $search_ids[] = $post_id; |
| 344 | 2205 | psotfx | } |
| 345 | 2205 | psotfx | } |
| 346 | 2205 | psotfx | |
| 347 | 2205 | psotfx | unset($result_list); |
| 348 | 2205 | psotfx | $total_match_count = count($search_ids); |
| 349 | 1293 | psotfx | } |
| 350 | 1293 | psotfx | |
| 351 | 2205 | psotfx | //
|
| 352 | 2205 | psotfx | // If user is logged in then we'll check to see which (if any) private
|
| 353 | 2205 | psotfx | // forums they are allowed to view and include them in the search.
|
| 354 | 2205 | psotfx | //
|
| 355 | 2205 | psotfx | // If not logged in we explicitly prevent searching of private forums
|
| 356 | 2205 | psotfx | //
|
| 357 | 2326 | psotfx | $auth_sql = ''; |
| 358 | 2205 | psotfx | if ( $search_forum != -1 ) |
| 359 | 2205 | psotfx | {
|
| 360 | 2205 | psotfx | $is_auth = auth(AUTH_READ, $search_forum, $userdata); |
| 361 | 1412 | psotfx | |
| 362 | 2205 | psotfx | if ( !$is_auth['auth_read'] ) |
| 363 | 2205 | psotfx | {
|
| 364 | 2205 | psotfx | message_die(GENERAL_MESSAGE, $lang['No_searchable_forums']); |
| 365 | 2205 | psotfx | } |
| 366 | 2205 | psotfx | |
| 367 | 2205 | psotfx | $auth_sql = "f.forum_id = $search_forum"; |
| 368 | 2205 | psotfx | } |
| 369 | 2205 | psotfx | else
|
| 370 | 1293 | psotfx | {
|
| 371 | 2205 | psotfx | $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata); |
| 372 | 2205 | psotfx | |
| 373 | 2205 | psotfx | if ( $search_cat != -1 ) |
| 374 | 1293 | psotfx | {
|
| 375 | 2205 | psotfx | $auth_sql = "f.cat_id = $search_cat"; |
| 376 | 1293 | psotfx | } |
| 377 | 1293 | psotfx | |
| 378 | 2326 | psotfx | $ignore_forum_sql = ''; |
| 379 | 2205 | psotfx | while( list($key, $value) = each($is_auth_ary) ) |
| 380 | 2205 | psotfx | {
|
| 381 | 2205 | psotfx | if ( !$value['auth_read'] ) |
| 382 | 2205 | psotfx | {
|
| 383 | 2326 | psotfx | $ignore_forum_sql .= ( ( $ignore_forum_sql != '' ) ? ', ' : '' ) . $key; |
| 384 | 2205 | psotfx | } |
| 385 | 2205 | psotfx | } |
| 386 | 1511 | psotfx | |
| 387 | 2326 | psotfx | if ( $ignore_forum_sql != '' ) |
| 388 | 2205 | psotfx | {
|
| 389 | 2326 | psotfx | $auth_sql .= ( $auth_sql != '' ) ? " AND f.forum_id NOT IN ($ignore_forum_sql) " : "f.forum_id NOT IN ($ignore_forum_sql) "; |
| 390 | 2205 | psotfx | } |
| 391 | 1311 | thefinn | } |
| 392 | 1938 | psotfx | |
| 393 | 2205 | psotfx | //
|
| 394 | 2205 | psotfx | // Author name search
|
| 395 | 2205 | psotfx | //
|
| 396 | 2326 | psotfx | if ( $search_author != '' ) |
| 397 | 1511 | psotfx | {
|
| 398 | 2326 | psotfx | $search_author = str_replace('*', '%', trim(str_replace("\'", "''", $search_author))); |
| 399 | 1511 | psotfx | } |
| 400 | 1293 | psotfx | |
| 401 | 2205 | psotfx | if ( $total_match_count ) |
| 402 | 1511 | psotfx | {
|
| 403 | 2326 | psotfx | if ( $show_results == 'topics' ) |
| 404 | 1051 | psotfx | {
|
| 405 | 2326 | psotfx | $where_sql = ''; |
| 406 | 2205 | psotfx | |
| 407 | 2205 | psotfx | if ( $search_time ) |
| 408 | 1089 | psotfx | {
|
| 409 | 2326 | psotfx | $where_sql .= ( $search_author == '' && $auth_sql == '' ) ? " AND post_time >= $search_time " : " AND p.post_time >= $search_time "; |
| 410 | 1089 | psotfx | } |
| 411 | 1089 | psotfx | |
| 412 | 2326 | psotfx | if ( $search_author == '' && $auth_sql == '' ) |
| 413 | 2205 | psotfx | {
|
| 414 | 2205 | psotfx | $sql = "SELECT topic_id |
| 415 | 2205 | psotfx | FROM " . POSTS_TABLE . " |
| 416 | 2205 | psotfx | WHERE post_id IN (" . implode(", ", $search_ids) . ") |
| 417 | 2205 | psotfx | $where_sql |
| 418 | 2205 | psotfx | GROUP BY topic_id";
|
| 419 | 2205 | psotfx | } |
| 420 | 2205 | psotfx | else
|
| 421 | 2205 | psotfx | {
|
| 422 | 2205 | psotfx | $from_sql = POSTS_TABLE . " p"; |
| 423 | 1089 | psotfx | |
| 424 | 2205 | psotfx | if ( $search_author != '' ) |
| 425 | 2205 | psotfx | {
|
| 426 | 2205 | psotfx | $from_sql .= ", " . USERS_TABLE . " u"; |
| 427 | 2205 | psotfx | $where_sql .= " AND u.user_id = p.poster_id AND u.username LIKE '$search_author' "; |
| 428 | 2205 | psotfx | } |
| 429 | 1938 | psotfx | |
| 430 | 2205 | psotfx | if ( $auth_sql != '' ) |
| 431 | 2205 | psotfx | {
|
| 432 | 2205 | psotfx | $from_sql .= ", " . FORUMS_TABLE . " f"; |
| 433 | 2205 | psotfx | $where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql"; |
| 434 | 2205 | psotfx | } |
| 435 | 1938 | psotfx | |
| 436 | 2205 | psotfx | $sql = "SELECT p.topic_id |
| 437 | 2205 | psotfx | FROM $from_sql |
| 438 | 2205 | psotfx | WHERE p.post_id IN (" . implode(", ", $search_ids) . ") |
| 439 | 2205 | psotfx | $where_sql |
| 440 | 2205 | psotfx | GROUP BY p.topic_id";
|
| 441 | 2205 | psotfx | } |
| 442 | 1938 | psotfx | |
| 443 | 2205 | psotfx | if ( !($result = $db->sql_query($sql)) ) |
| 444 | 2205 | psotfx | {
|
| 445 | 2326 | psotfx | message_die(GENERAL_ERROR, 'Could not obtain topic ids', '', __LINE__, __FILE__, $sql); |
| 446 | 2205 | psotfx | } |
| 447 | 2205 | psotfx | |
| 448 | 2205 | psotfx | $search_ids = array(); |
| 449 | 2205 | psotfx | while( $row = $db->sql_fetchrow($result) ) |
| 450 | 2205 | psotfx | {
|
| 451 | 2205 | psotfx | $search_ids[] = $row['topic_id']; |
| 452 | 2205 | psotfx | } |
| 453 | 2205 | psotfx | $db->sql_freeresult($result); |
| 454 | 2205 | psotfx | |
| 455 | 2205 | psotfx | $total_match_count = sizeof($search_ids); |
| 456 | 2205 | psotfx | |
| 457 | 1938 | psotfx | } |
| 458 | 2205 | psotfx | else if ( $search_author != '' || $search_time || $auth_sql != '' ) |
| 459 | 1938 | psotfx | {
|
| 460 | 2498 | psotfx | $where_sql = ( $search_author == '' && $auth_sql == '' ) ? 'post_id IN (' . implode(', ', $search_ids) . ')' : 'p.post_id IN (' . implode(', ', $search_ids) . ')'; |
| 461 | 2498 | psotfx | $from_sql = ( $search_author == '' && $auth_sql == '' ) ? POSTS_TABLE : POSTS_TABLE . ' p'; |
| 462 | 1938 | psotfx | |
| 463 | 2205 | psotfx | if ( $search_time ) |
| 464 | 1938 | psotfx | {
|
| 465 | 2326 | psotfx | $where_sql .= ( $search_author == '' && $auth_sql == '' ) ? " AND post_time >= $search_time " : " AND p.post_time >= $search_time"; |
| 466 | 1938 | psotfx | } |
| 467 | 1938 | psotfx | |
| 468 | 2205 | psotfx | if ( $auth_sql != '' ) |
| 469 | 1938 | psotfx | {
|
| 470 | 1938 | psotfx | $from_sql .= ", " . FORUMS_TABLE . " f"; |
| 471 | 1938 | psotfx | $where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql"; |
| 472 | 1938 | psotfx | } |
| 473 | 1938 | psotfx | |
| 474 | 2205 | psotfx | if ( $search_author != '' ) |
| 475 | 2205 | psotfx | {
|
| 476 | 2205 | psotfx | $from_sql .= ", " . USERS_TABLE . " u"; |
| 477 | 2205 | psotfx | $where_sql .= " AND u.user_id = p.poster_id AND u.username LIKE '$search_author'"; |
| 478 | 2205 | psotfx | } |
| 479 | 2205 | psotfx | |
| 480 | 2205 | psotfx | $sql = "SELECT p.post_id |
| 481 | 1938 | psotfx | FROM $from_sql |
| 482 | 2205 | psotfx | WHERE $where_sql"; |
| 483 | 2205 | psotfx | if ( !($result = $db->sql_query($sql)) ) |
| 484 | 2205 | psotfx | {
|
| 485 | 2326 | psotfx | message_die(GENERAL_ERROR, 'Could not obtain post ids', '', __LINE__, __FILE__, $sql); |
| 486 | 2205 | psotfx | } |
| 487 | 1938 | psotfx | |
| 488 | 2205 | psotfx | $search_ids = array(); |
| 489 | 2205 | psotfx | while( $row = $db->sql_fetchrow($result) ) |
| 490 | 2205 | psotfx | {
|
| 491 | 2205 | psotfx | $search_ids[] = $row['post_id']; |
| 492 | 2205 | psotfx | } |
| 493 | 1938 | psotfx | |
| 494 | 2205 | psotfx | $db->sql_freeresult($result); |
| 495 | 1938 | psotfx | |
| 496 | 2205 | psotfx | $total_match_count = count($search_ids); |
| 497 | 2205 | psotfx | } |
| 498 | 1511 | psotfx | } |
| 499 | 2205 | psotfx | else if ( $search_id == 'unanswered' ) |
| 500 | 1938 | psotfx | {
|
| 501 | 2326 | psotfx | if ( $auth_sql != '' ) |
| 502 | 1938 | psotfx | {
|
| 503 | 2205 | psotfx | $sql = "SELECT t.topic_id, f.forum_id |
| 504 | 2205 | psotfx | FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f |
| 505 | 2205 | psotfx | WHERE t.topic_replies = 0 |
| 506 | 2205 | psotfx | AND t.forum_id = f.forum_id |
| 507 | 2205 | psotfx | AND t.topic_moved_id = 0 |
| 508 | 2205 | psotfx | AND $auth_sql"; |
| 509 | 1938 | psotfx | } |
| 510 | 2205 | psotfx | else
|
| 511 | 1938 | psotfx | {
|
| 512 | 2205 | psotfx | $sql = "SELECT topic_id |
| 513 | 2205 | psotfx | FROM " . TOPICS_TABLE . " |
| 514 | 2205 | psotfx | WHERE topic_replies = 0 |
| 515 | 2205 | psotfx | AND topic_moved_id = 0";
|
| 516 | 1938 | psotfx | } |
| 517 | 2205 | psotfx | |
| 518 | 2205 | psotfx | if ( !($result = $db->sql_query($sql)) ) |
| 519 | 1938 | psotfx | {
|
| 520 | 2326 | psotfx | message_die(GENERAL_ERROR, 'Could not obtain post ids', '', __LINE__, __FILE__, $sql); |
| 521 | 1938 | psotfx | } |
| 522 | 1938 | psotfx | |
| 523 | 1938 | psotfx | $search_ids = array(); |
| 524 | 1938 | psotfx | while( $row = $db->sql_fetchrow($result) ) |
| 525 | 1938 | psotfx | {
|
| 526 | 2205 | psotfx | $search_ids[] = $row['topic_id']; |
| 527 | 1938 | psotfx | } |
| 528 | 1938 | psotfx | $db->sql_freeresult($result); |
| 529 | 1938 | psotfx | |
| 530 | 1938 | psotfx | $total_match_count = count($search_ids); |
| 531 | 2205 | psotfx | |
| 532 | 2205 | psotfx | //
|
| 533 | 2205 | psotfx | // Basic requirements
|
| 534 | 2205 | psotfx | //
|
| 535 | 2326 | psotfx | $show_results = 'topics'; |
| 536 | 2205 | psotfx | $sort_by = 0; |
| 537 | 2326 | psotfx | $sort_dir = 'DESC'; |
| 538 | 1938 | psotfx | } |
| 539 | 2048 | thefinn | else
|
| 540 | 2048 | thefinn | {
|
| 541 | 2205 | psotfx | message_die(GENERAL_MESSAGE, $lang['No_search_match']); |
| 542 | 2048 | thefinn | } |
| 543 | 1293 | psotfx | |
| 544 | 1511 | psotfx | //
|
| 545 | 2205 | psotfx | // Finish building query (for all combinations)
|
| 546 | 2205 | psotfx | // and run it ...
|
| 547 | 1938 | psotfx | //
|
| 548 | 1511 | psotfx | $sql = "SELECT session_id |
| 549 | 1511 | psotfx | FROM " . SESSIONS_TABLE; |
| 550 | 2205 | psotfx | if ( $result = $db->sql_query($sql) ) |
| 551 | 1511 | psotfx | {
|
| 552 | 1938 | psotfx | $delete_search_ids = array(); |
| 553 | 1511 | psotfx | while( $row = $db->sql_fetchrow($result) ) |
| 554 | 1293 | psotfx | {
|
| 555 | 1938 | psotfx | $delete_search_ids[] = "'" . $row['session_id'] . "'"; |
| 556 | 1511 | psotfx | } |
| 557 | 1051 | psotfx | |
| 558 | 2205 | psotfx | if ( count($delete_search_ids) ) |
| 559 | 1511 | psotfx | {
|
| 560 | 1511 | psotfx | $sql = "DELETE FROM " . SEARCH_TABLE . " |
| 561 | 1938 | psotfx | WHERE session_id NOT IN (" . implode(", ", $delete_search_ids) . ")"; |
| 562 | 2205 | psotfx | if ( !$result = $db->sql_query($sql) ) |
| 563 | 1051 | psotfx | {
|
| 564 | 2326 | psotfx | message_die(GENERAL_ERROR, 'Could not delete old search id sessions', '', __LINE__, __FILE__, $sql); |
| 565 | 1051 | psotfx | } |
| 566 | 1293 | psotfx | } |
| 567 | 1511 | psotfx | } |
| 568 | 1051 | psotfx | |
| 569 | 1511 | psotfx | //
|
| 570 | 1511 | psotfx | // Store new result data
|
| 571 | 1511 | psotfx | //
|
| 572 | 2326 | psotfx | $search_results = implode(', ', $search_ids); |
| 573 | 2326 | psotfx | $per_page = ( $show_results == 'posts' ) ? $board_config['posts_per_page'] : $board_config['topics_per_page']; |
| 574 | 2205 | psotfx | |
| 575 | 2205 | psotfx | //
|
| 576 | 2205 | psotfx | // Combine both results and search data (apart from original query)
|
| 577 | 2205 | psotfx | // so we can serialize it and place it in the DB
|
| 578 | 2205 | psotfx | //
|
| 579 | 2205 | psotfx | $store_search_data = array(); |
| 580 | 2205 | psotfx | for($i = 0; $i < count($store_vars); $i++) |
| 581 | 1511 | psotfx | {
|
| 582 | 2205 | psotfx | $store_search_data[$store_vars[$i]] = $$store_vars[$i]; |
| 583 | 2205 | psotfx | } |
| 584 | 1293 | psotfx | |
| 585 | 2205 | psotfx | $result_array = serialize($store_search_data); |
| 586 | 2205 | psotfx | unset($store_search_data); |
| 587 | 1051 | psotfx | |
| 588 | 2205 | psotfx | mt_srand ((double) microtime() * 1000000); |
| 589 | 2205 | psotfx | $search_id = mt_rand();
|
| 590 | 1938 | psotfx | |
| 591 | 2205 | psotfx | $sql = "UPDATE " . SEARCH_TABLE . " |
| 592 | 2205 | psotfx | SET search_id = $search_id, search_array = '$result_array' |
| 593 | 2205 | psotfx | WHERE session_id = '" . $userdata['session_id'] . "'"; |
| 594 | 2205 | psotfx | if ( !($result = $db->sql_query($sql)) || !$db->sql_affectedrows() ) |
| 595 | 2205 | psotfx | {
|
| 596 | 2205 | psotfx | $sql = "INSERT INTO " . SEARCH_TABLE . " (search_id, session_id, search_array) |
| 597 | 2205 | psotfx | VALUES($search_id, '" . $userdata['session_id'] . "', '" . str_replace("\'", "''", $result_array) . "')"; |
| 598 | 2205 | psotfx | if ( !($result = $db->sql_query($sql)) ) |
| 599 | 1511 | psotfx | {
|
| 600 | 2326 | psotfx | message_die(GENERAL_ERROR, 'Could not insert search results', '', __LINE__, __FILE__, $sql); |
| 601 | 1511 | psotfx | } |
| 602 | 382 | psotfx | } |
| 603 | 1051 | psotfx | } |
| 604 | 2205 | psotfx | else
|
| 605 | 1051 | psotfx | {
|
| 606 | 2454 | psotfx | if ( intval($search_id) ) |
| 607 | 382 | psotfx | {
|
| 608 | 2452 | psotfx | $sql = "SELECT search_array |
| 609 | 2452 | psotfx | FROM " . SEARCH_TABLE . " |
| 610 | 2452 | psotfx | WHERE search_id = $search_id |
| 611 | 2452 | psotfx | AND session_id = '". $userdata['session_id'] . "'"; |
| 612 | 2452 | psotfx | if ( !($result = $db->sql_query($sql)) ) |
| 613 | 2452 | psotfx | {
|
| 614 | 2452 | psotfx | message_die(GENERAL_ERROR, 'Could not obtain search results', '', __LINE__, __FILE__, $sql); |
| 615 | 2452 | psotfx | } |
| 616 | 368 | psotfx | |
| 617 | 2452 | psotfx | if ( $row = $db->sql_fetchrow($result) ) |
| 618 | 2205 | psotfx | {
|
| 619 | 2452 | psotfx | $search_data = unserialize($row['search_array']); |
| 620 | 2452 | psotfx | for($i = 0; $i < count($store_vars); $i++) |
| 621 | 2452 | psotfx | {
|
| 622 | 2452 | psotfx | $$store_vars[$i] = $search_data[$store_vars[$i]]; |
| 623 | 2452 | psotfx | } |
| 624 | 2205 | psotfx | } |
| 625 | 1051 | psotfx | } |
| 626 | 1051 | psotfx | } |
| 627 | 368 | psotfx | |
| 628 | 2205 | psotfx | //
|
| 629 | 2205 | psotfx | // Look up data ...
|
| 630 | 2205 | psotfx | //
|
| 631 | 2326 | psotfx | if ( $search_results != '' ) |
| 632 | 1051 | psotfx | {
|
| 633 | 2326 | psotfx | if ( $show_results == 'posts' ) |
| 634 | 1938 | psotfx | {
|
| 635 | 1938 | psotfx | $sql = "SELECT pt.post_text, pt.bbcode_uid, pt.post_subject, p.*, f.forum_id, f.forum_name, t.*, u.username, u.user_id, u.user_sig, u.user_sig_bbcode_uid |
| 636 | 1938 | psotfx | FROM " . FORUMS_TABLE . " f, " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TEXT_TABLE . " pt |
| 637 | 1938 | psotfx | WHERE p.post_id IN ($search_results) |
| 638 | 1938 | psotfx | AND pt.post_id = p.post_id |
| 639 | 1938 | psotfx | AND f.forum_id = p.forum_id |
| 640 | 1938 | psotfx | AND p.topic_id = t.topic_id |
| 641 | 1938 | psotfx | AND p.poster_id = u.user_id";
|
| 642 | 1938 | psotfx | } |
| 643 | 1938 | psotfx | else
|
| 644 | 1938 | psotfx | {
|
| 645 | 2448 | psotfx | $sql = "SELECT t.*, f.forum_id, f.forum_name, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time |
| 646 | 2448 | psotfx | FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2 |
| 647 | 1938 | psotfx | WHERE t.topic_id IN ($search_results) |
| 648 | 2448 | psotfx | AND t.topic_poster = u.user_id |
| 649 | 1938 | psotfx | AND f.forum_id = t.forum_id |
| 650 | 2448 | psotfx | AND p.post_id = t.topic_first_post_id |
| 651 | 2448 | psotfx | AND p2.post_id = t.topic_last_post_id |
| 652 | 2448 | psotfx | AND u2.user_id = p2.poster_id";
|
| 653 | 1938 | psotfx | } |
| 654 | 2498 | psotfx | |
| 655 | 2326 | psotfx | $per_page = ( $show_results == 'posts' ) ? $board_config['posts_per_page'] : $board_config['topics_per_page']; |
| 656 | 1051 | psotfx | |
| 657 | 2498 | psotfx | $sql .= " ORDER BY "; |
| 658 | 2498 | psotfx | switch ( $sort_by ) |
| 659 | 2498 | psotfx | {
|
| 660 | 2498 | psotfx | case 1: |
| 661 | 2498 | psotfx | $sql .= ( $show_results == 'posts' ) ? 'pt.post_subject' : 't.topic_title'; |
| 662 | 2498 | psotfx | break;
|
| 663 | 2498 | psotfx | case 2: |
| 664 | 2498 | psotfx | $sql .= 't.topic_title'; |
| 665 | 2498 | psotfx | break;
|
| 666 | 2498 | psotfx | case 3: |
| 667 | 2498 | psotfx | $sql .= 'u.username'; |
| 668 | 2498 | psotfx | break;
|
| 669 | 2498 | psotfx | case 4: |
| 670 | 2498 | psotfx | $sql .= 'f.forum_id'; |
| 671 | 2498 | psotfx | break;
|
| 672 | 2498 | psotfx | default:
|
| 673 | 2498 | psotfx | $sql .= ( $show_results == 'posts' ) ? 'p.post_time' : 'p2.post_time'; |
| 674 | 2498 | psotfx | break;
|
| 675 | 2498 | psotfx | } |
| 676 | 2498 | psotfx | $sql .= " $sort_dir LIMIT $start, " . $per_page; |
| 677 | 1938 | psotfx | |
| 678 | 2205 | psotfx | if ( !$result = $db->sql_query($sql) ) |
| 679 | 1938 | psotfx | {
|
| 680 | 2326 | psotfx | message_die(GENERAL_ERROR, 'Could not obtain search results', '', __LINE__, __FILE__, $sql); |
| 681 | 1938 | psotfx | } |
| 682 | 1938 | psotfx | |
| 683 | 1938 | psotfx | $searchset = array(); |
| 684 | 1938 | psotfx | while( $row = $db->sql_fetchrow($result) ) |
| 685 | 1938 | psotfx | {
|
| 686 | 1938 | psotfx | $searchset[] = $row; |
| 687 | 1938 | psotfx | } |
| 688 | 1938 | psotfx | |
| 689 | 1938 | psotfx | $db->sql_freeresult($result); |
| 690 | 1938 | psotfx | |
| 691 | 1051 | psotfx | //
|
| 692 | 1051 | psotfx | // Define censored word matches
|
| 693 | 1051 | psotfx | //
|
| 694 | 1051 | psotfx | $orig_word = array(); |
| 695 | 1051 | psotfx | $replacement_word = array(); |
| 696 | 1051 | psotfx | obtain_word_list($orig_word, $replacement_word); |
| 697 | 1051 | psotfx | |
| 698 | 1938 | psotfx | //
|
| 699 | 1938 | psotfx | // Output header
|
| 700 | 1938 | psotfx | //
|
| 701 | 1938 | psotfx | $page_title = $lang['Search']; |
| 702 | 1938 | psotfx | include($phpbb_root_path . 'includes/page_header.'.$phpEx); |
| 703 | 1938 | psotfx | |
| 704 | 2326 | psotfx | if ( $show_results == 'posts' ) |
| 705 | 1051 | psotfx | {
|
| 706 | 1051 | psotfx | $template->set_filenames(array( |
| 707 | 2448 | psotfx | 'body' => 'search_results_posts.tpl') |
| 708 | 1051 | psotfx | ); |
| 709 | 1051 | psotfx | } |
| 710 | 1051 | psotfx | else
|
| 711 | 1051 | psotfx | {
|
| 712 | 1051 | psotfx | $template->set_filenames(array( |
| 713 | 2448 | psotfx | 'body' => 'search_results_topics.tpl') |
| 714 | 1051 | psotfx | ); |
| 715 | 1051 | psotfx | } |
| 716 | 2448 | psotfx | make_jumpbox('viewforum.'.$phpEx); |
| 717 | 1051 | psotfx | |
| 718 | 1368 | psotfx | $l_search_matches = ( $total_match_count == 1 ) ? sprintf($lang['Found_search_match'], $total_match_count) : sprintf($lang['Found_search_matches'], $total_match_count); |
| 719 | 1368 | psotfx | |
| 720 | 1051 | psotfx | $template->assign_vars(array( |
| 721 | 2326 | psotfx | 'L_SEARCH_MATCHES' => $l_search_matches, |
| 722 | 2326 | psotfx | 'L_TOPIC' => $lang['Topic']) |
| 723 | 1051 | psotfx | ); |
| 724 | 1051 | psotfx | |
| 725 | 2448 | psotfx | $highlight_active = ''; |
| 726 | 2448 | psotfx | $highlight_match = array(); |
| 727 | 1293 | psotfx | for($j = 0; $j < count($split_search); $j++ ) |
| 728 | 1051 | psotfx | {
|
| 729 | 1293 | psotfx | $split_word = $split_search[$j]; |
| 730 | 1293 | psotfx | |
| 731 | 2448 | psotfx | if ( $split_word != 'and' && $split_word != 'or' && $split_word != 'not' ) |
| 732 | 1293 | psotfx | {
|
| 733 | 2448 | psotfx | $highlight_match[] = '#\b(' . str_replace("*", "([\w]+)?", $split_word) . ')\b#is'; |
| 734 | 1370 | psotfx | $highlight_active .= " " . $split_word; |
| 735 | 1293 | psotfx | |
| 736 | 1293 | psotfx | for ($k = 0; $k < count($synonym_array); $k++) |
| 737 | 1293 | psotfx | {
|
| 738 | 2326 | psotfx | list($replace_synonym, $match_synonym) = split(' ', trim(strtolower($synonym_array[$k]))); |
| 739 | 1293 | psotfx | |
| 740 | 2448 | psotfx | if ( $replace_synonym == $split_word ) |
| 741 | 1293 | psotfx | {
|
| 742 | 2448 | psotfx | $highlight_match[] = '#\b(' . str_replace("*", "([\w]+)?", $replace_synonym) . ')\b#is'; |
| 743 | 2326 | psotfx | $highlight_active .= ' ' . $match_synonym; |
| 744 | 1293 | psotfx | } |
| 745 | 1293 | psotfx | } |
| 746 | 1293 | psotfx | } |
| 747 | 1051 | psotfx | } |
| 748 | 1051 | psotfx | |
| 749 | 1370 | psotfx | $highlight_active = urlencode(trim($highlight_active)); |
| 750 | 1293 | psotfx | |
| 751 | 2326 | psotfx | $tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array(); |
| 752 | 2326 | psotfx | $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array(); |
| 753 | 1851 | psotfx | |
| 754 | 1938 | psotfx | for($i = 0; $i < count($searchset); $i++) |
| 755 | 1051 | psotfx | {
|
| 756 | 2448 | psotfx | $forum_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . '=' . $searchset[$i]['forum_id']); |
| 757 | 2448 | psotfx | $topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $searchset[$i]['topic_id'] . "&highlight=$highlight_active"); |
| 758 | 2507 | psotfx | $post_url = append_sid("viewtopic.$phpEx?" . POST_POST_URL . '=' . $searchset[$i]['post_id'] . "&highlight=$highlight_active") . '#' . $searchset[$i]['post_id']; |
| 759 | 1051 | psotfx | |
| 760 | 1051 | psotfx | $post_date = create_date($board_config['default_dateformat'], $searchset[$i]['post_time'], $board_config['board_timezone']); |
| 761 | 1051 | psotfx | |
| 762 | 1051 | psotfx | $message = $searchset[$i]['post_text']; |
| 763 | 1348 | psotfx | $topic_title = $searchset[$i]['topic_title']; |
| 764 | 1051 | psotfx | |
| 765 | 1851 | psotfx | $forum_id = $searchset[$i]['forum_id']; |
| 766 | 1851 | psotfx | $topic_id = $searchset[$i]['topic_id']; |
| 767 | 1851 | psotfx | |
| 768 | 2448 | psotfx | if ( $show_results == 'posts' ) |
| 769 | 373 | psotfx | {
|
| 770 | 2448 | psotfx | if ( isset($return_chars) ) |
| 771 | 1051 | psotfx | {
|
| 772 | 1423 | psotfx | $bbcode_uid = $searchset[$i]['bbcode_uid']; |
| 773 | 1423 | psotfx | |
| 774 | 1051 | psotfx | //
|
| 775 | 1051 | psotfx | // If the board has HTML off but the post has HTML
|
| 776 | 1051 | psotfx | // on then we process it, else leave it alone
|
| 777 | 1051 | psotfx | //
|
| 778 | 2448 | psotfx | if ( $return_chars != -1 ) |
| 779 | 1051 | psotfx | {
|
| 780 | 1423 | psotfx | $message = strip_tags($message); |
| 781 | 2355 | psotfx | $message = preg_replace("/\[.*?:$bbcode_uid:?.*?\]/si", '', $message); |
| 782 | 2355 | psotfx | $message = preg_replace('/\[url\]|\[\/url\]/si', '', $message); |
| 783 | 2355 | psotfx | $message = ( strlen($message) > $return_chars ) ? substr($message, 0, $return_chars) . ' ...' : $message; |
| 784 | 1511 | psotfx | |
| 785 | 2448 | psotfx | if ( count($search_string) ) |
| 786 | 1511 | psotfx | {
|
| 787 | 1511 | psotfx | $message = preg_replace($search_string, $replace_string, $message); |
| 788 | 1511 | psotfx | } |
| 789 | 1051 | psotfx | } |
| 790 | 1051 | psotfx | else
|
| 791 | 1051 | psotfx | {
|
| 792 | 2448 | psotfx | if ( !$board_config['allow_html'] ) |
| 793 | 1051 | psotfx | {
|
| 794 | 2448 | psotfx | if ( $postrow[$i]['enable_html'] ) |
| 795 | 1051 | psotfx | {
|
| 796 | 2326 | psotfx | $message = preg_replace('#(<)([\/]?.*?)(>)#is', '<\\2>', $message); |
| 797 | 1051 | psotfx | } |
| 798 | 1051 | psotfx | } |
| 799 | 1051 | psotfx | |
| 800 | 2448 | psotfx | if ( $bbcode_uid != '' ) |
| 801 | 1051 | psotfx | {
|
| 802 | 2326 | psotfx | $message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $message); |
| 803 | 1051 | psotfx | } |
| 804 | 1051 | psotfx | |
| 805 | 1555 | natec | $message = make_clickable($message); |
| 806 | 1566 | psotfx | |
| 807 | 2448 | psotfx | if ( $highlight_active ) |
| 808 | 1566 | psotfx | {
|
| 809 | 2448 | psotfx | if ( preg_match('/<.*>/', $message) ) |
| 810 | 2448 | psotfx | {
|
| 811 | 2448 | psotfx | $message = preg_replace($highlight_match, '<!-- #sh -->\1<!-- #eh -->', $message); |
| 812 | 2448 | psotfx | |
| 813 | 2448 | psotfx | $end_html = 0; |
| 814 | 2448 | psotfx | $start_html = 1; |
| 815 | 2448 | psotfx | $temp_message = ''; |
| 816 | 2448 | psotfx | $message = ' ' . $message . ' '; |
| 817 | 2448 | psotfx | |
| 818 | 2448 | psotfx | while( $start_html = strpos($message, '<', $start_html) ) |
| 819 | 2448 | psotfx | {
|
| 820 | 2448 | psotfx | $grab_length = $start_html - $end_html - 1; |
| 821 | 2448 | psotfx | $temp_message .= substr($message, $end_html + 1, $grab_length); |
| 822 | 2448 | psotfx | |
| 823 | 2448 | psotfx | if ( $end_html = strpos($message, '>', $start_html) ) |
| 824 | 2448 | psotfx | {
|
| 825 | 2448 | psotfx | $length = $end_html - $start_html + 1; |
| 826 | 2448 | psotfx | $hold_string = substr($message, $start_html, $length); |
| 827 | 2448 | psotfx | |
| 828 | 2448 | psotfx | if ( strrpos(' ' . $hold_string, '<') != 1 ) |
| 829 | 2448 | psotfx | {
|
| 830 | 2448 | psotfx | $end_html = $start_html + 1; |
| 831 | 2448 | psotfx | $end_counter = 1; |
| 832 | 2448 | psotfx | |
| 833 | 2448 | psotfx | while ( $end_counter && $end_html < strlen($message) ) |
| 834 | 2448 | psotfx | {
|
| 835 | 2448 | psotfx | if ( substr($message, $end_html, 1) == '>' ) |
| 836 | 2448 | psotfx | {
|
| 837 | 2448 | psotfx | $end_counter--;
|
| 838 | 2448 | psotfx | } |
| 839 | 2448 | psotfx | else if ( substr($message, $end_html, 1) == '<' ) |
| 840 | 2448 | psotfx | {
|
| 841 | 2448 | psotfx | $end_counter++;
|
| 842 | 2448 | psotfx | } |
| 843 | 2448 | psotfx | |
| 844 | 2448 | psotfx | $end_html++;
|
| 845 | 2448 | psotfx | } |
| 846 | 2448 | psotfx | |
| 847 | 2448 | psotfx | $length = $end_html - $start_html + 1; |
| 848 | 2448 | psotfx | $hold_string = substr($message, $start_html, $length); |
| 849 | 2448 | psotfx | $hold_string = str_replace('<!-- #sh -->', '', $hold_string); |
| 850 | 2448 | psotfx | $hold_string = str_replace('<!-- #eh -->', '', $hold_string); |
| 851 | 2448 | psotfx | } |
| 852 | 2448 | psotfx | else if ( $hold_string == '<!-- #sh -->' ) |
| 853 | 2448 | psotfx | {
|
| 854 | 2448 | psotfx | $hold_string = str_replace('<!-- #sh -->', '<span style="color:#' . $theme['fontcolor3'] . '"><b>', $hold_string); |
| 855 | 2448 | psotfx | } |
| 856 | 2448 | psotfx | else if ( $hold_string == '<!-- #eh -->' ) |
| 857 | 2448 | psotfx | {
|
| 858 | 2448 | psotfx | $hold_string = str_replace('<!-- #eh -->', '</b></span>', $hold_string); |
| 859 | 2448 | psotfx | } |
| 860 | 2448 | psotfx | |
| 861 | 2448 | psotfx | $temp_message .= $hold_string; |
| 862 | 2448 | psotfx | |
| 863 | 2448 | psotfx | $start_html += $length; |
| 864 | 2448 | psotfx | } |
| 865 | 2448 | psotfx | else
|
| 866 | 2448 | psotfx | {
|
| 867 | 2448 | psotfx | $start_html = strlen($message); |
| 868 | 2448 | psotfx | } |
| 869 | 2448 | psotfx | } |
| 870 | 2448 | psotfx | |
| 871 | 2448 | psotfx | $grab_length = strlen($message) - $end_html - 1; |
| 872 | 2448 | psotfx | $temp_message .= substr($message, $end_html + 1, $grab_length); |
| 873 | 2448 | psotfx | |
| 874 | 2448 | psotfx | $message = trim($temp_message); |
| 875 | 2448 | psotfx | } |
| 876 | 2448 | psotfx | else
|
| 877 | 2448 | psotfx | {
|
| 878 | 2448 | psotfx | $message = preg_replace($highlight_match, '<span style="color:#' . $theme['fontcolor3'] . '"><b>\1</b></span>', $message); |
| 879 | 2448 | psotfx | } |
| 880 | 1566 | psotfx | } |
| 881 | 1051 | psotfx | } |
| 882 | 1051 | psotfx | |
| 883 | 2448 | psotfx | if ( count($orig_word) ) |
| 884 | 1051 | psotfx | {
|
| 885 | 1348 | psotfx | $topic_title = preg_replace($orig_word, $replacement_word, $topic_title); |
| 886 | 1051 | psotfx | $post_subject = ( $searchset[$i]['post_subject'] != "" ) ? preg_replace($orig_word, $replacement_word, $searchset[$i]['post_subject']) : $topic_title; |
| 887 | 1051 | psotfx | |
| 888 | 1051 | psotfx | $message = preg_replace($orig_word, $replacement_word, $message); |
| 889 | 1051 | psotfx | } |
| 890 | 1349 | psotfx | else
|
| 891 | 1349 | psotfx | {
|
| 892 | 2326 | psotfx | $post_subject = ( $searchset[$i]['post_subject'] != '' ) ? $searchset[$i]['post_subject'] : $topic_title; |
| 893 | 1349 | psotfx | } |
| 894 | 1051 | psotfx | |
| 895 | 2448 | psotfx | if ($board_config['allow_smilies'] && $searchset[$i]['enable_smilies']) |
| 896 | 1051 | psotfx | {
|
| 897 | 1051 | psotfx | $message = smilies_pass($message); |
| 898 | 1051 | psotfx | } |
| 899 | 1051 | psotfx | |
| 900 | 2326 | psotfx | $message = str_replace("\n", '<br />', $message); |
| 901 | 1051 | psotfx | |
| 902 | 1051 | psotfx | } |
| 903 | 1511 | psotfx | |
| 904 | 2326 | psotfx | $poster = ( $searchset[$i]['user_id'] != ANONYMOUS ) ? '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $searchset[$i]['user_id']) . '">' : ''; |
| 905 | 1947 | psotfx | $poster .= ( $searchset[$i]['user_id'] != ANONYMOUS ) ? $searchset[$i]['username'] : ( ( $searchset[$i]['post_username'] != "" ) ? $searchset[$i]['post_username'] : $lang['Guest'] ); |
| 906 | 2326 | psotfx | $poster .= ( $searchset[$i]['user_id'] != ANONYMOUS ) ? '</a>' : ''; |
| 907 | 1947 | psotfx | |
| 908 | 2448 | psotfx | if ( $userdata['session_logged_in'] && $searchset[$i]['post_time'] > $userdata['user_lastvisit'] ) |
| 909 | 1851 | psotfx | {
|
| 910 | 2448 | psotfx | if ( !empty($tracking_topics[$topic_id]) && !empty($tracking_forums[$forum_id]) ) |
| 911 | 1851 | psotfx | {
|
| 912 | 2385 | psotfx | $topic_last_read = ( $tracking_topics[$topic_id] > $tracking_forums[$forum_id] ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id]; |
| 913 | 1851 | psotfx | } |
| 914 | 2448 | psotfx | else if ( !empty($tracking_topics[$topic_id]) || !empty($tracking_forums[$forum_id]) ) |
| 915 | 1851 | psotfx | {
|
| 916 | 2385 | psotfx | $topic_last_read = ( !empty($tracking_topics[$topic_id]) ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id]; |
| 917 | 1851 | psotfx | } |
| 918 | 1851 | psotfx | |
| 919 | 2448 | psotfx | if ( $searchset[$i]['post_time'] > $topic_last_read ) |
| 920 | 1851 | psotfx | {
|
| 921 | 2448 | psotfx | $mini_post_img = $images['icon_minipost_new']; |
| 922 | 2448 | psotfx | $mini_post_alt = $lang['New_post']; |
| 923 | 1851 | psotfx | } |
| 924 | 1851 | psotfx | else
|
| 925 | 1851 | psotfx | {
|
| 926 | 2448 | psotfx | $mini_post_img = $images['icon_minipost']; |
| 927 | 2448 | psotfx | $mini_post_alt = $lang['Post']; |
| 928 | 1851 | psotfx | } |
| 929 | 1851 | psotfx | } |
| 930 | 1851 | psotfx | else
|
| 931 | 1851 | psotfx | {
|
| 932 | 2448 | psotfx | $mini_post_img = $images['icon_minipost']; |
| 933 | 2448 | psotfx | $mini_post_alt = $lang['Post']; |
| 934 | 1851 | psotfx | } |
| 935 | 1851 | psotfx | |
| 936 | 1051 | psotfx | $template->assign_block_vars("searchresults", array( |
| 937 | 2326 | psotfx | 'TOPIC_TITLE' => $topic_title, |
| 938 | 2326 | psotfx | 'FORUM_NAME' => $searchset[$i]['forum_name'], |
| 939 | 2326 | psotfx | 'POST_SUBJECT' => $post_subject, |
| 940 | 2326 | psotfx | 'POST_DATE' => $post_date, |
| 941 | 2326 | psotfx | 'POSTER_NAME' => $poster, |
| 942 | 2326 | psotfx | 'TOPIC_REPLIES' => $searchset[$i]['topic_replies'], |
| 943 | 2326 | psotfx | 'TOPIC_VIEWS' => $searchset[$i]['topic_views'], |
| 944 | 2326 | psotfx | 'MESSAGE' => $message, |
| 945 | 2326 | psotfx | 'MINI_POST_IMG' => $mini_post_img, |
| 946 | 1851 | psotfx | |
| 947 | 2448 | psotfx | 'L_MINI_POST_ALT' => $mini_post_alt, |
| 948 | 2448 | psotfx | |
| 949 | 2326 | psotfx | 'U_POST' => $post_url, |
| 950 | 2326 | psotfx | 'U_TOPIC' => $topic_url, |
| 951 | 2326 | psotfx | 'U_FORUM' => $forum_url) |
| 952 | 373 | psotfx | ); |
| 953 | 1051 | psotfx | } |
| 954 | 1051 | psotfx | else
|
| 955 | 1051 | psotfx | {
|
| 956 | 2385 | psotfx | $message = ''; |
| 957 | 368 | psotfx | |
| 958 | 2448 | psotfx | if ( count($orig_word) ) |
| 959 | 368 | psotfx | {
|
| 960 | 1051 | psotfx | $topic_title = preg_replace($orig_word, $replacement_word, $searchset[$i]['topic_title']); |
| 961 | 368 | psotfx | } |
| 962 | 368 | psotfx | |
| 963 | 1051 | psotfx | $topic_type = $searchset[$i]['topic_type']; |
| 964 | 1051 | psotfx | |
| 965 | 2448 | psotfx | if ($topic_type == POST_ANNOUNCE) |
| 966 | 368 | psotfx | {
|
| 967 | 2326 | psotfx | $topic_type = $lang['Topic_Announcement'] . ' '; |
| 968 | 1051 | psotfx | } |
| 969 | 2448 | psotfx | else if ($topic_type == POST_STICKY) |
| 970 | 1051 | psotfx | {
|
| 971 | 2326 | psotfx | $topic_type = $lang['Topic_Sticky'] . ' '; |
| 972 | 1051 | psotfx | } |
| 973 | 1051 | psotfx | else
|
| 974 | 1051 | psotfx | {
|
| 975 | 2448 | psotfx | $topic_type = ''; |
| 976 | 1051 | psotfx | } |
| 977 | 368 | psotfx | |
| 978 | 2448 | psotfx | if ( $searchset[$i]['topic_vote'] ) |
| 979 | 1051 | psotfx | {
|
| 980 | 2326 | psotfx | $topic_type .= $lang['Topic_Poll'] . ' '; |
| 981 | 1051 | psotfx | } |
| 982 | 368 | psotfx | |
| 983 | 1851 | psotfx | $views = $searchset[$i]['topic_views']; |
| 984 | 1051 | psotfx | $replies = $searchset[$i]['topic_replies']; |
| 985 | 1051 | psotfx | |
| 986 | 2448 | psotfx | if ( ( $replies + 1 ) > $board_config['posts_per_page'] ) |
| 987 | 1051 | psotfx | {
|
| 988 | 2385 | psotfx | $total_pages = ceil( ( $replies + 1 ) / $board_config['posts_per_page'] ); |
| 989 | 2385 | psotfx | $goto_page = ' [ <img src="' . $images['icon_gotopost'] . '" alt="' . $lang['Goto_page'] . '" title="' . $lang['Goto_page'] . '" />' . $lang['Goto_page'] . ': '; |
| 990 | 1051 | psotfx | |
| 991 | 1051 | psotfx | $times = 1; |
| 992 | 1641 | psotfx | for($j = 0; $j < $replies + 1; $j += $board_config['posts_per_page']) |
| 993 | 368 | psotfx | {
|
| 994 | 2385 | psotfx | $goto_page .= '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $topic_id . "&start=$j") . '">' . $times . '</a>'; |
| 995 | 2448 | psotfx | if ( $times == 1 && $total_pages > 4 ) |
| 996 | 368 | psotfx | {
|
| 997 | 2385 | psotfx | $goto_page .= ' ... '; |
| 998 | 2385 | psotfx | $times = $total_pages - 3; |
| 999 | 2385 | psotfx | $j += ( $total_pages - 4 ) * $board_config['posts_per_page']; |
| 1000 | 368 | psotfx | } |
| 1001 | 2385 | psotfx | else if ( $times < $total_pages ) |
| 1002 | 1051 | psotfx | {
|
| 1003 | 2385 | psotfx | $goto_page .= ', '; |
| 1004 | 1051 | psotfx | } |
| 1005 | 1051 | psotfx | $times++;
|
| 1006 | 1051 | psotfx | } |
| 1007 | 2385 | psotfx | $goto_page .= ' ] '; |
| 1008 | 1051 | psotfx | } |
| 1009 | 1051 | psotfx | else
|
| 1010 | 1051 | psotfx | {
|
| 1011 | 2205 | psotfx | $goto_page = ''; |
| 1012 | 1051 | psotfx | } |
| 1013 | 943 | thefinn | |
| 1014 | 2448 | psotfx | if ( $searchset[$i]['topic_status'] == TOPIC_MOVED ) |
| 1015 | 1051 | psotfx | {
|
| 1016 | 2326 | psotfx | $topic_type = $lang['Topic_Moved'] . ' '; |
| 1017 | 1051 | psotfx | $topic_id = $searchset[$i]['topic_moved_id']; |
| 1018 | 1368 | psotfx | |
| 1019 | 2326 | psotfx | $folder_image = '<img src="' . $images['folder'] . '" alt="' . $lang['No_new_posts'] . '" />'; |
| 1020 | 2326 | psotfx | $newest_post_img = ''; |
| 1021 | 1051 | psotfx | } |
| 1022 | 1051 | psotfx | else
|
| 1023 | 1051 | psotfx | {
|
| 1024 | 2448 | psotfx | if ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) |
| 1025 | 1051 | psotfx | {
|
| 1026 | 1293 | psotfx | $folder = $images['folder_locked']; |
| 1027 | 1293 | psotfx | $folder_new = $images['folder_locked_new']; |
| 1028 | 1293 | psotfx | } |
| 1029 | 2448 | psotfx | else if ( $searchset[$i]['topic_type'] == POST_ANNOUNCE ) |
| 1030 | 1293 | psotfx | {
|
| 1031 | 1051 | psotfx | $folder = $images['folder_announce']; |
| 1032 | 1051 | psotfx | $folder_new = $images['folder_announce_new']; |
| 1033 | 1051 | psotfx | } |
| 1034 | 2448 | psotfx | else if ( $searchset[$i]['topic_type'] == POST_STICKY ) |
| 1035 | 1051 | psotfx | {
|
| 1036 | 1051 | psotfx | $folder = $images['folder_sticky']; |
| 1037 | 1051 | psotfx | $folder_new = $images['folder_sticky_new']; |
| 1038 | 1051 | psotfx | } |
| 1039 | 1051 | psotfx | else
|
| 1040 | 1051 | psotfx | {
|
| 1041 | 2448 | psotfx | if ( $replies >= $board_config['hot_threshold'] ) |
| 1042 | 382 | psotfx | {
|
| 1043 | 1051 | psotfx | $folder = $images['folder_hot']; |
| 1044 | 1293 | psotfx | $folder_new = $images['folder_hot_new']; |
| 1045 | 382 | psotfx | } |
| 1046 | 1051 | psotfx | else
|
| 1047 | 1051 | psotfx | {
|
| 1048 | 1051 | psotfx | $folder = $images['folder']; |
| 1049 | 1051 | psotfx | $folder_new = $images['folder_new']; |
| 1050 | 1051 | psotfx | } |
| 1051 | 1051 | psotfx | } |
| 1052 | 368 | psotfx | |
| 1053 | 2448 | psotfx | if ( $userdata['session_logged_in'] ) |
| 1054 | 1051 | psotfx | {
|
| 1055 | 2448 | psotfx | if ( $searchset[$i]['post_time'] > $userdata['user_lastvisit'] ) |
| 1056 | 1851 | psotfx | {
|
| 1057 | 2448 | psotfx | if ( !empty($tracking_topics) || !empty($tracking_forums) || isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) ) |
| 1058 | 1851 | psotfx | {
|
| 1059 | 1368 | psotfx | |
| 1060 | 1851 | psotfx | $unread_topics = true; |
| 1061 | 1511 | psotfx | |
| 1062 | 2448 | psotfx | if ( !empty($tracking_topics[$topic_id]) ) |
| 1063 | 1851 | psotfx | {
|
| 1064 | 2448 | psotfx | if ( $tracking_topics[$topic_id] > $searchset[$i]['post_time'] ) |
| 1065 | 1851 | psotfx | {
|
| 1066 | 1851 | psotfx | $unread_topics = false; |
| 1067 | 1851 | psotfx | } |
| 1068 | 1851 | psotfx | } |
| 1069 | 1851 | psotfx | |
| 1070 | 2448 | psotfx | if ( !empty($tracking_forums[$forum_id]) ) |
| 1071 | 1851 | psotfx | {
|
| 1072 | 2448 | psotfx | if ( $tracking_forums[$forum_id] > $searchset[$i]['post_time'] ) |
| 1073 | 1851 | psotfx | {
|
| 1074 | 1851 | psotfx | $unread_topics = false; |
| 1075 | 1851 | psotfx | } |
| 1076 | 1851 | psotfx | } |
| 1077 | 1851 | psotfx | |
| 1078 | 2448 | psotfx | if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) ) |
| 1079 | 1851 | psotfx | {
|
| 1080 | 2448 | psotfx | if ( $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all'] > $searchset[$i]['post_time'] ) |
| 1081 | 1851 | psotfx | {
|
| 1082 | 1851 | psotfx | $unread_topics = false; |
| 1083 | 1851 | psotfx | } |
| 1084 | 1851 | psotfx | } |
| 1085 | 1851 | psotfx | |
| 1086 | 2448 | psotfx | if ( $unread_topics ) |
| 1087 | 1851 | psotfx | {
|
| 1088 | 2448 | psotfx | $folder_image = $folder_new; |
| 1089 | 2448 | psotfx | $folder_alt = $lang['New_posts']; |
| 1090 | 1851 | psotfx | |
| 1091 | 2385 | psotfx | $newest_post_img = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['View_newest_post'] . '" title="' . $lang['View_newest_post'] . '" border="0" /></a> '; |
| 1092 | 1851 | psotfx | } |
| 1093 | 1851 | psotfx | else
|
| 1094 | 1851 | psotfx | {
|
| 1095 | 1851 | psotfx | $folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts']; |
| 1096 | 1851 | psotfx | |
| 1097 | 2448 | psotfx | $folder_image = $folder; |
| 1098 | 2448 | psotfx | $folder_alt = $folder_alt; |
| 1099 | 2326 | psotfx | $newest_post_img = ''; |
| 1100 | 1851 | psotfx | } |
| 1101 | 1851 | psotfx | |
| 1102 | 1851 | psotfx | } |
| 1103 | 2448 | psotfx | else if ( $searchset[$i]['post_time'] > $userdata['user_lastvisit'] ) |
| 1104 | 1368 | psotfx | {
|
| 1105 | 2448 | psotfx | $folder_image = $folder_new; |
| 1106 | 2448 | psotfx | $folder_alt = $lang['New_posts']; |
| 1107 | 1368 | psotfx | |
| 1108 | 2385 | psotfx | $newest_post_img = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['View_newest_post'] . '" title="' . $lang['View_newest_post'] . '" border="0" /></a> '; |
| 1109 | 1368 | psotfx | } |
| 1110 | 1851 | psotfx | else
|
| 1111 | 1368 | psotfx | {
|
| 1112 | 2448 | psotfx | $folder_image = $folder; |
| 1113 | 1851 | psotfx | $folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts']; |
| 1114 | 2448 | psotfx | $newest_post_img = ''; |
| 1115 | 1368 | psotfx | } |
| 1116 | 1051 | psotfx | } |
| 1117 | 1051 | psotfx | else
|
| 1118 | 1051 | psotfx | {
|
| 1119 | 2448 | psotfx | $folder_image = $folder; |
| 1120 | 1851 | psotfx | $folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts']; |
| 1121 | 2448 | psotfx | $newest_post_img = ''; |
| 1122 | 1051 | psotfx | } |
| 1123 | 368 | psotfx | } |
| 1124 | 1851 | psotfx | else
|
| 1125 | 1511 | psotfx | {
|
| 1126 | 2448 | psotfx | $folder_image = $folder; |
| 1127 | 1851 | psotfx | $folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts']; |
| 1128 | 2448 | psotfx | $newest_post_img = ''; |
| 1129 | 1511 | psotfx | } |
| 1130 | 1051 | psotfx | } |
| 1131 | 368 | psotfx | |
| 1132 | 368 | psotfx | |
| 1133 | 2448 | psotfx | $topic_author = ( $searchset[$i]['user_id'] != ANONYMOUS ) ? '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . '=' . $searchset[$i]['user_id']) . '">' : ''; |
| 1134 | 2448 | psotfx | $topic_author .= ( $searchset[$i]['user_id'] != ANONYMOUS ) ? $searchset[$i]['username'] : ( ( $searchset[$i]['post_username'] != '' ) ? $searchset[$i]['post_username'] : $lang['Guest'] ); |
| 1135 | 2448 | psotfx | |
| 1136 | 2448 | psotfx | $topic_author .= ( $searchset[$i]['user_id'] != ANONYMOUS ) ? '</a>' : ''; |
| 1137 | 2448 | psotfx | |
| 1138 | 2448 | psotfx | $first_post_time = create_date($board_config['default_dateformat'], $searchset[$i]['topic_time'], $board_config['board_timezone']); |
| 1139 | 2448 | psotfx | |
| 1140 | 1051 | psotfx | $last_post_time = create_date($board_config['default_dateformat'], $searchset[$i]['post_time'], $board_config['board_timezone']); |
| 1141 | 368 | psotfx | |
| 1142 | 2448 | psotfx | $last_post_author = ( $searchset[$i]['id2'] == ANONYMOUS ) ? ( ($searchset[$i]['post_username2'] != '' ) ? $searchset[$i]['post_username2'] . ' ' : $lang['Guest'] . ' ' ) : '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . '=' . $searchset[$i]['id2']) . '">' . $searchset[$i]['user2'] . '</a>'; |
| 1143 | 368 | psotfx | |
| 1144 | 2448 | psotfx | $last_post_url = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_POST_URL . '=' . $searchset[$i]['topic_last_post_id']) . '#' . $searchset[$i]['topic_last_post_id'] . '"><img src="' . $images['icon_latest_reply'] . '" alt="' . $lang['View_latest_post'] . '" title="' . $lang['View_latest_post'] . '" border="0" /></a>'; |
| 1145 | 368 | psotfx | |
| 1146 | 2326 | psotfx | $template->assign_block_vars('searchresults', array( |
| 1147 | 2326 | psotfx | 'FORUM_NAME' => $searchset[$i]['forum_name'], |
| 1148 | 2326 | psotfx | 'FORUM_ID' => $forum_id, |
| 1149 | 2326 | psotfx | 'TOPIC_ID' => $topic_id, |
| 1150 | 2326 | psotfx | 'FOLDER' => $folder_image, |
| 1151 | 2326 | psotfx | 'NEWEST_POST_IMG' => $newest_post_img, |
| 1152 | 2448 | psotfx | 'TOPIC_FOLDER_IMG' => $folder_image, |
| 1153 | 2326 | psotfx | 'GOTO_PAGE' => $goto_page, |
| 1154 | 2326 | psotfx | 'REPLIES' => $replies, |
| 1155 | 2326 | psotfx | 'TOPIC_TITLE' => $topic_title, |
| 1156 | 2326 | psotfx | 'TOPIC_TYPE' => $topic_type, |
| 1157 | 2326 | psotfx | 'VIEWS' => $views, |
| 1158 | 2448 | psotfx | 'TOPIC_AUTHOR' => $topic_author, |
| 1159 | 2448 | psotfx | 'FIRST_POST_TIME' => $first_post_time, |
| 1160 | 2448 | psotfx | 'LAST_POST_TIME' => $last_post_time, |
| 1161 | 2448 | psotfx | 'LAST_POST_AUTHOR' => $last_post_author, |
| 1162 | 2448 | psotfx | 'LAST_POST_IMG' => $last_post_url, |
| 1163 | 1051 | psotfx | |
| 1164 | 2448 | psotfx | 'L_TOPIC_FOLDER_ALT' => $folder_alt, |
| 1165 | 2448 | psotfx | |
| 1166 | 2326 | psotfx | 'U_VIEW_FORUM' => $forum_url, |
| 1167 | 2448 | psotfx | 'U_VIEW_TOPIC' => $topic_url) |
| 1168 | 368 | psotfx | ); |
| 1169 | 1051 | psotfx | } |
| 1170 | 1051 | psotfx | } |
| 1171 | 368 | psotfx | |
| 1172 | 1938 | psotfx | $base_url = "search.$phpEx?search_id=$search_id"; |
| 1173 | 368 | psotfx | |
| 1174 | 1051 | psotfx | $template->assign_vars(array( |
| 1175 | 2326 | psotfx | 'PAGINATION' => generate_pagination($base_url, $total_match_count, $per_page, $start), |
| 1176 | 2326 | psotfx | 'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $per_page ) + 1 ), ceil( $total_match_count / $per_page )), |
| 1177 | 1051 | psotfx | |
| 1178 | 2448 | psotfx | 'L_AUTHOR' => $lang['Author'], |
| 1179 | 2448 | psotfx | 'L_MESSAGE' => $lang['Message'], |
| 1180 | 2448 | psotfx | 'L_FORUM' => $lang['Forum'], |
| 1181 | 2448 | psotfx | 'L_TOPICS' => $lang['Topics'], |
| 1182 | 2448 | psotfx | 'L_REPLIES' => $lang['Replies'], |
| 1183 | 2448 | psotfx | 'L_VIEWS' => $lang['Views'], |
| 1184 | 2448 | psotfx | 'L_POSTS' => $lang['Posts'], |
| 1185 | 2448 | psotfx | 'L_LASTPOST' => $lang['Last_Post'], |
| 1186 | 2448 | psotfx | 'L_POSTED' => $lang['Posted'], |
| 1187 | 2448 | psotfx | 'L_SUBJECT' => $lang['Subject'], |
| 1188 | 2448 | psotfx | |
| 1189 | 2326 | psotfx | 'L_GOTO_PAGE' => $lang['Goto_page']) |
| 1190 | 1051 | psotfx | ); |
| 1191 | 1051 | psotfx | |
| 1192 | 2326 | psotfx | $template->pparse('body'); |
| 1193 | 1051 | psotfx | |
| 1194 | 1051 | psotfx | include($phpbb_root_path . 'includes/page_tail.'.$phpEx); |
| 1195 | 368 | psotfx | } |
| 1196 | 2455 | dougk_ff7 | else
|
| 1197 | 2455 | dougk_ff7 | {
|
| 1198 | 2455 | dougk_ff7 | message_die(GENERAL_MESSAGE, $lang['No_search_match']); |
| 1199 | 2455 | dougk_ff7 | } |
| 1200 | 368 | psotfx | } |
| 1201 | 368 | psotfx | |
| 1202 | 368 | psotfx | //
|
| 1203 | 1051 | psotfx | // Search forum
|
| 1204 | 368 | psotfx | //
|
| 1205 | 1051 | psotfx | $sql = "SELECT c.cat_title, c.cat_id, f.forum_name, f.forum_id |
| 1206 | 1051 | psotfx | FROM " . CATEGORIES_TABLE . " c, " . FORUMS_TABLE . " f |
| 1207 | 1051 | psotfx | WHERE f.cat_id = c.cat_id |
| 1208 | 1051 | psotfx | ORDER BY c.cat_id, f.forum_order";
|
| 1209 | 368 | psotfx | $result = $db->sql_query($sql); |
| 1210 | 2448 | psotfx | if ( !$result ) |
| 1211 | 368 | psotfx | {
|
| 1212 | 2326 | psotfx | message_die(GENERAL_ERROR, 'Could not obtain forum_name/forum_id', '', __LINE__, __FILE__, $sql); |
| 1213 | 368 | psotfx | } |
| 1214 | 368 | psotfx | |
| 1215 | 506 | psotfx | $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata); |
| 1216 | 410 | psotfx | |
| 1217 | 2326 | psotfx | $s_forums = ''; |
| 1218 | 1644 | psotfx | while( $row = $db->sql_fetchrow($result) ) |
| 1219 | 368 | psotfx | {
|
| 1220 | 2448 | psotfx | if ( $is_auth_ary[$row['forum_id']]['auth_read'] ) |
| 1221 | 410 | psotfx | {
|
| 1222 | 2326 | psotfx | $s_forums .= '<option value="' . $row['forum_id'] . '">' . $row['forum_name'] . '</option>'; |
| 1223 | 2448 | psotfx | if ( empty($list_cat[$row['cat_id']]) ) |
| 1224 | 1051 | psotfx | {
|
| 1225 | 1051 | psotfx | $list_cat[$row['cat_id']] = $row['cat_title']; |
| 1226 | 1051 | psotfx | } |
| 1227 | 410 | psotfx | } |
| 1228 | 368 | psotfx | } |
| 1229 | 368 | psotfx | |
| 1230 | 2448 | psotfx | if ( $s_forums != '' ) |
| 1231 | 1051 | psotfx | {
|
| 1232 | 2326 | psotfx | $s_forums = '<option value="-1">' . $lang['All_available'] . '</option>' . $s_forums; |
| 1233 | 1479 | psotfx | |
| 1234 | 1479 | psotfx | //
|
| 1235 | 1479 | psotfx | // Category to search
|
| 1236 | 1479 | psotfx | //
|
| 1237 | 2326 | psotfx | $s_categories = '<option value="-1">' . $lang['All_available'] . '</option>'; |
| 1238 | 1479 | psotfx | while( list($cat_id, $cat_title) = @each($list_cat)) |
| 1239 | 1479 | psotfx | {
|
| 1240 | 2326 | psotfx | $s_categories .= '<option value="' . $cat_id . '">' . $cat_title . '</option>'; |
| 1241 | 1479 | psotfx | } |
| 1242 | 1051 | psotfx | } |
| 1243 | 1479 | psotfx | else
|
| 1244 | 1479 | psotfx | {
|
| 1245 | 1479 | psotfx | message_die(GENERAL_MESSAGE, $lang['No_searchable_forums']); |
| 1246 | 1479 | psotfx | } |
| 1247 | 1051 | psotfx | |
| 1248 | 1051 | psotfx | //
|
| 1249 | 1051 | psotfx | // Number of chars returned
|
| 1250 | 1051 | psotfx | //
|
| 1251 | 2205 | psotfx | $s_characters = '<option value="-1">' . $lang['All_available'] . '</option>'; |
| 1252 | 2205 | psotfx | $s_characters .= '<option value="0">0</option>'; |
| 1253 | 2205 | psotfx | $s_characters .= '<option value="25">25</option>'; |
| 1254 | 2205 | psotfx | $s_characters .= '<option value="50">50</option>'; |
| 1255 | 1051 | psotfx | |
| 1256 | 368 | psotfx | for($i = 100; $i < 1100 ; $i += 100) |
| 1257 | 368 | psotfx | {
|
| 1258 | 2205 | psotfx | $selected = ( $i == 200 ) ? ' selected="selected"' : ''; |
| 1259 | 2205 | psotfx | $s_characters .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>'; |
| 1260 | 368 | psotfx | } |
| 1261 | 368 | psotfx | |
| 1262 | 1051 | psotfx | //
|
| 1263 | 1051 | psotfx | // Sorting
|
| 1264 | 1051 | psotfx | //
|
| 1265 | 2205 | psotfx | $s_sort_by = ""; |
| 1266 | 2205 | psotfx | for($i = 0; $i < count($sort_by_types); $i++) |
| 1267 | 368 | psotfx | {
|
| 1268 | 2205 | psotfx | $s_sort_by .= '<option value="' . $i . '">' . $sort_by_types[$i] . '</option>'; |
| 1269 | 368 | psotfx | } |
| 1270 | 368 | psotfx | |
| 1271 | 1051 | psotfx | //
|
| 1272 | 1051 | psotfx | // Search time
|
| 1273 | 1051 | psotfx | //
|
| 1274 | 1051 | psotfx | $previous_days = array(0, 1, 7, 14, 30, 90, 180, 364); |
| 1275 | 1293 | psotfx | $previous_days_text = array($lang['All_Posts'], $lang['1_Day'], $lang['7_Days'], $lang['2_Weeks'], $lang['1_Month'], $lang['3_Months'], $lang['6_Months'], $lang['1_Year']); |
| 1276 | 1051 | psotfx | |
| 1277 | 2326 | psotfx | $s_time = ''; |
| 1278 | 1051 | psotfx | for($i = 0; $i < count($previous_days); $i++) |
| 1279 | 1051 | psotfx | {
|
| 1280 | 2326 | psotfx | $selected = ( $topic_days == $previous_days[$i] ) ? ' selected="selected"' : ''; |
| 1281 | 2326 | psotfx | $s_time .= '<option value="' . $previous_days[$i] . '"' . $selected . '>' . $previous_days_text[$i] . '</option>'; |
| 1282 | 1051 | psotfx | } |
| 1283 | 1051 | psotfx | |
| 1284 | 1089 | psotfx | //
|
| 1285 | 1089 | psotfx | // Output the basic page
|
| 1286 | 1089 | psotfx | //
|
| 1287 | 1051 | psotfx | $page_title = $lang['Search']; |
| 1288 | 646 | psotfx | include($phpbb_root_path . 'includes/page_header.'.$phpEx); |
| 1289 | 368 | psotfx | |
| 1290 | 368 | psotfx | $template->set_filenames(array( |
| 1291 | 2448 | psotfx | 'body' => 'search_body.tpl') |
| 1292 | 368 | psotfx | ); |
| 1293 | 2448 | psotfx | make_jumpbox('viewforum.'.$phpEx); |
| 1294 | 1051 | psotfx | |
| 1295 | 368 | psotfx | $template->assign_vars(array( |
| 1296 | 2326 | psotfx | 'L_SEARCH_QUERY' => $lang['Search_query'], |
| 1297 | 2326 | psotfx | 'L_SEARCH_OPTIONS' => $lang['Search_options'], |
| 1298 | 2326 | psotfx | 'L_SEARCH_KEYWORDS' => $lang['Search_keywords'], |
| 1299 | 2326 | psotfx | 'L_SEARCH_KEYWORDS_EXPLAIN' => $lang['Search_keywords_explain'], |
| 1300 | 2326 | psotfx | 'L_SEARCH_AUTHOR' => $lang['Search_author'], |
| 1301 | 2326 | psotfx | 'L_SEARCH_AUTHOR_EXPLAIN' => $lang['Search_author_explain'], |
| 1302 | 2326 | psotfx | 'L_SEARCH_ANY_TERMS' => $lang['Search_for_any'], |
| 1303 | 2326 | psotfx | 'L_SEARCH_ALL_TERMS' => $lang['Search_for_all'], |
| 1304 | 2326 | psotfx | 'L_SEARCH_MESSAGE_ONLY' => $lang['Search_msg_only'], |
| 1305 | 2326 | psotfx | 'L_SEARCH_MESSAGE_TITLE' => $lang['Search_title_msg'], |
| 1306 | 2326 | psotfx | 'L_CATEGORY' => $lang['Category'], |
| 1307 | 2326 | psotfx | 'L_RETURN_FIRST' => $lang['Return_first'], |
| 1308 | 2326 | psotfx | 'L_CHARACTERS' => $lang['characters_posts'], |
| 1309 | 2326 | psotfx | 'L_SORT_BY' => $lang['Sort_by'], |
| 1310 | 2326 | psotfx | 'L_SORT_ASCENDING' => $lang['Sort_Ascending'], |
| 1311 | 2326 | psotfx | 'L_SORT_DESCENDING' => $lang['Sort_Descending'], |
| 1312 | 2326 | psotfx | 'L_SEARCH_PREVIOUS' => $lang['Search_previous'], |
| 1313 | 2326 | psotfx | 'L_DISPLAY_RESULTS' => $lang['Display_results'], |
| 1314 | 2448 | psotfx | 'L_FORUM' => $lang['Forum'], |
| 1315 | 2448 | psotfx | 'L_TOPICS' => $lang['Topics'], |
| 1316 | 2448 | psotfx | 'L_POSTS' => $lang['Posts'], |
| 1317 | 368 | psotfx | |
| 1318 | 2326 | psotfx | 'S_SEARCH_ACTION' => append_sid("search.$phpEx?mode=results"), |
| 1319 | 2326 | psotfx | 'S_CHARACTER_OPTIONS' => $s_characters, |
| 1320 | 2326 | psotfx | 'S_FORUM_OPTIONS' => $s_forums, |
| 1321 | 2326 | psotfx | 'S_CATEGORY_OPTIONS' => $s_categories, |
| 1322 | 2326 | psotfx | 'S_TIME_OPTIONS' => $s_time, |
| 1323 | 2326 | psotfx | 'S_SORT_OPTIONS' => $s_sort_by, |
| 1324 | 2326 | psotfx | 'S_HIDDEN_FIELDS' => $s_hidden_fields) |
| 1325 | 368 | psotfx | ); |
| 1326 | 368 | psotfx | |
| 1327 | 2326 | psotfx | $template->pparse('body'); |
| 1328 | 368 | psotfx | |
| 1329 | 646 | psotfx | include($phpbb_root_path . 'includes/page_tail.'.$phpEx); |
| 1330 | 368 | psotfx | |
| 1331 | 2498 | psotfx | ?> |

