-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.php
executable file
·124 lines (98 loc) · 4.01 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
<?php
define('DEBUG', FALSE);
// If the config file does not exist assume the installer has not yet been executed and thus show a link to the install page.
if (!file_exists("./config.json")) {
include 'errors/NewInstall.html';
die();
}
// Before allow the page to be rendered, check if the install page is still there. This is because the install script can change configs and be a sever security flaw when still there.
if (!DEBUG) {
if (file_exists("./install")) {
die("Please remove /install after installation");
}
}
// Turn off error reporting to prevent security leaks
if (DEBUG) {
error_reporting(-1);
ini_set("display_errors", 'On');
}
else {
error_reporting(0);
ini_set("display_errors", 0);
}
// Make reference of the root path of BlueStats. This is used in other parts of the webapp to get theme files and others.
$appPath = __DIR__;
/* Classes */
require_once "$appPath/classes/config.class.php";
require_once "$appPath/classes/cache.class.php";
// Load config file. This file stores the BlueStats mysql settings.
// It is used to establish the connection the to config database.
$config = json_decode(file_get_contents("config.json"), TRUE);
$mysqli = new mysqli(
$config["mysql"]["host"],
$config["mysql"]["username"],
$config["mysql"]["password"],
$config["mysql"]["dbname"]
);
if (!DEBUG && $mysqli->connect_error) {
include 'errors/MysqlError.html';
die();
}
$cache = new cache($mysqli, $appPath);
// Replace remove ?recache from url
$uri = $_SERVER["REQUEST_URI"];
$uri = str_replace("?recache&", "?", $uri);
$uri = str_replace("&recache", "", $uri);
$uri = str_replace("?recache", "", $uri);
if ($cache->reCache($uri)) {
/* Include all classes and api if a new cache has to be created */
require_once "$appPath/classes/bluestats.class.php";
require_once "$appPath/classes/module.class.php";
require_once "$appPath/classes/view.class.php";
require_once "$appPath/classes/player.class.php";
require_once "$appPath/classes/url.class.php";
require_once "$appPath/classes/chart.class.php";
require_once "$appPath/classes/plugin/plugin.php";
require_once "$appPath/classes/table.class.php";
require_once "$appPath/classes/formatter.php";
/* Functions */
require_once "$appPath/functions/utils.func.php";
require_once "$appPath/functions/blocks.func.php";
// Start the BlueStats core
$BlueStats = new BlueStats($mysqli, $appPath);
$plugins = [];
/* Load all plugins */
foreach ($BlueStats->getPluginList() as $plugin) {
/* Load in core plugin class*/
/** @noinspection PhpIncludeInspection */
include "$appPath/plugins/$plugin/$plugin.php";
$pluginClass = "\\BlueStats\\Plugin\\$plugin";
$plugins[$plugin] = new $pluginClass($mysqli);
}
$BlueStats->loadPlugins($plugins);
$content = $BlueStats->loadPage();
// Add the copyright statements
// I don't trust theme creators to include my copyright after all :)
// Because I (The Author) do like attribution for what I make.
$credits = '
<!--
Copyright Zeyphros (robinp7720) 2015
BlueStats 3 is released under the Apache 2 license.
Removal of this copyright notice is an infringement of the license.
Developed by Zeyphros (robinp7720)
-->
';
$copyrightMeta = '<meta name="dcterms.rightsHolder" content="Zeyphros (robinp7720)"><meta name="dcterms.rights" content="Released under Apache 2.0 license"><meta name="dcterms.dateCopyrighted" content="2015"><meta name="dc.license" content="Apache 2.0"><meta name="web_author" content="Zeyphros (robinp7720)">';
// Add the copyright stuff to the head tag
$content = str_replace("<head>", "<head>" . $copyrightMeta, $content);
// Compress html
$content = trim(preg_replace('/\s\s+/', ' ', $content));
$content = str_replace("\lf", '', $content);
// Add credits into head
$content = str_replace("<head>", "<head>" . $credits, $content);
echo $content;
$cache->cache($content, $uri);
}
else {
echo $cache->getCache($uri);
}