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);
) {
//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)
global $varDir;
$listItems = array();
- addPreviousItem($listItems, $path);
$fullPath = $varDir . $path;
addScriptOutput($listItems, $fullPath);
- sendListItems($listItems);
+ sendListItems($listItems, buildPreviousItem($path), false);
}
function addScriptOutput(&$listItems, $fullPath)
{
global $varDir;
$listItems = array();
- addPreviousItem($listItems, $path);
$lines = file($varDir . $path);
addTextLines($listItems, $lines);
- sendListItems($listItems);
+ sendListItems($listItems, buildPreviousItem($path));
}
function addTextLines(&$listItems, $lines)
. '</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)
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";