PageRenderTime 26ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/header.php

https://gitlab.com/giumbai/fluxbb
PHP | 326 lines | 276 code | 27 blank | 23 comment | 15 complexity | fe27c532fc0bbdedfaabe3dca90af8f5 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright (C) 2008-2012 FluxBB
  4. * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
  5. * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
  6. */
  7. // Make sure no one attempts to run this script "directly"
  8. if (!defined('PUN'))
  9. exit;
  10. // Send no-cache headers
  11. header('Expires: Thu, 21 Jul 1977 07:30:00 GMT'); // When yours truly first set eyes on this world! :)
  12. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  13. header('Cache-Control: post-check=0, pre-check=0', false);
  14. header('Pragma: no-cache'); // For HTTP/1.0 compatibility
  15. // Send the Content-type header in case the web server is setup to send something else
  16. header('Content-type: text/html; charset=utf-8');
  17. // Prevent site from being embedded in a frame
  18. $frame_options = defined('FORUM_FRAME_OPTIONS') ? FORUM_FRAME_OPTIONS : 'deny';
  19. header('X-Frame-Options: '.$frame_options);
  20. // Load the template
  21. if (defined('PUN_ADMIN_CONSOLE'))
  22. $tpl_file = 'admin.tpl';
  23. else if (defined('PUN_HELP'))
  24. $tpl_file = 'help.tpl';
  25. else
  26. $tpl_file = 'main.tpl';
  27. if (file_exists(PUN_ROOT.'style/'.$pun_user['style'].'/'.$tpl_file))
  28. {
  29. $tpl_file = PUN_ROOT.'style/'.$pun_user['style'].'/'.$tpl_file;
  30. $tpl_inc_dir = PUN_ROOT.'style/'.$pun_user['style'].'/';
  31. }
  32. else
  33. {
  34. $tpl_file = PUN_ROOT.'include/template/'.$tpl_file;
  35. $tpl_inc_dir = PUN_ROOT.'include/user/';
  36. }
  37. $tpl_main = file_get_contents($tpl_file);
  38. // START SUBST - <pun_include "*">
  39. preg_match_all('%<pun_include "([^"]+)">%i', $tpl_main, $pun_includes, PREG_SET_ORDER);
  40. foreach ($pun_includes as $cur_include)
  41. {
  42. ob_start();
  43. $file_info = pathinfo($cur_include[1]);
  44. if (!in_array($file_info['extension'], array('php', 'php4', 'php5', 'inc', 'html', 'txt'))) // Allow some extensions
  45. error(sprintf($lang_common['Pun include extension'], pun_htmlspecialchars($cur_include[0]), basename($tpl_file), pun_htmlspecialchars($file_info['extension'])));
  46. if (strpos($file_info['dirname'], '..') !== false) // Don't allow directory traversal
  47. error(sprintf($lang_common['Pun include directory'], pun_htmlspecialchars($cur_include[0]), basename($tpl_file)));
  48. // Allow for overriding user includes, too.
  49. if (file_exists($tpl_inc_dir.$cur_include[1]))
  50. require $tpl_inc_dir.$cur_include[1];
  51. else if (file_exists(PUN_ROOT.'include/user/'.$cur_include[1]))
  52. require PUN_ROOT.'include/user/'.$cur_include[1];
  53. else
  54. error(sprintf($lang_common['Pun include error'], pun_htmlspecialchars($cur_include[0]), basename($tpl_file)));
  55. $tpl_temp = ob_get_contents();
  56. $tpl_main = str_replace($cur_include[0], $tpl_temp, $tpl_main);
  57. ob_end_clean();
  58. }
  59. // END SUBST - <pun_include "*">
  60. // START SUBST - <pun_language>
  61. $tpl_main = str_replace('<pun_language>', $lang_common['lang_identifier'], $tpl_main);
  62. // END SUBST - <pun_language>
  63. // START SUBST - <pun_content_direction>
  64. $tpl_main = str_replace('<pun_content_direction>', $lang_common['lang_direction'], $tpl_main);
  65. // END SUBST - <pun_content_direction>
  66. // START SUBST - <pun_head>
  67. ob_start();
  68. // Define $p if it's not set to avoid a PHP notice
  69. $p = isset($p) ? $p : null;
  70. // Is this a page that we want search index spiders to index?
  71. if (!defined('PUN_ALLOW_INDEX'))
  72. echo '<meta name="ROBOTS" content="NOINDEX, FOLLOW" />'."\n";
  73. ?>
  74. <title><?php echo generate_page_title($page_title, $p) ?></title>
  75. <link rel="stylesheet" type="text/css" href="style/<?php echo $pun_user['style'].'.css' ?>" />
  76. <?php
  77. if (defined('PUN_ADMIN_CONSOLE'))
  78. {
  79. if (file_exists(PUN_ROOT.'style/'.$pun_user['style'].'/base_admin.css'))
  80. echo '<link rel="stylesheet" type="text/css" href="style/'.$pun_user['style'].'/base_admin.css" />'."\n";
  81. else
  82. echo '<link rel="stylesheet" type="text/css" href="style/imports/base_admin.css" />'."\n";
  83. }
  84. if (isset($required_fields))
  85. {
  86. // Output JavaScript to validate form (make sure required fields are filled out)
  87. ?>
  88. <script type="text/javascript">
  89. /* <![CDATA[ */
  90. function process_form(the_form)
  91. {
  92. var required_fields = {
  93. <?php
  94. // Output a JavaScript object with localised field names
  95. $tpl_temp = count($required_fields);
  96. foreach ($required_fields as $elem_orig => $elem_trans)
  97. {
  98. echo "\t\t\"".$elem_orig.'": "'.addslashes(str_replace('&#160;', ' ', $elem_trans));
  99. if (--$tpl_temp) echo "\",\n";
  100. else echo "\"\n\t};\n";
  101. }
  102. ?>
  103. if (document.all || document.getElementById)
  104. {
  105. for (var i = 0; i < the_form.length; ++i)
  106. {
  107. var elem = the_form.elements[i];
  108. if (elem.name && required_fields[elem.name] && !elem.value && elem.type && (/^(?:text(?:area)?|password|file)$/i.test(elem.type)))
  109. {
  110. alert('"' + required_fields[elem.name] + '" <?php echo $lang_common['required field'] ?>');
  111. elem.focus();
  112. return false;
  113. }
  114. }
  115. }
  116. return true;
  117. }
  118. /* ]]> */
  119. </script>
  120. <?php
  121. }
  122. if (!empty($page_head))
  123. echo implode("\n", $page_head)."\n";
  124. $tpl_temp = trim(ob_get_contents());
  125. $tpl_main = str_replace('<pun_head>', $tpl_temp, $tpl_main);
  126. ob_end_clean();
  127. // END SUBST - <pun_head>
  128. // START SUBST - <body>
  129. if (isset($focus_element))
  130. {
  131. $tpl_main = str_replace('<body onload="', '<body onload="document.getElementById(\''.$focus_element[0].'\').elements[\''.$focus_element[1].'\'].focus();', $tpl_main);
  132. $tpl_main = str_replace('<body>', '<body onload="document.getElementById(\''.$focus_element[0].'\').elements[\''.$focus_element[1].'\'].focus()">', $tpl_main);
  133. }
  134. // END SUBST - <body>
  135. // START SUBST - <pun_page>
  136. $tpl_main = str_replace('<pun_page>', htmlspecialchars(basename($_SERVER['PHP_SELF'], '.php')), $tpl_main);
  137. // END SUBST - <pun_page>
  138. // START SUBST - <pun_title>
  139. $tpl_main = str_replace('<pun_title>', '<h1><a href="index.php">'.pun_htmlspecialchars($pun_config['o_board_title']).'</a></h1>', $tpl_main);
  140. // END SUBST - <pun_title>
  141. // START SUBST - <pun_desc>
  142. $tpl_main = str_replace('<pun_desc>', '<div id="brddesc">'.$pun_config['o_board_desc'].'</div>', $tpl_main);
  143. // END SUBST - <pun_desc>
  144. // START SUBST - <pun_navlinks>
  145. $links = array();
  146. // Index should always be displayed
  147. $links[] = '<li id="navindex"'.((PUN_ACTIVE_PAGE == 'index') ? ' class="isactive"' : '').'><a href="index.php">'.$lang_common['Index'].'</a></li>';
  148. if ($pun_user['g_read_board'] == '1' && $pun_user['g_view_users'] == '1')
  149. $links[] = '<li id="navuserlist"'.((PUN_ACTIVE_PAGE == 'userlist') ? ' class="isactive"' : '').'><a href="userlist.php">'.$lang_common['User list'].'</a></li>';
  150. if ($pun_config['o_rules'] == '1' && (!$pun_user['is_guest'] || $pun_user['g_read_board'] == '1' || $pun_config['o_regs_allow'] == '1'))
  151. $links[] = '<li id="navrules"'.((PUN_ACTIVE_PAGE == 'rules') ? ' class="isactive"' : '').'><a href="misc.php?action=rules">'.$lang_common['Rules'].'</a></li>';
  152. if ($pun_user['g_read_board'] == '1' && $pun_user['g_search'] == '1')
  153. $links[] = '<li id="navsearch"'.((PUN_ACTIVE_PAGE == 'search') ? ' class="isactive"' : '').'><a href="search.php">'.$lang_common['Search'].'</a></li>';
  154. if ($pun_user['is_guest'])
  155. {
  156. $links[] = '<li id="navregister"'.((PUN_ACTIVE_PAGE == 'register') ? ' class="isactive"' : '').'><a href="register.php">'.$lang_common['Register'].'</a></li>';
  157. $links[] = '<li id="navlogin"'.((PUN_ACTIVE_PAGE == 'login') ? ' class="isactive"' : '').'><a href="login.php">'.$lang_common['Login'].'</a></li>';
  158. }
  159. else
  160. {
  161. $links[] = '<li id="navprofile"'.((PUN_ACTIVE_PAGE == 'profile') ? ' class="isactive"' : '').'><a href="profile.php?id='.$pun_user['id'].'">'.$lang_common['Profile'].'</a></li>';
  162. if ($pun_user['is_admmod'])
  163. $links[] = '<li id="navadmin"'.((PUN_ACTIVE_PAGE == 'admin') ? ' class="isactive"' : '').'><a href="admin_index.php">'.$lang_common['Admin'].'</a></li>';
  164. $links[] = '<li id="navlogout"><a href="login.php?action=out&amp;id='.$pun_user['id'].'&amp;csrf_token='.pun_csrf_token().'">'.$lang_common['Logout'].'</a></li>';
  165. }
  166. // Are there any additional navlinks we should insert into the array before imploding it?
  167. if ($pun_user['g_read_board'] == '1' && $pun_config['o_additional_navlinks'] != '')
  168. {
  169. if (preg_match_all('%([0-9]+)\s*=\s*(.*?)\n%s', $pun_config['o_additional_navlinks']."\n", $extra_links))
  170. {
  171. // Insert any additional links into the $links array (at the correct index)
  172. $num_links = count($extra_links[1]);
  173. for ($i = 0; $i < $num_links; ++$i)
  174. array_splice($links, $extra_links[1][$i], 0, array('<li id="navextra'.($i + 1).'">'.$extra_links[2][$i].'</li>'));
  175. }
  176. }
  177. $tpl_temp = '<div id="brdmenu" class="inbox">'."\n\t\t\t".'<ul>'."\n\t\t\t\t".implode("\n\t\t\t\t", $links)."\n\t\t\t".'</ul>'."\n\t\t".'</div>';
  178. $tpl_main = str_replace('<pun_navlinks>', $tpl_temp, $tpl_main);
  179. // END SUBST - <pun_navlinks>
  180. // START SUBST - <pun_status>
  181. $page_statusinfo = $page_topicsearches = array();
  182. if ($pun_user['is_guest'])
  183. $page_statusinfo = '<p class="conl">'.$lang_common['Not logged in'].'</p>';
  184. else
  185. {
  186. $page_statusinfo[] = '<li><span>'.$lang_common['Logged in as'].' <strong>'.pun_htmlspecialchars($pun_user['username']).'</strong></span></li>';
  187. $page_statusinfo[] = '<li><span>'.sprintf($lang_common['Last visit'], format_time($pun_user['last_visit'])).'</span></li>';
  188. if ($pun_user['is_admmod'])
  189. {
  190. if ($pun_config['o_report_method'] == '0' || $pun_config['o_report_method'] == '2')
  191. {
  192. $result_header = $db->query('SELECT 1 FROM '.$db->prefix.'reports WHERE zapped IS NULL') or error('Unable to fetch reports info', __FILE__, __LINE__, $db->error());
  193. if ($db->result($result_header))
  194. $page_statusinfo[] = '<li class="reportlink"><span><strong><a href="admin_reports.php">'.$lang_common['New reports'].'</a></strong></span></li>';
  195. }
  196. if ($pun_config['o_maintenance'] == '1')
  197. $page_statusinfo[] = '<li class="maintenancelink"><span><strong><a href="admin_options.php#maintenance">'.$lang_common['Maintenance mode enabled'].'</a></strong></span></li>';
  198. }
  199. if ($pun_user['g_read_board'] == '1' && $pun_user['g_search'] == '1')
  200. {
  201. $page_topicsearches[] = '<a href="search.php?action=show_replies" title="'.$lang_common['Show posted topics'].'">'.$lang_common['Posted topics'].'</a>';
  202. $page_topicsearches[] = '<a href="search.php?action=show_new" title="'.$lang_common['Show new posts'].'">'.$lang_common['New posts header'].'</a>';
  203. }
  204. }
  205. // Quick searches
  206. if ($pun_user['g_read_board'] == '1' && $pun_user['g_search'] == '1')
  207. {
  208. $page_topicsearches[] = '<a href="search.php?action=show_recent" title="'.$lang_common['Show active topics'].'">'.$lang_common['Active topics'].'</a>';
  209. $page_topicsearches[] = '<a href="search.php?action=show_unanswered" title="'.$lang_common['Show unanswered topics'].'">'.$lang_common['Unanswered topics'].'</a>';
  210. }
  211. // Generate all that jazz
  212. $tpl_temp = '<div id="brdwelcome" class="inbox">';
  213. // The status information
  214. if (is_array($page_statusinfo))
  215. {
  216. $tpl_temp .= "\n\t\t\t".'<ul class="conl">';
  217. $tpl_temp .= "\n\t\t\t\t".implode("\n\t\t\t\t", $page_statusinfo);
  218. $tpl_temp .= "\n\t\t\t".'</ul>';
  219. }
  220. else
  221. $tpl_temp .= "\n\t\t\t".$page_statusinfo;
  222. // Generate quicklinks
  223. if (!empty($page_topicsearches))
  224. {
  225. $tpl_temp .= "\n\t\t\t".'<ul class="conr">';
  226. $tpl_temp .= "\n\t\t\t\t".'<li><span>'.$lang_common['Topic searches'].' '.implode(' | ', $page_topicsearches).'</span></li>';
  227. $tpl_temp .= "\n\t\t\t".'</ul>';
  228. }
  229. $tpl_temp .= "\n\t\t\t".'<div class="clearer"></div>'."\n\t\t".'</div>';
  230. $tpl_main = str_replace('<pun_status>', $tpl_temp, $tpl_main);
  231. // END SUBST - <pun_status>
  232. // START SUBST - <pun_announcement>
  233. if ($pun_user['g_read_board'] == '1' && $pun_config['o_announcement'] == '1')
  234. {
  235. ob_start();
  236. ?>
  237. <div id="announce" class="block">
  238. <div class="hd"><h2><span><?php echo $lang_common['Announcement'] ?></span></h2></div>
  239. <div class="box">
  240. <div id="announce-block" class="inbox">
  241. <div class="usercontent"><?php echo $pun_config['o_announcement_message'] ?></div>
  242. </div>
  243. </div>
  244. </div>
  245. <?php
  246. $tpl_temp = trim(ob_get_contents());
  247. $tpl_main = str_replace('<pun_announcement>', $tpl_temp, $tpl_main);
  248. ob_end_clean();
  249. }
  250. else
  251. $tpl_main = str_replace('<pun_announcement>', '', $tpl_main);
  252. // END SUBST - <pun_announcement>
  253. // START SUBST - <pun_main>
  254. ob_start();
  255. define('PUN_HEADER', 1);