index.template.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines
  7. * @copyright 2011 Simple Machines
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.0
  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. // Initialize the template... mainly little settings.
  31. function template_init()
  32. {
  33. global $context, $settings, $options, $txt;
  34. /* Use images from default theme when using templates from the default theme?
  35. if this is 'always', images from the default theme will be used.
  36. if this is 'defaults', images from the default theme will only be used with default templates.
  37. if this is 'never' or isn't set at all, images from the default theme will not be used. */
  38. $settings['use_default_images'] = 'never';
  39. /* What document type definition is being used? (for font size and other issues.)
  40. 'xhtml' for an XHTML 1.0 document type definition.
  41. 'html' for an HTML 4.01 document type definition. */
  42. $settings['doctype'] = 'xhtml';
  43. /* The version this template/theme is for.
  44. This should probably be the version of SMF it was created for. */
  45. $settings['theme_version'] = '2.0';
  46. /* Set a setting that tells the theme that it can render the tabs. */
  47. $settings['use_tabs'] = true;
  48. /* Use plain buttons - as opposed to text buttons? */
  49. $settings['use_buttons'] = true;
  50. /* Show sticky and lock status separate from topic icons? */
  51. $settings['separate_sticky_lock'] = true;
  52. /* Does this theme use the strict doctype? */
  53. $settings['strict_doctype'] = false;
  54. /* Does this theme use post previews on the message index? */
  55. $settings['message_index_preview'] = false;
  56. /* Set the following variable to true if this theme requires the optional theme strings file to be loaded. */
  57. $settings['require_theme_strings'] = false;
  58. }
  59. // The main sub template above the content.
  60. function template_html_above()
  61. {
  62. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  63. // Show right to left and the character set for ease of translating.
  64. echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  65. <html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
  66. <head>';
  67. // The ?fin20 part of this link is just here to make sure browsers don't cache it wrongly.
  68. echo '
  69. <link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?fin20" />';
  70. // Some browsers need an extra stylesheet due to bugs/compatibility issues.
  71. foreach (array('ie7', 'ie6', 'webkit') as $cssfix)
  72. if ($context['browser']['is_' . $cssfix])
  73. echo '
  74. <link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/css/', $cssfix, '.css" />';
  75. // RTL languages require an additional stylesheet.
  76. if ($context['right_to_left'])
  77. echo '
  78. <link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/rtl.css" />';
  79. // Here comes the JavaScript bits!
  80. echo '
  81. <script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/script.js?fin20"></script>
  82. <script type="text/javascript" src="', $settings['theme_url'], '/scripts/theme.js?fin20"></script>
  83. <script type="text/javascript"><!-- // --><![CDATA[
  84. var smf_theme_url = "', $settings['theme_url'], '";
  85. var smf_default_theme_url = "', $settings['default_theme_url'], '";
  86. var smf_images_url = "', $settings['images_url'], '";
  87. var smf_scripturl = "', $scripturl, '";
  88. var smf_iso_case_folding = ', $context['server']['iso_case_folding'] ? 'true' : 'false', ';
  89. var smf_charset = "', $context['character_set'], '";', $context['show_pm_popup'] ? '
  90. var fPmPopup = function ()
  91. {
  92. if (confirm("' . $txt['show_personal_messages'] . '"))
  93. window.open(smf_prepareScriptUrl(smf_scripturl) + "action=pm");
  94. }
  95. addLoadEvent(fPmPopup);' : '', '
  96. var ajax_notification_text = "', $txt['ajax_in_progress'], '";
  97. var ajax_notification_cancel_text = "', $txt['modify_cancel'], '";
  98. // ]]></script>';
  99. echo '
  100. <meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
  101. <meta name="description" content="', $context['page_title_html_safe'], '" />', !empty($context['meta_keywords']) ? '
  102. <meta name="keywords" content="' . $context['meta_keywords'] . '" />' : '', '
  103. <title>', $context['page_title_html_safe'], '</title>';
  104. // Bad Behavior Start
  105. if (function_exists('bb2_insert_head')) {
  106. bb2_insert_head();
  107. }
  108. // Bad Behavior End
  109. // Please don't index these Mr Robot.
  110. if (!empty($context['robot_no_index']))
  111. echo '
  112. <meta name="robots" content="noindex" />';
  113. // Present a canonical url for search engines to prevent duplicate content in their indices.
  114. if (!empty($context['canonical_url']))
  115. echo '
  116. <link rel="canonical" href="', $context['canonical_url'], '" />';
  117. // Show all the relative links, such as help, search, contents, and the like.
  118. echo '
  119. <link rel="help" href="', $scripturl, '?action=help" />
  120. <link rel="search" href="', $scripturl, '?action=search" />
  121. <link rel="contents" href="', $scripturl, '" />';
  122. // If RSS feeds are enabled, advertise the presence of one.
  123. if (!empty($modSettings['xmlnews_enable']) && (!empty($modSettings['allow_guestAccess']) || $context['user']['is_logged']))
  124. echo '
  125. <link rel="alternate" type="application/rss+xml" title="', $context['forum_name_html_safe'], ' - ', $txt['rss'], '" href="', $scripturl, '?type=rss;action=.xml" />';
  126. // If we're viewing a topic, these should be the previous and next topics, respectively.
  127. if (!empty($context['current_topic']))
  128. echo '
  129. <link rel="prev" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=prev" />
  130. <link rel="next" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=next" />';
  131. // If we're in a board, or a topic for that matter, the index will be the board's index.
  132. if (!empty($context['current_board']))
  133. echo '
  134. <link rel="index" href="', $scripturl, '?board=', $context['current_board'], '.0" />';
  135. // Output any remaining HTML headers. (from mods, maybe?)
  136. echo $context['html_headers'];
  137. echo ('<script type="text/x-mathjax-config">MathJax.Hub.Config({tex2jax: {inlineMath: [[\'##\', \'##\']],displayMath: [[\'###\', \'###\']],skipTags: ["script","noscript","style","textarea","pre","code","body"],}});</script>');
  138. echo ('<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/mathjax/2.3/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>');
  139. echo '
  140. </head>
  141. <body>';
  142. }
  143. function template_body_above()
  144. {
  145. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  146. echo !empty($settings['forum_width']) ? '
  147. <div id="wrapper" style="width: ' . $settings['forum_width'] . '">' : '', '
  148. <div id="header"><div class="frame">
  149. <div id="top_section">
  150. <h1 class="forumtitle">
  151. <a href="', $scripturl, '"><img id="logo" src="' . $settings['images_url'] . '/omnimaga.png" alt="'.$context['forum_name'].'" title="'.$context['forum_name'].'" /></a>
  152. </h1>
  153. <div class="floatRight">
  154. <div class="user floatLeft" style="padding-right:10px;">';
  155. // If the user is logged in, display stuff like their name, new messages, etc.
  156. if ($context['user']['is_logged']){
  157. echo '
  158. <ul class="reset">';
  159. // Is the forum in maintenance mode?
  160. if ($context['in_maintenance'] && $context['user']['is_admin'])
  161. echo '
  162. <li class="notice">', $txt['maintain_mode_on'], '</li>';
  163. // Are there any members waiting for approval?
  164. if (!empty($context['unapproved_members']))
  165. echo '
  166. <li>', $context['unapproved_members'] == 1 ? $txt['approve_thereis'] : $txt['approve_thereare'], ' <a href="', $scripturl, '?action=admin;area=viewmembers;sa=browse;type=approve">', $context['unapproved_members'] == 1 ? $txt['approve_member'] : $context['unapproved_members'] . ' ' . $txt['approve_members'], '</a> ', $txt['approve_members_waiting'], '</li>';
  167. if (!empty($context['open_mod_reports']) && $context['show_open_reports'])
  168. echo '
  169. <li><a href="', $scripturl, '?action=moderate;area=reports">', sprintf($txt['mod_reports_waiting'], $context['open_mod_reports']), '</a></li>';
  170. echo '
  171. <li>', $context['current_time'], '</li>
  172. </ul>';
  173. }
  174. // Otherwise they're a guest - this time ask them to either register or login - lazy bums...
  175. elseif (!empty($context['show_login_bar']))
  176. {
  177. echo '
  178. <script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/sha1.js"></script>
  179. <form id="guest_form" action="', $scripturl, '?action=login2" method="post" accept-charset="', $context['character_set'], '" ', empty($context['disable_login_hashing']) ? ' onsubmit="hashLoginPassword(this, \'' . $context['session_id'] . '\');"' : '', '>
  180. <div class="info">', sprintf($txt['welcome_guest'], $txt['guest_title']), '</div>
  181. <input type="text" name="user" size="10" class="input_text" />
  182. <input type="password" name="passwrd" size="10" class="input_password" />
  183. <select name="cookielength">
  184. <option value="60">', $txt['one_hour'], '</option>
  185. <option value="1440">', $txt['one_day'], '</option>
  186. <option value="10080">', $txt['one_week'], '</option>
  187. <option value="43200">', $txt['one_month'], '</option>
  188. <option value="-1" selected="selected">', $txt['forever'], '</option>
  189. </select>
  190. <input type="submit" value="', $txt['login'], '" class="button_submit" /><br />
  191. <div class="info">', $txt['quick_login_dec'], '</div>';
  192. if (!empty($modSettings['enableOpenID']))
  193. echo '
  194. <br /><input type="text" name="openid_identifier" id="openid_url" size="25" class="input_text openid_login" />';
  195. echo '
  196. <input type="hidden" name="hash_passwrd" value="" />
  197. </form>';
  198. }
  199. echo '
  200. </div>
  201. <form id="search_form" class="floatRight" action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
  202. <input type="text" name="search" value="" class="input_text" />&nbsp;
  203. <input type="submit" name="submit" value="', $txt['search'], '" class="button_submit" />
  204. <input type="hidden" name="advanced" value="0" />';
  205. // Search within current topic?
  206. if (!empty($context['current_topic']))
  207. echo '
  208. <input type="hidden" name="topic" value="', $context['current_topic'], '" />';
  209. // If we're on a certain board, limit it to this board ;).
  210. elseif (!empty($context['current_board']))
  211. echo '
  212. <input type="hidden" name="brd[', $context['current_board'], ']" value="', $context['current_board'], '" />';
  213. echo ' </form>
  214. </div>
  215. <div class="floatLeft news normaltext">';
  216. echo '
  217. </div>
  218. </div>
  219. <br class="clear" />';
  220. // Define the upper_section toggle in JavaScript.
  221. echo '
  222. <script type="text/javascript"><!-- // --><![CDATA[
  223. var oMainHeaderToggle = new smc_Toggle({
  224. bToggleEnabled: true,
  225. bCurrentlyCollapsed: ', empty($options['collapse_header']) ? 'false' : 'true', ',
  226. aSwappableContainers: [
  227. \'upper_section\'
  228. ],
  229. aSwapImages: [
  230. {
  231. sId: \'upshrink\',
  232. srcExpanded: smf_images_url + \'/upshrink.png\',
  233. altExpanded: ', JavaScriptEscape($txt['upshrink_description']), ',
  234. srcCollapsed: smf_images_url + \'/upshrink2.png\',
  235. altCollapsed: ', JavaScriptEscape($txt['upshrink_description']), '
  236. }
  237. ],
  238. oThemeOptions: {
  239. bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
  240. sOptionName: \'collapse_header\',
  241. sSessionVar: ', JavaScriptEscape($context['session_var']), ',
  242. sSessionId: ', JavaScriptEscape($context['session_id']), '
  243. },
  244. oCookieOptions: {
  245. bUseCookie: ', $context['user']['is_guest'] ? 'true' : 'false', ',
  246. sCookieName: \'upshrink\'
  247. }
  248. });
  249. // ]]></script>';
  250. // Show the menu here, according to the menu sub template.
  251. template_menu();
  252. echo '
  253. <br class="clear" />
  254. </div></div>';
  255. // The main content should go here.
  256. echo '
  257. <div id="content_section"><div class="frame">
  258. <div id="main_content_section">';
  259. // Custom banners and shoutboxes should be placed here, before the linktree.
  260. // Show the navigation tree.
  261. theme_linktree();
  262. }
  263. function template_body_below()
  264. {
  265. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  266. echo '
  267. </div>
  268. </div></div>';
  269. // Show the "Powered by" and "Valid" logos, as well as the copyright. Remember, the copyright must be somewhere!
  270. echo '
  271. <div id="footer_section"><div class="frame">
  272. <ul class="reset">
  273. <li class="copyright">', theme_copyright(), '</li>
  274. <li><a id="button_xhtml" href="http://validator.w3.org/check?uri=referer" target="_blank" class="new_win" title="', $txt['valid_xhtml'], '"><span>', $txt['xhtml'], '</span></a></li>
  275. ', !empty($modSettings['xmlnews_enable']) && (!empty($modSettings['allow_guestAccess']) || $context['user']['is_logged']) ? '<li><a id="button_rss" href="' . $scripturl . '?action=.xml;type=rss" class="new_win"><span>' . $txt['rss'] . '</span></a></li>' : '', '
  276. <li class="last"><a id="button_wap2" href="', $scripturl , '?wap2" class="new_win"><span>', $txt['wap2'], '</span></a></li>
  277. </ul>';
  278. // DevCenter - Show load average.
  279. if (!empty($modSettings['devcenter_displayserverload']))
  280. echo '<p>', sprintf($txt['devcenter_load'], $context['dc_load'][0], $context['dc_load'][1], $context['dc_load'][2]), '</p>';
  281. // DevCenter - Show load average.
  282. if (!empty($modSettings['devcenter_displayserverload']))
  283. echo '<p>', sprintf($txt['devcenter_load'], $context['dc_load'][0], $context['dc_load'][1], $context['dc_load'][2]), '</p>'; // Show the load time?
  284. if ($context['show_load_time'])
  285. echo '
  286. <p>', $txt['page_created'], $context['load_time'], $txt['seconds_with'], $context['load_queries'], $txt['queries'], '</p>';
  287. echo '
  288. </div></div>', !empty($settings['forum_width']) ? '
  289. </div>' : '';
  290. }
  291. function template_html_below()
  292. {
  293. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  294. echo '
  295. </body></html>';
  296. }
  297. // Show a linktree. This is that thing that shows "My Community | General Category | General Discussion"..
  298. function theme_linktree($force_show = false)
  299. {
  300. global $context, $settings, $options, $shown_linktree;
  301. // If linktree is empty, just return - also allow an override.
  302. if (empty($context['linktree']) || (!empty($context['dont_default_linktree']) && !$force_show))
  303. return;
  304. echo '
  305. <div class="navigate_section">
  306. <ul>';
  307. // Each tree item has a URL and name. Some may have extra_before and extra_after.
  308. foreach ($context['linktree'] as $link_num => $tree)
  309. {
  310. echo '
  311. <li', ($link_num == count($context['linktree']) - 1) ? ' class="last"' : '', '>';
  312. // Show something before the link?
  313. if (isset($tree['extra_before']))
  314. echo $tree['extra_before'];
  315. // Show the link, including a URL if it should have one.
  316. echo $settings['linktree_link'] && isset($tree['url']) ? '
  317. <a href="' . $tree['url'] . '"><span>' . $tree['name'] . '</span></a>' : '<span>' . $tree['name'] . '</span>';
  318. // Show something after the link...?
  319. if (isset($tree['extra_after']))
  320. echo $tree['extra_after'];
  321. // Don't show a separator for the last one.
  322. if ($link_num != count($context['linktree']) - 1)
  323. echo ' &#187;';
  324. echo '
  325. </li>';
  326. }
  327. echo '
  328. </ul>
  329. </div>';
  330. $shown_linktree = true;
  331. }
  332. // Show the menu up top. Something like [home] [help] [profile] [logout]...
  333. function template_menu()
  334. {
  335. global $context, $settings, $options, $scripturl, $txt;
  336. echo '
  337. <div id="main_menu">
  338. <ul class="dropmenu" id="menu_nav">';
  339. foreach ($context['menu_buttons'] as $act => $button)
  340. {
  341. echo '
  342. <li id="button_', $act, '">
  343. <a class="', $button['active_button'] ? 'active ' : '', 'firstlevel" href="', $button['href'], '"', isset($button['target']) ? ' target="' . $button['target'] . '"' : '', '>
  344. <span class="', isset($button['is_last']) ? 'last ' : '', 'firstlevel">', $button['title'], '</span>
  345. </a>';
  346. if (!empty($button['sub_buttons']))
  347. {
  348. echo '
  349. <ul>';
  350. foreach ($button['sub_buttons'] as $childbutton)
  351. {
  352. echo '
  353. <li>
  354. <a href="', $childbutton['href'], '"', isset($childbutton['target']) ? ' target="' . $childbutton['target'] . '"' : '', '>
  355. <span', isset($childbutton['is_last']) ? ' class="last"' : '', '>', $childbutton['title'], !empty($childbutton['sub_buttons']) ? '...' : '', '</span>
  356. </a>';
  357. // 3rd level menus :)
  358. if (!empty($childbutton['sub_buttons']))
  359. {
  360. echo '
  361. <ul>';
  362. foreach ($childbutton['sub_buttons'] as $grandchildbutton)
  363. echo '
  364. <li>
  365. <a href="', $grandchildbutton['href'], '"', isset($grandchildbutton['target']) ? ' target="' . $grandchildbutton['target'] . '"' : '', '>
  366. <span', isset($grandchildbutton['is_last']) ? ' class="last"' : '', '>', $grandchildbutton['title'], '</span>
  367. </a>
  368. </li>';
  369. echo '
  370. </ul>';
  371. }
  372. echo '
  373. </li>';
  374. }
  375. echo '
  376. </ul>';
  377. }
  378. echo '
  379. </li>';
  380. }
  381. echo '
  382. </ul>
  383. </div>';
  384. }
  385. // Generate a strip of buttons.
  386. function template_button_strip($button_strip, $direction = 'top', $strip_options = array())
  387. {
  388. global $settings, $context, $txt, $scripturl;
  389. if (!is_array($strip_options))
  390. $strip_options = array();
  391. // List the buttons in reverse order for RTL languages.
  392. if ($context['right_to_left'])
  393. $button_strip = array_reverse($button_strip, true);
  394. // Create the buttons...
  395. $buttons = array();
  396. foreach ($button_strip as $key => $value)
  397. {
  398. if (!isset($value['test']) || !empty($context[$value['test']]))
  399. $buttons[] = '
  400. <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>';
  401. }
  402. // No buttons? No button strip either.
  403. if (empty($buttons))
  404. return;
  405. // Make the last one, as easy as possible.
  406. $buttons[count($buttons) - 1] = str_replace('<span>', '<span class="last">', $buttons[count($buttons) - 1]);
  407. echo '
  408. <div class="buttonlist', !empty($direction) ? ' float' . $direction : '', '"', (empty($buttons) ? ' style="display: none;"' : ''), (!empty($strip_options['id']) ? ' id="' . $strip_options['id'] . '"': ''), '>
  409. <ul>',
  410. implode('', $buttons), '
  411. </ul>
  412. </div>';
  413. }
  414. ?>