From 87090d8ae7582708d20f3c09fb37d780af860bcd Mon Sep 17 00:00:00 2001 From: tcit Date: Thu, 24 Apr 2014 03:04:02 +0200 Subject: Added epub export function --- inc/poche/Poche.class.php | 83 +++++++++++++++++++++++++++++++++++++++++++++++ inc/poche/global.inc.php | 5 +++ 2 files changed, 88 insertions(+) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 7e3e6afe..e5539468 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -1131,4 +1131,87 @@ class Poche return new HTMLPurifier($config); } + + /** + * handle epub + */ + public function createEpub() { + + if (isset($_GET['epub']) && isset($_GET['id'])) { + if ($_GET['id'] == "all") { // we put all entries in the file + $entries = $this->store->retrieveAll($this->user->getId()); + } + else { // we put only one entry in the file + $entryID = filter_var($_GET['id'],FILTER_SANITIZE_NUMBER_INT); + $entry = $this->store->retrieveOneById($entryID, $this->user->getId()); + $entries = array($entry); + } + } + $content_start = + "\n" + . "\n" + . "\n" + . "" + . "\n" + . "\n" + . "Test Book\n" + . "\n" + . "\n"; + + $bookEnd = "\n\n"; + + $log = new Logger($entryID, TRUE); + $fileDir = CACHE; + + + $book = new EPub(); + $log->logLine("new EPub()"); + $log->logLine("EPub class version: " . EPub::VERSION); + $log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION); + $log->logLine("Zip version: " . Zip::VERSION); + $log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL()); + $log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL()); + + $book->setTitle("wallabag's articles"); + $book->setIdentifier("http://$_SERVER[HTTP_HOST]", EPub::IDENTIFIER_URI); // Could also be the ISBN number, prefered for published books, or a UUID. + //$book->setLanguage("en"); // Not needed, but included for the example, Language is mandatory, but EPub defaults to "en". Use RFC3066 Language codes, such as "en", "da", "fr" etc. + $book->setDescription("Some articles saved on my wallabag"); + $book->setAuthor("wallabag","wallabag"); + $book->setPublisher("wallabag","wallabag"); // I hope this is a non existant address :) + $book->setDate(time()); // Strictly not needed as the book date defaults to time(). + //$book->setRights("Copyright and licence information specific for the book."); // As this is generated, this _could_ contain the name or licence information of the user who purchased the book, if needed. If this is used that way, the identifier must also be made unique for the book. + $book->setSourceURL("http://$_SERVER[HTTP_HOST]"); + + $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP"); + + $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"; + $cover = $content_start . "

My articles on wallabag

\n

As seen on : http://$_SERVER[HTTP_HOST]

\n" . $bookEnd; + $book->addChapter("Notices", "Cover.html", $cover); + $book->buildTOC(NULL, "toc", "Table of Contents", TRUE, TRUE); + + foreach ($entries as $entry) { + $tags = $this->store->retrieveTagsByEntry($entry['id']); + foreach ($tags as $tag) { + $book->setSubject($tag); + } + + $log->logLine("Set up parameters"); + + + + $chapter = $content_start . $entry['content'] . $bookEnd; + $book->addChapter("Chapter " . $entry['id'] . ": " . $entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD); + } + + + if (true) { + $epuplog = $book->getLog(); + $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n" . $bookEnd); // generation log + // Only used in case we need to debug EPub.php. + //$book->addChapter("ePubLog", "ePubLog.html", $content_start . $epuplog . "\n" . $bookEnd); + } + $book->finalize(); + $zipData = $book->sendBook("wallabag's articles"); + } } diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php index 14e9dd93..8cf86d03 100755 --- a/inc/poche/global.inc.php +++ b/inc/poche/global.inc.php @@ -31,6 +31,11 @@ require_once INCLUDES . '/3rdparty/FlattrItem.class.php'; require_once INCLUDES . '/3rdparty/htmlpurifier/HTMLPurifier.auto.php'; +# epub library +require_once INCLUDES . '/3rdparty/libraries/PHPePub/Logger.php'; +require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPub.php'; +require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPubChapterSplitter.php'; + # Composer its autoloader for automatically loading Twig if (! file_exists(ROOT . '/vendor/autoload.php')) { Poche::$canRenderTemplates = false; -- cgit v1.2.3 From 7ec445b06e05d8caa5219c5802007d897c48ab4e Mon Sep 17 00:00:00 2001 From: tcit Date: Fri, 25 Apr 2014 16:20:25 +0200 Subject: Big changes for epub export. Now possible to do it from a tag, a category and a search. Also, improved ebook rendering. --- inc/poche/Poche.class.php | 56 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 18 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index e5539468..c476df3e 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -1136,36 +1136,52 @@ class Poche * handle epub */ public function createEpub() { - - if (isset($_GET['epub']) && isset($_GET['id'])) { - if ($_GET['id'] == "all") { // we put all entries in the file - $entries = $this->store->retrieveAll($this->user->getId()); - } - else { // we put only one entry in the file + + switch ($_GET['method']) { + case 'id': $entryID = filter_var($_GET['id'],FILTER_SANITIZE_NUMBER_INT); $entry = $this->store->retrieveOneById($entryID, $this->user->getId()); $entries = array($entry); - } + break; + case 'all': + $entries = $this->store->retrieveAll($this->user->getId()); + 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()); + break; + case 'category': + $category = filter_var($_GET['category'],FILTER_SANITIZE_STRING); + $entries = $this->store->getEntriesByView($category,$this->user->getId()); + break; + case 'search': + $search = filter_var($_GET['search'],FILTER_SANITIZE_STRING); + $entries = $this->store->search($search,$this->user->getId()); + break; + case 'default': + die(_('Uh, there is a problem while generating epub.')); + } + $content_start = "\n" - . "\n" - . "\n" - . "" - . "\n" + . "\n" + . "\n" + . "\n" . "\n" - . "Test Book\n" + . "wallabag article\n" . "\n" . "\n"; $bookEnd = "\n\n"; - $log = new Logger($entryID, TRUE); + $log = new Logger("wallabag", TRUE); $fileDir = CACHE; - $book = new EPub(); + $book = new EPub(EPub::BOOK_VERSION_EPUB3); $log->logLine("new EPub()"); $log->logLine("EPub class version: " . EPub::VERSION); $log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION); @@ -1186,6 +1202,10 @@ class Poche $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP"); $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 Image"); + $book->setCoverImage("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png"); + $cover = $content_start . "

My articles on wallabag

\n

As seen on : http://$_SERVER[HTTP_HOST]

\n" . $bookEnd; $book->addChapter("Notices", "Cover.html", $cover); $book->buildTOC(NULL, "toc", "Table of Contents", TRUE, TRUE); @@ -1193,7 +1213,7 @@ class Poche foreach ($entries as $entry) { $tags = $this->store->retrieveTagsByEntry($entry['id']); foreach ($tags as $tag) { - $book->setSubject($tag); + $book->setSubject($tag['value']); } $log->logLine("Set up parameters"); @@ -1201,11 +1221,11 @@ class Poche $chapter = $content_start . $entry['content'] . $bookEnd; - $book->addChapter("Chapter " . $entry['id'] . ": " . $entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD); + $book->addChapter($entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub::EXTERNAL_REF_ADD); } - if (true) { + if (DEBUG_POCHE) { $epuplog = $book->getLog(); $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n" . $bookEnd); // generation log // Only used in case we need to debug EPub.php. -- cgit v1.2.3 From 4877836b12cde621a9c6200ec460ce025384ea35 Mon Sep 17 00:00:00 2001 From: tcit Date: Wed, 7 May 2014 12:40:09 +0200 Subject: Many improvements to epub produced : better cover, better tags --- inc/poche/Poche.class.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index c476df3e..c99bfcba 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -1200,30 +1200,37 @@ class Poche $book->setSourceURL("http://$_SERVER[HTTP_HOST]"); $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP"); + $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "wallabag"); $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 Image"); - $book->setCoverImage("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png"); + $log->logLine("Add Cover"); + if (count($entries)>1){ + $cover = "

" . $entries[0]['title'] . " and " . count($entries) . " other articles

"; + } else { + $cover = "

" . $entries[0]['title'] . "

"; + } + $book->setCover("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png", $cover); + - $cover = $content_start . "

My articles on wallabag

\n

As seen on : http://$_SERVER[HTTP_HOST]

\n" . $bookEnd; - $book->addChapter("Notices", "Cover.html", $cover); + $book->setCover($cover); + //$book->addChapter("Notices", "Cover.html", $cover); $book->buildTOC(NULL, "toc", "Table of Contents", TRUE, TRUE); + $subject = ""; foreach ($entries as $entry) { $tags = $this->store->retrieveTagsByEntry($entry['id']); foreach ($tags as $tag) { - $book->setSubject($tag['value']); + $subject =. $tag['value'] . ','; } $log->logLine("Set up parameters"); - - $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(); -- cgit v1.2.3 From 34acb02cbbc700f0d73ac340e906d3179932ab2b Mon Sep 17 00:00:00 2001 From: tcit Date: Wed, 7 May 2014 12:48:46 +0200 Subject: Added translation capabilities for epub system --- inc/poche/Poche.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index c99bfcba..c59973f3 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -1189,10 +1189,10 @@ class Poche $log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL()); $log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL()); - $book->setTitle("wallabag's articles"); + $book->setTitle(_('wallabag\'s articles')); $book->setIdentifier("http://$_SERVER[HTTP_HOST]", EPub::IDENTIFIER_URI); // Could also be the ISBN number, prefered for published books, or a UUID. //$book->setLanguage("en"); // Not needed, but included for the example, Language is mandatory, but EPub defaults to "en". Use RFC3066 Language codes, such as "en", "da", "fr" etc. - $book->setDescription("Some articles saved on my wallabag"); + $book->setDescription(_("Some articles saved on my wallabag")); $book->setAuthor("wallabag","wallabag"); $book->setPublisher("wallabag","wallabag"); // I hope this is a non existant address :) $book->setDate(time()); // Strictly not needed as the book date defaults to time(). @@ -1206,16 +1206,16 @@ class Poche $log->logLine("Add Cover"); if (count($entries)>1){ - $cover = "

" . $entries[0]['title'] . " and " . count($entries) . " other articles

"; + $cover = sprintf(_('

%s and %s other articles

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

" . $entries[0]['title'] . "

"; + $cover = sprintf(_('

%s

'), $entries[0]['title']); } $book->setCover("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png", $cover); $book->setCover($cover); //$book->addChapter("Notices", "Cover.html", $cover); - $book->buildTOC(NULL, "toc", "Table of Contents", TRUE, TRUE); + $book->buildTOC(NULL, "toc", _('Table of Contents'), TRUE, TRUE); $subject = ""; foreach ($entries as $entry) { @@ -1239,6 +1239,6 @@ class Poche //$book->addChapter("ePubLog", "ePubLog.html", $content_start . $epuplog . "\n" . $bookEnd); } $book->finalize(); - $zipData = $book->sendBook("wallabag's articles"); + $zipData = $book->sendBook(_('wallabag\'s articles')); } } -- cgit v1.2.3 From f2b6b4e23064c40cde9e2ad5327499589dee503b Mon Sep 17 00:00:00 2001 From: tcit Date: Wed, 14 May 2014 22:03:16 +0200 Subject: Fix bugs and improved epub rendering --- inc/poche/Poche.class.php | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 85dd3848..99d2989b 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->setCoverImage("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png", $fullTitle); - $book->setCover($cover); - //$book->addChapter("Notices", "Cover.html", $cover); - $book->buildTOC(NULL, "toc", _('Table of Contents'), TRUE, TRUE); - $subject = ""; + $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(); -- cgit v1.2.3 From f3f0b11393dd7f11bc1e63df9488c3930c0bc06f Mon Sep 17 00:00:00 2001 From: tcit Date: Thu, 15 May 2014 15:42:36 +0200 Subject: Better names for epub files and epub in all themes now --- inc/poche/Poche.class.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 99d2989b..bce7d651 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -1143,27 +1143,32 @@ class Poche $entry = $this->store->retrieveOneById($entryID, $this->user->getId()); $entries = array($entry); $bookTitle = $entry['title']; + $bookFileName = substr($bookTitle, 0, 200); break; case 'all': $entries = $this->store->retrieveAll($this->user->getId()); - $bookTitle = _('All my articles'); + $bookTitle = sprintf(_('All my articles on '), date(_('d.m.y'))); #translatable because each country has it's own date format system + $bookFileName = _('Allarticles') . date(_('dmY')); 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); + $bookTitle = sprintf(_('Articles tagged %s'),$tag); + $bookFileName = substr(sprintf(_('Tag %s'),$tag), 0, 200); 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); + $bookTitle = sprintf(_('All articles in category %s'), $category); + $bookFileName = substr(sprintf(_('Category %s'),$category), 0, 200); 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); + $bookTitle = sprintf(_('All articles for search %s'), $search); + $bookFileName = substr(sprintf(_('Search %s'), $search), 0, 200); break; case 'default': die(_('Uh, there is a problem while generating epub.')); @@ -1241,6 +1246,6 @@ class Poche //$book->addChapter("ePubLog", "ePubLog.html", $content_start . $epuplog . "\n" . $bookEnd); } $book->finalize(); - $zipData = $book->sendBook(_('wallabag\'s articles')); + $zipData = $book->sendBook($bookFileName); } } -- cgit v1.2.3