aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/WallabagEpub.class.php
diff options
context:
space:
mode:
authortcit <tcit@tcit.fr>2014-07-24 15:49:36 +0200
committertcit <tcit@tcit.fr>2014-07-24 15:49:36 +0200
commit4188f38ad56d7ba2ea46e94403f305243514f80c (patch)
treef357ddbd0d846ebae0ecf5d2ab00d6b7dd6eb8d5 /inc/poche/WallabagEpub.class.php
parent2b58426b2d4a7f1585d5d7667c0a4fbea4cd29dd (diff)
downloadwallabag-4188f38ad56d7ba2ea46e94403f305243514f80c.tar.gz
wallabag-4188f38ad56d7ba2ea46e94403f305243514f80c.tar.zst
wallabag-4188f38ad56d7ba2ea46e94403f305243514f80c.zip
add pdf and mobi libraries
Diffstat (limited to 'inc/poche/WallabagEpub.class.php')
-rw-r--r--inc/poche/WallabagEpub.class.php114
1 files changed, 107 insertions, 7 deletions
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 @@
8 * @license http://opensource.org/licenses/MIT see COPYING file 8 * @license http://opensource.org/licenses/MIT see COPYING file
9 */ 9 */
10 10
11class WallabagEpub 11class WallabagEBooks
12{ 12{
13 protected $wallabag; 13 protected $wallabag;
14 protected $method; 14 protected $method;
15 protected $value; 15 protected $value;
16 protected $entries;
17 protected $bookTitle;
18 protected $bookFileName;
16 19
17 public function __construct(Poche $wallabag, $method, $value) 20 public function __construct(Poche $wallabag, $method, $value)
18 { 21 {
@@ -21,10 +24,7 @@ class WallabagEpub
21 $this->value = $value; 24 $this->value = $value;
22 } 25 }
23 26
24 /** 27 public function prepareData()
25 * handle ePub
26 */
27 public function run()
28 { 28 {
29 switch ($this->method) { 29 switch ($this->method) {
30 case 'id': 30 case 'id':
@@ -62,7 +62,16 @@ class WallabagEpub
62 case 'default': 62 case 'default':
63 die(_('Uh, there is a problem while generating epub.')); 63 die(_('Uh, there is a problem while generating epub.'));
64 } 64 }
65 }
66}
65 67
68class WallabagEpub extends WallabagEBooks
69{
70 /**
71 * handle ePub
72 */
73 public function produceEpub()
74 {
66 $content_start = 75 $content_start =
67 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 76 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
68 . "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">\n" 77 . "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">\n"
@@ -132,4 +141,95 @@ class WallabagEpub
132 $book->finalize(); 141 $book->finalize();
133 $zipData = $book->sendBook($bookFileName); 142 $zipData = $book->sendBook($bookFileName);
134 } 143 }
135} \ No newline at end of file 144}
145
146class WallabagMobi extends WallabagEBooks
147{
148 /**
149 * Adapted from News2Kindle
150 * @author Jakub Westfalewski <jwest@jwest.pl>
151 *
152 */
153
154 public function produceMobi()
155 {
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
163 (
164 md5($item['title']),
165 mb_convert_encoding($item['title'], 'HTML-ENTITIES', 'utf-8'),
166 $content,
167 $item['url']],
168 ""
169 );
170 }
171 $articles = $storage->get_contents();
172 $toc = array();
173 $articles_count = count($articles);
174
175 foreach($articles as $article){
176 if(array_key_exists($article->website->title, $toc)){
177 $toc[$article->website->title]->articles[] = $article;
178 }else{
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,
184 );
185 }
186 }
187
188 $mobi = new MOBI();
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'),
194 ));
195
196 $images = array();
197
198 //prepare images for mobi format
199 foreach ( $storage->info('images') as $n => $image )
200 {
201 $images[$n] = new FileRecord(new Record(file_get_contents($storage->get_path() . $image)));
202 }
203
204 $mobi->setImages($images);
205 $mobi->save( $storage->get_path(FALSE) . 'articles-' . date('Y-m-d') . '.mobi');
206
207 $storage->clean();
208
209 if ($send) {
210 $files = glob($storage->get_path(FALSE).'*.mobi');
211 $mail = new Send(KINDLEMAIL,MAIL);
212 foreach ( $files as $file_mobi )
213 {
214 $mail->send( $file_mobi );
215 }
216 // clean cache
217 foreach ( $files as $file_mobi )
218 {
219 unlink( $file_mobi );
220 }
221 }
222 }
223}
224
225class WallabagPDF extends WallabagEbooks
226{
227 public function producePDF()
228 {
229 $mpdf = new mPDF('c');
230
231 $mpdf->WriteHTML($html);
232 $mpdf->Output();
233 exit;
234 }
235} \ No newline at end of file