mirror of
https://github.com/moparisthebest/wallabag
synced 2024-11-23 09:32:15 -05:00
commit
60c3a4d3e1
@ -511,6 +511,25 @@ class Database {
|
|||||||
$query = $this->executeQuery($sql_action, $params_action);
|
$query = $this->executeQuery($sql_action, $params_action);
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 WHERE tags.id=?";
|
||||||
|
$query = $this->executeQuery($sql_action,array($tag_id));
|
||||||
|
$alltags = $query->fetchAll();
|
||||||
|
|
||||||
|
foreach ($alltags as $tag) {
|
||||||
|
if ($tag && !in_array($tag,$tagstokeep)) {
|
||||||
|
$sql_action = "DELETE FROM tags WHERE id=?";
|
||||||
|
$params_action = array($tag[0]);
|
||||||
|
$this->executeQuery($sql_action, $params_action);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function retrieveTagByValue($value) {
|
public function retrieveTagByValue($value) {
|
||||||
$tag = NULL;
|
$tag = NULL;
|
||||||
|
@ -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());
|
$tags = array($_GET['search']);
|
||||||
if (!$entry) {
|
$allentry_ids = $this->store->search($tags[0], $this->user->getId());
|
||||||
$this->messages->add('e', _('Article not found!'));
|
$entry_ids = array();
|
||||||
Tools::logm('error : article not found');
|
foreach ($allentry_ids as $eachentry) {
|
||||||
Tools::redirect();
|
$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::logm('The tag has been applied successfully');
|
||||||
Tools::redirect();
|
Tools::redirect();
|
||||||
break;
|
break;
|
||||||
case 'remove_tag' :
|
case 'remove_tag' :
|
||||||
@ -558,6 +571,11 @@ class Poche
|
|||||||
Tools::redirect();
|
Tools::redirect();
|
||||||
}
|
}
|
||||||
$this->store->removeTagForEntry($id, $tag_id);
|
$this->store->removeTagForEntry($id, $tag_id);
|
||||||
|
Tools::logm('tag entry deleted');
|
||||||
|
if ($this->store->cleanUnusedTag($tag_id)) {
|
||||||
|
Tools::logm('tag deleted');
|
||||||
|
}
|
||||||
|
$this->messages->add('s', _('The tag has been successfully deleted'));
|
||||||
Tools::redirect();
|
Tools::redirect();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
{% block pager %}
|
{% block pager %}
|
||||||
{% if nb_results > 1 %}
|
{% if nb_results > 1 %}
|
||||||
<div class="results">
|
<div class="results">
|
||||||
<div class="nb-results">{{ nb_results }} {% trans "results" %}{% if search_term is defined %}{% trans " found for « " %} {{ search_term }} »{% endif %}</div>
|
<div class="nb-results">{{ nb_results }} {% trans "results" %}{% if search_term is defined %} {% trans %}found for « {{ search_term }} »{% endtrans %}{% endif %}</div>
|
||||||
{{ page_links | raw }}
|
{{ page_links | raw }}
|
||||||
</div>
|
</div>
|
||||||
{% elseif nb_results == 1 %}
|
{% elseif nb_results == 1 %}
|
||||||
@ -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 }} to this search {% endtrans %}" href="./?action=add_tag&search={{ search_term }}">{% trans %} Apply the tag {{ search_term }} to this search {% endtrans %}</a>{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ block('pager') }}
|
{{ block('pager') }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user