2 require_once __DIR__ . '/../src/header.php';
4 if (strtolower($fullUri) == '/setupapp/radio567/asp/browsexpa/loginxml.asp?token=0'
5 || $fullUri == '/RadioNativeLogin.php'
7 //initial login for "internet radio", podcasts and "my noxon"
8 header('Content-type: text/html');
9 readfile($dataDir . 'login-camelcase.xml');
11 } else if ($path == '/setupapp/radio567/asp/BrowseXPA/LoginXML.asp') {
13 $path = '/internetradio/';
14 } else if ($path == '/setupapp/radio567/asp/BrowseXPA/navXML.asp') {
17 } else if ($path == '/RadioNative.php') {
20 } else if ($path == '/setupapp/radio567/asp/BrowseXML/FavXML.asp') {
21 //Internet Radio Station favorites favorited on device
22 sendMessage('Unsupported');
23 } else if ($path == '/RadioNativeFavorites.php') {
24 //Favorites, defined via web interface
25 sendMessage('Unsupported');
28 handleRequest(ltrim($path, '/'));
30 function handleRequest($path)
33 if (strpos($path, '/../') !== false) {
38 if (substr($path, 0, 14) == 'internetradio/') {
39 require_once 'mediatomb.php';
40 handleMediatomb('browse', $path, 'internetradio/');
42 } else if (substr($path, 0, 11) == '.mt-single/') {
43 require_once 'mediatomb.php';
44 handleMediatomb('single', $path, '.mt-single/');
49 $fullPath = $varDir . $path;
50 if (!file_exists($fullPath)) {
51 sendMessage('Not found: ' . $path);
55 $ext = pathinfo($path, PATHINFO_EXTENSION);
56 if (is_dir($fullPath)) {
58 } else if ($ext == 'url') {
59 require_once 'podcasts.php';
61 } else if ($ext == 'txt') {
63 } else if (is_executable($fullPath)) {
66 sendMessage('Unknown file type');
70 function pathEncode($urlPath)
72 return str_replace('%2F', '/', rawurlencode($urlPath));
75 function sendDir($path)
82 $entries = glob(str_replace('//', '/', $varDir . rtrim($path, '/') . '/*'));
85 foreach ($entries as $entry) {
86 $urlPath = pathEncode(substr($entry, strlen($varDir)));
87 $ext = pathinfo($entry, PATHINFO_EXTENSION);
89 $titleBase = basename($entry);
90 $titleBase = preg_replace('#^[0-9]+_#', '', $titleBase);
93 $listItems[] = getDirItem($titleBase, $urlPath . '/');
94 } else if ($ext == 'url') {
97 $listItems[] = getPodcastItem(basename($titleBase, '.url'), $urlPath);
98 } else if (is_executable($entry)
99 && strpos(basename($entry), '.auto') !== false
101 //automatically execute script while listing this directory
102 addScriptOutput($listItems, $entry);
103 $enablePaging = false;
104 } else if ($ext == 'txt' || is_executable($entry)) {
107 $listItems[] = getDirItem(basename($titleBase, '.' . $ext), $urlPath);
108 } else if (basename($entry) == 'nocache') {
113 $listItems[] = getMessageItem('No files or folders');
116 $listItems, buildPreviousItem($path),
117 $enablePaging, $noCache
121 function sendScript($path)
125 $listItems = array();
127 $fullPath = $varDir . $path;
128 addScriptOutput($listItems, $fullPath);
129 sendListItems($listItems, buildPreviousItem($path), false);
132 function addScriptOutput(&$listItems, $fullPath)
134 exec($fullPath . ' 2>&1', $output, $retVal);
137 addTextLines($listItems, $output);
139 $listItems[] = getMessageItem('Error executing script');
140 addTextLines($listItems, $output);
144 function sendTextFile($path)
147 $listItems = array();
149 $lines = file($varDir . $path);
150 addTextLines($listItems, $lines);
151 sendListItems($listItems, buildPreviousItem($path));
154 function addTextLines(&$listItems, $lines)
156 foreach ($lines as $line) {
159 $listItems[] = getDisplayItem($line);
164 function getDisplayItem($line)
166 $line = preg_replace('#\s+#', ' ', $line);
168 . '<ItemType>Display</ItemType>'
169 . '<Display>' . nox_esc($line) . '</Display>'
173 function getDirItem($title, $urlPath)
175 global $host1, $host2;
177 . '<ItemType>Dir</ItemType>'
178 . '<Title>' . nox_esc($title) . '</Title>'
179 . '<UrlDir>' . $host1 . nox_esc($urlPath) . '</UrlDir>'
180 . '<UrlDirBackUp>' . $host2 . nox_esc($urlPath) . '</UrlDirBackUp>'
184 function getEpisodeItem($title, $fullUrl, $desc, $type)
187 . '<ItemType>ShowEpisode</ItemType>'
188 . '<ShowEpisodeName>' . nox_esc($title) . '</ShowEpisodeName>'
189 . '<ShowEpisodeURL>' . htmlspecialchars($fullUrl) . '</ShowEpisodeURL>'
190 . '<ShowDesc>' . nox_esc($desc) . '</ShowDesc>'
191 . '<ShowMime>' . $type . '</ShowMime>'
195 function getPodcastItem($title, $urlPath)
199 . '<ItemType>ShowOnDemand</ItemType>'
200 . '<ShowOnDemandName>' . nox_esc($title) . '</ShowOnDemandName>'
201 . '<ShowOnDemandURL>' . $host1 . nox_esc($urlPath) . '</ShowOnDemandURL>'
205 function getMessageItem($msg)
208 . '<ItemType>Message</ItemType>'
209 . '<Message>' . nox_esc($msg) . '</Message>'
213 function getPreviousItem($urlPath)
215 global $host1, $host2;
217 . '<ItemType>Previous</ItemType>'
218 . '<UrlPrevious>' . $host1 . nox_esc($urlPath) . '</UrlPrevious>'
219 . '<UrlPreviousBackUp>' . $host1 . nox_esc($urlPath) . '</UrlPreviousBackUp>'
223 function buildPreviousItem($urlPath)
225 $parentDir = dirname($urlPath) . '/';
226 if ($parentDir == '/') {
229 return getPreviousItem($parentDir);
232 function nox_esc($string)
234 return utf8_decode(htmlspecialchars($string));
237 function sendMessage($msg)
239 sendListItems(array(getMessageItem($msg)));
242 function sendListItems(
243 $listItems, $previous = null, $enablePaging = true, $noCache = false
247 if (isset($_GET['startitems'])) {
248 $startitems = (int) $_GET['startitems'];
250 if (isset($_GET['enditems'])) {
251 $enditems = (int) $_GET['enditems'];
255 $itemCount = count($listItems);
259 if ($previous !== null) {
263 $xml = '<?xml version="1.0" encoding="iso-8859-1"?>' . "\n";
264 $xml .= '<?xml-stylesheet type="text/xsl" href="/html.xsl"?>' . "\n";
265 $xml .= '<ListOfItems>' . "\n";
267 $xml .= "<NoCache>1</NoCache>\n";
269 $xml .= '<ItemCount>' . $itemCount . '</ItemCount>' . "\n";
273 foreach ($listItems as $item) {
275 if (!$enablePaging || ($num >= $startitems && $num <= $enditems)) {
276 $xml .= $item . "\n";
279 $xml .= "</ListOfItems>\n";
281 header('Content-type: text/xml; charset=iso-8859-1');