PageRenderTime 56ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/doweneed/forums/search.php

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