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 +++++++++++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 inc/poche/WallabagEBooks.class.php (limited to 'inc/poche/WallabagEBooks.class.php') 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 -- 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/WallabagEBooks.class.php | 166 +++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 90 deletions(-) (limited to 'inc/poche/WallabagEBooks.class.php') 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 -- 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/WallabagEBooks.class.php') 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/WallabagEBooks.class.php | 59 +++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-) (limited to 'inc/poche/WallabagEBooks.class.php') 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/WallabagEBooks.class.php') 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/WallabagEBooks.class.php') 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/WallabagEBooks.class.php') 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 ++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 32 deletions(-) (limited to 'inc/poche/WallabagEBooks.class.php') 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 -- 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/WallabagEBooks.class.php') 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/WallabagEBooks.class.php') 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/WallabagEBooks.class.php | 69 +++----------------------------------- 1 file changed, 4 insertions(+), 65 deletions(-) (limited to 'inc/poche/WallabagEBooks.class.php') 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