aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Poche.class.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/poche/Poche.class.php')
-rwxr-xr-xinc/poche/Poche.class.php94
1 files changed, 75 insertions, 19 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']);