source: trunk/web/punbb/header.php

Last change on this file was 6, checked in by dj3c1t, 13 years ago

mise a jour du trunk

File size: 11.4 KB
Line 
1<?php
2
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 */
8
9// Make sure no one attempts to run this script "directly"
10if (!defined('PUN'))
11        exit;
12
13// Send no-cache headers
14header('Expires: Thu, 21 Jul 1977 07:30:00 GMT'); // When yours truly first set eyes on this world! :)
15header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
16header('Cache-Control: post-check=0, pre-check=0', false);
17header('Pragma: no-cache'); // For HTTP/1.0 compatibility
18
19// Send the Content-type header in case the web server is setup to send something else
20header('Content-type: text/html; charset=utf-8');
21
22// Load the template
23if (defined('PUN_ADMIN_CONSOLE'))
24        $tpl_file = 'admin.tpl';
25else if (defined('PUN_HELP'))
26        $tpl_file = 'help.tpl';
27else
28        $tpl_file = 'main.tpl';
29
30if (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}
35else
36{
37        $tpl_file = PUN_ROOT.'include/template/'.$tpl_file;
38        $tpl_inc_dir = PUN_ROOT.'include/user/';
39}
40
41$tpl_main = file_get_contents($tpl_file);
42
43// START SUBST - <pun_include "*">
44preg_match_all('%<pun_include "([^/\\\\]*?)\.(php[45]?|inc|html?|txt)">%i', $tpl_main, $pun_includes, PREG_SET_ORDER);
45
46foreach ($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
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>
76ob_start();
77
78// Define $p if its not set to avoid a PHP notice
79$p = isset($p) ? $p : null;
80
81// Is this a page that we want search index spiders to index?
82if (!defined('PUN_ALLOW_INDEX'))
83        echo '<meta name="ROBOTS" content="NOINDEX, FOLLOW" />'."\n";
84
85?>
86<title><?php echo generate_page_title($page_title, $p) ?></title>
87<link rel="stylesheet" type="text/css" href="style/<?php echo $pun_user['style'].'.css' ?>" />
88<?php
89
90if (defined('PUN_ADMIN_CONSOLE'))
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}
97
98if (isset($required_fields))
99{
100        // Output JavaScript to validate form (make sure required fields are filled out)
101
102?>
103<script type="text/javascript">
104/* <![CDATA[ */
105function process_form(the_form)
106{
107        var element_names = {
108<?php
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('&#160;', ' ', $elem_trans));
114                if (--$tpl_temp) echo "\",\n";
115                else echo "\"\n\t};\n";
116        }
117?>
118        if (document.all || document.getElementById)
119        {
120                for (var i = 0; i < the_form.length; ++i)
121                {
122                        var elem = the_form.elements[i];
123                        if (elem.name && (/^req_/.test(elem.name)))
124                        {
125                                if (!elem.value && elem.type && (/^(?:text(?:area)?|password|file)$/i.test(elem.type)))
126                                {
127                                        alert('"' + element_names[elem.name] + '" <?php echo $lang_common['required field'] ?>');
128                                        elem.focus();
129                                        return false;
130                                }
131                        }
132                }
133        }
134        return true;
135}
136/* ]]> */
137</script>
138<?php
139
140}
141
142// JavaScript tricks for IE6 and older
143echo '<!--[if lte IE 6]><script type="text/javascript" src="style/imports/minmax.js"></script><![endif]-->'."\n";
144
145if (isset($page_head))
146        echo implode("\n", $page_head)."\n";
147
148$tpl_temp = trim(ob_get_contents());
149$tpl_main = str_replace('<pun_head>', $tpl_temp, $tpl_main);
150ob_end_clean();
151// END SUBST - <pun_head>
152
153
154// START SUBST - <body>
155if (isset($focus_element))
156{
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);
159}
160// END SUBST - <body>
161
162
163// START SUBST - <pun_page>
164$tpl_main = str_replace('<pun_page>', htmlspecialchars(basename($_SERVER['PHP_SELF'], '.php')), $tpl_main);
165// END SUBST - <pun_page>
166
167
168// START SUBST - <pun_title>
169$tpl_main = str_replace('<pun_title>', '<h1><a href="index.php">'.pun_htmlspecialchars($pun_config['o_board_title']).'</a></h1>', $tpl_main);
170// END SUBST - <pun_title>
171
172
173// START SUBST - <pun_desc>
174$tpl_main = str_replace('<pun_desc>', '<div id="brddesc">'.$pun_config['o_board_desc'].'</div>', $tpl_main);
175// END SUBST - <pun_desc>
176
177
178// START SUBST - <pun_navlinks>
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
184if ($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
187if ($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
190if ($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
193if ($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}
198else
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&amp;id='.$pun_user['id'].'&amp;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?
209if ($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);
222// END SUBST - <pun_navlinks>
223
224
225// START SUBST - <pun_status>
226$page_statusinfo = $page_topicsearches = array();
227
228if ($pun_user['is_guest'])
229        $page_statusinfo = '<p class="conl">'.$lang_common['Not logged in'].'</p>';
230else
231{
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>';
234
235        if ($pun_user['is_admmod'])
236        {
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());
240
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                }
244
245                if ($pun_config['o_maintenance'] == '1')
246                        $page_statusinfo[] = '<li class="maintenancelink"><span><strong><a href="admin_options.php#maintenance">'.$lang_common['Maintenance mode enabled'].'</a></strong></span></li>';
247        }
248
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        }
254}
255
256// Quick searches
257if ($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
268if (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}
274else
275        $tpl_temp .= "\n\t\t\t".$page_statusinfo;
276
277// Generate quicklinks
278if (!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
287$tpl_main = str_replace('<pun_status>', $tpl_temp, $tpl_main);
288// END SUBST - <pun_status>
289
290
291// START SUBST - <pun_announcement>
292if ($pun_user['g_read_board'] == '1' && $pun_config['o_announcement'] == '1')
293{
294        ob_start();
295
296?>
297<div id="announce" class="block">
298        <div class="hd"><h2><span><?php echo $lang_common['Announcement'] ?></span></h2></div>
299        <div class="box">
300                <div id="announce-block" class="inbox">
301                        <div class="usercontent"><?php echo $pun_config['o_announcement_message'] ?></div>
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}
311else
312        $tpl_main = str_replace('<pun_announcement>', '', $tpl_main);
313// END SUBST - <pun_announcement>
314
315
316// START SUBST - <pun_main>
317ob_start();
318
319
320define('PUN_HEADER', 1);
Note: See TracBrowser for help on using the repository browser.