Search.template.php 20 KB

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