1
0
mirror of https://github.com/moparisthebest/wallabag synced 2024-11-23 09:32:15 -05:00

Added save search as tag functionality

This commit is contained in:
tcit 2014-04-30 11:25:03 +02:00
parent 21f29fe492
commit decc23aaf2
2 changed files with 45 additions and 31 deletions

View File

@ -511,42 +511,55 @@ class Poche
Tools::redirect(); Tools::redirect();
break; break;
case 'add_tag' : case 'add_tag' :
$tags = explode(',', $_POST['value']); if (isset($_GET['search'])) {
$entry_id = $_POST['entry_id']; //when we want to apply a tag to a search
$entry = $this->store->retrieveOneById($entry_id, $this->user->getId()); $search = true;
if (!$entry) { $tags = array($_GET['search']);
$this->messages->add('e', _('Article not found!')); $allentry_ids = $this->store->search($tags[0], $this->user->getId());
Tools::logm('error : article not found'); $entry_ids = array();
Tools::redirect(); 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 foreach($entry_ids as $entry_id) {
$already_set_tags = array(); $entry = $this->store->retrieveOneById($entry_id, $this->user->getId());
$entry_tags = $this->store->retrieveTagsByEntry($entry_id); if (!$entry) {
foreach ($entry_tags as $tag) { $this->messages->add('e', _('Article not found!'));
$already_set_tags[] = $tag['value']; Tools::logm('error : article not found');
} Tools::redirect();
foreach($tags as $key => $tag_value) { }
$value = trim($tag_value); //get all already set tags to preven duplicates
if ($value && !in_array($value, $already_set_tags)) { $already_set_tags = array();
$tag = $this->store->retrieveTagByValue($value); $entry_tags = $this->store->retrieveTagsByEntry($entry_id);
foreach ($entry_tags as $tag) {
if (is_null($tag)) { $already_set_tags[] = $tag['value'];
# we create the tag }
$tag = $this->store->createTag($value); foreach($tags as $key => $tag_value) {
$sequence = ''; $value = trim($tag_value);
if (STORAGE == 'postgres') { if ($value && !in_array($value, $already_set_tags)) {
$sequence = 'tags_id_seq'; $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 # we assign the tag to the article
$this->store->setTagToEntry($tag_id, $entry_id); $this->store->setTagToEntry($tag_id, $entry_id);
}
} }
} }
$this->messages->add('s', _('the tag has been applied successfully'));
Tools::redirect(); Tools::redirect();
break; break;
case 'remove_tag' : case 'remove_tag' :

View File

@ -57,6 +57,7 @@
{% endfor %} {% endfor %}
</div> </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 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 %} {% endif %}
{{ block('pager') }} {{ block('pager') }}
{% endblock %} {% endblock %}