forked from Blount/Cheky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
95 lines (81 loc) · 2.53 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
<?php
header('Content-Type: text/html; charset=utf-8');
require __DIR__."/bootstrap.php";
$module = "default";
if (isset($_GET["mod"])) {
$module = $_GET["mod"];
}
$action = "index";
if (isset($_GET["a"])) {
$action = $_GET["a"];
}
if (!$currentVersion = $config->get("general", "version")) {
if ($module != "install") {
$module = "install";
}
} elseif (isset($_GET["url"])) { // rendre compatible avec l'ancien système de flux RSS
$module = "rss";
$action = "refresh";
}
if ($module != "install") {
$storageType = $config->get("storage", "type", "files");
if ($storageType == "db") {
$userStorage = new \App\Storage\Db\User($dbConnection);
} else {
$userStorage = new \App\Storage\File\User(DOCUMENT_ROOT."/var/users.db");
}
// identification nécessaire
if ($module == "rss" && $action == "refresh") {
$auth = new Auth\Session($userStorage);
if (!$userAuthed = $auth->authenticate()) {
$auth = new Auth\Basic($userStorage);
if (!$userAuthed = $auth->authenticate()) {
header('WWW-Authenticate: Basic realm="Identification"');
header('HTTP/1.0 401 Unauthorized');
echo "Non autorisé.";
exit;
}
}
} else {
$auth = new Auth\Session($userStorage);
if (!$userAuthed = $auth->authenticate()) {
$module = "default";
$action = "login";
}
}
$upgradeStarted = version_compare($currentVersion, APPLICATION_VERSION, "<");
if ($upgradeStarted) {
if ($userAuthed && $userAuthed->isAdmin()) {
if ($module != "admin" || $action != "upgrade") {
header("LOCATION: ./?mod=admin&a=upgrade");
exit;
}
} elseif ($action != "login") {
require DOCUMENT_ROOT."/app/default/views/upgrade.phtml";
return;
}
}
}
$init = DOCUMENT_ROOT."/app/".$module."/init.php";
$script = DOCUMENT_ROOT."/app/".$module."/scripts/".$action.".php";
$view = DOCUMENT_ROOT."/app/".$module."/views/".$action.".phtml";
$layout = DOCUMENT_ROOT."/app/".$module."/views/layout.phtml";
if (is_file($init)) {
require $init;
}
if (is_file($script)) {
require $script;
}
if (!is_file($layout)) {
$layout = DOCUMENT_ROOT."/app/default/views/layout.phtml";
}
ob_start();
if (is_file($view)) {
require $view;
}
$content = ob_get_clean();
if (isset($disableLayout) && $disableLayout == true) {
echo $content;
} else {
require $layout;
}