3 * wallabag, self hostable application allowing you to not miss any content anymore
6 * @author Nicolas LÅ“uillet <nicolas@loeuillet.org>
8 * @license http://opensource.org/licenses/MIT see COPYING file
18 protected $bookFileName;
20 public function __construct(Poche
$wallabag, $method, $value)
22 $this->wallabag
= $wallabag;
23 $this->method
= $method;
24 $this->value
= $value;
27 public function prepareData()
29 switch ($this->method
) {
31 $entryID = filter_var($this->value
, FILTER_SANITIZE_NUMBER_INT
);
32 $entry = $this->wallabag
->store
->retrieveOneById($entryID, $this->wallabag
->user
->getId());
33 $entries = array($entry);
34 $bookTitle = $entry['title'];
35 $bookFileName = substr($bookTitle, 0, 200);
38 $entries = $this->wallabag
->store
->retrieveAll($this->wallabag
->user
->getId());
39 $bookTitle = sprintf(_('All my articles on '), date(_('d.m.y'))); #translatable because each country has it's own date format system
40 $bookFileName = _('Allarticles') . date(_('dmY'));
43 $tag = filter_var($this->value
, FILTER_SANITIZE_STRING
);
44 $tags_id = $this->wallabag
->store
->retrieveAllTags($this->wallabag
->user
->getId(), $tag);
45 $tag_id = $tags_id[0]["id"]; // we take the first result, which is supposed to match perfectly. There must be a workaround.
46 $entries = $this->wallabag
->store
->retrieveEntriesByTag($tag_id, $this->wallabag
->user
->getId());
47 $bookTitle = sprintf(_('Articles tagged %s'), $tag);
48 $bookFileName = substr(sprintf(_('Tag %s'), $tag), 0, 200);
51 $category = filter_var($this->value
, FILTER_SANITIZE_STRING
);
52 $entries = $this->wallabag
->store
->getEntriesByView($category, $this->wallabag
->user
->getId());
53 $bookTitle = sprintf(_('All articles in category %s'), $category);
54 $bookFileName = substr(sprintf(_('Category %s'), $category), 0, 200);
57 $search = filter_var($this->value
, FILTER_SANITIZE_STRING
);
58 $entries = $this->store
->search($search, $this->wallabag
->user
->getId());
59 $bookTitle = sprintf(_('All articles for search %s'), $search);
60 $bookFileName = substr(sprintf(_('Search %s'), $search), 0, 200);
63 die(_('Uh, there is a problem while generating epub.'));
68 class WallabagEpub
extends WallabagEBooks
73 public function produceEpub()
76 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
77 . "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">\n"
79 . "<meta http-equiv=\"Default-Style\" content=\"text/html; charset=utf-8\" />\n"
80 . "<title>wallabag articles book</title>\n"
84 $bookEnd = "</body>\n</html>\n";
86 $log = new Logger("wallabag", TRUE);
89 $book = new EPub(EPub
::BOOK_VERSION_EPUB3
, DEBUG_POCHE
);
90 $log->logLine("new EPub()");
91 $log->logLine("EPub class version: " . EPub
::VERSION
);
92 $log->logLine("EPub Req. Zip version: " . EPub
::REQ_ZIP_VERSION
);
93 $log->logLine("Zip version: " . Zip
::VERSION
);
94 $log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL());
95 $log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL());
97 $book->setTitle($bookTitle);
98 $book->setIdentifier("http://$_SERVER[HTTP_HOST]", EPub
::IDENTIFIER_URI
); // Could also be the ISBN number, prefered for published books, or a UUID.
99 //$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.
100 $book->setDescription(_("Some articles saved on my wallabag"));
101 $book->setAuthor("wallabag", "wallabag");
102 $book->setPublisher("wallabag", "wallabag"); // I hope this is a non existant address :)
103 $book->setDate(time()); // Strictly not needed as the book date defaults to time().
104 //$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.
105 $book->setSourceURL("http://$_SERVER[HTTP_HOST]");
107 $book->addDublinCoreMetadata(DublinCore
::CONTRIBUTOR
, "PHP");
108 $book->addDublinCoreMetadata(DublinCore
::CONTRIBUTOR
, "wallabag");
110 $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";
112 $log->logLine("Add Cover");
114 $fullTitle = "<h1> " . $bookTitle . "</h1>\n";
116 $book->setCoverImage("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png", $fullTitle);
118 $cover = $content_start . '<div style="text-align:center;"><p>' . _('Produced by wallabag with PHPePub') . '</p><p>'. _('Please open <a href="https://github.com/wallabag/wallabag/issues" >an issue</a> if you have trouble with the display of this E-Book on your device.') . '</p></div>' . $bookEnd;
120 //$book->addChapter("Table of Contents", "TOC.xhtml", NULL, false, EPub::EXTERNAL_REF_IGNORE);
121 $book->addChapter("Notices", "Cover2.html", $cover);
125 foreach ($entries as $entry) { //set tags as subjects
126 $tags = $this->wallabag
->store
->retrieveTagsByEntry($entry['id']);
127 foreach ($tags as $tag) {
128 $book->setSubject($tag['value']);
131 $log->logLine("Set up parameters");
133 $chapter = $content_start . $entry['content'] . $bookEnd;
134 $book->addChapter($entry['title'], htmlspecialchars($entry['title']) . ".html", $chapter, true, EPub
::EXTERNAL_REF_ADD
);
135 $log->logLine("Added chapter " . $entry['title']);
139 $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n</pre>" . $bookEnd); // log generation
142 $zipData = $book->sendBook($bookFileName);
146 class WallabagMobi
extends WallabagEBooks
149 * Adapted from News2Kindle
150 * @author Jakub Westfalewski <jwest@jwest.pl>
154 public function produceMobi()
156 $storage = new Storage('static');
157 $this->prepareData();
158 foreach ($entries as $i => $item) {
159 $content = $item['content'];
160 $images = new Images($storage, $content);
161 $content = $images->convert();
162 $storage->add_content
165 mb_convert_encoding($item['title'], 'HTML-ENTITIES', 'utf-8'),
171 $articles = $storage->get_contents();
173 $articles_count = count($articles);
175 foreach($articles as $article){
176 if(array_key_exists($article->website
->title
, $toc)){
177 $toc[$article->website
->title
]->articles
[] = $article;
179 $toc[$article->website
->title
] = (object)array(
180 'articles' => array($article),
181 'title' => $article->website
->title
,
182 'streamId' => $article->website
->streamId
,
183 'url' => $article->website
->htmlUrl
,
189 $mobi->setData($content);
190 $mobi->setOptions(array(
191 'title' => 'Articles from '.date('Y-m-d'),
192 'author' => 'wallabag',
193 'subject' => 'Articles from '.date('Y-m-d'),
198 //prepare images for mobi format
199 foreach ( $storage->info('images') as $n => $image )
201 $images[$n] = new FileRecord(new Record(file_get_contents($storage->get_path() . $image)));
204 $mobi->setImages($images);
205 $mobi->save( $storage->get_path(FALSE) . 'articles-' . date('Y-m-d') . '.mobi');
210 $files = glob($storage->get_path(FALSE).'*.mobi');
211 $mail = new Send(KINDLEMAIL
,MAIL
);
212 foreach ( $files as $file_mobi )
214 $mail->send( $file_mobi );
217 foreach ( $files as $file_mobi )
219 unlink( $file_mobi );
225 class WallabagPDF
extends WallabagEbooks
227 public function producePDF()
229 $mpdf = new mPDF('c');
231 $mpdf->WriteHTML($html);