aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
Diffstat (limited to 'inc/poche')
-rwxr-xr-xinc/poche/Poche.class.php94
-rwxr-xr-xinc/poche/Routing.class.php5
-rwxr-xr-xinc/poche/Tools.class.php5
-rw-r--r--inc/poche/WallabagEBooks.class.php41
4 files changed, 115 insertions, 30 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index f5262a8e..a164ed47 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -180,6 +180,13 @@ class Poche
180 } 180 }
181 } 181 }
182 182
183 // if there are tags, add them to the new article
184 if (isset($_GET['tags'])) {
185 $_POST['value'] = $_GET['tags'];
186 $_POST['entry_id'] = $last_id;
187 $this->action('add_tag', $url);
188 }
189
183 $this->messages->add('s', _('the link has been added successfully')); 190 $this->messages->add('s', _('the link has been added successfully'));
184 } 191 }
185 else { 192 else {
@@ -192,20 +199,34 @@ class Poche
192 } else { 199 } else {
193 Tools::redirect('?view=home&closewin=true'); 200 Tools::redirect('?view=home&closewin=true');
194 } 201 }
202 return $last_id;
195 break; 203 break;
196 case 'delete': 204 case 'delete':
197 $msg = 'delete link #' . $id; 205 if (isset($_GET['search'])) {
198 if ($this->store->deleteById($id, $this->user->getId())) { 206 //when we want to apply a delete to a search
199 if (DOWNLOAD_PICTURES) { 207 $tags = array($_GET['search']);
200 Picture::removeDirectory(ABS_PATH . $id); 208 $allentry_ids = $this->store->search($tags[0], $this->user->getId());
209 $entry_ids = array();
210 foreach ($allentry_ids as $eachentry) {
211 $entry_ids[] = $eachentry[0];
201 } 212 }
202 $this->messages->add('s', _('the link has been deleted successfully')); 213 } else { // delete a single article
214 $entry_ids = array($id);
203 } 215 }
204 else { 216 foreach($entry_ids as $id) {
205 $this->messages->add('e', _('the link wasn\'t deleted')); 217 $msg = 'delete link #' . $id;
206 $msg = 'error : can\'t delete link #' . $id; 218 if ($this->store->deleteById($id, $this->user->getId())) {
219 if (DOWNLOAD_PICTURES) {
220 Picture::removeDirectory(ABS_PATH . $id);
221 }
222 $this->messages->add('s', _('the link has been deleted successfully'));
223 }
224 else {
225 $this->messages->add('e', _('the link wasn\'t deleted'));
226 $msg = 'error : can\'t delete link #' . $id;
227 }
228 Tools::logm($msg);
207 } 229 }
208 Tools::logm($msg);
209 Tools::redirect('?'); 230 Tools::redirect('?');
210 break; 231 break;
211 case 'toggle_fav' : 232 case 'toggle_fav' :
@@ -220,8 +241,21 @@ class Poche
220 } 241 }
221 break; 242 break;
222 case 'toggle_archive' : 243 case 'toggle_archive' :
223 $this->store->archiveById($id, $this->user->getId()); 244 if (isset($_GET['tag_id'])) {
224 Tools::logm('archive link #' . $id); 245 //when we want to archive a whole tag
246 $tag_id = $_GET['tag_id'];
247 $allentry_ids = $this->store->retrieveEntriesByTag($tag_id, $this->user->getId());
248 $entry_ids = array();
249 foreach ($allentry_ids as $eachentry) {
250 $entry_ids[] = $eachentry[0];
251 }
252 } else { //archive a single article
253 $entry_ids = array($id);
254 }
255 foreach($entry_ids as $id) {
256 $this->store->archiveById($id, $this->user->getId());
257 Tools::logm('archive link #' . $id);
258 }
225 if ( Tools::isAjaxRequest() ) { 259 if ( Tools::isAjaxRequest() ) {
226 echo 1; 260 echo 1;
227 exit; 261 exit;
@@ -414,9 +448,12 @@ class Poche
414 } 448 }
415 449
416 # flattr checking 450 # flattr checking
417 $flattr = new FlattrItem(); 451 $flattr = NULL;
418 $flattr->checkItem($entry['url'], $entry['id']); 452 if (FLATTR) {
419 453 $flattr = new FlattrItem();
454 $flattr->checkItem($entry['url'], $entry['id']);
455 }
456
420 # tags 457 # tags
421 $tags = $this->store->retrieveTagsByEntry($entry['id']); 458 $tags = $this->store->retrieveTagsByEntry($entry['id']);
422 459
@@ -549,6 +586,8 @@ class Poche
549 Tools::redirect($referer); 586 Tools::redirect($referer);
550 } 587 }
551 $this->messages->add('e', _('login failed: bad login or password')); 588 $this->messages->add('e', _('login failed: bad login or password'));
589 // log login failure in web server log to allow fail2ban usage
590 error_log('user '.$login.' authentication failure');
552 Tools::logm('login failed'); 591 Tools::logm('login failed');
553 Tools::redirect(); 592 Tools::redirect();
554 } 593 }
@@ -634,7 +673,18 @@ class Poche
634 $urlsInserted[] = $url; //add 673 $urlsInserted[] = $url; //add
635 if (isset($record['tags']) && trim($record['tags'])) { 674 if (isset($record['tags']) && trim($record['tags'])) {
636 675
637 // @TODO: set tags 676 $tags = explode(',', $record['tags']);
677 foreach($tags as $tag) {
678 $entry_id = $id;
679 $tag_id = $this->store->retrieveTagByValue($tag);
680 if ($tag_id) {
681 $this->store->setTagToEntry($tag_id['id'], $entry_id);
682 } else {
683 $this->store->createTag($tag);
684 $tag_id = $this->store->retrieveTagByValue($tag);
685 $this->store->setTagToEntry($tag_id['id'], $entry_id);
686 }
687 }
638 688
639 } 689 }
640 } 690 }
@@ -757,10 +807,11 @@ class Poche
757 * 807 *
758 * @param $token 808 * @param $token
759 * @param $user_id 809 * @param $user_id
760 * @param $tag_id 810 * @param $tag_id if $type is 'tag', the id of the tag to generate feed for
761 * @param string $type 811 * @param string $type the type of feed to generate
812 * @param int $limit the maximum number of items (0 means all)
762 */ 813 */
763 public function generateFeeds($token, $user_id, $tag_id, $type = 'home') 814 public function generateFeeds($token, $user_id, $tag_id, $type = 'home', $limit = 0)
764 { 815 {
765 $allowed_types = array('home', 'fav', 'archive', 'tag'); 816 $allowed_types = array('home', 'fav', 'archive', 'tag');
766 $config = $this->store->getConfigUser($user_id); 817 $config = $this->store->getConfigUser($user_id);
@@ -787,8 +838,13 @@ class Poche
787 $entries = $this->store->getEntriesByView($type, $user_id); 838 $entries = $this->store->getEntriesByView($type, $user_id);
788 } 839 }
789 840
841 // if $limit is set to zero, use all entries
842 if (0 == $limit) {
843 $limit = count($entries);
844 }
790 if (count($entries) > 0) { 845 if (count($entries) > 0) {
791 foreach ($entries as $entry) { 846 for ($i = 0; $i < min(count($entries), $limit); $i++) {
847 $entry = $entries[$i];
792 $newItem = $feed->createNewItem(); 848 $newItem = $feed->createNewItem();
793 $newItem->setTitle($entry['title']); 849 $newItem->setTitle($entry['title']);
794 $newItem->setSource(Tools::getPocheUrl() . '?view=view&amp;id=' . $entry['id']); 850 $newItem->setSource(Tools::getPocheUrl() . '?view=view&amp;id=' . $entry['id']);
diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php
index 5acd08ba..a8d00b89 100755
--- a/inc/poche/Routing.class.php
+++ b/inc/poche/Routing.class.php
@@ -102,7 +102,8 @@ class Routing
102 $this->wallabag->login($this->referer); 102 $this->wallabag->login($this->referer);
103 } elseif (isset($_GET['feed']) && isset($_GET['user_id'])) { 103 } elseif (isset($_GET['feed']) && isset($_GET['user_id'])) {
104 $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0); 104 $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0);
105 $this->wallabag->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type']); 105 $limit = (isset($_GET['limit']) ? intval($_GET['limit']) : 0);
106 $this->wallabag->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type'], $limit);
106 } 107 }
107 108
108 //allowed ONLY to logged in user 109 //allowed ONLY to logged in user
@@ -115,7 +116,7 @@ class Routing
115 // update password 116 // update password
116 $this->wallabag->updatePassword($_POST['password'], $_POST['password_repeat']); 117 $this->wallabag->updatePassword($_POST['password'], $_POST['password_repeat']);
117 } elseif (isset($_GET['newuser'])) { 118 } elseif (isset($_GET['newuser'])) {
118 $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser']); 119 $this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser'], $_POST['newuseremail']);
119 } elseif (isset($_GET['deluser'])) { 120 } elseif (isset($_GET['deluser'])) {
120 $this->wallabag->deleteUser($_POST['password4deletinguser']); 121 $this->wallabag->deleteUser($_POST['password4deletinguser']);
121 } elseif (isset($_GET['epub'])) { 122 } elseif (isset($_GET['epub'])) {
diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php
index f803e3b5..7ccfc069 100755
--- a/inc/poche/Tools.class.php
+++ b/inc/poche/Tools.class.php
@@ -342,7 +342,10 @@ final class Tools
342 return $json; 342 return $json;
343 }; 343 };
344 344
345 $json = $scope("inc/3rdparty/makefulltextfeed.php", array("url" => $url)); 345 // Silence $scope function to avoid
346 // issues with FTRSS when error_reporting is to high
347 // FTRSS generates PHP warnings which break output
348 $json = @$scope("inc/3rdparty/makefulltextfeed.php", array("url" => $url));
346 349
347 // Clearing and restoring context 350 // Clearing and restoring context
348 foreach ($GLOBALS as $key => $value) { 351 foreach ($GLOBALS as $key => $value) {
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}