]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Added save search as tag functionality
authortcit <tcit@tcit.fr>
Wed, 30 Apr 2014 09:25:03 +0000 (11:25 +0200)
committertcit <tcit@tcit.fr>
Wed, 30 Apr 2014 09:25:03 +0000 (11:25 +0200)
inc/poche/Poche.class.php
themes/baggy/home.twig

index 5aa6ea072f70b5d7b0b0ef6920c3400fbe345013..429c13b875c1fac48eb6e21aacd09f0510480d8a 100755 (executable)
@@ -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' :
index 5dd91307748bd7c40a75908f540bcd808f90cee5..92a3c8664775655486ca72dba5cedf93f0966d1e 100755 (executable)
@@ -57,6 +57,7 @@
                 {% endfor %}
             </div>
             {% if view == 'home' %}{% if nb_results > 1 %}<a title="{% trans "Mark all the entries as read" %}"  href="./?action=archive_all">{{ "Mark all the entries as read" }}</a>{% endif %}{% endif %}
+            {% if search_term is defined %}<a title="{% trans "Apply the tag" %} {{ search_term }} {% trans "to this search" %}" href="./?action=add_tag&search={{ search_term }}">{% trans "Apply the tag" %} {{ search_term }} {% trans "to this search" %}</a>{% endif %}
             {% endif %}
             {{ block('pager') }}
 {% endblock %}