shorten escaping code
[noxon-gateway.git] / www / index.php
index d64436cad0ce3ebbe6dbb85f92562496a4f9d2d5..a81f774bddb46d6ae2530597001daad873385c4e 100644 (file)
@@ -1,23 +1,5 @@
 <?php
-set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . '/../src/');
-$fullUri = $_SERVER['REQUEST_URI'];
-if (isset($_SERVER['REDIRECT_URL'])) {
-    $path    = $_SERVER['REDIRECT_URL'];
-} else {
-    $path = '/';
-}
-$dataDir = __DIR__ . '/../data/';
-$varDir  = realpath(__DIR__ . '/../var') . '/';
-$host1 = 'http://radio567.vtuner.com/';
-$host2 = 'http://radio5672.vtuner.com/';
-if ($_SERVER['HTTP_HOST'] !== '') {
-    $host1 = 'http://' . $_SERVER['HTTP_HOST'] . '/';
-    $host2 = 'http://' . $_SERVER['HTTP_HOST'] . '/';
-}
-$cfgFile = $dataDir . 'config.php';
-if (file_exists($cfgFile)) {
-    include $cfgFile;
-}
+require_once __DIR__ . '/../src/header.php';
 
 if (strtolower($fullUri) == '/setupapp/radio567/asp/browsexpa/loginxml.asp?token=0'
     || $fullUri == '/RadioNativeLogin.php'
@@ -55,7 +37,11 @@ function handleRequest($path)
 
     if (substr($path, 0, 14) == 'internetradio/') {
         require_once 'mediatomb.php';
-        handleRequestMediatomb($path, 'internetradio/');
+        handleMediatomb('browse', $path, 'internetradio/');
+        return;
+    } else if (substr($path, 0, 11) == '.mt-single/') {
+        require_once 'mediatomb.php';
+        handleMediatomb('single', $path, '.mt-single/');
         return;
     }
 
@@ -74,7 +60,7 @@ function handleRequest($path)
         sendPodcast($path);
     } else if ($ext == 'txt') {
         sendTextFile($path);
-    } else if ($ext == 'sh') {
+    } else if (is_executable($fullPath)) {
         sendScript($path);
     } else {
         sendMessage('Unknown file type');
@@ -108,10 +94,12 @@ function sendDir($path)
             //podcast
             ++$count;
             $listItems[] = getPodcastItem(basename($titleBase, '.url'), $urlPath);
-        } else if (substr($entry, -8) == '.auto.sh') {
+        } else if (is_executable($entry)
+            && strpos(basename($entry), '.auto') !== false
+        ) {
             //automatically execute script while listing this directory
             addScriptOutput($listItems, $entry);
-        } else if ($ext == 'txt' || $ext == 'sh') {
+        } else if ($ext == 'txt' || is_executable($entry)) {
             //plain text file
             ++$count;
             $listItems[] = getDirItem(basename($titleBase, '.' . $ext), $urlPath);
@@ -173,7 +161,7 @@ function getDisplayItem($line)
     $line = preg_replace('#\s+#', ' ', $line);
     return '<Item>'
         . '<ItemType>Display</ItemType>'
-        . '<Display>' . utf8_decode(htmlspecialchars($line)) . '</Display>'
+        . '<Display>' . nox_esc($line) . '</Display>'
         . '</Item>';
 }
 
@@ -182,9 +170,9 @@ function getDirItem($title, $urlPath)
     global $host1, $host2;
     return '<Item>'
         . '<ItemType>Dir</ItemType>'
-        . '<Title>' . utf8_decode(htmlspecialchars($title)) . '</Title>'
-        . '<UrlDir>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlDir>'
-        . '<UrlDirBackUp>' . $host2 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlDirBackUp>'
+        . '<Title>' . nox_esc($title) . '</Title>'
+        . '<UrlDir>' . $host1 . nox_esc($urlPath) . '</UrlDir>'
+        . '<UrlDirBackUp>' . $host2 . nox_esc($urlPath) . '</UrlDirBackUp>'
         . '</Item>';
 }
 
@@ -192,9 +180,9 @@ function getEpisodeItem($title, $fullUrl, $desc, $type)
 {
     return '<Item>'
         . '<ItemType>ShowEpisode</ItemType>'
-        . '<ShowEpisodeName>' . utf8_decode(htmlspecialchars($title)) . '</ShowEpisodeName>'
-        . '<ShowEpisodeURL>' . $fullUrl . '</ShowEpisodeURL>'
-        . '<ShowDesc>' . utf8_decode(htmlspecialchars($desc)) . '</ShowDesc>'
+        . '<ShowEpisodeName>' . nox_esc($title) . '</ShowEpisodeName>'
+        . '<ShowEpisodeURL>' . htmlspecialchars($fullUrl) . '</ShowEpisodeURL>'
+        . '<ShowDesc>' . nox_esc($desc) . '</ShowDesc>'
         . '<ShowMime>' . $type . '</ShowMime>'
         . '</Item>';
 }
@@ -204,8 +192,8 @@ function getPodcastItem($title, $urlPath)
     global $host1;
     return '<Item>'
         . '<ItemType>ShowOnDemand</ItemType>'
-        . '<ShowOnDemandName>' . utf8_decode(htmlspecialchars($title)) . '</ShowOnDemandName>'
-        . '<ShowOnDemandURL>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</ShowOnDemandURL>'
+        . '<ShowOnDemandName>' . nox_esc($title) . '</ShowOnDemandName>'
+        . '<ShowOnDemandURL>' . $host1 . nox_esc($urlPath) . '</ShowOnDemandURL>'
         . '</Item>';
 }
 
@@ -213,7 +201,7 @@ function getMessageItem($msg)
 {
     return '<Item>'
         . '<ItemType>Message</ItemType>'
-        . '<Message>' . utf8_decode(htmlspecialchars($msg)) . '</Message>'
+        . '<Message>' . nox_esc($msg) . '</Message>'
         . '</Item>';
 }
 
@@ -222,8 +210,8 @@ function getPreviousItem($urlPath)
     global $host1, $host2;
     return '<Item>'
         . '<ItemType>Previous</ItemType>'
-        . '<UrlPrevious>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlPrevious>'
-        . '<UrlPreviousBackUp>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlPreviousBackUp>'
+        . '<UrlPrevious>' . $host1 . nox_esc($urlPath) . '</UrlPrevious>'
+        . '<UrlPreviousBackUp>' . $host1 . nox_esc($urlPath) . '</UrlPreviousBackUp>'
         . '</Item>';
 }
 
@@ -236,6 +224,11 @@ function addPreviousItem(&$listItems, $urlPath)
     $listItems[] = getPreviousItem($parentDir);
 }
 
+function nox_esc($string)
+{
+    return utf8_decode(htmlspecialchars($string));
+}
+
 function sendMessage($msg)
 {
     sendListItems(array(getMessageItem($msg)));
@@ -261,7 +254,7 @@ function sendListItems($listItems)
     }
     $xml .= "</ListOfItems>\n";
 
-    header('Content-type: text/xml');
+    header('Content-type: text/xml; charset=iso-8859-1');
     echo $xml;
 }
 ?>