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

