-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
executable file
·157 lines (149 loc) · 4.84 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
<?php
// header("Content-type: text/plain");
// session_start();
// print_r($_SESSION["user"]);
// exit();
/**
* Load all definitions
*/
require_once("common/include/funcs/defines.php");
/**
* Import Service definitions
*/
require_once(CLASSES_DIR . "Frontend.php");
$frontend = new frontend_api();
$frontend->get_definitions("api", false, "obj");
$frontend->get_definitions("tags", false, "obj");
$frontend->get_definitions("types", false, "obj");
require_once(FUNCS_DIR . "nl2.php");
require_once(FUNCS_DIR . "readmore.php");
require_once(FUNCS_DIR . "has_permissions.php");
require_once(LIB_DIR . "php-markdown-extra-extended/markdown.php");
require_once(FUNCS_DIR . "optimize_markdown.php");
require_once(CLASSES_DIR . "Parse_json.php");
if(session_status() == PHP_SESSION_NONE) {
session_start();
}
if(isset($_COOKIE["l"]) && trim($_COOKIE["l"]) !== "") {
/**
* Load session data
*/
if(isset($_SESSION["user"])) {
$user = json_decode(json_encode($_SESSION["user"]), 1);
}
/**
* Assign a random image if there's no assigned
*/
if(!isset($user[kTAG_ENTITY_ICON])) {
$user_images = array_diff(scandir(ADMIN_IMAGES_DIR . "user_rand_images"), array("..", "."));
$img_c = 0;
foreach($user_images as $img_file) {
$img_c++;
}
$rand_img = rand(0, ($img_c - 1)) . ".jpg";
$_SESSION["user"][kTAG_ENTITY_ICON] = array(kAPI_PARAM_RESPONSE_FRMT_DISP => $rand_img);
$user[kTAG_ENTITY_ICON] = array(kAPI_PARAM_RESPONSE_FRMT_DISP => $rand_img);
}
if(!isset($user[kTAG_ENTITY_PGP_FINGERPRINT])) {
$user = array();
$logged = false;
session_destroy();
setcookie("l", "", time()-3600);
unset($_COOKIE["l"]);
} else {
$logged = (md5($user[kTAG_ENTITY_PGP_FINGERPRINT][kAPI_PARAM_RESPONSE_FRMT_DISP]) == $_COOKIE["l"]) ? true : false;
}
}
if(!defined("LOGGED")) {
define("LOGGED", $logged);
}
$global_menu = new Parse_json(CONF_DIR . "menu.json");
if(LOGGED) {
$admin_menu = new Parse_json(CONF_DIR . "menu_admin.php");
// print_r($admin_menu);
// exit();
}
$map_config = new Parse_json(CONF_DIR . "map.json");
$pages_config = new Parse_json(CONF_DIR . "pages.json");
$i18n_config = new Parse_json(INTERFACE_CONF_DIR . "i18n.js");
$interface_config = new Parse_json(INTERFACE_CONF_DIR . "site.js");
$i18n = $i18n_config->parse_js_config("i18n");
$interface = $interface_config->parse_js_config("config");
$page = $pages_config->parse_page_config("pages");
if(isset($_COOKIE["lang"]) && trim($_COOKIE["lang"]) !== "") {
$lang = $_COOKIE["lang"];
} else {
$lang = $interface["site"]["default_language"];
}
// Uncommet if you have a dashboard page
if($page->current == "Home") {
$page->is_backend = true;
}
if(!isset($page->class)) {
$page->class = array();
}
if(isset($user)) {
$page->has_permissions = has_permissions($user, $page);
} else {
$page->has_permissions = false;
}
?>
<!DOCTYPE html>
<html lang="en"<?php print (strtolower($page->current) == "map") ? ' class="map"' : ""; ?>>
<head>
<?php include(TEMPLATE_DIR . "head.tpl"); ?>
</head>
<body <?php print ((count($page->class) > 0 || LOGGED) ? 'class="' . ((LOGGED) ? "fixed-header fixed-page-footer " : "") . ((!$interface["site"]["allow_signin"] || $page->need_login && !$page->has_permissions) ? "e405" : ((isset($page->class)) ? implode($page->class, " ") : "")) . '"' : "") . ' data-error="' . (($page->has_error) ? "true" : "false") . '"'; ?>>
<?php
switch(strtolower($page->current)) {
case "signin":
if($interface["site"]["allow_signin"]) {
include(TEMPLATE_PAGES_DIR . "Signin.tpl");
include(TEMPLATE_DIR . "script.tpl");
include(TEMPLATE_DIR . "loader.tpl");
} else {
include(TEMPLATE_PAGES_DIR . "405_nologin.tpl");
include(TEMPLATE_DIR . "loader.tpl");
include(TEMPLATE_DIR . "script.tpl");
}
break;
case "signout":
include(TEMPLATE_DIR . "script.tpl");
include(TEMPLATE_PAGES_DIR . "Signout.tpl");
include(TEMPLATE_DIR . "loader.tpl");
break;
case "activation":
include(TEMPLATE_DIR . "script.tpl");
include(TEMPLATE_PAGES_DIR . "Activation.tpl");
include(TEMPLATE_DIR . "loader.tpl");
break;
default:
if(!$page->exists) {
include(TEMPLATE_PAGES_DIR . "404.tpl");
} else {
if($page->need_login && !LOGGED) {
include(TEMPLATE_PAGES_DIR . "405.tpl");
include(TEMPLATE_DIR . "loader.tpl");
include(TEMPLATE_DIR . "script.tpl");
} else {
include(TEMPLATE_DIR . "loader.tpl");
if(LOGGED && $page->current == "Home" || LOGGED && $page->need_login) {
if($page->has_permissions) {
include(ADMIN_TEMPLATE_DIR . "index.tpl");
} else {
include(TEMPLATE_PAGES_DIR . "405_nologin.tpl");
}
} else {
?>
<?php include(TEMPLATE_DIR . "body_header.tpl"); ?>
<?php include(INCLUDE_DIR . "get_contents.php"); ?>
<?php include(TEMPLATE_DIR . "script.tpl"); ?>
<?php
}
}
}
break;
}
?>
</body>
</html>