PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/search.php

https://bitbucket.org/gencer/punbb
PHP | 779 lines | 556 code | 155 blank | 68 comment | 165 complexity | 6fe9a9ba9c9f68da89acd951da050e8f MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * Allows users to search the forum based on various criteria.
  4. *
  5. * @copyright (C) 2008-2012 PunBB, partially based on code (C) 2008-2009 FluxBB.org
  6. * @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
  7. * @package PunBB
  8. */
  9. if (!defined('FORUM_ROOT'))
  10. define('FORUM_ROOT', './');
  11. require FORUM_ROOT.'include/common.php';
  12. ($hook = get_hook('se_start')) ? eval($hook) : null;
  13. // Load the search.php language file
  14. require FORUM_ROOT.'lang/'.$forum_user['language'].'/search.php';
  15. // Load the necessary search functions
  16. require FORUM_ROOT.'include/search_functions.php';
  17. if ($forum_user['g_read_board'] == '0')
  18. message($lang_common['No view']);
  19. else if ($forum_user['g_search'] == '0')
  20. message($lang_search['No search permission']);
  21. // If a search_id was supplied
  22. if (isset($_GET['search_id']))
  23. {
  24. $search_id = intval($_GET['search_id']);
  25. if ($search_id < 1)
  26. message($lang_common['Bad request']);
  27. // Generate the query to grab the cached results
  28. $query = generate_cached_search_query($search_id, $show_as);
  29. $url_type = $forum_url['search_results'];
  30. }
  31. // We aren't just grabbing a cached search
  32. else if (isset($_GET['action']))
  33. {
  34. $action = $_GET['action'];
  35. // Validate action
  36. if (!validate_search_action($action))
  37. message($lang_common['Bad request']);
  38. // If it's a regular search (keywords and/or author)
  39. if ($action == 'search')
  40. {
  41. $keywords = (isset($_GET['keywords']) && is_string($_GET['keywords'])) ? forum_trim($_GET['keywords']) : null;
  42. $author = (isset($_GET['author']) && is_string($_GET['author'])) ? forum_trim($_GET['author']) : null;
  43. $sort_dir = (isset($_GET['sort_dir'])) ? (($_GET['sort_dir'] == 'DESC') ? 'DESC' : 'ASC') : 'DESC';
  44. $show_as = (isset($_GET['show_as'])) ? $_GET['show_as'] : 'posts';
  45. $sort_by = (isset($_GET['sort_by'])) ? intval($_GET['sort_by']) : null;
  46. $search_in = (!isset($_GET['search_in']) || $_GET['search_in'] == 'all') ? 0 : (($_GET['search_in'] == 'message') ? 1 : -1);
  47. $forum = (isset($_GET['forum']) && is_array($_GET['forum'])) ? array_map('intval', $_GET['forum']) : array(-1);
  48. if (preg_match('#^[\*%]+$#', $keywords))
  49. $keywords = '';
  50. if (preg_match('#^[\*%]+$#', $author))
  51. $author = '';
  52. if (!$keywords && !$author)
  53. message($lang_search['No terms']);
  54. // Create a cache of the results and redirect the user to the results
  55. create_search_cache($keywords, $author, $search_in, $forum, $show_as, $sort_by, $sort_dir);
  56. }
  57. // Its not a regular search, so its a quicksearch
  58. else
  59. {
  60. $value = null;
  61. // Get any additional variables for quicksearches
  62. if ($action == 'show_user_posts' || $action == 'show_user_topics' || $action == 'show_subscriptions' || $action == 'show_forum_subscriptions')
  63. {
  64. $value = isset($_GET['user_id']) ? intval($_GET['user_id']) : 0;
  65. if ($value < 2)
  66. message($lang_common['Bad request']);
  67. }
  68. else if ($action == 'show_recent')
  69. $value = (isset($_GET['value'])) ? intval($_GET['value']) : 86400;
  70. else if ($action == 'show_new')
  71. $value = (isset($_GET['forum'])) ? intval($_GET['forum']) : -1;
  72. ($hook = get_hook('se_additional_quicksearch_variables')) ? eval($hook) : null;
  73. $search_id = '';
  74. // Show as
  75. if ($action == 'show_forum_subscriptions')
  76. $show_as = 'forums';
  77. else
  78. $show_as = 'topics';
  79. // Generate the query for the search
  80. $query = generate_action_search_query($action, $value, $search_id, $url_type, $show_as);
  81. }
  82. }
  83. ($hook = get_hook('se_pre_search_query')) ? eval($hook) : null;
  84. // We have the query to get the results, lets get them!
  85. if (isset($query))
  86. {
  87. // No results?
  88. if (!$query)
  89. no_search_results();
  90. // Work out the settings for pagination
  91. if ($show_as == 'posts')
  92. $forum_page['per_page'] = $forum_user['disp_posts'];
  93. else if ($show_as == 'topics')
  94. $forum_page['per_page'] = $forum_user['disp_topics'];
  95. else if ($show_as == 'forums')
  96. $forum_page['per_page'] = 0; // Show all
  97. // We now have a query that will give us our results in $query, lets get the data!
  98. $num_hits = get_search_results($query, $search_set);
  99. ($hook = get_hook('se_post_results_fetched')) ? eval($hook) : null;
  100. // No search results?
  101. if ($num_hits == 0)
  102. no_search_results($action);
  103. //
  104. // Output the search results
  105. //
  106. // Setup breadcrumbs and results header and footer
  107. $forum_page['crumbs'][] = array($forum_config['o_board_title'], forum_link($forum_url['index']));
  108. $action = (isset($action)) ? $action : null;
  109. generate_search_crumbs($action);
  110. // Generate paging links
  111. if ($show_as == 'posts' || $show_as == 'topics')
  112. $forum_page['page_post']['paging'] = '<p class="paging"><span class="pages">'.$lang_common['Pages'].'</span> '.paginate($forum_page['num_pages'], $forum_page['page'], $url_type, $lang_common['Paging separator'], $search_id).'</p>';
  113. // Get topic/forum tracking data
  114. if (!$forum_user['is_guest'])
  115. $tracked_topics = get_tracked_topics();
  116. // Navigation links for header and page numbering for title/meta description
  117. if ($show_as == 'posts' || $show_as == 'topics')
  118. {
  119. if ($forum_page['page'] < $forum_page['num_pages'])
  120. {
  121. $forum_page['nav']['last'] = '<link rel="last" href="'.forum_sublink($url_type, $forum_url['page'], $forum_page['num_pages'], $search_id).'" title="'.$lang_common['Page'].' '.$forum_page['num_pages'].'" />';
  122. $forum_page['nav']['next'] = '<link rel="next" href="'.forum_sublink($url_type, $forum_url['page'], ($forum_page['page'] + 1), $search_id).'" title="'.$lang_common['Page'].' '.($forum_page['page'] + 1).'" />';
  123. }
  124. if ($forum_page['page'] > 1)
  125. {
  126. $forum_page['nav']['prev'] = '<link rel="prev" href="'.forum_sublink($url_type, $forum_url['page'], ($forum_page['page'] - 1), $search_id).'" title="'.$lang_common['Page'].' '.($forum_page['page'] - 1).'" />';
  127. $forum_page['nav']['first'] = '<link rel="first" href="'.forum_link($url_type, $search_id).'" title="'.$lang_common['Page'].' 1" />';
  128. }
  129. // Setup main heading
  130. if ($forum_page['num_pages'] > 1)
  131. $forum_page['main_head_pages'] = sprintf($lang_common['Page info'], $forum_page['page'], $forum_page['num_pages']);
  132. }
  133. // Setup main options header
  134. $forum_page['main_title'] = $lang_search['Search options'];
  135. ($hook = get_hook('se_results_pre_header_load')) ? eval($hook) : null;
  136. // Define page type
  137. if ($show_as == 'posts')
  138. define('FORUM_PAGE', 'searchposts');
  139. else if ($show_as == 'topics')
  140. define('FORUM_PAGE', 'searchtopics');
  141. else
  142. define('FORUM_PAGE', 'searchforums');
  143. require FORUM_ROOT.'header.php';
  144. // START SUBST - <!-- forum_main -->
  145. ob_start();
  146. ($hook = get_hook('se_results_output_start')) ? eval($hook) : null;
  147. if ($show_as == 'topics')
  148. {
  149. // Load the forum.php language file
  150. require FORUM_ROOT.'lang/'.$forum_user['language'].'/forum.php';
  151. $forum_page['item_header'] = array();
  152. $forum_page['item_header']['subject']['title'] = '<strong class="subject-title">'.$lang_forum['Topics'].'</strong>';
  153. $forum_page['item_header']['info']['forum'] = '<strong class="info-forum">'.$lang_forum['Forum'].'</strong>';
  154. $forum_page['item_header']['info']['replies'] = '<strong class="info-replies">'.$lang_forum['replies'].'</strong>';
  155. $forum_page['item_header']['info']['lastpost'] = '<strong class="info-lastpost">'.$lang_forum['last post'].'</strong>';
  156. ($hook = get_hook('se_results_topics_pre_item_header_output')) ? eval($hook) : null;
  157. ?>
  158. <div class="main-head">
  159. <?php
  160. if (!empty($forum_page['main_head_options']))
  161. echo "\n\t\t".'<p class="options">'.implode(' ', $forum_page['main_head_options']).'</p>';
  162. ?>
  163. <h2 class="hn"><span><?php echo $forum_page['items_info'] ?></span></h2>
  164. </div>
  165. <div class="main-subhead">
  166. <p class="item-summary forum-noview"><span><?php printf($lang_forum['Search subtitle'], implode(' ', $forum_page['item_header']['subject']), implode(', ', $forum_page['item_header']['info'])) ?></span></p>
  167. </div>
  168. <div class="main-content main-forum forum-forums">
  169. <?php
  170. }
  171. else if ($show_as == 'posts')
  172. {
  173. // Load the topic.php language file
  174. require FORUM_ROOT.'lang/'.$forum_user['language'].'/topic.php';
  175. // Load parser
  176. if (!defined('FORUM_PARSER_LOADED'))
  177. require FORUM_ROOT.'include/parser.php';
  178. ?>
  179. <div class="main-head">
  180. <?php
  181. if (!empty($forum_page['main_head_options']))
  182. echo "\n\t\t".'<p class="options">'.implode(' ', $forum_page['main_head_options']).'</p>';
  183. ?>
  184. <h2 class="hn"><span><?php echo $forum_page['items_info'] ?></span></h2>
  185. </div>
  186. <div class="main-content main-topic">
  187. <?php
  188. }
  189. else if ($show_as == 'forums')
  190. {
  191. // Load the forum.php language file
  192. require FORUM_ROOT.'lang/'.$forum_user['language'].'/index.php';
  193. $forum_page['cur_category'] = $forum_page['cat_count'] = $forum_page['item_count'] = 0;
  194. }
  195. $forum_page['item_count'] = 0;
  196. // Finally, lets loop through the results and output them
  197. foreach ($search_set as $cur_set)
  198. {
  199. ($hook = get_hook('se_results_loop_start')) ? eval($hook) : null;
  200. ++$forum_page['item_count'];
  201. if ($forum_config['o_censoring'] == '1')
  202. $cur_set['subject'] = censor_words($cur_set['subject']);
  203. if ($show_as == 'posts')
  204. {
  205. // Generate the result heading
  206. $forum_page['post_ident'] = array();
  207. $forum_page['post_ident']['num'] = '<span class="post-num">'.forum_number_format($forum_page['start_from'] + $forum_page['item_count']).'</span>';
  208. $forum_page['post_ident']['byline'] = '<span class="post-byline">'.sprintf((($cur_set['pid'] == $cur_set['first_post_id']) ? $lang_topic['Topic byline'] : $lang_topic['Reply byline']), '<strong>'.forum_htmlencode($cur_set['pposter']).'</strong>').'</span>';
  209. $forum_page['post_ident']['link'] = '<span class="post-link"><a class="permalink" rel="bookmark" title="'.$lang_topic['Permalink post'].'" href="'.forum_link($forum_url['post'], $cur_set['pid']).'">'.format_time($cur_set['pposted']).'</a></span>';
  210. ($hook = get_hook('se_results_posts_row_pre_item_ident_merge')) ? eval($hook) : null;
  211. // Generate the topic title
  212. $forum_page['item_subject'] = '<a class="permalink" rel="bookmark" title="'.$lang_topic['Permalink topic'].'" href="'.forum_link($forum_url['topic'], array($cur_set['tid'], sef_friendly($cur_set['subject']))).'">'.sprintf((($cur_set['pid'] == $cur_set['first_post_id']) ? $lang_topic['Topic title'] : $lang_topic['Reply title']), forum_htmlencode($cur_set['subject'])).'</a> <small>'.sprintf($lang_topic['Search replies'], forum_number_format($cur_set['num_replies']), '<a href="'.forum_link($forum_url['forum'], array($cur_set['forum_id'], sef_friendly($cur_set['forum_name']))).'">'.forum_htmlencode($cur_set['forum_name']).'</a>').'</small>';
  213. // Generate author identification
  214. $forum_page['user_ident'] = ($cur_set['poster_id'] > 1 && $forum_user['g_view_users'] == '1') ? '<strong class="username"><a title="'.sprintf($lang_search['Go to profile'], forum_htmlencode($cur_set['pposter'])).'" href="'.forum_link($forum_url['user'], $cur_set['poster_id']).'">'.forum_htmlencode($cur_set['pposter']).'</a></strong>' : '<strong class="username">'.forum_htmlencode($cur_set['pposter']).'</strong>';
  215. // Generate the post actions links
  216. $forum_page['post_actions'] = array();
  217. $forum_page['post_actions']['forum'] = '<span><a href="'.forum_link($forum_url['forum'], array($cur_set['forum_id'], sef_friendly($cur_set['forum_name']))).'">'.$lang_search['Go to forum'].'<span>: '.forum_htmlencode($cur_set['forum_name']).'</span></a></span>';
  218. if ($cur_set['pid'] != $cur_set['first_post_id'])
  219. $forum_page['post_actions']['topic'] = '<span><a class="permalink" rel="bookmark" title="'.$lang_topic['Permalink topic'].'" href="'.forum_link($forum_url['topic'], array($cur_set['tid'], sef_friendly($cur_set['subject']))).'">'.$lang_search['Go to topic'].'<span>: '.forum_htmlencode($cur_set['subject']).'</span></a></span>';
  220. $forum_page['post_actions']['post'] = '<span><a class="permalink" rel="bookmark" title="'.$lang_topic['Permalink post'].'" href="'.forum_link($forum_url['post'], $cur_set['pid']).'">'.$lang_search['Go to post'].'<span> '.forum_number_format($forum_page['start_from'] + $forum_page['item_count']).'</span></a></span>';
  221. $forum_page['message'] = parse_message($cur_set['message'], $cur_set['hide_smilies']);
  222. // Give the post some class
  223. $forum_page['item_status'] = array(
  224. 'post',
  225. (($forum_page['item_count'] % 2 != 0) ? 'odd' : 'even' )
  226. );
  227. if ($forum_page['item_count'] == 1)
  228. $forum_page['item_status']['firstpost'] = 'firstpost';
  229. if (($forum_page['start_from'] + $forum_page['item_count']) == $forum_page['finish_at'])
  230. $forum_page['item_status']['lastpost'] = 'lastpost';
  231. if ($cur_set['pid'] == $cur_set['first_post_id'])
  232. $forum_page['item_status']['topicpost'] = 'topicpost';
  233. ($hook = get_hook('se_results_posts_row_pre_display')) ? eval($hook) : null;
  234. ?>
  235. <div class="<?php echo implode(' ', $forum_page['item_status']) ?> resultpost">
  236. <div class="posthead">
  237. <h3 class="hn post-ident"><?php echo implode(' ', $forum_page['post_ident']) ?></h3>
  238. <h4 class="hn post-title"><span><?php echo $forum_page['item_subject'] ?></span></h4>
  239. </div>
  240. <div class="postbody">
  241. <div class="post-entry">
  242. <div class="entry-content">
  243. <?php echo $forum_page['message'] ?>
  244. </div>
  245. <?php ($hook = get_hook('se_results_posts_row_new_post_entry_data')) ? eval($hook) : null; ?>
  246. </div>
  247. </div>
  248. <div class="postfoot">
  249. <div class="post-options">
  250. <p class="post-actions"><?php echo implode(' ', $forum_page['post_actions']) ?></p>
  251. </div>
  252. </div>
  253. </div>
  254. <?php
  255. }
  256. else if ($show_as == 'topics')
  257. {
  258. // Start from scratch
  259. $forum_page['item_subject'] = $forum_page['item_body'] = $forum_page['item_status'] = $forum_page['item_nav'] = $forum_page['item_title'] = $forum_page['item_title_status'] = array();
  260. // Assemble the Topic heading
  261. // Should we display the dot or not? :)
  262. if (!$forum_user['is_guest'] && $forum_config['o_show_dot'] == '1' && $cur_set['has_posted'] == $forum_user['id'])
  263. {
  264. $forum_page['item_title']['posted'] = '<span class="posted-mark">'.$lang_forum['You posted indicator'].'</span>';
  265. $forum_page['item_status']['posted'] = 'posted';
  266. }
  267. if ($cur_set['sticky'] == '1')
  268. {
  269. $forum_page['item_title_status']['sticky'] = '<em class="sticky">'.$lang_forum['Sticky'].'</em>';
  270. $forum_page['item_status']['sticky'] = 'sticky';
  271. }
  272. if ($cur_set['closed'] != '0')
  273. {
  274. $forum_page['item_title_status']['closed'] = '<em class="closed">'.$lang_forum['Closed'].'</em>';
  275. $forum_page['item_status']['closed'] = 'closed';
  276. }
  277. ($hook = get_hook('se_results_topics_row_pre_item_subject_status_merge')) ? eval($hook) : null;
  278. if (!empty($forum_page['item_title_status']))
  279. $forum_page['item_title']['status'] = '<span class="item-status">'.sprintf($lang_forum['Item status'], implode(', ', $forum_page['item_title_status'])).'</span>';
  280. $forum_page['item_title']['link'] = '<a href="'.forum_link($forum_url['topic'], array($cur_set['tid'], sef_friendly($cur_set['subject']))).'">'.forum_htmlencode($cur_set['subject']).'</a>';
  281. ($hook = get_hook('se_results_topics_row_pre_item_title_merge')) ? eval($hook) : null;
  282. $forum_page['item_body']['subject']['title'] = '<h3 class="hn"><span class="item-num">'.forum_number_format($forum_page['start_from'] + $forum_page['item_count']).'</span> '.implode(' ', $forum_page['item_title']).'</h3>';
  283. $forum_page['item_pages'] = ceil(($cur_set['num_replies'] + 1) / $forum_user['disp_posts']);
  284. if ($forum_page['item_pages'] > 1)
  285. $forum_page['item_nav']['pages'] = '<span>'.$lang_forum['Pages'].'&#160;</span>'.paginate($forum_page['item_pages'], -1, $forum_url['topic'], $lang_common['Page separator'], array($cur_set['tid'], sef_friendly($cur_set['subject'])));
  286. // Does this topic contain posts we haven't read? If so, tag it accordingly.
  287. if (!$forum_user['is_guest'] && $cur_set['last_post'] > $forum_user['last_visit'] && (!isset($tracked_topics['topics'][$cur_set['tid']]) || $tracked_topics['topics'][$cur_set['tid']] < $cur_set['last_post']) && (!isset($tracked_topics['forums'][$cur_set['forum_id']]) || $tracked_topics['forums'][$cur_set['forum_id']] < $cur_set['last_post']))
  288. {
  289. $forum_page['item_nav']['new'] = '<em class="item-newposts"><a href="'.forum_link($forum_url['topic_new_posts'], array($cur_set['tid'], sef_friendly($cur_set['subject']))).'" title="'.$lang_forum['New posts info'].'">'.$lang_forum['New posts'].'</a></em>';
  290. $forum_page['item_status']['new'] = 'new';
  291. }
  292. ($hook = get_hook('se_results_topics_row_pre_item_nav_merge')) ? eval($hook) : null;
  293. $forum_page['item_subject']['starter'] = '<span class="item-starter">'.sprintf($lang_forum['Topic starter'], forum_htmlencode($cur_set['poster'])).'</span>';
  294. if (!empty($forum_page['item_nav']))
  295. $forum_page['item_subject']['nav'] = '<span class="item-nav">'.sprintf($lang_forum['Topic navigation'], implode('&#160;&#160;', $forum_page['item_nav'])).'</span>';
  296. ($hook = get_hook('se_results_topics_row_pre_item_subject_merge')) ? eval($hook) : null;
  297. $forum_page['item_body']['subject']['desc'] = '<p>'.implode(' ', $forum_page['item_subject']).'</p>';
  298. if (empty($forum_page['item_status']))
  299. $forum_page['item_status']['normal'] = 'normal';
  300. ($hook = get_hook('se_results_topics_pre_item_status_merge')) ? eval($hook) : null;
  301. $forum_page['item_style'] = (($forum_page['item_count'] % 2 != 0) ? ' odd' : ' even').(($forum_page['item_count'] == 1) ? ' main-first-item' : '').((!empty($forum_page['item_status'])) ? ' '.implode(' ', $forum_page['item_status']) : '');
  302. $forum_page['item_body']['info']['forum'] = '<li class="info-forum"><span class="label">'.$lang_search['Posted in'].'</span><a href="'.forum_link($forum_url['forum'], array($cur_set['forum_id'], sef_friendly($cur_set['forum_name']))).'">'.$cur_set['forum_name'].'</a></li>';
  303. $forum_page['item_body']['info']['replies'] = '<li class="info-replies"><strong>'.forum_number_format($cur_set['num_replies']).'</strong> <span class="label">'.(($cur_set['num_replies'] == 1) ? $lang_forum['Reply'] : $lang_forum['Replies']).'</span></li>';
  304. $forum_page['item_body']['info']['lastpost'] = '<li class="info-lastpost"><span class="label">'.$lang_forum['Last post'].'</span> <strong><a href="'.forum_link($forum_url['post'], $cur_set['last_post_id']).'">'.format_time($cur_set['last_post']).'</a></strong> <cite>'.sprintf($lang_forum['by poster'], forum_htmlencode($cur_set['last_poster'])).'</cite></li>';
  305. ($hook = get_hook('se_results_topics_row_pre_display')) ? eval($hook) : null;
  306. ?>
  307. <div class="main-item<?php echo $forum_page['item_style'] ?>">
  308. <span class="icon <?php echo implode(' ', $forum_page['item_status']) ?>"><!-- --></span>
  309. <div class="item-subject">
  310. <?php echo implode("\n\t\t\t\t", $forum_page['item_body']['subject'])."\n" ?>
  311. </div>
  312. <ul class="item-info">
  313. <?php echo implode("\n\t\t\t\t", $forum_page['item_body']['info'])."\n" ?>
  314. </ul>
  315. </div>
  316. <?php
  317. }
  318. else if ($show_as == 'forums')
  319. {
  320. if ($cur_set['cid'] != $forum_page['cur_category']) // A new category since last iteration?
  321. {
  322. if ($forum_page['cur_category'] != 0)
  323. echo "\t".'</div>'."\n";
  324. ++$forum_page['cat_count'];
  325. $forum_page['item_count'] = 1;
  326. $forum_page['item_header'] = array();
  327. $forum_page['item_header']['subject']['title'] = '<strong class="subject-title">'.$lang_index['Forums'].'</strong>';
  328. $forum_page['item_header']['info']['topics'] = '<strong class="info-topics">'.$lang_index['topics'].'</strong>';
  329. $forum_page['item_header']['info']['post'] = '<strong class="info-posts">'.$lang_index['posts'].'</strong>';
  330. $forum_page['item_header']['info']['lastpost'] = '<strong class="info-lastpost">'.$lang_index['last post'].'</strong>';
  331. ($hook = get_hook('se_results_forums_row_pre_cat_head')) ? eval($hook) : null;
  332. $forum_page['cur_category'] = $cur_set['cid'];
  333. ?>
  334. <div class="main-head">
  335. <h2 class="hn"><span><?php echo forum_htmlencode($cur_set['cat_name']) ?></span></h2>
  336. </div>
  337. <div class="main-subhead">
  338. <p class="item-summary"><span><?php printf($lang_index['Category subtitle'], implode(' ', $forum_page['item_header']['subject']), implode(', ', $forum_page['item_header']['info'])) ?></span></p>
  339. </div>
  340. <div id="category<?php echo $forum_page['cat_count'] ?>" class="main-content main-category">
  341. <?php
  342. }
  343. // Reset arrays and globals for each forum
  344. $forum_page['item_status'] = $forum_page['item_subject'] = $forum_page['item_body'] = $forum_page['item_title'] = array();
  345. // Is this a redirect forum?
  346. if ($cur_set['redirect_url'] != '')
  347. {
  348. $forum_page['item_body']['subject']['title'] = '<h3 class="hn"><a class="external" href="'.forum_htmlencode($cur_forum['redirect_url']).'" title="'.sprintf($lang_index['Link to'], forum_htmlencode($cur_forum['redirect_url'])).'"><span>'.forum_htmlencode($cur_set['forum_name']).'</span></a></h3>';
  349. $forum_page['item_status']['redirect'] = 'redirect';
  350. if ($cur_set['forum_desc'] != '')
  351. $forum_page['item_subject']['desc'] = $cur_set['forum_desc'];
  352. $forum_page['item_subject']['redirect'] = '<span>'.$lang_index['External forum'].'</span>';
  353. ($hook = get_hook('se_results_forums_row_redirect_pre_item_subject_merge')) ? eval($hook) : null;
  354. if (!empty($forum_page['item_subject']))
  355. $forum_page['item_body']['subject']['desc'] = '<p>'.implode(' ', $forum_page['item_subject']).'</p>';
  356. // Forum topic and post count
  357. $forum_page['item_body']['info']['topics'] = '<li class="info-topics"><span class="label">'.$lang_index['No topic info'].'</span></li>';
  358. $forum_page['item_body']['info']['posts'] = '<li class="info-posts"><span class="label">'.$lang_index['No post info'].'</span></li>';
  359. $forum_page['item_body']['info']['lastpost'] = '<li class="info-lastpost"><span class="label">'.$lang_index['No lastpost info'].'</span></li>';
  360. ($hook = get_hook('se_results_forums_row_redirect_pre_display')) ? eval($hook) : null;
  361. }
  362. else
  363. {
  364. // Setup the title and link to the forum
  365. $forum_page['item_title']['title'] = '<a href="'.forum_link($forum_url['forum'], array($cur_set['fid'], sef_friendly($cur_set['forum_name']))).'"><span>'.forum_htmlencode($cur_set['forum_name']).'</span></a>';
  366. ($hook = get_hook('se_results_forums_row_redirect_pre_item_title_merge')) ? eval($hook) : null;
  367. $forum_page['item_body']['subject']['title'] = '<h3 class="hn">'.implode(' ', $forum_page['item_title']).'</h3>';
  368. // Setup the forum description and mod list
  369. if ($cur_set['forum_desc'] != '')
  370. $forum_page['item_subject']['desc'] = $cur_set['forum_desc'];
  371. ($hook = get_hook('se_results_forums_row_normal_pre_item_subject_merge')) ? eval($hook) : null;
  372. if (!empty($forum_page['item_subject']))
  373. $forum_page['item_body']['subject']['desc'] = '<p>'.implode(' ', $forum_page['item_subject']).'</p>';
  374. // Setup forum topics, post count and last post
  375. $forum_page['item_body']['info']['topics'] = '<li class="info-topics"><strong>'.forum_number_format($cur_set['num_topics']).'</strong> <span class="label">'.(($cur_set['num_topics'] == 1) ? $lang_index['topic'] : $lang_index['topics']).'</span></li>';
  376. $forum_page['item_body']['info']['posts'] = '<li class="info-posts"><strong>'.forum_number_format($cur_set['num_posts']).'</strong> <span class="label">'.(($cur_set['num_posts'] == 1) ? $lang_index['post'] : $lang_index['posts']).'</span></li>';
  377. if ($cur_set['last_post'] != '')
  378. $forum_page['item_body']['info']['lastpost'] = '<li class="info-lastpost"><span class="label">'.$lang_index['Last post'].'</span> <strong><a href="'.forum_link($forum_url['post'], $cur_set['last_post_id']).'">'.format_time($cur_set['last_post']).'</a></strong> <cite>'.sprintf($lang_index['Last poster'], forum_htmlencode($cur_set['last_poster'])).'</cite></li>';
  379. else
  380. $forum_page['item_body']['info']['lastpost'] = '<li class="info-lastpost"><strong>'.$lang_common['Never'].'</strong></li>';
  381. ($hook = get_hook('se_results_forums_row_normal_pre_display')) ? eval($hook) : null;
  382. }
  383. // Generate classes for this forum depending on its status
  384. $forum_page['item_style'] = (($forum_page['item_count'] % 2 != 0) ? ' odd' : ' even').(($forum_page['item_count'] == 1) ? ' main-first-item' : '').((!empty($forum_page['item_status'])) ? ' '.implode(' ', $forum_page['item_status']) : '');
  385. ($hook = get_hook('se_results_forums_row_pre_display')) ? eval($hook) : null;
  386. ?>
  387. <div id="forum<?php echo $cur_set['fid'] ?>" class="main-item<?php echo $forum_page['item_style'] ?>">
  388. <span class="icon <?php echo implode(' ', $forum_page['item_status']) ?>"><!-- --></span>
  389. <div class="item-subject">
  390. <?php echo implode("\n\t\t\t\t", $forum_page['item_body']['subject'])."\n" ?>
  391. </div>
  392. <ul class="item-info">
  393. <?php echo implode("\n\t\t\t\t", $forum_page['item_body']['info'])."\n" ?>
  394. </ul>
  395. </div>
  396. <?php
  397. }
  398. }
  399. ?>
  400. </div>
  401. <div class="main-foot">
  402. <?php
  403. if (!empty($forum_page['main_foot_options']))
  404. echo "\n\t\t\t".'<p class="options">'.implode(' ', $forum_page['main_foot_options']).'</p>';
  405. ?>
  406. <h2 class="hn"><span><?php echo $forum_page['items_info'] ?></span></h2>
  407. </div>
  408. <?php
  409. ($hook = get_hook('se_results_end')) ? eval($hook) : null;
  410. $tpl_temp = forum_trim(ob_get_contents());
  411. $tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
  412. ob_end_clean();
  413. // END SUBST - <!-- forum_main -->
  414. require FORUM_ROOT.'footer.php';
  415. }
  416. //
  417. // Display the search form
  418. //
  419. // Setup form information
  420. $forum_page['frm-info'] = array(
  421. 'keywords' => '<li><span>'.$lang_search['Keywords info'].'</span></li>',
  422. 'refine' => '<li><span>'.$lang_search['Refine info'].'</span></li>',
  423. 'wildcard' => '<li><span>'.$lang_search['Wildcard info'].'</span></li>'
  424. );
  425. if ($forum_config['o_search_all_forums'] == '1' || $forum_user['is_admmod'])
  426. $forum_page['frm-info']['forums'] = '<li><span>'.$lang_search['Forum default info'].'</span></li>';
  427. else
  428. $forum_page['frm-info']['forums'] = '<li><span>'.$lang_search['Forum require info'].'</span></li>';
  429. // Setup sort by options
  430. $forum_page['frm-sort'] = array(
  431. 'post_time' => '<option value="0">'.$lang_search['Sort by post time'].'</option>',
  432. 'author' => '<option value="1">'.$lang_search['Sort by author'].'</option>',
  433. 'subject' => '<option value="2">'.$lang_search['Sort by subject'].'</option>',
  434. 'forum_name' => '<option value="3">'.$lang_search['Sort by forum'].'</option>'
  435. );
  436. // Setup breadcrumbs
  437. $forum_page['crumbs'] = array(
  438. array($forum_config['o_board_title'], forum_link($forum_url['index'])),
  439. $lang_common['Search']
  440. );
  441. $advanced_search = isset($_GET['advanced']) ? true : false;
  442. // Show link for advanced form
  443. if (!$advanced_search)
  444. {
  445. $forum_page['main_head_options']['advanced_search'] = '<span'.(empty($forum_page['main_head_options']) ? ' class="first-item"' : '').'><a href="'.forum_link($forum_url['search_advanced']).'">'.$lang_search['Advanced search'].'</a></span>';
  446. }
  447. // Setup form
  448. $forum_page['group_count'] = $forum_page['item_count'] = $forum_page['fld_count'] = 0;
  449. ($hook = get_hook('se_pre_header_load')) ? eval($hook) : null;
  450. define('FORUM_PAGE', 'search');
  451. require FORUM_ROOT.'header.php';
  452. // START SUBST - <!-- forum_main -->
  453. ob_start();
  454. ($hook = get_hook('se_main_output_start')) ? eval($hook) : null;
  455. ?>
  456. <div class="main-head">
  457. <?php
  458. if (!empty($forum_page['main_head_options']))
  459. echo "\n\t\t".'<p class="options">'.implode(' ', $forum_page['main_head_options']).'</p>';
  460. ?>
  461. <h2 class="hn"><span><?php echo $lang_search['Search heading'] ?></span></h2>
  462. </div>
  463. <div class="main-content main-frm">
  464. <?php if ($advanced_search): ?>
  465. <div class="ct-box info-box">
  466. <ul class="info-list">
  467. <?php echo implode("\n\t\t\t\t", $forum_page['frm-info'])."\n" ?>
  468. </ul>
  469. </div>
  470. <?php endif; ?>
  471. <form id="afocus" class="frm-form" method="get" accept-charset="utf-8" action="<?php echo forum_link($forum_url['search']) ?>">
  472. <div class="hidden">
  473. <input type="hidden" name="action" value="search" />
  474. </div>
  475. <?php ($hook = get_hook('se_pre_criteria_fieldset')) ? eval($hook) : null; ?>
  476. <fieldset class="frm-group group<?php echo ++$forum_page['group_count'] ?>">
  477. <legend class="group-legend"><strong><?php echo $lang_search['Search legend'] ?></strong></legend>
  478. <?php ($hook = get_hook('se_pre_keywords')) ? eval($hook) : null; ?>
  479. <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
  480. <div class="sf-box text">
  481. <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_search['Keyword search'] ?></span></label><br />
  482. <span class="fld-input"><input type="text" id="fld<?php echo $forum_page['fld_count'] ?>" name="keywords" size="40" maxlength="100" <?php echo ($advanced_search) ? '' : 'required' ?> /></span>
  483. </div>
  484. </div>
  485. <?php ($hook = get_hook('se_pre_author')) ? eval($hook) : null; ?>
  486. <?php if ($advanced_search): ?>
  487. <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
  488. <div class="sf-box text">
  489. <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_search['Author search'] ?></span></label><br />
  490. <span class="fld-input"><input id="fld<?php echo $forum_page['fld_count'] ?>" type="text" name="author" size="40" maxlength="25" /></span>
  491. </div>
  492. </div>
  493. <?php ($hook = get_hook('se_pre_search_in')) ? eval($hook) : null; ?>
  494. <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
  495. <div class="sf-box select">
  496. <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_search['Search in'] ?></span></label><br />
  497. <span class="fld-input"><select id="fld<?php echo $forum_page['fld_count'] ?>" name="search_in">
  498. <option value="all"><?php echo $lang_search['Message and subject'] ?></option>
  499. <option value="message"><?php echo $lang_search['Message only'] ?></option>
  500. <option value="topic"><?php echo $lang_search['Topic only'] ?></option>
  501. </select></span>
  502. </div>
  503. </div>
  504. <?php endif; if ((!$advanced_search && ($forum_config['o_search_all_forums'] == '0' && !$forum_user['is_admmod'])) || $advanced_search): ?>
  505. <?php ($hook = get_hook('se_pre_forum_fieldset')) ? eval($hook) : null; ?>
  506. <fieldset class="mf-set set<?php echo ++$forum_page['item_count'] ?>">
  507. <legend><span><?php echo $lang_search['Forum search'] ?> <em><?php echo ($forum_config['o_search_all_forums'] == '1' || $forum_user['is_admmod']) ? $lang_search['Forum search default'] : $lang_search['Forum search require'] ?></em></span></legend>
  508. <?php ($hook = get_hook('se_pre_forum_checklist')) ? eval($hook) : null; ?>
  509. <div class="mf-box">
  510. <div class="checklist">
  511. <?php
  512. // Get the list of categories and forums
  513. $query = array(
  514. 'SELECT' => 'c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.redirect_url',
  515. 'FROM' => 'categories AS c',
  516. 'JOINS' => array(
  517. array(
  518. 'INNER JOIN' => 'forums AS f',
  519. 'ON' => 'c.id=f.cat_id'
  520. ),
  521. array(
  522. 'LEFT JOIN' => 'forum_perms AS fp',
  523. 'ON' => '(fp.forum_id=f.id AND fp.group_id='.$forum_user['g_id'].')'
  524. )
  525. ),
  526. 'WHERE' => '(fp.read_forum IS NULL OR fp.read_forum=1) AND f.redirect_url IS NULL',
  527. 'ORDER BY' => 'c.disp_position, c.id, f.disp_position'
  528. );
  529. ($hook = get_hook('se_qr_get_cats_and_forums')) ? eval($hook) : null;
  530. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  531. $forums = array();
  532. while ($cur_forum = $forum_db->fetch_assoc($result))
  533. {
  534. $forums[] = $cur_forum;
  535. }
  536. if (!empty($forums))
  537. {
  538. $cur_category = 0;
  539. foreach ($forums as $cur_forum)
  540. {
  541. ($hook = get_hook('se_forum_loop_start')) ? eval($hook) : null;
  542. if ($cur_forum['cid'] != $cur_category) // A new category since last iteration?
  543. {
  544. if ($cur_category)
  545. echo "\t\t\t\t\t\t\t".'</fieldset>'."\n";
  546. echo "\t\t\t\t\t\t\t".'<fieldset>'."\n\t\t\t\t\t\t\t\t".'<legend><span>'.forum_htmlencode($cur_forum['cat_name']).':</span></legend>'."\n";
  547. $cur_category = $cur_forum['cid'];
  548. }
  549. echo "\t\t\t\t\t\t\t\t".'<div class="checklist-item"><span class="fld-input"><input type="checkbox" id="fld'.(++$forum_page['fld_count']).'" name="forum[]" value="'.$cur_forum['fid'].'" /></span> <label for="fld'.$forum_page['fld_count'].'">'.forum_htmlencode($cur_forum['forum_name']).'</label></div>'."\n";
  550. ($hook = get_hook('se_forum_loop_end')) ? eval($hook) : null;
  551. }
  552. echo "\t\t\t\t\t\t\t".'</fieldset>'."\n";
  553. }
  554. ?>
  555. </div>
  556. </div>
  557. <?php ($hook = get_hook('se_pre_forum_fieldset_end')) ? eval($hook) : null; ?>
  558. </fieldset>
  559. <?php endif; ?>
  560. <?php ($hook = get_hook('se_forum_fieldset_end')) ? eval($hook) : null; ?>
  561. </fieldset>
  562. <?php ($hook = get_hook('se_criteria_fieldset_end')) ? eval($hook) : null; ?>
  563. <?php $forum_page['item_count'] = 0; ?>
  564. <?php ($hook = get_hook('se_pre_results_fieldset')) ? eval($hook) : null; ?>
  565. <?php if ($advanced_search): ?>
  566. <fieldset class="frm-group group<?php echo ++$forum_page['group_count'] ?>">
  567. <legend class="group-legend"><strong><?php echo $lang_search['Results legend'] ?></strong></legend>
  568. <?php ($hook = get_hook('se_pre_sort_by')) ? eval($hook) : null; ?>
  569. <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
  570. <div class="sf-box select">
  571. <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_search['Sort by'] ?></span></label><br />
  572. <span class="fld-input"><select id="fld<?php echo $forum_page['fld_count'] ?>" name="sort_by">
  573. <?php echo implode("\n\t\t\t\t\t\t", $forum_page['frm-sort'])."\n" ?>
  574. </select></span>
  575. </div>
  576. </div>
  577. <?php ($hook = get_hook('se_pre_sort_order_fieldset')) ? eval($hook) : null; ?>
  578. <fieldset class="mf-set set<?php echo ++$forum_page['item_count'] ?>">
  579. <legend><span><?php echo $lang_search['Sort order'] ?></span></legend>
  580. <?php ($hook = get_hook('se_pre_sort_order')) ? eval($hook) : null; ?>
  581. <div class="mf-box mf-yesno">
  582. <div class="mf-item">
  583. <span class="fld-input"><input type="radio" id="fld<?php echo ++$forum_page['fld_count'] ?>" name="sort_dir" value="ASC" /></span>
  584. <label for="fld<?php echo $forum_page['fld_count'] ?>"><?php echo $lang_search['Ascending'] ?></label>
  585. </div>
  586. <div class="mf-item">
  587. <span class="fld-input"><input type="radio" id="fld<?php echo ++$forum_page['fld_count'] ?>" name="sort_dir" value="DESC" checked="checked" /></span>
  588. <label for="fld<?php echo $forum_page['fld_count'] ?>"><?php echo $lang_search['Descending'] ?></label>
  589. </div>
  590. </div>
  591. <?php ($hook = get_hook('se_pre_sort_order_fieldset_end')) ? eval($hook) : null; ?>
  592. </fieldset>
  593. <?php ($hook = get_hook('se_pre_display_choices_fieldset')) ? eval($hook) : null; ?>
  594. <fieldset class="mf-set set<?php echo ++$forum_page['item_count'] ?>">
  595. <legend><span><?php echo $lang_search['Display results'] ?></span></legend>
  596. <?php ($hook = get_hook('se_pre_display_choices')) ? eval($hook) : null; ?>
  597. <div class="mf-box mf-yesno">
  598. <div class="mf-item">
  599. <span class="fld-input"><input type="radio" id="fld<?php echo ++$forum_page['fld_count'] ?>" name="show_as" value="topics" /></span>
  600. <label for="fld<?php echo $forum_page['fld_count'] ?>"><?php echo $lang_search['Show as topics'] ?></label>
  601. </div>
  602. <div class="mf-item">
  603. <span class="fld-input"><input type="radio" id="fld<?php echo ++$forum_page['fld_count'] ?>" name="show_as" value="posts" checked="checked" /></span>
  604. <label for="fld<?php echo $forum_page['fld_count'] ?>"><?php echo $lang_search['Show as posts'] ?></label>
  605. </div>
  606. <?php ($hook = get_hook('se_new_display_choices')) ? eval($hook) : null; ?>
  607. </div>
  608. <?php ($hook = get_hook('se_pre_display_choices_fieldset_end')) ? eval($hook) : null; ?>
  609. </fieldset>
  610. <?php ($hook = get_hook('se_pre_results_fieldset_end')) ? eval($hook) : null; ?>
  611. </fieldset>
  612. <?php endif; ($hook = get_hook('se_results_fieldset_end')) ? eval($hook) : null; ?>
  613. <div class="frm-buttons">
  614. <span class="submit primary"><input type="submit" name="search" value="<?php echo $lang_search['Submit search'] ?>" /></span>
  615. </div>
  616. </form>
  617. </div>
  618. <?php
  619. ($hook = get_hook('se_end')) ? eval($hook) : null;
  620. $tpl_temp = forum_trim(ob_get_contents());
  621. $tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
  622. ob_end_clean();
  623. // END SUBST - <!-- forum_main -->
  624. require FORUM_ROOT.'footer.php';