From: Christian Weiske Date: Mon, 4 Jan 2016 20:42:58 +0000 (+0100) Subject: add paging support X-Git-Url: https://git.cweiske.de/noxon-gateway.git/commitdiff_plain/ed993bdeefda0612110ef489e28a45d3ccdfc5c4 add paging support --- diff --git a/README.rst b/README.rst index 11bac20..1d3d3a3 100644 --- a/README.rst +++ b/README.rst @@ -27,6 +27,7 @@ Features - Transcoding of non-mp3 file types to ``.mp3`` that iRadios can play - Single file mode for children that want to listen to a single story before sleeping +- Paging results with ``?startitems=1&enditems=10`` GET parameters RSS feed support diff --git a/src/mediatomb.php b/src/mediatomb.php index bdfa4eb..d80e20e 100644 --- a/src/mediatomb.php +++ b/src/mediatomb.php @@ -26,7 +26,6 @@ function mediatombBrowse(Services_MediaTomb $smt, $fullPath, $prefix) $path = substr($fullPath, strlen($prefix)); $container = $smt->getContainerByPath($path); $listItems = array(); - addPreviousItem($listItems, $fullPath); $it = $container->getItemIterator(false); $it->rewind(); @@ -57,7 +56,7 @@ function mediatombBrowse(Services_MediaTomb $smt, $fullPath, $prefix) mediatombAddFile($listItems, $item); } - sendListItems($listItems); + sendListItems($listItems, buildPreviousItem($fullPath)); } function mediatombAddFile(&$listItems, $item) @@ -104,13 +103,14 @@ function mediatombSingle(Services_MediaTomb $smt, $fullPath, $prefix) $container = $smt->getContainerByPath($path); $listItems = array(); + $previous = null; if ($fileMode) { //show single file to play - addPreviousItem($listItems, pathEncode($fullPath)); + $previous = buildPreviousItem(pathEncode($fullPath)); $item = $smt->getSingleItem($container, $fileTitle, false); mediatombAddFile($listItems, $item); } else { - addPreviousItem($listItems, pathEncode('internetradio/' . $path . '/dummy')); + $previous = buildPreviousItem(pathEncode('internetradio/' . $path . '/dummy')); //browse directory foreach ($container->getItemIterator(false) as $item) { @@ -121,6 +121,6 @@ function mediatombSingle(Services_MediaTomb $smt, $fullPath, $prefix) } } - sendListItems($listItems); + sendListItems($listItems, $previous); } ?> diff --git a/src/podcasts.php b/src/podcasts.php index 3acccbb..bb8f5ce 100644 --- a/src/podcasts.php +++ b/src/podcasts.php @@ -21,7 +21,6 @@ function sendPodcast($path) $sx = simplexml_load_file($cacheFile); $listItems = array(); - addPreviousItem($listItems, $path); foreach ($sx->channel->item as $item) { $title = (string) $item->title; @@ -35,7 +34,7 @@ function sendPodcast($path) 'MP3' ); } - sendListItems($listItems); + sendListItems($listItems, buildPreviousItem($path)); } diff --git a/www/index.php b/www/index.php index a81f774..b3b2a7b 100644 --- a/www/index.php +++ b/www/index.php @@ -2,7 +2,7 @@ require_once __DIR__ . '/../src/header.php'; if (strtolower($fullUri) == '/setupapp/radio567/asp/browsexpa/loginxml.asp?token=0' - || $fullUri == '/RadioNativeLogin.php' + || $fullUri == '/RadioNativeLogin.phpb' ) { //initial login for "internet radio", podcasts and "my noxon" header('Content-type: text/html'); @@ -77,7 +77,7 @@ function sendDir($path) global $varDir; $listItems = array(); - addPreviousItem($listItems, $path); + $enablePaging = true; $entries = glob(str_replace('//', '/', $varDir . rtrim($path, '/') . '/*')); $count = 0; @@ -99,6 +99,7 @@ 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; @@ -108,7 +109,7 @@ function sendDir($path) if (!$count) { $listItems[] = getMessageItem('No files or folders'); } - sendListItems($listItems); + sendListItems($listItems, buildPreviousItem($path), $enablePaging); } function sendScript($path) @@ -116,11 +117,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 +139,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 +214,13 @@ function getPreviousItem($urlPath) . ''; } -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 +233,38 @@ function sendMessage($msg) sendListItems(array(getMessageItem($msg))); } -function sendListItems($listItems) +function sendListItems($listItems, $previous = null, $enablePaging = true) { $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"; + $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";