forked from WWBN/AVideo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaylist.php
executable file
·178 lines (157 loc) · 5.33 KB
/
playlist.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
global $global, $config;
if(!isset($global['systemRootPath'])){
require_once '../videos/configuration.php';
}
require_once $global['systemRootPath'] . 'objects/user.php';
class PlayList extends ObjectYPT {
protected $id, $name, $users_id, $status;
static function getSearchFieldsNames() {
return array('pl.name');
}
static function getTableName() {
return 'playlists';
}
/**
*
* @global type $global
* @param type $publicOnly
* @param type $userId if not present check session
* @param type $isVideoIdPresent pass the ID of the video checking
* @return boolean
*/
static function getAllFromUser($userId, $publicOnly = true) {
global $global;
$formats = "";
$values = array();
$sql = "SELECT u.*, pl.* FROM " . static::getTableName() . " pl "
. " LEFT JOIN users u ON u.id = users_id WHERE 1=1 ";
if ($publicOnly) {
$sql .= " AND pl.status = 'public' ";
}
if (!empty($userId)) {
$sql .= " AND users_id = ? ";
$formats .= "i";
$values[] = $userId;
}
$sql .= self::getSqlFromPost("pl.");
$res = sqlDAL::readSql($sql,$formats,$values);
$fullData = sqlDAL::fetchAllAssoc($res);
sqlDAL::close($res);
$rows = array();
if ($res!=false) {
foreach ($fullData as $row) {
$row['videos'] = static::getVideosFromPlaylist($row['id']);
$rows[] = $row;
}
} else {
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
}
return $rows;
}
static function getVideosFromPlaylist($playlists_id) {
global $global;
$sql = "SELECT *,v.created as cre, p.`order` as video_order FROM playlists_has_videos p "
. " LEFT JOIN videos as v ON videos_id = v.id "
. " LEFT JOIN users u ON u.id = v.users_id "
. " WHERE playlists_id = ? ORDER BY p.`order` ASC ";
$sql .= self::getSqlFromPost();
$res = sqlDAL::readSql($sql,"i",array($playlists_id));
$fullData = sqlDAL::fetchAllAssoc($res);
sqlDAL::close($res);
$rows = array();
if ($res!=false) {
foreach ($fullData as $row) {
if(!empty($_GET['isChannel'])){
$row['tags'] = Video::getTags($row['id']);
$row['pluginBtns'] = YouPHPTubePlugin::getPlayListButtons($playlists_id);
$row['humancreate'] = humanTiming(strtotime($row['cre']));
}
$rows[] = $row;
}
} else {
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
}
return $rows;
}
static function getVideosIdFromPlaylist($playlists_id) {
$videosId = array();
$rows = static::getVideosFromPlaylist($playlists_id);
foreach ($rows as $value) {
$videosId[] = $value['videos_id'];
}
return $videosId;
}
static function sortVideos($videosList, $listIdOrder){
$list = array();
foreach ($listIdOrder as $value) {
foreach ($videosList as $key => $value2) {
if($value2['id']==$value){
$list[] = $value2;
unset($videosList[$key]);
}
}
}
return $list;
}
public function save() {
if (!User::isLogged()) {
return false;
}
$users_id = User::getId();
$this->setUsers_id($users_id);
return parent::save();
}
public function addVideo($video_id, $add, $order=0) {
global $global;
$formats = "";
$values = array();
if(empty($add) || $add === "false"){
$sql = "DELETE FROM playlists_has_videos WHERE playlists_id = ? AND videos_id = ? ";
$formats = "ii";
$values[] = $this->id;
$values[] = $video_id;
}else{
$this->addVideo($video_id, false);
$sql = "INSERT INTO playlists_has_videos ( playlists_id, videos_id , `order`) VALUES (?, ?, ?) ";
$formats = "iii";
$values[] = $this->id;
$values[] = $video_id;
$values[] = $order;
}
return sqlDAL::writeSql($sql,$formats,$values);
}
public function delete() {
if(empty($this->id)){
return false;
}
global $global;
$sql = "DELETE FROM playlists WHERE id = ? ";
//echo $sql;
return sqlDAL::writeSql($sql,"i",array($this->id));
}
function getId() {
return $this->id;
}
function getName() {
return $this->name;
}
function getUsers_id() {
return $this->users_id;
}
function getStatus() {
return $this->status;
}
function setId($id) {
$this->id = $id;
}
function setName($name) {
$this->name = xss_esc($name);;
}
function setUsers_id($users_id) {
$this->users_id = $users_id;
}
function setStatus($status) {
$this->status = $status;
}
}