From decc23aaf230f320613f5f09e0c70c7eb758ca70 Mon Sep 17 00:00:00 2001 From: tcit Date: Wed, 30 Apr 2014 11:25:03 +0200 Subject: Added save search as tag functionality --- inc/poche/Poche.class.php | 77 +++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 32 deletions(-) (limited to 'inc/poche/Poche.class.php') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 5aa6ea07..429c13b8 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -511,42 +511,55 @@ class Poche Tools::redirect(); break; case 'add_tag' : - $tags = explode(',', $_POST['value']); - $entry_id = $_POST['entry_id']; - $entry = $this->store->retrieveOneById($entry_id, $this->user->getId()); - if (!$entry) { - $this->messages->add('e', _('Article not found!')); - Tools::logm('error : article not found'); - Tools::redirect(); - } - //get all already set tags to preven duplicates - $already_set_tags = array(); - $entry_tags = $this->store->retrieveTagsByEntry($entry_id); - foreach ($entry_tags as $tag) { - $already_set_tags[] = $tag['value']; + if (isset($_GET['search'])) { + //when we want to apply a tag to a search + $search = true; + $tags = array($_GET['search']); + $allentry_ids = $this->store->search($tags[0], $this->user->getId()); + $entry_ids = array(); + foreach ($allentry_ids as $eachentry) { + $entry_ids[] = $eachentry[0]; + } + } else { //add a tag to a single article + $tags = explode(',', $_POST['value']); + $entry_ids = array($_POST['entry_id']); } - foreach($tags as $key => $tag_value) { - $value = trim($tag_value); - if ($value && !in_array($value, $already_set_tags)) { - $tag = $this->store->retrieveTagByValue($value); - - if (is_null($tag)) { - # we create the tag - $tag = $this->store->createTag($value); - $sequence = ''; - if (STORAGE == 'postgres') { - $sequence = 'tags_id_seq'; + foreach($entry_ids as $entry_id) { + $entry = $this->store->retrieveOneById($entry_id, $this->user->getId()); + if (!$entry) { + $this->messages->add('e', _('Article not found!')); + Tools::logm('error : article not found'); + Tools::redirect(); + } + //get all already set tags to preven duplicates + $already_set_tags = array(); + $entry_tags = $this->store->retrieveTagsByEntry($entry_id); + foreach ($entry_tags as $tag) { + $already_set_tags[] = $tag['value']; + } + foreach($tags as $key => $tag_value) { + $value = trim($tag_value); + if ($value && !in_array($value, $already_set_tags)) { + $tag = $this->store->retrieveTagByValue($value); + if (is_null($tag)) { + # we create the tag + $tag = $this->store->createTag($value); + $sequence = ''; + if (STORAGE == 'postgres') { + $sequence = 'tags_id_seq'; + } + $tag_id = $this->store->getLastId($sequence); } - $tag_id = $this->store->getLastId($sequence); - } - else { - $tag_id = $tag['id']; - } - - # we assign the tag to the article - $this->store->setTagToEntry($tag_id, $entry_id); + else { + $tag_id = $tag['id']; + } + + # we assign the tag to the article + $this->store->setTagToEntry($tag_id, $entry_id); + } } } + $this->messages->add('s', _('the tag has been applied successfully')); Tools::redirect(); break; case 'remove_tag' : -- cgit v1.2.3 From 78bddb22bee94c86af04061cb630c97625b17898 Mon Sep 17 00:00:00 2001 From: tcit Date: Wed, 30 Apr 2014 11:31:21 +0200 Subject: Remove unnecessary line --- inc/poche/Poche.class.php | 1 - 1 file changed, 1 deletion(-) (limited to 'inc/poche/Poche.class.php') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 429c13b8..61bc8e13 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -513,7 +513,6 @@ class Poche case 'add_tag' : if (isset($_GET['search'])) { //when we want to apply a tag to a search - $search = true; $tags = array($_GET['search']); $allentry_ids = $this->store->search($tags[0], $this->user->getId()); $entry_ids = array(); -- cgit v1.2.3 From 9c743ab965b978aa72a6272172b33f562d1f1f96 Mon Sep 17 00:00:00 2001 From: tcit Date: Wed, 30 Apr 2014 12:14:20 +0200 Subject: Clean old unused tags when deleting a tag --- inc/poche/Poche.class.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'inc/poche/Poche.class.php') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 61bc8e13..dc7b76d0 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -558,7 +558,7 @@ class Poche } } } - $this->messages->add('s', _('the tag has been applied successfully')); + $this->messages->add('s', _('The tag has been applied successfully')); Tools::redirect(); break; case 'remove_tag' : @@ -570,6 +570,10 @@ class Poche Tools::redirect(); } $this->store->removeTagForEntry($id, $tag_id); + Tools::logm('tag entry deleted'); + $this->store->cleanUnusedTags(); + Tools::logm('old tags cleaned'); + $this->messages->add('s', _('The tag has been successfully deleted')); Tools::redirect(); break; default: @@ -1131,6 +1135,13 @@ class Poche $this->messages->add('s', _('Cache deleted.')); Tools::redirect(); } + + public function cleanTags() { + $this->store->cleanUnusedTags(); + $this->messages->add('s', _('The unused tags have been cleaned.')); + Tools::logm('clean tags'); + Tools::redirect(); + } /** * return new purifier object with actual config -- cgit v1.2.3 From 4910af33ff79cdce6325a07bb0dc74fe4821e680 Mon Sep 17 00:00:00 2001 From: tcit Date: Sun, 11 May 2014 16:14:47 +0200 Subject: Removed unnecessary function for cleaning tags --- inc/poche/Poche.class.php | 7 ------- 1 file changed, 7 deletions(-) (limited to 'inc/poche/Poche.class.php') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index dc7b76d0..8ea5e7a2 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -1135,13 +1135,6 @@ class Poche $this->messages->add('s', _('Cache deleted.')); Tools::redirect(); } - - public function cleanTags() { - $this->store->cleanUnusedTags(); - $this->messages->add('s', _('The unused tags have been cleaned.')); - Tools::logm('clean tags'); - Tools::redirect(); - } /** * return new purifier object with actual config -- cgit v1.2.3 From 24696800e5caac6e37ebd2ac166578a9b18aba9d Mon Sep 17 00:00:00 2001 From: tcit Date: Wed, 14 May 2014 18:51:02 +0200 Subject: Simplifed function which does tag cleanup --- inc/poche/Poche.class.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'inc/poche/Poche.class.php') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 8ea5e7a2..515d4cac 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -559,6 +559,7 @@ class Poche } } $this->messages->add('s', _('The tag has been applied successfully')); + Tools::logm('The tag has been applied successfully'); Tools::redirect(); break; case 'remove_tag' : @@ -571,8 +572,9 @@ class Poche } $this->store->removeTagForEntry($id, $tag_id); Tools::logm('tag entry deleted'); - $this->store->cleanUnusedTags(); - Tools::logm('old tags cleaned'); + if ($this->store->cleanUnusedTag($tag_id)) { + Tools::logm('tag deleted'); + } $this->messages->add('s', _('The tag has been successfully deleted')); Tools::redirect(); break; -- cgit v1.2.3