Verzeichnisstruktur phpBB-2.0.0
- Veröffentlicht
- 03.04.2002
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
search.php
0001 <?php
0002 /***************************************************************************
0003 * search.php
0004 * -------------------
0005 * begin : Saturday, Feb 13, 2001
0006 * copyright : (C) 2001 The phpBB Group
0007 * email : support@phpbb.com
0008 *
0009 * $Id$
0010 *
0011 *
0012 ***************************************************************************/
0013
0014 /***************************************************************************
0015 *
0016 * This program is free software; you can redistribute it and/or modify
0017 * it under the terms of the GNU General Public License as published by
0018 * the Free Software Foundation; either version 2 of the License, or
0019 * (at your option) any later version.
0020 *
0021 ***************************************************************************/
0022
0023 define('IN_PHPBB', true);
0024 $phpbb_root_path = './';
0025 include($phpbb_root_path . 'extension.inc');
0026 include($phpbb_root_path . 'common.'.$phpEx);
0027 include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
0028 include($phpbb_root_path . 'includes/functions_search.'.$phpEx);
0029
0030 //
0031 // Start session management
0032 //
0033 $userdata = session_pagestart($user_ip, PAGE_SEARCH);
0034 init_userprefs($userdata);
0035 //
0036 // End session management
0037 //
0038
0039 //
0040 // Define initial vars
0041 //
0042 if ( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
0043 {
0044 $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
0045 }
0046 else
0047 {
0048 $mode = '';
0049 }
0050
0051 if ( isset($HTTP_POST_VARS['search_keywords']) || isset($HTTP_GET_VARS['search_keywords']) )
0052 {
0053 $search_keywords = ( isset($HTTP_POST_VARS['search_keywords']) ) ? $HTTP_POST_VARS['search_keywords'] : $HTTP_GET_VARS['search_keywords'];
0054 }
0055 else
0056 {
0057 $search_keywords = '';
0058 }
0059
0060 if ( isset($HTTP_POST_VARS['search_author']) || isset($HTTP_GET_VARS['search_author']))
0061 {
0062 $search_author = ( isset($HTTP_POST_VARS['search_author']) ) ? $HTTP_POST_VARS['search_author'] : $HTTP_GET_VARS['search_author'];
0063 $search_author = phpbb_clean_username($search_author);
0064 }
0065 else
0066 {
0067 $search_author = '';
0068 }
0069
0070 $search_id = ( isset($HTTP_GET_VARS['search_id']) ) ? $HTTP_GET_VARS['search_id'] : '';
0071
0072 $show_results = ( isset($HTTP_POST_VARS['show_results']) ) ? $HTTP_POST_VARS['show_results'] : 'posts';
0073 $show_results = ($show_results == 'topics') ? 'topics' : 'posts';
0074
0075 if ( isset($HTTP_POST_VARS['search_terms']) )
0076 {
0077 $search_terms = ( $HTTP_POST_VARS['search_terms'] == 'all' ) ? 1 : 0;
0078 }
0079 else
0080 {
0081 $search_terms = 0;
0082 }
0083
0084 if ( isset($HTTP_POST_VARS['search_fields']) )
0085 {
0086 $search_fields = ( $HTTP_POST_VARS['search_fields'] == 'all' ) ? 1 : 0;
0087 }
0088 else
0089 {
0090 $search_fields = 0;
0091 }
0092
0093 $return_chars = ( isset($HTTP_POST_VARS['return_chars']) ) ? intval($HTTP_POST_VARS['return_chars']) : 200;
0094
0095 $search_cat = ( isset($HTTP_POST_VARS['search_cat']) ) ? intval($HTTP_POST_VARS['search_cat']) : -1;
0096 $search_forum = ( isset($HTTP_POST_VARS['search_forum']) ) ? intval($HTTP_POST_VARS['search_forum']) : -1;
0097
0098 $sort_by = ( isset($HTTP_POST_VARS['sort_by']) ) ? intval($HTTP_POST_VARS['sort_by']) : 0;
0099
0100 if ( isset($HTTP_POST_VARS['sort_dir']) )
0101 {
0102 $sort_dir = ( $HTTP_POST_VARS['sort_dir'] == 'DESC' ) ? 'DESC' : 'ASC';
0103 }
0104 else
0105 {
0106 $sort_dir = 'DESC';
0107 }
0108
0109 if ( !empty($HTTP_POST_VARS['search_time']) || !empty($HTTP_GET_VARS['search_time']))
0110 {
0111 $search_time = time() - ( ( ( !empty($HTTP_POST_VARS['search_time']) ) ? intval($HTTP_POST_VARS['search_time']) : intval($HTTP_GET_VARS['search_time']) ) * 86400 );
0112 $topic_days = (!empty($HTTP_POST_VARS['search_time'])) ? intval($HTTP_POST_VARS['search_time']) : intval($HTTP_GET_VARS['search_time']);
0113 }
0114 else
0115 {
0116 $search_time = 0;
0117 $topic_days = 0;
0118 }
0119
0120 $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
0121 $start = ($start < 0) ? 0 : $start;
0122
0123 $sort_by_types = array($lang['Sort_Time'], $lang['Sort_Post_Subject'], $lang['Sort_Topic_Title'], $lang['Sort_Author'], $lang['Sort_Forum']);
0124
0125 //
0126 // encoding match for workaround
0127 //
0128 $multibyte_charset = 'utf-8, big5, shift_jis, euc-kr, gb2312';
0129
0130 //
0131 // Begin core code
0132 //
0133 if ( $mode == 'searchuser' )
0134 {
0135 //
0136 // This handles the simple windowed user search functions called from various other scripts
0137 //
0138 if ( isset($HTTP_POST_VARS['search_username']) )
0139 {
0140 username_search($HTTP_POST_VARS['search_username']);
0141 }
0142 else
0143 {
0144 username_search('');
0145 }
0146
0147 exit;
0148 }
0149 else if ( $search_keywords != '' || $search_author != '' || $search_id )
0150 {
0151 $store_vars = array('search_results', 'total_match_count', 'split_search', 'sort_by', 'sort_dir', 'show_results', 'return_chars');
0152 $search_results = '';
0153
0154 //
0155 // Search ID Limiter, decrease this value if you experience further timeout problems with searching forums
0156 $limiter = 5000;
0157 $current_time = time();
0158
0159 //
0160 // Cycle through options ...
0161 //
0162 if ( $search_id == 'newposts' || $search_id == 'egosearch' || $search_id == 'unanswered' || $search_keywords != '' || $search_author != '' )
0163 {
0164 //
0165 // Flood control
0166 //
0167 $where_sql = ($userdata['user_id'] == ANONYMOUS) ? "se.session_ip = '$user_ip'" : 'se.session_user_id = ' . $userdata['user_id'];
0168 $sql = 'SELECT MAX(sr.search_time) AS last_search_time
0169 FROM ' . SEARCH_TABLE . ' sr, ' . SESSIONS_TABLE . " se
0170 WHERE sr.session_id = se.session_id
0171 AND $where_sql";
0172 if ($result = $db->sql_query($sql))
0173 {
0174 if ($row = $db->sql_fetchrow($result))
0175 {
0176 if (intval($row['last_search_time']) > 0 && ($current_time - intval($row['last_search_time'])) < intval($board_config['search_flood_interval']))
0177 {
0178 message_die(GENERAL_MESSAGE, $lang['Search_Flood_Error']);
0179 }
0180 }
0181 }
0182 if ( $search_id == 'newposts' || $search_id == 'egosearch' || ( $search_author != '' && $search_keywords == '' ) )
0183 {
0184 if ( $search_id == 'newposts' )
0185 {
0186 if ( $userdata['session_logged_in'] )
0187 {
0188 $sql = "SELECT post_id
0189 FROM " . POSTS_TABLE . "
0190 WHERE post_time >= " . $userdata['user_lastvisit'];
0191 }
0192 else
0193 {
0194 redirect(append_sid("login.$phpEx?redirect=search.$phpEx&search_id=newposts", true));
0195 }
0196
0197 $show_results = 'topics';
0198 $sort_by = 0;
0199 $sort_dir = 'DESC';
0200 }
0201 else if ( $search_id == 'egosearch' )
0202 {
0203 if ( $userdata['session_logged_in'] )
0204 {
0205 $sql = "SELECT post_id
0206 FROM " . POSTS_TABLE . "
0207 WHERE poster_id = " . $userdata['user_id'];
0208 }
0209 else
0210 {
0211 redirect(append_sid("login.$phpEx?redirect=search.$phpEx&search_id=egosearch", true));
0212 }
0213
0214 $show_results = 'topics';
0215 $sort_by = 0;
0216 $sort_dir = 'DESC';
0217 }
0218 else
0219 {
0220 $search_author = str_replace('*', '%', trim($search_author));
0221
0222 if( ( strpos($search_author, '%') !== false ) && ( strlen(str_replace('%', '', $search_author)) < $board_config['search_min_chars'] ) )
0223 {
0224 $search_author = '';
0225 }
0226
0227 $sql = "SELECT user_id
0228 FROM " . USERS_TABLE . "
0229 WHERE username LIKE '" . str_replace("\'", "''", $search_author) . "'";
0230 if ( !($result = $db->sql_query($sql)) )
0231 {
0232 message_die(GENERAL_ERROR, "Couldn't obtain list of matching users (searching for: $search_author)", "", __LINE__, __FILE__, $sql);
0233 }
0234
0235 $matching_userids = '';
0236 if ( $row = $db->sql_fetchrow($result) )
0237 {
0238 do
0239 {
0240 $matching_userids .= ( ( $matching_userids != '' ) ? ', ' : '' ) . $row['user_id'];
0241 }
0242 while( $row = $db->sql_fetchrow($result) );
0243 }
0244 else
0245 {
0246 message_die(GENERAL_MESSAGE, $lang['No_search_match']);
0247 }
0248
0249 $sql = "SELECT post_id
0250 FROM " . POSTS_TABLE . "
0251 WHERE poster_id IN ($matching_userids)";
0252
0253 if ($search_time)
0254 {
0255 $sql .= " AND post_time >= " . $search_time;
0256 }
0257 }
0258
0259 if ( !($result = $db->sql_query($sql)) )
0260 {
0261 message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql);
0262 }
0263
0264 $search_ids = array();
0265 while( $row = $db->sql_fetchrow($result) )
0266 {
0267 $search_ids[] = $row['post_id'];
0268 }
0269 $db->sql_freeresult($result);
0270
0271 $total_match_count = count($search_ids);
0272
0273 }
0274 else if ( $search_keywords != '' )
0275 {
0276 $stopword_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_stopwords.txt');
0277 $synonym_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_synonyms.txt');
0278
0279 $split_search = array();
0280 $stripped_keywords = stripslashes($search_keywords);
0281 $split_search = ( !strstr($multibyte_charset, $lang['ENCODING']) ) ? split_words(clean_words('search', $stripped_keywords, $stopword_array, $synonym_array), 'search') : split(' ', $search_keywords);
0282 unset($stripped_keywords);
0283
0284 $search_msg_only = ( !$search_fields ) ? "AND m.title_match = 0" : ( ( strstr($multibyte_charset, $lang['ENCODING']) ) ? '' : '' );
0285
0286 $word_count = 0;
0287 $current_match_type = 'or';
0288
0289 $word_match = array();
0290 $result_list = array();
0291
0292 for($i = 0; $i < count($split_search); $i++)
0293 {
0294 if ( strlen(str_replace(array('*', '%'), '', trim($split_search[$i]))) < $board_config['search_min_chars'] )
0295 {
0296 $split_search[$i] = '';
0297 continue;
0298 }
0299
0300 switch ( $split_search[$i] )
0301 {
0302 case 'and':
0303 $current_match_type = 'and';
0304 break;
0305
0306 case 'or':
0307 $current_match_type = 'or';
0308 break;
0309
0310 case 'not':
0311 $current_match_type = 'not';
0312 break;
0313
0314 default:
0315 if ( !empty($search_terms) )
0316 {
0317 $current_match_type = 'and';
0318 }
0319
0320 if ( !strstr($multibyte_charset, $lang['ENCODING']) )
0321 {
0322 $match_word = str_replace('*', '%', $split_search[$i]);
0323 $sql = "SELECT m.post_id
0324 FROM " . SEARCH_WORD_TABLE . " w, " . SEARCH_MATCH_TABLE . " m
0325 WHERE w.word_text LIKE '$match_word'
0326 AND m.word_id = w.word_id
0327 AND w.word_common <> 1
0328 $search_msg_only";
0329 }
0330 else
0331 {
0332 $match_word = addslashes('%' . str_replace('*', '', $split_search[$i]) . '%');
0333 $search_msg_only = ( $search_fields ) ? "OR post_subject LIKE '$match_word'" : '';
0334 $sql = "SELECT post_id
0335 FROM " . POSTS_TEXT_TABLE . "
0336 WHERE post_text LIKE '$match_word'
0337 $search_msg_only";
0338 }
0339 if ( !($result = $db->sql_query($sql)) )
0340 {
0341 message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql);
0342 }
0343
0344 $row = array();
0345 while( $temp_row = $db->sql_fetchrow($result) )
0346 {
0347 $row[$temp_row['post_id']] = 1;
0348
0349 if ( !$word_count )
0350 {
0351 $result_list[$temp_row['post_id']] = 1;
0352 }
0353 else if ( $current_match_type == 'or' )
0354 {
0355 $result_list[$temp_row['post_id']] = 1;
0356 }
0357 else if ( $current_match_type == 'not' )
0358 {
0359 $result_list[$temp_row['post_id']] = 0;
0360 }
0361 }
0362
0363 if ( $current_match_type == 'and' && $word_count )
0364 {
0365 @reset($result_list);
0366 while( list($post_id, $match_count) = @each($result_list) )
0367 {
0368 if ( !$row[$post_id] )
0369 {
0370 $result_list[$post_id] = 0;
0371 }
0372 }
0373 }
0374
0375 $word_count++;
0376
0377 $db->sql_freeresult($result);
0378 }
0379 }
0380
0381 @reset($result_list);
0382
0383 $search_ids = array();
0384 while( list($post_id, $matches) = each($result_list) )
0385 {
0386 if ( $matches )
0387 {
0388 $search_ids[] = $post_id;
0389 }
0390 }
0391
0392 unset($result_list);
0393 $total_match_count = count($search_ids);
0394 }
0395
0396 //
0397 // If user is logged in then we'll check to see which (if any) private
0398 // forums they are allowed to view and include them in the search.
0399 //
0400 // If not logged in we explicitly prevent searching of private forums
0401 //
0402 $auth_sql = '';
0403 if ( $search_forum != -1 )
0404 {
0405 $is_auth = auth(AUTH_READ, $search_forum, $userdata);
0406
0407 if ( !$is_auth['auth_read'] )
0408 {
0409 message_die(GENERAL_MESSAGE, $lang['No_searchable_forums']);
0410 }
0411
0412 $auth_sql = "f.forum_id = $search_forum";
0413 }
0414 else
0415 {
0416 $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata);
0417
0418 if ( $search_cat != -1 )
0419 {
0420 $auth_sql = "f.cat_id = $search_cat";
0421 }
0422
0423 $ignore_forum_sql = '';
0424 while( list($key, $value) = each($is_auth_ary) )
0425 {
0426 if ( !$value['auth_read'] )
0427 {
0428 $ignore_forum_sql .= ( ( $ignore_forum_sql != '' ) ? ', ' : '' ) . $key;
0429 }
0430 }
0431
0432 if ( $ignore_forum_sql != '' )
0433 {
0434 $auth_sql .= ( $auth_sql != '' ) ? " AND f.forum_id NOT IN ($ignore_forum_sql) " : "f.forum_id NOT IN ($ignore_forum_sql) ";
0435 }
0436 }
0437
0438 //
0439 // Author name search
0440 //
0441 if ( $search_author != '' )
0442 {
0443 $search_author = str_replace('*', '%', trim($search_author));
0444
0445 if( ( strpos($search_author, '%') !== false ) && ( strlen(str_replace('%', '', $search_author)) < $board_config['search_min_chars'] ) )
0446 {
0447 $search_author = '';
0448 }
0449 }
0450
0451 if ( $total_match_count )
0452 {
0453 if ( $show_results == 'topics' )
0454 {
0455 //
0456 // This one is a beast, try to seperate it a bit (workaround for connection timeouts)
0457 //
0458 $search_id_chunks = array();
0459 $count = 0;
0460 $chunk = 0;
0461
0462 if (count($search_ids) > $limiter)
0463 {
0464 for ($i = 0; $i < count($search_ids); $i++)
0465 {
0466 if ($count == $limiter)
0467 {
0468 $chunk++;
0469 $count = 0;
0470 }
0471
0472 $search_id_chunks[$chunk][$count] = $search_ids[$i];
0473 $count++;
0474 }
0475 }
0476 else
0477 {
0478 $search_id_chunks[0] = $search_ids;
0479 }
0480
0481 $search_ids = array();
0482
0483 for ($i = 0; $i < count($search_id_chunks); $i++)
0484 {
0485 $where_sql = '';
0486
0487 if ( $search_time )
0488 {
0489 $where_sql .= ( $search_author == '' && $auth_sql == '' ) ? " AND post_time >= $search_time " : " AND p.post_time >= $search_time ";
0490 }
0491
0492 if ( $search_author == '' && $auth_sql == '' )
0493 {
0494 $sql = "SELECT topic_id
0495 FROM " . POSTS_TABLE . "
0496 WHERE post_id IN (" . implode(", ", $search_id_chunks[$i]) . ")
0497 $where_sql
0498 GROUP BY topic_id";
0499 }
0500 else
0501 {
0502 $from_sql = POSTS_TABLE . " p";
0503
0504 if ( $search_author != '' )
0505 {
0506 $from_sql .= ", " . USERS_TABLE . " u";
0507 $where_sql .= " AND u.user_id = p.poster_id AND u.username LIKE '$search_author' ";
0508 }
0509
0510 if ( $auth_sql != '' )
0511 {
0512 $from_sql .= ", " . FORUMS_TABLE . " f";
0513 $where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql";
0514 }
0515
0516 $sql = "SELECT p.topic_id
0517 FROM $from_sql
0518 WHERE p.post_id IN (" . implode(", ", $search_id_chunks[$i]) . ")
0519 $where_sql
0520 GROUP BY p.topic_id";
0521 }
0522
0523 if ( !($result = $db->sql_query($sql)) )
0524 {
0525 message_die(GENERAL_ERROR, 'Could not obtain topic ids', '', __LINE__, __FILE__, $sql);
0526 }
0527
0528 while ($row = $db->sql_fetchrow($result))
0529 {
0530 $search_ids[] = $row['topic_id'];
0531 }
0532 $db->sql_freeresult($result);
0533 }
0534
0535 $total_match_count = sizeof($search_ids);
0536
0537 }
0538 else if ( $search_author != '' || $search_time || $auth_sql != '' )
0539 {
0540 $search_id_chunks = array();
0541 $count = 0;
0542 $chunk = 0;
0543
0544 if (count($search_ids) > $limiter)
0545 {
0546 for ($i = 0; $i < count($search_ids); $i++)
0547 {
0548 if ($count == $limiter)
0549 {
0550 $chunk++;
0551 $count = 0;
0552 }
0553
0554 $search_id_chunks[$chunk][$count] = $search_ids[$i];
0555 $count++;
0556 }
0557 }
0558 else
0559 {
0560 $search_id_chunks[0] = $search_ids;
0561 }
0562
0563 $search_ids = array();
0564
0565 for ($i = 0; $i < count($search_id_chunks); $i++)
0566 {
0567 $where_sql = ( $search_author == '' && $auth_sql == '' ) ? 'post_id IN (' . implode(', ', $search_id_chunks[$i]) . ')' : 'p.post_id IN (' . implode(', ', $search_id_chunks[$i]) . ')';
0568 $select_sql = ( $search_author == '' && $auth_sql == '' ) ? 'post_id' : 'p.post_id';
0569 $from_sql = ( $search_author == '' && $auth_sql == '' ) ? POSTS_TABLE : POSTS_TABLE . ' p';
0570
0571 if ( $search_time )
0572 {
0573 $where_sql .= ( $search_author == '' && $auth_sql == '' ) ? " AND post_time >= $search_time " : " AND p.post_time >= $search_time";
0574 }
0575
0576 if ( $auth_sql != '' )
0577 {
0578 $from_sql .= ", " . FORUMS_TABLE . " f";
0579 $where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql";
0580 }
0581
0582 if ( $search_author != '' )
0583 {
0584 $from_sql .= ", " . USERS_TABLE . " u";
0585 $where_sql .= " AND u.user_id = p.poster_id AND u.username LIKE '$search_author'";
0586 }
0587
0588 $sql = "SELECT " . $select_sql . "
0589 FROM $from_sql
0590 WHERE $where_sql";
0591 if ( !($result = $db->sql_query($sql)) )
0592 {
0593 message_die(GENERAL_ERROR, 'Could not obtain post ids', '', __LINE__, __FILE__, $sql);
0594 }
0595
0596 while( $row = $db->sql_fetchrow($result) )
0597 {
0598 $search_ids[] = $row['post_id'];
0599 }
0600 $db->sql_freeresult($result);
0601 }
0602
0603 $total_match_count = count($search_ids);
0604 }
0605 }
0606 else if ( $search_id == 'unanswered' )
0607 {
0608 if ( $auth_sql != '' )
0609 {
0610 $sql = "SELECT t.topic_id, f.forum_id
0611 FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
0612 WHERE t.topic_replies = 0
0613 AND t.forum_id = f.forum_id
0614 AND t.topic_moved_id = 0
0615 AND $auth_sql";
0616 }
0617 else
0618 {
0619 $sql = "SELECT topic_id
0620 FROM " . TOPICS_TABLE . "
0621 WHERE topic_replies = 0
0622 AND topic_moved_id = 0";
0623 }
0624
0625 if ( !($result = $db->sql_query($sql)) )
0626 {
0627 message_die(GENERAL_ERROR, 'Could not obtain post ids', '', __LINE__, __FILE__, $sql);
0628 }
0629
0630 $search_ids = array();
0631 while( $row = $db->sql_fetchrow($result) )
0632 {
0633 $search_ids[] = $row['topic_id'];
0634 }
0635 $db->sql_freeresult($result);
0636
0637 $total_match_count = count($search_ids);
0638
0639 //
0640 // Basic requirements
0641 //
0642 $show_results = 'topics';
0643 $sort_by = 0;
0644 $sort_dir = 'DESC';
0645 }
0646 else
0647 {
0648 message_die(GENERAL_MESSAGE, $lang['No_search_match']);
0649 }
0650
0651 //
0652 // Delete old data from the search result table
0653 //
0654 $sql = 'DELETE FROM ' . SEARCH_TABLE . '
0655 WHERE search_time < ' . ($current_time - (int) $board_config['session_length']);
0656 if ( !$result = $db->sql_query($sql) )
0657 {
0658 message_die(GENERAL_ERROR, 'Could not delete old search id sessions', '', __LINE__, __FILE__, $sql);
0659 }
0660
0661 //
0662 // Store new result data
0663 //
0664 $search_results = implode(', ', $search_ids);
0665 $per_page = ( $show_results == 'posts' ) ? $board_config['posts_per_page'] : $board_config['topics_per_page'];
0666
0667 //
0668 // Combine both results and search data (apart from original query)
0669 // so we can serialize it and place it in the DB
0670 //
0671 $store_search_data = array();
0672
0673 //
0674 // Limit the character length (and with this the results displayed at all following pages) to prevent
0675 // truncated result arrays. Normally, search results above 12000 are affected.
0676 // - to include or not to include
0677 /*
0678 $max_result_length = 60000;
0679 if (strlen($search_results) > $max_result_length)
0680 {
0681 $search_results = substr($search_results, 0, $max_result_length);
0682 $search_results = substr($search_results, 0, strrpos($search_results, ','));
0683 $total_match_count = count(explode(', ', $search_results));
0684 }
0685 */
0686
0687 for($i = 0; $i < count($store_vars); $i++)
0688 {
0689 $store_search_data[$store_vars[$i]] = $$store_vars[$i];
0690 }
0691
0692 $result_array = serialize($store_search_data);
0693 unset($store_search_data);
0694
0695 $search_id = abs(crc32(dss_rand()));
0696
0697 $sql = "UPDATE " . SEARCH_TABLE . "
0698 SET search_id = $search_id, search_time = $current_time, search_array = '" . str_replace("\'", "''", $result_array) . "'
0699 WHERE session_id = '" . $userdata['session_id'] . "'";
0700 if ( !($result = $db->sql_query($sql)) || !$db->sql_affectedrows() )
0701 {
0702 $sql = "INSERT INTO " . SEARCH_TABLE . " (search_id, session_id, search_time, search_array)
0703 VALUES($search_id, '" . $userdata['session_id'] . "', $current_time, '" . str_replace("\'", "''", $result_array) . "')";
0704 if ( !($result = $db->sql_query($sql)) )
0705 {
0706 message_die(GENERAL_ERROR, 'Could not insert search results', '', __LINE__, __FILE__, $sql);
0707 }
0708 }
0709 }
0710 else
0711 {
0712 $search_id = intval($search_id);
0713 if ( $search_id )
0714 {
0715 $sql = "SELECT search_array
0716 FROM " . SEARCH_TABLE . "
0717 WHERE search_id = $search_id
0718 AND session_id = '". $userdata['session_id'] . "'";
0719 if ( !($result = $db->sql_query($sql)) )
0720 {
0721 message_die(GENERAL_ERROR, 'Could not obtain search results', '', __LINE__, __FILE__, $sql);
0722 }
0723
0724 if ( $row = $db->sql_fetchrow($result) )
0725 {
0726 $search_data = unserialize($row['search_array']);
0727 for($i = 0; $i < count($store_vars); $i++)
0728 {
0729 $$store_vars[$i] = $search_data[$store_vars[$i]];
0730 }
0731 }
0732 }
0733 }
0734
0735 //
0736 // Look up data ...
0737 //
0738 if ( $search_results != '' )
0739 {
0740 if ( $show_results == 'posts' )
0741 {
0742 $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
0743 FROM " . FORUMS_TABLE . " f, " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TEXT_TABLE . " pt
0744 WHERE p.post_id IN ($search_results)
0745 AND pt.post_id = p.post_id
0746 AND f.forum_id = p.forum_id
0747 AND p.topic_id = t.topic_id
0748 AND p.poster_id = u.user_id";
0749 }
0750 else
0751 {
0752 $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
0753 FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2
0754 WHERE t.topic_id IN ($search_results)
0755 AND t.topic_poster = u.user_id
0756 AND f.forum_id = t.forum_id
0757 AND p.post_id = t.topic_first_post_id
0758 AND p2.post_id = t.topic_last_post_id
0759 AND u2.user_id = p2.poster_id";
0760 }
0761
0762 $per_page = ( $show_results == 'posts' ) ? $board_config['posts_per_page'] : $board_config['topics_per_page'];
0763
0764 $sql .= " ORDER BY ";
0765 switch ( $sort_by )
0766 {
0767 case 1:
0768 $sql .= ( $show_results == 'posts' ) ? 'pt.post_subject' : 't.topic_title';
0769 break;
0770 case 2:
0771 $sql .= 't.topic_title';
0772 break;
0773 case 3:
0774 $sql .= 'u.username';
0775 break;
0776 case 4:
0777 $sql .= 'f.forum_id';
0778 break;
0779 default:
0780 $sql .= ( $show_results == 'posts' ) ? 'p.post_time' : 'p2.post_time';
0781 break;
0782 }
0783 $sql .= " $sort_dir LIMIT $start, " . $per_page;
0784
0785 if ( !$result = $db->sql_query($sql) )
0786 {
0787 message_die(GENERAL_ERROR, 'Could not obtain search results', '', __LINE__, __FILE__, $sql);
0788 }
0789
0790 $searchset = array();
0791 while( $row = $db->sql_fetchrow($result) )
0792 {
0793 $searchset[] = $row;
0794 }
0795
0796 $db->sql_freeresult($result);
0797
0798 //
0799 // Define censored word matches
0800 //
0801 $orig_word = array();
0802 $replacement_word = array();
0803 obtain_word_list($orig_word, $replacement_word);
0804
0805 //
0806 // Output header
0807 //
0808 $page_title = $lang['Search'];
0809 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
0810
0811 if ( $show_results == 'posts' )
0812 {
0813 $template->set_filenames(array(
0814 'body' => 'search_results_posts.tpl')
0815 );
0816 }
0817 else
0818 {
0819 $template->set_filenames(array(
0820 'body' => 'search_results_topics.tpl')
0821 );
0822 }
0823 make_jumpbox('viewforum.'.$phpEx);
0824
0825 $l_search_matches = ( $total_match_count == 1 ) ? sprintf($lang['Found_search_match'], $total_match_count) : sprintf($lang['Found_search_matches'], $total_match_count);
0826
0827 $template->assign_vars(array(
0828 'L_SEARCH_MATCHES' => $l_search_matches,
0829 'L_TOPIC' => $lang['Topic'])
0830 );
0831
0832 $highlight_active = '';
0833 $highlight_match = array();
0834 for($j = 0; $j < count($split_search); $j++ )
0835 {
0836 $split_word = $split_search[$j];
0837
0838 if ( $split_word != 'and' && $split_word != 'or' && $split_word != 'not' )
0839 {
0840 $highlight_match[] = '#\b(' . str_replace("*", "([\w]+)?", $split_word) . ')\b#is';
0841 $highlight_active .= " " . $split_word;
0842
0843 for ($k = 0; $k < count($synonym_array); $k++)
0844 {
0845 list($replace_synonym, $match_synonym) = split(' ', trim(strtolower($synonym_array[$k])));
0846
0847 if ( $replace_synonym == $split_word )
0848 {
0849 $highlight_match[] = '#\b(' . str_replace("*", "([\w]+)?", $replace_synonym) . ')\b#is';
0850 $highlight_active .= ' ' . $match_synonym;
0851 }
0852 }
0853 }
0854 }
0855
0856 $highlight_active = urlencode(trim($highlight_active));
0857
0858 $tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();
0859 $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();
0860
0861 for($i = 0; $i < count($searchset); $i++)
0862 {
0863 $forum_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . '=' . $searchset[$i]['forum_id']);
0864 $topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $searchset[$i]['topic_id'] . "&highlight=$highlight_active");
0865 $post_url = append_sid("viewtopic.$phpEx?" . POST_POST_URL . '=' . $searchset[$i]['post_id'] . "&highlight=$highlight_active") . '#' . $searchset[$i]['post_id'];
0866
0867 $post_date = create_date($board_config['default_dateformat'], $searchset[$i]['post_time'], $board_config['board_timezone']);
0868
0869 $message = $searchset[$i]['post_text'];
0870 $topic_title = $searchset[$i]['topic_title'];
0871
0872 $forum_id = $searchset[$i]['forum_id'];
0873 $topic_id = $searchset[$i]['topic_id'];
0874
0875 if ( $show_results == 'posts' )
0876 {
0877 if ( isset($return_chars) )
0878 {
0879 $bbcode_uid = $searchset[$i]['bbcode_uid'];
0880
0881 //
0882 // If the board has HTML off but the post has HTML
0883 // on then we process it, else leave it alone
0884 //
0885 if ( $return_chars != -1 )
0886 {
0887 $message = strip_tags($message);
0888 $message = preg_replace("/\[.*?:$bbcode_uid:?.*?\]/si", '', $message);
0889 $message = preg_replace('/\[url\]|\[\/url\]/si', '', $message);
0890 $message = ( strlen($message) > $return_chars ) ? substr($message, 0, $return_chars) . ' ...' : $message;
0891 }
0892 else
0893 {
0894 if ( !$board_config['allow_html'] )
0895 {
0896 if ( $postrow[$i]['enable_html'] )
0897 {
0898 $message = preg_replace('#(<)([\/]?.*?)(>)#is', '<\\2>', $message);
0899 }
0900 }
0901
0902 if ( $bbcode_uid != '' )
0903 {
0904 $message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $message);
0905 }
0906
0907 $message = make_clickable($message);
0908
0909 if ( $highlight_active )
0910 {
0911 if ( preg_match('/<.*>/', $message) )
0912 {
0913 $message = preg_replace($highlight_match, '<!-- #sh -->\1<!-- #eh -->', $message);
0914
0915 $end_html = 0;
0916 $start_html = 1;
0917 $temp_message = '';
0918 $message = ' ' . $message . ' ';
0919
0920 while( $start_html = strpos($message, '<', $start_html) )
0921 {
0922 $grab_length = $start_html - $end_html - 1;
0923 $temp_message .= substr($message, $end_html + 1, $grab_length);
0924
0925 if ( $end_html = strpos($message, '>', $start_html) )
0926 {
0927 $length = $end_html - $start_html + 1;
0928 $hold_string = substr($message, $start_html, $length);
0929
0930 if ( strrpos(' ' . $hold_string, '<') != 1 )
0931 {
0932 $end_html = $start_html + 1;
0933 $end_counter = 1;
0934
0935 while ( $end_counter && $end_html < strlen($message) )
0936 {
0937 if ( substr($message, $end_html, 1) == '>' )
0938 {
0939 $end_counter--;
0940 }
0941 else if ( substr($message, $end_html, 1) == '<' )
0942 {
0943 $end_counter++;
0944 }
0945
0946 $end_html++;
0947 }
0948
0949 $length = $end_html - $start_html + 1;
0950 $hold_string = substr($message, $start_html, $length);
0951 $hold_string = str_replace('<!-- #sh -->', '', $hold_string);
0952 $hold_string = str_replace('<!-- #eh -->', '', $hold_string);
0953 }
0954 else if ( $hold_string == '<!-- #sh -->' )
0955 {
0956 $hold_string = str_replace('<!-- #sh -->', '<span style="color:#' . $theme['fontcolor3'] . '"><b>', $hold_string);
0957 }
0958 else if ( $hold_string == '<!-- #eh -->' )
0959 {
0960 $hold_string = str_replace('<!-- #eh -->', '</b></span>', $hold_string);
0961 }
0962
0963 $temp_message .= $hold_string;
0964
0965 $start_html += $length;
0966 }
0967 else
0968 {
0969 $start_html = strlen($message);
0970 }
0971 }
0972
0973 $grab_length = strlen($message) - $end_html - 1;
0974 $temp_message .= substr($message, $end_html + 1, $grab_length);
0975
0976 $message = trim($temp_message);
0977 }
0978 else
0979 {
0980 $message = preg_replace($highlight_match, '<span style="color:#' . $theme['fontcolor3'] . '"><b>\1</b></span>', $message);
0981 }
0982 }
0983 }
0984
0985 if ( count($orig_word) )
0986 {
0987 $topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
0988 $post_subject = ( $searchset[$i]['post_subject'] != "" ) ? preg_replace($orig_word, $replacement_word, $searchset[$i]['post_subject']) : $topic_title;
0989
0990 $message = preg_replace($orig_word, $replacement_word, $message);
0991 }
0992 else
0993 {
0994 $post_subject = ( $searchset[$i]['post_subject'] != '' ) ? $searchset[$i]['post_subject'] : $topic_title;
0995 }
0996
0997 if ($board_config['allow_smilies'] && $searchset[$i]['enable_smilies'])
0998 {
0999 $message = smilies_pass($message);
1000 }
1001
1002 $message = str_replace("\n", '<br />', $message);
1003
1004 }
1005
1006 $poster = ( $searchset[$i]['user_id'] != ANONYMOUS ) ? '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $searchset[$i]['user_id']) . '">' : '';
1007 $poster .= ( $searchset[$i]['user_id'] != ANONYMOUS ) ? $searchset[$i]['username'] : ( ( $searchset[$i]['post_username'] != "" ) ? $searchset[$i]['post_username'] : $lang['Guest'] );
1008 $poster .= ( $searchset[$i]['user_id'] != ANONYMOUS ) ? '</a>' : '';
1009
1010 if ( $userdata['session_logged_in'] && $searchset[$i]['post_time'] > $userdata['user_lastvisit'] )
1011 {
1012 if ( !empty($tracking_topics[$topic_id]) && !empty($tracking_forums[$forum_id]) )
1013 {
1014 $topic_last_read = ( $tracking_topics[$topic_id] > $tracking_forums[$forum_id] ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
1015 }
1016 else if ( !empty($tracking_topics[$topic_id]) || !empty($tracking_forums[$forum_id]) )
1017 {
1018 $topic_last_read = ( !empty($tracking_topics[$topic_id]) ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
1019 }
1020
1021 if ( $searchset[$i]['post_time'] > $topic_last_read )
1022 {
1023 $mini_post_img = $images['icon_minipost_new'];
1024 $mini_post_alt = $lang['New_post'];
1025 }
1026 else
1027 {
1028 $mini_post_img = $images['icon_minipost'];
1029 $mini_post_alt = $lang['Post'];
1030 }
1031 }
1032 else
1033 {
1034 $mini_post_img = $images['icon_minipost'];
1035 $mini_post_alt = $lang['Post'];
1036 }
1037
1038 $template->assign_block_vars("searchresults", array(
1039 'TOPIC_TITLE' => $topic_title,
1040 'FORUM_NAME' => $searchset[$i]['forum_name'],
1041 'POST_SUBJECT' => $post_subject,
1042 'POST_DATE' => $post_date,
1043 'POSTER_NAME' => $poster,
1044 'TOPIC_REPLIES' => $searchset[$i]['topic_replies'],
1045 'TOPIC_VIEWS' => $searchset[$i]['topic_views'],
1046 'MESSAGE' => $message,
1047 'MINI_POST_IMG' => $mini_post_img,
1048
1049 'L_MINI_POST_ALT' => $mini_post_alt,
1050
1051 'U_POST' => $post_url,
1052 'U_TOPIC' => $topic_url,
1053 'U_FORUM' => $forum_url)
1054 );
1055 }
1056 else
1057 {
1058 $message = '';
1059
1060 if ( count($orig_word) )
1061 {
1062 $topic_title = preg_replace($orig_word, $replacement_word, $searchset[$i]['topic_title']);
1063 }
1064
1065 $topic_type = $searchset[$i]['topic_type'];
1066
1067 if ($topic_type == POST_ANNOUNCE)
1068 {
1069 $topic_type = $lang['Topic_Announcement'] . ' ';
1070 }
1071 else if ($topic_type == POST_STICKY)
1072 {
1073 $topic_type = $lang['Topic_Sticky'] . ' ';
1074 }
1075 else
1076 {
1077 $topic_type = '';
1078 }
1079
1080 if ( $searchset[$i]['topic_vote'] )
1081 {
1082 $topic_type .= $lang['Topic_Poll'] . ' ';
1083 }
1084
1085 $views = $searchset[$i]['topic_views'];
1086 $replies = $searchset[$i]['topic_replies'];
1087
1088 if ( ( $replies + 1 ) > $board_config['posts_per_page'] )
1089 {
1090 $total_pages = ceil( ( $replies + 1 ) / $board_config['posts_per_page'] );
1091 $goto_page = ' [ <img src="' . $images['icon_gotopost'] . '" alt="' . $lang['Goto_page'] . '" title="' . $lang['Goto_page'] . '" />' . $lang['Goto_page'] . ': ';
1092
1093 $times = 1;
1094 for($j = 0; $j < $replies + 1; $j += $board_config['posts_per_page'])
1095 {
1096 $goto_page .= '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $topic_id . "&start=$j") . '">' . $times . '</a>';
1097 if ( $times == 1 && $total_pages > 4 )
1098 {
1099 $goto_page .= ' ... ';
1100 $times = $total_pages - 3;
1101 $j += ( $total_pages - 4 ) * $board_config['posts_per_page'];
1102 }
1103 else if ( $times < $total_pages )
1104 {
1105 $goto_page .= ', ';
1106 }
1107 $times++;
1108 }
1109 $goto_page .= ' ] ';
1110 }
1111 else
1112 {
1113 $goto_page = '';
1114 }
1115
1116 if ( $searchset[$i]['topic_status'] == TOPIC_MOVED )
1117 {
1118 $topic_type = $lang['Topic_Moved'] . ' ';
1119 $topic_id = $searchset[$i]['topic_moved_id'];
1120
1121 $folder_image = '<img src="' . $images['folder'] . '" alt="' . $lang['No_new_posts'] . '" />';
1122 $newest_post_img = '';
1123 }
1124 else
1125 {
1126 if ( $searchset[$i]['topic_status'] == TOPIC_LOCKED )
1127 {
1128 $folder = $images['folder_locked'];
1129 $folder_new = $images['folder_locked_new'];
1130 }
1131 else if ( $searchset[$i]['topic_type'] == POST_ANNOUNCE )
1132 {
1133 $folder = $images['folder_announce'];
1134 $folder_new = $images['folder_announce_new'];
1135 }
1136 else if ( $searchset[$i]['topic_type'] == POST_STICKY )
1137 {
1138 $folder = $images['folder_sticky'];
1139 $folder_new = $images['folder_sticky_new'];
1140 }
1141 else
1142 {
1143 if ( $replies >= $board_config['hot_threshold'] )
1144 {
1145 $folder = $images['folder_hot'];
1146 $folder_new = $images['folder_hot_new'];
1147 }
1148 else
1149 {
1150 $folder = $images['folder'];
1151 $folder_new = $images['folder_new'];
1152 }
1153 }
1154
1155 if ( $userdata['session_logged_in'] )
1156 {
1157 if ( $searchset[$i]['post_time'] > $userdata['user_lastvisit'] )
1158 {
1159 if ( !empty($tracking_topics) || !empty($tracking_forums) || isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
1160 {
1161
1162 $unread_topics = true;
1163
1164 if ( !empty($tracking_topics[$topic_id]) )
1165 {
1166 if ( $tracking_topics[$topic_id] > $searchset[$i]['post_time'] )
1167 {
1168 $unread_topics = false;
1169 }
1170 }
1171
1172 if ( !empty($tracking_forums[$forum_id]) )
1173 {
1174 if ( $tracking_forums[$forum_id] > $searchset[$i]['post_time'] )
1175 {
1176 $unread_topics = false;
1177 }
1178 }
1179
1180 if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
1181 {
1182 if ( $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all'] > $searchset[$i]['post_time'] )
1183 {
1184 $unread_topics = false;
1185 }
1186 }
1187
1188 if ( $unread_topics )
1189 {
1190 $folder_image = $folder_new;
1191 $folder_alt = $lang['New_posts'];
1192
1193 $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> ';
1194 }
1195 else
1196 {
1197 $folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
1198
1199 $folder_image = $folder;
1200 $folder_alt = $folder_alt;
1201 $newest_post_img = '';
1202 }
1203
1204 }
1205 else if ( $searchset[$i]['post_time'] > $userdata['user_lastvisit'] )
1206 {
1207 $folder_image = $folder_new;
1208 $folder_alt = $lang['New_posts'];
1209
1210 $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> ';
1211 }
1212 else
1213 {
1214 $folder_image = $folder;
1215 $folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
1216 $newest_post_img = '';
1217 }
1218 }
1219 else
1220 {
1221 $folder_image = $folder;
1222 $folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
1223 $newest_post_img = '';
1224 }
1225 }
1226 else
1227 {
1228 $folder_image = $folder;
1229 $folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
1230 $newest_post_img = '';
1231 }
1232 }
1233
1234
1235 $topic_author = ( $searchset[$i]['user_id'] != ANONYMOUS ) ? '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . '=' . $searchset[$i]['user_id']) . '">' : '';
1236 $topic_author .= ( $searchset[$i]['user_id'] != ANONYMOUS ) ? $searchset[$i]['username'] : ( ( $searchset[$i]['post_username'] != '' ) ? $searchset[$i]['post_username'] : $lang['Guest'] );
1237
1238 $topic_author .= ( $searchset[$i]['user_id'] != ANONYMOUS ) ? '</a>' : '';
1239
1240 $first_post_time = create_date($board_config['default_dateformat'], $searchset[$i]['topic_time'], $board_config['board_timezone']);
1241
1242 $last_post_time = create_date($board_config['default_dateformat'], $searchset[$i]['post_time'], $board_config['board_timezone']);
1243
1244 $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>';
1245
1246 $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>';
1247
1248 $template->assign_block_vars('searchresults', array(
1249 'FORUM_NAME' => $searchset[$i]['forum_name'],
1250 'FORUM_ID' => $forum_id,
1251 'TOPIC_ID' => $topic_id,
1252 'FOLDER' => $folder_image,
1253 'NEWEST_POST_IMG' => $newest_post_img,
1254 'TOPIC_FOLDER_IMG' => $folder_image,
1255 'GOTO_PAGE' => $goto_page,
1256 'REPLIES' => $replies,
1257 'TOPIC_TITLE' => $topic_title,
1258 'TOPIC_TYPE' => $topic_type,
1259 'VIEWS' => $views,
1260 'TOPIC_AUTHOR' => $topic_author,
1261 'FIRST_POST_TIME' => $first_post_time,
1262 'LAST_POST_TIME' => $last_post_time,
1263 'LAST_POST_AUTHOR' => $last_post_author,
1264 'LAST_POST_IMG' => $last_post_url,
1265
1266 'L_TOPIC_FOLDER_ALT' => $folder_alt,
1267
1268 'U_VIEW_FORUM' => $forum_url,
1269 'U_VIEW_TOPIC' => $topic_url)
1270 );
1271 }
1272 }
1273
1274 $base_url = "search.$phpEx?search_id=$search_id";
1275
1276 $template->assign_vars(array(
1277 'PAGINATION' => generate_pagination($base_url, $total_match_count, $per_page, $start),
1278 'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $per_page ) + 1 ), ceil( $total_match_count / $per_page )),
1279
1280 'L_AUTHOR' => $lang['Author'],
1281 'L_MESSAGE' => $lang['Message'],
1282 'L_FORUM' => $lang['Forum'],
1283 'L_TOPICS' => $lang['Topics'],
1284 'L_REPLIES' => $lang['Replies'],
1285 'L_VIEWS' => $lang['Views'],
1286 'L_POSTS' => $lang['Posts'],
1287 'L_LASTPOST' => $lang['Last_Post'],
1288 'L_POSTED' => $lang['Posted'],
1289 'L_SUBJECT' => $lang['Subject'],
1290
1291 'L_GOTO_PAGE' => $lang['Goto_page'])
1292 );
1293
1294 $template->pparse('body');
1295
1296 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
1297 }
1298 else
1299 {
1300 message_die(GENERAL_MESSAGE, $lang['No_search_match']);
1301 }
1302 }
1303
1304 //
1305 // Search forum
1306 //
1307 $sql = "SELECT c.cat_title, c.cat_id, f.forum_name, f.forum_id
1308 FROM " . CATEGORIES_TABLE . " c, " . FORUMS_TABLE . " f
1309 WHERE f.cat_id = c.cat_id
1310 ORDER BY c.cat_order, f.forum_order";
1311 $result = $db->sql_query($sql);
1312 if ( !$result )
1313 {
1314 message_die(GENERAL_ERROR, 'Could not obtain forum_name/forum_id', '', __LINE__, __FILE__, $sql);
1315 }
1316
1317 $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata);
1318
1319 $s_forums = '';
1320 while( $row = $db->sql_fetchrow($result) )
1321 {
1322 if ( $is_auth_ary[$row['forum_id']]['auth_read'] )
1323 {
1324 $s_forums .= '<option value="' . $row['forum_id'] . '">' . $row['forum_name'] . '</option>';
1325 if ( empty($list_cat[$row['cat_id']]) )
1326 {
1327 $list_cat[$row['cat_id']] = $row['cat_title'];
1328 }
1329 }
1330 }
1331
1332 if ( $s_forums != '' )
1333 {
1334 $s_forums = '<option value="-1">' . $lang['All_available'] . '</option>' . $s_forums;
1335
1336 //
1337 // Category to search
1338 //
1339 $s_categories = '<option value="-1">' . $lang['All_available'] . '</option>';
1340 while( list($cat_id, $cat_title) = @each($list_cat))
1341 {
1342 $s_categories .= '<option value="' . $cat_id . '">' . $cat_title . '</option>';
1343 }
1344 }
1345 else
1346 {
1347 message_die(GENERAL_MESSAGE, $lang['No_searchable_forums']);
1348 }
1349
1350 //
1351 // Number of chars returned
1352 //
1353 $s_characters = '<option value="-1">' . $lang['All_available'] . '</option>';
1354 $s_characters .= '<option value="0">0</option>';
1355 $s_characters .= '<option value="25">25</option>';
1356 $s_characters .= '<option value="50">50</option>';
1357
1358 for($i = 100; $i < 1100 ; $i += 100)
1359 {
1360 $selected = ( $i == 200 ) ? ' selected="selected"' : '';
1361 $s_characters .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>';
1362 }
1363
1364 //
1365 // Sorting
1366 //
1367 $s_sort_by = "";
1368 for($i = 0; $i < count($sort_by_types); $i++)
1369 {
1370 $s_sort_by .= '<option value="' . $i . '">' . $sort_by_types[$i] . '</option>';
1371 }
1372
1373 //
1374 // Search time
1375 //
1376 $previous_days = array(0, 1, 7, 14, 30, 90, 180, 364);
1377 $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']);
1378
1379 $s_time = '';
1380 for($i = 0; $i < count($previous_days); $i++)
1381 {
1382 $selected = ( $topic_days == $previous_days[$i] ) ? ' selected="selected"' : '';
1383 $s_time .= '<option value="' . $previous_days[$i] . '"' . $selected . '>' . $previous_days_text[$i] . '</option>';
1384 }
1385
1386 //
1387 // Output the basic page
1388 //
1389 $page_title = $lang['Search'];
1390 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
1391
1392 $template->set_filenames(array(
1393 'body' => 'search_body.tpl')
1394 );
1395 make_jumpbox('viewforum.'.$phpEx);
1396
1397 $template->assign_vars(array(
1398 'L_SEARCH_QUERY' => $lang['Search_query'],
1399 'L_SEARCH_OPTIONS' => $lang['Search_options'],
1400 'L_SEARCH_KEYWORDS' => $lang['Search_keywords'],
1401 'L_SEARCH_KEYWORDS_EXPLAIN' => $lang['Search_keywords_explain'],
1402 'L_SEARCH_AUTHOR' => $lang['Search_author'],
1403 'L_SEARCH_AUTHOR_EXPLAIN' => $lang['Search_author_explain'],
1404 'L_SEARCH_ANY_TERMS' => $lang['Search_for_any'],
1405 'L_SEARCH_ALL_TERMS' => $lang['Search_for_all'],
1406 'L_SEARCH_MESSAGE_ONLY' => $lang['Search_msg_only'],
1407 'L_SEARCH_MESSAGE_TITLE' => $lang['Search_title_msg'],
1408 'L_CATEGORY' => $lang['Category'],
1409 'L_RETURN_FIRST' => $lang['Return_first'],
1410 'L_CHARACTERS' => $lang['characters_posts'],
1411 'L_SORT_BY' => $lang['Sort_by'],
1412 'L_SORT_ASCENDING' => $lang['Sort_Ascending'],
1413 'L_SORT_DESCENDING' => $lang['Sort_Descending'],
1414 'L_SEARCH_PREVIOUS' => $lang['Search_previous'],
1415 'L_DISPLAY_RESULTS' => $lang['Display_results'],
1416 'L_FORUM' => $lang['Forum'],
1417 'L_TOPICS' => $lang['Topics'],
1418 'L_POSTS' => $lang['Posts'],
1419
1420 'S_SEARCH_ACTION' => append_sid("search.$phpEx?mode=results"),
1421 'S_CHARACTER_OPTIONS' => $s_characters,
1422 'S_FORUM_OPTIONS' => $s_forums,
1423 'S_CATEGORY_OPTIONS' => $s_categories,
1424 'S_TIME_OPTIONS' => $s_time,
1425 'S_SORT_OPTIONS' => $s_sort_by,
1426 'S_HIDDEN_FIELDS' => '')
1427 );
1428
1429 $template->pparse('body');
1430
1431 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
1432
1433 ?>