PageRenderTime 63ms CodeModel.GetById 37ms RepoModel.GetById 1ms app.codeStats 0ms

/header.php

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