index.template.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines
  7. * @copyright 2013 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 $context, $settings, $options, $txt;
  36. /* Use images from default theme when using templates from the default theme?
  37. if this is 'always', images from the default theme will be used.
  38. if this is 'defaults', images from the default theme will only be used with default templates.
  39. if this is 'never' or isn't set at all, images from the default theme will not be used. */
  40. $settings['use_default_images'] = 'never';
  41. /* What document type definition is being used? (for font size and other issues.)
  42. 'xhtml' for an XHTML 1.0 document type definition.
  43. 'html' for an HTML 4.01 document type definition. */
  44. $settings['doctype'] = 'xhtml';
  45. // The version this template/theme is for. This should probably be the version of SMF it was created for.
  46. $settings['theme_version'] = '2.0';
  47. // Use plain buttons - as opposed to text buttons?
  48. $settings['use_buttons'] = true;
  49. // Show sticky and lock status separate from topic icons?
  50. $settings['separate_sticky_lock'] = true;
  51. // Does this theme use the strict doctype?
  52. $settings['strict_doctype'] = false;
  53. // Set the following variable to true if this theme requires the optional theme strings file to be loaded.
  54. $settings['require_theme_strings'] = false;
  55. // 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
  56. $settings['avatars_on_indexes'] = false;
  57. }
  58. /**
  59. * The main sub template above the content.
  60. */
  61. function template_html_above()
  62. {
  63. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  64. // Show right to left and the character set for ease of translating.
  65. echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  66. <html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
  67. <head>';
  68. // The ?alp21 part of this link is just here to make sure browsers don't cache it wrongly.
  69. echo '
  70. <link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index.css?alp21" />';
  71. // The most efficient way of writing multi themes is to use a master index.css plus variant.css files.
  72. if (!empty($context['theme_variant']))
  73. echo '
  74. <link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?alp21" />';
  75. // Save some database hits, if a width for multiple wrappers is set in admin.
  76. if (!empty($settings['forum_width']))
  77. echo '
  78. <style type="text/css">#wrapper, .frame {width: ', $settings['forum_width'], ';}</style>';
  79. // Quick and dirty testing of RTL horrors. Remove before production build.
  80. //echo '
  81. //<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/rtl.css?alp21" />';
  82. // load in any css from mods or themes so they can overwrite if wanted
  83. template_css();
  84. // load in any javascript files from mods and themes
  85. template_javascript();
  86. // RTL languages require an additional stylesheet.
  87. if ($context['right_to_left'])
  88. {
  89. echo '
  90. <link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/rtl.css?alp21" />';
  91. if (!empty($context['theme_variant']))
  92. echo '
  93. <link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/rtl', $context['theme_variant'], '.css?alp21" />';
  94. }
  95. echo '
  96. <meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
  97. <meta name="description" content="', $context['page_title_html_safe'], '" />', !empty($context['meta_keywords']) ? '
  98. <meta name="keywords" content="' . $context['meta_keywords'] . '" />' : '', '
  99. <title>', $context['page_title_html_safe'], '</title>';
  100. // Please don't index these Mr Robot.
  101. if (!empty($context['robot_no_index']))
  102. echo '
  103. <meta name="robots" content="noindex" />';
  104. // Present a canonical url for search engines to prevent duplicate content in their indices.
  105. if (!empty($context['canonical_url']))
  106. echo '
  107. <link rel="canonical" href="', $context['canonical_url'], '" />';
  108. // Show all the relative links, such as help, search, contents, and the like.
  109. echo '
  110. <link rel="help" href="', $scripturl, '?action=help" />
  111. <link rel="contents" href="', $scripturl, '" />', ($context['allow_search'] ? '
  112. <link rel="search" href="' . $scripturl . '?action=search" />' : '');
  113. // If RSS feeds are enabled, advertise the presence of one.
  114. if (!empty($modSettings['xmlnews_enable']) && (!empty($modSettings['allow_guestAccess']) || $context['user']['is_logged']))
  115. echo '
  116. <link rel="alternate" type="application/rss+xml" title="', $context['forum_name_html_safe'], ' - ', $txt['rss'], '" href="', $scripturl, '?type=rss2;action=.xml" />
  117. <link rel="alternate" type="application/rss+xml" title="', $context['forum_name_html_safe'], ' - ', $txt['atom'], '" href="', $scripturl, '?type=atom;action=.xml" />';
  118. // If we're viewing a topic, these should be the previous and next topics, respectively.
  119. if (!empty($context['links']['next']))
  120. echo '<link rel="next" href="', $context['links']['next'], '" />';
  121. else if (!empty($context['current_topic']))
  122. echo '<link rel="next" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=next" />';
  123. if (!empty($context['links']['prev']))
  124. echo '<link rel="prev" href="', $context['links']['prev'], '" />';
  125. else if (!empty($context['current_topic']))
  126. echo '<link rel="prev" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=prev" />';
  127. // If we're in a board, or a topic for that matter, the index will be the board's index.
  128. if (!empty($context['current_board']))
  129. echo '
  130. <link rel="index" href="', $scripturl, '?board=', $context['current_board'], '.0" />';
  131. // Output any remaining HTML headers. (from mods, maybe?)
  132. echo $context['html_headers'];
  133. echo '
  134. </head>
  135. <body id="', $context['browser_body_id'], '" class="action_', !empty($context['current_action']) ? $context['current_action'] : (!empty($context['current_board']) ?
  136. 'messageindex' : (!empty($context['current_topic']) ? 'display' : 'home')), !empty($context['current_board']) ? ' board_' . $context['current_board'] : '', '">';
  137. }
  138. function template_body_above()
  139. {
  140. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  141. // Wrapper div now echoes permanently for better layout options. h1 a is now target for "Go up" links.
  142. echo '
  143. <div id="top_section">
  144. <div class="frame">
  145. <ul class="floatleft">';
  146. // If the user is logged in, display the time, or a maintenance warning for admins.
  147. if ($context['user']['is_logged'])
  148. {
  149. // Is the forum in maintenance mode?
  150. if ($context['in_maintenance'] && $context['user']['is_admin'])
  151. echo '
  152. <li class="notice">', $txt['maintain_mode_on'], '<br /></li>';
  153. if (!empty($context['open_mod_reports']) && $context['show_open_reports'])
  154. echo '
  155. <li class="modnotice"><a href="', $scripturl, '?action=moderate;area=reports">', $txt['mod_reports_waiting'], '</a>: <span class="amt">', $context['open_mod_reports'], '</span></li>';
  156. // Are there any members waiting for approval?
  157. if (!empty($context['unapproved_members']))
  158. echo '
  159. <li class="modnotice"><a href="', $scripturl, '?action=admin;area=viewmembers;sa=browse;type=approve">', $txt['approve_members_waiting'], '</a>: <span class="amt">', $context['unapproved_members'], '</span></li>';
  160. }
  161. // Otherwise they're a guest. Ask them to either register or login.
  162. else
  163. echo '
  164. <li>', sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $scripturl . '?action=login'), '</li>';
  165. echo '
  166. </ul>';
  167. if ($context['allow_search'])
  168. {
  169. echo '
  170. <form id="search_form" class="floatright" action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
  171. <input type="text" name="search" value="" class="input_text" />&nbsp;';
  172. // Using the quick search dropdown?
  173. if (!empty($modSettings['search_dropdown']))
  174. {
  175. $selected = !empty($context['current_topic']) ? 'current_topic' : (!empty($context['current_board']) ? 'current_board' : 'all');
  176. echo '
  177. <select name="search_selection">
  178. <option value="all"', ($selected == 'all' ? ' selected="selected"' : ''), '>', $txt['search_entireforum'], ' </option>';
  179. // Can't limit it to a specific topic if we are not in one
  180. if (!empty($context['current_topic']))
  181. echo '
  182. <option value="topic"', ($selected == 'current_topic' ? ' selected="selected"' : ''), '>', $txt['search_thistopic'], '</option>';
  183. // Can't limit it to a specific board if we are not in one
  184. if (!empty($context['current_board']))
  185. echo '
  186. <option value="board"', ($selected == 'current_board' ? ' selected="selected"' : ''), '>', $txt['search_thisbrd'], '</option>';
  187. echo '
  188. <option value="members"', ($selected == 'members' ? ' selected="selected"' : ''), '>', $txt['search_members'], ' </option>
  189. </select>';
  190. }
  191. // Search within current topic?
  192. if (!empty($context['current_topic']))
  193. echo '
  194. <input type="hidden" name="', (!empty($modSettings['search_dropdown']) ? 'sd_topic' : 'topic'), '" value="', $context['current_topic'], '" />';
  195. // If we're on a certain board, limit it to this board ;).
  196. elseif (!empty($context['current_board']))
  197. echo '
  198. <input type="hidden" name="', (!empty($modSettings['search_dropdown']) ? 'sd_brd[' : 'brd['), $context['current_board'], ']"', ' value="', $context['current_board'], '" />';
  199. echo '
  200. <input type="submit" name="search2" value="', $txt['search'], '" class="button_submit" />
  201. <input type="hidden" name="advanced" value="0" />
  202. </form>';
  203. }
  204. echo '
  205. </div>
  206. </div>';
  207. echo '
  208. <div id="header">
  209. <div class="frame">
  210. <h1 class="forumtitle">
  211. <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>
  212. </h1>';
  213. echo '
  214. ', 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>', '';
  215. echo'
  216. </div>
  217. </div>
  218. <div id="wrapper">
  219. <div id="upper_section">
  220. <div id="inner_section">
  221. <div id="inner_wrap">
  222. <div class="user floatright">';
  223. // Otherwise they're a guest - this time ask them to either register or login - lazy bums...
  224. if (!empty($context['show_login_bar']))
  225. {
  226. echo '
  227. <script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/sha1.js"></script>
  228. <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'] : '') . '\');"' : '', '>
  229. <input type="text" name="user" size="10" class="input_text" />
  230. <input type="password" name="passwrd" size="10" class="input_password" />
  231. <select name="cookielength">
  232. <option value="60">', $txt['one_hour'], '</option>
  233. <option value="1440">', $txt['one_day'], '</option>
  234. <option value="10080">', $txt['one_week'], '</option>
  235. <option value="43200">', $txt['one_month'], '</option>
  236. <option value="-1" selected="selected">', $txt['forever'], '</option>
  237. </select>
  238. <input type="submit" value="', $txt['login'], '" class="button_submit" />
  239. <div>', $txt['quick_login_dec'], '</div>';
  240. if (!empty($modSettings['enableOpenID']))
  241. echo '
  242. <br /><input type="text" name="openid_identifier" size="25" class="input_text openid_login" />';
  243. echo '
  244. <input type="hidden" name="hash_passwrd" value="" />
  245. <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
  246. <input type="hidden" name="', $context['login_token_var'], '" value="', $context['login_token'], '" />
  247. </form>';
  248. }
  249. // If the user is logged in, display stuff like their name, new messages, etc.
  250. if ($context['user']['is_logged'])
  251. {
  252. if (!empty($context['user']['avatar']))
  253. echo '
  254. <a href="', $scripturl, '?action=profile" class="avatar">', $context['user']['avatar']['image'], '</a>';
  255. echo '
  256. <ul>
  257. <li class="greeting">', $txt['hello_member_ndt'], ' <span>', $context['user']['name'], '</span></li>
  258. <li>', $context['current_time'], '</li>
  259. </ul>';
  260. }
  261. echo'
  262. </div>';
  263. // Show a random news item? (or you could pick one from news_lines...)
  264. if (!empty($settings['enable_news']) && !empty($context['random_news_line']))
  265. echo '
  266. <div class="news">
  267. <h2>', $txt['news'], ': </h2>
  268. <p>', $context['random_news_line'], '</p>
  269. </div>';
  270. echo '
  271. <hr class="clear" />
  272. </div>';
  273. // Show the menu here, according to the menu sub template, followed by the navigation tree.
  274. template_menu();
  275. theme_linktree();
  276. echo '
  277. </div>
  278. </div>';
  279. // The main content should go here.
  280. echo '
  281. <div id="content_section">
  282. <div id="main_content_section">';
  283. }
  284. function template_body_below()
  285. {
  286. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  287. echo '
  288. </div>
  289. </div>
  290. </div>';
  291. // Show the XHTML, RSS and WAP2 links, as well as the copyright.
  292. // Footer is now full-width by default. Frame inside it will match theme wrapper width automatically.
  293. echo '
  294. <div id="footer_section">
  295. <div class="frame">';
  296. // There is now a global "Go to top" link at the right.
  297. echo '
  298. <a href="#top" id="bot" class="go_up">', $txt['go_up'], '</a>
  299. <ul class="reset">
  300. <li class="copyright">', theme_copyright(), '</li>
  301. </ul>';
  302. // Show the load time?
  303. if ($context['show_load_time'])
  304. echo '
  305. <p>', sprintf($txt['page_created_full'], $context['load_time'], $context['load_queries']), '</p>';
  306. echo '
  307. </div>
  308. </div>';
  309. }
  310. function template_html_below()
  311. {
  312. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  313. // load in any javascipt that could be defered to the end of the page
  314. template_javascript(true);
  315. echo '
  316. </body>
  317. </html>';
  318. }
  319. /**
  320. * Show a linktree. This is that thing that shows "My Community | General Category | General Discussion"..
  321. * @param bool $force_show = false
  322. */
  323. function theme_linktree($force_show = false)
  324. {
  325. global $context, $settings, $options, $shown_linktree, $scripturl, $txt;
  326. // If linktree is empty, just return - also allow an override.
  327. if (empty($context['linktree']) || (!empty($context['dont_default_linktree']) && !$force_show))
  328. return;
  329. echo '
  330. <div class="navigate_section">
  331. <ul>';
  332. if ($context['user']['is_logged'])
  333. echo '
  334. <li class="unread_links">
  335. <a href="', $scripturl, '?action=unread" title="', $txt['unread_since_visit'], '">', $txt['view_unread_category'], '</a>
  336. <a href="', $scripturl, '?action=unreadreplies" title="', $txt['show_unread_replies'], '">', $txt['unread_replies'], '</a>
  337. </li>';
  338. // Each tree item has a URL and name. Some may have extra_before and extra_after.
  339. foreach ($context['linktree'] as $link_num => $tree)
  340. {
  341. echo '
  342. <li', ($link_num == count($context['linktree']) - 1) ? ' class="last"' : '', '>';
  343. // Don't show a separator for the first one.
  344. // Better here. Always points to the next level when the linktree breaks to a second line.
  345. // Picked a better looking HTML entity, and added support for RTL plus a span for styling.
  346. if ($link_num != 0)
  347. echo '
  348. <span class="dividers">', $context['right_to_left'] ? ' &#9668; ' : ' &#9658; ', '</span>';
  349. // Show something before the link?
  350. if (isset($tree['extra_before']))
  351. echo $tree['extra_before'];
  352. // Show the link, including a URL if it should have one.
  353. echo $settings['linktree_link'] && isset($tree['url']) ? '
  354. <a href="' . $tree['url'] . '"><span>' . $tree['name'] . '</span></a>' : '<span>' . $tree['name'] . '</span>';
  355. // Show something after the link...?
  356. if (isset($tree['extra_after']))
  357. echo $tree['extra_after'];
  358. echo '
  359. </li>';
  360. }
  361. echo '
  362. </ul>
  363. </div>';
  364. $shown_linktree = true;
  365. }
  366. /**
  367. * Show the menu up top. Something like [home] [help] [profile] [logout]...
  368. */
  369. function template_menu()
  370. {
  371. global $context, $settings, $options, $scripturl, $txt;
  372. echo '
  373. <div id="main_menu">
  374. <ul class="dropmenu" id="menu_nav">';
  375. // Note: Menu markup has been cleaned up to remove unnecessary spans and classes.
  376. foreach ($context['menu_buttons'] as $act => $button)
  377. {
  378. echo '
  379. <li id="button_', $act, '" ', !empty($button['sub_buttons']) ? 'class="subsections"' :'', '>
  380. <a class="', $button['active_button'] ? 'active' : '', '" href="', $button['href'], '" ', isset($button['target']) ? 'target="' . $button['target'] . '"' : '', '>
  381. ', $button['title'], '
  382. </a>';
  383. if (!empty($button['sub_buttons']))
  384. {
  385. echo '
  386. <ul>';
  387. foreach ($button['sub_buttons'] as $childbutton)
  388. {
  389. echo '
  390. <li ', !empty($childbutton['sub_buttons']) ? 'class="subsections"' :'', '>
  391. <a href="', $childbutton['href'], '" ' , isset($childbutton['target']) ? 'target="' . $childbutton['target'] . '"' : '', '>
  392. ', $childbutton['title'], '
  393. </a>';
  394. // 3rd level menus :)
  395. if (!empty($childbutton['sub_buttons']))
  396. {
  397. echo '
  398. <ul>';
  399. foreach ($childbutton['sub_buttons'] as $grandchildbutton)
  400. echo '
  401. <li>
  402. <a href="', $grandchildbutton['href'], '" ' , isset($grandchildbutton['target']) ? 'target="' . $grandchildbutton['target'] . '"' : '', '>
  403. ', $grandchildbutton['title'], '
  404. </a>
  405. </li>';
  406. echo '
  407. </ul>';
  408. }
  409. echo '
  410. </li>';
  411. }
  412. echo '
  413. </ul>';
  414. }
  415. echo '
  416. </li>';
  417. }
  418. echo '
  419. </ul>
  420. </div>';
  421. }
  422. /**
  423. * Generate a strip of buttons.
  424. * @param array $button_strip
  425. * @param string $direction = ''
  426. * @param array $strip_options = array()
  427. */
  428. function template_button_strip($button_strip, $direction = '', $strip_options = array())
  429. {
  430. global $settings, $context, $txt, $scripturl;
  431. if (!is_array($strip_options))
  432. $strip_options = array();
  433. // List the buttons in reverse order for RTL languages.
  434. if ($context['right_to_left'])
  435. $button_strip = array_reverse($button_strip, true);
  436. // Create the buttons...
  437. $buttons = array();
  438. foreach ($button_strip as $key => $value)
  439. {
  440. // @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
  441. // Kept for backward compatibility
  442. if (!isset($value['test']) || !empty($context[$value['test']]))
  443. $buttons[] = '
  444. <li><a' . (isset($value['id']) ? ' id="button_strip_' . $value['id'] . '"' : '') . ' class="button_strip_' . $key . (isset($value['active']) ? ' active' : '') . '" href="' . $value['url'] . '"' . (isset($value['custom']) ? ' ' . $value['custom'] : '') . '><span>' . $txt[$value['text']] . '</span></a></li>';
  445. }
  446. // No buttons? No button strip either.
  447. if (empty($buttons))
  448. return;
  449. echo '
  450. <div class="buttonlist', !empty($direction) ? ' float' . $direction : '', '"', (empty($buttons) ? ' style="display: none;"' : ''), (!empty($strip_options['id']) ? ' id="' . $strip_options['id'] . '"': ''), '>
  451. <ul>',
  452. implode('', $buttons), '
  453. </ul>
  454. </div>';
  455. }
  456. ?>