From 11645b2155b481c6367e01af2eecf22b677330e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Sun, 20 Jan 2013 08:30:41 +0100 Subject: [PATCH] Small fixes to facets handling. re #21 * Fix ths duplicate of URL parameter * Fix when parameter is empty --- OPDS_renderer.php | 2 +- base.php | 11 +++++++++++ book.php | 2 +- config_default.php | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/OPDS_renderer.php b/OPDS_renderer.php index 5a05e88..00fdeb1 100644 --- a/OPDS_renderer.php +++ b/OPDS_renderer.php @@ -133,7 +133,7 @@ class OPDSRenderer if ($page->containsBook () && !is_null ($config['cops_books_filter']) && count ($config['cops_books_filter']) > 0) { $Urlfilter = getURLParam ("tag", ""); foreach ($config['cops_books_filter'] as $lib => $filter) { - $link = new LinkFacet ("?" . $_SERVER['QUERY_STRING'] . "&tag=" . $filter, $lib, localize ("tagword.title"), $filter == $Urlfilter); + $link = new LinkFacet ("?" . addURLParameter ($_SERVER['QUERY_STRING'], "tag", $filter), $lib, localize ("tagword.title"), $filter == $Urlfilter); self::renderLink ($link); } } diff --git a/base.php b/base.php index ae4e559..470a62c 100644 --- a/base.php +++ b/base.php @@ -81,6 +81,17 @@ function localize($phrase, $count=-1) { return $translations[$phrase]; } +function addURLParameter($urlParams, $paramName, $paramValue) { + $params = array(); + parse_str($urlParams, $params); + if (empty ($paramValue)) { + unset ($params[$paramName]); + } else { + $params[$paramName] = $paramValue; + } + return http_build_query($params); +} + class Link { const OPDS_THUMBNAIL_TYPE = "http://opds-spec.org/image/thumbnail"; diff --git a/book.php b/book.php index fd62e12..6832643 100644 --- a/book.php +++ b/book.php @@ -119,7 +119,7 @@ class Book extends Base { public function getFilterString () { $filter = getURLParam ("tag", NULL); - if (is_null ($filter)) return ""; + if (empty ($filter)) return ""; $exists = true; if (preg_match ("/^!(.*)$/", $filter, $matches)) { diff --git a/config_default.php b/config_default.php index 247fed9..4cb57ee 100644 --- a/config_default.php +++ b/config_default.php @@ -139,7 +139,7 @@ /* * Filter on tags to book list */ - $config['cops_books_filter'] = array ("Non lus" => "!Read", "lus" => "Read"); + $config['cops_books_filter'] = array ("Tout" => "", "Non lus" => "!Read", "lus" => "Read"); /* * Custom Columns to add as an array containing the lookup names