|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @Auther: bhief |
|
5
|
|
|
* @Version: 1.0 |
|
6
|
|
|
* |
|
7
|
|
|
* Gets info from videos |
|
8
|
|
|
* |
|
9
|
|
|
**/ |
|
10
|
|
|
class video_helper { |
|
11
|
|
|
public $__db; |
|
12
|
|
|
|
|
13
|
|
|
public function sh_exec(string $cmd, string $outputfile = "", string $pidfile = "", bool $mergestderror = true, bool $bg = false) { |
|
14
|
|
|
$fullcmd = $cmd; |
|
15
|
|
|
if(strlen($outputfile) > 0) $fullcmd .= " >> " . $outputfile; |
|
16
|
|
|
if($mergestderror) $fullcmd .= " 2>&1"; |
|
17
|
|
|
|
|
18
|
|
|
if($bg) { |
|
19
|
|
|
$fullcmd = "nohup " . $fullcmd . " &"; |
|
20
|
|
|
if(strlen($pidfile)) $fullcmd .= " echo $! > " . $pidfile; |
|
21
|
|
|
} else { |
|
22
|
|
|
if(strlen($pidfile) > 0) $fullcmd .= "; echo $$ > " . $pidfile; |
|
23
|
|
|
} |
|
24
|
|
|
shell_exec($fullcmd); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
function file_get_contents_chunked($file, $chunk_size, $callback) { |
|
|
|
|
|
|
28
|
|
|
try { |
|
29
|
|
|
$handle = fopen($file, "r"); |
|
30
|
|
|
$i = 0; |
|
31
|
|
|
while (!feof($handle)) { |
|
32
|
|
|
call_user_func_array($callback,array(fread($handle,$chunk_size),&$handle,$i)); |
|
33
|
|
|
$i++; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
fclose($handle); |
|
37
|
|
|
} |
|
38
|
|
|
catch(Exception $e) { |
|
39
|
|
|
trigger_error("file_get_contents_chunked::" . $e->getMessage(),E_USER_NOTICE); |
|
40
|
|
|
return false; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
return true; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function __construct($conn){ |
|
47
|
|
|
$this->__db = $conn; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
function fetch_video_views(string $id) { |
|
|
|
|
|
|
51
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM views WHERE videoid = :id"); |
|
52
|
|
|
$stmt->bindParam(":id", $id); |
|
53
|
|
|
$stmt->execute(); |
|
54
|
|
|
|
|
55
|
|
|
return $stmt->rowCount(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
function fetch_views_from_user($user) { |
|
|
|
|
|
|
59
|
|
|
$stmt = $this->__db->prepare("SELECT `rid` FROM videos WHERE author = :username"); |
|
60
|
|
|
$stmt->bindParam(":username", $user); |
|
61
|
|
|
$stmt->execute(); |
|
62
|
|
|
|
|
63
|
|
|
$views = 0; |
|
64
|
|
|
while($video = $stmt->fetch(PDO::FETCH_ASSOC)) { |
|
65
|
|
|
$views = $views + $this->fetch_video_views($video['rid']); |
|
66
|
|
|
} |
|
67
|
|
|
return $views; |
|
68
|
|
|
$stmt->close(); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
function get_comments_from_video($id) { |
|
|
|
|
|
|
72
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM comments WHERE toid = :id"); |
|
73
|
|
|
$stmt->bindParam(":id", $id); |
|
74
|
|
|
$stmt->execute(); |
|
75
|
|
|
|
|
76
|
|
|
return $stmt->rowCount(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
function shorten_description(string $description, int $limit, bool $newlines = false) { |
|
|
|
|
|
|
80
|
|
|
$description = trim($description); |
|
81
|
|
|
if(strlen($description) >= $limit) { |
|
82
|
|
|
$description = substr($description, 0, $limit) . "..."; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$description = htmlspecialchars($description); |
|
86
|
|
|
if($newlines) { $description = str_replace(PHP_EOL, "<br>", $description); } |
|
87
|
|
|
return $description; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
function get_video_responses($id) { |
|
|
|
|
|
|
91
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM video_response WHERE toid = :id"); |
|
92
|
|
|
$stmt->bindParam(":id", $id); |
|
93
|
|
|
$stmt->execute(); |
|
94
|
|
|
|
|
95
|
|
|
return $stmt->rowCount(); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
function get_video_likes($reciever, $liked) { |
|
|
|
|
|
|
99
|
|
|
if($liked) { |
|
100
|
|
|
$stmt = $this->__db->prepare("SELECT `sender` FROM likes WHERE reciever = :reciever AND type = 'l'"); |
|
101
|
|
|
$stmt->bindParam(":reciever", $reciever); |
|
102
|
|
|
$stmt->execute(); |
|
103
|
|
|
|
|
104
|
|
|
return $stmt->rowCount(); |
|
105
|
|
|
} else { |
|
106
|
|
|
$stmt = $this->__db->prepare("SELECT `sender` FROM likes WHERE reciever = :reciever AND type = 'd'"); |
|
107
|
|
|
$stmt->bindParam(":reciever", $reciever); |
|
108
|
|
|
$stmt->execute(); |
|
109
|
|
|
|
|
110
|
|
|
return $stmt->rowCount(); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
function if_liked($user, $reciever, $liked) { |
|
|
|
|
|
|
115
|
|
|
if($liked) { |
|
116
|
|
|
$stmt = $this->__db->prepare("SELECT `sender` FROM likes WHERE sender = :sender AND reciever = :reciever AND type = 'l'"); |
|
117
|
|
|
$stmt->bindParam(":sender", $user); |
|
118
|
|
|
$stmt->bindParam(":reciever", $reciever); |
|
119
|
|
|
$stmt->execute(); |
|
120
|
|
|
|
|
121
|
|
|
return $stmt->rowCount() === 1; |
|
122
|
|
|
} else { |
|
123
|
|
|
$stmt = $this->__db->prepare("SELECT `sender` FROM likes WHERE sender = :sender AND reciever = :reciever AND type = 'd'"); |
|
124
|
|
|
$stmt->bindParam(":sender", $user); |
|
125
|
|
|
$stmt->bindParam(":reciever", $reciever); |
|
126
|
|
|
$stmt->execute(); |
|
127
|
|
|
|
|
128
|
|
|
return $stmt->rowCount() === 1; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
function fetch_video_rid(string $rid) { |
|
|
|
|
|
|
133
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM videos WHERE rid = :rid"); |
|
134
|
|
|
$stmt->bindParam(":rid", $rid); |
|
135
|
|
|
$stmt->execute(); |
|
136
|
|
|
|
|
137
|
|
|
return ($stmt->rowCount() === 0 ? 0 : $stmt->fetch(PDO::FETCH_ASSOC)); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
function fetch_playlist_rid(string $rid) { |
|
|
|
|
|
|
141
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM playlists WHERE rid = :rid"); |
|
142
|
|
|
$stmt->bindParam(":rid", $rid); |
|
143
|
|
|
$stmt->execute(); |
|
144
|
|
|
|
|
145
|
|
|
return ($stmt->rowCount() === 0 ? 0 : $stmt->fetch(PDO::FETCH_ASSOC)); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
function fetch_comment_id(string $id) { |
|
|
|
|
|
|
149
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM comments WHERE id = :id"); |
|
150
|
|
|
$stmt->bindParam(":id", $id); |
|
151
|
|
|
$stmt->execute(); |
|
152
|
|
|
|
|
153
|
|
|
return ($stmt->rowCount() === 0 ? 0 : $stmt->fetch(PDO::FETCH_ASSOC)); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
function get_video_stars_level($id, $level) { |
|
|
|
|
|
|
157
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM stars WHERE reciever = :id AND type = :lvl"); |
|
158
|
|
|
$stmt->bindParam(":id", $id); |
|
159
|
|
|
$stmt->bindParam(":lvl", $level, PDO::PARAM_INT); |
|
160
|
|
|
$stmt->execute(); |
|
161
|
|
|
|
|
162
|
|
|
return $stmt->rowCount(); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
function video_exists($video) { |
|
|
|
|
|
|
166
|
|
|
$stmt = $this->__db->prepare("SELECT rid FROM videos WHERE rid = :rid"); |
|
167
|
|
|
$stmt->bindParam(":rid", $video); |
|
168
|
|
|
$stmt->execute(); |
|
169
|
|
|
|
|
170
|
|
|
return $stmt->rowCount() === 1; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
function if_favorited($user, $reciever) { |
|
|
|
|
|
|
174
|
|
|
$stmt = $this->__db->prepare("SELECT `reciever` FROM favorite_video WHERE sender = :user AND reciever = :reciever"); |
|
175
|
|
|
$stmt->bindParam(":user", $user); |
|
176
|
|
|
$stmt->bindParam(":reciever", $reciever); |
|
177
|
|
|
$stmt->execute(); |
|
178
|
|
|
|
|
179
|
|
|
return $stmt->rowCount() === 1; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
function fetch_user_videos($v) { |
|
|
|
|
|
|
183
|
|
|
$stmt = $this->__db->prepare("SELECT rid FROM videos WHERE author = :v"); |
|
184
|
|
|
$stmt->bindParam(":v", $v); |
|
185
|
|
|
$stmt->execute(); |
|
186
|
|
|
|
|
187
|
|
|
return $stmt->rowCount(); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
?> |
|
|
|
|
|
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.