This repository was archived by the owner on Apr 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathplaylist-controller.php
More file actions
164 lines (136 loc) · 6.51 KB
/
playlist-controller.php
File metadata and controls
164 lines (136 loc) · 6.51 KB
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
<?php
if (file_exists(dirname(dirname(dirname(dirname(__FILE__)))) . "/wp-config.php")) {
require_once dirname(dirname(dirname(dirname(__FILE__)))) . "/wp-config.php";
} else {
require_once dirname(dirname(dirname(dirname(dirname(__FILE__))))) . "/wp-config.php";
}
if (!class_exists("PlaylistController")) {
class PlaylistController {
var $entries;
var $tablePrefix;
// default constructor
function PlaylistController() {
global $table_prefix;
$this->entries = array(array());
// unfortunately stupid WP doesn't carry these details :S
$connection = mysql_pconnect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME, $connection);
$this->tablePrefix = $table_prefix;
}
// add to playlist
function addToPlaylist($id, $entry) {
$this->entries[$id][] = $entry;
}
// return selected playlist as xml
function generatePlaylist($id = '') {
$playlist = $this->entries[$id];
if (is_array($playlist)) {
$xml = new DOMDocument("1.0", "utf-8");
$playlistElement = $xml->createElement("playlist");
$versionAttribute = $xml->createAttribute("version");
$versionAttribute->appendChild($xml->createTextNode("1"));
$nsAttribute = $xml->createAttribute("xmlns");
$nsAttribute->appendChild($xml->createTextNode("http://xspf.org/ns/0/"));
$playlistElement->appendChild($versionAttribute);
$playlistElement->appendChild($nsAttribute);
$xml->appendChild($playlistElement);
$trackListElement = $xml->createElement("trackList");
$playlistElement->appendChild($trackListElement);
foreach ($playlist as $trackEntry) {
$trackElement = $xml->createElement("track");
$locationElement = $xml->createElement("location");
$locationElement->appendChild($xml->createTextNode(urldecode($trackEntry->getUrl())));
$trackElement->appendChild($locationElement);
$typeElement = $xml->createElement("meta");
$typeAttribute = $xml->createAttribute("rel");
$typeAttribute->appendChild($xml->createTextNode("type"));
$typeElement->appendChild($typeAttribute);
$typeElement->appendChild($xml->createTextNode($trackEntry->getType()));
$trackElement->appendChild($typeElement);
$previewImage = $trackEntry->getImage();
if (!empty($previewImage)) {
$imageElement = $xml->createElement("image");
$imageElement->appendChild($xml->createTextNode($previewImage));
$trackElement->appendChild($imageElement);
}
$title = $trackEntry->getTitle();
if (!empty($title)) {
$trackTitleElement = $xml->createElement("title");
$trackTitleElement->appendChild($xml->createTextNode($title));
$trackElement->appendChild($trackTitleElement);
}
$trackListElement->appendChild($trackElement);
}
return $xml->saveXML();
}
return '';
}
function savePlaylist($id = '') {
$playlist = $this->generatePlaylist($id);
// delete the old entry
mysql_query("DELETE FROM ".$this->tablePrefix."proplayer_playlist WHERE (POST_ID='$id')");
// save updated entry
mysql_query("INSERT INTO ".$this->tablePrefix."proplayer_playlist
VALUES (
'',
'$id',
'".addslashes($playlist)."'
)
");
}
function getPlaylist($id = '') {
$query = mysql_query("SELECT * FROM ".$this->tablePrefix."proplayer_playlist WHERE (POST_ID='$id')");
$playlistRow = mysql_fetch_row($query);
return $this->withBackwardCompatibility($playlistRow[2]);
}
function withBackwardCompatibility($xml = '') {
$xml = str_ireplace(">3g2<", ">video<", $xml);
$xml = str_ireplace(">3gp<", ">video<", $xml);
$xml = str_ireplace(">aac<", ">video<", $xml);
$xml = str_ireplace(">f4b<", ">video<", $xml);
$xml = str_ireplace(">f4p<", ">video<", $xml);
$xml = str_ireplace(">f4v<", ">video<", $xml);
$xml = str_ireplace(">flv<", ">video<", $xml);
$xml = str_ireplace(">m4a<", ">video<", $xml);
$xml = str_ireplace(">m4v<", ">video<", $xml);
$xml = str_ireplace(">sdp<", ">video<", $xml);
$xml = str_ireplace(">vp6<", ">video<", $xml);
$xml = str_ireplace(">mov<", ">video<", $xml);
$xml = str_ireplace(">mp4<", ">video<", $xml);
$xml = str_ireplace(">mp3<", ">sound<", $xml);
$xml = str_ireplace(">rbs<", ">sound<", $xml);
$xml = str_ireplace(">png<", ">image<", $xml);
$xml = str_ireplace(">gif<", ">image<", $xml);
$xml = str_ireplace(">jpg<", ">image<", $xml);
$xml = str_ireplace(">jpeg<", ">image<", $xml);
$xml = str_ireplace(">swf<", ">image<", $xml);
return $xml;
}
}
}
$playlistController = new PlaylistController();
if (!empty($_GET["pp_playlist_id"])) {
header("Content-type: application/xml");
$xml = $playlistController->getPlaylist(mysql_real_escape_string($_GET["pp_playlist_id"]));
if (!empty($xml)) {
print $xml;
} else {
// video is not accessible
$wwwDirInfo = parse_url(!empty($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : $_SERVER["SCRIPT_NAME"]);
$errorImage = str_replace("playlist-controller.php", "not-accessible.png", $wwwDirInfo["path"]);
print trim("
<?xml version='1.0' encoding='utf-8'?>
<playlist xmlns='http://xspf.org/ns/0/' version='1'>
<trackList>
<track>
<location>$errorImage</location>
<meta rel='type'>image</meta>
<image>$errorImage</image>
</track>
</trackList>
</playlist>
");
}
die;
}
?>