aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/WallabagEBooks.class.php
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2015-02-01 11:33:41 +0100
committerThomas Citharel <tcit@tcit.fr>2015-02-01 11:33:41 +0100
commitc416cab8c9297d17f073c66d07bafab8b5068db2 (patch)
tree5f6342c866127675e3c59e1b664adc257262d86c /inc/poche/WallabagEBooks.class.php
parente51487f93265521cf04d8752b0554bb1f05dd189 (diff)
parentbc6f5a8086b331bf21cdfcac799788264d8cd3b2 (diff)
downloadwallabag-c416cab8c9297d17f073c66d07bafab8b5068db2.tar.gz
wallabag-c416cab8c9297d17f073c66d07bafab8b5068db2.tar.zst
wallabag-c416cab8c9297d17f073c66d07bafab8b5068db2.zip
Merge branch 'dev' into randomarticle
Diffstat (limited to 'inc/poche/WallabagEBooks.class.php')
-rw-r--r--inc/poche/WallabagEBooks.class.php41
1 files changed, 33 insertions, 8 deletions
diff --git a/inc/poche/WallabagEBooks.class.php b/inc/poche/WallabagEBooks.class.php
index bc40990b..55831571 100644
--- a/inc/poche/WallabagEBooks.class.php
+++ b/inc/poche/WallabagEBooks.class.php
@@ -33,7 +33,7 @@ class WallabagEBooks
33 $entry = $this->wallabag->store->retrieveOneById($entryID, $this->wallabag->user->getId()); 33 $entry = $this->wallabag->store->retrieveOneById($entryID, $this->wallabag->user->getId());
34 $this->entries = array($entry); 34 $this->entries = array($entry);
35 $this->bookTitle = $entry['title']; 35 $this->bookTitle = $entry['title'];
36 $this->bookFileName = substr($this->bookTitle, 0, 200); 36 $this->bookFileName = str_replace('/', '_', substr($this->bookTitle, 0, 200));
37 $this->author = preg_replace('#^w{3}.#', '', Tools::getdomain($entry["url"])); # if only one article, set author to domain name (we strip the eventual www part) 37 $this->author = preg_replace('#^w{3}.#', '', Tools::getdomain($entry["url"])); # if only one article, set author to domain name (we strip the eventual www part)
38 Tools::logm('Producing ebook from article ' . $this->bookTitle); 38 Tools::logm('Producing ebook from article ' . $this->bookTitle);
39 break; 39 break;
@@ -81,6 +81,9 @@ class WallabagEpub extends WallabagEBooks
81 public function produceEpub() 81 public function produceEpub()
82 { 82 {
83 Tools::logm('Starting to produce ePub 3 file'); 83 Tools::logm('Starting to produce ePub 3 file');
84
85 try {
86
84 $content_start = 87 $content_start =
85 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 88 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
86 . "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">\n" 89 . "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">\n"
@@ -155,6 +158,11 @@ class WallabagEpub extends WallabagEBooks
155 $book->finalize(); 158 $book->finalize();
156 $zipData = $book->sendBook($this->bookFileName); 159 $zipData = $book->sendBook($this->bookFileName);
157 Tools::logm('Ebook produced'); 160 Tools::logm('Ebook produced');
161 }
162 catch (Exception $e) {
163 Tools::logm('PHPePub has encountered an error : '.$e->getMessage());
164 $this->wallabag->messages->add('e', $e->getMessage());
165 }
158 } 166 }
159} 167}
160 168
@@ -167,7 +175,7 @@ class WallabagMobi extends WallabagEBooks
167 175
168 public function produceMobi() 176 public function produceMobi()
169 { 177 {
170 178 try {
171 Tools::logm('Starting to produce Mobi file'); 179 Tools::logm('Starting to produce Mobi file');
172 $mobi = new MOBI(); 180 $mobi = new MOBI();
173 $content = new MOBIFile(); 181 $content = new MOBIFile();
@@ -194,9 +202,17 @@ class WallabagMobi extends WallabagEBooks
194 } 202 }
195 $mobi->setContentProvider($content); 203 $mobi->setContentProvider($content);
196 204
205 // the browser inside Kindle Devices doesn't likes special caracters either, we limit to A-z/0-9
206 $this->bookFileName = preg_replace('/[^A-Za-z0-9\-]/', '', $this->bookFileName);
207
197 // we offer file to download 208 // we offer file to download
198 $mobi->download($this->bookFileName.'.mobi'); 209 $mobi->download($this->bookFileName.'.mobi');
199 Tools::logm('Mobi file produced'); 210 Tools::logm('Mobi file produced');
211 }
212 catch (Exception $e) {
213 Tools::logm('PHPMobi has encountered an error : '.$e->getMessage());
214 $this->wallabag->messages->add('e', $e->getMessage());
215 }
200 } 216 }
201} 217}
202 218
@@ -206,15 +222,16 @@ class WallabagPDF extends WallabagEbooks
206 { 222 {
207 223
208 Tools::logm('Starting to produce PDF file'); 224 Tools::logm('Starting to produce PDF file');
209 225 @define ('K_TCPDF_THROW_EXCEPTION_ERROR', TRUE);
226 try {
210 $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 227 $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
211 228
212 Tools::logm('Filling metadata for PDF...'); 229 Tools::logm('Filling metadata for PDF...');
213 $pdf->SetCreator(PDF_CREATOR); 230 $pdf->SetCreator(PDF_CREATOR);
214 $pdf->SetAuthor(''); 231 $pdf->SetAuthor('wallabag');
215 $pdf->SetTitle($this->bookTitle); 232 $pdf->SetTitle($this->bookTitle);
216 $pdf->SetSubject('TCPDF Tutorial'); 233 $pdf->SetSubject('Articles via wallabag');
217 $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); 234 $pdf->SetKeywords('wallabag');
218 235
219 Tools::logm('Adding introduction...'); 236 Tools::logm('Adding introduction...');
220 $pdf->AddPage(); 237 $pdf->AddPage();
@@ -229,18 +246,26 @@ class WallabagPDF extends WallabagEbooks
229 $i = 1; 246 $i = 1;
230 Tools::logm('Adding actual content...'); 247 Tools::logm('Adding actual content...');
231 foreach ($this->entries as $item) { 248 foreach ($this->entries as $item) {
249 $tags = $this->wallabag->store->retrieveTagsByEntry($entry['id']);
250 foreach ($tags as $tag) {
251 $pdf->SetKeywords($tag['value']);
252 }
232 $pdf->AddPage(); 253 $pdf->AddPage();
233 $html = '<h1>' . $item['title'] . '</h1>'; 254 $html = '<h1>' . $item['title'] . '</h1>';
234 $html .= $item['content']; 255 $html .= $item['content'];
235 $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); 256 $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
236 $i = $i+1;
237 } 257 }
238 258
239 // set image scale factor 259 // set image scale factor
240 $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); 260 $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
241 261
242 262
243 $pdf->Output($this->bookFileName . '.pdf', 'FD'); 263 $pdf->Output($this->bookFileName . '.pdf', 'FD');
264 }
265 catch (Exception $e) {
266 Tools::logm('TCPDF has encountered an error : '.$e->getMessage());
267 $this->wallabag->messages->add('e', $e->getMessage());
268 }
244 269
245 } 270 }
246} 271}