X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=inc%2Fpoche%2FWallabagEpub.class.php;h=1477442570adefc20a79a53eac4ccd4d151abfe6;hb=4188f38ad56d7ba2ea46e94403f305243514f80c;hp=9c4d3566d558fdcc7207f6b20720e4ef1a66ee7f;hpb=2b58426b2d4a7f1585d5d7667c0a4fbea4cd29dd;p=github%2Fwallabag%2Fwallabag.git 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