slek_12000

search.php

Oct 9th, 2014
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 47.71 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @package phpBB3
  5. * @version $Id$
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10.  
  11. /**
  12. * @ignore
  13. */
  14. define('IN_PHPBB', true);
  15. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  16. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  17. include($phpbb_root_path . 'common.' . $phpEx);
  18.  
  19. // Start session management
  20. $user->session_begin();
  21. $auth->acl($user->data);
  22. $user->setup('search');
  23.  
  24. // Define initial vars
  25. $mode = request_var('mode', '');
  26. $search_id = request_var('search_id', '');
  27. $start = max(request_var('start', 0), 0);
  28. $post_id = request_var('p', 0);
  29. $topic_id = request_var('t', 0);
  30. $view = request_var('view', '');
  31.  
  32. $submit = request_var('submit', false);
  33. $keywords = utf8_normalize_nfc(request_var('keywords', '', true));
  34. $add_keywords = utf8_normalize_nfc(request_var('add_keywords', '', true));
  35. $author = request_var('author', '', true);
  36. $author_id = request_var('author_id', 0);
  37. $show_results = ($topic_id) ? 'posts' : request_var('sr', 'posts');
  38. $show_results = ($show_results == 'posts') ? 'posts' : 'topics';
  39. $search_terms = request_var('terms', 'all');
  40. $search_fields = request_var('sf', 'all');
  41. $search_child = request_var('sc', true);
  42.  
  43. $sort_days = request_var('st', 0);
  44. $sort_key = request_var('sk', 't');
  45. $sort_dir = request_var('sd', 'd');
  46.  
  47. $return_chars = request_var('ch', ($topic_id) ? -1 : 300);
  48. $search_forum = request_var('fid', array(0));
  49. //-- mod : quick title edition -------------------------------------------------
  50. //-- add
  51. $attr_id = request_var('attr_id', 0);
  52. $show_results = $attr_id ? 'topics' : $show_results;
  53. //-- fin mod : quick title edition ---------------------------------------------
  54. // We put login boxes for the case if search_id is newposts, egosearch or unreadposts
  55. // because a guest should be able to log in even if guests search is not permitted
  56.  
  57. switch ($search_id)
  58. {
  59. // Egosearch is an author search
  60. case 'egosearch':
  61. $author_id = $user->data['user_id'];
  62. if ($user->data['user_id'] == ANONYMOUS)
  63. {
  64. login_box('', $user->lang['LOGIN_EXPLAIN_EGOSEARCH']);
  65. }
  66. break;
  67.  
  68. // Search for unread posts needs to be allowed and user to be logged in if topics tracking for guests is disabled
  69. case 'unreadposts':
  70. if (!$config['load_unreads_search'])
  71. {
  72. $template->assign_var('S_NO_SEARCH', true);
  73. trigger_error('NO_SEARCH_UNREADS');
  74. }
  75. else if (!$config['load_anon_lastread'] && !$user->data['is_registered'])
  76. {
  77. login_box('', $user->lang['LOGIN_EXPLAIN_UNREADSEARCH']);
  78. }
  79. break;
  80.  
  81. // The "new posts" search uses user_lastvisit which is user based, so it should require user to log in.
  82. case 'newposts':
  83. if ($user->data['user_id'] == ANONYMOUS)
  84. {
  85. login_box('', $user->lang['LOGIN_EXPLAIN_NEWPOSTS']);
  86. }
  87. break;
  88.  
  89. default:
  90. // There's nothing to do here for now ;)
  91. break;
  92. }
  93.  
  94. // Is user able to search? Has search been disabled?
  95. if (!$auth->acl_get('u_search') || !$auth->acl_getf_global('f_search') || !$config['load_search'])
  96. {
  97. $template->assign_var('S_NO_SEARCH', true);
  98. trigger_error('NO_SEARCH');
  99. }
  100.  
  101. // Check search load limit
  102. if ($user->load && $config['limit_search_load'] && ($user->load > doubleval($config['limit_search_load'])))
  103. {
  104. $template->assign_var('S_NO_SEARCH', true);
  105. trigger_error('NO_SEARCH_TIME');
  106. }
  107.  
  108. // It is applicable if the configuration setting is non-zero, and the user cannot
  109. // ignore the flood setting, and the search is a keyword search.
  110. $interval = ($user->data['user_id'] == ANONYMOUS) ? $config['search_anonymous_interval'] : $config['search_interval'];
  111. if ($interval && !in_array($search_id, array('unreadposts', 'unanswered', 'active_topics', 'egosearch')) && !$auth->acl_get('u_ignoreflood'))
  112. {
  113. if ($user->data['user_last_search'] > time() - $interval)
  114. {
  115. $template->assign_var('S_NO_SEARCH', true);
  116. trigger_error('NO_SEARCH_TIME');
  117. }
  118. }
  119.  
  120. // Define some vars
  121. $limit_days = array(0 => $user->lang['ALL_RESULTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
  122. $sort_by_text = array('a' => $user->lang['SORT_AUTHOR'], 't' => $user->lang['SORT_TIME'], 'f' => $user->lang['SORT_FORUM'], 'i' => $user->lang['SORT_TOPIC_TITLE'], 's' => $user->lang['SORT_POST_SUBJECT']);
  123.  
  124. $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
  125. gen_sort_selects(
  126. //-- mod : quick title edition -------------------------------------------------
  127. //-- add
  128. $submit |= $attr_id;
  129. //-- fin mod : quick title edition ---------------------------------------------$limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
  130.  
  131. if ($keywords || $author || $author_id || $search_id || $submit)
  132. {
  133. // clear arrays
  134. $id_ary = array();
  135.  
  136. // If we are looking for authors get their ids
  137. $author_id_ary = array();
  138. $sql_author_match = '';
  139. if ($author_id)
  140. {
  141. $author_id_ary[] = $author_id;
  142. }
  143. else if ($author)
  144. {
  145. if ((strpos($author, '*') !== false) && (utf8_strlen(str_replace(array('*', '%'), '', $author)) < $config['min_search_author_chars']))
  146. {
  147. trigger_error(sprintf($user->lang['TOO_FEW_AUTHOR_CHARS'], $config['min_search_author_chars']));
  148. }
  149.  
  150. $sql_where = (strpos($author, '*') !== false) ? ' username_clean ' . $db->sql_like_expression(str_replace('*', $db->any_char, utf8_clean_string($author))) : " username_clean = '" . $db->sql_escape(utf8_clean_string($author)) . "'";
  151.  
  152. $sql = 'SELECT user_id
  153. FROM ' . USERS_TABLE . "
  154. WHERE $sql_where
  155. AND user_type <> " . USER_IGNORE;
  156. $result = $db->sql_query_limit($sql, 100);
  157.  
  158. while ($row = $db->sql_fetchrow($result))
  159. {
  160. $author_id_ary[] = (int) $row['user_id'];
  161. }
  162. $db->sql_freeresult($result);
  163.  
  164. $sql_where = (strpos($author, '*') !== false) ? ' post_username ' . $db->sql_like_expression(str_replace('*', $db->any_char, utf8_clean_string($author))) : " post_username = '" . $db->sql_escape(utf8_clean_string($author)) . "'";
  165.  
  166. $sql = 'SELECT 1 as guest_post
  167. FROM ' . POSTS_TABLE . "
  168. WHERE $sql_where
  169. AND poster_id = " . ANONYMOUS;
  170. $result = $db->sql_query_limit($sql, 1);
  171. $found_guest_post = $db->sql_fetchfield('guest_post');
  172. $db->sql_freeresult($result);
  173.  
  174. if ($found_guest_post)
  175. {
  176. $author_id_ary[] = ANONYMOUS;
  177. $sql_author_match = (strpos($author, '*') !== false) ? ' ' . $db->sql_like_expression(str_replace('*', $db->any_char, utf8_clean_string($author))) : " = '" . $db->sql_escape(utf8_clean_string($author)) . "'";
  178. }
  179.  
  180. if (!sizeof($author_id_ary))
  181. {
  182. trigger_error('NO_SEARCH_RESULTS');
  183. }
  184. }
  185.  
  186. // if we search in an existing search result just add the additional keywords. But we need to use "all search terms"-mode
  187. // so we can keep the old keywords in their old mode, but add the new ones as required words
  188. if ($add_keywords)
  189. {
  190. if ($search_terms == 'all')
  191. {
  192. $keywords .= ' ' . $add_keywords;
  193. }
  194. else
  195. {
  196. $search_terms = 'all';
  197. $keywords = implode(' |', explode(' ', preg_replace('#\s+#u', ' ', $keywords))) . ' ' .$add_keywords;
  198. }
  199. }
  200.  
  201. // Which forums should not be searched? Author searches are also carried out in unindexed forums
  202. if (empty($keywords) && sizeof($author_id_ary))
  203. {
  204. $ex_fid_ary = array_keys($auth->acl_getf('!f_read', true));
  205. }
  206. else
  207. {
  208. $ex_fid_ary = array_unique(array_merge(array_keys($auth->acl_getf('!f_read', true)), array_keys($auth->acl_getf('!f_search', true))));
  209. }
  210.  
  211. $not_in_fid = (sizeof($ex_fid_ary)) ? 'WHERE ' . $db->sql_in_set('f.forum_id', $ex_fid_ary, true) . " OR (f.forum_password <> '' AND fa.user_id <> " . (int) $user->data['user_id'] . ')' : "";
  212.  
  213. $sql = 'SELECT f.forum_id, f.forum_name, f.parent_id, f.forum_type, f.right_id, f.forum_password, f.forum_flags, fa.user_id
  214. FROM ' . FORUMS_TABLE . ' f
  215. LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa ON (fa.forum_id = f.forum_id
  216. AND fa.session_id = '" . $db->sql_escape($user->session_id) . "')
  217. $not_in_fid
  218. ORDER BY f.left_id";
  219. $result = $db->sql_query($sql);
  220.  
  221. $right_id = 0;
  222. $reset_search_forum = true;
  223. while ($row = $db->sql_fetchrow($result))
  224. {
  225. if ($row['forum_password'] && $row['user_id'] != $user->data['user_id'])
  226. {
  227. $ex_fid_ary[] = (int) $row['forum_id'];
  228. continue;
  229. }
  230.  
  231. // Exclude forums from active topics
  232. if (!($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) && ($search_id == 'active_topics'))
  233. {
  234. $ex_fid_ary[] = (int) $row['forum_id'];
  235. continue;
  236. }
  237.  
  238. if (sizeof($search_forum))
  239. {
  240. if ($search_child)
  241. {
  242. if (in_array($row['forum_id'], $search_forum) && $row['right_id'] > $right_id)
  243. {
  244. $right_id = (int) $row['right_id'];
  245. }
  246. else if ($row['right_id'] < $right_id)
  247. {
  248. continue;
  249. }
  250. }
  251.  
  252. if (!in_array($row['forum_id'], $search_forum))
  253. {
  254. $ex_fid_ary[] = (int) $row['forum_id'];
  255. $reset_search_forum = false;
  256. }
  257. }
  258. }
  259. $db->sql_freeresult($result);
  260.  
  261. // find out in which forums the user is allowed to view approved posts
  262. if ($auth->acl_get('m_approve'))
  263. {
  264. $m_approve_fid_ary = array(-1);
  265. $m_approve_fid_sql = '';
  266. }
  267. else if ($auth->acl_getf_global('m_approve'))
  268. {
  269. $m_approve_fid_ary = array_diff(array_keys($auth->acl_getf('!m_approve', true)), $ex_fid_ary);
  270. $m_approve_fid_sql = ' AND (p.post_approved = 1' . ((sizeof($m_approve_fid_ary)) ? ' OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) : '') . ')';
  271. }
  272. else
  273. {
  274. $m_approve_fid_ary = array();
  275. $m_approve_fid_sql = ' AND p.post_approved = 1';
  276. }
  277.  
  278. if ($reset_search_forum)
  279. {
  280. $search_forum = array();
  281. }
  282.  
  283. // Select which method we'll use to obtain the post_id or topic_id information
  284. $search_type = basename($config['search_type']);
  285.  
  286. if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
  287. {
  288. trigger_error('NO_SUCH_SEARCH_MODULE');
  289. }
  290.  
  291. require("{$phpbb_root_path}includes/search/$search_type.$phpEx");
  292.  
  293. // We do some additional checks in the module to ensure it can actually be utilised
  294. $error = false;
  295. $search = new $search_type($error);
  296.  
  297. if ($error)
  298. {
  299. trigger_error($error);
  300. }
  301.  
  302. // let the search module split up the keywords
  303. if ($keywords)
  304. {
  305. $correct_query = $search->split_keywords($keywords, $search_terms);
  306. if (!$correct_query || (empty($search->search_query) && !sizeof($author_id_ary) && !$search_id))
  307. {
  308. $ignored = (sizeof($search->common_words)) ? sprintf($user->lang['IGNORED_TERMS_EXPLAIN'], implode(' ', $search->common_words)) . '<br />' : '';
  309. trigger_error($ignored . sprintf($user->lang['NO_KEYWORDS'], $search->word_length['min'], $search->word_length['max']));
  310. }
  311. }
  312.  
  313. if (!$keywords && sizeof($author_id_ary))
  314. {
  315. // if it is an author search we want to show topics by default
  316. $show_results = ($topic_id) ? 'posts' : request_var('sr', ($search_id == 'egosearch') ? 'topics' : 'posts');
  317. $show_results = ($show_results == 'posts') ? 'posts' : 'topics';
  318. }
  319.  
  320. // define some variables needed for retrieving post_id/topic_id information
  321. $sort_by_sql = array('a' => 'u.username_clean', 't' => (($show_results == 'posts') ? 'p.post_time' : 't.topic_last_post_time'), 'f' => 'f.forum_id', 'i' => 't.topic_title', 's' => (($show_results == 'posts') ? 'p.post_subject' : 't.topic_title'));
  322.  
  323. // pre-made searches
  324. $sql = $field = $l_search_title = '';
  325. if ($search_id)
  326. {
  327. switch ($search_id)
  328. {
  329. // Oh holy Bob, bring us some activity...
  330. case 'active_topics':
  331. $l_search_title = $user->lang['SEARCH_ACTIVE_TOPICS'];
  332. $show_results = 'topics';
  333. $sort_key = 't';
  334. $sort_dir = 'd';
  335. $sort_days = request_var('st', 7);
  336. $sort_by_sql['t'] = 't.topic_last_post_time';
  337.  
  338. gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
  339. $s_sort_key = $s_sort_dir = '';
  340.  
  341. $last_post_time_sql = ($sort_days) ? ' AND t.topic_last_post_time > ' . (time() - ($sort_days * 24 * 3600)) : '';
  342.  
  343. $sql = 'SELECT t.topic_last_post_time, t.topic_id
  344. FROM ' . TOPICS_TABLE . " t
  345. WHERE t.topic_moved_id = 0
  346. $last_post_time_sql
  347. " . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . '
  348. ' . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . '
  349. ORDER BY t.topic_last_post_time DESC';
  350. $field = 'topic_id';
  351. break;
  352.  
  353. case 'unanswered':
  354. $l_search_title = $user->lang['SEARCH_UNANSWERED'];
  355. $show_results = request_var('sr', 'topics');
  356. $show_results = ($show_results == 'posts') ? 'posts' : 'topics';
  357. $sort_by_sql['t'] = ($show_results == 'posts') ? 'p.post_time' : 't.topic_last_post_time';
  358. $sort_by_sql['s'] = ($show_results == 'posts') ? 'p.post_subject' : 't.topic_title';
  359. $sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC');
  360.  
  361. $sort_join = ($sort_key == 'f') ? FORUMS_TABLE . ' f, ' : '';
  362. $sql_sort = ($sort_key == 'f') ? ' AND f.forum_id = p.forum_id ' . $sql_sort : $sql_sort;
  363.  
  364. if ($sort_days)
  365. {
  366. $last_post_time = 'AND p.post_time > ' . (time() - ($sort_days * 24 * 3600));
  367. }
  368. else
  369. {
  370. $last_post_time = '';
  371. }
  372.  
  373. if ($sort_key == 'a')
  374. {
  375. $sort_join = USERS_TABLE . ' u, ';
  376. $sql_sort = ' AND u.user_id = p.poster_id ' . $sql_sort;
  377. }
  378. if ($show_results == 'posts')
  379. {
  380. $sql = "SELECT p.post_id
  381. FROM $sort_join" . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
  382. WHERE t.topic_replies = 0
  383. AND p.topic_id = t.topic_id
  384. $last_post_time
  385. $m_approve_fid_sql
  386. " . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '') . "
  387. $sql_sort";
  388. $field = 'post_id';
  389. }
  390. else
  391. {
  392. $sql = 'SELECT DISTINCT ' . $sort_by_sql[$sort_key] . ", p.topic_id
  393. FROM $sort_join" . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
  394. WHERE t.topic_replies = 0
  395. AND t.topic_moved_id = 0
  396. AND p.topic_id = t.topic_id
  397. $last_post_time
  398. $m_approve_fid_sql
  399. " . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '') . "
  400. $sql_sort";
  401. $field = 'topic_id';
  402. }
  403. break;
  404.  
  405. case 'unreadposts':
  406. $l_search_title = $user->lang['SEARCH_UNREAD'];
  407. // force sorting
  408. $show_results = 'topics';
  409. $sort_key = 't';
  410. $sort_by_sql['t'] = 't.topic_last_post_time';
  411. $sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC');
  412.  
  413. $sql_where = 'AND t.topic_moved_id = 0
  414. ' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . '
  415. ' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '');
  416.  
  417. gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
  418. $s_sort_key = $s_sort_dir = $u_sort_param = $s_limit_days = '';
  419. break;
  420.  
  421. case 'newposts':
  422. $l_search_title = $user->lang['SEARCH_NEW'];
  423. // force sorting
  424. $show_results = (request_var('sr', 'topics') == 'posts') ? 'posts' : 'topics';
  425. $sort_key = 't';
  426. $sort_dir = 'd';
  427. $sort_by_sql['t'] = ($show_results == 'posts') ? 'p.post_time' : 't.topic_last_post_time';
  428. $sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC');
  429.  
  430. gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
  431. $s_sort_key = $s_sort_dir = $u_sort_param = $s_limit_days = '';
  432.  
  433. if ($show_results == 'posts')
  434. {
  435. $sql = 'SELECT p.post_id
  436. FROM ' . POSTS_TABLE . ' p
  437. WHERE p.post_time > ' . $user->data['user_lastvisit'] . "
  438. $m_approve_fid_sql
  439. " . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '') . "
  440. $sql_sort";
  441. $field = 'post_id';
  442. }
  443. else
  444. {
  445. $sql = 'SELECT t.topic_id
  446. FROM ' . TOPICS_TABLE . ' t
  447. WHERE t.topic_last_post_time > ' . $user->data['user_lastvisit'] . '
  448. AND t.topic_moved_id = 0
  449. ' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . '
  450. ' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . "
  451. $sql_sort";
  452. /*
  453. [Fix] queued replies missing from "view new posts" (Bug #42705 - Patch by Paul)
  454. - Creates temporary table, query is far from optimized
  455.  
  456. $sql = 'SELECT t.topic_id
  457. FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p
  458. WHERE p.post_time > ' . $user->data['user_lastvisit'] . '
  459. AND t.topic_id = p.topic_id
  460. AND t.topic_moved_id = 0
  461. ' . $m_approve_fid_sql . '
  462. ' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . "
  463. GROUP BY t.topic_id
  464. $sql_sort";
  465. */
  466. $field = 'topic_id';
  467. }
  468. break;
  469.  
  470. case 'egosearch':
  471. $l_search_title = $user->lang['SEARCH_SELF'];
  472. break;
  473. }
  474. }
  475.  
  476. // show_results should not change after this
  477. $per_page = ($show_results == 'posts') ? $config['posts_per_page'] : $config['topics_per_page'];
  478. $total_match_count = 0;
  479.  
  480. // Set limit for the $total_match_count to reduce server load
  481. $total_matches_limit = 1000;
  482. $found_more_search_matches = false;
  483.  
  484. if ($search_id)
  485. {
  486. if ($sql)
  487. {
  488. // Only return up to $total_matches_limit+1 ids (the last one will be removed later)
  489. $result = $db->sql_query_limit($sql, $total_matches_limit + 1);
  490.  
  491. while ($row = $db->sql_fetchrow($result))
  492. {
  493. $id_ary[] = (int) $row[$field];
  494. }
  495. $db->sql_freeresult($result);
  496. }
  497. else if ($search_id == 'unreadposts')
  498. {
  499. // Only return up to $total_matches_limit+1 ids (the last one will be removed later)
  500. $id_ary = array_keys(get_unread_topics($user->data['user_id'], $sql_where, $sql_sort, $total_matches_limit + 1));
  501. }
  502. else
  503. {
  504. $search_id = '';
  505. }
  506.  
  507. $total_match_count = sizeof($id_ary);
  508. if ($total_match_count)
  509. {
  510. // Limit the number to $total_matches_limit for pre-made searches
  511. if ($total_match_count > $total_matches_limit)
  512. {
  513. $found_more_search_matches = true;
  514. $total_match_count = $total_matches_limit;
  515. }
  516.  
  517. // Make sure $start is set to the last page if it exceeds the amount
  518. if ($start < 0)
  519. {
  520. $start = 0;
  521. }
  522. else if ($start >= $total_match_count)
  523. {
  524. $start = floor(($total_match_count - 1) / $per_page) * $per_page;
  525. }
  526.  
  527. $id_ary = array_slice($id_ary, $start, $per_page);
  528. }
  529. else
  530. {
  531. // Set $start to 0 if no matches were found
  532. $start = 0;
  533. }
  534. }
  535.  
  536. // make sure that some arrays are always in the same order
  537. sort($ex_fid_ary);
  538. sort($m_approve_fid_ary);
  539. sort($author_id_ary);
  540. //-- mod : quick title edition -------------------------------------------------
  541. //-- add
  542. $id_ary += array('attr_id' => $attr_id);
  543. //-- fin mod : quick title edition ---------------------------------------------
  544. if (!empty($search->search_query))
  545. {
  546. $total_match_count = $search->keyword_search($show_results, $search_fields, $search_terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page);
  547. }
  548. else if (sizeof($author_id_ary))
  549. {
  550. $firstpost_only = ($search_fields === 'firstpost' || $search_fields == 'titleonly') ? true : false;
  551. $total_match_count = $search->author_search($show_results, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page);
  552. }
  553. //-- mod : quick title edition -------------------------------------------------
  554. //-- add
  555. else if ( empty($search_id) && $attr_id )
  556. {
  557. $total_match_count = $search->attribute_search($sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $id_ary, $start, $per_page);
  558. }
  559. //-- fin mod : quick title edition ---------------------------------------------
  560. // For some searches we need to print out the "no results" page directly to allow re-sorting/refining the search options.
  561. if (!sizeof($id_ary) && !$search_id)
  562. {
  563. trigger_error('NO_SEARCH_RESULTS');
  564. }
  565.  
  566. $sql_where = '';
  567.  
  568. if (sizeof($id_ary))
  569. {
  570. $sql_where .= $db->sql_in_set(($show_results == 'posts') ? 'p.post_id' : 't.topic_id', $id_ary);
  571. //-- mod : quick title edition -------------------------------------------------
  572. //-- add
  573. if ( $attr_id )
  574. {
  575. $sql_where .= (!empty($sql_where) ? ' AND ' : '') . 't.topic_attr_id = ' . (int) $attr_id;
  576. }
  577. //-- fin mod : quick title edition ---------------------------------------------
  578. $sql_where .= (sizeof($ex_fid_ary)) ? ' AND (' . $db->sql_in_set('f.forum_id', $ex_fid_ary, true) . ' OR f.forum_id IS NULL)' : '';
  579. $sql_where .= ($show_results == 'posts') ? $m_approve_fid_sql : str_replace(array('p.post_approved', 'p.forum_id'), array('t.topic_approved', 't.forum_id'), $m_approve_fid_sql);
  580. }
  581.  
  582. if ($show_results == 'posts')
  583. {
  584. include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
  585. }
  586. else
  587. {
  588. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  589. }
  590.  
  591. $user->add_lang('viewtopic');
  592.  
  593. // Grab icons
  594. $icons = $cache->obtain_icons();
  595.  
  596. // Output header
  597. if ($found_more_search_matches)
  598. {
  599. $l_search_matches = sprintf($user->lang['FOUND_MORE_SEARCH_MATCHES'], $total_match_count);
  600. }
  601. else
  602. {
  603. $l_search_matches = ($total_match_count == 1) ? sprintf($user->lang['FOUND_SEARCH_MATCH'], $total_match_count) : sprintf($user->lang['FOUND_SEARCH_MATCHES'], $total_match_count);
  604. }
  605.  
  606. // define some vars for urls
  607. $hilit = implode('|', explode(' ', preg_replace('#\s+#u', ' ', str_replace(array('+', '-', '|', '(', ')', '&quot;'), ' ', $keywords))));
  608. // Do not allow *only* wildcard being used for hilight
  609. $hilit = (strspn($hilit, '*') === strlen($hilit)) ? '' : $hilit;
  610.  
  611. $u_hilit = urlencode(htmlspecialchars_decode(str_replace('|', ' ', $hilit)));
  612. $u_show_results = '&amp;sr=' . $show_results;
  613. $u_search_forum = implode('&amp;fid%5B%5D=', $search_forum);
  614.  
  615. $u_search = append_sid("{$phpbb_root_path}search.$phpEx", $u_sort_param . $u_show_results);
  616. $u_search .= ($search_id) ? '&amp;search_id=' . $search_id : '';
  617. $u_search .= ($u_hilit) ? '&amp;keywords=' . urlencode(htmlspecialchars_decode($keywords)) : '';
  618. $u_search .= ($search_terms != 'all') ? '&amp;terms=' . $search_terms : '';
  619. $u_search .= ($topic_id) ? '&amp;t=' . $topic_id : '';
  620. $u_search .= ($author) ? '&amp;author=' . urlencode(htmlspecialchars_decode($author)) : '';
  621. $u_search .= ($author_id) ? '&amp;author_id=' . $author_id : '';
  622. $u_search .= ($u_search_forum) ? '&amp;fid%5B%5D=' . $u_search_forum : '';
  623. $u_search .= (!$search_child) ? '&amp;sc=0' : '';
  624. $u_search .= ($search_fields != 'all') ? '&amp;sf=' . $search_fields : '';
  625. $u_search .= ($return_chars != 300) ? '&amp;ch=' . $return_chars : '';
  626. //-- mod : quick title edition -------------------------------------------------
  627. //-- add
  628. if ( $attr_id )
  629. {
  630. $u_search .= '&amp;attr_id=' . $attr_id;
  631. }
  632. //-- fin mod : quick title edition ---------------------------------------------
  633. $template->assign_vars(array(
  634. 'SEARCH_TITLE' => $l_search_title,
  635. 'SEARCH_MATCHES' => $l_search_matches,
  636. 'SEARCH_WORDS' => $keywords,
  637. 'SEARCHED_QUERY' => $search->search_query,
  638. 'IGNORED_WORDS' => (sizeof($search->common_words)) ? implode(' ', $search->common_words) : '',
  639. 'PAGINATION' => generate_pagination($u_search, $total_match_count, $per_page, $start),
  640. 'PAGE_NUMBER' => on_page($total_match_count, $per_page, $start),
  641. 'TOTAL_MATCHES' => $total_match_count,
  642. 'SEARCH_IN_RESULTS' => ($search_id) ? false : true,
  643.  
  644. 'S_SELECT_SORT_DIR' => $s_sort_dir,
  645. 'S_SELECT_SORT_KEY' => $s_sort_key,
  646. 'S_SELECT_SORT_DAYS' => $s_limit_days,
  647. 'S_SEARCH_ACTION' => $u_search,
  648. 'S_SHOW_TOPICS' => ($show_results == 'posts') ? false : true,
  649.  
  650. 'GOTO_PAGE_IMG' => $user->img('icon_post_target', 'GOTO_PAGE'),
  651. 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
  652. 'REPORTED_IMG' => $user->img('icon_topic_reported', 'TOPIC_REPORTED'),
  653. 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'),
  654. 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
  655.  
  656. 'U_SEARCH_WORDS' => $u_search,
  657. ));
  658.  
  659. if ($sql_where)
  660. {
  661. if ($show_results == 'posts')
  662. {
  663. // @todo Joining this query to the one below?
  664. $sql = 'SELECT zebra_id, friend, foe
  665. FROM ' . ZEBRA_TABLE . '
  666. WHERE user_id = ' . $user->data['user_id'];
  667. $result = $db->sql_query($sql);
  668.  
  669. $zebra = array();
  670. while ($row = $db->sql_fetchrow($result))
  671. {
  672. $zebra[($row['friend']) ? 'friend' : 'foe'][] = $row['zebra_id'];
  673. }
  674. $db->sql_freeresult($result);
  675.  
  676. $sql = 'SELECT p.*, f.forum_id, f.forum_name, t.*, u.username, u.username_clean, u.user_sig, u.user_sig_bbcode_uid, u.user_colour
  677. FROM ' . POSTS_TABLE . ' p
  678. LEFT JOIN ' . TOPICS_TABLE . ' t ON (p.topic_id = t.topic_id)
  679. LEFT JOIN ' . FORUMS_TABLE . ' f ON (p.forum_id = f.forum_id)
  680. LEFT JOIN ' . USERS_TABLE . " u ON (p.poster_id = u.user_id)
  681. WHERE $sql_where";
  682. }
  683. else
  684. {
  685. $sql_from = TOPICS_TABLE . ' t
  686. LEFT JOIN ' . FORUMS_TABLE . ' f ON (f.forum_id = t.forum_id)
  687. ' . (($sort_key == 'a') ? ' LEFT JOIN ' . USERS_TABLE . ' u ON (u.user_id = t.topic_poster) ' : '');
  688. $sql_select = 't.*, f.forum_id, f.forum_name';
  689.  
  690. if ($user->data['is_registered'])
  691. {
  692. if ($config['load_db_track'] && $author_id !== $user->data['user_id'])
  693. {
  694. $sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.user_id = ' . $user->data['user_id'] . '
  695. AND t.topic_id = tp.topic_id)';
  696. $sql_select .= ', tp.topic_posted';
  697. }
  698.  
  699. if ($config['load_db_lastread'])
  700. {
  701. $sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.user_id = ' . $user->data['user_id'] . '
  702. AND t.topic_id = tt.topic_id)
  703. LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . '
  704. AND ft.forum_id = f.forum_id)';
  705. $sql_select .= ', tt.mark_time, ft.mark_time as f_mark_time';
  706. }
  707. }
  708.  
  709. if ($config['load_anon_lastread'] || ($user->data['is_registered'] && !$config['load_db_lastread']))
  710. {
  711. $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : '';
  712. $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
  713. }
  714.  
  715. $sql = "SELECT $sql_select
  716. FROM $sql_from
  717. WHERE $sql_where";
  718. }
  719. $sql .= ' ORDER BY ' . $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
  720. $result = $db->sql_query($sql);
  721. $result_topic_id = 0;
  722.  
  723. $rowset = array();
  724.  
  725. if ($show_results == 'topics')
  726. {
  727. $forums = $rowset = $shadow_topic_list = array();
  728. while ($row = $db->sql_fetchrow($result))
  729. {
  730. $row['forum_id'] = (int) $row['forum_id'];
  731. $row['topic_id'] = (int) $row['topic_id'];
  732.  
  733. if ($row['topic_status'] == ITEM_MOVED)
  734. {
  735. $shadow_topic_list[$row['topic_moved_id']] = $row['topic_id'];
  736. }
  737.  
  738. $rowset[$row['topic_id']] = $row;
  739.  
  740. if (!isset($forums[$row['forum_id']]) && $user->data['is_registered'] && $config['load_db_lastread'])
  741. {
  742. $forums[$row['forum_id']]['mark_time'] = $row['f_mark_time'];
  743. }
  744. $forums[$row['forum_id']]['topic_list'][] = $row['topic_id'];
  745. $forums[$row['forum_id']]['rowset'][$row['topic_id']] = &$rowset[$row['topic_id']];
  746. }
  747. $db->sql_freeresult($result);
  748.  
  749. // If we have some shadow topics, update the rowset to reflect their topic information
  750. if (sizeof($shadow_topic_list))
  751. {
  752. $sql = 'SELECT *
  753. FROM ' . TOPICS_TABLE . '
  754. WHERE ' . $db->sql_in_set('topic_id', array_keys($shadow_topic_list));
  755. $result = $db->sql_query($sql);
  756.  
  757. while ($row = $db->sql_fetchrow($result))
  758. {
  759. $orig_topic_id = $shadow_topic_list[$row['topic_id']];
  760.  
  761. // We want to retain some values
  762. $row = array_merge($row, array(
  763. 'topic_moved_id' => $rowset[$orig_topic_id]['topic_moved_id'],
  764. 'topic_status' => $rowset[$orig_topic_id]['topic_status'],
  765. 'forum_name' => $rowset[$orig_topic_id]['forum_name'])
  766. );
  767.  
  768. $rowset[$orig_topic_id] = $row;
  769. }
  770. $db->sql_freeresult($result);
  771. }
  772. unset($shadow_topic_list);
  773.  
  774. foreach ($forums as $forum_id => $forum)
  775. {
  776. if ($user->data['is_registered'] && $config['load_db_lastread'])
  777. {
  778. $topic_tracking_info[$forum_id] = get_topic_tracking($forum_id, $forum['topic_list'], $forum['rowset'], array($forum_id => $forum['mark_time']), ($forum_id) ? false : $forum['topic_list']);
  779. }
  780. else if ($config['load_anon_lastread'] || $user->data['is_registered'])
  781. {
  782. $topic_tracking_info[$forum_id] = get_complete_topic_tracking($forum_id, $forum['topic_list'], ($forum_id) ? false : $forum['topic_list']);
  783.  
  784. if (!$user->data['is_registered'])
  785. {
  786. $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
  787. }
  788. }
  789. }
  790. unset($forums);
  791. }
  792. else
  793. {
  794. $bbcode_bitfield = $text_only_message = '';
  795. $attach_list = array();
  796.  
  797. while ($row = $db->sql_fetchrow($result))
  798. {
  799. // We pre-process some variables here for later usage
  800. $row['post_text'] = censor_text($row['post_text']);
  801.  
  802. $text_only_message = $row['post_text'];
  803. // make list items visible as such
  804. if ($row['bbcode_uid'])
  805. {
  806. $text_only_message = str_replace('[*:' . $row['bbcode_uid'] . ']', '&sdot;&nbsp;', $text_only_message);
  807. // no BBCode in text only message
  808. strip_bbcode($text_only_message, $row['bbcode_uid']);
  809. }
  810.  
  811. if ($return_chars == -1 || utf8_strlen($text_only_message) < ($return_chars + 3))
  812. {
  813. $row['display_text_only'] = false;
  814. $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
  815.  
  816. // Does this post have an attachment? If so, add it to the list
  817. if ($row['post_attachment'] && $config['allow_attachments'])
  818. {
  819. $attach_list[$row['forum_id']][] = $row['post_id'];
  820. }
  821. }
  822. else
  823. {
  824. $row['post_text'] = $text_only_message;
  825. $row['display_text_only'] = true;
  826. }
  827.  
  828. $rowset[] = $row;
  829. }
  830. $db->sql_freeresult($result);
  831.  
  832. unset($text_only_message);
  833.  
  834. // Instantiate BBCode if needed
  835. if ($bbcode_bitfield !== '')
  836. {
  837. include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
  838. $bbcode = new bbcode(base64_encode($bbcode_bitfield));
  839. }
  840.  
  841. // Pull attachment data
  842. if (sizeof($attach_list))
  843. {
  844. $use_attach_list = $attach_list;
  845. $attach_list = array();
  846.  
  847. foreach ($use_attach_list as $forum_id => $_list)
  848. {
  849. if ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id))
  850. {
  851. $attach_list = array_merge($attach_list, $_list);
  852. }
  853. }
  854. }
  855.  
  856. if (sizeof($attach_list))
  857. {
  858. $sql = 'SELECT *
  859. FROM ' . ATTACHMENTS_TABLE . '
  860. WHERE ' . $db->sql_in_set('post_msg_id', $attach_list) . '
  861. AND in_message = 0
  862. ORDER BY filetime DESC, post_msg_id ASC';
  863. $result = $db->sql_query($sql);
  864.  
  865. while ($row = $db->sql_fetchrow($result))
  866. {
  867. $attachments[$row['post_msg_id']][] = $row;
  868. }
  869. $db->sql_freeresult($result);
  870. }
  871. }
  872.  
  873. if ($hilit)
  874. {
  875. // Remove bad highlights
  876. $hilit_array = array_filter(explode('|', $hilit), 'strlen');
  877. foreach ($hilit_array as $key => $value)
  878. {
  879. $hilit_array[$key] = str_replace('\*', '\w*?', preg_quote($value, '#'));
  880. $hilit_array[$key] = preg_replace('#(^|\s)\\\\w\*\?(\s|$)#', '$1\w+?$2', $hilit_array[$key]);
  881. }
  882. $hilit = implode('|', $hilit_array);
  883. }
  884. //-- mod : quick title edition -------------------------------------------------
  885. //-- add
  886. $topic_list = array();
  887. foreach ( $rowset as $row )
  888. {
  889. $topic_list[] = (int) $row['topic_id'];
  890. }
  891. $qte->get_users_by_topic_id($topic_list);
  892. //-- fin mod : quick title edition ---------------------------------------------
  893. foreach ($rowset as $row)
  894. {
  895. $forum_id = $row['forum_id'];
  896. $result_topic_id = $row['topic_id'];
  897. $topic_title = censor_text($row['topic_title']);
  898.  
  899. // we need to select a forum id for this global topic
  900. if (!$forum_id)
  901. {
  902. if (!isset($g_forum_id))
  903. {
  904. // Get a list of forums the user cannot read
  905. $forum_ary = array_unique(array_keys($auth->acl_getf('!f_read', true)));
  906.  
  907. // Determine first forum the user is able to read (must not be a category)
  908. $sql = 'SELECT forum_id
  909. FROM ' . FORUMS_TABLE . '
  910. WHERE forum_type = ' . FORUM_POST;
  911.  
  912. if (sizeof($forum_ary))
  913. {
  914. $sql .= ' AND ' . $db->sql_in_set('forum_id', $forum_ary, true);
  915. }
  916.  
  917. $result = $db->sql_query_limit($sql, 1);
  918. $g_forum_id = (int) $db->sql_fetchfield('forum_id');
  919. }
  920. $u_forum_id = $g_forum_id;
  921. }
  922. else
  923. {
  924. $u_forum_id = $forum_id;
  925. }
  926.  
  927. $view_topic_url_params = "f=$u_forum_id&amp;t=$result_topic_id" . (($u_hilit) ? "&amp;hilit=$u_hilit" : '');
  928. $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params);
  929.  
  930. $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
  931.  
  932. if ($show_results == 'topics')
  933. {
  934. if ($config['load_db_track'] && $author_id === $user->data['user_id'])
  935. {
  936. $row['topic_posted'] = 1;
  937. }
  938.  
  939. $folder_img = $folder_alt = $topic_type = '';
  940. topic_status($row, $replies, (isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']]) ? true : false, $folder_img, $folder_alt, $topic_type);
  941.  
  942. $unread_topic = (isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']]) ? true : false;
  943.  
  944. $topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $forum_id)) ? true : false;
  945. $posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $forum_id)) ? true : false;
  946. $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&amp;t=$result_topic_id", true, $user->session_id) : '';
  947.  
  948. $row['topic_title'] = preg_replace('#(?!<.*)(?<!\w)(' . $hilit . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">$1</span>', $row['topic_title']);
  949.  
  950. $tpl_ary = array(
  951. 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  952. 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  953. 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  954. 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
  955. 'LAST_POST_SUBJECT' => $row['topic_last_post_subject'],
  956. 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
  957. 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
  958. 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  959. 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  960. 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  961.  
  962. 'PAGINATION' => topic_generate_pagination($replies, $view_topic_url),
  963. 'TOPIC_TYPE' => $topic_type,
  964.  
  965. 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
  966. 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'),
  967. 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt],
  968. 'TOPIC_FOLDER_IMG_WIDTH'=> $user->img($folder_img, '', false, '', 'width'),
  969. 'TOPIC_FOLDER_IMG_HEIGHT' => $user->img($folder_img, '', false, '', 'height'),
  970.  
  971. 'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
  972. 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
  973. 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
  974. 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
  975. 'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
  976.  
  977. 'S_TOPIC_GLOBAL' => (!$forum_id) ? true : false,
  978. 'S_TOPIC_TYPE' => $row['topic_type'],
  979. 'S_USER_POSTED' => (!empty($row['topic_posted'])) ? true : false,
  980. 'S_UNREAD_TOPIC' => $unread_topic,
  981.  
  982. 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $forum_id)) ? true : false,
  983. 'S_TOPIC_UNAPPROVED' => $topic_unapproved,
  984. 'S_POSTS_UNAPPROVED' => $posts_unapproved,
  985.  
  986. 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
  987. 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  988. 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  989. 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;view=unread') . '#unread',
  990. 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=reports&amp;t=' . $result_topic_id, true, $user->session_id),
  991. 'U_MCP_QUEUE' => $u_mcp_queue,
  992. );
  993. }
  994. else
  995. {
  996. if ((isset($zebra['foe']) && in_array($row['poster_id'], $zebra['foe'])) && (!$view || $view != 'show' || $post_id != $row['post_id']))
  997. {
  998. $template->assign_block_vars('searchresults', array(
  999. 'S_IGNORE_POST' => true,
  1000.  
  1001. 'L_IGNORE_POST' => sprintf($user->lang['POST_BY_FOE'], $row['username'], "<a href=\"$u_search&amp;start=$start&amp;p=" . $row['post_id'] . '&amp;view=show#p' . $row['post_id'] . '">', '</a>'))
  1002. );
  1003.  
  1004. continue;
  1005. }
  1006.  
  1007. // Replace naughty words such as farty pants
  1008. $row['post_subject'] = censor_text($row['post_subject']);
  1009.  
  1010. if ($row['display_text_only'])
  1011. {
  1012. // now find context for the searched words
  1013. $row['post_text'] = get_context($row['post_text'], array_filter(explode('|', $hilit), 'strlen'), $return_chars);
  1014. $row['post_text'] = bbcode_nl2br($row['post_text']);
  1015. }
  1016. else
  1017. {
  1018. // Second parse bbcode here
  1019. if ($row['bbcode_bitfield'])
  1020. {
  1021. $bbcode->bbcode_second_pass($row['post_text'], $row['bbcode_uid'], $row['bbcode_bitfield']);
  1022. }
  1023.  
  1024. $row['post_text'] = bbcode_nl2br($row['post_text']);
  1025. $row['post_text'] = smiley_text($row['post_text']);
  1026.  
  1027. if (!empty($attachments[$row['post_id']]))
  1028. {
  1029. parse_attachments($forum_id, $row['post_text'], $attachments[$row['post_id']], $update_count);
  1030.  
  1031. // we only display inline attachments
  1032. unset($attachments[$row['post_id']]);
  1033. }
  1034. }
  1035.  
  1036. if ($hilit)
  1037. {
  1038. // post highlighting
  1039. $row['post_text'] = preg_replace('#(?!<.*)(?<!\w)(' . $hilit . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">$1</span>', $row['post_text']);
  1040. $row['post_subject'] = preg_replace('#(?!<.*)(?<!\w)(' . $hilit . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">$1</span>', $row['post_subject']);
  1041. }
  1042.  
  1043. $tpl_ary = array(
  1044. 'POST_AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
  1045. 'POST_AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
  1046. 'POST_AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
  1047. 'U_POST_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
  1048.  
  1049. 'POST_SUBJECT' => $row['post_subject'],
  1050. 'POST_DATE' => (!empty($row['post_time'])) ? $user->format_date($row['post_time']) : '',
  1051. 'MESSAGE' => $row['post_text']
  1052. );
  1053. }
  1054. //-- mod : quick title edition -------------------------------------------------
  1055. //-- add
  1056. if ( !empty($row['topic_attr_id']) )
  1057. {
  1058. $tpl_ary += array(
  1059. 'S_TOPIC_ATTR' => isset($row['post_id']) ? (($row['topic_first_post_id'] == $row['post_id']) ? true : false) : true,
  1060. 'TOPIC_ATTRIBUTE' => $qte->attr_display($row['topic_attr_id'], $row['topic_attr_user'], $row['topic_attr_time']),
  1061. );
  1062. }
  1063. //-- fin mod : quick title edition ---------------------------------------------
  1064. $template->assign_block_vars('searchresults', array_merge($tpl_ary, array(
  1065. 'FORUM_ID' => $forum_id,
  1066. 'TOPIC_ID' => $result_topic_id,
  1067. 'POST_ID' => ($show_results == 'posts') ? $row['post_id'] : false,
  1068.  
  1069. 'FORUM_TITLE' => $row['forum_name'],
  1070. 'TOPIC_TITLE' => $topic_title,
  1071. 'TOPIC_REPLIES' => $replies,
  1072. 'TOPIC_VIEWS' => $row['topic_views'],
  1073.  
  1074. 'U_VIEW_TOPIC' => $view_topic_url,
  1075. 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
  1076. 'U_VIEW_POST' => (!empty($row['post_id'])) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=" . $row['topic_id'] . '&amp;p=' . $row['post_id'] . (($u_hilit) ? '&amp;hilit=' . $u_hilit : '')) . '#p' . $row['post_id'] : '')
  1077. ));
  1078. }
  1079.  
  1080. if ($topic_id && ($topic_id == $result_topic_id))
  1081. {
  1082. $template->assign_vars(array(
  1083. 'SEARCH_TOPIC' => $topic_title,
  1084. 'U_SEARCH_TOPIC' => $view_topic_url
  1085. ));
  1086. }
  1087. }
  1088. unset($rowset);
  1089.  
  1090. page_header(($l_search_title) ? $l_search_title : $user->lang['SEARCH']);
  1091.  
  1092. $template->set_filenames(array(
  1093. 'body' => 'search_results.html')
  1094. );
  1095. make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
  1096.  
  1097. page_footer();
  1098. }
  1099.  
  1100. // Search forum
  1101. $s_forums = '';
  1102. $sql = 'SELECT f.forum_id, f.forum_name, f.parent_id, f.forum_type, f.left_id, f.right_id, f.forum_password, f.enable_indexing, fa.user_id
  1103. FROM ' . FORUMS_TABLE . ' f
  1104. LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa ON (fa.forum_id = f.forum_id
  1105. AND fa.session_id = '" . $db->sql_escape($user->session_id) . "')
  1106. ORDER BY f.left_id ASC";
  1107. $result = $db->sql_query($sql);
  1108.  
  1109. $right = $cat_right = $padding_inc = 0;
  1110. $padding = $forum_list = $holding = '';
  1111. $pad_store = array('0' => '');
  1112.  
  1113. while ($row = $db->sql_fetchrow($result))
  1114. {
  1115. if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
  1116. {
  1117. // Non-postable forum with no subforums, don't display
  1118. continue;
  1119. }
  1120.  
  1121. if ($row['forum_type'] == FORUM_POST && ($row['left_id'] + 1 == $row['right_id']) && !$row['enable_indexing'])
  1122. {
  1123. // Postable forum with no subforums and indexing disabled, don't display
  1124. continue;
  1125. }
  1126.  
  1127. if ($row['forum_type'] == FORUM_LINK || ($row['forum_password'] && !$row['user_id']))
  1128. {
  1129. // if this forum is a link or password protected (user has not entered the password yet) then skip to the next branch
  1130. continue;
  1131. }
  1132.  
  1133. if ($row['left_id'] < $right)
  1134. {
  1135. $padding .= '&nbsp; &nbsp;';
  1136. $pad_store[$row['parent_id']] = $padding;
  1137. }
  1138. else if ($row['left_id'] > $right + 1)
  1139. {
  1140. if (isset($pad_store[$row['parent_id']]))
  1141. {
  1142. $padding = $pad_store[$row['parent_id']];
  1143. }
  1144. else
  1145. {
  1146. continue;
  1147. }
  1148. }
  1149.  
  1150. $right = $row['right_id'];
  1151.  
  1152. if ($auth->acl_gets('!f_search', '!f_list', $row['forum_id']))
  1153. {
  1154. // if the user does not have permissions to search or see this forum skip only this forum/category
  1155. continue;
  1156. }
  1157.  
  1158. $selected = (in_array($row['forum_id'], $search_forum)) ? ' selected="selected"' : '';
  1159.  
  1160. if ($row['left_id'] > $cat_right)
  1161. {
  1162. // make sure we don't forget anything
  1163. $s_forums .= $holding;
  1164. $holding = '';
  1165. }
  1166.  
  1167. if ($row['right_id'] - $row['left_id'] > 1)
  1168. {
  1169. $cat_right = max($cat_right, $row['right_id']);
  1170.  
  1171. $holding .= '<option value="' . $row['forum_id'] . '"' . $selected . '>' . $padding . $row['forum_name'] . '</option>';
  1172. }
  1173. else
  1174. {
  1175. $s_forums .= $holding . '<option value="' . $row['forum_id'] . '"' . $selected . '>' . $padding . $row['forum_name'] . '</option>';
  1176. $holding = '';
  1177. }
  1178. }
  1179.  
  1180. if ($holding)
  1181. {
  1182. $s_forums .= $holding;
  1183. }
  1184.  
  1185. $db->sql_freeresult($result);
  1186. unset($pad_store);
  1187.  
  1188. if (!$s_forums)
  1189. {
  1190. trigger_error('NO_SEARCH');
  1191. }
  1192.  
  1193. // Number of chars returned
  1194. $s_characters = '<option value="-1">' . $user->lang['ALL_AVAILABLE'] . '</option>';
  1195. $s_characters .= '<option value="0">0</option>';
  1196. $s_characters .= '<option value="25">25</option>';
  1197. $s_characters .= '<option value="50">50</option>';
  1198.  
  1199. for ($i = 100; $i <= 1000 ; $i += 100)
  1200. {
  1201. $selected = ($i == 300) ? ' selected="selected"' : '';
  1202. $s_characters .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>';
  1203. }
  1204.  
  1205. $s_hidden_fields = array('t' => $topic_id);
  1206.  
  1207. if ($_SID)
  1208. {
  1209. $s_hidden_fields['sid'] = $_SID;
  1210. }
  1211.  
  1212. if (!empty($_EXTRA_URL))
  1213. {
  1214. foreach ($_EXTRA_URL as $url_param)
  1215. {
  1216. $url_param = explode('=', $url_param, 2);
  1217. $s_hidden_fields[$url_param[0]] = $url_param[1];
  1218. }
  1219. }
  1220.  
  1221. $template->assign_vars(array(
  1222. 'S_SEARCH_ACTION' => append_sid("{$phpbb_root_path}search.$phpEx", false, true, 0), // We force no ?sid= appending by using 0
  1223. 'S_HIDDEN_FIELDS' => build_hidden_fields($s_hidden_fields),
  1224. 'S_CHARACTER_OPTIONS' => $s_characters,
  1225. 'S_FORUM_OPTIONS' => $s_forums,
  1226. 'S_SELECT_SORT_DIR' => $s_sort_dir,
  1227. 'S_SELECT_SORT_KEY' => $s_sort_key,
  1228. 'S_SELECT_SORT_DAYS' => $s_limit_days,
  1229. 'S_IN_SEARCH' => true,
  1230. ));
  1231. //-- mod : quick title edition -------------------------------------------------
  1232. //-- add
  1233. $qte->attr_search();
  1234. //-- fin mod : quick title edition ---------------------------------------------
  1235. // only show recent searches to search administrators
  1236. if ($auth->acl_get('a_search'))
  1237. {
  1238. // Handle large objects differently for Oracle and MSSQL
  1239. switch ($db->sql_layer)
  1240. {
  1241. case 'oracle':
  1242. $sql = 'SELECT search_time, search_keywords
  1243. FROM ' . SEARCH_RESULTS_TABLE . '
  1244. WHERE dbms_lob.getlength(search_keywords) > 0
  1245. ORDER BY search_time DESC';
  1246. break;
  1247.  
  1248. case 'mssql':
  1249. case 'mssql_odbc':
  1250. case 'mssqlnative':
  1251. $sql = 'SELECT search_time, search_keywords
  1252. FROM ' . SEARCH_RESULTS_TABLE . '
  1253. WHERE DATALENGTH(search_keywords) > 0
  1254. ORDER BY search_time DESC';
  1255. break;
  1256.  
  1257. default:
  1258. $sql = 'SELECT search_time, search_keywords
  1259. FROM ' . SEARCH_RESULTS_TABLE . '
  1260. WHERE search_keywords <> \'\'
  1261. ORDER BY search_time DESC';
  1262. break;
  1263. }
  1264. $result = $db->sql_query_limit($sql, 5);
  1265.  
  1266. while ($row = $db->sql_fetchrow($result))
  1267. {
  1268. $keywords = $row['search_keywords'];
  1269.  
  1270. $template->assign_block_vars('recentsearch', array(
  1271. 'KEYWORDS' => $keywords,
  1272. 'TIME' => $user->format_date($row['search_time']),
  1273.  
  1274. 'U_KEYWORDS' => append_sid("{$phpbb_root_path}search.$phpEx", 'keywords=' . urlencode(htmlspecialchars_decode($keywords)))
  1275. ));
  1276. }
  1277. $db->sql_freeresult($result);
  1278. }
  1279.  
  1280. // Output the basic page
  1281. page_header($user->lang['SEARCH']);
  1282.  
  1283. $template->set_filenames(array(
  1284. 'body' => 'search_body.html')
  1285. );
  1286. make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
  1287.  
  1288. page_footer();
  1289.  
  1290. ?>
Add Comment
Please, Sign In to add comment