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 by daylin */ |
80
|
|
|
function timeToSeekEquation($time) { |
|
|
|
|
81
|
|
|
$times = preg_split('/:/', $time); |
82
|
|
|
$timesc = count($times); |
83
|
|
|
$final = ''; |
84
|
|
|
if ($times[0] != 0) { |
85
|
|
|
for ($i = 0; $i < $timesc; $i++) { |
86
|
|
|
$remaining = $timesc - $i - 1; |
87
|
|
|
if ($i < $timesc - 1) { |
88
|
|
|
$final.=$times[$i].'*'.(60 ** $remaining).'+'; |
89
|
|
|
} else { |
90
|
|
|
$final.=$times[$i]; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} else { |
94
|
|
|
$final = $times[1]; |
95
|
|
|
} |
96
|
|
|
return $final; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
function shorten_description(string $description, int $limit, bool $newlines = false) { |
|
|
|
|
100
|
|
|
$description = trim($description); |
101
|
|
|
if(strlen($description) >= $limit) { |
102
|
|
|
$description = substr($description, 0, $limit) . "..."; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$description = htmlspecialchars($description); |
106
|
|
|
if($newlines) { $description = str_replace(PHP_EOL, "<br>", $description); } |
107
|
|
|
$description = preg_replace("/@([a-zA-Z0-9-]+|\\+\\])/", "<a href='/user/$1'>@$1</a>", $description); |
108
|
|
|
$description = preg_replace("/((\d{1,2}:)+\d{2})/", "<a onclick=\"yt.www.watch.player.seekTo('$1', false)\">$1</a>", $description); |
109
|
|
|
return $description; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
function get_video_responses($id) { |
|
|
|
|
113
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM video_response WHERE toid = :id"); |
114
|
|
|
$stmt->bindParam(":id", $id); |
115
|
|
|
$stmt->execute(); |
116
|
|
|
|
117
|
|
|
return $stmt->rowCount(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
function get_video_likes($reciever, $liked) { |
|
|
|
|
121
|
|
|
if($liked) { |
122
|
|
|
$stmt = $this->__db->prepare("SELECT `sender` FROM likes WHERE reciever = :reciever AND type = 'l'"); |
123
|
|
|
$stmt->bindParam(":reciever", $reciever); |
124
|
|
|
$stmt->execute(); |
125
|
|
|
|
126
|
|
|
return $stmt->rowCount(); |
127
|
|
|
} else { |
128
|
|
|
$stmt = $this->__db->prepare("SELECT `sender` FROM likes WHERE reciever = :reciever AND type = 'd'"); |
129
|
|
|
$stmt->bindParam(":reciever", $reciever); |
130
|
|
|
$stmt->execute(); |
131
|
|
|
|
132
|
|
|
return $stmt->rowCount(); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
function check_view($vidid, $user) { |
|
|
|
|
137
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM views WHERE viewer = :viewer AND videoid = :rid"); |
138
|
|
|
$stmt->bindParam(":viewer", $user); |
139
|
|
|
$stmt->bindParam(":rid", $vidid); |
140
|
|
|
$stmt->execute(); |
141
|
|
|
if($stmt->rowCount() === 0) { |
142
|
|
|
$this->add_view($vidid, $user); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
function add_view($vidid, $user) { |
|
|
|
|
147
|
|
|
$stmt = $this->__db->prepare("INSERT INTO views (viewer, videoid) VALUES (:user, :vidid)"); |
148
|
|
|
$stmt->bindParam(":user", $user); |
149
|
|
|
$stmt->bindParam(":vidid", $vidid); |
150
|
|
|
$stmt->execute(); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
function get_comment_likes($reciever, $liked) { |
|
|
|
|
154
|
|
|
if($liked) { |
155
|
|
|
$stmt = $this->__db->prepare("SELECT `sender` FROM comment_likes WHERE reciever = :reciever AND type = 'l'"); |
156
|
|
|
$stmt->bindParam(":reciever", $reciever); |
157
|
|
|
$stmt->execute(); |
158
|
|
|
|
159
|
|
|
return $stmt->rowCount(); |
160
|
|
|
} else { |
161
|
|
|
$stmt = $this->__db->prepare("SELECT `sender` FROM comment_likes WHERE reciever = :reciever AND type = 'd'"); |
162
|
|
|
$stmt->bindParam(":reciever", $reciever); |
163
|
|
|
$stmt->execute(); |
164
|
|
|
|
165
|
|
|
return $stmt->rowCount(); |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
function if_liked($user, $reciever, $liked) { |
|
|
|
|
170
|
|
|
if($liked) { |
171
|
|
|
$stmt = $this->__db->prepare("SELECT `sender` FROM likes WHERE sender = :sender AND reciever = :reciever AND type = 'l'"); |
172
|
|
|
$stmt->bindParam(":sender", $user); |
173
|
|
|
$stmt->bindParam(":reciever", $reciever); |
174
|
|
|
$stmt->execute(); |
175
|
|
|
|
176
|
|
|
return $stmt->rowCount() === 1; |
177
|
|
|
} else { |
178
|
|
|
$stmt = $this->__db->prepare("SELECT `sender` FROM likes WHERE sender = :sender AND reciever = :reciever AND type = 'd'"); |
179
|
|
|
$stmt->bindParam(":sender", $user); |
180
|
|
|
$stmt->bindParam(":reciever", $reciever); |
181
|
|
|
$stmt->execute(); |
182
|
|
|
|
183
|
|
|
return $stmt->rowCount() === 1; |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
function if_comment_liked($user, $reciever, $liked) { |
|
|
|
|
188
|
|
|
if($liked) { |
189
|
|
|
$stmt = $this->__db->prepare("SELECT `sender` FROM comment_likes WHERE sender = :sender AND reciever = :reciever AND type = 'l'"); |
190
|
|
|
$stmt->bindParam(":sender", $user); |
191
|
|
|
$stmt->bindParam(":reciever", $reciever); |
192
|
|
|
$stmt->execute(); |
193
|
|
|
|
194
|
|
|
return $stmt->rowCount() === 1; |
195
|
|
|
} else { |
196
|
|
|
$stmt = $this->__db->prepare("SELECT `sender` FROM comment_likes WHERE sender = :sender AND reciever = :reciever AND type = 'd'"); |
197
|
|
|
$stmt->bindParam(":sender", $user); |
198
|
|
|
$stmt->bindParam(":reciever", $reciever); |
199
|
|
|
$stmt->execute(); |
200
|
|
|
|
201
|
|
|
return $stmt->rowCount() === 1; |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
function fetch_video_rid(string $rid) { |
|
|
|
|
206
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM videos WHERE rid = :rid"); |
207
|
|
|
$stmt->bindParam(":rid", $rid); |
208
|
|
|
$stmt->execute(); |
209
|
|
|
|
210
|
|
|
return ($stmt->rowCount() === 0 ? 0 : $stmt->fetch(PDO::FETCH_ASSOC)); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
function fetch_playlist_rid(string $rid) { |
|
|
|
|
214
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM playlists WHERE rid = :rid"); |
215
|
|
|
$stmt->bindParam(":rid", $rid); |
216
|
|
|
$stmt->execute(); |
217
|
|
|
|
218
|
|
|
return ($stmt->rowCount() === 0 ? 0 : $stmt->fetch(PDO::FETCH_ASSOC)); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
function fetch_comment_id(string $id) { |
|
|
|
|
222
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM comments WHERE id = :id"); |
223
|
|
|
$stmt->bindParam(":id", $id); |
224
|
|
|
$stmt->execute(); |
225
|
|
|
|
226
|
|
|
return ($stmt->rowCount() === 0 ? 0 : $stmt->fetch(PDO::FETCH_ASSOC)); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
function get_video_stars_level($id, $level) { |
|
|
|
|
230
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM stars WHERE reciever = :id AND type = :lvl"); |
231
|
|
|
$stmt->bindParam(":id", $id); |
232
|
|
|
$stmt->bindParam(":lvl", $level, PDO::PARAM_INT); |
233
|
|
|
$stmt->execute(); |
234
|
|
|
|
235
|
|
|
return $stmt->rowCount(); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
function video_exists($video) { |
|
|
|
|
239
|
|
|
$stmt = $this->__db->prepare("SELECT rid FROM videos WHERE rid = :rid"); |
240
|
|
|
$stmt->bindParam(":rid", $video); |
241
|
|
|
$stmt->execute(); |
242
|
|
|
|
243
|
|
|
return $stmt->rowCount() === 1; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
function if_favorited($user, $reciever) { |
|
|
|
|
247
|
|
|
$stmt = $this->__db->prepare("SELECT `reciever` FROM favorite_video WHERE sender = :user AND reciever = :reciever"); |
248
|
|
|
$stmt->bindParam(":user", $user); |
249
|
|
|
$stmt->bindParam(":reciever", $reciever); |
250
|
|
|
$stmt->execute(); |
251
|
|
|
|
252
|
|
|
return $stmt->rowCount() === 1; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
function fetch_user_videos($v) { |
|
|
|
|
256
|
|
|
$stmt = $this->__db->prepare("SELECT rid FROM videos WHERE author = :v"); |
257
|
|
|
$stmt->bindParam(":v", $v); |
258
|
|
|
$stmt->execute(); |
259
|
|
|
|
260
|
|
|
return $stmt->rowCount(); |
261
|
|
|
} |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
|
265
|
|
|
/* SHITTY FIX INCOMING FOR EMBEDS - MOVE SO IT'S IN EVERY PAGE WHEN POSSIBLE AND NOT LAZY */ |
266
|
|
|
$__server->page_embeds->page_title = "SubRocks - " . $__server->page_title; |
267
|
|
|
$__server->page_embeds->page_description = "Welcome to a Youtube recreation dedicated to replecating 2012's YouTube layout."; |
268
|
|
|
$__server->page_embeds->page_url = "https://subrock.rocks/"; |
269
|
|
|
?> |
|
|
|
|
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.