aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
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
parentc70bfefc68fcc96b1ce57845e5b2942a596239ec (diff)
downloadwallabag-fb9df0c269f36703909b8b259abbdbed29881ecd.tar.gz
wallabag-fb9df0c269f36703909b8b259abbdbed29881ecd.tar.zst
wallabag-fb9df0c269f36703909b8b259abbdbed29881ecd.zip
use directly MOBIClass
Diffstat (limited to 'inc/poche')
-rw-r--r--inc/poche/Routing.class.php3
-rw-r--r--inc/poche/WallabagEBooks.class.php166
-rwxr-xr-xinc/poche/global.inc.php6
3 files changed, 80 insertions, 95 deletions
diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php
index e01d8129..83eabf19 100644
--- a/inc/poche/Routing.class.php
+++ b/inc/poche/Routing.class.php
@@ -112,12 +112,15 @@ class Routing
112 $this->wallabag->deleteUser($_POST['password4deletinguser']); 112 $this->wallabag->deleteUser($_POST['password4deletinguser']);
113 } elseif (isset($_GET['epub'])) { 113 } elseif (isset($_GET['epub'])) {
114 $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['value']); 114 $epub = new WallabagEpub($this->wallabag, $_GET['method'], $_GET['value']);
115 $epub->prepareData();
115 $epub->produceEpub(); 116 $epub->produceEpub();
116 } elseif (isset($_GET['mobi'])) { 117 } elseif (isset($_GET['mobi'])) {
117 $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']); 118 $mobi = new WallabagMobi($this->wallabag, $_GET['method'], $_GET['value']);
119 $mobi->prepareData();
118 $mobi->produceMobi(); 120 $mobi->produceMobi();
119 } elseif (isset($_GET['pdf'])) { 121 } elseif (isset($_GET['pdf'])) {
120 $pdf = new WallabagPDF($this->wallabag, $_GET['method'], $_GET['value']); 122 $pdf = new WallabagPDF($this->wallabag, $_GET['method'], $_GET['value']);
123 $pdf->prepareData();
121 $pdf->producePDF(); 124 $pdf->producePDF();
122 } elseif (isset($_GET['import'])) { 125 } elseif (isset($_GET['import'])) {
123 $import = $this->wallabag->import(); 126 $import = $this->wallabag->import();
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
diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php
index 1542fbfa..182f721d 100755
--- a/inc/poche/global.inc.php
+++ b/inc/poche/global.inc.php
@@ -42,11 +42,7 @@ require_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 44# mobi library
45require_once INCLUDES . '/3rdparty/libraries/send2kindle/send.php'; 45require_once INCLUDES . '/3rdparty/libraries/MOBIClass/MOBI.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 46
51# pdf library 47# pdf library
52require_once INCLUDES . '/3rdparty/libraries/mpdf/mpdf.php'; 48require_once INCLUDES . '/3rdparty/libraries/mpdf/mpdf.php';