Move most of JSON code to getJSON. re #73

This commit is contained in:
Sébastien Lucas 2013-06-15 08:43:38 +02:00
parent e9065b9c29
commit b7ab8bd9d9
2 changed files with 50 additions and 56 deletions

View file

@ -434,62 +434,7 @@ class Page
if (!is_null ($database)) $this->title = Base::getDbName (); 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 () public function isPaginated ()
{ {
global $config; global $config;

View file

@ -26,6 +26,55 @@
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $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);
?> ?>