aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
Diffstat (limited to 'inc/poche')
-rw-r--r--inc/poche/WallabagEpub.class.php114
-rwxr-xr-xinc/poche/global.inc.php10
2 files changed, 117 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
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';
41require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPub.php'; 41require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPub.php';
42require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPubChapterSplitter.php'; 42require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPubChapterSplitter.php';
43 43
44# mobi library
45require_once INCLUDES . '/3rdparty/libraries/send2kindle/send.php';
46require_once INCLUDES . '/3rdparty/libraries/send2kindle/images.php';
47require_once INCLUDES . '/3rdparty/libraries/send2kindle/storage.php';
48require_once INCLUDES . '/3rdparty/libraries/send2kindle/MOBIClass/MOBI.php';
49require_once INCLUDES . '/3rdparty/libraries/send2kindle/utils.php';
50
51# pdf library
52require_once INCLUDES . '/3rdparty/libraries/mpdf/mpdf.php';
53
44# system configuration; database credentials et caetera 54# system configuration; database credentials et caetera
45require_once INCLUDES . '/poche/config.inc.php'; 55require_once INCLUDES . '/poche/config.inc.php';
46require_once INCLUDES . '/poche/config.inc.default.php'; 56require_once INCLUDES . '/poche/config.inc.default.php';