forked from WWBN/AVideo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playlistSort.php
95 lines (84 loc) · 2.44 KB
/
playlistSort.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
<?php
header('Content-Type: application/json');
if (empty($global['systemRootPath'])) {
$global['systemRootPath'] = '../';
}
require_once $global['systemRootPath'] . 'videos/configuration.php';
require_once $global['systemRootPath'] . 'objects/user.php';
require_once $global['systemRootPath'] . 'objects/playlist.php';
if (!User::isLogged()) {
die('{"error":"'.__("Permission denied").'"}');
}
if(empty($_POST['playlist_id']) && !empty($_GET['playlist_id'])){
$_POST['playlist_id'] = intval($_GET['playlist_id']);
}
$obj = new PlayList($_POST['playlist_id']);
if(User::getId() != $obj->getUsers_id()){
die('{"error":"'.__("Permission denied").'"}');
}
$count = 1;
if(empty($_POST['list'])){
// get all videos from playlist
$videosArrayId = PlayList::getVideosIdFromPlaylist($_POST['playlist_id']);
$videos = array();
foreach ($videosArrayId as $value) {
$videos[] = Video::getVideoLight($value);
}
$sortFunc = "titleASC";
switch ($_GET['sort']) {
case 1:
$sortFunc = "titleASC";
break;
case 2:
$sortFunc = "titleDESC";
break;
case 3:
$sortFunc = "dateCmp";
break;
case 4:
$sortFunc = "dateCmpDesc";
break;
}
//var_dump($sortFunc);exit;
// sort video
uasort($videos, $sortFunc);
// transfer the id to the list
foreach ($videos as $key => $value) {
$_POST['list'][] = $value['id'];
}
}
foreach ($_POST['list'] as $key => $value) {
$result = $obj->addVideo($value, true, $count++);
}
if(!empty($_GET['sort'])){
header("Location: ". $_SERVER['HTTP_REFERER']);
//header("Location: ". User::getChannelLink($obj->getUsers_id()));
exit;
}
$o = new stdClass();
$o->status = $result;
//$o->channelName = $obj->get;
echo json_encode($o);exit;
// Comparison function
function dateCmp($videoA, $videoB) {
$a = strtotime($videoA['created']);
$b = strtotime($videoB['created']);
if ($a == $b) {
return 0;
}
return ($a > $b) ? -1 : 1;
}
function dateCmpDesc($videoA, $videoB) {
$a = strtotime($videoA['created']);
$b = strtotime($videoB['created']);
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
function titleASC($videoA, $videoB) {
return strcasecmp($videoA['title'], $videoB['title']);
}
function titleDESC($videoA, $videoB) {
return strcasecmp($videoB['title'], $videoA['title']);
}