From 4188f38ad56d7ba2ea46e94403f305243514f80c Mon Sep 17 00:00:00 2001 From: tcit Date: Thu, 24 Jul 2014 15:49:36 +0200 Subject: add pdf and mobi libraries --- inc/poche/WallabagEpub.class.php | 114 ++++++++++++++++++++++++++++++++++++--- inc/poche/global.inc.php | 10 ++++ 2 files changed, 117 insertions(+), 7 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/WallabagEpub.class.php b/inc/poche/WallabagEpub.class.php index 9c4d3566..14774425 100644 --- a/inc/poche/WallabagEpub.class.php +++ b/inc/poche/WallabagEpub.class.php @@ -8,11 +8,14 @@ * @license http://opensource.org/licenses/MIT see COPYING file */ -class WallabagEpub +class WallabagEBooks { - protected $wallabag; + protected $wallabag; protected $method; protected $value; + protected $entries; + protected $bookTitle; + protected $bookFileName; public function __construct(Poche $wallabag, $method, $value) { @@ -21,10 +24,7 @@ class WallabagEpub $this->value = $value; } - /** - * handle ePub - */ - public function run() + public function prepareData() { switch ($this->method) { case 'id': @@ -62,7 +62,16 @@ class WallabagEpub case 'default': die(_('Uh, there is a problem while generating epub.')); } + } +} +class WallabagEpub extends WallabagEBooks +{ + /** + * handle ePub + */ + public function produceEpub() + { $content_start = "\n" . "\n" @@ -132,4 +141,95 @@ class WallabagEpub $book->finalize(); $zipData = $book->sendBook($bookFileName); } -} \ No newline at end of file +} + +class WallabagMobi extends WallabagEBooks +{ + /** + * Adapted from News2Kindle + * @author Jakub Westfalewski + * + */ + + public function produceMobi() + { + $storage = new Storage('static'); + $this->prepareData(); + foreach ($entries as $i => $item) { + $content = $item['content']; + $images = new Images($storage, $content); + $content = $images->convert(); + $storage->add_content + ( + md5($item['title']), + mb_convert_encoding($item['title'], 'HTML-ENTITIES', 'utf-8'), + $content, + $item['url']], + "" + ); + } + $articles = $storage->get_contents(); + $toc = array(); + $articles_count = count($articles); + + foreach($articles as $article){ + if(array_key_exists($article->website->title, $toc)){ + $toc[$article->website->title]->articles[] = $article; + }else{ + $toc[$article->website->title] = (object)array( + 'articles' => array($article), + 'title' => $article->website->title, + 'streamId' => $article->website->streamId, + 'url' => $article->website->htmlUrl, + ); + } + } + + $mobi = new MOBI(); + $mobi->setData($content); + $mobi->setOptions(array( + 'title' => 'Articles from '.date('Y-m-d'), + 'author' => 'wallabag', + 'subject' => 'Articles from '.date('Y-m-d'), + )); + + $images = array(); + + //prepare images for mobi format + foreach ( $storage->info('images') as $n => $image ) + { + $images[$n] = new FileRecord(new Record(file_get_contents($storage->get_path() . $image))); + } + + $mobi->setImages($images); + $mobi->save( $storage->get_path(FALSE) . 'articles-' . date('Y-m-d') . '.mobi'); + + $storage->clean(); + + if ($send) { + $files = glob($storage->get_path(FALSE).'*.mobi'); + $mail = new Send(KINDLEMAIL,MAIL); + foreach ( $files as $file_mobi ) + { + $mail->send( $file_mobi ); + } + // clean cache + foreach ( $files as $file_mobi ) + { + unlink( $file_mobi ); + } + } + } +} + +class WallabagPDF extends WallabagEbooks +{ + public function producePDF() + { + $mpdf = new mPDF('c'); + + $mpdf->WriteHTML($html); + $mpdf->Output(); + exit; + } +} \ No newline at end of file diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php index b8c487e3..e3687eb2 100755 --- a/inc/poche/global.inc.php +++ b/inc/poche/global.inc.php @@ -41,6 +41,16 @@ require_once INCLUDES . '/3rdparty/libraries/PHPePub/Logger.php'; require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPub.php'; require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPubChapterSplitter.php'; +# mobi library +require_once INCLUDES . '/3rdparty/libraries/send2kindle/send.php'; +require_once INCLUDES . '/3rdparty/libraries/send2kindle/images.php'; +require_once INCLUDES . '/3rdparty/libraries/send2kindle/storage.php'; +require_once INCLUDES . '/3rdparty/libraries/send2kindle/MOBIClass/MOBI.php'; +require_once INCLUDES . '/3rdparty/libraries/send2kindle/utils.php'; + +# pdf library +require_once INCLUDES . '/3rdparty/libraries/mpdf/mpdf.php'; + # system configuration; database credentials et caetera require_once INCLUDES . '/poche/config.inc.php'; require_once INCLUDES . '/poche/config.inc.default.php'; -- cgit v1.2.3 From 15317991f3ff456e6e215947402a0dcfd951e0df Mon Sep 17 00:00:00 2001 From: tcit Date: Thu, 24 Jul 2014 15:53:23 +0200 Subject: from epub to all kind of ebooks --- inc/poche/WallabagEBooks.class.php | 235 +++++++++++++++++++++++++++++++++++++ inc/poche/WallabagEpub.class.php | 235 ------------------------------------- inc/poche/global.inc.php | 2 +- 3 files changed, 236 insertions(+), 236 deletions(-) create mode 100644 inc/poche/WallabagEBooks.class.php delete mode 100644 inc/poche/WallabagEpub.class.php (limited to 'inc/poche') diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php new file mode 100644 index 00000000..14774425 --- /dev/null +++ b/inc/poche/WallabagEBooks.class.php @@ -0,0 +1,235 @@ + + * @copyright 2013 + * @license http://opensource.org/licenses/MIT see COPYING file + */ + +class WallabagEBooks +{ + protected $wallabag; + protected $method; + protected $value; + protected $entries; + protected $bookTitle; + protected $bookFileName; + + public function __construct(Poche $wallabag, $method, $value) + { + $this->wallabag = $wallabag; + $this->method = $method; + $this->value = $value; + } + + public function prepareData() + { + switch ($this->method) { + case 'id': + $entryID = filter_var($this->value, FILTER_SANITIZE_NUMBER_INT); + $entry = $this->wallabag->store->retrieveOneById($entryID, $this->wallabag->user->getId()); + $entries = array($entry); + $bookTitle = $entry['title']; + $bookFileName = substr($bookTitle, 0, 200); + break; + case 'all': + $entries = $this->wallabag->store->retrieveAll($this->wallabag->user->getId()); + $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($this->value, FILTER_SANITIZE_STRING); + $tags_id = $this->wallabag->store->retrieveAllTags($this->wallabag->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->wallabag->store->retrieveEntriesByTag($tag_id, $this->wallabag->user->getId()); + $bookTitle = sprintf(_('Articles tagged %s'), $tag); + $bookFileName = substr(sprintf(_('Tag %s'), $tag), 0, 200); + break; + case 'category': + $category = filter_var($this->value, FILTER_SANITIZE_STRING); + $entries = $this->wallabag->store->getEntriesByView($category, $this->wallabag->user->getId()); + $bookTitle = sprintf(_('All articles in category %s'), $category); + $bookFileName = substr(sprintf(_('Category %s'), $category), 0, 200); + break; + case 'search': + $search = filter_var($this->value, FILTER_SANITIZE_STRING); + $entries = $this->store->search($search, $this->wallabag->user->getId()); + $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.')); + } + } +} + +class WallabagEpub extends WallabagEBooks +{ + /** + * handle ePub + */ + public function produceEpub() + { + $content_start = + "\n" + . "\n" + . "" + . "\n" + . "wallabag articles book\n" + . "\n" + . "\n"; + + $bookEnd = "\n\n"; + + $log = new Logger("wallabag", TRUE); + $fileDir = CACHE; + + $book = new EPub(EPub::BOOK_VERSION_EPUB3, DEBUG_POCHE); + $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($bookTitle); + $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"); + $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"); + + $fullTitle = "

" . $bookTitle . "

\n"; + + $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') . '

'. _('Please open an issue if you have trouble with the display of this E-Book on your device.') . '

' . $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) { //set tags as subjects + $tags = $this->wallabag->store->retrieveTagsByEntry($entry['id']); + foreach ($tags as $tag) { + $book->setSubject($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']); + } + + if (DEBUG_POCHE) { + $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n" . $bookEnd); // log generation + } + $book->finalize(); + $zipData = $book->sendBook($bookFileName); + } +} + +class WallabagMobi extends WallabagEBooks +{ + /** + * Adapted from News2Kindle + * @author Jakub Westfalewski + * + */ + + public function produceMobi() + { + $storage = new Storage('static'); + $this->prepareData(); + foreach ($entries as $i => $item) { + $content = $item['content']; + $images = new Images($storage, $content); + $content = $images->convert(); + $storage->add_content + ( + md5($item['title']), + mb_convert_encoding($item['title'], 'HTML-ENTITIES', 'utf-8'), + $content, + $item['url']], + "" + ); + } + $articles = $storage->get_contents(); + $toc = array(); + $articles_count = count($articles); + + foreach($articles as $article){ + if(array_key_exists($article->website->title, $toc)){ + $toc[$article->website->title]->articles[] = $article; + }else{ + $toc[$article->website->title] = (object)array( + 'articles' => array($article), + 'title' => $article->website->title, + 'streamId' => $article->website->streamId, + 'url' => $article->website->htmlUrl, + ); + } + } + + $mobi = new MOBI(); + $mobi->setData($content); + $mobi->setOptions(array( + 'title' => 'Articles from '.date('Y-m-d'), + 'author' => 'wallabag', + 'subject' => 'Articles from '.date('Y-m-d'), + )); + + $images = array(); + + //prepare images for mobi format + foreach ( $storage->info('images') as $n => $image ) + { + $images[$n] = new FileRecord(new Record(file_get_contents($storage->get_path() . $image))); + } + + $mobi->setImages($images); + $mobi->save( $storage->get_path(FALSE) . 'articles-' . date('Y-m-d') . '.mobi'); + + $storage->clean(); + + if ($send) { + $files = glob($storage->get_path(FALSE).'*.mobi'); + $mail = new Send(KINDLEMAIL,MAIL); + foreach ( $files as $file_mobi ) + { + $mail->send( $file_mobi ); + } + // clean cache + foreach ( $files as $file_mobi ) + { + unlink( $file_mobi ); + } + } + } +} + +class WallabagPDF extends WallabagEbooks +{ + public function producePDF() + { + $mpdf = new mPDF('c'); + + $mpdf->WriteHTML($html); + $mpdf->Output(); + exit; + } +} \ No newline at end of file diff --git a/inc/poche/WallabagEpub.class.php b/inc/poche/WallabagEpub.class.php deleted file mode 100644 index 14774425..00000000 --- a/inc/poche/WallabagEpub.class.php +++ /dev/null @@ -1,235 +0,0 @@ - - * @copyright 2013 - * @license http://opensource.org/licenses/MIT see COPYING file - */ - -class WallabagEBooks -{ - protected $wallabag; - protected $method; - protected $value; - protected $entries; - protected $bookTitle; - protected $bookFileName; - - public function __construct(Poche $wallabag, $method, $value) - { - $this->wallabag = $wallabag; - $this->method = $method; - $this->value = $value; - } - - public function prepareData() - { - switch ($this->method) { - case 'id': - $entryID = filter_var($this->value, FILTER_SANITIZE_NUMBER_INT); - $entry = $this->wallabag->store->retrieveOneById($entryID, $this->wallabag->user->getId()); - $entries = array($entry); - $bookTitle = $entry['title']; - $bookFileName = substr($bookTitle, 0, 200); - break; - case 'all': - $entries = $this->wallabag->store->retrieveAll($this->wallabag->user->getId()); - $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($this->value, FILTER_SANITIZE_STRING); - $tags_id = $this->wallabag->store->retrieveAllTags($this->wallabag->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->wallabag->store->retrieveEntriesByTag($tag_id, $this->wallabag->user->getId()); - $bookTitle = sprintf(_('Articles tagged %s'), $tag); - $bookFileName = substr(sprintf(_('Tag %s'), $tag), 0, 200); - break; - case 'category': - $category = filter_var($this->value, FILTER_SANITIZE_STRING); - $entries = $this->wallabag->store->getEntriesByView($category, $this->wallabag->user->getId()); - $bookTitle = sprintf(_('All articles in category %s'), $category); - $bookFileName = substr(sprintf(_('Category %s'), $category), 0, 200); - break; - case 'search': - $search = filter_var($this->value, FILTER_SANITIZE_STRING); - $entries = $this->store->search($search, $this->wallabag->user->getId()); - $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.')); - } - } -} - -class WallabagEpub extends WallabagEBooks -{ - /** - * handle ePub - */ - public function produceEpub() - { - $content_start = - "\n" - . "\n" - . "" - . "\n" - . "wallabag articles book\n" - . "\n" - . "\n"; - - $bookEnd = "\n\n"; - - $log = new Logger("wallabag", TRUE); - $fileDir = CACHE; - - $book = new EPub(EPub::BOOK_VERSION_EPUB3, DEBUG_POCHE); - $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($bookTitle); - $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"); - $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"); - - $fullTitle = "

" . $bookTitle . "

\n"; - - $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') . '

'. _('Please open an issue if you have trouble with the display of this E-Book on your device.') . '

' . $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) { //set tags as subjects - $tags = $this->wallabag->store->retrieveTagsByEntry($entry['id']); - foreach ($tags as $tag) { - $book->setSubject($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']); - } - - if (DEBUG_POCHE) { - $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n" . $bookEnd); // log generation - } - $book->finalize(); - $zipData = $book->sendBook($bookFileName); - } -} - -class WallabagMobi extends WallabagEBooks -{ - /** - * Adapted from News2Kindle - * @author Jakub Westfalewski - * - */ - - public function produceMobi() - { - $storage = new Storage('static'); - $this->prepareData(); - foreach ($entries as $i => $item) { - $content = $item['content']; - $images = new Images($storage, $content); - $content = $images->convert(); - $storage->add_content - ( - md5($item['title']), - mb_convert_encoding($item['title'], 'HTML-ENTITIES', 'utf-8'), - $content, - $item['url']], - "" - ); - } - $articles = $storage->get_contents(); - $toc = array(); - $articles_count = count($articles); - - foreach($articles as $article){ - if(array_key_exists($article->website->title, $toc)){ - $toc[$article->website->title]->articles[] = $article; - }else{ - $toc[$article->website->title] = (object)array( - 'articles' => array($article), - 'title' => $article->website->title, - 'streamId' => $article->website->streamId, - 'url' => $article->website->htmlUrl, - ); - } - } - - $mobi = new MOBI(); - $mobi->setData($content); - $mobi->setOptions(array( - 'title' => 'Articles from '.date('Y-m-d'), - 'author' => 'wallabag', - 'subject' => 'Articles from '.date('Y-m-d'), - )); - - $images = array(); - - //prepare images for mobi format - foreach ( $storage->info('images') as $n => $image ) - { - $images[$n] = new FileRecord(new Record(file_get_contents($storage->get_path() . $image))); - } - - $mobi->setImages($images); - $mobi->save( $storage->get_path(FALSE) . 'articles-' . date('Y-m-d') . '.mobi'); - - $storage->clean(); - - if ($send) { - $files = glob($storage->get_path(FALSE).'*.mobi'); - $mail = new Send(KINDLEMAIL,MAIL); - foreach ( $files as $file_mobi ) - { - $mail->send( $file_mobi ); - } - // clean cache - foreach ( $files as $file_mobi ) - { - unlink( $file_mobi ); - } - } - } -} - -class WallabagPDF extends WallabagEbooks -{ - public function producePDF() - { - $mpdf = new mPDF('c'); - - $mpdf->WriteHTML($html); - $mpdf->Output(); - exit; - } -} \ No newline at end of file diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php index e3687eb2..1542fbfa 100755 --- a/inc/poche/global.inc.php +++ b/inc/poche/global.inc.php @@ -22,7 +22,7 @@ require_once ROOT . '/vendor/autoload.php'; require_once INCLUDES . '/poche/Template.class.php'; require_once INCLUDES . '/poche/Language.class.php'; require_once INCLUDES . '/poche/Routing.class.php'; -require_once INCLUDES . '/poche/WallabagEpub.class.php'; +require_once INCLUDES . '/poche/WallabagEBooks.class.php'; require_once INCLUDES . '/poche/Poche.class.php'; require_once INCLUDES . '/poche/Database.class.php'; -- cgit v1.2.3 From c70bfefc68fcc96b1ce57845e5b2942a596239ec Mon Sep 17 00:00:00 2001 From: tcit Date: Thu, 24 Jul 2014 15:59:08 +0200 Subject: add mobi and pdf to routing --- inc/poche/Routing.class.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php index 2db57d12..e01d8129 100644 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php @@ -112,7 +112,13 @@ class Routing $this->wallabag->deleteUser($_POST['password4deletinguser']); } elseif (isset($_GET['epub'])) { $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['value']); - $epub->run(); + $epub->produceEpub(); + } elseif (isset($_GET['mobi'])) { + $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); + $mobi->produceMobi(); + } elseif (isset($_GET['pdf'])) { + $pdf = new WallabagPDF($this->wallabag, $_GET['method'], $_GET['value']); + $pdf->producePDF(); } elseif (isset($_GET['import'])) { $import = $this->wallabag->import(); $tplVars = array_merge($this->vars, $import); -- cgit v1.2.3 From fb9df0c269f36703909b8b259abbdbed29881ecd Mon Sep 17 00:00:00 2001 From: tcit Date: Thu, 24 Jul 2014 21:56:04 +0200 Subject: use directly MOBIClass --- inc/poche/Routing.class.php | 3 + inc/poche/WallabagEBooks.class.php | 166 +++++++++++++++++-------------------- inc/poche/global.inc.php | 6 +- 3 files changed, 80 insertions(+), 95 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php index e01d8129..83eabf19 100644 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php @@ -112,12 +112,15 @@ class Routing $this->wallabag->deleteUser($_POST['password4deletinguser']); } elseif (isset($_GET['epub'])) { $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['value']); + $epub->prepareData(); $epub->produceEpub(); } elseif (isset($_GET['mobi'])) { $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); + $mobi->prepareData(); $mobi->produceMobi(); } elseif (isset($_GET['pdf'])) { $pdf = new WallabagPDF($this->wallabag, $_GET['method'], $_GET['value']); + $pdf->prepareData(); $pdf->producePDF(); } elseif (isset($_GET['import'])) { $import = $this->wallabag->import(); diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index 14774425..deaf57e2 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -30,34 +30,35 @@ class WallabagEBooks case 'id': $entryID = filter_var($this->value, FILTER_SANITIZE_NUMBER_INT); $entry = $this->wallabag->store->retrieveOneById($entryID, $this->wallabag->user->getId()); - $entries = array($entry); - $bookTitle = $entry['title']; - $bookFileName = substr($bookTitle, 0, 200); + $this->entries = array($entry); + $this->bookTitle = $entry['title']; + $this->bookFileName = substr($this->bookTitle, 0, 200); break; case 'all': - $entries = $this->wallabag->store->retrieveAll($this->wallabag->user->getId()); - $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')); + $this->entries = $this->wallabag->store->retrieveAll($this->wallabag->user->getId()); + $this->bookTitle = sprintf(_('All my articles on '), date(_('d.m.y'))); #translatable because each country has it's own date format system + $this->bookFileName = _('Allarticles') . date(_('dmY')); break; case 'tag': $tag = filter_var($this->value, FILTER_SANITIZE_STRING); $tags_id = $this->wallabag->store->retrieveAllTags($this->wallabag->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->wallabag->store->retrieveEntriesByTag($tag_id, $this->wallabag->user->getId()); - $bookTitle = sprintf(_('Articles tagged %s'), $tag); - $bookFileName = substr(sprintf(_('Tag %s'), $tag), 0, 200); + $this->entries = $this->wallabag->store->retrieveEntriesByTag($tag_id, $this->wallabag->user->getId()); + $this->bookTitle = sprintf(_('Articles tagged %s'), $tag); + $this->bookFileName = substr(sprintf(_('Tag %s'), $tag), 0, 200); break; case 'category': $category = filter_var($this->value, FILTER_SANITIZE_STRING); - $entries = $this->wallabag->store->getEntriesByView($category, $this->wallabag->user->getId()); - $bookTitle = sprintf(_('All articles in category %s'), $category); - $bookFileName = substr(sprintf(_('Category %s'), $category), 0, 200); + $this->entries = $this->wallabag->store->getEntriesByView($category, $this->wallabag->user->getId()); + $this->bookTitle = sprintf(_('All articles in category %s'), $category); + $this->bookFileName = substr(sprintf(_('Category %s'), $category), 0, 200); break; case 'search': $search = filter_var($this->value, FILTER_SANITIZE_STRING); - $entries = $this->store->search($search, $this->wallabag->user->getId()); - $bookTitle = sprintf(_('All articles for search %s'), $search); - $bookFileName = substr(sprintf(_('Search %s'), $search), 0, 200); + Tools::logm($search); + $this->entries = $this->wallabag->store->search($search, $this->wallabag->user->getId()); + $this->bookTitle = sprintf(_('All articles for search %s'), $search); + $this->bookFileName = substr(sprintf(_('Search %s'), $search), 0, 200); break; case 'default': die(_('Uh, there is a problem while generating epub.')); @@ -94,7 +95,7 @@ class WallabagEpub extends WallabagEBooks $log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL()); $log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL()); - $book->setTitle($bookTitle); + $book->setTitle($this->bookTitle); $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")); @@ -111,7 +112,7 @@ class WallabagEpub extends WallabagEBooks $log->logLine("Add Cover"); - $fullTitle = "

" . $bookTitle . "

\n"; + $fullTitle = "

" . $this->bookTitle . "

\n"; $book->setCoverImage("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png", $fullTitle); @@ -122,7 +123,7 @@ class WallabagEpub extends WallabagEBooks $book->buildTOC(); - foreach ($entries as $entry) { //set tags as subjects + foreach ($this->entries as $entry) { //set tags as subjects $tags = $this->wallabag->store->retrieveTagsByEntry($entry['id']); foreach ($tags as $tag) { $book->setSubject($tag['value']); @@ -139,97 +140,82 @@ class WallabagEpub extends WallabagEBooks $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n" . $bookEnd); // log generation } $book->finalize(); - $zipData = $book->sendBook($bookFileName); + $zipData = $book->sendBook($this->bookFileName); } } class WallabagMobi extends WallabagEBooks { /** - * Adapted from News2Kindle - * @author Jakub Westfalewski - * + * MOBI Class + * @author Sander Kromwijk */ - public function produceMobi() + public function produceMobi($send = FALSE) { - $storage = new Storage('static'); - $this->prepareData(); - foreach ($entries as $i => $item) { - $content = $item['content']; - $images = new Images($storage, $content); - $content = $images->convert(); - $storage->add_content - ( - md5($item['title']), - mb_convert_encoding($item['title'], 'HTML-ENTITIES', 'utf-8'), - $content, - $item['url']], - "" - ); - } - $articles = $storage->get_contents(); - $toc = array(); - $articles_count = count($articles); - - foreach($articles as $article){ - if(array_key_exists($article->website->title, $toc)){ - $toc[$article->website->title]->articles[] = $article; - }else{ - $toc[$article->website->title] = (object)array( - 'articles' => array($article), - 'title' => $article->website->title, - 'streamId' => $article->website->streamId, - 'url' => $article->website->htmlUrl, - ); - } - } - - $mobi = new MOBI(); - $mobi->setData($content); - $mobi->setOptions(array( - 'title' => 'Articles from '.date('Y-m-d'), - 'author' => 'wallabag', - 'subject' => 'Articles from '.date('Y-m-d'), - )); - $images = array(); - - //prepare images for mobi format - foreach ( $storage->info('images') as $n => $image ) - { - $images[$n] = new FileRecord(new Record(file_get_contents($storage->get_path() . $image))); + # Good try + $mobi = new MOBI(); + + $content = new MOBIFile(); + + $content->set("title", $this->bookTitle); + $content->set("author", "wallabag"); + + # introduction + //$content->appendChapterTitle("Cover"); + $content->appendParagraph('

' . _('Produced by wallabag with PHPMobi') . '

'. _('Please open an issue if you have trouble with the display of this E-Book on your device.') . '

'); + $content->appendImage(imagecreatefrompng("themes/baggy/img/apple-touch-icon-152.png")); + $content->appendPageBreak(); + + foreach ($this->entries as $item) { + $content->appendChapterTitle($item['title']); + $content->appendParagraph($item['content']); + $content->appendPageBreak(); } + $mobi->setContentProvider($content); - $mobi->setImages($images); - $mobi->save( $storage->get_path(FALSE) . 'articles-' . date('Y-m-d') . '.mobi'); - - $storage->clean(); - - if ($send) { - $files = glob($storage->get_path(FALSE).'*.mobi'); - $mail = new Send(KINDLEMAIL,MAIL); - foreach ( $files as $file_mobi ) - { - $mail->send( $file_mobi ); - } - // clean cache - foreach ( $files as $file_mobi ) - { - unlink( $file_mobi ); - } - } - } + $mobi->download($this->bookFileName.".mobi"); + } } class WallabagPDF extends WallabagEbooks { public function producePDF() { + //$this->prepareData(); $mpdf = new mPDF('c'); - $mpdf->WriteHTML($html); - $mpdf->Output(); - exit; + # intro + + $html = '

' . $this->bookTitle . '

'; + + foreach ($this->entries as $item) { + $html .= '

' . $item['title'] . '

'; + $html .= ''; + $html .= $item['content']; + } + + //$mpdf->h2toc = array('H1'=>0); + + # headers + $mpdf->SetHeader('{DATE j-m-Y}|{PAGENO}/{nb}|Produced with wallabag'); + $mpdf->SetFooter('{PAGENO}'); + + $mpdf->WriteHTML($html); + + # remove characters that make mpdf bug + $char_in = array('/', '.', ',', ':', '|'); + $pdfExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName . '.pdf')); + + $mpdf->Output('cache/' . $pdfExportName); + + header('Content-Disposition: attachment; filename="' . $pdfExportName . '"'); + + header('Content-Transfer-Encoding: base64'); + header('Content-Type: application/pdf'); + echo file_get_contents('cache/' . $pdfExportName); + + //exit; } } \ No newline at end of file diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php index 1542fbfa..182f721d 100755 --- a/inc/poche/global.inc.php +++ b/inc/poche/global.inc.php @@ -42,11 +42,7 @@ require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPub.php'; require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPubChapterSplitter.php'; # mobi library -require_once INCLUDES . '/3rdparty/libraries/send2kindle/send.php'; -require_once INCLUDES . '/3rdparty/libraries/send2kindle/images.php'; -require_once INCLUDES . '/3rdparty/libraries/send2kindle/storage.php'; -require_once INCLUDES . '/3rdparty/libraries/send2kindle/MOBIClass/MOBI.php'; -require_once INCLUDES . '/3rdparty/libraries/send2kindle/utils.php'; +require_once INCLUDES . '/3rdparty/libraries/MOBIClass/MOBI.php'; # pdf library require_once INCLUDES . '/3rdparty/libraries/mpdf/mpdf.php'; -- cgit v1.2.3 From deab6280d3cbe3f8d001ff5214d36399653e3027 Mon Sep 17 00:00:00 2001 From: tcit Date: Fri, 25 Jul 2014 00:33:19 +0200 Subject: mobi (not tested on actual device) and pdf working --- inc/poche/WallabagEBooks.class.php | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index deaf57e2..2b18b718 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -36,7 +36,7 @@ class WallabagEBooks break; case 'all': $this->entries = $this->wallabag->store->retrieveAll($this->wallabag->user->getId()); - $this->bookTitle = sprintf(_('All my articles on '), date(_('d.m.y'))); #translatable because each country has it's own date format system + $this->bookTitle = sprintf(_('All my articles on %s'), date(_('d.m.y'))); #translatable because each country has it's own date format system $this->bookFileName = _('Allarticles') . date(_('dmY')); break; case 'tag': @@ -154,17 +154,17 @@ class WallabagMobi extends WallabagEBooks public function produceMobi($send = FALSE) { - # Good try $mobi = new MOBI(); $content = new MOBIFile(); $content->set("title", $this->bookTitle); $content->set("author", "wallabag"); + $content->set("subject", $this->bookTitle); # introduction //$content->appendChapterTitle("Cover"); - $content->appendParagraph('

' . _('Produced by wallabag with PHPMobi') . '

'. _('Please open an issue if you have trouble with the display of this E-Book on your device.') . '

'); + $content->appendParagraph('

' . _('Produced by wallabag with PHPMobi') . '

'. _('Please open an issue if you have trouble with the display of this E-Book on your device.') . '

'); $content->appendImage(imagecreatefrompng("themes/baggy/img/apple-touch-icon-152.png")); $content->appendPageBreak(); @@ -183,20 +183,25 @@ class WallabagPDF extends WallabagEbooks { public function producePDF() { - //$this->prepareData(); $mpdf = new mPDF('c'); # intro - $html = '

' . $this->bookTitle . '

'; + $html = '

' . $this->bookTitle . '

+

' . _('Produced by wallabag with mPDF') . '

+

'. _('Please open an issue if you have trouble with the display of this E-Book on your device.') . '

+
'; + $html .= ''; + $i = 1; foreach ($this->entries as $item) { - $html .= '

' . $item['title'] . '

'; + $html .= '

' . $item['title'] . '

'; $html .= ''; $html .= $item['content']; + $html .= ''; + $i = $i+1; } - //$mpdf->h2toc = array('H1'=>0); # headers $mpdf->SetHeader('{DATE j-m-Y}|{PAGENO}/{nb}|Produced with wallabag'); @@ -207,6 +212,13 @@ class WallabagPDF extends WallabagEbooks # remove characters that make mpdf bug $char_in = array('/', '.', ',', ':', '|'); $pdfExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName . '.pdf')); + + # index + $html = '

Index

+ + '; + + $mpdf->WriteHTML($html); $mpdf->Output('cache/' . $pdfExportName); -- cgit v1.2.3 From dc59f164a94ce2ab9e3165aa0090acff8a352493 Mon Sep 17 00:00:00 2001 From: tcit Date: Fri, 25 Jul 2014 01:33:31 +0200 Subject: send2kindle --- inc/poche/Routing.class.php | 4 +++ inc/poche/WallabagEBooks.class.php | 59 +++++++++++++++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 4 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php index 83eabf19..ec33432c 100644 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php @@ -118,6 +118,10 @@ class Routing $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); $mobi->prepareData(); $mobi->produceMobi(); + } elseif (isset($_GET['send2kindle'])) { + $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); + $mobi->prepareData(); + $mobi->produceMobi(TRUE); } elseif (isset($_GET['pdf'])) { $pdf = new WallabagPDF($this->wallabag, $_GET['method'], $_GET['value']); $pdf->prepareData(); diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index 2b18b718..a12befa8 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -151,19 +151,21 @@ class WallabagMobi extends WallabagEBooks * @author Sander Kromwijk */ - public function produceMobi($send = FALSE) + private $_kindle_email; + + public function produceMobi($sendByMail = FALSE) { $mobi = new MOBI(); - $content = new MOBIFile(); + + $messages = new Messages(); // for later $content->set("title", $this->bookTitle); $content->set("author", "wallabag"); $content->set("subject", $this->bookTitle); # introduction - //$content->appendChapterTitle("Cover"); $content->appendParagraph('

' . _('Produced by wallabag with PHPMobi') . '

'. _('Please open an issue if you have trouble with the display of this E-Book on your device.') . '

'); $content->appendImage(imagecreatefrompng("themes/baggy/img/apple-touch-icon-152.png")); $content->appendPageBreak(); @@ -175,7 +177,56 @@ class WallabagMobi extends WallabagEBooks } $mobi->setContentProvider($content); - $mobi->download($this->bookFileName.".mobi"); + if (!$sendByMail) { + // we offer file to download + $mobi->download($this->bookFileName.'.mobi'); + } + else { + // we send file to kindle + + $char_in = array('/', '.', ',', ':', '|'); # we sanitize filename to avoid conflicts with special characters (for instance, / goes for a directory) + $mobiExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName . '.mobi')); + + $file = 'cache/' . $mobiExportName; + $mobi->save($file); + + $file_size = filesize($file); + $filename = basename($file); + $handle = fopen($file, "r"); + $content = fread($handle, $file_size); + fclose($handle); + $content = chunk_split(base64_encode($content)); + + $uid = md5(uniqid(time())); + + //generate header for mail + $header = "From: wallabag <". $this->wallabag->user->email .">\r\n"; + $header .= "MIME-Version: 1.0\r\n"; + $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; + $header .= "This is a multi-part message in MIME format.\r\n"; + $header .= "--".$uid."\r\n"; + $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; + $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; + $header .= "send via wallabag\r\n\r\n"; + $header .= "--".$uid."\r\n"; + $header .= "Content-Type: application/x-mobipocket-ebook; name=\"".$filename."\"\r\n"; + $header .= "Content-Transfer-Encoding: base64\r\n"; + $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; + $header .= $content."\r\n\r\n"; + $header .= "--".$uid."--"; + + # trying to get the kindle email adress + if ($this->wallabag->user->getConfigValue('kindleemail')) + { + #do a try...exeption here + mail( $this->wallabag->user->getConfigValue('kindleemail'), '[wallabag] ' . $this->bookTitle, "", $header ); + $messages->add('s', _('The email has been sent to your kindle !')); + } + else + { + $messages->add('e', _('You didn\'t set your kindle\'s email adress !')); + } + } } } -- cgit v1.2.3 From d49446ff98044bdaf19f06d72c94d513cbbabcec Mon Sep 17 00:00:00 2001 From: tcit Date: Fri, 25 Jul 2014 01:38:28 +0200 Subject: bug with extension in the filename --- inc/poche/WallabagEBooks.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index a12befa8..5f42308e 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -185,7 +185,7 @@ class WallabagMobi extends WallabagEBooks // we send file to kindle $char_in = array('/', '.', ',', ':', '|'); # we sanitize filename to avoid conflicts with special characters (for instance, / goes for a directory) - $mobiExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName . '.mobi')); + $mobiExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName)) . '.mobi'; $file = 'cache/' . $mobiExportName; $mobi->save($file); -- cgit v1.2.3 From f8c37985224313533111e5b1d78b5a20eeff8b04 Mon Sep 17 00:00:00 2001 From: tcit Date: Sat, 26 Jul 2014 11:52:43 +0200 Subject: little better --- inc/poche/WallabagEBooks.class.php | 76 ++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 23 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index 5f42308e..906a2247 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -16,6 +16,7 @@ class WallabagEBooks protected $entries; protected $bookTitle; protected $bookFileName; + protected $author = 'wallabag'; public function __construct(Poche $wallabag, $method, $value) { @@ -33,11 +34,14 @@ class WallabagEBooks $this->entries = array($entry); $this->bookTitle = $entry['title']; $this->bookFileName = substr($this->bookTitle, 0, 200); + $this->author = preg_replace('#^w{3}.#', '', Tools::getdomain($entry["url"])); # if only one article, set author to domain name (we strip the eventual www part) + Tools::logm('Producing ebook from article ' . $this->bookTitle); break; case 'all': $this->entries = $this->wallabag->store->retrieveAll($this->wallabag->user->getId()); $this->bookTitle = sprintf(_('All my articles on %s'), date(_('d.m.y'))); #translatable because each country has it's own date format system $this->bookFileName = _('Allarticles') . date(_('dmY')); + Tools::logm('Producing ebook from all articles'); break; case 'tag': $tag = filter_var($this->value, FILTER_SANITIZE_STRING); @@ -46,12 +50,14 @@ class WallabagEBooks $this->entries = $this->wallabag->store->retrieveEntriesByTag($tag_id, $this->wallabag->user->getId()); $this->bookTitle = sprintf(_('Articles tagged %s'), $tag); $this->bookFileName = substr(sprintf(_('Tag %s'), $tag), 0, 200); + Tools::logm('Producing ebook from tag ' . $tag); break; case 'category': $category = filter_var($this->value, FILTER_SANITIZE_STRING); $this->entries = $this->wallabag->store->getEntriesByView($category, $this->wallabag->user->getId()); $this->bookTitle = sprintf(_('All articles in category %s'), $category); $this->bookFileName = substr(sprintf(_('Category %s'), $category), 0, 200); + Tools::logm('Producing ebook from category ' . $category); break; case 'search': $search = filter_var($this->value, FILTER_SANITIZE_STRING); @@ -59,9 +65,10 @@ class WallabagEBooks $this->entries = $this->wallabag->store->search($search, $this->wallabag->user->getId()); $this->bookTitle = sprintf(_('All articles for search %s'), $search); $this->bookFileName = substr(sprintf(_('Search %s'), $search), 0, 200); + Tools::logm('Producing ebook from search ' . $search); break; case 'default': - die(_('Uh, there is a problem while generating epub.')); + die(_('Uh, there is a problem while generating eBook.')); } } } @@ -73,12 +80,13 @@ class WallabagEpub extends WallabagEBooks */ public function produceEpub() { + Tools::logm('Starting to produce ePub 3 file'); $content_start = "\n" . "\n" . "" . "\n" - . "wallabag articles book\n" + . "" . _("wallabag articles book") . "\n" . "\n" . "\n"; @@ -95,11 +103,13 @@ class WallabagEpub extends WallabagEBooks $log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL()); $log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL()); + Tools::logm('Filling metadata for ePub...'); + $book->setTitle($this->bookTitle); $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->setAuthor($this->author,$this->author); $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. @@ -123,6 +133,8 @@ class WallabagEpub extends WallabagEBooks $book->buildTOC(); + Tools::logm('Adding actual content...'); + foreach ($this->entries as $entry) { //set tags as subjects $tags = $this->wallabag->store->retrieveTagsByEntry($entry['id']); foreach ($tags as $tag) { @@ -138,9 +150,11 @@ class WallabagEpub extends WallabagEBooks if (DEBUG_POCHE) { $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n" . $bookEnd); // log generation + Tools::logm('Production log available in produced file'); } $book->finalize(); $zipData = $book->sendBook($this->bookFileName); + Tools::logm('Ebook produced'); } } @@ -151,18 +165,19 @@ class WallabagMobi extends WallabagEBooks * @author Sander Kromwijk */ - private $_kindle_email; - public function produceMobi($sendByMail = FALSE) { + Tools::logm('Starting to produce Mobi file'); $mobi = new MOBI(); $content = new MOBIFile(); $messages = new Messages(); // for later - + + Tools::logm('Filling metadata for Mobi...'); + $content->set("title", $this->bookTitle); - $content->set("author", "wallabag"); + $content->set("author", $this->author); $content->set("subject", $this->bookTitle); # introduction @@ -170,6 +185,8 @@ class WallabagMobi extends WallabagEBooks $content->appendImage(imagecreatefrompng("themes/baggy/img/apple-touch-icon-152.png")); $content->appendPageBreak(); + Tools::logm('Adding actual content...'); + foreach ($this->entries as $item) { $content->appendChapterTitle($item['title']); $content->appendParagraph($item['content']); @@ -180,10 +197,19 @@ class WallabagMobi extends WallabagEBooks if (!$sendByMail) { // we offer file to download $mobi->download($this->bookFileName.'.mobi'); + Tools::logm('Mobi file produced'); } else { // we send file to kindle + Tools::logm('Preparing to send file by email'); + + $error = FALSE; + # testing Mail function + if (!function_exists('mail')) { + $error = _('Mail function is unavailable'); + } + $char_in = array('/', '.', ',', ':', '|'); # we sanitize filename to avoid conflicts with special characters (for instance, / goes for a directory) $mobiExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName)) . '.mobi'; @@ -216,15 +242,17 @@ class WallabagMobi extends WallabagEBooks $header .= "--".$uid."--"; # trying to get the kindle email adress - if ($this->wallabag->user->getConfigValue('kindleemail')) + if (!$this->wallabag->user->getConfigValue('kindleemail')) { - #do a try...exeption here - mail( $this->wallabag->user->getConfigValue('kindleemail'), '[wallabag] ' . $this->bookTitle, "", $header ); - $messages->add('s', _('The email has been sent to your kindle !')); + $error = _('You didn\'t set your kindle\'s email adress !'); } - else - { - $messages->add('e', _('You didn\'t set your kindle\'s email adress !')); + if (!$error) { + mail($this->wallabag->user->getConfigValue('kindleemail'), '[wallabag] ' . $this->bookTitle, "", $header ); + $messages->add('s', _('The email has been sent to your kindle !')); + Tools::logm('Email sent'); + } else { + $messages->add('e', $error); + Tools::logm($error); } } } @@ -236,8 +264,15 @@ class WallabagPDF extends WallabagEbooks { $mpdf = new mPDF('c'); - # intro + Tools::logm('Starting to produce PDF file'); + Tools::logm('Filling metadata for PDF...'); + + # headers + $mpdf->SetHeader('{DATE j-m-Y}|{PAGENO}/{nb}|Produced with wallabag'); + $mpdf->SetFooter('{PAGENO}'); + + # intro $html = '

' . $this->bookTitle . '

' . _('Produced by wallabag with mPDF') . '

'. _('Please open an issue if you have trouble with the display of this E-Book on your device.') . '

@@ -245,6 +280,7 @@ class WallabagPDF extends WallabagEbooks $html .= ''; $i = 1; + Tools::logm('Adding actual content...'); foreach ($this->entries as $item) { $html .= '

' . $item['title'] . '

'; $html .= ''; @@ -252,17 +288,12 @@ class WallabagPDF extends WallabagEbooks $html .= ''; $i = $i+1; } - - - # headers - $mpdf->SetHeader('{DATE j-m-Y}|{PAGENO}/{nb}|Produced with wallabag'); - $mpdf->SetFooter('{PAGENO}'); $mpdf->WriteHTML($html); # remove characters that make mpdf bug $char_in = array('/', '.', ',', ':', '|'); - $pdfExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName . '.pdf')); + $pdfExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName . '.pdf')); # maybe someone can make a proper regex of this ? # index $html = '

Index

@@ -278,7 +309,6 @@ class WallabagPDF extends WallabagEbooks header('Content-Transfer-Encoding: base64'); header('Content-Type: application/pdf'); echo file_get_contents('cache/' . $pdfExportName); - - //exit; + Tools::logm('PDF file produced'); } } \ No newline at end of file -- cgit v1.2.3 From ab86a5124ae4a23cc37dc78ccfbd73089b3248d8 Mon Sep 17 00:00:00 2001 From: tcit Date: Sat, 26 Jul 2014 13:04:12 +0200 Subject: more translations --- inc/poche/WallabagEBooks.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index 906a2247..80aa7e43 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -55,7 +55,7 @@ class WallabagEBooks case 'category': $category = filter_var($this->value, FILTER_SANITIZE_STRING); $this->entries = $this->wallabag->store->getEntriesByView($category, $this->wallabag->user->getId()); - $this->bookTitle = sprintf(_('All articles in category %s'), $category); + $this->bookTitle = sprintf(_('Articles in category %s'), $category); $this->bookFileName = substr(sprintf(_('Category %s'), $category), 0, 200); Tools::logm('Producing ebook from category ' . $category); break; @@ -63,7 +63,7 @@ class WallabagEBooks $search = filter_var($this->value, FILTER_SANITIZE_STRING); Tools::logm($search); $this->entries = $this->wallabag->store->search($search, $this->wallabag->user->getId()); - $this->bookTitle = sprintf(_('All articles for search %s'), $search); + $this->bookTitle = sprintf(_('Articles for search %s'), $search); $this->bookFileName = substr(sprintf(_('Search %s'), $search), 0, 200); Tools::logm('Producing ebook from search ' . $search); break; @@ -207,7 +207,7 @@ class WallabagMobi extends WallabagEBooks $error = FALSE; # testing Mail function if (!function_exists('mail')) { - $error = _('Mail function is unavailable'); + $error = _("Mail function is disabled. You can't send emails from your server"); } $char_in = array('/', '.', ',', ':', '|'); # we sanitize filename to avoid conflicts with special characters (for instance, / goes for a directory) @@ -244,7 +244,7 @@ class WallabagMobi extends WallabagEBooks # trying to get the kindle email adress if (!$this->wallabag->user->getConfigValue('kindleemail')) { - $error = _('You didn\'t set your kindle\'s email adress !'); + $error = _("You didn't set your kindle's email adress !"); } if (!$error) { mail($this->wallabag->user->getConfigValue('kindleemail'), '[wallabag] ' . $this->bookTitle, "", $header ); -- cgit v1.2.3 From 824f8c45edb20e27221e92805b0090f1768a2756 Mon Sep 17 00:00:00 2001 From: tcit Date: Sat, 27 Sep 2014 19:34:17 +0200 Subject: changed mpdf with tcpdf --- inc/poche/WallabagEBooks.class.php | 56 ++++++++++++++++---------------------- inc/poche/global.inc.php | 3 +- 2 files changed, 26 insertions(+), 33 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index 80aa7e43..d77fe0d8 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -262,53 +262,45 @@ class WallabagPDF extends WallabagEbooks { public function producePDF() { - $mpdf = new mPDF('c'); Tools::logm('Starting to produce PDF file'); - Tools::logm('Filling metadata for PDF...'); - - # headers - $mpdf->SetHeader('{DATE j-m-Y}|{PAGENO}/{nb}|Produced with wallabag'); - $mpdf->SetFooter('{PAGENO}'); + $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); - # intro - $html = '

' . $this->bookTitle . '

-

' . _('Produced by wallabag with mPDF') . '

+ Tools::logm('Filling metadata for PDF...'); + $pdf->SetCreator(PDF_CREATOR); + $pdf->SetAuthor(''); + $pdf->SetTitle($this->bookTitle); + $pdf->SetSubject('TCPDF Tutorial'); + $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); + + Tools::logm('Adding introduction...'); + $pdf->AddPage(); + $intro = '

' . $this->bookTitle . '

+

' . _('Produced by wallabag with tcpdf') . '

'. _('Please open an issue if you have trouble with the display of this E-Book on your device.') . '

'; - $html .= ''; - $i = 1; + + $pdf->writeHTMLCell(0, 0, '', '', $intro, 0, 1, 0, true, '', true); + + $i = 1; Tools::logm('Adding actual content...'); foreach ($this->entries as $item) { - $html .= '

' . $item['title'] . '

'; - $html .= ''; + $pdf->AddPage(); + $html = '

' . $item['title'] . '

'; $html .= $item['content']; - $html .= ''; + $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); $i = $i+1; } - - $mpdf->WriteHTML($html); - # remove characters that make mpdf bug - $char_in = array('/', '.', ',', ':', '|'); - $pdfExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName . '.pdf')); # maybe someone can make a proper regex of this ? + // set image scale factor + $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); - # index - $html = '

Index

- - '; + + - $mpdf->WriteHTML($html); - - $mpdf->Output('cache/' . $pdfExportName); - - header('Content-Disposition: attachment; filename="' . $pdfExportName . '"'); + $pdf->Output($this->bookFileName, 'I'); - header('Content-Transfer-Encoding: base64'); - header('Content-Type: application/pdf'); - echo file_get_contents('cache/' . $pdfExportName); - Tools::logm('PDF file produced'); } } \ No newline at end of file diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php index 182f721d..728528f8 100755 --- a/inc/poche/global.inc.php +++ b/inc/poche/global.inc.php @@ -45,7 +45,8 @@ require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPubChapterSplitter.php'; require_once INCLUDES . '/3rdparty/libraries/MOBIClass/MOBI.php'; # pdf library -require_once INCLUDES . '/3rdparty/libraries/mpdf/mpdf.php'; +#require_once INCLUDES . '/3rdparty/libraries/mpdf/mpdf.php'; +require_once INCLUDES . '/3rdparty/libraries/tcpdf/tcpdf.php'; # system configuration; database credentials et caetera require_once INCLUDES . '/poche/config.inc.php'; -- cgit v1.2.3 From a1b31d93b69c78db0ebc0635b619b02ee7392957 Mon Sep 17 00:00:00 2001 From: tcit Date: Sat, 27 Sep 2014 19:42:37 +0200 Subject: get up to date --- inc/poche/Routing.class.php | 92 ++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 52 deletions(-) mode change 100644 => 100755 inc/poche/Routing.class.php (limited to 'inc/poche') diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php old mode 100644 new mode 100755 index ec33432c..0b373058 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php @@ -98,62 +98,50 @@ class Routing private function _launchAction() { if (isset($_GET['login'])) { - // hello you - $this->wallabag->login($this->referer); - } elseif (isset($_GET['logout'])) { - // see you soon ! - $this->wallabag->logout(); - } elseif (isset($_GET['config'])) { - // update password - $this->wallabag->updatePassword($_POST['password'], $_POST['password_repeat']); - } elseif (isset($_GET['newuser'])) { - $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser']); - } elseif (isset($_GET['deluser'])) { - $this->wallabag->deleteUser($_POST['password4deletinguser']); - } elseif (isset($_GET['epub'])) { - $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['value']); - $epub->prepareData(); - $epub->produceEpub(); - } elseif (isset($_GET['mobi'])) { - $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); - $mobi->prepareData(); - $mobi->produceMobi(); - } elseif (isset($_GET['send2kindle'])) { - $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); - $mobi->prepareData(); - $mobi->produceMobi(TRUE); - } elseif (isset($_GET['pdf'])) { - $pdf = new WallabagPDF($this->wallabag, $_GET['method'], $_GET['value']); - $pdf->prepareData(); - $pdf->producePDF(); - } elseif (isset($_GET['import'])) { - $import = $this->wallabag->import(); - $tplVars = array_merge($this->vars, $import); - } elseif (isset($_GET['download'])) { - Tools::downloadDb(); - } elseif (isset($_GET['empty-cache'])) { - Tools::emptyCache(); - } elseif (isset($_GET['export'])) { - $this->wallabag->export(); - } elseif (isset($_GET['updatetheme'])) { - $this->wallabag->tpl->updateTheme($_POST['theme']); - } elseif (isset($_GET['updatelanguage'])) { - $this->wallabag->language->updateLanguage($_POST['language']); - } elseif (isset($_GET['uploadfile'])) { - $this->wallabag->uploadFile(); - } elseif (isset($_GET['feed'])) { - if (isset($_GET['action']) && $_GET['action'] == 'generate') { + // hello to you + $this->wallabag->login($this->referer); + } elseif (isset($_GET['feed']) && isset($_GET['user_id'])) { + $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0); + $this->wallabag->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type']); + } + + //allowed ONLY to logged in user + if (\Session::isLogged() === true) + { + if (isset($_GET['logout'])) { + // see you soon ! + $this->wallabag->logout(); + } elseif (isset($_GET['config'])) { + // update password + $this->wallabag->updatePassword($_POST['password'], $_POST['password_repeat']); + } elseif (isset($_GET['newuser'])) { + $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser']); + } elseif (isset($_GET['deluser'])) { + $this->wallabag->deleteUser($_POST['password4deletinguser']); + } elseif (isset($_GET['epub'])) { + $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['id'], $_GET['value']); + $epub->run(); + } elseif (isset($_GET['import'])) { + $import = $this->wallabag->import(); + $tplVars = array_merge($this->vars, $import); + } elseif (isset($_GET['empty-cache'])) { + Tools::emptyCache(); + } elseif (isset($_GET['export'])) { + $this->wallabag->export(); + } elseif (isset($_GET['updatetheme'])) { + $this->wallabag->tpl->updateTheme($_POST['theme']); + } elseif (isset($_GET['updatelanguage'])) { + $this->wallabag->language->updateLanguage($_POST['language']); + } elseif (isset($_GET['uploadfile'])) { + $this->wallabag->uploadFile(); + } elseif (isset($_GET['feed']) && isset($_GET['action']) && $_GET['action'] == 'generate') { $this->wallabag->updateToken(); } - else { - $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0); - $this->wallabag->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type']); + elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) { + $plainUrl = new Url(base64_encode($_GET['plainurl'])); + $this->wallabag->action('add', $plainUrl); } } - elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) { - $plainUrl = new Url(base64_encode($_GET['plainurl'])); - $this->wallabag->action('add', $plainUrl); - } } public function _render($file, $vars) -- cgit v1.2.3 From 6fc2c29daaadcd5075aec6bde2fd0f94274367a8 Mon Sep 17 00:00:00 2001 From: tcit Date: Sat, 27 Sep 2014 19:47:50 +0200 Subject: revert routing bad deleting --- inc/poche/Routing.class.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php index 0b373058..bd61a0b3 100755 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php @@ -119,8 +119,21 @@ class Routing } elseif (isset($_GET['deluser'])) { $this->wallabag->deleteUser($_POST['password4deletinguser']); } elseif (isset($_GET['epub'])) { - $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['id'], $_GET['value']); - $epub->run(); + $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['value']); + $epub->prepareData(); + $epub->produceEpub(); + } elseif (isset($_GET['mobi'])) { + $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); + $mobi->prepareData(); + $mobi->produceMobi(); + } elseif (isset($_GET['send2kindle'])) { + $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); + $mobi->prepareData(); + $mobi->produceMobi(TRUE); + } elseif (isset($_GET['pdf'])) { + $pdf = new WallabagPDF($this->wallabag, $_GET['method'], $_GET['value']); + $pdf->prepareData(); + $pdf->producePDF(); } elseif (isset($_GET['import'])) { $import = $this->wallabag->import(); $tplVars = array_merge($this->vars, $import); -- cgit v1.2.3 From fa926fb47c3d282c7662e4767923a5b7bd927a59 Mon Sep 17 00:00:00 2001 From: tcit Date: Sat, 27 Sep 2014 19:59:43 +0200 Subject: offering download for pdf file and comment in code --- inc/poche/WallabagEBooks.class.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index d77fe0d8..66569730 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -200,6 +200,9 @@ class WallabagMobi extends WallabagEBooks Tools::logm('Mobi file produced'); } else { + ## ## + # Not working yet !!! # + ## ## // we send file to kindle Tools::logm('Preparing to send file by email'); @@ -300,7 +303,7 @@ class WallabagPDF extends WallabagEbooks - $pdf->Output($this->bookFileName, 'I'); + $pdf->Output($this->bookFileName, 'FD'); } } \ No newline at end of file -- cgit v1.2.3 From b852df020c68ad6bc94df73cb1025c6b64ec10a6 Mon Sep 17 00:00:00 2001 From: tcit Date: Sun, 28 Sep 2014 12:18:47 +0200 Subject: add extension for pdf file --- inc/poche/WallabagEBooks.class.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index 66569730..9dc545df 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -299,11 +299,9 @@ class WallabagPDF extends WallabagEbooks // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); - - - $pdf->Output($this->bookFileName, 'FD'); + $pdf->Output($this->bookFileName . '.pdf', 'FD'); } } \ No newline at end of file -- cgit v1.2.3 From 9f86454b48dec3c9ecfee8da224112eef0f61441 Mon Sep 17 00:00:00 2001 From: tcit Date: Sun, 28 Sep 2014 17:20:35 +0200 Subject: deleting send to kindle function --- inc/poche/Routing.class.php | 4 --- inc/poche/WallabagEBooks.class.php | 69 +++----------------------------------- 2 files changed, 4 insertions(+), 69 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php index bd61a0b3..44b0e168 100755 --- a/inc/poche/Routing.class.php +++ b/inc/poche/Routing.class.php @@ -126,10 +126,6 @@ class Routing $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); $mobi->prepareData(); $mobi->produceMobi(); - } elseif (isset($_GET['send2kindle'])) { - $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); - $mobi->prepareData(); - $mobi->produceMobi(TRUE); } elseif (isset($_GET['pdf'])) { $pdf = new WallabagPDF($this->wallabag, $_GET['method'], $_GET['value']); $pdf->prepareData(); diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php index 9dc545df..2ddece61 100644 --- a/inc/poche/WallabagEBooks.class.php +++ b/inc/poche/WallabagEBooks.class.php @@ -165,7 +165,7 @@ class WallabagMobi extends WallabagEBooks * @author Sander Kromwijk */ - public function produceMobi($sendByMail = FALSE) + public function produceMobi() { Tools::logm('Starting to produce Mobi file'); @@ -194,70 +194,9 @@ class WallabagMobi extends WallabagEBooks } $mobi->setContentProvider($content); - if (!$sendByMail) { - // we offer file to download - $mobi->download($this->bookFileName.'.mobi'); - Tools::logm('Mobi file produced'); - } - else { - ## ## - # Not working yet !!! # - ## ## - // we send file to kindle - - Tools::logm('Preparing to send file by email'); - - $error = FALSE; - # testing Mail function - if (!function_exists('mail')) { - $error = _("Mail function is disabled. You can't send emails from your server"); - } - - $char_in = array('/', '.', ',', ':', '|'); # we sanitize filename to avoid conflicts with special characters (for instance, / goes for a directory) - $mobiExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName)) . '.mobi'; - - $file = 'cache/' . $mobiExportName; - $mobi->save($file); - - $file_size = filesize($file); - $filename = basename($file); - $handle = fopen($file, "r"); - $content = fread($handle, $file_size); - fclose($handle); - $content = chunk_split(base64_encode($content)); - - $uid = md5(uniqid(time())); - - //generate header for mail - $header = "From: wallabag <". $this->wallabag->user->email .">\r\n"; - $header .= "MIME-Version: 1.0\r\n"; - $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; - $header .= "This is a multi-part message in MIME format.\r\n"; - $header .= "--".$uid."\r\n"; - $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; - $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; - $header .= "send via wallabag\r\n\r\n"; - $header .= "--".$uid."\r\n"; - $header .= "Content-Type: application/x-mobipocket-ebook; name=\"".$filename."\"\r\n"; - $header .= "Content-Transfer-Encoding: base64\r\n"; - $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; - $header .= $content."\r\n\r\n"; - $header .= "--".$uid."--"; - - # trying to get the kindle email adress - if (!$this->wallabag->user->getConfigValue('kindleemail')) - { - $error = _("You didn't set your kindle's email adress !"); - } - if (!$error) { - mail($this->wallabag->user->getConfigValue('kindleemail'), '[wallabag] ' . $this->bookTitle, "", $header ); - $messages->add('s', _('The email has been sent to your kindle !')); - Tools::logm('Email sent'); - } else { - $messages->add('e', $error); - Tools::logm($error); - } - } + // we offer file to download + $mobi->download($this->bookFileName.'.mobi'); + Tools::logm('Mobi file produced'); } } -- cgit v1.2.3 From 5ea5310ab450035143e2f5637f9fa69773f7879b Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 14 Dec 2014 15:17:39 +0100 Subject: enable showing or not for epub/mobi/pdf export buttons --- inc/poche/config.inc.default.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'inc/poche') diff --git a/inc/poche/config.inc.default.php b/inc/poche/config.inc.default.php index 3eaee3a3..a159e713 100755 --- a/inc/poche/config.inc.default.php +++ b/inc/poche/config.inc.default.php @@ -52,6 +52,12 @@ @define ('FLATTRABLE', '1'); @define ('FLATTRED', '2'); @define ('CARROT', FALSE); + +// ebook +@define ('EPUB', TRUE); +@define ('MOBI', FALSE); +@define ('PDF', FALSE); + // display or not print link in article view @define ('SHOW_PRINTLINK', '1'); // display or not percent of read in article view. Affects only default theme. -- cgit v1.2.3