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