2 require_once __DIR__ . '/../src/header.php';
4 $radioPodcastLogin = isset($_GET['token']) && $_GET['token'] == '0'
5 && strtolower($path) == '/setupapp/radio567/asp/browsexpa/loginxml.asp';
6 $myNoxonLogin = $path == '/RadioNativeLogin.php';
8 if ($radioPodcastLogin || $myNoxonLogin) {
9 //initial login for "internet radio", podcasts and "my noxon"
10 header('Content-type: text/html');
11 readfile($dataDir . 'login-camelcase.xml');
13 } else if ($path == '/setupapp/radio567/asp/BrowseXPA/LoginXML.asp') {
15 $path = '/internetradio/';
16 } else if ($path == '/setupapp/radio567/asp/BrowseXPA/navXML.asp') {
19 } else if ($path == '/RadioNative.php') {
22 } else if ($path == '/setupapp/radio567/asp/BrowseXML/FavXML.asp') {
23 //Internet Radio Station favorites favorited on device
24 sendMessage('Unsupported');
25 } else if ($path == '/RadioNativeFavorites.php') {
26 //Favorites, defined via web interface
27 sendMessage('Unsupported');
30 handleRequest(ltrim($path, '/'));
32 function handleRequest($path)
35 if (strpos($path, '/../') !== false) {
40 if (substr($path, 0, 14) == 'internetradio/') {
41 require_once 'mediatomb.php';
42 handleMediatomb('browse', $path, 'internetradio/');
44 } else if (substr($path, 0, 11) == '.mt-single/') {
45 require_once 'mediatomb.php';
46 handleMediatomb('single', $path, '.mt-single/');
51 $fullPath = $varDir . $path;
52 if (!file_exists($fullPath)) {
53 sendMessage('Not found: ' . $path);
57 $ext = pathinfo($path, PATHINFO_EXTENSION);
58 if (is_dir($fullPath)) {
60 } else if ($ext == 'url') {
61 require_once 'podcasts.php';
63 } else if ($ext == 'txt') {
65 } else if (is_executable($fullPath)) {
68 sendMessage('Unknown file type');
72 function pathEncode($urlPath)
74 return str_replace('%2F', '/', rawurlencode($urlPath));
77 function sendDir($path)
84 $entries = glob(str_replace('//', '/', $varDir . rtrim($path, '/') . '/*'));
87 foreach ($entries as $entry) {
88 $urlPath = pathEncode(substr($entry, strlen($varDir)));
89 $ext = pathinfo($entry, PATHINFO_EXTENSION);
91 $titleBase = basename($entry);
92 $titleBase = preg_replace('#^[0-9]+_#', '', $titleBase);
95 $listItems[] = getDirItem($titleBase, $urlPath . '/');
96 } else if ($ext == 'url') {
99 $listItems[] = getPodcastItem(basename($titleBase, '.url'), $urlPath);
100 } else if (is_executable($entry)
101 && strpos(basename($entry), '.auto') !== false
103 //automatically execute script while listing this directory
104 addScriptOutput($listItems, $entry);
105 $enablePaging = false;
106 } else if ($ext == 'txt' || is_executable($entry)) {
109 $listItems[] = getDirItem(basename($titleBase, '.' . $ext), $urlPath);
110 } else if (basename($entry) == 'nocache') {
115 $listItems[] = getMessageItem('No files or folders');
118 $listItems, buildPreviousItem($path),
119 $enablePaging, $noCache
123 function sendScript($path)
127 $listItems = array();
129 $fullPath = $varDir . $path;
130 addScriptOutput($listItems, $fullPath);
131 sendListItems($listItems, buildPreviousItem($path), false);
134 function addScriptOutput(&$listItems, $fullPath)
136 exec($fullPath . ' 2>&1', $output, $retVal);
139 addTextLines($listItems, $output);
141 $listItems[] = getMessageItem('Error executing script');
142 addTextLines($listItems, $output);
146 function sendTextFile($path)
149 $listItems = array();
151 $lines = file($varDir . $path);
152 addTextLines($listItems, $lines);
153 sendListItems($listItems, buildPreviousItem($path));
156 function addTextLines(&$listItems, $lines)
158 foreach ($lines as $line) {
161 $listItems[] = getDisplayItem($line);
166 function getDisplayItem($line)
168 $line = preg_replace('#\s+#', ' ', $line);
170 . '<ItemType>Display</ItemType>'
171 . '<Display>' . nox_esc($line) . '</Display>'
175 function getDirItem($title, $urlPath)
177 global $host1, $host2;
179 . '<ItemType>Dir</ItemType>'
180 . '<Title>' . nox_esc($title) . '</Title>'
181 . '<UrlDir>' . $host1 . nox_esc($urlPath) . '</UrlDir>'
182 . '<UrlDirBackUp>' . $host2 . nox_esc($urlPath) . '</UrlDirBackUp>'
186 function getEpisodeItem($title, $fullUrl, $desc, $type)
189 . '<ItemType>ShowEpisode</ItemType>'
190 . '<ShowEpisodeName>' . nox_esc($title) . '</ShowEpisodeName>'
191 . '<ShowEpisodeURL>' . htmlspecialchars($fullUrl) . '</ShowEpisodeURL>'
192 . '<ShowDesc>' . nox_esc($desc) . '</ShowDesc>'
193 . '<ShowMime>' . $type . '</ShowMime>'
197 function getPodcastItem($title, $urlPath)
201 . '<ItemType>ShowOnDemand</ItemType>'
202 . '<ShowOnDemandName>' . nox_esc($title) . '</ShowOnDemandName>'
203 . '<ShowOnDemandURL>' . $host1 . nox_esc($urlPath) . '</ShowOnDemandURL>'
207 function getMessageItem($msg)
210 . '<ItemType>Message</ItemType>'
211 . '<Message>' . nox_esc($msg) . '</Message>'
215 function getPreviousItem($urlPath)
217 global $host1, $host2;
219 . '<ItemType>Previous</ItemType>'
220 . '<UrlPrevious>' . $host1 . nox_esc($urlPath) . '</UrlPrevious>'
221 . '<UrlPreviousBackUp>' . $host1 . nox_esc($urlPath) . '</UrlPreviousBackUp>'
225 function buildPreviousItem($urlPath)
227 $parentDir = dirname($urlPath) . '/';
228 if ($parentDir == '/') {
231 return getPreviousItem($parentDir);
234 function nox_esc($string)
236 return utf8_decode(htmlspecialchars($string));
239 function sendMessage($msg)
241 sendListItems(array(getMessageItem($msg)));
244 function sendListItems(
245 $listItems, $previous = null, $enablePaging = true, $noCache = false
249 if (isset($_GET['startitems'])) {
250 $startitems = (int) $_GET['startitems'];
252 if (isset($_GET['enditems'])) {
253 $enditems = (int) $_GET['enditems'];
257 $itemCount = count($listItems);
261 if ($previous !== null) {
265 $xml = '<?xml version="1.0" encoding="iso-8859-1"?>' . "\n";
266 $xml .= '<?xml-stylesheet type="text/xsl" href="/html.xsl"?>' . "\n";
267 $xml .= '<ListOfItems>' . "\n";
269 $xml .= "<NoCache>1</NoCache>\n";
271 $xml .= '<ItemCount>' . $itemCount . '</ItemCount>' . "\n";
275 foreach ($listItems as $item) {
277 if (!$enablePaging || ($num >= $startitems && $num <= $enditems)) {
278 $xml .= $item . "\n";
281 $xml .= "</ListOfItems>\n";
283 header('Content-type: text/xml; charset=iso-8859-1');