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.php87
1 files changed, 55 insertions, 32 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 5aa6ea07..dc7b76d0 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -511,42 +511,54 @@ 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);
539 } 551 }
540 $tag_id = $this->store->getLastId($sequence); 552 else {
541 } 553 $tag_id = $tag['id'];
542 else { 554 }
543 $tag_id = $tag['id']; 555
544 } 556 # we assign the tag to the article
545 557 $this->store->setTagToEntry($tag_id, $entry_id);
546 # we assign the tag to the article 558 }
547 $this->store->setTagToEntry($tag_id, $entry_id);
548 } 559 }
549 } 560 }
561 $this->messages->add('s', _('The tag has been applied successfully'));
550 Tools::redirect(); 562 Tools::redirect();
551 break; 563 break;
552 case 'remove_tag' : 564 case 'remove_tag' :
@@ -558,6 +570,10 @@ class Poche
558 Tools::redirect(); 570 Tools::redirect();
559 } 571 }
560 $this->store->removeTagForEntry($id, $tag_id); 572 $this->store->removeTagForEntry($id, $tag_id);
573 Tools::logm('tag entry deleted');
574 $this->store->cleanUnusedTags();
575 Tools::logm('old tags cleaned');
576 $this->messages->add('s', _('The tag has been successfully deleted'));
561 Tools::redirect(); 577 Tools::redirect();
562 break; 578 break;
563 default: 579 default:
@@ -1119,6 +1135,13 @@ class Poche
1119 $this->messages->add('s', _('Cache deleted.')); 1135 $this->messages->add('s', _('Cache deleted.'));
1120 Tools::redirect(); 1136 Tools::redirect();
1121 } 1137 }
1138
1139 public function cleanTags() {
1140 $this->store->cleanUnusedTags();
1141 $this->messages->add('s', _('The unused tags have been cleaned.'));
1142 Tools::logm('clean tags');
1143 Tools::redirect();
1144 }
1122 1145
1123 /** 1146 /**
1124 * return new purifier object with actual config 1147 * return new purifier object with actual config