forked from bjdodson/jinzora
-
Notifications
You must be signed in to change notification settings - Fork 14
/
api2.php
204 lines (161 loc) · 4.86 KB
/
api2.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
define('JZ_SECURE_ACCESS','true');
/**
* - JINZORA | Web-based Media Streamer -
*
* Jinzora is a Web-based media streamer, primarily desgined to stream MP3s
* (but can be used for any media file that can stream from HTTP).
* Jinzora can be integrated into a CMS site, run as a standalone application,
* or integrated into any PHP website. It is released under the GNU GPL.
*
* - Resources -
* - Jinzora Author: Ross Carlson <ross@jasbone.com>
* - Web: http://www.jinzora.org
* - Documentation: http://www.jinzora.org/docs
* - Support: http://www.jinzora.org/forum
* - Downloads: http://www.jinzora.org/downloads
* - License: GNU GPL <http://www.gnu.org/copyleft/gpl.html>
*
* - Contributors -
* Please see http://www.jinzora.org/team.html
*
* - Code Purpose -
* - This page handles all API requests for add-on services
*
* @since 04.14.05
* @author Ross Carlson <ross@jinzora.org>
* @author Ben Dodson <ben@jinzora.org>
*/
// Let's set the error reporting level
//@error_reporting(E_ERROR);
// Let's include ALL the functions we'll need
// Now we'll need to figure out the path stuff for our includes
// This is critical for CMS modes
$include_path = ""; $link_root = ""; $cms_type = ""; $cms_mode = "false";
$backend = ""; $jz_lang_file = ""; $skin = ""; $my_frontend = "";
include_once('system.php');
include_once('settings.php');
include_once('backend/backend.php');
include_once('playlists/playlists.php');
include_once('lib/general.lib.php');
include_once('lib/jzcomp.lib.php');
include_once('services/class.php');
include_once('frontend/display.php');
$this_page = setThisPage();
// Let's create our user object for later
$jzUSER = new jzUser();
if (isset($_GET['user']) && isset($_GET['pass'])) {
$store_cookie = true;
// Are they ok?
if ($jzUSER->login($_GET['user'],$_GET['pass'],$store_cookie, false) === false) {
echo "login failed";
exit();
}
}
// Let's make sure this user has the right permissions
if ($jzUSER->getSetting("view") === false) {
echo "must log in (user=x&pass=y)";
exit();
}
// Let's create our services object
// This object lets us do things like get metadata, resize images, get lyrics, etc
$jzSERVICES = new jzServices();
$jzSERVICES->loadStandardServices();
$display = new jzDisplay();
if (isset ($_GET['page'])) {
$args = $_GET;
unset($args['page']);
$func = 'jzApi_' . $_GET['page'];
} else {
$args = array();
$func = 'jzApi_main';
}
// todo: make this a function; use Smarty
// makes API flexible for various formats (json,xml,etc.)
$res = $func($args);
header('Content-Type: application/xml');
echo "<mediaXML>\n";
foreach ($res as $e) {
echo '<node name="'.xmlentities($e['name']) .'" ';
if (isset ($e['link'])) {
echo 'browse="'.xmlentities($e['link']).'" ';
}
if (isset($e['play'])) {
echo 'play="'.xmlentities($e['play']).'" ';
}
echo "/>\n";
}
echo '</mediaXML>';
function xmlentities($string) {
return str_replace ( array ( '&', '"', "'", '<', '>', '�' ), array ( '&' , '"', ''' , '<' , '>', ''' ), $string );
}
/* Ex:
*
* Playlists
* Sleepy
* Party
* Genres
* Alternative
* Random Playlist
* 311
* Alice in Chains
* ....
* Rock
* Punk
* Soft
* Random
* New Album
* Played Album
* Random Album
* Options
* Play on Chumby
* Play on MPD Player
* Build playlist
*/
function jzApi_main($argv) {
$ret = array();
//$ret[] = E("Playlists", null, "playlists");
//$ret[] = E("Charts & Random", null, "random");
$ret[] = E("Genres", null, "nodes");
return $ret;
}
function jzApi_playlists($argv) {
}
function jzApi_random($argv) {
}
/* todo: make me better */
function jzApi_nodes($argv) {
global $display;
$ret = array();
if (isset($argv["id"])) {
$root = new jzMediaNode($argv["id"], "id");
} else {
$root = new jzMediaNode();
}
foreach ($root->getSubNodes("both") as $node) {
if ($node instanceof jzMediaNode) {
$ret[] = E($node->getName(),
($node->getLevel() > 2) ? $node->getPlayHREF() : null,
"nodes",array("id" => $node->getID()));
} else {
$ret[] = E($node->getName(),$node->getPlayHREF());
}
}
return $ret;
}
function E($display_name, $playlink, $method = null, $args = array()) {
$a = array('name'=>$display_name,'play'=>$playlink,'method'=>$method,'args'=>$args);
if ($method != null) {
$link = $_SERVER['PHP_SELF'];
if (isset($_REQUEST['user']) && isset($_REQUEST['pass'])) {
$link .= '?user='.urlencode($_REQUEST['user']).'&pass='.urlencode($_REQUEST['pass']).'&';
}
$link .= 'page=' . $method;
foreach ($args as $key=>$val) {
$link .= '&' . urlencode($key) . '=' . urlencode($val);
}
$a['link']=$link;
}
return $a;
}
?>