From f2b6b4e23064c40cde9e2ad5327499589dee503b Mon Sep 17 00:00:00 2001 From: tcit Date: Wed, 14 May 2014 22:03:16 +0200 Subject: [PATCH] Fix bugs and improved epub rendering --- inc/3rdparty/libraries/PHPePub/EPub.php | 14 ++++----- inc/poche/Poche.class.php | 40 +++++++++++++------------ 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/inc/3rdparty/libraries/PHPePub/EPub.php b/inc/3rdparty/libraries/PHPePub/EPub.php index e120b34..f1f41bd 100644 --- a/inc/3rdparty/libraries/PHPePub/EPub.php +++ b/inc/3rdparty/libraries/PHPePub/EPub.php @@ -574,7 +574,7 @@ class EPub { * @param string $mimetype Image mimetype, such as "image/jpeg" or "image/png". * @return bool $success */ - function setCover($fileName, $imageData = NULL, $mimetype = NULL, $coverText=NULL) { + function setCoverImage($fileName, $imageData = NULL, $mimetype = NULL,$bookTitle) { if ($this->isFinalized || $this->isCoverImageSet || array_key_exists("CoverPage.html", $this->fileList)) { return FALSE; } @@ -621,13 +621,13 @@ class EPub { . "\n" . "\t\n" . "\t\t\n" - . "\t\tCover\n" + . "\t\tCover Image\n" . "\t\t\n" . "\t\n" . "\t\n" - . "\t\t" . $coverText . "\n" + . "\t" . $bookTitle . "\n" . "\t\t
\n" - . "\t\t\t\"Cover\n" + . "\t\t\t\"Cover\n" . "\t\t
\n" . "\t\n" . "\n"; @@ -636,13 +636,13 @@ class EPub { . "\n" . "" . "\t\n" - . "\t\tCover\n" + . "\t\tCover Image\n" . "\t\t\n" . "\t\n" . "\t\n" . "\t\t
\n" - . "\t\t" . $coverText . "\n" - . "\t\t\t\"Cover\n" + . "\t" . $bookTitle . "\n" + . "\t\t\t\"Cover\n" . "\t\t
\n" . "\t\n" . "\n"; diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 85dd384..99d2989 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -1142,23 +1142,28 @@ class Poche $entryID = filter_var($_GET['id'],FILTER_SANITIZE_NUMBER_INT); $entry = $this->store->retrieveOneById($entryID, $this->user->getId()); $entries = array($entry); + $bookTitle = $entry['title']; break; case 'all': $entries = $this->store->retrieveAll($this->user->getId()); + $bookTitle = _('All my articles'); break; case 'tag': $tag = filter_var($_GET['tag'],FILTER_SANITIZE_STRING); $tags_id = $this->store->retrieveAllTags($this->user->getId(),$tag); $tag_id = $tags_id[0]["id"]; // we take the first result, which is supposed to match perfectly. There must be a workaround. $entries = $this->store->retrieveEntriesByTag($tag_id,$this->user->getId()); + $bookTitle = sprintf(_('Articles related to %s'),$tag); break; case 'category': $category = filter_var($_GET['category'],FILTER_SANITIZE_STRING); $entries = $this->store->getEntriesByView($category,$this->user->getId()); + $bookTitle = sprintf(_('All my articles in category %s'), $category); break; case 'search': $search = filter_var($_GET['search'],FILTER_SANITIZE_STRING); $entries = $this->store->search($search,$this->user->getId()); + $bookTitle = sprintf(_('All my articles for search %s'), $search); break; case 'default': die(_('Uh, there is a problem while generating epub.')); @@ -1166,12 +1171,11 @@ class Poche } $content_start = - "\n" - . "\n" - . "\n" - . "\n" - . "\n" - . "wallabag article\n" + "\n" + . "\n" + . "" + . "\n" + . "wallabag articles book\n" . "\n" . "\n"; @@ -1205,23 +1209,22 @@ class Poche $cssData = "body {\n margin-left: .5em;\n margin-right: .5em;\n text-align: justify;\n}\n\np {\n font-family: serif;\n font-size: 10pt;\n text-align: justify;\n text-indent: 1em;\n margin-top: 0px;\n margin-bottom: 1ex;\n}\n\nh1, h2 {\n font-family: sans-serif;\n font-style: italic;\n text-align: center;\n background-color: #6b879c;\n color: white;\n width: 100%;\n}\n\nh1 {\n margin-bottom: 2px;\n}\n\nh2 {\n margin-top: -2px;\n margin-bottom: 2px;\n}\n"; $log->logLine("Add Cover"); - if (count($entries)>1){ - $cover = sprintf(_('

%s and %s other articles

'), $entries[0]['title'], count($entries)); - } else { - $cover = sprintf(_('

%s

'), $entries[0]['title']); - } - $book->setCover("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png", $cover); + $fullTitle = "

" . $bookTitle . "

\n"; - $book->setCover($cover); - //$book->addChapter("Notices", "Cover.html", $cover); - $book->buildTOC(NULL, "toc", _('Table of Contents'), TRUE, TRUE); - $subject = ""; + $book->setCoverImage("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png", $fullTitle); + + $cover = $content_start . _('Produced by wallabag with PHPePub') . $bookEnd; + + //$book->addChapter("Table of Contents", "TOC.xhtml", NULL, false, EPub::EXTERNAL_REF_IGNORE); + $book->addChapter("Notices", "Cover2.html", $cover); + + $book->buildTOC(); foreach ($entries as $entry) { $tags = $this->store->retrieveTagsByEntry($entry['id']); foreach ($tags as $tag) { - $subject =. $tag['value'] . ','; + $book->setSubject($tag['value']); } $log->logLine("Set up parameters"); @@ -1229,8 +1232,7 @@ class Poche $chapter = $content_start . $entry['content'] . $bookEnd; $book->addChapter($entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD); $log->logLine("Added chapter " . $entry['title']); - } - $book->setSubject($subject); + } if (DEBUG_POCHE) { $epuplog = $book->getLog();