From a509e3389de70b1986ad57e58e0e1607b4e56687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Sat, 15 Jun 2013 08:03:22 +0200 Subject: [PATCH] The new interface is completely in Ajax. Feel a lot faster. re #73 Uses pushState / popState to keep browser history correct and allow using back in the browser. --- base.php | 75 +++++++++++++++- book.php | 25 ++++++ getJSON.php | 31 +++++++ index.php | 244 +++++++++++----------------------------------------- util.js | 8 ++ 5 files changed, 186 insertions(+), 197 deletions(-) create mode 100644 getJSON.php create mode 100644 util.js diff --git a/base.php b/base.php index c242942..0834a9f 100644 --- a/base.php +++ b/base.php @@ -218,7 +218,7 @@ class LinkNavigation extends Link parent::__construct ($phref, Link::OPDS_NAVIGATION_TYPE, $prel, $ptitle); if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); if (!preg_match ("#^\?(.*)#", $this->href) && !empty ($this->href)) $this->href = "?" . $this->href; - if (preg_match ("/bookdetail.php/", $_SERVER["SCRIPT_NAME"])) { + if (preg_match ("/(bookdetail|getJSON).php/", $_SERVER["SCRIPT_NAME"])) { $this->href = "index.php" . $this->href; } else { $this->href = $_SERVER["SCRIPT_NAME"] . $this->href; @@ -265,6 +265,16 @@ class Entry } return date (DATE_ATOM, self::$updated); } + + public function getContentArray () { + $navlink = "#"; + foreach ($this->linkArray as $link) { + if ($link->type != Link::OPDS_NAVIGATION_TYPE) { continue; } + + $navlink = $link->hrefXhtml (); + } + return array ( "title" => $this->title, "content" => $this->content, "navlink" => $navlink ); + } public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray) { global $config; @@ -299,6 +309,14 @@ class EntryBook extends Entry $this->localUpdated = $pbook->timestamp; } + public function getContentArray () { + $entry = array ( "title" => $this->title); + $entry ["coverurl"] = $this->getCover (); + $entry ["thumbnailurl"] = $this->getCoverThumbnail (); + $entry ["book"] = $this->book->getContentArray (); + return $entry; + } + public function getCoverThumbnail () { foreach ($this->linkArray as $link) { if ($link->rel == Link::OPDS_THUMBNAIL_TYPE) @@ -417,6 +435,61 @@ class Page } } + 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/book.php b/book.php index 84d92a8..1b3459c 100644 --- a/book.php +++ b/book.php @@ -102,6 +102,31 @@ class Book extends Base { return "?page=".parent::PAGE_BOOK_DETAIL."&id=$this->id"; } + public function getContentArray () { + global $config; + $i = 0; + $preferedData = array (); + foreach ($config['cops_prefered_format'] as $format) + { + if ($i == 2) { break; } + if ($data = $this->getDataFormat ($format)) { + $i++; + array_push ($preferedData, array ("url" => $data->getHtmlLink (), "name" => $format)); + } + } + $serie = $this->getSerie (); + if (is_null ($serie)) $serie = ""; + + return array ("hasCover" => $this->hasCover, + "preferedData" => $preferedData, + "detailUrl" => $this->getDetailUrl (), + "rating" => $this->getRating (), + "pubDate" => $this->getPubDate (), + "authorsName" => $this->getAuthorsName (), + "tagsName" => $this->getTagsName (), + "seriesName" => $serie); + } + public function getDetailUrl ($permalink = false) { global $config; $urlParam = $this->getUri (); diff --git a/getJSON.php b/getJSON.php new file mode 100644 index 0000000..502361b --- /dev/null +++ b/getJSON.php @@ -0,0 +1,31 @@ + + * + */ + + require_once ("config.php"); + require_once ("base.php"); + require_once ("author.php"); + require_once ("serie.php"); + require_once ("tag.php"); + require_once ("language.php"); + require_once ("customcolumn.php"); + require_once ("book.php"); + + header ("Content-Type:application/json;charset=utf-8"); + $page = getURLParam ("page", Base::PAGE_INDEX); + $query = getURLParam ("query"); + $qid = getURLParam ("id"); + $n = getURLParam ("n", "1"); + $database = GetUrlParam (DB); + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + echo json_encode ($currentPage->getContentArray ()); + +?> \ No newline at end of file diff --git a/index.php b/index.php index f2f8c27..51d5467 100644 --- a/index.php +++ b/index.php @@ -32,9 +32,6 @@ $n = getURLParam ("n", "1"); $database = GetUrlParam (DB); - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - /* Test to see if pages are opened on an Eink screen * test Kindle, Kobo Touch and Sony PRS-T1 Ereader. * HTTP_USER_AGENT = "Mozilla/5.0 (Linux; U; en-us; EBRD1101; EXT) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1" @@ -52,7 +49,7 @@ - <?php echo htmlspecialchars ($currentPage->title) ?> + COPS @@ -60,12 +57,44 @@ " media="screen" /> + + - + " /> -
-
- "> - " alt="" /> - - " alt="Settings and menu" /> -
-

title) ?>

-
-
> -
-
-
- " /> -
-
- - - - - - -
-
-
- containsBook ()) { ?> -
-
- <?php echo localize (" /> -
-
- - -
-
- -
-
- -
-entryArray as $entry) { - if (get_class ($entry) != "EntryBook") { -?> - - - - -
- + +
diff --git a/util.js b/util.js new file mode 100644 index 0000000..7beab6d --- /dev/null +++ b/util.js @@ -0,0 +1,8 @@ +function htmlEscape(str) { + return String(str) + .replace(/&/g, '&') + .replace(/"/g, '"') + .replace(/'/g, ''') + .replace(//g, '>'); +} \ No newline at end of file