-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathload.php
67 lines (56 loc) · 2.26 KB
/
load.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
<?php
declare(strict_types=1);
use Firebase\JWT\JWT;
include_once 'settings.php';
$shouts = $repoShouts->query()
->orderBy('createdAt DESC')
->limit(isset($_GET['history']) ? $m_h : $m_s, isset($_GET['history']) ? $m_s : 0)
->execute();
$results = [];
$config = ['language' => '\RelativeTime\Languages\L' . $l_g, 'truncate' => 1];
$relativeTime = new \RelativeTime\RelativeTime($config);
foreach ($shouts as $shout) {
$timeAgo = $relativeTime->timeAgo($shout->createdAt);
$timeAgoValue = empty($timeAgo) ? date('H:i', $shout->createdAt) : $timeAgo;
$results[] = [
'id' => mb_substr($shout->getId(), 0, 4),
'loggedIn' => $shout->loggedIn,
'text' => $shout->text,
'name' => $shout->name,
'timeAgo' => $timeAgoValue,
'timeStamp' => date('d.m.Y H:i', $shout->createdAt),
];
}
header('Content-type: application/json; charset=utf-8');
try {
$token = JWT::decode($authHeader, $secretKey, ['HS512']);
if ($token->iss !== $serverName ||
$token->nbf > $now->getTimestamp() ||
$token->exp < $now->getTimestamp()) {
header('HTTP/1.1 401 Unauthorized');
exit;
}
$bannedProfile = $repoProfiles->query()
->where('username', '==', strtolower($token->data->userName))
->execute();
foreach($bannedProfile as $profile) {
$b = $profile->banned;
$u = $profile->username;
}
$is_not_valid_user = !$b && $u;
$is_valid_moderator = $token->data->moderator && $is_not_valid_user;
$is_valid_logged_in = $token->data->loggedIn && $is_not_valid_user;
if ($is_valid_moderator || $is_valid_logged_in) {
echo json_encode($results, JSON_UNESCAPED_UNICODE);
} else {
include 'data/languages/' . $l_g . '/app_lang.extra.' . $l_g . '.php';
echo '[{"id":"denied","text":"' . $lang['APP_ACCESS_DENIED_BANNED'] . '","name":"ChatX","timeAgo":""}]';
}
} catch (Exception $e) {
if ($r_a === '1') {
include 'data/languages/' . $l_g . '/app_lang.extra.' . $l_g . '.php';
echo '[{"id":"denied","text":"' . $lang['APP_ACCESS_DENIED'] . '","name":"ChatX","timeAgo":""}]';
} else {
echo json_encode($results, JSON_UNESCAPED_UNICODE);
}
}