Search.template.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines
  7. * @copyright 2011 Simple Machines
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.1 Alpha 1
  11. */
  12. function template_main()
  13. {
  14. global $context, $settings, $options, $txt, $scripturl, $modSettings;
  15. echo '
  16. <form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '" name="searchform" id="searchform">
  17. <div class="cat_bar">
  18. <h3 class="catbg">
  19. <span class="ie6_header floatleft">', !empty($settings['use_buttons']) ? '<img src="' . $settings['images_url'] . '/buttons/search.gif" alt="" class="icon" />' : ' ', $txt['set_parameters'], '</span>
  20. </h3>
  21. </div>';
  22. if (!empty($context['search_errors']))
  23. echo '
  24. <p id="search_error" class="error">', implode('<br />', $context['search_errors']['messages']), '</p>';
  25. // Simple Search?
  26. if ($context['simple_search'])
  27. {
  28. echo '
  29. <fieldset id="simple_search">
  30. <span class="upperframe"><span></span></span>
  31. <div class="roundframe">
  32. <div id="search_term_input">
  33. <strong>', $txt['search_for'], ':</strong>
  34. <input type="text" name="search"', !empty($context['search_params']['search']) ? ' value="' . $context['search_params']['search'] . '"' : '', ' maxlength="', $context['search_string_limit'], '" size="40" class="input_text" />
  35. ', $context['require_verification'] ? '' : '&nbsp;<input type="submit" name="submit" value="' . $txt['search'] . '" class="button_submit" />
  36. </div>';
  37. if (empty($modSettings['search_simple_fulltext']))
  38. echo '
  39. <p class="smalltext">', $txt['search_example'], '</p>';
  40. if ($context['require_verification'])
  41. echo '
  42. <div class="verification>
  43. <strong>', $txt['search_visual_verification_label'], ':</strong>
  44. <br />', template_control_verification($context['visual_verification_id'], 'all'), '<br />
  45. <input id="submit" type="submit" name="submit" value="' . $txt['search'] . '" class="button_submit" />
  46. </div>';
  47. echo '
  48. <a href="', $scripturl, '?action=search;advanced" onclick="this.href += \';search=\' + escape(document.forms.searchform.search.value);">', $txt['search_advanced'], '</a>
  49. <input type="hidden" name="advanced" value="0" />
  50. </div>
  51. <span class="lowerframe"><span></span></span>
  52. </fieldset>';
  53. }
  54. // Advanced search!
  55. else
  56. {
  57. echo '
  58. <fieldset id="advanced_search">
  59. <span class="upperframe"><span></span></span>
  60. <div class="roundframe">
  61. <input type="hidden" name="advanced" value="1" />
  62. <span class="enhanced">
  63. <strong>', $txt['search_for'], ':</strong>
  64. <input type="text" name="search"', !empty($context['search_params']['search']) ? ' value="' . $context['search_params']['search'] . '"' : '', ' maxlength="', $context['search_string_limit'], '" size="40" class="input_text" />
  65. <script type="text/javascript"><!-- // --><![CDATA[
  66. createEventListener(window);
  67. window.addEventListener("load", initSearch, false);
  68. // ]]></script>
  69. <select name="searchtype">
  70. <option value="1"', empty($context['search_params']['searchtype']) ? ' selected="selected"' : '', '>', $txt['all_words'], '</option>
  71. <option value="2"', !empty($context['search_params']['searchtype']) ? ' selected="selected"' : '', '>', $txt['any_words'], '</option>
  72. </select>
  73. </span>';
  74. if (empty($modSettings['search_simple_fulltext']))
  75. echo '
  76. <em class="smalltext">', $txt['search_example'], '</em>';
  77. echo '
  78. <dl id="search_options">
  79. <dt>', $txt['by_user'], ':</dt>
  80. <dd><input id="userspec" type="text" name="userspec" value="', empty($context['search_params']['userspec']) ? '*' : $context['search_params']['userspec'], '" size="40" class="input_text" /></dd>
  81. <dt>', $txt['search_order'], ':</dt>
  82. <dd>
  83. <select id="sort" name="sort">
  84. <option value="relevance|desc">', $txt['search_orderby_relevant_first'], '</option>
  85. <option value="num_replies|desc">', $txt['search_orderby_large_first'], '</option>
  86. <option value="num_replies|asc">', $txt['search_orderby_small_first'], '</option>
  87. <option value="id_msg|desc">', $txt['search_orderby_recent_first'], '</option>
  88. <option value="id_msg|asc">', $txt['search_orderby_old_first'], '</option>
  89. </select>
  90. </dd>
  91. <dt class="options">', $txt['search_options'], ':</dt>
  92. <dd class="options">
  93. <label for="show_complete"><input type="checkbox" name="show_complete" id="show_complete" value="1"', !empty($context['search_params']['show_complete']) ? ' checked="checked"' : '', ' class="input_check" /> ', $txt['search_show_complete_messages'], '</label><br />
  94. <label for="subject_only"><input type="checkbox" name="subject_only" id="subject_only" value="1"', !empty($context['search_params']['subject_only']) ? ' checked="checked"' : '', ' class="input_check" /> ', $txt['search_subject_only'], '</label>
  95. </dd>
  96. <dt class="between">', $txt['search_post_age'], ': </dt>
  97. <dd>', $txt['search_between'], ' <input type="text" name="minage" value="', empty($context['search_params']['minage']) ? '0' : $context['search_params']['minage'], '" size="5" maxlength="4" class="input_text" />&nbsp;', $txt['search_and'], '&nbsp;<input type="text" name="maxage" value="', empty($context['search_params']['maxage']) ? '9999' : $context['search_params']['maxage'], '" size="5" maxlength="4" class="input_text" /> ', $txt['days_word'], '</dd>
  98. </dl>';
  99. // Require an image to be typed to save spamming?
  100. if ($context['require_verification'])
  101. {
  102. echo '
  103. <p>
  104. <strong>', $txt['verification'], ':</strong>
  105. ', template_control_verification($context['visual_verification_id'], 'all'), '
  106. </p>';
  107. }
  108. // If $context['search_params']['topic'] is set, that means we're searching just one topic.
  109. if (!empty($context['search_params']['topic']))
  110. echo '
  111. <p>', $txt['search_specific_topic'], ' &quot;', $context['search_topic']['link'], '&quot;.</p>
  112. <input type="hidden" name="topic" value="', $context['search_topic']['id'], '" />';
  113. echo '
  114. </div>
  115. <span class="lowerframe"><span></span></span>
  116. </fieldset>';
  117. if (empty($context['search_params']['topic']))
  118. {
  119. echo '
  120. <fieldset class="flow_hidden">
  121. <span class="upperframe"><span></span></span>
  122. <div class="roundframe">
  123. <div class="title_bar">
  124. <h4 class="titlebg">
  125. <a href="javascript:void(0);" onclick="expandCollapseBoards(); return false;"><img src="', $settings['images_url'], '/expand.gif" id="expandBoardsIcon" alt="" /></a> <a href="javascript:void(0);" onclick="expandCollapseBoards(); return false;"><strong>', $txt['choose_board'], '</strong></a>
  126. </h4>
  127. </div>
  128. <div class="flow_auto" id="searchBoardsExpand"', $context['boards_check_all'] ? ' style="display: none;"' : '', '>
  129. <ul class="ignoreboards floatleft">';
  130. $i = 0;
  131. $limit = ceil($context['num_boards'] / 2);
  132. foreach ($context['categories'] as $category)
  133. {
  134. echo '
  135. <li class="category">
  136. <a href="javascript:void(0);" onclick="selectBoards([', implode(', ', $category['child_ids']), ']); return false;">', $category['name'], '</a>
  137. <ul>';
  138. foreach ($category['boards'] as $board)
  139. {
  140. if ($i == $limit)
  141. echo '
  142. </ul>
  143. </li>
  144. </ul>
  145. <ul class="ignoreboards floatright">
  146. <li class="category">
  147. <ul>';
  148. echo '
  149. <li class="board" style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">
  150. <label for="brd', $board['id'], '"><input type="checkbox" id="brd', $board['id'], '" name="brd[', $board['id'], ']" value="', $board['id'], '"', $board['selected'] ? ' checked="checked"' : '', ' class="input_check" /> ', $board['name'], '</label>
  151. </li>';
  152. $i ++;
  153. }
  154. echo '
  155. </ul>
  156. </li>';
  157. }
  158. echo '
  159. </ul>
  160. </div>
  161. <br class="clear" />';
  162. echo '
  163. <div class="padding">
  164. <input type="checkbox" name="all" id="check_all" value=""', $context['boards_check_all'] ? ' checked="checked"' : '', ' onclick="invertAll(this, this.form, \'brd\');" class="input_check floatleft" />
  165. <label for="check_all" class="floatleft">', $txt['check_all'], '</label>
  166. <input type="submit" name="submit" value="', $txt['search'], '" class="button_submit floatright" />
  167. </div>
  168. <br class="clear" />
  169. </div>
  170. <span class="lowerframe"><span></span></span>
  171. </fieldset>';
  172. }
  173. }
  174. echo '
  175. </form>';
  176. }
  177. function template_results()
  178. {
  179. global $context, $settings, $options, $txt, $scripturl, $message;
  180. if (isset($context['did_you_mean']) || empty($context['topics']))
  181. {
  182. echo '
  183. <div id="search_results">
  184. <div class="cat_bar">
  185. <h3 class="catbg">
  186. ', $txt['search_adjust_query'], '
  187. </h3>
  188. </div>
  189. <span class="upperframe"><span></span></span>
  190. <div class="roundframe">';
  191. // Did they make any typos or mistakes, perhaps?
  192. if (isset($context['did_you_mean']))
  193. echo '
  194. <p>', $txt['search_did_you_mean'], ' <a href="', $scripturl, '?action=search2;params=', $context['did_you_mean_params'], '">', $context['did_you_mean'], '</a>.</p>';
  195. echo '
  196. <form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
  197. <strong>', $txt['search_for'], ':</strong>
  198. <input type="text" name="search"', !empty($context['search_params']['search']) ? ' value="' . $context['search_params']['search'] . '"' : '', ' maxlength="', $context['search_string_limit'], '" size="40" class="input_text" />
  199. <input type="submit" name="submit" value="', $txt['search_adjust_submit'], '" class="button_submit" />
  200. <input type="hidden" name="searchtype" value="', !empty($context['search_params']['searchtype']) ? $context['search_params']['searchtype'] : 0, '" />
  201. <input type="hidden" name="userspec" value="', !empty($context['search_params']['userspec']) ? $context['search_params']['userspec'] : '', '" />
  202. <input type="hidden" name="show_complete" value="', !empty($context['search_params']['show_complete']) ? 1 : 0, '" />
  203. <input type="hidden" name="subject_only" value="', !empty($context['search_params']['subject_only']) ? 1 : 0, '" />
  204. <input type="hidden" name="minage" value="', !empty($context['search_params']['minage']) ? $context['search_params']['minage'] : '0', '" />
  205. <input type="hidden" name="maxage" value="', !empty($context['search_params']['maxage']) ? $context['search_params']['maxage'] : '9999', '" />
  206. <input type="hidden" name="sort" value="', !empty($context['search_params']['sort']) ? $context['search_params']['sort'] : 'relevance', '" />';
  207. if (!empty($context['search_params']['brd']))
  208. foreach ($context['search_params']['brd'] as $board_id)
  209. echo '
  210. <input type="hidden" name="brd[', $board_id, ']" value="', $board_id, '" />';
  211. echo '
  212. </form>
  213. </div>
  214. <span class="lowerframe"><span></span></span>
  215. </div><br />';
  216. }
  217. if ($context['compact'])
  218. {
  219. // Quick moderation set to checkboxes? Oh, how fun :/.
  220. if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
  221. echo '
  222. <form action="', $scripturl, '?action=quickmod" method="post" accept-charset="', $context['character_set'], '" name="topicForm">';
  223. echo '
  224. <div class="cat_bar">
  225. <h3 class="catbg">
  226. <span class="floatright">';
  227. if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
  228. echo '
  229. <input type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');" class="input_check" />';
  230. echo '
  231. </span>
  232. <span class="ie6_header floatleft"><img src="' . $settings['images_url'] . '/buttons/search.gif" alt="" />&nbsp;', $txt['mlist_search_results'],':&nbsp;',$context['search_params']['search'],'</span>
  233. </h3>
  234. </div>
  235. <div class="pagesection">
  236. <span>', $txt['pages'], ': ', $context['page_index'], '</span>
  237. </div>';
  238. while ($topic = $context['get_topics']())
  239. {
  240. $color_class = '';
  241. if ($topic['is_sticky'])
  242. $color_class = 'stickybg';
  243. if ($topic['is_locked'])
  244. $color_class .= 'lockedbg';
  245. echo '
  246. <div class="search_results_posts">
  247. <div class="', $message['alternate'] == 0 ? 'windowbg' : 'windowbg2', ' core_posts">
  248. <span class="topslice"><span></span></span>
  249. <div class="content flow_auto">';
  250. foreach ($topic['matches'] as $message)
  251. {
  252. echo '
  253. <div class="topic_details floatleft" style="width: 94%">
  254. <div class="counter">', $message['counter'], '</div>
  255. <h5>', $topic['board']['link'], ' / <a href="', $scripturl, '?topic=', $topic['id'], '.msg', $message['id'], '#msg', $message['id'], '">', $message['subject_highlighted'], '</a></h5>
  256. <span class="smalltext">&#171;&nbsp;',$txt['by'],'&nbsp;<strong>', $message['member']['link'], '</strong>&nbsp;',$txt['on'],'&nbsp;<em>', $message['time'], '</em>&nbsp;&#187;</span>
  257. </div>';
  258. if (!empty($options['display_quick_mod']))
  259. {
  260. echo '
  261. <div class="floatright">';
  262. if ($options['display_quick_mod'] == 1)
  263. {
  264. echo '
  265. <input type="checkbox" name="topics[]" value="', $topic['id'], '" class="input_check" />';
  266. }
  267. else
  268. {
  269. if ($topic['quick_mod']['remove'])
  270. echo '
  271. <a href="', $scripturl, '?action=quickmod;actions[', $topic['id'], ']=remove;', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['quickmod_confirm'], '\');"><img src="', $settings['images_url'], '/icons/quick_remove.gif" width="16" alt="', $txt['remove_topic'], '" title="', $txt['remove_topic'], '" /></a>';
  272. if ($topic['quick_mod']['lock'])
  273. echo '
  274. <a href="', $scripturl, '?action=quickmod;actions[', $topic['id'], ']=lock;', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['quickmod_confirm'], '\');"><img src="', $settings['images_url'], '/icons/quick_lock.gif" width="16" alt="', $txt['set_lock'], '" title="', $txt['set_lock'], '" /></a>';
  275. if ($topic['quick_mod']['lock'] || $topic['quick_mod']['remove'])
  276. echo '
  277. <br />';
  278. if ($topic['quick_mod']['sticky'])
  279. echo '
  280. <a href="', $scripturl, '?action=quickmod;actions[', $topic['id'], ']=sticky;', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['quickmod_confirm'], '\');"><img src="', $settings['images_url'], '/icons/quick_sticky.gif" width="16" alt="', $txt['set_sticky'], '" title="', $txt['set_sticky'], '" /></a>';
  281. if ($topic['quick_mod']['move'])
  282. echo '
  283. <a href="', $scripturl, '?action=movetopic;topic=', $topic['id'], '.0"><img src="', $settings['images_url'], '/icons/quick_move.gif" width="16" alt="', $txt['move_topic'], '" title="', $txt['move_topic'], '" /></a>';
  284. }
  285. echo '
  286. </div>';
  287. }
  288. if ($message['body_highlighted'] != '')
  289. echo '
  290. <br class="clear" />
  291. <div class="list_posts double_height">', $message['body_highlighted'], '</div>';
  292. }
  293. echo '
  294. </div>
  295. <span class="botslice"><span></span></span>
  296. </div>
  297. </div>';
  298. }
  299. if (!empty($context['topics']))
  300. echo '
  301. <div class="pagesection">
  302. <span>', $txt['pages'], ': ', $context['page_index'], '</span>
  303. </div>';
  304. if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']))
  305. {
  306. echo '
  307. <div class="middletext titlebg2" style="padding: 4px;">
  308. <div class="floatright">
  309. <select name="qaction"', $context['can_move'] ? ' onchange="this.form.moveItTo.disabled = (this.options[this.selectedIndex].value != \'move\');"' : '', '>
  310. <option value="">--------</option>', $context['can_remove'] ? '
  311. <option value="remove">' . $txt['quick_mod_remove'] . '</option>' : '', $context['can_lock'] ? '
  312. <option value="lock">' . $txt['quick_mod_lock'] . '</option>' : '', $context['can_sticky'] ? '
  313. <option value="sticky">' . $txt['quick_mod_sticky'] . '</option>' : '', $context['can_move'] ? '
  314. <option value="move">' . $txt['quick_mod_move'] . ': </option>' : '', $context['can_merge'] ? '
  315. <option value="merge">' . $txt['quick_mod_merge'] . '</option>' : '', '
  316. <option value="markread">', $txt['quick_mod_markread'], '</option>
  317. </select>';
  318. if ($context['can_move'])
  319. {
  320. echo '
  321. <select id="moveItTo" name="move_to" disabled="disabled">';
  322. foreach ($context['move_to_boards'] as $category)
  323. {
  324. echo '
  325. <optgroup label="', $category['name'], '">';
  326. foreach ($category['boards'] as $board)
  327. echo '
  328. <option value="', $board['id'], '"', $board['selected'] ? ' selected="selected"' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '</option>';
  329. echo '
  330. </optgroup>';
  331. }
  332. echo '
  333. </select>';
  334. }
  335. echo '
  336. <input type="hidden" name="redirect_url" value="', $scripturl . '?action=search2;params=' . $context['params'], '" />
  337. <input type="submit" style="font-size: 0.8em;" value="', $txt['quick_mod_go'], '" onclick="return this.form.qaction.value != \'\' &amp;&amp; confirm(\'', $txt['quickmod_confirm'], '\');" class="button_submit" />
  338. </div>
  339. <br class="clear" />
  340. </div>';
  341. }
  342. if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']))
  343. echo '
  344. <input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />
  345. </form>';
  346. }
  347. else
  348. {
  349. echo '
  350. <div class="cat_bar">
  351. <h3 class="catbg">
  352. <span class="ie6_header floatleft"><img src="' . $settings['images_url'] . '/buttons/search.gif" alt="" />&nbsp;', $txt['mlist_search_results'],':&nbsp;',$context['search_params']['search'],'</span>
  353. </h3>
  354. </div>
  355. <div class="pagesection">
  356. <span>', $txt['pages'], ': ', $context['page_index'], '</span>
  357. </div>';
  358. if (empty($context['topics']))
  359. echo '
  360. <div class="information">(', $txt['search_no_results'], ')</div>';
  361. while ($topic = $context['get_topics']())
  362. {
  363. foreach ($topic['matches'] as $message)
  364. {
  365. echo '
  366. <div class="search_results_posts">
  367. <div class="', $message['alternate'] == 0 ? 'windowbg' : 'windowbg2', ' core_posts">
  368. <span class="topslice"><span></span></span>
  369. <div class="content">
  370. <div class="counter">', $message['counter'], '</div>
  371. <div class="topic_details">
  372. <h5>', $topic['board']['link'], ' / <a href="', $scripturl, '?topic=', $topic['id'], '.', $message['start'], ';topicseen#msg', $message['id'], '">', $message['subject_highlighted'], '</a></h5>
  373. <span class="smalltext">&#171;&nbsp;', $txt['message'], ' ', $txt['by'], ' <strong>', $message['member']['link'], ' </strong>', $txt['on'], '&nbsp;<em>', $message['time'], '</em>&nbsp;&#187;</span>
  374. </div>
  375. <div class="list_posts">', $message['body_highlighted'], '</div>';
  376. if ($topic['can_reply'] || $topic['can_mark_notify'])
  377. echo '
  378. <div class="quickbuttons_wrap">
  379. <ul class="reset smalltext quickbuttons">';
  380. // If they *can* reply?
  381. if ($topic['can_reply'])
  382. echo '
  383. <li class="reply_button"><a href="', $scripturl . '?action=post;topic=' . $topic['id'] . '.' . $message['start'], '">', $txt['reply'], '</a></li>';
  384. // If they *can* quote?
  385. if ($topic['can_quote'])
  386. echo '
  387. <li class="quote_button"><a href="', $scripturl . '?action=post;topic=' . $topic['id'] . '.' . $message['start'] . ';quote=' . $message['id'] . '">', $txt['quote'], '</a></li>';
  388. // Can we request notification of topics?
  389. if ($topic['can_mark_notify'])
  390. echo '
  391. <li class="notify_button"><a href="', $scripturl . '?action=notify;topic=' . $topic['id'] . '.' . $message['start'], '">', $txt['notify'], '</a></li>';
  392. if ($topic['can_reply'] || $topic['can_mark_notify'])
  393. echo '
  394. </ul>
  395. </div>';
  396. echo '
  397. <br class="clear" />
  398. </div>
  399. <span class="botslice"><span></span></span>
  400. </div>
  401. </div>';
  402. }
  403. }
  404. echo '
  405. <div class="pagesection">
  406. <span>', $txt['pages'], ': ', $context['page_index'], '</span>
  407. </div>';
  408. }
  409. // Show a jump to box for easy navigation.
  410. echo '
  411. <br class="clear" />
  412. <div class="smalltext righttext" id="search_jump_to">&nbsp;</div>
  413. <script type="text/javascript"><!-- // --><![CDATA[
  414. if (typeof(window.XMLHttpRequest) != "undefined")
  415. aJumpTo[aJumpTo.length] = new JumpTo({
  416. sContainerId: "search_jump_to",
  417. sJumpToTemplate: "<label class=\"smalltext\" for=\"%select_id%\">', $context['jump_to']['label'], ':<" + "/label> %dropdown_list%",
  418. iCurBoardId: 0,
  419. iCurBoardChildLevel: 0,
  420. sCurBoardName: "', $context['jump_to']['board_name'], '",
  421. sBoardChildLevelIndicator: "==",
  422. sBoardPrefix: "=> ",
  423. sCatSeparator: "-----------------------------",
  424. sCatPrefix: "",
  425. sGoButtonLabel: "', $txt['quick_mod_go'], '"
  426. });
  427. // ]]></script>';
  428. }
  429. ?>