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'] . '/';
18 if (strtolower($fullUri) == '/setupapp/radio567/asp/browsexpa/loginxml.asp?token=0') {
19 //initial login for "internet radio" and podcasts
21 header('Content-type: text/html');
22 readfile($dataDir . 'initial-login.xml');
24 } else if ($fullUri == '/RadioNativeLogin.php') {
25 //initial login for "My noxon"
26 //this one wants CamelCased tags
27 header('Content-type: text/html');
28 readfile($dataDir . 'login-mynoxon.xml');
30 } else if ($path == '/setupapp/radio567/asp/BrowseXPA/LoginXML.asp') {
32 $path = '/internetradio';
33 } else if ($path == '/setupapp/radio567/asp/BrowseXPA/navXML.asp') {
36 } else if ($path == '/RadioNative.php') {
39 } else if ($path == '/setupapp/radio567/asp/BrowseXML/FavXML.asp') {
40 //Internet Radio Station favorites favorited on device
41 } else if ($path == '/RadioNativeFavorites.php') {
42 //Favorites, defined via web interface
43 } else if (substr($path, 0, 9) == '/play-url') {
44 //play a given URL, but first follow all redirects
45 //noxon iRadio Cube does not like too many redirections
46 // 3 redirects did not work.
48 header('HTTP/1.0 301 Moved Permanently');
49 header('Location: ' . getFinalUrl($url));
53 handleRequest(ltrim($path, '/'));
55 function handleRequest($path)
58 if (strpos($path, '..') !== false) {
63 $fullPath = $varDir . $path;
64 if (!file_exists($fullPath)) {
65 sendMessage('Not found: ' . $path);
69 if (is_dir($fullPath)) {
71 } else if (substr($path, -4) == '.url') {
72 require_once 'podcasts.php';
74 } else if (substr($path, -4) == '.txt') {
77 sendMessage('Unknown file type');
81 function sendDir($path)
86 addPreviousItem($listItems, $path);
88 $entries = glob(str_replace('//', '/', $varDir . rtrim($path, '/') . '/*'));
90 foreach ($entries as $entry) {
91 $urlPath = substr($entry, strlen($varDir));
94 $listItems[] = getDirItem(basename($entry), $urlPath . '/');
95 } else if (substr($entry, -4) == '.url') {
98 $listItems[] = getPodcastItem(basename($entry, '.url'), $urlPath);
99 } else if (substr($entry, -4) == '.txt') {
102 $listItems[] = getDirItem(basename($entry, '.txt'), $urlPath);
106 $listItems[] = getMessageItem('No files or folders');
108 sendListItems($listItems);
111 function sendTextFile($path)
114 $listItems = array();
115 addPreviousItem($listItems, $path);
117 $lines = file($varDir . $path);
118 foreach ($lines as $line) {
119 $listItems[] = getDisplayItem($line);
121 sendListItems($listItems);
124 function getDisplayItem($line)
127 . '<ItemType>Display</ItemType>'
128 . '<Display>' . utf8_decode(htmlspecialchars(trim($line))) . '</Display>'
132 function getDirItem($title, $urlPath)
134 global $host1, $host2;
136 . '<ItemType>Dir</ItemType>'
137 . '<Title>' . utf8_decode(htmlspecialchars($title)) . '</Title>'
138 . '<UrlDir>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlDir>'
139 . '<UrlDirBackUp>' . $host2 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlDirBackUp>'
143 function getPodcastItem($title, $urlPath)
147 . '<ItemType>ShowOnDemand</ItemType>'
148 . '<ShowOnDemandName>' . utf8_decode(htmlspecialchars($title)) . '</ShowOnDemandName>'
149 . '<ShowOnDemandURL>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</ShowOnDemandURL>'
153 function getMessageItem($msg)
156 . '<ItemType>Message</ItemType>'
157 . '<Message>' . utf8_decode(htmlspecialchars($msg)) . '</Message>'
161 function getPreviousItem($urlPath)
163 global $host1, $host2;
165 . '<ItemType>Previous</ItemType>'
166 . '<UrlPrevious>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlPrevious>'
167 . '<UrlPreviousBackUp>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlPreviousBackUp>'
171 function addPreviousItem(&$listItems, $urlPath)
173 $parentDir = dirname($urlPath) . '/';
174 if ($parentDir == '/') {
177 $listItems[] = getPreviousItem($parentDir);
180 function getFinalUrl($url)
182 $ctx = stream_context_set_default(
183 array('http' => array('method' => 'HEAD'))
185 //get_headers follows redirects automatically
186 $headers = get_headers($url, 1);
187 if ($headers !== false && isset($headers['Location'])) {
188 return end($headers['Location']);
193 function sendMessage($msg)
195 sendListItems(array(getMessageItem($msg)));
198 function sendListItems($listItems)
202 if (isset($_GET['startitems'])) {
203 $startitems = (int) $_GET['startitems'];
205 if (isset($_GET['enditems'])) {
206 $enditems = (int) $_GET['enditems'];
210 $xml = '<?xml version="1.0" encoding="iso-8859-1"?>' . "\n";
211 $xml .= '<?xml-stylesheet type="text/xsl" href="/html.xsl"?>' . "\n";
212 $xml .= '<ListOfItems>' . "\n";
213 foreach ($listItems as $item) {
214 $xml .= $item . "\n";
216 $xml .= "</ListOfItems>\n";
218 header('Content-type: text/xml');