1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @Auther: bhief |
5
|
|
|
* @Version: 1.0 |
6
|
|
|
* @Added Base |
7
|
|
|
* |
8
|
|
|
* Use this class for getting user information |
9
|
|
|
* |
10
|
|
|
**/ |
11
|
|
|
class user_helper { |
12
|
|
|
public $__db; |
13
|
|
|
|
14
|
|
|
public function __construct($conn){ |
15
|
|
|
$this->__db = $conn; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
function fetch_pfp($username) { |
|
|
|
|
19
|
|
|
$stmt = $this->__db->prepare("SELECT pfp FROM users WHERE username = :username"); |
20
|
|
|
$stmt->bindParam(":username", $username); |
21
|
|
|
$stmt->execute(); |
22
|
|
|
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { |
23
|
|
|
$pfp = $row['pfp']; |
24
|
|
|
} // why the while statement? just remove it (i cant be bothered to) |
25
|
|
|
|
26
|
|
|
return (isset($pfp) ? $pfp : "default.png"); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
function fetch_unread_pms($user) { |
|
|
|
|
31
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM pms WHERE touser = :user AND readed = 'y'"); |
32
|
|
|
$stmt->bindParam(":user", $user); |
33
|
|
|
$stmt->execute(); |
34
|
|
|
|
35
|
|
|
return $stmt->rowCount(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function if_blocked($user, $reciever) { |
|
|
|
|
39
|
|
|
$stmt = $this->__db->prepare("SELECT reciever FROM block WHERE sender = :user AND reciever = :reciever"); |
40
|
|
|
$stmt->bindParam(":user", $user); |
41
|
|
|
$stmt->bindParam(":reciever", $reciever); |
42
|
|
|
$stmt->execute(); |
43
|
|
|
|
44
|
|
|
return $stmt->rowCount() === 1; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
function if_admin($user) { |
|
|
|
|
48
|
|
|
$stmt = $this->__db->prepare("SELECT status FROM users WHERE username = :user AND status = 'admin'"); |
49
|
|
|
$stmt->bindParam(":user", $user);; |
50
|
|
|
$stmt->execute(); |
51
|
|
|
|
52
|
|
|
return $stmt->rowCount() === 1; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
function if_partner($user) { |
|
|
|
|
56
|
|
|
$stmt = $this->__db->prepare("SELECT partner FROM users WHERE username = :user AND partner = 'y'"); |
57
|
|
|
$stmt->bindParam(":user", $user);; |
58
|
|
|
$stmt->execute(); |
59
|
|
|
|
60
|
|
|
return $stmt->rowCount() === 1; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
function if_cooldown($user) { |
|
|
|
|
64
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM users WHERE username = :username AND cooldown_comment >= NOW() - INTERVAL 1 MINUTE"); |
65
|
|
|
$stmt->bindParam(":username", $user); |
66
|
|
|
$stmt->execute(); |
67
|
|
|
|
68
|
|
|
return $stmt->rowCount() === 1; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
function if_upload_cooldown($user) { |
|
|
|
|
72
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM users WHERE username = :username AND upload_cooldown >= NOW() - INTERVAL 10 MINUTE"); |
73
|
|
|
$stmt->bindParam(":username", $user); |
74
|
|
|
$stmt->execute(); |
75
|
|
|
|
76
|
|
|
return $stmt->rowCount() === 1; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
function fetch_user_username($username) { |
|
|
|
|
80
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM users WHERE username = :username"); |
81
|
|
|
$stmt->bindParam(":username", $username); |
82
|
|
|
$stmt->execute(); |
83
|
|
|
|
84
|
|
|
return ($stmt->rowCount() === 0 ? 0 : $stmt->fetch(PDO::FETCH_ASSOC)); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
function user_exists($user) { |
|
|
|
|
88
|
|
|
$stmt = $this->__db->prepare("SELECT username FROM users WHERE username = :username"); |
89
|
|
|
$stmt->bindParam(":username", $user); |
90
|
|
|
$stmt->execute(); |
91
|
|
|
|
92
|
|
|
return $stmt->rowCount() === 1; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
function if_subscribed($user, $reciever) { |
|
|
|
|
96
|
|
|
$stmt = $this->__db->prepare("SELECT reciever FROM subscribers WHERE sender = :sender AND reciever = :reciever"); |
97
|
|
|
$stmt->bindParam(":sender", $user); |
98
|
|
|
$stmt->bindParam(":reciever", $reciever); |
99
|
|
|
$stmt->execute(); |
100
|
|
|
|
101
|
|
|
return $stmt->rowCount() === 1; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
function fetch_subs_count($username) { |
|
|
|
|
105
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM subscribers WHERE reciever = :username"); |
106
|
|
|
$stmt->bindParam(":username", $username); |
107
|
|
|
$stmt->execute(); |
108
|
|
|
|
109
|
|
|
return $stmt->rowCount(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
function fetch_user_videos(string $id) { |
|
|
|
|
113
|
|
|
$stmt = $this->__db->prepare("SELECT rid FROM videos WHERE author = :id"); |
114
|
|
|
$stmt->bindParam(":id", $id); |
115
|
|
|
$stmt->execute(); |
116
|
|
|
|
117
|
|
|
return $stmt->rowCount(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
function fetch_user_favorites(string $username) { |
|
|
|
|
121
|
|
|
$stmt = $this->__db->prepare("SELECT reciever FROM favorite_video WHERE sender = :username"); |
122
|
|
|
$stmt->bindParam(":username", $username); |
123
|
|
|
$stmt->execute(); |
124
|
|
|
|
125
|
|
|
return $stmt->rowCount(); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
function fetch_subscriptions($username) { |
|
|
|
|
129
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM subscribers WHERE sender = :username"); |
130
|
|
|
$stmt->bindParam(":username", $username); |
131
|
|
|
$stmt->execute(); |
132
|
|
|
|
133
|
|
|
return $stmt->rowCount(); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
function get_channel_views(string $rid) { |
|
|
|
|
137
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM channel_views WHERE channel = :rid"); |
138
|
|
|
$stmt->bindParam(":rid", $rid); |
139
|
|
|
$stmt->execute(); |
140
|
|
|
|
141
|
|
|
return $stmt->rowCount(); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
function fetch_friends_accepted($username) { |
|
|
|
|
145
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM friends WHERE reciever = :username AND status = 'a'"); |
146
|
|
|
$stmt->bindParam(":username", $username); |
147
|
|
|
$stmt->execute(); |
148
|
|
|
|
149
|
|
|
$friends = $stmt->rowCount(); |
150
|
|
|
|
151
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM friends WHERE sender = :username AND status = 'a'"); |
152
|
|
|
$stmt->bindParam(":username", $username); |
153
|
|
|
$stmt->execute(); |
154
|
|
|
|
155
|
|
|
return $friends + $stmt->rowCount(); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
?> |
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.