X-Git-Url: https://git.cweiske.de/noxon-gateway.git/blobdiff_plain/66f8b109c6f8ddeb0c0c106641e7ae16da354b7d..58e37edfab922c69de3e2cae54fa7fcbe5378eb5:/www/index.php?ds=sidebyside
diff --git a/www/index.php b/www/index.php
index 3f06722..abbe698 100644
--- a/www/index.php
+++ b/www/index.php
@@ -1,53 +1,28 @@
&1', $output, $retVal);
+
+ if ($retVal == 0) {
+ addTextLines($listItems, $output);
+ } else {
+ $listItems[] = getMessageItem('Error executing script');
+ addTextLines($listItems, $output);
+ }
}
function sendTextFile($path)
{
global $varDir;
$listItems = array();
- addPreviousItem($listItems, $path);
$lines = file($varDir . $path);
+ addTextLines($listItems, $lines);
+ sendListItems($listItems, buildPreviousItem($path));
+}
+
+function addTextLines(&$listItems, $lines)
+{
foreach ($lines as $line) {
- $listItems[] = getDisplayItem($line);
+ $line = trim($line);
+ if ($line != '') {
+ $listItems[] = getDisplayItem($line);
+ }
}
- sendListItems($listItems);
}
function getDisplayItem($line)
{
+ $line = preg_replace('#\s+#', ' ', $line);
return '- '
. 'Display'
- . '' . utf8_decode(htmlspecialchars(trim($line))) . ''
+ . '' . nox_esc($line) . ''
. '
';
}
@@ -134,9 +175,20 @@ function getDirItem($title, $urlPath)
global $host1, $host2;
return '- '
. 'Dir'
- . '' . utf8_decode(htmlspecialchars($title)) . ''
- . '' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . ''
- . '' . $host2 . utf8_decode(htmlspecialchars($urlPath)) . ''
+ . '' . nox_esc($title) . ''
+ . '' . $host1 . nox_esc($urlPath) . ''
+ . '' . $host2 . nox_esc($urlPath) . ''
+ . '
';
+}
+
+function getEpisodeItem($title, $fullUrl, $desc, $type)
+{
+ return '- '
+ . 'ShowEpisode'
+ . '' . nox_esc($title) . ''
+ . '' . htmlspecialchars($fullUrl) . ''
+ . '' . nox_esc($desc) . ''
+ . '' . $type . ''
. '
';
}
@@ -145,8 +197,8 @@ function getPodcastItem($title, $urlPath)
global $host1;
return '- '
. 'ShowOnDemand'
- . '' . utf8_decode(htmlspecialchars($title)) . ''
- . '' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . ''
+ . '' . nox_esc($title) . ''
+ . '' . $host1 . nox_esc($urlPath) . ''
. '
';
}
@@ -154,7 +206,7 @@ function getMessageItem($msg)
{
return '- '
. 'Message'
- . '' . utf8_decode(htmlspecialchars($msg)) . ''
+ . '' . nox_esc($msg) . ''
. '
';
}
@@ -163,31 +215,23 @@ function getPreviousItem($urlPath)
global $host1, $host2;
return '- '
. 'Previous'
- . '' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . ''
- . '' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . ''
+ . '' . $host1 . nox_esc($urlPath) . ''
+ . '' . $host1 . nox_esc($urlPath) . ''
. '
';
}
-function addPreviousItem(&$listItems, $urlPath)
+function buildPreviousItem($urlPath)
{
$parentDir = dirname($urlPath) . '/';
if ($parentDir == '/') {
- return;
+ return null;
}
- $listItems[] = getPreviousItem($parentDir);
+ return getPreviousItem($parentDir);
}
-function getFinalUrl($url)
+function nox_esc($string)
{
- $ctx = stream_context_set_default(
- array('http' => array('method' => 'HEAD'))
- );
- //get_headers follows redirects automatically
- $headers = get_headers($url, 1);
- if ($headers !== false && isset($headers['Location'])) {
- return end($headers['Location']);
- }
- return $url;
+ return utf8_decode(htmlspecialchars($string));
}
function sendMessage($msg)
@@ -195,27 +239,46 @@ function sendMessage($msg)
sendListItems(array(getMessageItem($msg)));
}
-function sendListItems($listItems)
-{
+function sendListItems(
+ $listItems, $previous = null, $enablePaging = true, $noCache = false
+) {
$startitems = 1;
- $enditems = 10;
+ $enditems = 100000;
if (isset($_GET['startitems'])) {
$startitems = (int) $_GET['startitems'];
}
if (isset($_GET['enditems'])) {
$enditems = (int) $_GET['enditems'];
}
- //TODO: limit list
+
+ if ($enablePaging) {
+ $itemCount = count($listItems);
+ } else {
+ $itemCount = -1;
+ }
+ if ($previous !== null) {
+ $previous .= "\n";
+ }
$xml = '' . "\n";
$xml .= '' . "\n";
$xml .= '' . "\n";
+ if ($noCache) {
+ $xml .= "1\n";
+ }
+ $xml .= '' . $itemCount . '' . "\n";
+ $xml .= $previous;
+
+ $num = 0;
foreach ($listItems as $item) {
- $xml .= $item . "\n";
+ ++$num;
+ if (!$enablePaging || ($num >= $startitems && $num <= $enditems)) {
+ $xml .= $item . "\n";
+ }
}
$xml .= "\n";
- header('Content-type: text/xml');
+ header('Content-type: text/xml; charset=iso-8859-1');
echo $xml;
}
?>