forked from vladislav805/APIdog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzero.userarea.php
More file actions
240 lines (204 loc) · 6.28 KB
/
zero.userarea.php
File metadata and controls
240 lines (204 loc) · 6.28 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
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
<?
/**
* Работа с пользовательской частью
*/
/**
* Возвращает токен из кук
* @return String access_token
*/
function getAccessToken() {
return defined("userAccessToken") ? userAccessToken : null;
};
/**
* Возвращает ключ авторизации от APIdog
* @return String authKey
*/
function getAuthKey() {
return defined("userAuthKey") ? userAuthKey : null;
};
/**
* Возвращает сессию по авторизационному ключу сайта
* @param String $authKey Авторизационный ключ
* @return APIdogSession Сессия
*/
function getSessionByAuthKey ($authKey) {
$authKey = escape($authKey);
$result = SQLquery("SELECT `auth_id` AS `authId`, `user_id` AS `userId`, `date` FROM `auth` WHERE `hash` = '" . $authKey . "' ", SQL_RESULT_ITEM);
return $result ? new APIdogSession($result) : false;
};
/**
* Логаут
*/
function gotoLogout () {
header("Location: auth.php?act=logout&ts=" . time());
exit;
};
/**
* Сессия
*/
class APIdogSession {
public $authId;
public $userId;
public $date;
public function __construct ($result) {
$this->authId = (int) $result["authId"];
$this->userId = (int) $result["userId"];
$this->date = (int) $result["date"];
}
public function getSettings () {
return APIdogSettings::getById($this->userId);
}
/**
* Получение пользователя по authKey
* @param string $authKey authKey
* @return [type] [description]
*/
static function getByAuthKey($authKey = "") {
if (!$authKey) {
return false;
};
$user = SQLquery("SELECT * FROM `auth` WHERE `hash`='" . escape($authKey) . "' LIMIT 1", SQL_RESULT_ITEM);
return !$user ? false : new APIdogSession($user);
}
};
/**
* Авторизационная сессия
*/
class AuthSession {
public $authId;
public $authKey;
private $userId;
public $date;
public $appId;
public function __construct($q) {
$this->authId = (int) $q["auth_id"];
$this->authKey = $q["hash"];
$this->userId = $q["user_id"];
$this->date = (int) $q["date"];
$this->appId = (int) $q["appId"];
}
public function getUserId() {
return $this->userId;
}
/**
* Завершить сессию
* @return boolean true, если успешно
*/
public function kill() {
return (boolean) SQLquery("DELETE FROM `auth` WHERE `auth_id` = '" . $this->authId . "' LIMIT 1", SQL_RESULT_AFFECTED);
}
};
/**
* Настройки
*/
class APIdogSettings {
public $bitmask;
public $languageId;
public $themeId;
public $sharedData;
public function __construct ($d) {
$this->bitmask = (int) $d["bitmask"];
$this->languageId = (int) $d["lang"];
$this->themeId = (int) $d["themeId"];
$this->sharedData = json_decode($d["sharedData"]);
}
/**
* Получить настройки по userId ВКонтакте
* @param int $userId Идентификатор пользователя ВК
* @return APIdogSettings Результат
*/
static function getById ($userId) {
return new APIdogSettings(SQLquery("SELECT * FROM `settings` WHERE `userId` = '" . $userId . "' LIMIT 1", SQL_RESULT_ITEM));
}
/**
* Имеется ли установленная тема у пользователя?
* @return boolean true, если имеется
*/
public function hasTheme () {
return $this->themeId > 0;
}
/**
* Получить установленную тему по этому экземпляру настроек
* @return APIdogTheme Объект темы
*/
public function getTheme () {
return APIdogTheme::getById($this->themeId);
}
};
/**
* Класс пользователя
*/
class User {
public $userId;
public $firstName;
public $lastName;
public $photo50;
public $online;
public function __construct ($u) {
$this->userId = (int) ($u["id"] ? $u["id"] : $u["uid"]);
$this->firstName = $u["first_name"];
$this->lastName = $u["last_name"];
$this->photo50 = $u["photo_50"] ? $u["photo_50"] : $u["photo_rec"];
$this->online = (boolean) $u["online"];
}
/**
* Ассоциирование ключа authKey с userId
* @deprecated
* @param string $authKey Авторизационный ключ сайта
* @param int $authId Идентификатор авторизации
* @param int $userId Идентификатор пользователя
* @return array Данные
*/
static function associateAuthKey($authKey, $authId, $userId) { }
};
/**
* Тема для сайта
*/
class APIdogTheme {
public $themeId;
public $authorId;
public $file;
public $title;
public $updated;
public $fileJS;
/**
* Возвращает тему по её id
* @param int $themeId Идентификатор темы
* @return APIdogTheme Объект темы
*/
static function getById ($themeId) {
return new APIdogTheme(SQLquery("SELECT * FROM `themes` WHERE `themeId` = '" . $themeId . "' LIMIT 1", SQL_RESULT_ITEM));
}
public function __construct ($theme) {
$this->themeId = (int) $theme["themeId"];
$this->authorId = (int) $theme["authorId"];
$this->file = $theme["file"];
$this->title = $theme["title"];
$this->updated = (int) $theme["updated"];
$this->fileJS = $theme["filejs"];
}
/**
* Получает, записывает и возвращает код темы
* @return String Код темы
*/
public function open () {
$content = file_get_contents("../styles/" . $this->file);
$this->content = $content;
return $this;
}
/**
* Получает и возвращает код js темы
* @return String Код
*/
public function openJS () {
$content = file_get_contents("../scripts/" . $this->fileJS);
return $content;
}
/**
* Возвращает код темы
* @return String Код
*/
public function getContent () {
return $this->content ? $this->content : $this->open()->content;
}
};