-
Notifications
You must be signed in to change notification settings - Fork 0
/
header.php
364 lines (293 loc) · 12.9 KB
/
header.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<?php
/**
* Copyright (C) 2013-2014 ModernBB Group
* Based on code by FluxBB copyright (C) 2008-2012 FluxBB
* Based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
* Licensed under GPLv3 (http://modernbb.be/license.php)
*/
// Make sure no one attempts to run this script "directly"
if (!defined('FORUM'))
exit;
// Send no-cache headers
header('Expires: Thu, 21 Jul 1977 07:30:00 GMT'); // When yours truly first set eyes on this world! :)
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache'); // For HTTP/1.0 compatibility
// Send the Content-type header in case the web server is setup to send something else
header('Content-type: text/html; charset=utf-8');
// Prevent site from being embedded in a frame
header('X-Frame-Options: deny');
// Load the template
if (!defined('FORUM_FORM'))
$tpl_file = 'main.tpl';
else
$tpl_file = 'form.tpl';
if (file_exists(FORUM_ROOT.'style/'.$luna_user['style'].'/templates/'.$tpl_file))
{
$tpl_file = FORUM_ROOT.'style/'.$luna_user['style'].'/templates/'.$tpl_file;
$tpl_inc_dir = FORUM_ROOT.'style/'.$luna_user['style'].'/';
}
else
{
$tpl_file = FORUM_ROOT.'style/Core/templates/'.$tpl_file;
$tpl_inc_dir = FORUM_ROOT.'style/User/';
}
$tpl_main = file_get_contents($tpl_file);
// START SUBST - <luna_include "*">
preg_match_all('%<luna_include "([^"]+)">%i', $tpl_main, $luna_includes, PREG_SET_ORDER);
foreach ($luna_includes as $cur_include)
{
ob_start();
$file_info = pathinfo($cur_include[1]);
if (!in_array($file_info['extension'], array('php', 'php4', 'php5', 'inc', 'html', 'txt'))) // Allow some extensions
error(sprintf($lang['Pun include extension'], htmlspecialchars($cur_include[0]), basename($tpl_file), htmlspecialchars($file_info['extension'])));
if (strpos($file_info['dirname'], '..') !== false) // Don't allow directory traversal
error(sprintf($lang['Pun include directory'], htmlspecialchars($cur_include[0]), basename($tpl_file)));
// Allow for overriding user includes, too.
if (file_exists($tpl_inc_dir.$cur_include[1]))
require $tpl_inc_dir.$cur_include[1];
else if (file_exists(FORUM_ROOT.'include/user/'.$cur_include[1]))
require FORUM_ROOT.'include/user/'.$cur_include[1];
else
error(sprintf($lang['Pun include error'], luna_htmlspecialchars($cur_include[0]), basename($tpl_file)));
$tpl_temp = ob_get_contents();
$tpl_main = str_replace($cur_include[0], $tpl_temp, $tpl_main);
ob_end_clean();
}
// END SUBST - <luna_include "*">
// START SUBST - <luna_language>
$tpl_main = str_replace('<luna_language>', $lang['lang_identifier'], $tpl_main);
// END SUBST - <luna_language>
// START SUBST - <luna_content_direction>
$tpl_main = str_replace('<luna_content_direction>', $lang['lang_direction'], $tpl_main);
// END SUBST - <luna_content_direction>
// START SUBST - <luna_head>
ob_start();
// Define $p if it's not set to avoid a PHP notice
$p = isset($p) ? $p : null;
// Is this a page that we want search index spiders to index?
if (!defined('FORUM_ALLOW_INDEX'))
echo '<meta name="ROBOTS" content="NOINDEX, FOLLOW" />'."\n";
?>
<title><?php echo generate_page_title($page_title, $p) ?></title>
<?php
if (file_exists(FORUM_ROOT.'style/'.$luna_user['style'].'/style.css'))
$style = $luna_user['style'];
else
$style = $luna_config['o_default_style'];
?>
<link rel="stylesheet" type="text/css" href="style/<?php echo $style ?>/style.css" />
<?php
if (isset($required_fields))
{
// Output JavaScript to validate form (make sure required fields are filled out)
?>
<script type="text/javascript">
/* <![CDATA[ */
function process_form(the_form)
{
var required_fields = {
<?php
// Output a JavaScript object with localised field names
$tpl_temp = count($required_fields);
foreach ($required_fields as $elem_orig => $elem_trans)
{
echo "\t\t\"".$elem_orig.'": "'.addslashes(str_replace(' ', ' ', $elem_trans));
if (--$tpl_temp) echo "\",\n";
else echo "\"\n\t};\n";
}
?>
if (document.all || document.getElementById)
{
for (var i = 0; i < the_form.length; ++i)
{
var elem = the_form.elements[i];
if (elem.name && required_fields[elem.name] && !elem.value && elem.type && (/^(?:text(?:area)?|password|file)$/i.test(elem.type)))
{
alert('"' + required_fields[elem.name] + '" <?php echo $lang['required field'] ?>');
elem.focus();
return false;
}
}
}
return true;
}
/* ]]> */
</script>
<?php
}
if (isset($page_head))
echo implode("\n", $page_head)."\n";
$tpl_temp = trim(ob_get_contents());
$tpl_main = str_replace('<luna_head>', $tpl_temp, $tpl_main);
ob_end_clean();
// END SUBST - <luna_head>
// START SUBST - <body>
if (isset($focus_element))
{
$tpl_main = str_replace('<body onload="', '<body onload="document.getElementById(\''.$focus_element[0].'\').elements[\''.$focus_element[1].'\'].focus();', $tpl_main);
$tpl_main = str_replace('<body>', '<body onload="document.getElementById(\''.$focus_element[0].'\').elements[\''.$focus_element[1].'\'].focus()">', $tpl_main);
}
// END SUBST - <body>
if (!defined ('FORUM_FORM')) {
// START SUBST - <luna_page>
$tpl_main = str_replace('<luna_page>', htmlspecialchars(basename($_SERVER['PHP_SELF'], '.php')), $tpl_main);
// END SUBST - <luna_page>
// START SUBST - <luna_title>
if (($luna_config['o_header_title'] == 1) && ($luna_config['o_menu_title'] == 1)) {
$tpl_main = str_replace('<luna_title>', '<h1 class="hidden-xs"><a href="index.php">'.luna_htmlspecialchars($luna_config['o_board_title']).'</a></h1>', $tpl_main);
} elseif (($luna_config['o_header_title'] == 1) && ($luna_config['o_menu_title'] == 0)) {
$tpl_main = str_replace('<luna_title>', '<h1><a href="index.php">'.luna_htmlspecialchars($luna_config['o_board_title']).'</a></h1>', $tpl_main);
} else {
$tpl_main = str_replace('<luna_title>', '', $tpl_main);
}
// END SUBST - <luna_title>
// START SUBST - <luna_desc>
if ($luna_config['o_header_desc'] == 1) {
$tpl_main = str_replace('<luna_desc>', '<div id="brddesc"><p>'.$luna_config['o_board_desc'].'</p></div>', $tpl_main);
} else {
$tpl_main = str_replace('<luna_desc>', '', $tpl_main);
}
// END SUBST - <luna_desc>
// START SUBST - <luna_navlinks>
$links = array();
// Index should always be displayed
if ($luna_config['o_show_index'] == '1')
$links[] = '<li id="navindex"'.((FORUM_ACTIVE_PAGE == 'index') ? ' class="active"' : '').'><a href="index.php">'.$lang['Index'].'</a></li>';
if ($luna_user['g_read_board'] == '1' && $luna_user['g_view_users'] == '1' && $luna_config['o_show_userlist'] == '1')
$links[] = '<li id="navuserlist"'.((FORUM_ACTIVE_PAGE == 'userlist') ? ' class="active"' : '').'><a href="userlist.php">'.$lang['User list'].'</a></li>';
if ($luna_config['o_rules'] == '1' && (!$luna_user['is_guest'] || $luna_user['g_read_board'] == '1' || $luna_config['o_regs_allow'] == '1') && $luna_config['o_show_rules'] == '1')
$links[] = '<li id="navrules"'.((FORUM_ACTIVE_PAGE == 'rules') ? ' class="active"' : '').'><a href="misc.php?action=rules">'.$lang['Rules'].'</a></li>';
if ($luna_user['g_read_board'] == '1' && $luna_user['g_search'] == '1' && $luna_config['o_show_search'] == '1')
$links[] = '<li id="navsearch"'.((FORUM_ACTIVE_PAGE == 'search') ? ' class="active"' : '').'><a href="search.php">'.$lang['Search'].'</a></li>';
if ($luna_user['is_admmod'])
$links[] = '<li id="navadmin"'.((FORUM_ACTIVE_PAGE == 'admin') ? ' class="active"' : '').'><a href="backstage/index.php">'.$lang['Backstage'].'</a></li>';
// Are there any additional navlinks we should insert into the array before imploding it?
if ($luna_user['g_read_board'] == '1' && $luna_config['o_additional_navlinks'] != '')
{
if (preg_match_all('%([0-9]+)\s*=\s*(.*?)\n%s', $luna_config['o_additional_navlinks']."\n", $extra_links))
{
// Insert any additional links into the $links array (at the correct index)
$num_links = count($extra_links[1]);
for ($i = 0; $i < $num_links; ++$i)
array_splice($links, $extra_links[1][$i], 0, array('<li id="navextra'.($i + 1).'">'.$extra_links[2][$i].'</li>'));
}
}
// Generate avatar
$user_avatar = generate_avatar_markup($luna_user['id']);
// The user menu
if ($luna_user['is_guest'])
{
$usermenu[] = '<li id="navregister"'.((FORUM_ACTIVE_PAGE == 'register') ? ' class="active"' : '').'><a href="register.php">'.$lang['Register'].'</a></li>';
$usermenu[] = '<li id="navlogin"'.((FORUM_ACTIVE_PAGE == 'login') ? ' class="active"' : '').'><a href="login.php">'.$lang['Login'].'</a></li>';
} else {
$usermenu[] = '<li class="dropdown">';
$usermenu[] = '<a href="#" class="dropdown-toggle avatar-item" data-toggle="dropdown">'.$user_avatar.' '.(luna_htmlspecialchars($luna_user['username'])).' <b class="caret"></b></a>';
$usermenu[] = '<ul class="dropdown-menu">';
$usermenu[] = '<li><a href="profile.php?id='.$luna_user['id'].'">'.$lang['Profile'].'</a></li>';
$usermenu[] = '<li><a href="help.php">'.$lang['Help'].'</a></li>';
$usermenu[] = '<li class="divider"></li>';
$usermenu[] = '<li><a href="login.php?action=out&id='.$luna_user['id'].'&csrf_token='.luna_hash($luna_user['id'].luna_hash(get_remote_address())).'">'.$lang['Logout'].'</a></li>';
$usermenu[] = '</ul>';
$usermenu[] = '</li>';
}
if ($luna_config['o_menu_title'] == 1) {
$menu_title = '<a href="index.php" class="navbar-brand">'.luna_htmlspecialchars($luna_config['o_board_title']).'</a>';
} else {
$menu_title = '';
}
$tpl_temp = '<div class="navbar navbar-default navbar-static-top">
<div class="nav-inner">
'.$menu_title.'
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">'."\n\t\t\t\t\t\t".implode("\n\t\t\t\t", $links)."\n\t\t\t\t\t\t".'</ul>
<ul class="nav navbar-nav navbar-right">
'."\n\t\t\t\t\t\t".implode("\n\t\t\t\t", $usermenu)."\n\t\t\t\t\t\t".'
</ul>
</div>
</div>
</div>';
$tpl_main = str_replace('<luna_navlinks>', $tpl_temp, $tpl_main);
// END SUBST - <luna_navlinks>
// START SUBST - <luna_status>
$page_statusinfo = $page_topicsearches = array();
if (!$luna_user['is_guest'])
{
if (!empty($forum_actions))
{
$page_statusinfo[] = '<li><span>'.implode(' · ', $forum_actions).'</span></li>';
}
if (!empty($topic_actions))
{
$page_statusinfo[] = '<li><span>'.implode(' · ', $topic_actions).'</span></li>';
}
if ($luna_user['is_admmod'])
{
if ($luna_config['o_report_method'] == '0' || $luna_config['o_report_method'] == '2')
{
$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());
if ($db->result($result_header))
$page_statusinfo[] = '<li class="reportlink"><span><strong><a href="backstage/reports.php">'.$lang['New reports'].'</a></strong></span></li>';
}
if ($luna_config['o_maintenance'] == '1')
$page_statusinfo[] = '<li class="maintenancelink"><span><strong><a href="backstage/settings.php#maintenance">'.$lang['Maintenance mode enabled'].'</a></strong></span></li>';
}
if ($luna_user['g_read_board'] == '1' && $luna_user['g_search'] == '1')
{
$page_topicsearches[] = '<a href="search.php?action=show_new" title="'.$lang['Show new posts'].'">'.$lang['New posts header'].'</a>';
}
}
// Quick searches
if ($luna_user['g_read_board'] == '1' && $luna_user['g_search'] == '1')
{
$page_topicsearches[] = '<a href="search.php?action=show_recent" title="'.$lang['Show active topics'].'">'.$lang['Active topics'].'</a>';
$page_topicsearches[] = '<a href="search.php?action=show_unanswered" title="'.$lang['Show unanswered topics'].'">'.$lang['Unanswered topics'].'</a>';
}
// Generate all that jazz
$tpl_temp = '<div id="brdwelcome">';
// The status information
if (is_array($page_statusinfo))
{
$tpl_temp .= "\n\t\t\t".'<ul class="conl">';
$tpl_temp .= "\n\t\t\t\t".implode("\n\t\t\t\t", $page_statusinfo);
$tpl_temp .= "\n\t\t\t".'</ul>';
}
else
$tpl_temp .= "\n\t\t\t".$page_statusinfo;
// Generate quicklinks
if (!empty($page_topicsearches))
{
$tpl_temp .= "\n\t\t\t".'<ul class="conr">';
$tpl_temp .= "\n\t\t\t\t".'<li><span>'.implode(' · ', $page_topicsearches).'</span></li>';
$tpl_temp .= "\n\t\t\t".'</ul>';
}
$tpl_temp .= "\n\t\t\t".'<div class="clearer"></div>'."\n\t\t".'</div>';
$tpl_main = str_replace('<luna_status>', $tpl_temp, $tpl_main);
// END SUBST - <luna_status>
// START SUBST - <luna_announcement>
if ($luna_user['g_read_board'] == '1' && $luna_config['o_announcement'] == '1')
{
ob_start();
?>
<div class="alert alert-info announcement">
<div><?php echo $luna_config['o_announcement_message'] ?></div>
</div>
<?php
$tpl_temp = trim(ob_get_contents());
$tpl_main = str_replace('<luna_announcement>', $tpl_temp, $tpl_main);
ob_end_clean();
}
else
$tpl_main = str_replace('<luna_announcement>', '', $tpl_main);
// END SUBST - <luna_announcement>
}
// START SUBST - <luna_main>
ob_start();
define('FORUM_HEADER', 1);