From 14b06905d51a18419fab98d866ba1997fc9d82e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Fri, 21 Sep 2012 14:19:11 +0200 Subject: [PATCH] Refactoring --- OPDS_renderer.php | 14 +++++++------- base.php | 6 ++++++ index.php | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/OPDS_renderer.php b/OPDS_renderer.php index 2494974..547f011 100644 --- a/OPDS_renderer.php +++ b/OPDS_renderer.php @@ -202,7 +202,7 @@ class OPDSRenderer public function render ($page) { global $config; self::startXmlDocument ($page->title, $page->idPage); - if ($config['cops_max_item_per_page'] != -1 && $page->totalNumber != -1) + if ($page->isPaginated ()) { self::getXmlStream ()->startElement ("opensearch:totalResults"); self::getXmlStream ()->text ($page->totalNumber); @@ -213,13 +213,13 @@ class OPDSRenderer self::getXmlStream ()->startElement ("opensearch:startIndex"); self::getXmlStream ()->text (($page->n - 1) * $config['cops_max_item_per_page'] + 1); self::getXmlStream ()->endElement (); - $currentUrl = $_SERVER['QUERY_STRING']; - $currentUrl = preg_replace ("/\&n=.*?$/", "", "?" . $_SERVER['QUERY_STRING']); - if ($page->n > 1) { - self::renderLink (new LinkNavigation ($currentUrl . "&n=" . ($page->n - 1), "previous", "Page precedente")); + $prevLink = $page->getPrevLink (); + $nextLink = $page->getNextLink (); + if (!is_null ($prevLink)) { + self::renderLink ($prevLink); } - if (($page->n + 1) * $config['cops_max_item_per_page'] < $page->totalNumber) { - self::renderLink (new LinkNavigation ($currentUrl . "&n=" . ($page->n + 1), "next", "Page suivante")); + if (!is_null ($nextLink)) { + self::renderLink ($nextLink); } } foreach ($page->entryArray as $entry) { diff --git a/base.php b/base.php index 40ffe0e..ec48e25 100644 --- a/base.php +++ b/base.php @@ -242,6 +242,12 @@ class Page $this->entryArray = array_merge ($this->entryArray, Book::getCount()); } + public function isPaginated () + { + global $config; + return ($config['cops_max_item_per_page'] != -1 && $this->totalNumber != -1); + } + public function getNextLink () { global $config; diff --git a/index.php b/index.php index b940c28..04ab840 100644 --- a/index.php +++ b/index.php @@ -219,7 +219,7 @@ ?> totalNumber != -1) { + if ($currentPage->isPaginated ()) { $prevLink = $currentPage->getPrevLink (); $nextLink = $currentPage->getNextLink (); ?>