diff options
Diffstat (limited to 'inc/poche/Poche.class.php')
-rwxr-xr-x | inc/poche/Poche.class.php | 80 |
1 files changed, 62 insertions, 18 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 01f919d9..5a0edbe4 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 { |
@@ -195,18 +202,31 @@ class Poche | |||
195 | return $last_id; | 202 | return $last_id; |
196 | break; | 203 | break; |
197 | case 'delete': | 204 | case 'delete': |
198 | $msg = 'delete link #' . $id; | 205 | if (isset($_GET['search'])) { |
199 | if ($this->store->deleteById($id, $this->user->getId())) { | 206 | //when we want to apply a delete to a search |
200 | if (DOWNLOAD_PICTURES) { | 207 | $tags = array($_GET['search']); |
201 | 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]; | ||
202 | } | 212 | } |
203 | $this->messages->add('s', _('the link has been deleted successfully')); | 213 | } else { // delete a single article |
214 | $entry_ids = array($id); | ||
204 | } | 215 | } |
205 | else { | 216 | foreach($entry_ids as $id) { |
206 | $this->messages->add('e', _('the link wasn\'t deleted')); | 217 | $msg = 'delete link #' . $id; |
207 | $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); | ||
208 | } | 229 | } |
209 | Tools::logm($msg); | ||
210 | Tools::redirect('?'); | 230 | Tools::redirect('?'); |
211 | break; | 231 | break; |
212 | case 'toggle_fav' : | 232 | case 'toggle_fav' : |
@@ -221,8 +241,21 @@ class Poche | |||
221 | } | 241 | } |
222 | break; | 242 | break; |
223 | case 'toggle_archive' : | 243 | case 'toggle_archive' : |
224 | $this->store->archiveById($id, $this->user->getId()); | 244 | if (isset($_GET['tag_id'])) { |
225 | 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 | } | ||
226 | if ( Tools::isAjaxRequest() ) { | 259 | if ( Tools::isAjaxRequest() ) { |
227 | echo 1; | 260 | echo 1; |
228 | exit; | 261 | exit; |
@@ -406,9 +439,12 @@ class Poche | |||
406 | } | 439 | } |
407 | 440 | ||
408 | # flattr checking | 441 | # flattr checking |
409 | $flattr = new FlattrItem(); | 442 | $flattr = NULL; |
410 | $flattr->checkItem($entry['url'], $entry['id']); | 443 | if (FLATTR) { |
411 | 444 | $flattr = new FlattrItem(); | |
445 | $flattr->checkItem($entry['url'], $entry['id']); | ||
446 | } | ||
447 | |||
412 | # tags | 448 | # tags |
413 | $tags = $this->store->retrieveTagsByEntry($entry['id']); | 449 | $tags = $this->store->retrieveTagsByEntry($entry['id']); |
414 | 450 | ||
@@ -541,6 +577,8 @@ class Poche | |||
541 | Tools::redirect($referer); | 577 | Tools::redirect($referer); |
542 | } | 578 | } |
543 | $this->messages->add('e', _('login failed: bad login or password')); | 579 | $this->messages->add('e', _('login failed: bad login or password')); |
580 | // log login failure in web server log to allow fail2ban usage | ||
581 | error_log('user '.$login.' authentication failure'); | ||
544 | Tools::logm('login failed'); | 582 | Tools::logm('login failed'); |
545 | Tools::redirect(); | 583 | Tools::redirect(); |
546 | } | 584 | } |
@@ -760,10 +798,11 @@ class Poche | |||
760 | * | 798 | * |
761 | * @param $token | 799 | * @param $token |
762 | * @param $user_id | 800 | * @param $user_id |
763 | * @param $tag_id | 801 | * @param $tag_id if $type is 'tag', the id of the tag to generate feed for |
764 | * @param string $type | 802 | * @param string $type the type of feed to generate |
803 | * @param int $limit the maximum number of items (0 means all) | ||
765 | */ | 804 | */ |
766 | public function generateFeeds($token, $user_id, $tag_id, $type = 'home') | 805 | public function generateFeeds($token, $user_id, $tag_id, $type = 'home', $limit = 0) |
767 | { | 806 | { |
768 | $allowed_types = array('home', 'fav', 'archive', 'tag'); | 807 | $allowed_types = array('home', 'fav', 'archive', 'tag'); |
769 | $config = $this->store->getConfigUser($user_id); | 808 | $config = $this->store->getConfigUser($user_id); |
@@ -790,8 +829,13 @@ class Poche | |||
790 | $entries = $this->store->getEntriesByView($type, $user_id); | 829 | $entries = $this->store->getEntriesByView($type, $user_id); |
791 | } | 830 | } |
792 | 831 | ||
832 | // if $limit is set to zero, use all entries | ||
833 | if (0 == $limit) { | ||
834 | $limit = count($entries); | ||
835 | } | ||
793 | if (count($entries) > 0) { | 836 | if (count($entries) > 0) { |
794 | foreach ($entries as $entry) { | 837 | for ($i = 0; $i < min(count($entries), $limit); $i++) { |
838 | $entry = $entries[$i]; | ||
795 | $newItem = $feed->createNewItem(); | 839 | $newItem = $feed->createNewItem(); |
796 | $newItem->setTitle($entry['title']); | 840 | $newItem->setTitle($entry['title']); |
797 | $newItem->setSource(Tools::getPocheUrl() . '?view=view&id=' . $entry['id']); | 841 | $newItem->setSource(Tools::getPocheUrl() . '?view=view&id=' . $entry['id']); |