index.template.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  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.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. // 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 (isBrowser('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. // Note that the Superfish function seems to like being called by the full syntax.
  81. // It doesn't appear to like being called by short syntax. Please test if contemplating changes.
  82. echo '
  83. <script type="text/javascript" src="', $settings['theme_url'], '/scripts/jquery-1.6.4.min.js"></script>
  84. <script type="text/javascript" src="', $settings['theme_url'], '/scripts/hoverIntent.js"></script>
  85. <script type="text/javascript" src="', $settings['theme_url'], '/scripts/superfish.js"></script>
  86. <script type="text/javascript">
  87. $(document).ready(function() {
  88. $("ul.dropmenu").superfish();
  89. });
  90. </script>
  91. <script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/script.js?fin20"></script>
  92. <script type="text/javascript" src="', $settings['theme_url'], '/scripts/theme.js?fin20"></script>
  93. <script type="text/javascript"><!-- // --><![CDATA[
  94. var smf_theme_url = "', $settings['theme_url'], '";
  95. var smf_default_theme_url = "', $settings['default_theme_url'], '";
  96. var smf_images_url = "', $settings['images_url'], '";
  97. var smf_scripturl = "', $scripturl, '";
  98. var smf_iso_case_folding = ', $context['server']['iso_case_folding'] ? 'true' : 'false', ';
  99. var smf_charset = "', $context['character_set'], '";
  100. var smf_session_id = "', $context['session_id'], '";
  101. var smf_session_var = "', $context['session_var'], '";
  102. var smf_member_id = "', $context['user']['id'], '";', $context['show_pm_popup'] ? '
  103. var fPmPopup = function ()
  104. {
  105. if (confirm("' . $txt['show_personal_messages'] . '"))
  106. window.open(smf_prepareScriptUrl(smf_scripturl) + "action=pm");
  107. }
  108. addLoadEvent(fPmPopup);' : '', '
  109. var ajax_notification_text = "', $txt['ajax_in_progress'], '";
  110. var ajax_notification_cancel_text = "', $txt['modify_cancel'], '";
  111. // ]]></script>';
  112. echo '
  113. <meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
  114. <meta name="description" content="', $context['page_title_html_safe'], '" />', !empty($context['meta_keywords']) ? '
  115. <meta name="keywords" content="' . $context['meta_keywords'] . '" />' : '', '
  116. <title>', $context['page_title_html_safe'], '</title>';
  117. // Please don't index these Mr Robot.
  118. if (!empty($context['robot_no_index']))
  119. echo '
  120. <meta name="robots" content="noindex" />';
  121. // Present a canonical url for search engines to prevent duplicate content in their indices.
  122. if (!empty($context['canonical_url']))
  123. echo '
  124. <link rel="canonical" href="', $context['canonical_url'], '" />';
  125. // Show all the relative links, such as help, search, contents, and the like.
  126. echo '
  127. <link rel="help" href="', $scripturl, '?action=help" />
  128. <link rel="search" href="', $scripturl, '?action=search" />
  129. <link rel="contents" href="', $scripturl, '" />';
  130. // If RSS feeds are enabled, advertise the presence of one.
  131. if (!empty($modSettings['xmlnews_enable']) && (!empty($modSettings['allow_guestAccess']) || $context['user']['is_logged']))
  132. echo '
  133. <link rel="alternate" type="application/rss+xml" title="', $context['forum_name_html_safe'], ' - ', $txt['rss'], '" href="', $scripturl, '?type=rss;action=.xml" />';
  134. // If we're viewing a topic, these should be the previous and next topics, respectively.
  135. if (!empty($context['current_topic']))
  136. echo '
  137. <link rel="prev" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=prev" />
  138. <link rel="next" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=next" />';
  139. // If we're in a board, or a topic for that matter, the index will be the board's index.
  140. if (!empty($context['current_board']))
  141. echo '
  142. <link rel="index" href="', $scripturl, '?board=', $context['current_board'], '.0" />';
  143. // Output any remaining HTML headers. (from mods, maybe?)
  144. echo $context['html_headers'];
  145. echo '
  146. </head>
  147. <body class="action_', !empty($context['current_action']) ? htmlspecialchars($context['current_action']) : (!empty($context['current_board']) ? 'messageindex' : (!empty($context['current_topic']) ? 'display' : 'home')),
  148. !empty($context['current_board']) ? ' board_' . htmlspecialchars($context['current_board']) : '',
  149. '"',
  150. // Style per page.
  151. !empty($context['body_id']) ? ' id="' . $context['body_id'] . '"' : '', '>';
  152. }
  153. function template_body_above()
  154. {
  155. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  156. echo !empty($settings['forum_width']) ? '
  157. <div id="wrapper" style="width: ' . $settings['forum_width'] . '">' : '', '
  158. <div id="header"><div class="frame">
  159. <div id="top_section">
  160. <h1 class="forumtitle">
  161. <a 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>
  162. </h1>';
  163. // the upshrink image, right-floated
  164. echo '
  165. <img id="upshrink" src="', $settings['images_url'], '/upshrink.png" alt="*" title="', $txt['upshrink_description'], '" style="display: none;" />';
  166. echo '
  167. ', 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>', '
  168. </div>
  169. <div id="upper_section" class="middletext"', empty($options['collapse_header']) ? '' : ' style="display: none;"', '>
  170. <div class="user">';
  171. // If the user is logged in, display stuff like their name, new messages, etc.
  172. if ($context['user']['is_logged'])
  173. {
  174. if (!empty($context['user']['avatar']))
  175. echo '
  176. <p class="avatar">', $context['user']['avatar']['image'], '</p>';
  177. echo '
  178. <ul class="reset">
  179. <li class="greeting">', $txt['hello_member_ndt'], ' <span>', $context['user']['name'], '</span></li>
  180. <li><a href="', $scripturl, '?action=unread">', $txt['unread_since_visit'], '</a></li>
  181. <li><a href="', $scripturl, '?action=unreadreplies">', $txt['show_unread_replies'], '</a></li>';
  182. // Is the forum in maintenance mode?
  183. if ($context['in_maintenance'] && $context['user']['is_admin'])
  184. echo '
  185. <li class="notice">', $txt['maintain_mode_on'], '</li>';
  186. // Are there any members waiting for approval?
  187. if (!empty($context['unapproved_members']))
  188. echo '
  189. <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>';
  190. if (!empty($context['open_mod_reports']) && $context['show_open_reports'])
  191. echo '
  192. <li><a href="', $scripturl, '?action=moderate;area=reports">', sprintf($txt['mod_reports_waiting'], $context['open_mod_reports']), '</a></li>';
  193. echo '
  194. <li>', $context['current_time'], '</li>
  195. </ul>';
  196. }
  197. // Otherwise they're a guest - this time ask them to either register or login - lazy bums...
  198. elseif (!empty($context['show_login_bar']))
  199. {
  200. echo '
  201. <script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/sha1.js"></script>
  202. <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'] . '\');"' : '', '>
  203. <div class="info">', sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $scripturl . '?action=login'), '</div>
  204. <input type="text" name="user" size="10" class="input_text" />
  205. <input type="password" name="passwrd" size="10" class="input_password" />
  206. <select name="cookielength">
  207. <option value="60">', $txt['one_hour'], '</option>
  208. <option value="1440">', $txt['one_day'], '</option>
  209. <option value="10080">', $txt['one_week'], '</option>
  210. <option value="43200">', $txt['one_month'], '</option>
  211. <option value="-1" selected="selected">', $txt['forever'], '</option>
  212. </select>
  213. <input type="submit" value="', $txt['login'], '" class="button_submit" /><br />
  214. <div class="info">', $txt['quick_login_dec'], '</div>';
  215. if (!empty($modSettings['enableOpenID']))
  216. echo '
  217. <br /><input type="text" name="openid_identifier" id="openid_url" size="25" class="input_text openid_login" />';
  218. echo '
  219. <input type="hidden" name="hash_passwrd" value="" />
  220. <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
  221. <input type="hidden" name="', $context['login_token_var'], '" value="', $context['login_token'], '" />
  222. </form>';
  223. }
  224. echo '
  225. </div>
  226. <div class="news normaltext">
  227. <form id="search_form" action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
  228. <input type="text" name="search" value="" class="input_text" />&nbsp;
  229. <input type="submit" name="submit" value="', $txt['search'], '" class="button_submit" />
  230. <input type="hidden" name="advanced" value="0" />';
  231. // Search within current topic?
  232. if (!empty($context['current_topic']))
  233. echo '
  234. <input type="hidden" name="topic" value="', $context['current_topic'], '" />';
  235. // If we're on a certain board, limit it to this board ;).
  236. elseif (!empty($context['current_board']))
  237. echo '
  238. <input type="hidden" name="brd[', $context['current_board'], ']" value="', $context['current_board'], '" />';
  239. echo '</form>';
  240. // Show a random news item? (or you could pick one from news_lines...)
  241. if (!empty($settings['enable_news']))
  242. echo '
  243. <h2>', $txt['news'], ': </h2>
  244. <p>', $context['random_news_line'], '</p>';
  245. echo '
  246. </div>
  247. </div>
  248. <br class="clear" />';
  249. // Define the upper_section toggle in JavaScript.
  250. echo '
  251. <script type="text/javascript"><!-- // --><![CDATA[
  252. var oMainHeaderToggle = new smc_Toggle({
  253. bToggleEnabled: true,
  254. bCurrentlyCollapsed: ', empty($options['collapse_header']) ? 'false' : 'true', ',
  255. aSwappableContainers: [
  256. \'upper_section\'
  257. ],
  258. aSwapImages: [
  259. {
  260. sId: \'upshrink\',
  261. srcExpanded: smf_images_url + \'/upshrink.png\',
  262. altExpanded: ', JavaScriptEscape($txt['upshrink_description']), ',
  263. srcCollapsed: smf_images_url + \'/upshrink2.png\',
  264. altCollapsed: ', JavaScriptEscape($txt['upshrink_description']), '
  265. }
  266. ],
  267. oThemeOptions: {
  268. bUseThemeSettings: smf_member_id == 0 ? false : true,
  269. sOptionName: \'collapse_header\',
  270. sSessionVar: smf_session_var,
  271. sSessionId: smf_session_id
  272. },
  273. oCookieOptions: {
  274. bUseCookie: smf_member_id == 0 ? true : false,
  275. sCookieName: \'upshrink\'
  276. }
  277. });
  278. // ]]></script>';
  279. // Show the menu here, according to the menu sub template.
  280. template_menu();
  281. echo '
  282. <br class="clear" />
  283. </div></div>';
  284. // The main content should go here.
  285. echo '
  286. <div id="content_section"><div class="frame">
  287. <div id="main_content_section">';
  288. // Custom banners and shoutboxes should be placed here, before the linktree.
  289. // Show the navigation tree.
  290. theme_linktree();
  291. }
  292. function template_body_below()
  293. {
  294. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  295. echo '
  296. </div>
  297. </div></div>';
  298. // Show the "Powered by" and "Valid" logos, as well as the copyright. Remember, the copyright must be somewhere!
  299. echo '
  300. <div id="footer_section"><div class="frame">
  301. <ul class="reset">
  302. <li class="copyright">', theme_copyright(), '</li>
  303. <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>
  304. ', !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>' : '', '
  305. <li class="last"><a id="button_wap2" href="', $scripturl , '?wap2" class="new_win"><span>', $txt['wap2'], '</span></a></li>
  306. </ul>';
  307. // Show the load time?
  308. if ($context['show_load_time'])
  309. echo '
  310. <p>', $txt['page_created'], $context['load_time'], $txt['seconds_with'], $context['load_queries'], $txt['queries'], '</p>';
  311. echo '
  312. </div></div>', !empty($settings['forum_width']) ? '
  313. </div>' : '';
  314. }
  315. function template_html_below()
  316. {
  317. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  318. echo '
  319. </body></html>';
  320. }
  321. // Show a linktree. This is that thing that shows "My Community | General Category | General Discussion"..
  322. function theme_linktree($force_show = false)
  323. {
  324. global $context, $settings, $options, $shown_linktree;
  325. // If linktree is empty, just return - also allow an override.
  326. if (empty($context['linktree']) || (!empty($context['dont_default_linktree']) && !$force_show))
  327. return;
  328. echo '
  329. <div class="navigate_section">
  330. <ul>';
  331. // Each tree item has a URL and name. Some may have extra_before and extra_after.
  332. foreach ($context['linktree'] as $link_num => $tree)
  333. {
  334. echo '
  335. <li', ($link_num == count($context['linktree']) - 1) ? ' class="last"' : '', '>';
  336. // Show something before the link?
  337. if (isset($tree['extra_before']))
  338. echo $tree['extra_before'];
  339. // Show the link, including a URL if it should have one.
  340. echo $settings['linktree_link'] && isset($tree['url']) ? '
  341. <a href="' . $tree['url'] . '"><span>' . $tree['name'] . '</span></a>' : '<span>' . $tree['name'] . '</span>';
  342. // Show something after the link...?
  343. if (isset($tree['extra_after']))
  344. echo $tree['extra_after'];
  345. // Don't show a separator for the last one.
  346. if ($link_num != count($context['linktree']) - 1)
  347. echo ' &#187;';
  348. echo '
  349. </li>';
  350. }
  351. echo '
  352. </ul>
  353. </div>';
  354. $shown_linktree = true;
  355. }
  356. // Show the menu up top. Something like [home] [help] [profile] [logout]...
  357. function template_menu()
  358. {
  359. global $context, $settings, $options, $scripturl, $txt;
  360. echo '
  361. <div id="main_menu">
  362. <ul class="dropmenu" id="menu_nav">';
  363. foreach ($context['menu_buttons'] as $act => $button)
  364. {
  365. echo '
  366. <li id="button_', $act, '">
  367. <a class="', $button['active_button'] ? 'active ' : '', 'firstlevel" href="', $button['href'], '"', isset($button['target']) ? ' target="' . $button['target'] . '"' : '', '>
  368. <span class="', isset($button['is_last']) ? 'last ' : '', 'firstlevel">', $button['title'], '</span>
  369. </a>';
  370. if (!empty($button['sub_buttons']))
  371. {
  372. echo '
  373. <ul>';
  374. foreach ($button['sub_buttons'] as $childbutton)
  375. {
  376. echo '
  377. <li>
  378. <a href="', $childbutton['href'], '"', isset($childbutton['target']) ? ' target="' . $childbutton['target'] . '"' : '', '>
  379. <span', isset($childbutton['is_last']) ? ' class="last"' : '', '>', $childbutton['title'], !empty($childbutton['sub_buttons']) ? '...' : '', '</span>
  380. </a>';
  381. // 3rd level menus :)
  382. if (!empty($childbutton['sub_buttons']))
  383. {
  384. echo '
  385. <ul>';
  386. foreach ($childbutton['sub_buttons'] as $grandchildbutton)
  387. echo '
  388. <li>
  389. <a href="', $grandchildbutton['href'], '"', isset($grandchildbutton['target']) ? ' target="' . $grandchildbutton['target'] . '"' : '', '>
  390. <span', isset($grandchildbutton['is_last']) ? ' class="last"' : '', '>', $grandchildbutton['title'], '</span>
  391. </a>
  392. </li>';
  393. echo '
  394. </ul>';
  395. }
  396. echo '
  397. </li>';
  398. }
  399. echo '
  400. </ul>';
  401. }
  402. echo '
  403. </li>';
  404. }
  405. echo '
  406. </ul>
  407. </div>';
  408. }
  409. // Generate a strip of buttons.
  410. function template_button_strip($button_strip, $direction = 'top', $strip_options = array())
  411. {
  412. global $settings, $context, $txt, $scripturl;
  413. if (!is_array($strip_options))
  414. $strip_options = array();
  415. // List the buttons in reverse order for RTL languages.
  416. if ($context['right_to_left'])
  417. $button_strip = array_reverse($button_strip, true);
  418. // Create the buttons...
  419. $buttons = array();
  420. foreach ($button_strip as $key => $value)
  421. {
  422. if (!isset($value['test']) || !empty($context[$value['test']]))
  423. $buttons[] = '
  424. <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>';
  425. }
  426. // No buttons? No button strip either.
  427. if (empty($buttons))
  428. return;
  429. // Make the last one, as easy as possible.
  430. $buttons[count($buttons) - 1] = str_replace('<span>', '<span class="last">', $buttons[count($buttons) - 1]);
  431. echo '
  432. <div class="buttonlist', !empty($direction) ? ' float' . $direction : '', '"', (empty($buttons) ? ' style="display: none;"' : ''), (!empty($strip_options['id']) ? ' id="' . $strip_options['id'] . '"': ''), '>
  433. <ul>',
  434. implode('', $buttons), '
  435. </ul>
  436. </div>';
  437. }
  438. ?>