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.php52
1 files changed, 35 insertions, 17 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 0c8e798c..480f6d45 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -488,25 +488,33 @@ class Poche
488 Tools::logm('error : article not found'); 488 Tools::logm('error : article not found');
489 Tools::redirect(); 489 Tools::redirect();
490 } 490 }
491 //get all already set tags to preven duplicates
492 $already_set_tags = array();
493 $entry_tags = $this->store->retrieveTagsByEntry($entry_id);
494 foreach ($entry_tags as $tag) {
495 $already_set_tags[] = $tag['value'];
496 }
491 foreach($tags as $key => $tag_value) { 497 foreach($tags as $key => $tag_value) {
492 $value = trim($tag_value); 498 $value = trim($tag_value);
493 $tag = $this->store->retrieveTagByValue($value); 499 if ($value && !in_array($value, $already_set_tags)) {
494 500 $tag = $this->store->retrieveTagByValue($value);
495 if (is_null($tag)) { 501
496 # we create the tag 502 if (is_null($tag)) {
497 $tag = $this->store->createTag($value); 503 # we create the tag
498 $sequence = ''; 504 $tag = $this->store->createTag($value);
499 if (STORAGE == 'postgres') { 505 $sequence = '';
500 $sequence = 'tags_id_seq'; 506 if (STORAGE == 'postgres') {
501 } 507 $sequence = 'tags_id_seq';
502 $tag_id = $this->store->getLastId($sequence); 508 }
503 } 509 $tag_id = $this->store->getLastId($sequence);
504 else { 510 }
505 $tag_id = $tag['id']; 511 else {
512 $tag_id = $tag['id'];
513 }
514
515 # we assign the tag to the article
516 $this->store->setTagToEntry($tag_id, $entry_id);
506 } 517 }
507
508 # we assign the tag to the article
509 $this->store->setTagToEntry($tag_id, $entry_id);
510 } 518 }
511 if(!$import) { 519 if(!$import) {
512 Tools::redirect(); 520 Tools::redirect();
@@ -579,7 +587,17 @@ class Poche
579 break; 587 break;
580 case 'tags': 588 case 'tags':
581 $token = $this->user->getConfigValue('token'); 589 $token = $this->user->getConfigValue('token');
582 $tags = $this->store->retrieveAllTags($this->user->getId()); 590 //if term is set - search tags for this term
591 $term = Tools::checkVar('term');
592 $tags = $this->store->retrieveAllTags($this->user->getId(), $term);
593 if (Tools::isAjaxRequest()) {
594 $result = array();
595 foreach ($tags as $tag) {
596 $result[] = $tag['value'];
597 }
598 echo json_encode($result);
599 exit;
600 }
583 $tpl_vars = array( 601 $tpl_vars = array(
584 'token' => $token, 602 'token' => $token,
585 'user_id' => $this->user->getId(), 603 'user_id' => $this->user->getId(),