forked from vladislav805/APIdog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzero.framework.php
More file actions
109 lines (85 loc) · 2.77 KB
/
zero.framework.php
File metadata and controls
109 lines (85 loc) · 2.77 KB
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
<?
/**
* APIdog.ru v6.5
* Copyright (c) 2012-2016
*
* Vladislav Veluga (c) 2009-2016
* 16 august 2016
*/
include_once "zero.config.php";
include_once "zero.helper.php";
include_once "zero.userarea.php";
include_once "zero.pageutilites.php";
include_once "zero.language.php";
include_once "zero.authorize.php";
include_once "zero.db.php";
if (isset($_REQUEST["act"]) ?? false) {
header("X-Frame-Options: SAMEORIGIN");
};
if (!defined("_install")) {
exit("not configured. please, configure zero-module before using site");
};
session_start();
//error_reporting(E_ERROR | E_PARSE);
date_default_timezone_set("Europe/Minsk"); // GMT+3
header("Content-Type: text/html; charset=UTF-8");
define("KEY_ACCESS_TOKEN", "userAccessToken");
define("KEY_AUTH_KEY", "authKey");
function initDefines() {
global $ssAdmins;
$authKey = escape(isset($_COOKIE[KEY_AUTH_KEY]) ? $_COOKIE[KEY_AUTH_KEY] : "");
$session = getSessionByAuthKey($authKey);
if (!$authKey || !$session) {
$userAccessToken = "";
$authKey = "";
$userId = 0;
$isAdmin = false;
} else {
$userAccessToken = escape($_COOKIE[KEY_ACCESS_TOKEN]);
$userId = $session->userId;
$isAdmin = isset($ssAdmins[$session->userId]);
};
define("userAccessToken", $userAccessToken);
define("userAuthKey", $authKey);
define("userId", $userId);
define("isAdminCurrentUser", $isAdmin);
};
if (!function_exists("escape")) {
/**
* Функция для "обезопашивания" строк для записи в БД
* @param String $string Строка, которую нужно экранировать
* @return String Результат, безопасная строка
*/
function escape($string) {
return getDatabase()->escape_string($string);
};
};
/**
* Включил ли пользователь себе доступ к новой версии?
* @return boolean
*/
function isNewVersionEnabled() {
return SQLquery("SELECT `v5` FROM `settings` WHERE `userId` = '" . userId . "' LIMIT 1", SQL_RESULT_ITEM)["v5"];
};
/**
* Выкинуть ошибку и остановить выполнение
* @param int $errorId Идентификатор ошибки
* @param mixed $extra Дополнительные данные, если нужны
*/
function throwError($errorId, $extra = false) {
include_once "zero.errors.php";
$data = [
"errorId" => $errorId,
"message" => getErrorTextById($errorId),
"params" => $_REQUEST
];
if ($extra) {
$data["extra"] = [];
foreach ($extra as $key => $value) {
$data["extra"][$key] = $value;
};
};
output($data);
};
session_write_close();
initDefines();