index.template.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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"' : '', '><head>';
  66. // The ?fin20 part of this link is just here to make sure browsers don't cache it wrongly.
  67. echo '
  68. <link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?fin20" />';
  69. // Some browsers need an extra stylesheet due to bugs/compatibility issues.
  70. foreach (array('ie7', 'ie6', 'webkit') as $cssfix)
  71. if (isBrowser('is_' . $cssfix))
  72. echo '
  73. <link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/', $cssfix, '.css" />';
  74. // RTL languages require an additional stylesheet.
  75. if ($context['right_to_left'])
  76. echo '
  77. <link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/rtl.css" />';
  78. // Here comes the JavaScript bits!
  79. echo '
  80. <script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/script.js?fin20"></script>
  81. <script type="text/javascript" src="', $settings['theme_url'], '/scripts/theme.js?fin20"></script>
  82. <script type="text/javascript"><!-- // --><![CDATA[
  83. var smf_theme_url = "', $settings['theme_url'], '";
  84. var smf_default_theme_url = "', $settings['default_theme_url'], '";
  85. var smf_images_url = "', $settings['images_url'], '";
  86. var smf_scripturl = "', $scripturl, '";
  87. var smf_iso_case_folding = ', $context['server']['iso_case_folding'] ? 'true' : 'false', ';
  88. var smf_charset = "', $context['character_set'], '";', $context['show_pm_popup'] ? '
  89. var fPmPopup = function ()
  90. {
  91. if (confirm("' . $txt['show_personal_messages'] . '"))
  92. window.open(smf_prepareScriptUrl(smf_scripturl) + "action=pm");
  93. }
  94. addLoadEvent(fPmPopup);' : '', '
  95. var ajax_notification_text = "', $txt['ajax_in_progress'], '";
  96. var ajax_notification_cancel_text = "', $txt['modify_cancel'], '";
  97. // ]]></script>';
  98. echo '
  99. <meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
  100. <meta name="description" content="', $context['page_title_html_safe'], '" />', !empty($context['meta_keywords']) ? '
  101. <meta name="keywords" content="' . $context['meta_keywords'] . '" />' : '', '
  102. <title>', $context['page_title_html_safe'], '</title>';
  103. // Please don't index these Mr Robot.
  104. if (!empty($context['robot_no_index']))
  105. echo '
  106. <meta name="robots" content="noindex" />';
  107. // Present a canonical url for search engines to prevent duplicate content in their indices.
  108. if (!empty($context['canonical_url']))
  109. echo '
  110. <link rel="canonical" href="', $context['canonical_url'], '" />';
  111. // Show all the relative links, such as help, search, contents, and the like.
  112. echo '
  113. <link rel="help" href="', $scripturl, '?action=help" />
  114. <link rel="search" href="' . $scripturl . '?action=search" />
  115. <link rel="contents" href="', $scripturl, '" />';
  116. // If RSS feeds are enabled, advertise the presence of one.
  117. if (!empty($modSettings['xmlnews_enable']) && (!empty($modSettings['allow_guestAccess']) || $context['user']['is_logged']))
  118. echo '
  119. <link rel="alternate" type="application/rss+xml" title="', $context['forum_name_html_safe'], ' - ', $txt['rss'], '" href="', $scripturl, '?type=rss;action=.xml" />';
  120. // If we're viewing a topic, these should be the previous and next topics, respectively.
  121. if (!empty($context['current_topic']))
  122. echo '
  123. <link rel="prev" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=prev" />
  124. <link rel="next" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=next" />';
  125. // If we're in a board, or a topic for that matter, the index will be the board's index.
  126. if (!empty($context['current_board']))
  127. echo '
  128. <link rel="index" href="', $scripturl, '?board=', $context['current_board'], '.0" />';
  129. // We'll have to use the cookie to remember the header...
  130. if ($context['user']['is_guest'])
  131. {
  132. $options['collapse_header'] = !empty($_COOKIE['upshrink']);
  133. $options['collapse_header_ic'] = !empty($_COOKIE['upshrinkIC']);
  134. }
  135. // Output any remaining HTML headers. (from mods, maybe?)
  136. echo $context['html_headers'];
  137. echo '
  138. </head>
  139. <body>';
  140. }
  141. function template_body_above()
  142. {
  143. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  144. echo '
  145. <div id="mainframe"', !empty($settings['forum_width']) ? ' style="width: ' . $settings['forum_width'] . '"' : '', '>
  146. <div class="tborder">
  147. <div class="catbg">
  148. <img class="floatright" id="smflogo" src="', $settings['images_url'], '/smflogo.gif" alt="Simple Machines Forum" />
  149. <h1 id="forum_name">';
  150. if (empty($context['header_logo_url_html_safe']))
  151. echo $context['forum_name_html_safe'];
  152. else
  153. echo '
  154. <img src="', $context['header_logo_url_html_safe'], '" alt="', $context['forum_name_html_safe'], '" />';
  155. echo '
  156. </h1>
  157. </div>';
  158. // Display user name and time.
  159. echo '
  160. <ul id="greeting_section" class="reset titlebg2">
  161. <li id="time" class="smalltext floatright">
  162. ', $context['current_time'], '
  163. <img id="upshrink" src="', $settings['images_url'], '/upshrink.gif" alt="*" title="', $txt['upshrink_description'], '" align="bottom" style="display: none;" />
  164. </li>';
  165. if ($context['user']['is_logged'])
  166. echo '
  167. <li id="name">', $txt['hello_member_ndt'], ' <em>', $context['user']['name'], '</em></li>';
  168. else
  169. echo '
  170. <li id="name">', $txt['hello_guest'], ' <em>', $txt['guest'], '</em></li>';
  171. echo '
  172. </ul>';
  173. if ($context['user']['is_logged'] || !empty($context['show_login_bar']))
  174. echo '
  175. <div id="user_section" class="bordercolor"', empty($options['collapse_header']) ? '' : ' style="display: none;"', '>
  176. <div class="windowbg2 clearfix">';
  177. if (!empty($context['user']['avatar']))
  178. echo '
  179. <div id="myavatar">', $context['user']['avatar']['image'], '</div>';
  180. // If the user is logged in, display stuff like their name, new messages, etc.
  181. if ($context['user']['is_logged'])
  182. {
  183. echo '
  184. <ul class="reset">
  185. <li><a href="', $scripturl, '?action=unread">', $txt['unread_since_visit'], '</a></li>
  186. <li><a href="', $scripturl, '?action=unreadreplies">', $txt['show_unread_replies'], '</a></li>';
  187. // Is the forum in maintenance mode?
  188. if ($context['in_maintenance'] && $context['user']['is_admin'])
  189. echo '
  190. <li class="notice">', $txt['maintain_mode_on'], '</li>';
  191. // Are there any members waiting for approval?
  192. if (!empty($context['unapproved_members']))
  193. echo '
  194. <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>';
  195. // Show the total time logged in?
  196. if (!empty($context['user']['total_time_logged_in']))
  197. {
  198. echo '
  199. <li>', $txt['totalTimeLogged1'];
  200. // If days is just zero, don't bother to show it.
  201. if ($context['user']['total_time_logged_in']['days'] > 0)
  202. echo $context['user']['total_time_logged_in']['days'] . $txt['totalTimeLogged2'];
  203. // Same with hours - only show it if it's above zero.
  204. if ($context['user']['total_time_logged_in']['hours'] > 0)
  205. echo $context['user']['total_time_logged_in']['hours'] . $txt['totalTimeLogged3'];
  206. // But, let's always show minutes - Time wasted here: 0 minutes ;).
  207. echo $context['user']['total_time_logged_in']['minutes'], $txt['totalTimeLogged4'], '
  208. </li>';
  209. }
  210. if (!empty($context['open_mod_reports']) && $context['show_open_reports'])
  211. echo '
  212. <li><a href="', $scripturl, '?action=moderate;area=reports">', sprintf($txt['mod_reports_waiting'], $context['open_mod_reports']), '</a></li>';
  213. echo '
  214. </ul>';
  215. }
  216. // Otherwise they're a guest - this time ask them to either register or login - lazy bums...
  217. elseif (!empty($context['show_login_bar']))
  218. {
  219. echo '
  220. <script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/sha1.js"></script>
  221. <form class="windowbg" 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'] . '\');"' : '', '>
  222. ', $context['can_register'] ? $txt['login_or_register'] : $txt['please_login'], '<br />
  223. <input type="text" name="user" size="10" class="input_text" />
  224. <input type="password" name="passwrd" size="10" class="input_password" />
  225. <select name="cookielength">
  226. <option value="60">', $txt['one_hour'], '</option>
  227. <option value="1440">', $txt['one_day'], '</option>
  228. <option value="10080">', $txt['one_week'], '</option>
  229. <option value="43200">', $txt['one_month'], '</option>
  230. <option value="-1" selected="selected">', $txt['forever'], '</option>
  231. </select>
  232. <input type="submit" value="', $txt['login'], '" class="button_submit" /><br />
  233. ', $txt['quick_login_dec'];
  234. if (!empty($modSettings['enableOpenID']))
  235. echo '
  236. <br />
  237. <input type="text" name="openid_identifier" id="openid_url" size="25" class="input_text openid_login" />';
  238. echo '
  239. <input type="hidden" name="hash_passwrd" value="" />
  240. </form>';
  241. }
  242. if ($context['user']['is_logged'] || !empty($context['show_login_bar']))
  243. echo '
  244. </div>
  245. </div>';
  246. echo '
  247. <div id="news_section" class="titlebg2 clearfix"', empty($options['collapse_header']) ? '' : ' style="display: none;"', '>
  248. <form class="floatright" id="search_form" action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
  249. <a href="', $scripturl, '?action=search;advanced" title="', $txt['search_advanced'], '"><img id="advsearch" src="'.$settings['images_url'].'/filter.gif" align="middle" alt="', $txt['search_advanced'], '" /></a>
  250. <input type="text" name="search" value="" style="width: 190px;" class="input_text" />&nbsp;
  251. <input type="submit" name="submit" value="', $txt['search'], '" style="width: 11ex;" class="button_submit" />
  252. <input type="hidden" name="advanced" value="0" />';
  253. // Search within current topic?
  254. if (!empty($context['current_topic']))
  255. echo '
  256. <input type="hidden" name="topic" value="', $context['current_topic'], '" />';
  257. // If we're on a certain board, limit it to this board ;).
  258. elseif (!empty($context['current_board']))
  259. echo '
  260. <input type="hidden" name="brd[', $context['current_board'], ']" value="', $context['current_board'], '" />';
  261. echo '
  262. </form>';
  263. // Show a random news item? (or you could pick one from news_lines...)
  264. if (!empty($settings['enable_news']))
  265. echo '
  266. <div id="random_news"><h3>', $txt['news'], ':</h3><p>', $context['random_news_line'], '</p></div>';
  267. echo '
  268. </div>
  269. </div>';
  270. // Define the upper_section toggle in JavaScript.
  271. echo '
  272. <script type="text/javascript"><!-- // --><![CDATA[
  273. var oMainHeaderToggle = new smc_Toggle({
  274. bToggleEnabled: true,
  275. bCurrentlyCollapsed: ', empty($options['collapse_header']) ? 'false' : 'true', ',
  276. aSwappableContainers: [
  277. \'user_section\',
  278. \'news_section\'
  279. ],
  280. aSwapImages: [
  281. {
  282. sId: \'upshrink\',
  283. srcExpanded: smf_images_url + \'/upshrink.gif\',
  284. altExpanded: ', JavaScriptEscape($txt['upshrink_description']), ',
  285. srcCollapsed: smf_images_url + \'/upshrink2.gif\',
  286. altCollapsed: ', JavaScriptEscape($txt['upshrink_description']), '
  287. }
  288. ],
  289. oThemeOptions: {
  290. bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
  291. sOptionName: \'collapse_header\',
  292. sSessionVar: ', JavaScriptEscape($context['session_var']), ',
  293. sSessionId: ', JavaScriptEscape($context['session_id']), '
  294. },
  295. oCookieOptions: {
  296. bUseCookie: ', $context['user']['is_guest'] ? 'true' : 'false', ',
  297. sCookieName: \'upshrink\'
  298. }
  299. });
  300. // ]]></script>';
  301. // Show the menu here, according to the menu sub template.
  302. template_menu();
  303. // Show the navigation tree.
  304. theme_linktree();
  305. // The main content should go here.
  306. echo '
  307. <div id="bodyarea">';
  308. }
  309. function template_body_below()
  310. {
  311. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  312. echo '
  313. </div>';
  314. // Show the "Powered by" and "Valid" logos, as well as the copyright. Remember, the copyright must be somewhere!
  315. echo '
  316. <div id="footerarea" class="headerpadding topmargin clearfix">
  317. <ul class="reset smalltext">
  318. <li class="copyright">', theme_copyright(), '</li>
  319. <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>
  320. ', !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>' : '', '
  321. <li class="last"><a id="button_wap2" href="', $scripturl , '?wap2" class="new_win"><span>', $txt['wap2'], '</span></a></li>
  322. </ul>';
  323. // Show the load time?
  324. if ($context['show_load_time'])
  325. echo '
  326. <p class="smalltext" id="show_loadtime">', $txt['page_created'], $context['load_time'], $txt['seconds_with'], $context['load_queries'], $txt['queries'], '</p>';
  327. echo '
  328. </div>
  329. </div>';
  330. }
  331. function template_html_below()
  332. {
  333. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  334. echo '
  335. </body></html>';
  336. }
  337. // Show a linktree. This is that thing that shows "My Community | General Category | General Discussion"..
  338. function theme_linktree($force_show = false)
  339. {
  340. global $context, $settings, $options, $shown_linktree;
  341. // If linktree is empty, just return - also allow an override.
  342. if (empty($context['linktree']) || (!empty($context['dont_default_linktree']) && !$force_show))
  343. return;
  344. echo '
  345. <ul class="linktree" id="linktree_', empty($shown_linktree) ? 'upper' : 'lower', '">';
  346. // Each tree item has a URL and name. Some may have extra_before and extra_after.
  347. foreach ($context['linktree'] as $link_num => $tree)
  348. {
  349. echo '
  350. <li', ($link_num == count($context['linktree']) - 1) ? ' class="last"' : '', '>';
  351. // Show something before the link?
  352. if (isset($tree['extra_before']))
  353. echo $tree['extra_before'];
  354. // Show the link, including a URL if it should have one.
  355. echo $settings['linktree_link'] && isset($tree['url']) ? '
  356. <a href="' . $tree['url'] . '"><span>' . $tree['name'] . '</span></a>' : '<span>' . $tree['name'] . '</span>';
  357. // Show something after the link...?
  358. if (isset($tree['extra_after']))
  359. echo $tree['extra_after'];
  360. // Don't show a separator for the last one.
  361. if ($link_num != count($context['linktree']) - 1)
  362. echo ' &gt;';
  363. echo '
  364. </li>';
  365. }
  366. echo '
  367. </ul>';
  368. $shown_linktree = true;
  369. }
  370. // Show the menu up top. Something like [home] [help] [profile] [logout]...
  371. function template_menu()
  372. {
  373. global $context, $settings, $options, $scripturl, $txt;
  374. echo '
  375. <div class="main_menu">
  376. <ul class="reset clearfix">';
  377. foreach ($context['menu_buttons'] as $act => $button)
  378. {
  379. $classes = array();
  380. if (!empty($button['active_button']))
  381. $classes[] = 'active';
  382. if (!empty($button['is_last']))
  383. $classes[] = 'last';
  384. /* IE6 can't do multiple class selectors */
  385. if (isBrowser('is_ie6') && !empty($button['active_button']) && !empty($button['is_last']))
  386. $classes[] = 'lastactive';
  387. $classes = implode(' ', $classes);
  388. echo '
  389. <li id="button_', $act, '"', !empty($classes) ? ' class="' . $classes . '"' : '', '>
  390. <a title="', !empty($button['alttitle']) ? $button['alttitle'] : $button['title'], '" href="', $button['href'], '"', isset($button['target']) ? ' target="' . $button['target'] . '"' : '', '>
  391. <span>', ($button['active_button'] ? '<em>' : ''), $button['title'], ($button['active_button'] ? '</em>' : ''), '</span>
  392. </a>
  393. </li>';
  394. }
  395. echo '
  396. </ul>
  397. </div>';
  398. }
  399. // Generate a strip of buttons.
  400. function template_button_strip($button_strip, $direction = 'top', $strip_options = array())
  401. {
  402. global $settings, $context, $txt, $scripturl;
  403. if (!is_array($strip_options))
  404. $strip_options = array();
  405. // Right to left menu should be in reverse order.
  406. if ($context['right_to_left'])
  407. $button_strip = array_reverse($button_strip, true);
  408. // Create the buttons...
  409. $buttons = array();
  410. foreach ($button_strip as $key => $value)
  411. if (!isset($value['test']) || !empty($context[$value['test']]))
  412. $buttons[] = '
  413. <li' . (isset($value['active']) ? ' class="active"' : '') . '><a' . (isset($value['id']) ? ' id="button_strip_' . $value['id'] . '"' : '') . ' class="button_strip_' . $key . '" href="' . $value['url'] . '"' . (isset($value['custom']) ? ' ' . $value['custom'] : '') . '><span>' . (isset($value['active']) ? '<em>' . $txt[$value['text']] . '</em>' : $txt[$value['text']]) . '</span></a></li>';
  414. // No buttons? No button strip either.
  415. if (empty($buttons))
  416. return;
  417. // Make the last one, as easy as possible.
  418. $list_item = array('<li>', '<li class="active">');
  419. $active_item = array('<li class="last">', '<li class="active last lastactive">');
  420. $buttons[count($buttons) - 1] = str_replace($list_item, $active_item, $buttons[count($buttons) - 1]);
  421. echo '
  422. <div class="buttonlist', $direction != 'top' ? '_bottom' : '', '"', (empty($buttons) ? ' style="display: none;"' : ''), (!empty($strip_options['id']) ? ' id="' . $strip_options['id'] . '"': ''), '>
  423. <ul class="reset clearfix">',
  424. implode('', $buttons), '
  425. </ul>
  426. </div>';
  427. }
  428. ?>