PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/header.php

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