This repository has been archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.php
312 lines (253 loc) · 10.6 KB
/
index.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
<?php
$starttime = microtime(true);
define('BLARG', 1);
// change this to change your board's default page
define('MAIN_PAGE', 'index');
$ajaxPage = false;
if(isset($_GET['ajax']))
$ajaxPage = true;
require(__DIR__.'/lib/common.php');
$layout_crumbs = '';
$layout_actionlinks = '';
if (isset($_GET['forcelayout'])) {
setcookie('forcelayout', (int)$_GET['forcelayout'], time()+365*24*3600, URL_ROOT, "", false, true);
die(header('Location: '.$_SERVER['HTTP_REFERER']));
}
$layout_birthdays = getBirthdaysText();
$tpl->assign('logusername', htmlspecialchars($loguser['displayname'] ?: $loguser['name']));
$tpl->assign('loguser', $loguser);
$tpl->assign('loguserlink', UserLink($loguser));
$metaStuff = [
'description' => Settings::get('metaDescription'),
'tags' => Settings::get('metaTags')
];
//Use buffering to draw the page.
//Useful to have it disabled when running from the terminal.
$useBuffering = true;
//Support for running pages from the terminal.
if(isset($argv)) {
$_GET = [];
$_SERVER = [];
$_SERVER["REMOTE_ADDR"] = "0.0.0.0";
$ajaxPage = true;
$useBuffering = false;
}
//=======================
// Do the page
$match = $router->match();
ob_start();
$layout_crumbs = "";
if($useBuffering)
ob_start();
$fakeerror = false;
if ($loguser['flags'] & 0x2) {
if (rand(0,100) <= 75) {
Alert("Could not load requested page: failed to connect to the database. Try again later.", 'Error');
$fakeerror = true;
}
}
if (!$fakeerror) {
try {
// Throw the 404 page if we don't have a match already.
if ($match === false)
require_once(__DIR__.'/pages/404.php');
else {
// Set up the stuff for our page loader.
$pageName = $match['target'];
$pageParams = $match['params'];
// Check first for plugin pages.
if(array_key_exists($pageName, $pluginpages)) {
// TODO: Make this cleaner than a hack.
$plugin = $pluginpages[$pageName];
$self = $plugins[$plugin];
$addonWWXD = __DIR__.'/plugins/'.$self['dir'].'/pages/'.$pageName.'.php';
$addonABXD = __DIR__.'/plugins/'.$self['dir'].'/page_'.$pageName.'.php';
if (file_exists($addonWWXD))
require_once($addonWWXD);
elseif (file_exists($addonABXD))
require_once($addonABXD);
else
require_once(__DIR__.'/pages/404.php');
} else {
// Check now for core pages.
$page = __DIR__.'/pages/'.$pageName.'.php';
if (file_exists($page))
require_once($page);
else
require_once(__DIR__.'/pages/404.php');
}
}
} catch(KillException $e) {
// Nothing. Just ignore this exception.
}
}
if($ajaxPage) {
if($useBuffering) {
header("Content-Type: text/plain");
ob_end_flush();
}
die();
}
$layout_contents = ob_get_contents();
ob_end_clean();
//Do these things only if it's not an ajax page.
include(__DIR__."/lib/views.php");
setLastActivity();
//=======================
// Panels and footer
require(__DIR__.'/layouts/userpanel.php');
require(__DIR__.'/layouts/menus.php');
$mobileswitch = '';
if (Settings::get('defaultLayout') !== "mobile") {
if ($mobileLayout) $mobileswitch .= 'Mobile view <noscript>(Requires JS enabled for it to work.)</noscript> - ';
if (isset($_COOKIE['forcelayout']) && $_COOKIE['forcelayout']) $mobileswitch .= '<a href="?forcelayout=0" rel="nofollow">Auto view</a>';
else if ($mobileLayout) $mobileswitch .= '<a href="?forcelayout=-1" rel="nofollow">Force normal view</a>';
else $mobileswitch .= '<a href="?forcelayout=1" rel="nofollow">Force mobile view [BETA]</a>';
}
//=======================
// Notification bars
$notifications = getNotifications();
ob_start();
$bucket = "userBar"; include("./lib/pluginloader.php");
/*
if($rssBar)
{
write("
<div style=\"float: left; width: {1}px;\"> </div>
<div id=\"rss\">
{0}
</div>
", $rssBar, $rssWidth + 4);
}*/
$bucket = "topBar"; include("./lib/pluginloader.php");
$layout_bars = ob_get_contents();
ob_end_clean();
//=======================
// Misc stuff
$layout_time = formatdatenow();
$layout_onlineusers = getOnlineUsersText();
$layout_birthdays = getBirthdaysText();
$layout_views = '<span id="viewCount">'.number_format($misc['views']).'</span> '.__('views');
$layout_description = htmlspecialchars(Settings::get('metaDescription'));
$layout_boardtitle = htmlspecialchars(Settings::get('boardname'));
$layout_title = htmlspecialchars(Settings::get('boardname'));
if($title != '')
$layout_title .= ' » '.$title;
//=======================
// Board logo and theme
if (file_exists(URL_ROOT.'/themes/$theme/logo.png')) {
$logo = '<img id="theme_banner" src="themes/$theme/logo.png" alt="'.$layout_boardtitle.'" title="'.$layout_boardtitle.'">';
} else if (file_exists(URL_ROOT.'/themes/$theme/logo.jpg')) {
$logo = '<img id="theme_banner" src="themes/$theme/logo.jpg" alt="'.$layout_boardtitle.'" title="'.$layout_boardtitle.'">';
} else if (file_exists(URL_ROOT.'/themes/$theme/logo.jpeg')) {
$logo = '<img id="theme_banner" src="themes/$theme/logo.jpeg" alt="'.$layout_boardtitle.'" title="'.$layout_boardtitle.'">';
} else if (file_exists(URL_ROOT.'/themes/$theme/logo.gif')) {
$logo = '<img id="theme_banner" src="themes/$theme/logo.gif" alt="'.$layout_boardtitle.'" title="'.$layout_boardtitle.'">';
} else if (file_exists(URL_ROOT.'/img/logo.png')) {
$logo = '<img id="theme_banner" src="img/logo.png" alt="'.$layout_boardtitle.'" title="'.$layout_boardtitle.'">';
} else if (file_exists(URL_ROOT.'/img/logo.jpg')) {
$logo = '<img id="theme_banner" src="img/logo.jpg" alt="'.$layout_boardtitle.'" title="'.$layout_boardtitle.'">';
} else if (file_exists(URL_ROOT.'/img/logo.jpeg')) {
$logo = '<img id="theme_banner" src="img/logo.jpeg" alt="'.$layout_boardtitle.'" title="'.$layout_boardtitle.'">';
} else if (file_exists(URL_ROOT.'/img/logo.gif')) {
$logo = '<img id="theme_banner" src="img/logo.gif" alt="'.$layout_boardtitle.'" title="'.$layout_boardtitle.'">';
} else {
$logo = '<h1>'.$layout_boardtitle.'</h1><h3>'.$layout_description.'</h3>';
}
function checkForImage(&$image, $external, $file) {
global $dataDir, $dataUrl;
if($image) return;
if($external) {
if(file_exists($dataDir.$file))
$image = $dataUrl.$file;
} else {
if(file_exists($file))
$image = resourceLink($file);
}
}
checkForImage($favicon, true, "logos/favicon.gif");
checkForImage($favicon, true, "logos/favicon.ico");
checkForImage($favicon, false, "img/favicon.ico");
$themefile = "themes/$theme/style.css";
if(!file_exists(__DIR__.'/'.$themefile))
$themefile = "themes/$theme/style.php";
$layout_credits =
'<img src="'.resourceLink('img/poweredbywwxd.png').'" style="float: left; margin-right: 3px;">WorldWeb XD 0.0.1 · by MaorNinja322, Repflez <a href="'.pageLink('credits').'">et al</a><br>
Based off of Blargboard by StapleButter & ABXD by Dirbaio, Kawa & co.<br>';
$layout_contents = "<div id=\"page_contents\">$layout_contents</div>";
//=======================
// Print everything!
$perfdata = 'Page rendered in '.sprintf('%.03f',microtime(true)-$starttime).' seconds (with '.$queries.' SQL queries and '.sprintf('%.03f',memory_get_usage() / 1024).'K of RAM)';
?>
<!doctype html>
<html>
<head>
<title><?php print $layout_title; ?></title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=10">
<meta name="description" content="<?php print $metaStuff['description']; ?>">
<meta name="keywords" content="<?php print $metaStuff['tags']; ?>">
<?php if ($mobileLayout) { ?>
<meta name="viewport" content="user-scalable=yes, initial-scale=1.0, width=device-width">
<meta name="apple-mobile-web-app-capable" content="yes">
<script src="<?php echo resourceLink('js/mobile.js'); ?>"></script>
<?php if ($oldAndroid) { ?>
<style>
#mobile-sidebar { height: auto!important; max-height: none!important; }
#realbody { max-height: none!important; max-width: none!important; overflow: scroll!important; }
</style>
<?php }
} ?>
<base href="<?php echo getServerURLNoSlash($ishttps)?>" /><!--[if IE]></base><![endif]-->
<link rel="shortcut icon" href="<?php print $favicon;?>">
<link rel="stylesheet" href="<?php print resourceLink("css/common.css");?>">
<link rel="stylesheet" id="theme_css" href="<?php print resourceLink($themefile); ?>">
<link rel="stylesheet" href="<?php print resourceLink('css/font-awesome.min.css'); ?>">
<link rel="stylesheet" href="https://opensource.keycdn.com/fontawesome/4.6.3/font-awesome.min.css" integrity="sha384-Wrgq82RsEean5tP3NK3zWAemiNEXofJsTwTyHmNb/iL3dP/sZJ4+7sOld1uqYJtE" crossorigin="anonymous">
<link rel="stylesheet" href="<?php print resourceLink('css/w3.css'); ?>">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="<?php print resourceLink("js/jquery.js");?>"></script>
<script src="<?php print resourceLink("js/tricks.js");?>"></script>
<script src="<?php print resourceLink("js/jquery.tablednd_0_5.js");?>"></script>
<script src="<?php print resourceLink("js/jquery.scrollTo-1.4.2-min.js");?>"></script>
<script src="<?php print resourceLink("js/jscolor/jscolor.js");?>"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.2.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script>boardroot = <?php print json_encode(URL_ROOT); ?>;</script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="//twemoji.maxcdn.com/twemoji.min.js"></script>
<?php $bucket = "pageHeader"; include(__DIR__."/lib/pluginloader.php"); ?>
</head>
<body style="width:100%; font-size: <?php echo $loguser['fontsize']; ?>%;">
<form action="<?php echo htmlentities(pageLink('logout')); ?>" method="post" id="logout" style="display:none;"><input type="hidden" name="action" value="logout"></form>
<?php
if (Settings::get('maintenance'))
echo '<div style="font-size:30px; font-weight:bold; color:red; background:black; padding:5px; border:2px solid red; position:absolute; top:30px; left:30px;">MAINTENANCE MODE</div>';
RenderTemplate('default', [
'layout_contents' => $layout_contents,
'layout_crumbs' => $layout_crumbs,
'layout_actionlinks' => $layout_actionlinks,
'headerlinks' => $headerlinks,
'dropdownlinks' => $dropdownlinks,
'sidelinks' => $sidelinks,
'layout_userpanel' => $layout_userpanel,
'notifications' => $notifications,
'boardname' => Settings::get('boardname'),
'poratitle' => Settings::get('PoRATitle'),
'poratext' => parseBBCode(Settings::get('PoRAText')),
'layout_logopic' => $logo,
'layout_time' => $layout_time,
'layout_views' => $layout_views,
'layout_onlineusers' => $layout_onlineusers,
'layout_birthdays' => $layout_birthdays,
'board_credits' => $layout_credits,
'logo' => $logo,
'layout_credits' => parseBBCode(Settings::get('layout_credits')),
'mobileswitch' => $mobileswitch,
'perfdata' => $perfdata]);
?>
</body>
</html>
<?php
$bucket = "finish"; include(__DIR__.'/lib/pluginloader.php');
?>