Search.template.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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 src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
  191. <script><!-- // --><![CDATA[
  192. var oAddMemberSuggest = new smc_AutoSuggest({
  193. sSelf: \'oAddMemberSuggest\',
  194. sSessionId: smf_session_id,
  195. sSessionVar: smf_session_var,
  196. sControlId: \'userspec\',
  197. sSearchType: \'member\',
  198. bItemList: false
  199. });
  200. // ]]></script>';
  201. }
  202. function template_results()
  203. {
  204. global $context, $settings, $options, $txt, $scripturl, $message;
  205. if (isset($context['did_you_mean']) || empty($context['topics']) || !empty($context['search_ignored']))
  206. {
  207. echo '
  208. <div id="search_results">
  209. <div class="cat_bar">
  210. <h3 class="catbg">
  211. ', $txt['search_adjust_query'], '
  212. </h3>
  213. </div>
  214. <div class="roundframe">';
  215. // Did they make any typos or mistakes, perhaps?
  216. if (isset($context['did_you_mean']))
  217. echo '
  218. <p>', $txt['search_did_you_mean'], ' <a href="', $scripturl, '?action=search2;params=', $context['did_you_mean_params'], '">', $context['did_you_mean'], '</a>.</p>';
  219. if (!empty($context['search_ignored']))
  220. echo '
  221. <p>', $txt['search_warning_ignored_word' . (count($context['search_ignored']) == 1 ? '' : 's')], ': ', implode(', ', $context['search_ignored']), '</p>';
  222. echo '
  223. <form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
  224. <dl class="settings">
  225. <dt class="righttext">
  226. <strong>', $txt['search_for'], ':</strong>
  227. </dt>
  228. <dd>
  229. <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">
  230. </dd>
  231. </dl>
  232. <div class="flow_auto" >
  233. <input type="submit" name="edit_search" value="', $txt['search_adjust_submit'], '" class="button_submit">
  234. <input type="hidden" name="searchtype" value="', !empty($context['search_params']['searchtype']) ? $context['search_params']['searchtype'] : 0, '">
  235. <input type="hidden" name="userspec" value="', !empty($context['search_params']['userspec']) ? $context['search_params']['userspec'] : '', '">
  236. <input type="hidden" name="show_complete" value="', !empty($context['search_params']['show_complete']) ? 1 : 0, '">
  237. <input type="hidden" name="subject_only" value="', !empty($context['search_params']['subject_only']) ? 1 : 0, '">
  238. <input type="hidden" name="minage" value="', !empty($context['search_params']['minage']) ? $context['search_params']['minage'] : '0', '">
  239. <input type="hidden" name="maxage" value="', !empty($context['search_params']['maxage']) ? $context['search_params']['maxage'] : '9999', '">
  240. <input type="hidden" name="sort" value="', !empty($context['search_params']['sort']) ? $context['search_params']['sort'] : 'relevance', '">
  241. </div>';
  242. if (!empty($context['search_params']['brd']))
  243. foreach ($context['search_params']['brd'] as $board_id)
  244. echo '
  245. <input type="hidden" name="brd[', $board_id, ']" value="', $board_id, '">';
  246. echo '
  247. </form>
  248. </div>
  249. </div><br>';
  250. }
  251. if ($context['compact'])
  252. {
  253. // Quick moderation set to checkboxes? Oh, how fun :/.
  254. if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
  255. echo '
  256. <form action="', $scripturl, '?action=quickmod" method="post" accept-charset="', $context['character_set'], '" name="topicForm">';
  257. echo '
  258. <div class="cat_bar">
  259. <h3 class="catbg">
  260. <span class="floatright">';
  261. if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
  262. echo '
  263. <input type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');" class="input_check">';
  264. echo '
  265. </span>
  266. <img src="' . $settings['images_url'] . '/buttons/search.png" alt="?" class="centericon">&nbsp;', $txt['mlist_search_results'],':&nbsp;',$context['search_params']['search'],'
  267. </h3>
  268. </div>';
  269. // was anything even found?
  270. if (!empty($context['topics']))
  271. echo'
  272. <div class="pagesection">
  273. <span>', $context['page_index'], '</span>
  274. </div>';
  275. else
  276. echo '
  277. <div class="roundframe">', $txt['find_no_results'], '</div>';
  278. // while we have results to show ...
  279. while ($topic = $context['get_topics']())
  280. {
  281. echo '
  282. <div class="search_results_posts">
  283. <div class="', $message['alternate'] == 0 ? 'windowbg' : 'windowbg2', ' core_posts">
  284. <div class="content flow_auto">';
  285. foreach ($topic['matches'] as $message)
  286. {
  287. echo '
  288. <div class="topic_details floatleft" style="width: 94%">
  289. <div class="counter">', $message['counter'], '</div>
  290. <h5>', $topic['board']['link'], ' / <a href="', $scripturl, '?topic=', $topic['id'], '.msg', $message['id'], '#msg', $message['id'], '">', $message['subject_highlighted'], '</a></h5>
  291. <span class="smalltext">&#171;&nbsp;',$txt['by'],'&nbsp;<strong>', $message['member']['link'], '</strong>&nbsp;',$txt['on'],'&nbsp;<em>', $message['time'], '</em>&nbsp;&#187;</span>
  292. </div>';
  293. if (!empty($options['display_quick_mod']))
  294. {
  295. echo '
  296. <div class="floatright">';
  297. if ($options['display_quick_mod'] == 1)
  298. {
  299. echo '
  300. <input type="checkbox" name="topics[]" value="', $topic['id'], '" class="input_check">';
  301. }
  302. else
  303. {
  304. if ($topic['quick_mod']['remove'])
  305. echo '
  306. <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>';
  307. if ($topic['quick_mod']['lock'])
  308. echo '
  309. <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>';
  310. if ($topic['quick_mod']['lock'] || $topic['quick_mod']['remove'])
  311. echo '
  312. <br>';
  313. if ($topic['quick_mod']['sticky'])
  314. echo '
  315. <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>';
  316. if ($topic['quick_mod']['move'])
  317. echo '
  318. <a href="', $scripturl, '?action=movetopic;topic=', $topic['id'], '.0"><span class="generic_icons move" title="', $txt['move_topic'], '"></span></a>';
  319. }
  320. echo '
  321. </div>';
  322. }
  323. if ($message['body_highlighted'] != '')
  324. echo '
  325. <br class="clear">
  326. <div class="list_posts double_height">', $message['body_highlighted'], '</div>';
  327. }
  328. echo '
  329. </div>
  330. </div>
  331. </div>';
  332. }
  333. if (!empty($context['topics']))
  334. echo '
  335. <div class="pagesection">
  336. <span>', $context['page_index'], '</span>
  337. </div>';
  338. if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']))
  339. {
  340. echo '
  341. <div class="titlebg2" style="padding: 4px;">
  342. <div class="floatright flow_auto">
  343. <select class="qaction" name="qaction"', $context['can_move'] ? ' onchange="this.form.move_to.disabled = (this.options[this.selectedIndex].value != \'move\');"' : '', '>
  344. <option value="">--------</option>';
  345. foreach ($context['qmod_actions'] as $qmod_action)
  346. if ($context['can_' . $qmod_action])
  347. echo '
  348. <option value="' . $qmod_action . '">' . $txt['quick_mod_' . $qmod_action] . '</option>';
  349. echo '
  350. </select>';
  351. if ($context['can_move'])
  352. echo '
  353. <span id="quick_mod_jump_to">&nbsp;</span>';
  354. echo '
  355. <input type="hidden" name="redirect_url" value="', $scripturl . '?action=search2;params=' . $context['params'], '">
  356. <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;"/>
  357. </div>
  358. </div>';
  359. }
  360. if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']))
  361. echo '
  362. <input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '">
  363. </form>';
  364. }
  365. else
  366. {
  367. echo '
  368. <div class="cat_bar">
  369. <h3 class="catbg">
  370. <img class="centericon" src="' . $settings['images_url'] . '/buttons/search_hd.png" alt="?">&nbsp;', $txt['mlist_search_results'],':&nbsp;',$context['search_params']['search'],'
  371. </h3>
  372. </div>
  373. <div class="pagesection">
  374. <span>', $context['page_index'], '</span>
  375. </div>';
  376. if (empty($context['topics']))
  377. echo '
  378. <div class="information">(', $txt['search_no_results'], ')</div>';
  379. while ($topic = $context['get_topics']())
  380. {
  381. foreach ($topic['matches'] as $message)
  382. {
  383. echo '
  384. <div class="search_results_posts">
  385. <div class="', $message['alternate'] == 0 ? 'windowbg' : 'windowbg2', ' core_posts">
  386. <div class="content">
  387. <div class="counter">', $message['counter'], '</div>
  388. <div class="topic_details">
  389. <h5>', $topic['board']['link'], ' / <a href="', $scripturl, '?topic=', $topic['id'], '.', $message['start'], ';topicseen#msg', $message['id'], '">', $message['subject_highlighted'], '</a></h5>
  390. <span class="smalltext">&#171;&nbsp;', $txt['message'], ' ', $txt['by'], ' <strong>', $message['member']['link'], ' </strong>', $txt['on'], '&nbsp;<em>', $message['time'], '</em>&nbsp;&#187;</span>
  391. </div>
  392. <div class="list_posts">', $message['body_highlighted'], '</div>';
  393. if ($topic['can_reply'] || $topic['can_mark_notify'])
  394. echo '
  395. <div class="quickbuttons_wrap">
  396. <ul class="reset smalltext quickbuttons">';
  397. // If they *can* reply?
  398. if ($topic['can_reply'])
  399. echo '
  400. <li><a href="', $scripturl . '?action=post;topic=' . $topic['id'] . '.' . $message['start'], '" class="reply_button">', $txt['reply'], '</a></li>';
  401. // If they *can* quote?
  402. if ($topic['can_quote'])
  403. echo '
  404. <li><a href="', $scripturl . '?action=post;topic=' . $topic['id'] . '.' . $message['start'] . ';quote=' . $message['id'] . '" class="quote_button">', $txt['quote_action'], '</a></li>';
  405. // Can we request notification of topics?
  406. if ($topic['can_mark_notify'])
  407. echo '
  408. <li><a href="', $scripturl . '?action=notify;topic=' . $topic['id'] . '.' . $message['start'], '" class="notify_button">', $txt['notify'], '</a></li>';
  409. if ($topic['can_reply'] || $topic['can_mark_notify'])
  410. echo '
  411. </ul>
  412. </div>';
  413. echo '
  414. <br class="clear">
  415. </div>
  416. </div>
  417. </div>';
  418. }
  419. }
  420. echo '
  421. <div class="pagesection">
  422. <span>', $context['page_index'], '</span>
  423. </div>';
  424. }
  425. // Show a jump to box for easy navigation.
  426. echo '
  427. <br class="clear">
  428. <div class="smalltext righttext" id="search_jump_to">&nbsp;</div>
  429. <script><!-- // --><![CDATA[';
  430. if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']) && $context['can_move'])
  431. echo '
  432. if (typeof(window.XMLHttpRequest) != "undefined")
  433. aJumpTo[aJumpTo.length] = new JumpTo({
  434. sContainerId: "quick_mod_jump_to",
  435. sClassName: "qaction",
  436. sJumpToTemplate: "%dropdown_list%",
  437. sCurBoardName: "', $context['jump_to']['board_name'], '",
  438. sBoardChildLevelIndicator: "==",
  439. sBoardPrefix: "=> ",
  440. sCatSeparator: "-----------------------------",
  441. sCatPrefix: "",
  442. bNoRedirect: true,
  443. bDisabled: true,
  444. sCustomName: "move_to"
  445. });';
  446. echo '
  447. if (typeof(window.XMLHttpRequest) != "undefined")
  448. aJumpTo[aJumpTo.length] = new JumpTo({
  449. sContainerId: "search_jump_to",
  450. sJumpToTemplate: "<label class=\"smalltext\" for=\"%select_id%\">', $context['jump_to']['label'], ':<" + "/label> %dropdown_list%",
  451. iCurBoardId: 0,
  452. iCurBoardChildLevel: 0,
  453. sCurBoardName: "', $context['jump_to']['board_name'], '",
  454. sBoardChildLevelIndicator: "==",
  455. sBoardPrefix: "=> ",
  456. sCatSeparator: "-----------------------------",
  457. sCatPrefix: "",
  458. sGoButtonLabel: "', $txt['quick_mod_go'], '"
  459. });
  460. // ]]></script>';
  461. }
  462. ?>