PageRenderTime 47ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/Themes/default/Search.template.php

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