2 set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . '/../src/');
3 $fullUri = $_SERVER['REQUEST_URI'];
4 if (isset($_SERVER['REDIRECT_URL'])) {
5 $path = $_SERVER['REDIRECT_URL'];
9 $dataDir = __DIR__ . '/../data/';
10 $varDir = realpath(__DIR__ . '/../var') . '/';
11 $host1 = 'http://radio567.vtuner.com/';
12 $host2 = 'http://radio5672.vtuner.com/';
13 if ($_SERVER['HTTP_HOST'] !== '') {
14 $host1 = 'http://' . $_SERVER['HTTP_HOST'] . '/';
15 $host2 = 'http://' . $_SERVER['HTTP_HOST'] . '/';
17 $cfgFile = $dataDir . 'config.php';
18 if (file_exists($cfgFile)) {
22 if (strtolower($fullUri) == '/setupapp/radio567/asp/browsexpa/loginxml.asp?token=0') {
23 //initial login for "internet radio" and podcasts
25 header('Content-type: text/html');
26 readfile($dataDir . 'initial-login.xml');
28 } else if ($fullUri == '/RadioNativeLogin.php') {
29 //initial login for "My noxon"
30 //this one wants CamelCased tags
31 header('Content-type: text/html');
32 readfile($dataDir . 'login-mynoxon.xml');
34 } else if ($path == '/setupapp/radio567/asp/BrowseXPA/LoginXML.asp') {
36 $path = '/internetradio/';
37 } else if ($path == '/setupapp/radio567/asp/BrowseXPA/navXML.asp') {
40 } else if ($path == '/RadioNative.php') {
43 } else if ($path == '/setupapp/radio567/asp/BrowseXML/FavXML.asp') {
44 //Internet Radio Station favorites favorited on device
45 sendMessage('Unsupported');
46 } else if ($path == '/RadioNativeFavorites.php') {
47 //Favorites, defined via web interface
48 sendMessage('Unsupported');
49 } else if (substr($path, 0, 9) == '/play-url') {
50 //play a given URL, but first follow all redirects
51 //noxon iRadio Cube does not like too many redirections
52 // 3 redirects did not work.
54 header('HTTP/1.0 301 Moved Permanently');
55 header('Location: ' . getFinalUrl($url));
59 handleRequest(ltrim($path, '/'));
61 function handleRequest($path)
64 if (strpos($path, '..') !== false) {
69 if (substr($path, 0, 14) == 'internetradio/') {
70 require_once 'mediatomb.php';
71 handleRequestMediatomb($path, 'internetradio/');
76 $fullPath = $varDir . $path;
77 if (!file_exists($fullPath)) {
78 sendMessage('Not found: ' . $path);
82 if (is_dir($fullPath)) {
84 } else if (substr($path, -4) == '.url') {
85 require_once 'podcasts.php';
87 } else if (substr($path, -4) == '.txt') {
90 sendMessage('Unknown file type');
94 function sendDir($path)
99 addPreviousItem($listItems, $path);
101 $entries = glob(str_replace('//', '/', $varDir . rtrim($path, '/') . '/*'));
103 foreach ($entries as $entry) {
104 $urlPath = substr($entry, strlen($varDir));
105 if (is_dir($entry)) {
107 $listItems[] = getDirItem(basename($entry), $urlPath . '/');
108 } else if (substr($entry, -4) == '.url') {
111 $listItems[] = getPodcastItem(basename($entry, '.url'), $urlPath);
112 } else if (substr($entry, -4) == '.txt') {
115 $listItems[] = getDirItem(basename($entry, '.txt'), $urlPath);
119 $listItems[] = getMessageItem('No files or folders');
121 sendListItems($listItems);
124 function sendTextFile($path)
127 $listItems = array();
128 addPreviousItem($listItems, $path);
130 $lines = file($varDir . $path);
131 foreach ($lines as $line) {
132 $listItems[] = getDisplayItem($line);
134 sendListItems($listItems);
137 function getDisplayItem($line)
140 . '<ItemType>Display</ItemType>'
141 . '<Display>' . utf8_decode(htmlspecialchars(trim($line))) . '</Display>'
145 function getDirItem($title, $urlPath)
147 global $host1, $host2;
149 . '<ItemType>Dir</ItemType>'
150 . '<Title>' . utf8_decode(htmlspecialchars($title)) . '</Title>'
151 . '<UrlDir>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlDir>'
152 . '<UrlDirBackUp>' . $host2 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlDirBackUp>'
156 function getEpisodeItem($title, $fullUrl, $desc, $type)
159 . '<ItemType>ShowEpisode</ItemType>'
160 . '<ShowEpisodeName>' . utf8_decode(htmlspecialchars($title)) . '</ShowEpisodeName>'
161 . '<ShowEpisodeURL>' . $fullUrl . '</ShowEpisodeURL>'
162 . '<ShowDesc>' . utf8_decode(htmlspecialchars($desc)) . '</ShowDesc>'
163 . '<ShowMime>' . $type . '</ShowMime>'
167 function getPodcastItem($title, $urlPath)
171 . '<ItemType>ShowOnDemand</ItemType>'
172 . '<ShowOnDemandName>' . utf8_decode(htmlspecialchars($title)) . '</ShowOnDemandName>'
173 . '<ShowOnDemandURL>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</ShowOnDemandURL>'
177 function getMessageItem($msg)
180 . '<ItemType>Message</ItemType>'
181 . '<Message>' . utf8_decode(htmlspecialchars($msg)) . '</Message>'
185 function getPreviousItem($urlPath)
187 global $host1, $host2;
189 . '<ItemType>Previous</ItemType>'
190 . '<UrlPrevious>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlPrevious>'
191 . '<UrlPreviousBackUp>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlPreviousBackUp>'
195 function addPreviousItem(&$listItems, $urlPath)
197 $parentDir = dirname($urlPath) . '/';
198 if ($parentDir == '/') {
201 $listItems[] = getPreviousItem($parentDir);
204 function getFinalUrl($url)
206 $ctx = stream_context_set_default(
207 array('http' => array('method' => 'HEAD'))
209 //get_headers follows redirects automatically
210 $headers = get_headers($url, 1);
211 if ($headers !== false && isset($headers['Location'])) {
212 return end($headers['Location']);
217 function sendMessage($msg)
219 sendListItems(array(getMessageItem($msg)));
222 function sendListItems($listItems)
226 if (isset($_GET['startitems'])) {
227 $startitems = (int) $_GET['startitems'];
229 if (isset($_GET['enditems'])) {
230 $enditems = (int) $_GET['enditems'];
234 $xml = '<?xml version="1.0" encoding="iso-8859-1"?>' . "\n";
235 $xml .= '<?xml-stylesheet type="text/xsl" href="/html.xsl"?>' . "\n";
236 $xml .= '<ListOfItems>' . "\n";
237 foreach ($listItems as $item) {
238 $xml .= $item . "\n";
240 $xml .= "</ListOfItems>\n";
242 header('Content-type: text/xml');