From 66f8b109c6f8ddeb0c0c106641e7ae16da354b7d Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 24 Nov 2015 23:41:34 +0100 Subject: [PATCH] Rework folder browsing implementation - Add support for text files - Add previous directory - Add XSLT sheet for browsing with the browser --- src/podcasts.php | 40 +++------ www/.htaccess | 2 + www/html.xsl | 116 ++++++++++++++++++++++++++ www/index.php | 206 ++++++++++++++++++++++++++++++++++------------- 4 files changed, 278 insertions(+), 86 deletions(-) create mode 100644 www/html.xsl diff --git a/src/podcasts.php b/src/podcasts.php index 9948af4..1756ed5 100644 --- a/src/podcasts.php +++ b/src/podcasts.php @@ -1,45 +1,28 @@ ' - . 'ShowOnDemand' - . '' . htmlspecialchars($title) . '' - . 'http://radio567.vtuner.com/podcasts/' . urlencode(basename($file)) . '' - . ''; - } - sendListItems($listItems); -} - -function sendPodcast($file) -{ - //strip /podcasts/ - $file = substr(urldecode($file), 10); + $file = urldecode($path); if (strpos($file, '..') !== false) { sendMessage('No'); return; } - $path = __DIR__ . '/../var/podcasts/' . $file; - if (!file_exists($path)) { - return sendMessage('File does not exist: ' . $file); + $fullPath = $varDir . $path; + if (!file_exists($fullPath)) { + return sendMessage('File does not exist: ' . $path); } - $url = trim(file_get_contents($path)); + $url = trim(file_get_contents($fullPath)); - $cacheFile = '/tmp/podcast-' . md5($file) . '.xml'; + $cacheFile = '/tmp/podcast-' . md5($path) . '.xml'; downloadIfNewer($url, $cacheFile); $sx = simplexml_load_file($cacheFile); $listItems = array(); + addPreviousItem($listItems, $path); + foreach ($sx->channel->item as $item) { $title = (string) $item->title; $desc = (string) $item->description; @@ -48,8 +31,7 @@ function sendPodcast($file) $listItems[] = '' . 'ShowEpisode' . '' . utf8_decode(htmlspecialchars($title)) . '' - . 'http://radio567.vtuner.com/play-url?url=' . urlencode($url) . '' - //. '' . htmlspecialchars($url) . '' + . '' . $host1 . 'play-url?url=' . urlencode($url) . '' . '' . utf8_decode(htmlspecialchars($desc)) . '' . 'MP3' . ''; diff --git a/www/.htaccess b/www/.htaccess index 4fb1fbe..e834892 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -1,3 +1,5 @@ RewriteEngine On RewriteBase / +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ index.php diff --git a/www/html.xsl b/www/html.xsl new file mode 100644 index 0000000..4d15bd4 --- /dev/null +++ b/www/html.xsl @@ -0,0 +1,116 @@ + + + + + + +
+         
+          
+           
+          
+          < back
+         
+        
+
+ + +

Messages

+ +

+ +

+
+
+ +
+
+        
+         
+          [d] 
+          
+
+         
+
+         
+          [D] 
+          
+           
+            
+           
+           
+          
+          
+
+         
+
+         
+          [S] 
+           
+            
+             
+            
+            
+           
+           
+
+         
+
+         
+          [E] 
+          
+           
+            
+           
+           
+          
+           
+
+         
+
+        
+       
+ + +

Show episodes

+ +

+ + + + + + +

+

+ + () +

+
+
+ + +

Internet radio stations

+ +

+ #: + + + + + + +

+

+ + () +

+
+
+ + + +
+
diff --git a/www/index.php b/www/index.php index cc0be0e..3f06722 100644 --- a/www/index.php +++ b/www/index.php @@ -1,8 +1,19 @@ ' + . 'Display' + . '' . utf8_decode(htmlspecialchars(trim($line))) . '' + . ''; +} + +function getDirItem($title, $urlPath) +{ + global $host1, $host2; + return '' + . 'Dir' + . '' . utf8_decode(htmlspecialchars($title)) . '' + . '' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '' + . '' . $host2 . utf8_decode(htmlspecialchars($urlPath)) . '' + . ''; +} + +function getPodcastItem($title, $urlPath) +{ + global $host1; + return '' + . 'ShowOnDemand' + . '' . utf8_decode(htmlspecialchars($title)) . '' + . '' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '' + . ''; +} + +function getMessageItem($msg) +{ + return '' + . 'Message' + . '' . utf8_decode(htmlspecialchars($msg)) . '' + . ''; +} + +function getPreviousItem($urlPath) +{ + global $host1, $host2; + return '' + . 'Previous' + . '' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '' + . '' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '' + . ''; +} + +function addPreviousItem(&$listItems, $urlPath) +{ + $parentDir = dirname($urlPath) . '/'; + if ($parentDir == '/') { + return; + } + $listItems[] = getPreviousItem($parentDir); +} function getFinalUrl($url) { @@ -65,8 +190,12 @@ function getFinalUrl($url) return $url; } +function sendMessage($msg) +{ + sendListItems(array(getMessageItem($msg))); +} -function sendList($path) +function sendListItems($listItems) { $startitems = 1; $enditems = 10; @@ -76,54 +205,17 @@ function sendList($path) if (isset($_GET['enditems'])) { $enditems = (int) $_GET['enditems']; } + //TODO: limit list - header('Content-type: text/xml'); - echo << - - -1 - - Message - $path - - - Dir - $path - http://radio567.vtuner.com/$path - http://radio5672.vtuner.com/$path - - - -XML; -} - -function sendMessage($msg) -{ - header('Content-type: text/xml'); - $xMsg = htmlspecialchars($msg); - echo << - - - Message - $xMsg - - - -XML; -} - -function sendListItems($listItems) -{ $xml = '' . "\n"; + $xml .= '' . "\n"; $xml .= '' . "\n"; foreach ($listItems as $item) { $xml .= $item . "\n"; } $xml .= "\n"; - + header('Content-type: text/xml'); echo $xml; } - ?> -- 2.30.2