From a1cb83eea91ce046bc91366f1369c81f1f0f157a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Sat, 14 Dec 2013 11:30:42 +0100 Subject: [PATCH] Refactor the detection of the case when no database has been selected. re #127 --- base.php | 11 +++++++---- book.php | 3 +-- index.php | 2 +- util.js | 7 +++---- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/base.php b/base.php index 404cea9..484416a 100644 --- a/base.php +++ b/base.php @@ -453,8 +453,7 @@ class Page global $config; $this->title = $config['cops_title_default']; $this->subtitle = $config['cops_subtitle_default']; - $database = GetUrlParam (DB); - if (is_array ($config['calibre_directory']) && is_null ($database)) { + if (Base::noDatabaseSelected ()) { $i = 0; foreach (array_keys ($config['calibre_directory']) as $key) { $nBooks = Book::getBookCount ($i); @@ -484,7 +483,7 @@ class Page } $this->entryArray = array_merge ($this->entryArray, Book::getCount()); - if (!is_null ($database)) $this->title = Base::getDbName (); + if (Base::isMultipleDatabaseEnabled ()) $this->title = Base::getDbName (); } } @@ -739,7 +738,7 @@ class PageQueryResult extends Page $crit = "%" . $this->query . "%"; // Special case when we are doing a search and no database is selected - if (is_array ($config['calibre_directory']) && is_null (GetUrlParam (DB))) { + if (Base::noDatabaseSelected ()) { $i = 0; foreach ($config['calibre_directory'] as $key => $value) { Base::clearDb (); @@ -892,6 +891,10 @@ abstract class Base global $config; return is_array ($config['calibre_directory']); } + + public static function noDatabaseSelected () { + return self::isMultipleDatabaseEnabled () && is_null (GetUrlParam (DB)); + } public static function getDbList () { global $config; diff --git a/book.php b/book.php index 73b6faa..7ab3955 100644 --- a/book.php +++ b/book.php @@ -631,7 +631,6 @@ function getJson ($complete = false) { $page = getURLParam ("page", Base::PAGE_INDEX); $query = getURLParam ("query"); $search = getURLParam ("search"); - $multi = getURLParam ("multi"); $qid = getURLParam ("id"); $n = getURLParam ("n", "1"); $database = GetUrlParam (DB); @@ -641,7 +640,7 @@ function getJson ($complete = false) { $pagequery = Base::PAGE_OPENSEARCH_QUERY; // Special case when no databases were chosen, we search on all databases - if (is_array ($config['calibre_directory']) && $multi === "1") { + if (Base::noDatabaseSelected ()) { $i = 0; foreach (array_keys ($config['calibre_directory']) as $key) { Base::clearDb (); diff --git a/index.php b/index.php index 521cec0..c162d09 100644 --- a/index.php +++ b/index.php @@ -33,7 +33,7 @@ // Access the database ASAP to be sure it's readable, redirect if that's not the case. // It has to be done before any header is sent. - if (is_array ($config['calibre_directory']) && is_null ($database)) { + if (Base::noDatabaseSelected ()) { $i = 0; foreach (array_keys ($config['calibre_directory']) as $key) { $test = Base::getDb ($i); diff --git a/util.js b/util.js index 988d339..36e3757 100644 --- a/util.js +++ b/util.js @@ -280,13 +280,12 @@ updatePage = function (data) { limit: 24, template: templateSuggestion, remote: { - url: 'getJSON.php?search=1&db=%DB&query=%QUERY&multi=%MULTI', + url: 'getJSON.php?search=1&db=%DB&query=%QUERY', replace: function (url, query) { - var multi = 0; if (currentData.multipleDatabase === 1 && currentData.databaseId === "") { - multi = 1; + return url.replace('%QUERY', query).replace('&db=%DB', "") } - return url.replace('%QUERY', query).replace('%DB', currentData.databaseId).replace ("%MULTI", multi); + return url.replace('%QUERY', query).replace('%DB', currentData.databaseId); } } }