From decc23aaf230f320613f5f09e0c70c7eb758ca70 Mon Sep 17 00:00:00 2001 From: tcit Date: Wed, 30 Apr 2014 11:25:03 +0200 Subject: [PATCH 1/6] Added save search as tag functionality --- inc/poche/Poche.class.php | 75 +++++++++++++++++++++++---------------- themes/baggy/home.twig | 1 + 2 files changed, 45 insertions(+), 31 deletions(-) diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 5aa6ea0..429c13b 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(); + 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']); } - //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'; + 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); + } + else { + $tag_id = $tag['id']; } - $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); + # 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' : diff --git a/themes/baggy/home.twig b/themes/baggy/home.twig index 5dd9130..92a3c86 100755 --- a/themes/baggy/home.twig +++ b/themes/baggy/home.twig @@ -57,6 +57,7 @@ {% endfor %} {% if view == 'home' %}{% if nb_results > 1 %}{{ "Mark all the entries as read" }}{% endif %}{% endif %} + {% if search_term is defined %}{% trans "Apply the tag" %} {{ search_term }} {% trans "to this search" %}{% endif %} {% endif %} {{ block('pager') }} {% endblock %} From 78bddb22bee94c86af04061cb630c97625b17898 Mon Sep 17 00:00:00 2001 From: tcit Date: Wed, 30 Apr 2014 11:31:21 +0200 Subject: [PATCH 2/6] Remove unnecessary line --- inc/poche/Poche.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 429c13b..61bc8e1 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(); From 9c743ab965b978aa72a6272172b33f562d1f1f96 Mon Sep 17 00:00:00 2001 From: tcit Date: Wed, 30 Apr 2014 12:14:20 +0200 Subject: [PATCH 3/6] Clean old unused tags when deleting a tag --- inc/poche/Database.class.php | 18 ++++++++++++++++++ inc/poche/Poche.class.php | 13 ++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 141d798..02e8be8 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -511,6 +511,24 @@ class Database { $query = $this->executeQuery($sql_action, $params_action); return $query; } + + public function cleanUnusedTags() { + $sql_action = "SELECT tags.* FROM tags JOIN tags_entries ON tags_entries.tag_id=tags.id"; + $query = $this->executeQuery($sql_action,array()); + $tagstokeep = $query->fetchAll(); + $sql_action = "SELECT tags.* FROM tags LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id"; + $query = $this->executeQuery($sql_action,array()); + $alltags = $query->fetchAll(); + foreach ($alltags as $tag) { + if ($tag && !in_array($tag,$tagstokeep)) { + //delete tag + $sql_action = "DELETE FROM tags WHERE id=?"; + $params_action = array($tag[0]); + $query = $this->executeQuery($sql_action, $params_action); + return $query; + } + } + } public function retrieveTagByValue($value) { $tag = NULL; diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 61bc8e1..dc7b76d 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 From 4910af33ff79cdce6325a07bb0dc74fe4821e680 Mon Sep 17 00:00:00 2001 From: tcit Date: Sun, 11 May 2014 16:14:47 +0200 Subject: [PATCH 4/6] Removed unnecessary function for cleaning tags --- inc/poche/Poche.class.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index dc7b76d..8ea5e7a 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 From 24696800e5caac6e37ebd2ac166578a9b18aba9d Mon Sep 17 00:00:00 2001 From: tcit Date: Wed, 14 May 2014 18:51:02 +0200 Subject: [PATCH 5/6] Simplifed function which does tag cleanup --- inc/poche/Database.class.php | 17 +++++++++-------- inc/poche/Poche.class.php | 6 ++++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 02e8be8..9e90197 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -512,22 +512,23 @@ class Database { return $query; } - public function cleanUnusedTags() { - $sql_action = "SELECT tags.* FROM tags JOIN tags_entries ON tags_entries.tag_id=tags.id"; - $query = $this->executeQuery($sql_action,array()); + public function cleanUnusedTag($tag_id) { + $sql_action = "SELECT tags.* FROM tags JOIN tags_entries ON tags_entries.tag_id=tags.id WHERE tags.id=?"; + $query = $this->executeQuery($sql_action,array($tag_id)); $tagstokeep = $query->fetchAll(); - $sql_action = "SELECT tags.* FROM tags LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id"; - $query = $this->executeQuery($sql_action,array()); + $sql_action = "SELECT tags.* FROM tags LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id WHERE tags.id=?"; + $query = $this->executeQuery($sql_action,array($tag_id)); $alltags = $query->fetchAll(); + foreach ($alltags as $tag) { if ($tag && !in_array($tag,$tagstokeep)) { - //delete tag $sql_action = "DELETE FROM tags WHERE id=?"; $params_action = array($tag[0]); - $query = $this->executeQuery($sql_action, $params_action); - return $query; + $this->executeQuery($sql_action, $params_action); + return true; } } + } public function retrieveTagByValue($value) { diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 8ea5e7a..515d4ca 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; From 4555c38d3b857bf91ed383f379d9697ed6a79860 Mon Sep 17 00:00:00 2001 From: tcit Date: Wed, 14 May 2014 19:08:33 +0200 Subject: [PATCH 6/6] Changed theme for better translation method --- themes/baggy/home.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/baggy/home.twig b/themes/baggy/home.twig index 92a3c86..8df5ce1 100755 --- a/themes/baggy/home.twig +++ b/themes/baggy/home.twig @@ -25,7 +25,7 @@ {% block pager %} {% if nb_results > 1 %}
-
{{ nb_results }} {% trans "results" %}{% if search_term is defined %}{% trans " found for « " %} {{ search_term }} »{% endif %}
+
{{ nb_results }} {% trans "results" %}{% if search_term is defined %} {% trans %}found for « {{ search_term }} »{% endtrans %}{% endif %}
{{ page_links | raw }}
{% elseif nb_results == 1 %} @@ -57,7 +57,7 @@ {% endfor %} {% if view == 'home' %}{% if nb_results > 1 %}{{ "Mark all the entries as read" }}{% endif %}{% endif %} - {% if search_term is defined %}{% trans "Apply the tag" %} {{ search_term }} {% trans "to this search" %}{% endif %} + {% if search_term is defined %}{% trans %} Apply the tag {{ search_term }} to this search {% endtrans %}{% endif %} {% endif %} {{ block('pager') }} {% endblock %}