|
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
|
|
|
public function __construct($conn){ |
|
28
|
|
|
$this->__db = $conn; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
function fetch_video_views(string $id) { |
|
|
|
|
|
|
32
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM views WHERE videoid = ?"); |
|
33
|
|
|
$stmt->bind_param("s", $id); |
|
34
|
|
|
$stmt->execute(); |
|
35
|
|
|
$result = $stmt->get_result(); |
|
36
|
|
|
return $result->num_rows; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
function get_comments_from_video($id) { |
|
|
|
|
|
|
40
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM comments WHERE toid = ?"); |
|
41
|
|
|
$stmt->bind_param("s", $id); |
|
42
|
|
|
$stmt->execute(); |
|
43
|
|
|
$result = $stmt->get_result(); |
|
44
|
|
|
$rows = mysqli_num_rows($result); |
|
45
|
|
|
$stmt->close(); |
|
46
|
|
|
|
|
47
|
|
|
return $rows; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
function shorten_description(string $description, int $limit, bool $newlines = false) { |
|
|
|
|
|
|
51
|
|
|
$description = trim($description); |
|
52
|
|
|
if(strlen($description) >= $limit) { |
|
53
|
|
|
$description = substr($description, 0, $limit) . "..."; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$description = htmlspecialchars($description); |
|
57
|
|
|
if($newlines) { $description = str_replace(PHP_EOL, "<br>", $description); } |
|
58
|
|
|
return $description; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
function get_video_responses($id) { |
|
|
|
|
|
|
62
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM video_response WHERE toid = ?"); |
|
63
|
|
|
$stmt->bind_param("s", $id); |
|
64
|
|
|
$stmt->execute(); |
|
65
|
|
|
$result = $stmt->get_result(); |
|
66
|
|
|
$rows = mysqli_num_rows($result); |
|
67
|
|
|
$stmt->close(); |
|
68
|
|
|
|
|
69
|
|
|
return $rows; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
function fetch_video_rid(string $rid) { |
|
|
|
|
|
|
73
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM videos WHERE rid = ?"); |
|
74
|
|
|
$stmt->bind_param("s", $rid); |
|
75
|
|
|
$stmt->execute(); |
|
76
|
|
|
$result = $stmt->get_result(); |
|
77
|
|
|
$video = $result->fetch_assoc(); |
|
78
|
|
|
|
|
79
|
|
|
if($result->num_rows === 0) |
|
80
|
|
|
return 0; |
|
81
|
|
|
else |
|
82
|
|
|
return $video; |
|
83
|
|
|
|
|
84
|
|
|
$stmt->close(); |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
function get_video_stars_level($id, $level) { |
|
|
|
|
|
|
88
|
|
|
$stmt = $this->__db->prepare("SELECT * FROM stars WHERE reciever = ? AND type = ?"); |
|
89
|
|
|
$stmt->bind_param("si", $id, $level); |
|
90
|
|
|
$stmt->execute(); |
|
91
|
|
|
$result = $stmt->get_result(); |
|
92
|
|
|
$rows = mysqli_num_rows($result); |
|
93
|
|
|
$stmt->close(); |
|
94
|
|
|
|
|
95
|
|
|
return $rows; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
function video_exists($video) { |
|
|
|
|
|
|
99
|
|
|
$stmt = $this->__db->prepare("SELECT `rid` FROM videos WHERE rid = ?"); |
|
100
|
|
|
$stmt->bind_param("s", $video); |
|
101
|
|
|
$stmt->execute(); |
|
102
|
|
|
$result = $stmt->get_result(); |
|
103
|
|
|
$user = $result->fetch_assoc(); |
|
|
|
|
|
|
104
|
|
|
if($result->num_rows === 1) { return true; } else { return false; } |
|
105
|
|
|
$stmt->close(); |
|
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
return $user; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
function fetch_user_videos($v) { |
|
|
|
|
|
|
111
|
|
|
$stmt = $this->__db->prepare("SELECT rid FROM videos WHERE author = ?"); |
|
112
|
|
|
$stmt->bind_param("s", $v); |
|
113
|
|
|
$stmt->execute(); |
|
114
|
|
|
$result = $stmt->get_result(); |
|
115
|
|
|
$rows = mysqli_num_rows($result); |
|
116
|
|
|
$stmt->close(); |
|
117
|
|
|
|
|
118
|
|
|
return $rows; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
?> |
|
|
|
|
|
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.