PageRenderTime 58ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/header.php

https://github.com/karpenoktem/punbb
PHP | 316 lines | 182 code | 83 blank | 51 comment | 80 complexity | eb8677bb0fd3e8dd892a337e9eb1bd23 MD5 | raw file
  1. <?php
  2. /**
  3. * Outputs the header used by most forum pages.
  4. *
  5. * @copyright (C) 2008-2012 PunBB, partially based on code (C) 2008-2009 FluxBB.org
  6. * @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
  7. * @package PunBB
  8. */
  9. // Make sure no one attempts to run this script "directly"
  10. if (!defined('FORUM'))
  11. exit;
  12. // Send no-cache headers
  13. header('Expires: Thu, 21 Jul 1977 07:30:00 GMT'); // When yours truly first set eyes on this world! :)
  14. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  15. header('Cache-Control: post-check=0, pre-check=0', false);
  16. header('Pragma: no-cache'); // For HTTP/1.0 compability
  17. // Send the Content-type header in case the web server is setup to send something else
  18. header('Content-type: text/html; charset=utf-8');
  19. // Load the main template
  20. if (substr(FORUM_PAGE, 0, 5) == 'admin')
  21. {
  22. if ($forum_user['style'] != 'Oxygen' && file_exists(FORUM_ROOT.'style/'.$forum_user['style'].'/admin.tpl'))
  23. $tpl_path = FORUM_ROOT.'style/'.$forum_user['style'].'/admin.tpl';
  24. else
  25. $tpl_path = FORUM_ROOT.'include/template/admin.tpl';
  26. }
  27. else if (FORUM_PAGE == 'help')
  28. {
  29. if ($forum_user['style'] != 'Oxygen' && file_exists(FORUM_ROOT.'style/'.$forum_user['style'].'/help.tpl'))
  30. $tpl_path = FORUM_ROOT.'style/'.$forum_user['style'].'/help.tpl';
  31. else
  32. $tpl_path = FORUM_ROOT.'include/template/help.tpl';
  33. }
  34. else
  35. {
  36. if ($forum_user['style'] != 'Oxygen' && file_exists(FORUM_ROOT.'style/'.$forum_user['style'].'/main.tpl'))
  37. $tpl_path = FORUM_ROOT.'style/'.$forum_user['style'].'/main.tpl';
  38. else
  39. $tpl_path = FORUM_ROOT.'include/template/main.tpl';
  40. }
  41. ($hook = get_hook('hd_pre_template_loaded')) ? eval($hook) : null;
  42. $tpl_main = file_get_contents($tpl_path);
  43. ($hook = get_hook('hd_template_loaded')) ? eval($hook) : null;
  44. // START SUBST - <!-- forum_include "*" -->
  45. while (preg_match('#<!-- ?forum_include "([^/\\\\]*?)" ?-->#', $tpl_main, $cur_include))
  46. {
  47. if (!file_exists(FORUM_ROOT.'include/user/'.$cur_include[1]))
  48. error('Unable to process user include &lt;!-- forum_include "'.forum_htmlencode($cur_include[1]).'" --&gt; from template main.tpl.<br />There is no such file in folder /include/user/', __FILE__, __LINE__);
  49. ob_start();
  50. include FORUM_ROOT.'include/user/'.$cur_include[1];
  51. $tpl_temp = ob_get_contents();
  52. $tpl_main = str_replace($cur_include[0], $tpl_temp, $tpl_main);
  53. ob_end_clean();
  54. }
  55. // END SUBST - <!-- forum_include "*" -->
  56. // START SUBST - <!-- forum_local -->
  57. $tpl_main = str_replace('<!-- forum_local -->', 'lang="'.$lang_common['lang_identifier'].'" dir="'.$lang_common['lang_direction'].'"', $tpl_main);
  58. // END SUBST - <!-- forum_local -->
  59. // START SUBST - <!-- forum_head -->
  60. // Is this a page that we want search index spiders to index?
  61. if (!defined('FORUM_ALLOW_INDEX'))
  62. $forum_head['robots'] = '<meta name="ROBOTS" content="NOINDEX, FOLLOW" />';
  63. else
  64. $forum_head['descriptions'] = '<meta name="description" content="'.generate_crumbs(true).$lang_common['Title separator'].forum_htmlencode($forum_config['o_board_desc']).'" />';
  65. // Should we output a MicroID? http://microid.org/
  66. if (strpos(FORUM_PAGE, 'profile') === 0)
  67. $forum_head['microid'] = '<meta name="microid" content="mailto+http:sha1:'.sha1(sha1('mailto:'.$user['email']).sha1(forum_link($forum_url['user'], $id))).'" />';
  68. $forum_head['title'] = '<title>'.generate_crumbs(true).'</title>';
  69. // Should we output feed links?
  70. if (FORUM_PAGE == 'index')
  71. {
  72. $forum_head['rss'] = '<link rel="alternate" type="application/rss+xml" href="'.forum_link($forum_url['index_rss']).'" title="RSS" />';
  73. $forum_head['atom'] = '<link rel="alternate" type="application/atom+xml" href="'.forum_link($forum_url['index_atom']).'" title="ATOM" />';
  74. }
  75. else if (FORUM_PAGE == 'viewforum')
  76. {
  77. $forum_head['rss'] = '<link rel="alternate" type="application/rss+xml" href="'.forum_link($forum_url['forum_rss'], $id).'" title="RSS" />';
  78. $forum_head['atom'] = '<link rel="alternate" type="application/atom+xml" href="'.forum_link($forum_url['forum_atom'], $id).'" title="ATOM" />';
  79. }
  80. else if (FORUM_PAGE == 'viewtopic')
  81. {
  82. $forum_head['rss'] = '<link rel="alternate" type="application/rss+xml" href="'.forum_link($forum_url['topic_rss'], $id).'" title="RSS" />';
  83. $forum_head['atom'] = '<link rel="alternate" type="application/atom+xml" href="'.forum_link($forum_url['topic_atom'], $id).'" title="ATOM" />';
  84. }
  85. // If there are other page navigation links (first, next, prev and last)
  86. if (!empty($forum_page['nav']))
  87. $forum_head['nav'] = implode("\n", $forum_page['nav']);
  88. if ($forum_user['g_read_board'] == '1' && $forum_user['g_search'] == '1')
  89. {
  90. $forum_head['search'] = '<link rel="search" type="text/html" href="'.forum_link($forum_url['search']).'" title="'.$lang_common['Search'].'" />';
  91. $forum_head['opensearch'] = '<link rel="search" type="application/opensearchdescription+xml" href="'.forum_link($forum_url['opensearch']).'" title="'.forum_htmlencode($forum_config['o_board_title']).'" />';
  92. }
  93. $forum_head['author'] = '<link rel="author" type="text/html" href="'.forum_link($forum_url['users']).'" title="'.$lang_common['User list'].'" />';
  94. ob_start();
  95. // Include stylesheets
  96. require FORUM_ROOT.'style/'.$forum_user['style'].'/'.$forum_user['style'].'.php';
  97. $head_temp = forum_trim(ob_get_contents());
  98. $num_temp = 0;
  99. foreach (explode("\n", $head_temp) as $style_temp)
  100. $forum_head['style'.$num_temp++] = $style_temp;
  101. ob_end_clean();
  102. ($hook = get_hook('hd_head')) ? eval($hook) : null;
  103. // Render CSS from forum_loader
  104. $tmp_head = implode("\n", $forum_head).$forum_loader->render_css();
  105. $tpl_main = str_replace('<!-- forum_head -->', $tmp_head, $tpl_main);
  106. unset($forum_head, $tmp_head);
  107. // END SUBST - <!-- forum_head -->
  108. // START SUBST OF COMMON ELEMENTS
  109. // Setup array of general elements
  110. $gen_elements = array();
  111. // Forum page id and classes
  112. if (!defined('FORUM_PAGE_TYPE'))
  113. {
  114. if (substr(FORUM_PAGE, 0, 5) == 'admin')
  115. define('FORUM_PAGE_TYPE', 'admin-page');
  116. else
  117. {
  118. if (!empty($forum_page['page_post']))
  119. define('FORUM_PAGE_TYPE', 'paged-page');
  120. else if (!empty($forum_page['main_menu']))
  121. define('FORUM_PAGE_TYPE', 'menu-page');
  122. else
  123. define('FORUM_PAGE_TYPE', 'basic-page');
  124. }
  125. }
  126. $gen_elements['<!-- forum_page -->'] = 'id="brd-'.FORUM_PAGE.'" class="brd-page '.FORUM_PAGE_TYPE.'"';
  127. // Skip link
  128. $gen_elements['<!-- forum_skip -->'] = '<p id="brd-access"><a href="#brd-main">'.$lang_common['Skip to content'].'</a></p>';
  129. // Forum Title
  130. $gen_elements['<!-- forum_title -->'] = '<p id="brd-title"><a href="'.forum_link($forum_url['index']).'">'.forum_htmlencode($forum_config['o_board_title']).'</a></p>';
  131. // Forum Description
  132. $gen_elements['<!-- forum_desc -->'] = ($forum_config['o_board_desc'] != '') ? '<p id="brd-desc">'.forum_htmlencode($forum_config['o_board_desc']).'</p>' : '';
  133. // Main Navigation
  134. $gen_elements['<!-- forum_navlinks -->'] = '<ul>'."\n\t\t".generate_navlinks()."\n\t".'</ul>';
  135. // Announcement
  136. $gen_elements['<!-- forum_announcement -->'] = ($forum_config['o_announcement'] == '1' && $forum_user['g_read_board'] == '1') ? '<div id="brd-announcement" class="gen-content">'.($forum_config['o_announcement_heading'] != '' ? "\n\t".'<h1 class="hn"><span>'.$forum_config['o_announcement_heading'].'</span></h1>' : '')."\n\t".'<div class="content">'.$forum_config['o_announcement_message'].'</div>'."\n".'</div>'."\n" : '';
  137. // Flash messages
  138. $gen_elements['<!-- forum_messages -->'] = '<div id="brd-messages" class="brd">'.$forum_flash->show(true).'</div>'."\n";
  139. // Maintenance Warning
  140. $gen_elements['<!-- forum_maint -->'] = ($forum_user['g_id'] == FORUM_ADMIN && $forum_config['o_maintenance'] == '1') ? '<p id="maint-alert" class="warn">'.sprintf($lang_common['Maintenance warning'], '<a href="'.forum_link($forum_url['admin_settings_maintenance']).'">'.$lang_common['Maintenance mode'].'</a>').'</p>' : '';
  141. ($hook = get_hook('hd_gen_elements')) ? eval($hook) : null;
  142. $tpl_main = str_replace(array_keys($gen_elements), array_values($gen_elements), $tpl_main);
  143. unset($gen_elements);
  144. // END SUBST OF COMMON ELEMENTS
  145. // START SUBST VISIT ELEMENTS
  146. $visit_elements = array();
  147. if ($forum_user['is_guest'])
  148. $visit_elements['<!-- forum_welcome -->'] = '<p id="welcome"><span>'.$lang_common['Not logged in'].'</span> <span>'.$lang_common['Login nag'].'</span></p>';
  149. else
  150. $visit_elements['<!-- forum_welcome -->'] = '<p id="welcome"><span>'.sprintf($lang_common['Logged in as'], '<strong>'.forum_htmlencode($forum_user['username']).'</strong>').'</span></p>';
  151. if ($forum_user['g_read_board'] == '1' && $forum_user['g_search'] == '1')
  152. {
  153. $visit_links = array();
  154. if (!$forum_user['is_guest'])
  155. $visit_links['newposts'] = '<span id="visit-new"'.(empty($visit_links) ? ' class="first-item"' : '').'><a href="'.forum_link($forum_url['search_new']).'" title="'.$lang_common['New posts title'].'">'.$lang_common['New posts'].'</a></span>';
  156. $visit_links['recent'] = '<span id="visit-recent"'.(empty($visit_links) ? ' class="first-item"' : '').'><a href="'.forum_link($forum_url['search_recent']).'" title="'.$lang_common['Active topics title'].'">'.$lang_common['Active topics'].'</a></span>';
  157. $visit_links['unanswered'] = '<span id="visit-unanswered"'.(empty($visit_links) ? ' class="first-item"' : '').'><a href="'.forum_link($forum_url['search_unanswered']).'" title="'.$lang_common['Unanswered topics title'].'">'.$lang_common['Unanswered topics'].'</a></span>';
  158. }
  159. ($hook = get_hook('hd_visit_elements')) ? eval($hook) : null;
  160. $visit_elements['<!-- forum_visit -->'] = (!empty($visit_links)) ? '<p id="visit-links" class="options">'.implode(' ', $visit_links).'</p>' : '';
  161. $tpl_main = str_replace(array_keys($visit_elements), array_values($visit_elements), $tpl_main);
  162. unset($visit_elements);
  163. // END SUBST VISIT ELEMENTS
  164. // START SUBST - <!-- forum_admod -->
  165. $admod_links = array();
  166. // We only need to run this query for mods/admins if there will actually be reports to look at
  167. if ($forum_user['is_admmod'] && $forum_config['o_report_method'] != 1)
  168. {
  169. $query = array(
  170. 'SELECT' => 'COUNT(r.id)',
  171. 'FROM' => 'reports AS r',
  172. 'WHERE' => 'r.zapped IS NULL',
  173. );
  174. ($hook = get_hook('hd_qr_get_unread_reports_count')) ? eval($hook) : null;
  175. $result_header = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  176. if ($forum_db->result($result_header))
  177. $admod_links['reports'] = '<li id="reports"><a href="'.forum_link($forum_url['admin_reports']).'">'.$lang_common['New reports'].'</a></li>';
  178. }
  179. if ($forum_user['g_id'] == FORUM_ADMIN)
  180. {
  181. $alert_items = array();
  182. // Warn the admin that maintenance mode is enabled
  183. if ($forum_config['o_maintenance'] == '1')
  184. $alert_items['maintenance'] = '<p id="maint-alert" class="warn">'.$lang_common['Maintenance alert'].'</p>';
  185. if ($forum_config['o_check_for_updates'] == '1')
  186. {
  187. if ($forum_updates['fail'])
  188. $alert_items['update_fail'] = '<p><strong>'.$lang_common['Updates'].'</strong> '.$lang_common['Updates failed'].'</p>';
  189. else if (isset($forum_updates['version']) && isset($forum_updates['hotfix']))
  190. $alert_items['update_version_hotfix'] = '<p><strong>'.$lang_common['Updates'].'</strong> '.sprintf($lang_common['Updates version n hf'], $forum_updates['version'], forum_link($forum_url['admin_extensions_hotfixes'])).'</p>';
  191. else if (isset($forum_updates['version']))
  192. $alert_items['update_version'] = '<p><strong>'.$lang_common['Updates'].'</strong> '.sprintf($lang_common['Updates version'], $forum_updates['version']).'</p>';
  193. else if (isset($forum_updates['hotfix']))
  194. $alert_items['update_hotfix'] = '<p><strong>'.$lang_common['Updates'].'</strong> '.sprintf($lang_common['Updates hf'], forum_link($forum_url['admin_extensions_hotfixes'])).'</p>';
  195. }
  196. // Warn the admin that their version of the database is newer than the version supported by the code
  197. // NOTE: Why is it done on any page, but shown in admin section only.
  198. if ($forum_config['o_database_revision'] > FORUM_DB_REVISION)
  199. $alert_items['newer_database'] = '<p><strong>'.$lang_common['Database mismatch'].'</strong> '.$lang_common['Database mismatch alert'].'</p>';
  200. if (!empty($alert_items))
  201. $admod_links['alert'] = '<li id="alert"><a href="'.forum_link($forum_url['admin_index']).'">'.$lang_common['New alerts'].'</a></li>';
  202. ($hook = get_hook('hd_alert')) ? eval($hook) : null;
  203. }
  204. $tpl_main = str_replace('<!-- forum_admod -->', (!empty($admod_links)) ? '<ul id="brd-admod">'.implode(' ', $admod_links).'</ul>' : '', $tpl_main);
  205. // END SUBST - <!-- forum_admod -->
  206. // MAIN SECTION INTERFACE ELEMENT SUBSTITUTION
  207. $main_elements = array();
  208. // Top breadcrumbs
  209. $main_elements['<!-- forum_crumbs_top -->'] = (FORUM_PAGE != 'index') ? '<div id="brd-crumbs-top" class="crumbs">'."\n\t".'<p>'.generate_crumbs(false).'</p>'."\n".'</div>' : '';
  210. // Bottom breadcrumbs
  211. $main_elements['<!-- forum_crumbs_end -->'] = (FORUM_PAGE != 'index') ? '<div id="brd-crumbs-end" class="crumbs">'."\n\t".'<p>'.generate_crumbs(false).'</p>'."\n".'</div>' : '';
  212. // Main section heading
  213. $main_elements['<!-- forum_main_title -->'] = '<h1 class="main-title">'.((isset($forum_page['main_title'])) ? $forum_page['main_title'] : forum_htmlencode(is_array($last_crumb = end($forum_page['crumbs'])) ? reset($last_crumb) : $last_crumb)).(isset($forum_page['main_head_pages']) ? ' <small>'.$forum_page['main_head_pages'].'</small>' : '').'</h1>'."\n";
  214. // Top pagination and post links
  215. $main_elements['<!-- forum_main_pagepost_top -->'] = (!empty($forum_page['page_post'])) ? '<div id="brd-pagepost-top" class="main-pagepost gen-content">'."\n\t".implode("\n\t", $forum_page['page_post'])."\n".'</div>' : '';
  216. // Bottom pagination and postlink
  217. $main_elements['<!-- forum_main_pagepost_end -->'] = (!empty($forum_page['page_post'])) ? '<div id="brd-pagepost-end" class="main-pagepost gen-content">'."\n\t".implode("\n\t", $forum_page['page_post'])."\n".'</div>' : '';
  218. // Main section menu e.g. profile menu
  219. $main_elements['<!-- forum_main_menu -->'] = (!empty($forum_page['main_menu'])) ? '<div class="main-menu gen-content">'."\n\t".'<ul>'."\n\t\t".implode("\n\t\t", $forum_page['main_menu'])."\n\t".'</ul>'."\n".'</div>' : '';
  220. // Main section menu e.g. profile menu
  221. if (substr(FORUM_PAGE, 0, 5) == 'admin' && FORUM_PAGE_TYPE != 'paged')
  222. {
  223. $main_elements['<!-- forum_admin_menu -->'] = '<div class="admin-menu gen-content">'."\n\t".'<ul>'."\n\t\t".generate_admin_menu(false)."\n\t".'</ul>'."\n".'</div>';
  224. $forum_page['admin_sub'] = generate_admin_menu(true);
  225. $main_elements['<!-- forum_admin_submenu -->'] = ($forum_page['admin_sub'] != '') ? '<div class="admin-submenu gen-content">'."\n\t".'<ul>'."\n\t\t".$forum_page['admin_sub']."\n\t".'</ul>'."\n".'</div>' : '';
  226. }
  227. ($hook = get_hook('hd_main_elements')) ? eval($hook) : null;
  228. $tpl_main = str_replace(array_keys($main_elements), array_values($main_elements), $tpl_main);
  229. unset($main_elements);
  230. // END MAIN SECTION INTERFACE ELEMENT SUBSTITUTION
  231. ($hook = get_hook('hd_end')) ? eval($hook) : null;
  232. if (!defined('FORUM_HEADER'))
  233. define('FORUM_HEADER', 1);