aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Poche.class.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2014-05-16 13:31:53 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2014-05-16 13:31:53 +0200
commit60c3a4d3e17c991fccfea414b24ebf6e7649c90e (patch)
tree81eab74b7b5ea649b219451aad8279b3d71bfdbb /inc/poche/Poche.class.php
parent818b186f8aa3f46d7cbddaeca94bd9cec57c213e (diff)
parent4555c38d3b857bf91ed383f379d9697ed6a79860 (diff)
downloadwallabag-60c3a4d3e17c991fccfea414b24ebf6e7649c90e.tar.gz
wallabag-60c3a4d3e17c991fccfea414b24ebf6e7649c90e.tar.zst
wallabag-60c3a4d3e17c991fccfea414b24ebf6e7649c90e.zip
Merge pull request #689 from tcitworld/dev
Tag-related features
Diffstat (limited to 'inc/poche/Poche.class.php')
-rwxr-xr-xinc/poche/Poche.class.php82
1 files changed, 50 insertions, 32 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 5aa6ea07..515d4cac 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -511,42 +511,55 @@ class Poche
511 Tools::redirect(); 511 Tools::redirect();
512 break; 512 break;
513 case 'add_tag' : 513 case 'add_tag' :
514 $tags = explode(',', $_POST['value']); 514 if (isset($_GET['search'])) {
515 $entry_id = $_POST['entry_id']; 515 //when we want to apply a tag to a search
516 $entry = $this->store->retrieveOneById($entry_id, $this->user->getId()); 516 $tags = array($_GET['search']);
517 if (!$entry) { 517 $allentry_ids = $this->store->search($tags[0], $this->user->getId());
518 $this->messages->add('e', _('Article not found!')); 518 $entry_ids = array();
519 Tools::logm('error : article not found'); 519 foreach ($allentry_ids as $eachentry) {
520 Tools::redirect(); 520 $entry_ids[] = $eachentry[0];
521 } 521 }
522 //get all already set tags to preven duplicates 522 } else { //add a tag to a single article
523 $already_set_tags = array(); 523 $tags = explode(',', $_POST['value']);
524 $entry_tags = $this->store->retrieveTagsByEntry($entry_id); 524 $entry_ids = array($_POST['entry_id']);
525 foreach ($entry_tags as $tag) {
526 $already_set_tags[] = $tag['value'];
527 } 525 }
528 foreach($tags as $key => $tag_value) { 526 foreach($entry_ids as $entry_id) {
529 $value = trim($tag_value); 527 $entry = $this->store->retrieveOneById($entry_id, $this->user->getId());
530 if ($value && !in_array($value, $already_set_tags)) { 528 if (!$entry) {
531 $tag = $this->store->retrieveTagByValue($value); 529 $this->messages->add('e', _('Article not found!'));
532 530 Tools::logm('error : article not found');
533 if (is_null($tag)) { 531 Tools::redirect();
534 # we create the tag 532 }
535 $tag = $this->store->createTag($value); 533 //get all already set tags to preven duplicates
536 $sequence = ''; 534 $already_set_tags = array();
537 if (STORAGE == 'postgres') { 535 $entry_tags = $this->store->retrieveTagsByEntry($entry_id);
538 $sequence = 'tags_id_seq'; 536 foreach ($entry_tags as $tag) {
537 $already_set_tags[] = $tag['value'];
538 }
539 foreach($tags as $key => $tag_value) {
540 $value = trim($tag_value);
541 if ($value && !in_array($value, $already_set_tags)) {
542 $tag = $this->store->retrieveTagByValue($value);
543 if (is_null($tag)) {
544 # we create the tag
545 $tag = $this->store->createTag($value);
546 $sequence = '';
547 if (STORAGE == 'postgres') {
548 $sequence = 'tags_id_seq';
549 }
550 $tag_id = $this->store->getLastId($sequence);
551 }
552 else {
553 $tag_id = $tag['id'];
539 } 554 }
540 $tag_id = $this->store->getLastId($sequence); 555
541 } 556 # we assign the tag to the article
542 else { 557 $this->store->setTagToEntry($tag_id, $entry_id);
543 $tag_id = $tag['id']; 558 }
544 }
545
546 # we assign the tag to the article
547 $this->store->setTagToEntry($tag_id, $entry_id);
548 } 559 }
549 } 560 }
561 $this->messages->add('s', _('The tag has been applied successfully'));
562 Tools::logm('The tag has been applied successfully');
550 Tools::redirect(); 563 Tools::redirect();
551 break; 564 break;
552 case 'remove_tag' : 565 case 'remove_tag' :
@@ -558,6 +571,11 @@ class Poche
558 Tools::redirect(); 571 Tools::redirect();
559 } 572 }
560 $this->store->removeTagForEntry($id, $tag_id); 573 $this->store->removeTagForEntry($id, $tag_id);
574 Tools::logm('tag entry deleted');
575 if ($this->store->cleanUnusedTag($tag_id)) {
576 Tools::logm('tag deleted');
577 }
578 $this->messages->add('s', _('The tag has been successfully deleted'));
561 Tools::redirect(); 579 Tools::redirect();
562 break; 580 break;
563 default: 581 default: