diff options
Diffstat (limited to 'inc/poche/Poche.class.php')
-rwxr-xr-x | inc/poche/Poche.class.php | 94 |
1 files changed, 75 insertions, 19 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 3c7a2c5a..5b8e235f 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; |
@@ -413,9 +447,12 @@ class Poche | |||
413 | } | 447 | } |
414 | 448 | ||
415 | # flattr checking | 449 | # flattr checking |
416 | $flattr = new FlattrItem(); | 450 | $flattr = NULL; |
417 | $flattr->checkItem($entry['url'], $entry['id']); | 451 | if (FLATTR) { |
418 | 452 | $flattr = new FlattrItem(); | |
453 | $flattr->checkItem($entry['url'], $entry['id']); | ||
454 | } | ||
455 | |||
419 | # tags | 456 | # tags |
420 | $tags = $this->store->retrieveTagsByEntry($entry['id']); | 457 | $tags = $this->store->retrieveTagsByEntry($entry['id']); |
421 | 458 | ||
@@ -548,6 +585,8 @@ class Poche | |||
548 | Tools::redirect($referer); | 585 | Tools::redirect($referer); |
549 | } | 586 | } |
550 | $this->messages->add('e', _('login failed: bad login or password')); | 587 | $this->messages->add('e', _('login failed: bad login or password')); |
588 | // log login failure in web server log to allow fail2ban usage | ||
589 | error_log('user '.$login.' authentication failure'); | ||
551 | Tools::logm('login failed'); | 590 | Tools::logm('login failed'); |
552 | Tools::redirect(); | 591 | Tools::redirect(); |
553 | } | 592 | } |
@@ -633,7 +672,18 @@ class Poche | |||
633 | $urlsInserted[] = $url; //add | 672 | $urlsInserted[] = $url; //add |
634 | if (isset($record['tags']) && trim($record['tags'])) { | 673 | if (isset($record['tags']) && trim($record['tags'])) { |
635 | 674 | ||
636 | // @TODO: set tags | 675 | $tags = explode(',', $record['tags']); |
676 | foreach($tags as $tag) { | ||
677 | $entry_id = $id; | ||
678 | $tag_id = $this->store->retrieveTagByValue($tag); | ||
679 | if ($tag_id) { | ||
680 | $this->store->setTagToEntry($tag_id['id'], $entry_id); | ||
681 | } else { | ||
682 | $this->store->createTag($tag); | ||
683 | $tag_id = $this->store->retrieveTagByValue($tag); | ||
684 | $this->store->setTagToEntry($tag_id['id'], $entry_id); | ||
685 | } | ||
686 | } | ||
637 | 687 | ||
638 | } | 688 | } |
639 | } | 689 | } |
@@ -756,10 +806,11 @@ class Poche | |||
756 | * | 806 | * |
757 | * @param $token | 807 | * @param $token |
758 | * @param $user_id | 808 | * @param $user_id |
759 | * @param $tag_id | 809 | * @param $tag_id if $type is 'tag', the id of the tag to generate feed for |
760 | * @param string $type | 810 | * @param string $type the type of feed to generate |
811 | * @param int $limit the maximum number of items (0 means all) | ||
761 | */ | 812 | */ |
762 | public function generateFeeds($token, $user_id, $tag_id, $type = 'home') | 813 | public function generateFeeds($token, $user_id, $tag_id, $type = 'home', $limit = 0) |
763 | { | 814 | { |
764 | $allowed_types = array('home', 'fav', 'archive', 'tag'); | 815 | $allowed_types = array('home', 'fav', 'archive', 'tag'); |
765 | $config = $this->store->getConfigUser($user_id); | 816 | $config = $this->store->getConfigUser($user_id); |
@@ -786,8 +837,13 @@ class Poche | |||
786 | $entries = $this->store->getEntriesByView($type, $user_id); | 837 | $entries = $this->store->getEntriesByView($type, $user_id); |
787 | } | 838 | } |
788 | 839 | ||
840 | // if $limit is set to zero, use all entries | ||
841 | if (0 == $limit) { | ||
842 | $limit = count($entries); | ||
843 | } | ||
789 | if (count($entries) > 0) { | 844 | if (count($entries) > 0) { |
790 | foreach ($entries as $entry) { | 845 | for ($i = 0; $i < min(count($entries), $limit); $i++) { |
846 | $entry = $entries[$i]; | ||
791 | $newItem = $feed->createNewItem(); | 847 | $newItem = $feed->createNewItem(); |
792 | $newItem->setTitle($entry['title']); | 848 | $newItem->setTitle($entry['title']); |
793 | $newItem->setSource(Tools::getPocheUrl() . '?view=view&id=' . $entry['id']); | 849 | $newItem->setSource(Tools::getPocheUrl() . '?view=view&id=' . $entry['id']); |