From b7ab8bd9d9c2ba9f9a614cf94ccd2148e1f2ea54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Sat, 15 Jun 2013 08:43:38 +0200 Subject: [PATCH] Move most of JSON code to getJSON. re #73 --- base.php | 55 ----------------------------------------------------- getJSON.php | 51 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 56 deletions(-) diff --git a/base.php b/base.php index 0834a9f..85081ac 100644 --- a/base.php +++ b/base.php @@ -434,62 +434,7 @@ class Page if (!is_null ($database)) $this->title = Base::getDbName (); } } - - public function getContentArray () - { - global $config; - $database = GetUrlParam (DB); - $page = getURLParam ("page", Base::PAGE_INDEX); - $out = array ( "title" => $this->title, "version" => VERSION); - $entries = array (); - foreach ($this->entryArray as $entry) { - array_push ($entries, $entry->getContentArray ()); - } - $out ["databaseId"] = GetUrlParam (DB, ""); - $out ["databaseName"] = Base::getDbName (); - $out ["page"] = $page; - $out ["entries"] = $entries; - $out ["isPaginated"] = 0; - if ($this->isPaginated ()) { - $prevLink = $this->getPrevLink (); - $nextLink = $this->getNextLink (); - $out ["isPaginated"] = 1; - $out ["prevLink"] = ""; - if (!is_null ($prevLink)) { - $out ["prevLink"] = $prevLink->hrefXhtml (); - } - $out ["nextLink"] = ""; - if (!is_null ($nextLink)) { - $out ["nextLink"] = $nextLink->hrefXhtml (); - } - $out ["maxPage"] = $this->getMaxPage (); - $out ["currentPage"] = $this->n; - } - $out ["i18n"] = array ("coverAlt" => localize("i18n.coversection"), - "authorsTitle" => localize("authors.title"), - "tagsTitle" => localize("tags.title"), - "seriesTitle" => localize("series.title"), - "customizeTitle" => localize ("customize.title"), - "aboutTitle" => localize ("about.title"), - "previousAlt" => localize ("paging.previous.alternate"), - "nextAlt" => localize ("paging.next.alternate"), - "searchAlt" => localize ("search.alternate"), - "homeAlt" => localize ("home.alternate")); - $out ["containsBook"] = 0; - if ($this->containsBook ()) { - $out ["containsBook"] = 1; - } - $out["abouturl"] = "about.xml"; - if (getCurrentOption ('use_fancyapps') == 0) { - $out["abouturl"] = "index.php" . str_replace ("&", "&", addURLParameter ("?page=16", DB, $database)); - } - - $out ["homeurl"] = "index.php"; - if ($page != Base::PAGE_INDEX && !is_null ($database)) $out ["homeurl"] = $out ["homeurl"] . "?" . addURLParameter ("", DB, $database); - return $out; - } - public function isPaginated () { global $config; diff --git a/getJSON.php b/getJSON.php index 502361b..e5bfeb2 100644 --- a/getJSON.php +++ b/getJSON.php @@ -26,6 +26,55 @@ $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - echo json_encode ($currentPage->getContentArray ()); + $out = array ( "title" => $currentPage->title, "version" => VERSION); + $entries = array (); + foreach ($currentPage->entryArray as $entry) { + array_push ($entries, $entry->getContentArray ()); + } + $out ["databaseId"] = GetUrlParam (DB, ""); + $out ["databaseName"] = Base::getDbName (); + $out ["page"] = $page; + $out ["entries"] = $entries; + $out ["isPaginated"] = 0; + if ($currentPage->isPaginated ()) { + $prevLink = $currentPage->getPrevLink (); + $nextLink = $currentPage->getNextLink (); + $out ["isPaginated"] = 1; + $out ["prevLink"] = ""; + if (!is_null ($prevLink)) { + $out ["prevLink"] = $prevLink->hrefXhtml (); + } + $out ["nextLink"] = ""; + if (!is_null ($nextLink)) { + $out ["nextLink"] = $nextLink->hrefXhtml (); + } + $out ["maxPage"] = $currentPage->getMaxPage (); + $out ["currentPage"] = $currentPage->n; + } + $out ["i18n"] = array ("coverAlt" => localize("i18n.coversection"), + "authorsTitle" => localize("authors.title"), + "tagsTitle" => localize("tags.title"), + "seriesTitle" => localize("series.title"), + "customizeTitle" => localize ("customize.title"), + "aboutTitle" => localize ("about.title"), + "previousAlt" => localize ("paging.previous.alternate"), + "nextAlt" => localize ("paging.next.alternate"), + "searchAlt" => localize ("search.alternate"), + "homeAlt" => localize ("home.alternate")); + + $out ["containsBook"] = 0; + if ($currentPage->containsBook ()) { + $out ["containsBook"] = 1; + } + $out["abouturl"] = "about.xml"; + if (getCurrentOption ('use_fancyapps') == 0) { + $out["abouturl"] = "index.php" . str_replace ("&", "&", addURLParameter ("?page=16", DB, $database)); + } + + $out ["homeurl"] = "index.php"; + if ($page != Base::PAGE_INDEX && !is_null ($database)) $out ["homeurl"] = $out ["homeurl"] . "?" . addURLParameter ("", DB, $database); + + + echo json_encode ($out); ?> \ No newline at end of file