forked from antirez/lloogg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pro.php
80 lines (70 loc) · 1.9 KB
/
pro.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
<?
function isPro($id=false) {
global $__procache;
if (isset($__procache)) return $__procache !== false;
if ($id === false) {
$id=userId();
if ($id == -1) return false;
}
$r = redisLink();
$pro = $r->get("uid:$id:pro");
if (!$pro) {
$__procache = false;
return $__procache;
}
$__procache = $pro;
return true;
}
function setPro($uid,$level,$duration=3600) {
$r = redisLink();
if ($level == 0) {
$r->del("uid:$uid:pro");
$r->del("uid:$uid:pro.since");
$r->del("uid:$uid:pro.until");
$r->srem("global:prousers",$uid);
} else {
$r->set("uid:$uid:pro",$level);
$r->set("uid:$uid:pro.since",time());
$r->set("uid:$uid:pro.until",time()+$duration);
$r->sadd("global:prousers",$uid);
}
}
function getAllowing($uid=false) {
if ($uid === false) $uid = userId();
$r = redisLink();
return $r->smembers("uid:$uid:allowing");
}
function getAllowed($uid=false) {
if ($uid === false) $uid = userId();
$r = redisLink();
return $r->smembers("uid:$uid:allowed");
}
function addAllowed($allowing_id,$allowed_id) {
$r = redisLink();
$r->sadd("uid:$allowing_id:allowing",$allowed_id);
return $r->sadd("uid:$allowed_id:allowed",$allowing_id);
}
function delAllowed($allowing_id,$allowed_id) {
$r = redisLink();
$r->srem("uid:$allowing_id:allowing",$allowed_id);
return $r->srem("uid:$allowed_id:allowed",$allowing_id);
}
function reqUserId() {
global $_COOKIE;
$r = redisLink();
if (!isset($_COOKIE['requser'])) return userId();
$username = $_COOKIE['requser'];
if (($id = getIdFromUsername($username)) == -1) {
return userId();
}
if ($r->sismember("uid:$id:allowing",userId())) {
return $id;
} else {
return userId();
}
}
function getProLevel() {
global $__procache;
return $__procache;
}
?>