fix mynoxon login
[noxon-gateway.git] / www / index.php
index a81f774bddb46d6ae2530597001daad873385c4e..1ec3bf1de81f0341cbeb5110c6515edb133e376a 100644 (file)
@@ -77,10 +77,11 @@ function sendDir($path)
     global $varDir;
 
     $listItems = array();
-    addPreviousItem($listItems, $path);
+    $enablePaging = true;
 
     $entries = glob(str_replace('//', '/', $varDir . rtrim($path, '/') . '/*'));
     $count = 0;
+    $noCache = false;
     foreach ($entries as $entry) {
         $urlPath = pathEncode(substr($entry, strlen($varDir)));
         $ext = pathinfo($entry, PATHINFO_EXTENSION);
@@ -99,16 +100,22 @@ function sendDir($path)
         ) {
             //automatically execute script while listing this directory
             addScriptOutput($listItems, $entry);
+            $enablePaging = false;
         } else if ($ext == 'txt' || is_executable($entry)) {
             //plain text file
             ++$count;
             $listItems[] = getDirItem(basename($titleBase, '.' . $ext), $urlPath);
+        } else  if (basename($entry) == 'nocache') {
+            $noCache = true;
         }
     }
     if (!$count) {
         $listItems[] = getMessageItem('No files or folders');
     }
-    sendListItems($listItems);
+    sendListItems(
+        $listItems, buildPreviousItem($path),
+        $enablePaging, $noCache
+    );
 }
 
 function sendScript($path)
@@ -116,11 +123,10 @@ function sendScript($path)
     global $varDir;
 
     $listItems = array();
-    addPreviousItem($listItems, $path);
 
     $fullPath = $varDir . $path;
     addScriptOutput($listItems, $fullPath);
-    sendListItems($listItems);
+    sendListItems($listItems, buildPreviousItem($path), false);
 }
 
 function addScriptOutput(&$listItems, $fullPath)
@@ -139,11 +145,10 @@ function sendTextFile($path)
 {
     global $varDir;
     $listItems = array();
-    addPreviousItem($listItems, $path);
 
     $lines = file($varDir . $path);
     addTextLines($listItems, $lines);
-    sendListItems($listItems);
+    sendListItems($listItems, buildPreviousItem($path));
 }
 
 function addTextLines(&$listItems, $lines)
@@ -215,13 +220,13 @@ function getPreviousItem($urlPath)
         . '</Item>';
 }
 
-function addPreviousItem(&$listItems, $urlPath)
+function buildPreviousItem($urlPath)
 {
     $parentDir = dirname($urlPath) . '/';
     if ($parentDir == '/') {
-        return;
+        return null;
     }
-    $listItems[] = getPreviousItem($parentDir);
+    return getPreviousItem($parentDir);
 }
 
 function nox_esc($string)
@@ -234,23 +239,42 @@ 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 = '<?xml version="1.0" encoding="iso-8859-1"?>' . "\n";
     $xml .= '<?xml-stylesheet type="text/xsl" href="/html.xsl"?>' . "\n";
     $xml .= '<ListOfItems>' . "\n";
+    if ($noCache) {
+        $xml .= "<NoCache>1</NoCache>\n";
+    }
+    $xml .= '<ItemCount>' . $itemCount . '</ItemCount>' . "\n";
+    $xml .= $previous;
+
+    $num = 0;
     foreach ($listItems as $item) {
-        $xml .= $item . "\n";
+        ++$num;
+        if (!$enablePaging || ($num >= $startitems && $num <= $enditems)) {
+            $xml .= $item . "\n";
+        }
     }
     $xml .= "</ListOfItems>\n";