index.template.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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. /* This template is, perhaps, the most important template in the theme. It
  13. contains the main template layer that displays the header and footer of
  14. the forum, namely with main_above and main_below. It also contains the
  15. menu sub template, which appropriately displays the menu; the init sub
  16. template, which is there to set the theme up; (init can be missing.) and
  17. the linktree sub template, which sorts out the link tree.
  18. The init sub template should load any data and set any hardcoded options.
  19. The main_above sub template is what is shown above the main content, and
  20. should contain anything that should be shown up there.
  21. The main_below sub template, conversely, is shown after the main content.
  22. It should probably contain the copyright statement and some other things.
  23. The linktree sub template should display the link tree, using the data
  24. in the $context['linktree'] variable.
  25. The menu sub template should display all the relevant buttons the user
  26. wants and or needs.
  27. For more information on the templating system, please see the site at:
  28. http://www.simplemachines.org/
  29. */
  30. /**
  31. * Initialize the template... mainly little settings.
  32. */
  33. function template_init()
  34. {
  35. global $settings;
  36. /* $context, $options and $txt may be available for use, but may not be fully populated yet. */
  37. /* Use images from default theme when using templates from the default theme?
  38. if this is 'always', images from the default theme will be used.
  39. if this is 'defaults', images from the default theme will only be used with default templates.
  40. if this is 'never' or isn't set at all, images from the default theme will not be used. */
  41. $settings['use_default_images'] = 'never';
  42. // The version this template/theme is for. This should probably be the version of SMF it was created for.
  43. $settings['theme_version'] = '2.1';
  44. // Use plain buttons - as opposed to text buttons?
  45. $settings['use_buttons'] = true;
  46. // Show sticky and lock status separate from topic icons?
  47. $settings['separate_sticky_lock'] = true;
  48. // Set the following variable to true if this theme requires the optional theme strings file to be loaded.
  49. $settings['require_theme_strings'] = false;
  50. // Set the following variable to true is this theme wants to display the avatar of the user that posted the last post on the board index and message index
  51. $settings['avatars_on_indexes'] = false;
  52. }
  53. /**
  54. * The main sub template above the content.
  55. */
  56. function template_html_above()
  57. {
  58. global $context, $settings, $scripturl, $txt, $modSettings;
  59. // Show right to left and the character set for ease of translating.
  60. echo '<!DOCTYPE html>
  61. <html', $context['right_to_left'] ? ' dir="rtl"' : '', '>
  62. <head>';
  63. // You don't need to manually load index.css, this will be set up for you. You can, of course, add
  64. // any other files you want, after template_css() has been run. Note that RTL will also be loaded for you.
  65. // The most efficient way of writing multi themes is to use a master index.css plus variant.css files.
  66. // If you've set them up properly (through $settings['theme_variants'], loadCSSFile will load the variant files for you.
  67. // load in any css from mods or themes so they can overwrite if wanted
  68. template_css();
  69. // Save some database hits, if a width for multiple wrappers is set in admin.
  70. if (!empty($settings['forum_width']))
  71. echo '
  72. <style type="text/css">#wrapper, .frame {width: ', $settings['forum_width'], ';}</style>';
  73. // load in any javascript files from mods and themes
  74. template_javascript();
  75. echo '
  76. <meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '">
  77. <meta name="description" content="', !empty($context['meta_description']) ? $context['meta_description'] : $context['page_title_html_safe'], '">', !empty($context['meta_keywords']) ? '
  78. <meta name="keywords" content="' . $context['meta_keywords'] . '">' : '', '
  79. <title>', $context['page_title_html_safe'], '</title>';
  80. // Please don't index these Mr Robot.
  81. if (!empty($context['robot_no_index']))
  82. echo '
  83. <meta name="robots" content="noindex">';
  84. // Present a canonical url for search engines to prevent duplicate content in their indices.
  85. if (!empty($context['canonical_url']))
  86. echo '
  87. <link rel="canonical" href="', $context['canonical_url'], '">';
  88. // Show all the relative links, such as help, search, contents, and the like.
  89. echo '
  90. <link rel="help" href="', $scripturl, '?action=help">
  91. <link rel="contents" href="', $scripturl, '">', ($context['allow_search'] ? '
  92. <link rel="search" href="' . $scripturl . '?action=search">' : '');
  93. // If RSS feeds are enabled, advertise the presence of one.
  94. if (!empty($modSettings['xmlnews_enable']) && (!empty($modSettings['allow_guestAccess']) || $context['user']['is_logged']))
  95. echo '
  96. <link rel="alternate" type="application/rss+xml" title="', $context['forum_name_html_safe'], ' - ', $txt['rss'], '" href="', $scripturl, '?type=rss2;action=.xml">
  97. <link rel="alternate" type="application/rss+xml" title="', $context['forum_name_html_safe'], ' - ', $txt['atom'], '" href="', $scripturl, '?type=atom;action=.xml">';
  98. // If we're viewing a topic, these should be the previous and next topics, respectively.
  99. if (!empty($context['links']['next']))
  100. {
  101. echo '
  102. <link rel="next" href="', $context['links']['next'], '">';
  103. }
  104. if (!empty($context['links']['prev']))
  105. {
  106. echo '
  107. <link rel="prev" href="', $context['links']['prev'], '">';
  108. }
  109. // If we're in a board, or a topic for that matter, the index will be the board's index.
  110. if (!empty($context['current_board']))
  111. echo '
  112. <link rel="index" href="', $scripturl, '?board=', $context['current_board'], '.0">';
  113. // Output any remaining HTML headers. (from mods, maybe?)
  114. echo $context['html_headers'];
  115. echo '
  116. </head>
  117. <body id="', $context['browser_body_id'], '" class="action_', !empty($context['current_action']) ? $context['current_action'] : (!empty($context['current_board']) ?
  118. 'messageindex' : (!empty($context['current_topic']) ? 'display' : 'home')), !empty($context['current_board']) ? ' board_' . $context['current_board'] : '', '">';
  119. }
  120. function template_body_above()
  121. {
  122. global $context, $settings, $scripturl, $txt, $modSettings;
  123. // Wrapper div now echoes permanently for better layout options. h1 a is now target for "Go up" links.
  124. echo '
  125. <div id="top_section">
  126. <div class="frame">';
  127. // If the user is logged in, display some things that might be useful.
  128. if ($context['user']['is_logged'])
  129. {
  130. // Firstly, the user's menu
  131. echo '
  132. <ul class="floatleft" id="top_info">
  133. <li>
  134. <a href="', $scripturl, '?action=profile"', !empty($context['self_profile']) ? ' class="active"' : '', ' id="profile_menu_top" onclick="return false;">', $context['user']['name'], ' &#9660;</a>
  135. <div id="profile_menu" class="top_menu"></div>
  136. </li>';
  137. // Secondly, PMs if we're doing them
  138. if ($context['allow_pm'])
  139. {
  140. echo '
  141. <li>
  142. <a href="', $scripturl, '?action=pm"', !empty($context['self_pm']) ? ' class="active"' : '', ' id="pm_menu_top">', $txt['pm_short'], !empty($context['user']['unread_messages']) ? ' <span class="amt">' . $context['user']['unread_messages'] . '</span>' : '', '</a>
  143. <div id="pm_menu" class="top_menu"></div>
  144. </li>';
  145. }
  146. // Thirdly, alerts
  147. echo '
  148. <li>
  149. <a href="', $scripturl, '?action=alerts"', !empty($context['self_alerts']) ? ' class="active"' : '', ' id="alerts_menu_top">', $txt['alerts'], !empty($context['user']['alerts']) ? ' <span class="amt">' . $context['user']['alerts'] . '</span>' : '', '</a>
  150. <div id="alerts_menu" class="top_menu"></div>
  151. </li>';
  152. // And now we're done.
  153. echo '
  154. </ul>';
  155. }
  156. // Otherwise they're a guest. Ask them to either register or login.
  157. else
  158. echo '
  159. <ul class="floatleft welcome">
  160. <li>', sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $scripturl . '?action=login'), '</li>
  161. </ul>';
  162. if ($context['allow_search'])
  163. {
  164. echo '
  165. <form id="search_form" class="floatright" action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
  166. <input type="text" name="search" value="" class="input_text">&nbsp;';
  167. // Using the quick search dropdown?
  168. if (!empty($modSettings['search_dropdown']))
  169. {
  170. $selected = !empty($context['current_topic']) ? 'current_topic' : (!empty($context['current_board']) ? 'current_board' : 'all');
  171. echo '
  172. <select name="search_selection">
  173. <option value="all"', ($selected == 'all' ? ' selected' : ''), '>', $txt['search_entireforum'], ' </option>';
  174. // Can't limit it to a specific topic if we are not in one
  175. if (!empty($context['current_topic']))
  176. echo '
  177. <option value="topic"', ($selected == 'current_topic' ? ' selected' : ''), '>', $txt['search_thistopic'], '</option>';
  178. // Can't limit it to a specific board if we are not in one
  179. if (!empty($context['current_board']))
  180. echo '
  181. <option value="board"', ($selected == 'current_board' ? ' selected' : ''), '>', $txt['search_thisbrd'], '</option>';
  182. echo '
  183. <option value="members"', ($selected == 'members' ? ' selected' : ''), '>', $txt['search_members'], ' </option>
  184. </select>';
  185. }
  186. // Search within current topic?
  187. if (!empty($context['current_topic']))
  188. echo '
  189. <input type="hidden" name="', (!empty($modSettings['search_dropdown']) ? 'sd_topic' : 'topic'), '" value="', $context['current_topic'], '">';
  190. // If we're on a certain board, limit it to this board ;).
  191. elseif (!empty($context['current_board']))
  192. echo '
  193. <input type="hidden" name="', (!empty($modSettings['search_dropdown']) ? 'sd_brd[' : 'brd['), $context['current_board'], ']"', ' value="', $context['current_board'], '">';
  194. echo '
  195. <input type="submit" name="search2" value="', $txt['search'], '" class="button_submit">
  196. <input type="hidden" name="advanced" value="0">
  197. </form>';
  198. }
  199. echo '
  200. </div>
  201. </div>';
  202. echo '
  203. <div id="header">
  204. <div class="frame">
  205. <h1 class="forumtitle">
  206. <a id="top" href="', $scripturl, '">', empty($context['header_logo_url_html_safe']) ? $context['forum_name'] : '<img src="' . $context['header_logo_url_html_safe'] . '" alt="' . $context['forum_name'] . '">', '</a>
  207. </h1>';
  208. echo '
  209. ', empty($settings['site_slogan']) ? '<img id="smflogo" src="' . $settings['images_url'] . '/smflogo.png" alt="Simple Machines Forum" title="Simple Machines Forum">' : '<div id="siteslogan" class="floatright">' . $settings['site_slogan'] . '</div>', '';
  210. echo'
  211. </div>
  212. </div>
  213. <div id="wrapper">
  214. <div id="upper_section">
  215. <div id="inner_section">
  216. <div id="inner_wrap">
  217. <div class="user">';
  218. // Otherwise they're a guest - this time ask them to either register or login - lazy bums...
  219. if (!empty($context['show_login_bar']))
  220. {
  221. echo '
  222. <script src="', $settings['default_theme_url'], '/scripts/sha1.js"></script>
  223. <form id="guest_form" action="', $scripturl, '?action=login2;quicklogin" method="post" accept-charset="', $context['character_set'], '" ', empty($context['disable_login_hashing']) ? ' onsubmit="hashLoginPassword(this, \'' . $context['session_id'] . '\', \'' . (!empty($context['login_token']) ? $context['login_token'] : '') . '\');"' : '', '>
  224. <input type="text" name="user" size="10" class="input_text">
  225. <input type="password" name="passwrd" size="10" class="input_password">
  226. <select name="cookielength">
  227. <option value="60">', $txt['one_hour'], '</option>
  228. <option value="1440">', $txt['one_day'], '</option>
  229. <option value="10080">', $txt['one_week'], '</option>
  230. <option value="43200">', $txt['one_month'], '</option>
  231. <option value="-1" selected>', $txt['forever'], '</option>
  232. </select>
  233. <input type="submit" value="', $txt['login'], '" class="button_submit">
  234. <div>', $txt['quick_login_dec'], '</div>';
  235. if (!empty($modSettings['enableOpenID']))
  236. echo '
  237. <br><input type="text" name="openid_identifier" size="25" class="input_text openid_login">';
  238. echo '
  239. <input type="hidden" name="hash_passwrd" value="">
  240. <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
  241. <input type="hidden" name="', $context['login_token_var'], '" value="', $context['login_token'], '">
  242. </form>';
  243. }
  244. else
  245. {
  246. echo '
  247. ', $context['current_time'];
  248. }
  249. echo'
  250. </div>';
  251. // Show a random news item? (or you could pick one from news_lines...)
  252. if (!empty($settings['enable_news']) && !empty($context['random_news_line']))
  253. echo '
  254. <div class="news">
  255. <h2>', $txt['news'], ': </h2>
  256. <p>', $context['random_news_line'], '</p>
  257. </div>';
  258. echo '
  259. <hr class="clear">
  260. </div>';
  261. // Show the menu here, according to the menu sub template, followed by the navigation tree.
  262. template_menu();
  263. theme_linktree();
  264. echo '
  265. </div>
  266. </div>';
  267. // The main content should go here.
  268. echo '
  269. <div id="content_section">
  270. <div id="main_content_section">';
  271. }
  272. function template_body_below()
  273. {
  274. global $context, $txt, $scripturl;
  275. echo '
  276. </div>
  277. </div>
  278. </div>';
  279. // Show the XHTML, RSS and WAP2 links, as well as the copyright.
  280. // Footer is now full-width by default. Frame inside it will match theme wrapper width automatically.
  281. echo '
  282. <div id="footer_section">
  283. <div class="frame">';
  284. // There is now a global "Go to top" link at the right.
  285. echo '
  286. <a href="#top_section" id="bot" class="go_up">', $txt['go_up'], '</a>
  287. <ul class="floatright">
  288. <li><a href="', $scripturl, '?action=help">', $txt['help'], '</a> | <a href="', $scripturl, '?action=help;sa=rules">', $txt['terms_and_rules'], '</a></li>
  289. </ul>
  290. <ul class="reset">
  291. <li class="copyright">', theme_copyright(), '</li>
  292. </ul>';
  293. // Show the load time?
  294. if ($context['show_load_time'])
  295. echo '
  296. <p>', sprintf($txt['page_created_full'], $context['load_time'], $context['load_queries']), '</p>';
  297. echo '
  298. </div>
  299. </div>';
  300. }
  301. function template_html_below()
  302. {
  303. // load in any javascipt that could be defered to the end of the page
  304. template_javascript(true);
  305. echo '
  306. </body>
  307. </html>';
  308. }
  309. /**
  310. * Show a linktree. This is that thing that shows "My Community | General Category | General Discussion"..
  311. * @param bool $force_show = false
  312. */
  313. function theme_linktree($force_show = false)
  314. {
  315. global $context, $settings, $shown_linktree, $scripturl, $txt;
  316. // If linktree is empty, just return - also allow an override.
  317. if (empty($context['linktree']) || (!empty($context['dont_default_linktree']) && !$force_show))
  318. return;
  319. echo '
  320. <div class="navigate_section">
  321. <ul>';
  322. if ($context['user']['is_logged'])
  323. echo '
  324. <li class="unread_links">
  325. <a href="', $scripturl, '?action=unread" title="', $txt['unread_since_visit'], '">', $txt['view_unread_category'], '</a>
  326. <a href="', $scripturl, '?action=unreadreplies" title="', $txt['show_unread_replies'], '">', $txt['unread_replies'], '</a>
  327. </li>';
  328. // Each tree item has a URL and name. Some may have extra_before and extra_after.
  329. foreach ($context['linktree'] as $link_num => $tree)
  330. {
  331. echo '
  332. <li', ($link_num == count($context['linktree']) - 1) ? ' class="last"' : '', '>';
  333. // Don't show a separator for the first one.
  334. // Better here. Always points to the next level when the linktree breaks to a second line.
  335. // Picked a better looking HTML entity, and added support for RTL plus a span for styling.
  336. if ($link_num != 0)
  337. echo '
  338. <span class="dividers">', $context['right_to_left'] ? ' &#9668; ' : ' &#9658; ', '</span>';
  339. // Show something before the link?
  340. if (isset($tree['extra_before']))
  341. echo $tree['extra_before'], ' ';
  342. // Show the link, including a URL if it should have one.
  343. echo isset($tree['url']) ? '
  344. <a href="' . $tree['url'] . '"><span>' . $tree['name'] . '</span></a>' : '<span>' . $tree['name'] . '</span>';
  345. // Show something after the link...?
  346. if (isset($tree['extra_after']))
  347. echo ' ', $tree['extra_after'];
  348. echo '
  349. </li>';
  350. }
  351. echo '
  352. </ul>
  353. </div>';
  354. $shown_linktree = true;
  355. }
  356. /**
  357. * Show the menu up top. Something like [home] [help] [profile] [logout]...
  358. */
  359. function template_menu()
  360. {
  361. global $context;
  362. echo '
  363. <div id="main_menu">
  364. <ul class="dropmenu" id="menu_nav">';
  365. // Note: Menu markup has been cleaned up to remove unnecessary spans and classes.
  366. foreach ($context['menu_buttons'] as $act => $button)
  367. {
  368. echo '
  369. <li id="button_', $act, '"', !empty($button['sub_buttons']) ? ' class="subsections"' :'', '>
  370. <a', $button['active_button'] ? ' class="active"' : '', ' href="', $button['href'], '"', isset($button['target']) ? ' target="' . $button['target'] . '"' : '', '>
  371. ', $button['title'], '
  372. </a>';
  373. if (!empty($button['sub_buttons']))
  374. {
  375. echo '
  376. <ul>';
  377. foreach ($button['sub_buttons'] as $childbutton)
  378. {
  379. echo '
  380. <li', !empty($childbutton['sub_buttons']) ? ' class="subsections"' :'', '>
  381. <a href="', $childbutton['href'], '"' , isset($childbutton['target']) ? ' target="' . $childbutton['target'] . '"' : '', '>
  382. ', $childbutton['title'], '
  383. </a>';
  384. // 3rd level menus :)
  385. if (!empty($childbutton['sub_buttons']))
  386. {
  387. echo '
  388. <ul>';
  389. foreach ($childbutton['sub_buttons'] as $grandchildbutton)
  390. echo '
  391. <li>
  392. <a href="', $grandchildbutton['href'], '"' , isset($grandchildbutton['target']) ? ' target="' . $grandchildbutton['target'] . '"' : '', '>
  393. ', $grandchildbutton['title'], '
  394. </a>
  395. </li>';
  396. echo '
  397. </ul>';
  398. }
  399. echo '
  400. </li>';
  401. }
  402. echo '
  403. </ul>';
  404. }
  405. echo '
  406. </li>';
  407. }
  408. echo '
  409. </ul>
  410. </div>';
  411. }
  412. /**
  413. * Generate a strip of buttons.
  414. * @param array $button_strip
  415. * @param string $direction = ''
  416. * @param array $strip_options = array()
  417. */
  418. function template_button_strip($button_strip, $direction = '', $strip_options = array())
  419. {
  420. global $context, $txt;
  421. if (!is_array($strip_options))
  422. $strip_options = array();
  423. // List the buttons in reverse order for RTL languages.
  424. if ($context['right_to_left'])
  425. $button_strip = array_reverse($button_strip, true);
  426. // Create the buttons...
  427. $buttons = array();
  428. foreach ($button_strip as $key => $value)
  429. {
  430. // @todo this check here doesn't make much sense now (from 2.1 on), it should be moved to where the button array is generated
  431. // Kept for backward compatibility
  432. if (!isset($value['test']) || !empty($context[$value['test']]))
  433. $buttons[] = '
  434. <li><a' . (isset($value['id']) ? ' id="button_strip_' . $value['id'] . '"' : '') . ' class="button_strip_' . $key . (!empty($value['active']) ? ' active' : '') . '" href="' . $value['url'] . '"' . (isset($value['custom']) ? ' ' . $value['custom'] : '') . '><span>' . $txt[$value['text']] . '</span></a></li>';
  435. }
  436. // No buttons? No button strip either.
  437. if (empty($buttons))
  438. return;
  439. echo '
  440. <div class="buttonlist', !empty($direction) ? ' float' . $direction : '', '"', (empty($buttons) ? ' style="display: none;"' : ''), (!empty($strip_options['id']) ? ' id="' . $strip_options['id'] . '"': ''), '>
  441. <ul>',
  442. implode('', $buttons), '
  443. </ul>
  444. </div>';
  445. }
  446. function template_maint_warning_above()
  447. {
  448. global $txt, $context, $scripturl;
  449. echo '
  450. <div class="errorbox" id="errors">
  451. <dl>
  452. <dt>
  453. <strong id="error_serious">', $txt['forum_in_maintainence'], '</strong>
  454. </dt>
  455. <dd class="error" id="error_list">
  456. ', sprintf($txt['maintenance_page'], $scripturl . '?action=admin;area=serversettings;' . $context['session_var'] . '=' . $context['session_id']), '
  457. </dd>
  458. </dl>
  459. </div>';
  460. }
  461. function template_maint_warning_below()
  462. {
  463. }
  464. ?>