aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/WallabagEBooks.class.php
diff options
context:
space:
mode:
authortcit <tcit@tcit.fr>2014-07-24 21:56:04 +0200
committertcit <tcit@tcit.fr>2014-07-24 21:56:04 +0200
commitfb9df0c269f36703909b8b259abbdbed29881ecd (patch)
tree03069262fe6a7bd5891f5649d31fc057b3ca8541 /inc/poche/WallabagEBooks.class.php
parentc70bfefc68fcc96b1ce57845e5b2942a596239ec (diff)
downloadwallabag-fb9df0c269f36703909b8b259abbdbed29881ecd.tar.gz
wallabag-fb9df0c269f36703909b8b259abbdbed29881ecd.tar.zst
wallabag-fb9df0c269f36703909b8b259abbdbed29881ecd.zip
use directly MOBIClass
Diffstat (limited to 'inc/poche/WallabagEBooks.class.php')
-rw-r--r--inc/poche/WallabagEBooks.class.php166
1 files changed, 76 insertions, 90 deletions
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
30 case 'id': 30 case 'id':
31 $entryID = filter_var($this->value, FILTER_SANITIZE_NUMBER_INT); 31 $entryID = filter_var($this->value, FILTER_SANITIZE_NUMBER_INT);
32 $entry = $this->wallabag->store->retrieveOneById($entryID, $this->wallabag->user->getId()); 32 $entry = $this->wallabag->store->retrieveOneById($entryID, $this->wallabag->user->getId());
33 $entries = array($entry); 33 $this->entries = array($entry);
34 $bookTitle = $entry['title']; 34 $this->bookTitle = $entry['title'];
35 $bookFileName = substr($bookTitle, 0, 200); 35 $this->bookFileName = substr($this->bookTitle, 0, 200);
36 break; 36 break;
37 case 'all': 37 case 'all':
38 $entries = $this->wallabag->store->retrieveAll($this->wallabag->user->getId()); 38 $this->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 39 $this->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')); 40 $this->bookFileName = _('Allarticles') . date(_('dmY'));
41 break; 41 break;
42 case 'tag': 42 case 'tag':
43 $tag = filter_var($this->value, FILTER_SANITIZE_STRING); 43 $tag = filter_var($this->value, FILTER_SANITIZE_STRING);
44 $tags_id = $this->wallabag->store->retrieveAllTags($this->wallabag->user->getId(), $tag); 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. 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()); 46 $this->entries = $this->wallabag->store->retrieveEntriesByTag($tag_id, $this->wallabag->user->getId());
47 $bookTitle = sprintf(_('Articles tagged %s'), $tag); 47 $this->bookTitle = sprintf(_('Articles tagged %s'), $tag);
48 $bookFileName = substr(sprintf(_('Tag %s'), $tag), 0, 200); 48 $this->bookFileName = substr(sprintf(_('Tag %s'), $tag), 0, 200);
49 break; 49 break;
50 case 'category': 50 case 'category':
51 $category = filter_var($this->value, FILTER_SANITIZE_STRING); 51 $category = filter_var($this->value, FILTER_SANITIZE_STRING);
52 $entries = $this->wallabag->store->getEntriesByView($category, $this->wallabag->user->getId()); 52 $this->entries = $this->wallabag->store->getEntriesByView($category, $this->wallabag->user->getId());
53 $bookTitle = sprintf(_('All articles in category %s'), $category); 53 $this->bookTitle = sprintf(_('All articles in category %s'), $category);
54 $bookFileName = substr(sprintf(_('Category %s'), $category), 0, 200); 54 $this->bookFileName = substr(sprintf(_('Category %s'), $category), 0, 200);
55 break; 55 break;
56 case 'search': 56 case 'search':
57 $search = filter_var($this->value, FILTER_SANITIZE_STRING); 57 $search = filter_var($this->value, FILTER_SANITIZE_STRING);
58 $entries = $this->store->search($search, $this->wallabag->user->getId()); 58 Tools::logm($search);
59 $bookTitle = sprintf(_('All articles for search %s'), $search); 59 $this->entries = $this->wallabag->store->search($search, $this->wallabag->user->getId());
60 $bookFileName = substr(sprintf(_('Search %s'), $search), 0, 200); 60 $this->bookTitle = sprintf(_('All articles for search %s'), $search);
61 $this->bookFileName = substr(sprintf(_('Search %s'), $search), 0, 200);
61 break; 62 break;
62 case 'default': 63 case 'default':
63 die(_('Uh, there is a problem while generating epub.')); 64 die(_('Uh, there is a problem while generating epub.'));
@@ -94,7 +95,7 @@ class WallabagEpub extends WallabagEBooks
94 $log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL()); 95 $log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL());
95 $log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL()); 96 $log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL());
96 97
97 $book->setTitle($bookTitle); 98 $book->setTitle($this->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->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->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->setDescription(_("Some articles saved on my wallabag"));
@@ -111,7 +112,7 @@ class WallabagEpub extends WallabagEBooks
111 112
112 $log->logLine("Add Cover"); 113 $log->logLine("Add Cover");
113 114
114 $fullTitle = "<h1> " . $bookTitle . "</h1>\n"; 115 $fullTitle = "<h1> " . $this->bookTitle . "</h1>\n";
115 116
116 $book->setCoverImage("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png", $fullTitle); 117 $book->setCoverImage("Cover.png", file_get_contents("themes/baggy/img/apple-touch-icon-152.png"), "image/png", $fullTitle);
117 118
@@ -122,7 +123,7 @@ class WallabagEpub extends WallabagEBooks
122 123
123 $book->buildTOC(); 124 $book->buildTOC();
124 125
125 foreach ($entries as $entry) { //set tags as subjects 126 foreach ($this->entries as $entry) { //set tags as subjects
126 $tags = $this->wallabag->store->retrieveTagsByEntry($entry['id']); 127 $tags = $this->wallabag->store->retrieveTagsByEntry($entry['id']);
127 foreach ($tags as $tag) { 128 foreach ($tags as $tag) {
128 $book->setSubject($tag['value']); 129 $book->setSubject($tag['value']);
@@ -139,97 +140,82 @@ class WallabagEpub extends WallabagEBooks
139 $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n</pre>" . $bookEnd); // log generation 140 $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n</pre>" . $bookEnd); // log generation
140 } 141 }
141 $book->finalize(); 142 $book->finalize();
142 $zipData = $book->sendBook($bookFileName); 143 $zipData = $book->sendBook($this->bookFileName);
143 } 144 }
144} 145}
145 146
146class WallabagMobi extends WallabagEBooks 147class WallabagMobi extends WallabagEBooks
147{ 148{
148 /** 149 /**
149 * Adapted from News2Kindle 150 * MOBI Class
150 * @author Jakub Westfalewski <jwest@jwest.pl> 151 * @author Sander Kromwijk
151 *
152 */ 152 */
153 153
154 public function produceMobi() 154 public function produceMobi($send = FALSE)
155 { 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 156
196 $images = array(); 157 # Good try
197 158 $mobi = new MOBI();
198 //prepare images for mobi format 159
199 foreach ( $storage->info('images') as $n => $image ) 160 $content = new MOBIFile();
200 { 161
201 $images[$n] = new FileRecord(new Record(file_get_contents($storage->get_path() . $image))); 162 $content->set("title", $this->bookTitle);
163 $content->set("author", "wallabag");
164
165 # introduction
166 //$content->appendChapterTitle("Cover");
167 $content->appendParagraph('<div style="text-align:center;"><p>' . _('Produced by wallabag with PHPMobi') . '</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>');
168 $content->appendImage(imagecreatefrompng("themes/baggy/img/apple-touch-icon-152.png"));
169 $content->appendPageBreak();
170
171 foreach ($this->entries as $item) {
172 $content->appendChapterTitle($item['title']);
173 $content->appendParagraph($item['content']);
174 $content->appendPageBreak();
202 } 175 }
176 $mobi->setContentProvider($content);
203 177
204 $mobi->setImages($images); 178 $mobi->download($this->bookFileName.".mobi");
205 $mobi->save( $storage->get_path(FALSE) . 'articles-' . date('Y-m-d') . '.mobi'); 179 }
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} 180}
224 181
225class WallabagPDF extends WallabagEbooks 182class WallabagPDF extends WallabagEbooks
226{ 183{
227 public function producePDF() 184 public function producePDF()
228 { 185 {
186 //$this->prepareData();
229 $mpdf = new mPDF('c'); 187 $mpdf = new mPDF('c');
230 188
231 $mpdf->WriteHTML($html); 189 # intro
232 $mpdf->Output(); 190
233 exit; 191 $html = '<h1>' . $this->bookTitle . '</h1><img src="themes/baggy/img/apple-touch-icon-152.png" />';
192
193 foreach ($this->entries as $item) {
194 $html .= '<h1>' . $item['title'] . '</h1>';
195 $html .= '<indexentry content="'. $item['title'] .'" />';
196 $html .= $item['content'];
197 }
198
199 //$mpdf->h2toc = array('H1'=>0);
200
201 # headers
202 $mpdf->SetHeader('{DATE j-m-Y}|{PAGENO}/{nb}|Produced with wallabag');
203 $mpdf->SetFooter('{PAGENO}');
204
205 $mpdf->WriteHTML($html);
206
207 # remove characters that make mpdf bug
208 $char_in = array('/', '.', ',', ':', '|');
209 $pdfExportName = preg_replace('/\s+/', '-', str_replace($char_in, '-', $this->bookFileName . '.pdf'));
210
211 $mpdf->Output('cache/' . $pdfExportName);
212
213 header('Content-Disposition: attachment; filename="' . $pdfExportName . '"');
214
215 header('Content-Transfer-Encoding: base64');
216 header('Content-Type: application/pdf');
217 echo file_get_contents('cache/' . $pdfExportName);
218
219 //exit;
234 } 220 }
235} \ No newline at end of file 221} \ No newline at end of file