diff options
-rwxr-xr-x | inc/poche/Database.class.php | 19 | ||||
-rwxr-xr-x | inc/poche/Poche.class.php | 82 | ||||
-rwxr-xr-x | themes/baggy/css/main.css | 21 | ||||
-rwxr-xr-x | themes/baggy/home.twig | 4 | ||||
-rwxr-xr-x | themes/default/js/saveLink.js | 2 |
5 files changed, 93 insertions, 35 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 141d7987..9e901974 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php | |||
@@ -511,6 +511,25 @@ class Database { | |||
511 | $query = $this->executeQuery($sql_action, $params_action); | 511 | $query = $this->executeQuery($sql_action, $params_action); |
512 | return $query; | 512 | return $query; |
513 | } | 513 | } |
514 | |||
515 | public function cleanUnusedTag($tag_id) { | ||
516 | $sql_action = "SELECT tags.* FROM tags JOIN tags_entries ON tags_entries.tag_id=tags.id WHERE tags.id=?"; | ||
517 | $query = $this->executeQuery($sql_action,array($tag_id)); | ||
518 | $tagstokeep = $query->fetchAll(); | ||
519 | $sql_action = "SELECT tags.* FROM tags LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id WHERE tags.id=?"; | ||
520 | $query = $this->executeQuery($sql_action,array($tag_id)); | ||
521 | $alltags = $query->fetchAll(); | ||
522 | |||
523 | foreach ($alltags as $tag) { | ||
524 | if ($tag && !in_array($tag,$tagstokeep)) { | ||
525 | $sql_action = "DELETE FROM tags WHERE id=?"; | ||
526 | $params_action = array($tag[0]); | ||
527 | $this->executeQuery($sql_action, $params_action); | ||
528 | return true; | ||
529 | } | ||
530 | } | ||
531 | |||
532 | } | ||
514 | 533 | ||
515 | public function retrieveTagByValue($value) { | 534 | public function retrieveTagByValue($value) { |
516 | $tag = NULL; | 535 | $tag = NULL; |
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index bce7d651..92db7d1b 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -511,42 +511,55 @@ class Poche | |||
511 | Tools::redirect(); | 511 | Tools::redirect(); |
512 | break; | 512 | break; |
513 | case 'add_tag' : | 513 | case 'add_tag' : |
514 | $tags = explode(',', $_POST['value']); | 514 | if (isset($_GET['search'])) { |
515 | $entry_id = $_POST['entry_id']; | 515 | //when we want to apply a tag to a search |
516 | $entry = $this->store->retrieveOneById($entry_id, $this->user->getId()); | 516 | $tags = array($_GET['search']); |
517 | if (!$entry) { | 517 | $allentry_ids = $this->store->search($tags[0], $this->user->getId()); |
518 | $this->messages->add('e', _('Article not found!')); | 518 | $entry_ids = array(); |
519 | Tools::logm('error : article not found'); | 519 | foreach ($allentry_ids as $eachentry) { |
520 | Tools::redirect(); | 520 | $entry_ids[] = $eachentry[0]; |
521 | } | 521 | } |
522 | //get all already set tags to preven duplicates | 522 | } else { //add a tag to a single article |
523 | $already_set_tags = array(); | 523 | $tags = explode(',', $_POST['value']); |
524 | $entry_tags = $this->store->retrieveTagsByEntry($entry_id); | 524 | $entry_ids = array($_POST['entry_id']); |
525 | foreach ($entry_tags as $tag) { | ||
526 | $already_set_tags[] = $tag['value']; | ||
527 | } | 525 | } |
528 | foreach($tags as $key => $tag_value) { | 526 | foreach($entry_ids as $entry_id) { |
529 | $value = trim($tag_value); | 527 | $entry = $this->store->retrieveOneById($entry_id, $this->user->getId()); |
530 | if ($value && !in_array($value, $already_set_tags)) { | 528 | if (!$entry) { |
531 | $tag = $this->store->retrieveTagByValue($value); | 529 | $this->messages->add('e', _('Article not found!')); |
532 | 530 | Tools::logm('error : article not found'); | |
533 | if (is_null($tag)) { | 531 | Tools::redirect(); |
534 | # we create the tag | 532 | } |
535 | $tag = $this->store->createTag($value); | 533 | //get all already set tags to preven duplicates |
536 | $sequence = ''; | 534 | $already_set_tags = array(); |
537 | if (STORAGE == 'postgres') { | 535 | $entry_tags = $this->store->retrieveTagsByEntry($entry_id); |
538 | $sequence = 'tags_id_seq'; | 536 | foreach ($entry_tags as $tag) { |
537 | $already_set_tags[] = $tag['value']; | ||
538 | } | ||
539 | foreach($tags as $key => $tag_value) { | ||
540 | $value = trim($tag_value); | ||
541 | if ($value && !in_array($value, $already_set_tags)) { | ||
542 | $tag = $this->store->retrieveTagByValue($value); | ||
543 | if (is_null($tag)) { | ||
544 | # we create the tag | ||
545 | $tag = $this->store->createTag($value); | ||
546 | $sequence = ''; | ||
547 | if (STORAGE == 'postgres') { | ||
548 | $sequence = 'tags_id_seq'; | ||
549 | } | ||
550 | $tag_id = $this->store->getLastId($sequence); | ||
551 | } | ||
552 | else { | ||
553 | $tag_id = $tag['id']; | ||
539 | } | 554 | } |
540 | $tag_id = $this->store->getLastId($sequence); | 555 | |
541 | } | 556 | # we assign the tag to the article |
542 | else { | 557 | $this->store->setTagToEntry($tag_id, $entry_id); |
543 | $tag_id = $tag['id']; | 558 | } |
544 | } | ||
545 | |||
546 | # we assign the tag to the article | ||
547 | $this->store->setTagToEntry($tag_id, $entry_id); | ||
548 | } | 559 | } |
549 | } | 560 | } |
561 | $this->messages->add('s', _('The tag has been applied successfully')); | ||
562 | Tools::logm('The tag has been applied successfully'); | ||
550 | Tools::redirect(); | 563 | Tools::redirect(); |
551 | break; | 564 | break; |
552 | case 'remove_tag' : | 565 | case 'remove_tag' : |
@@ -558,6 +571,11 @@ class Poche | |||
558 | Tools::redirect(); | 571 | Tools::redirect(); |
559 | } | 572 | } |
560 | $this->store->removeTagForEntry($id, $tag_id); | 573 | $this->store->removeTagForEntry($id, $tag_id); |
574 | Tools::logm('tag entry deleted'); | ||
575 | if ($this->store->cleanUnusedTag($tag_id)) { | ||
576 | Tools::logm('tag deleted'); | ||
577 | } | ||
578 | $this->messages->add('s', _('The tag has been successfully deleted')); | ||
561 | Tools::redirect(); | 579 | Tools::redirect(); |
562 | break; | 580 | break; |
563 | default: | 581 | default: |
diff --git a/themes/baggy/css/main.css b/themes/baggy/css/main.css index 52d8ecaa..6d3a56e1 100755 --- a/themes/baggy/css/main.css +++ b/themes/baggy/css/main.css | |||
@@ -537,7 +537,7 @@ footer a { | |||
537 | } | 537 | } |
538 | 538 | ||
539 | /* ========================================================================== | 539 | /* ========================================================================== |
540 | 2.1 = "save a link" popup div related styles | 540 | 2.1 = "save a link" related styles |
541 | ========================================================================== */ | 541 | ========================================================================== */ |
542 | 542 | ||
543 | #bagit-form, #search-form { | 543 | #bagit-form, #search-form { |
@@ -609,6 +609,25 @@ a#bagit-form-close:hover, a#search-form-close:hover { | |||
609 | padding: 0 3px 2px 3px; | 609 | padding: 0 3px 2px 3px; |
610 | } | 610 | } |
611 | 611 | ||
612 | a.add-to-wallabag-link-after { | ||
613 | visibility: hidden; | ||
614 | position: absolute; | ||
615 | opacity: 0; | ||
616 | transition-duration: 2s; | ||
617 | transition-timing-function: ease-out; | ||
618 | } | ||
619 | |||
620 | #article article a:hover + a.add-to-wallabag-link-after, a.add-to-wallabag-link-after:hover { | ||
621 | opacity: 1; | ||
622 | visibility: visible; | ||
623 | transition-duration: .3s; | ||
624 | transition-timing-function: ease-in; | ||
625 | } | ||
626 | |||
627 | a.add-to-wallabag-link-after:after { | ||
628 | content: "w"; | ||
629 | } | ||
630 | |||
612 | #add-link-result { | 631 | #add-link-result { |
613 | font-weight: bold; | 632 | font-weight: bold; |
614 | margin-top: 10px; | 633 | margin-top: 10px; |
diff --git a/themes/baggy/home.twig b/themes/baggy/home.twig index ef2e097c..3942d3bf 100755 --- a/themes/baggy/home.twig +++ b/themes/baggy/home.twig | |||
@@ -25,7 +25,7 @@ | |||
25 | {% block pager %} | 25 | {% block pager %} |
26 | {% if nb_results > 1 %} | 26 | {% if nb_results > 1 %} |
27 | <div class="results"> | 27 | <div class="results"> |
28 | <div class="nb-results">{{ nb_results }} {% trans "results" %}{% if search_term is defined %}{% trans " found for « " %} {{ search_term }} »{% endif %}</div> | 28 | <div class="nb-results">{{ nb_results }} {% trans "results" %}{% if search_term is defined %} {% trans %}found for « {{ search_term }} »{% endtrans %}{% endif %}</div> |
29 | {{ page_links | raw }} | 29 | {{ page_links | raw }} |
30 | </div> | 30 | </div> |
31 | {% elseif nb_results == 1 %} | 31 | {% elseif nb_results == 1 %} |
@@ -58,6 +58,8 @@ | |||
58 | </div> | 58 | </div> |
59 | {{ block('pager') }} | 59 | {{ block('pager') }} |
60 | {% 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 %} | 60 | {% 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 %} |
61 | |||
62 | {% 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 %} | ||
61 | 63 | ||
62 | {% if tag %}<a title="{% trans "Download the articles from this tag in an epub" %}" href="./?epub&method=tag&tag={{ tag.value }}">{% trans "Download the articles from this tag in an epub" %}</a> | 64 | {% if tag %}<a title="{% trans "Download the articles from this tag in an epub" %}" href="./?epub&method=tag&tag={{ tag.value }}">{% trans "Download the articles from this tag in an epub" %}</a> |
63 | {% elseif search_term is defined %}<a title="{% trans "Download the articles from this search in an epub" %}" href="./?epub&method=search&search={{ search_term }}">{% trans "Download the articles from this search in an epub" %}</a> | 65 | {% elseif search_term is defined %}<a title="{% trans "Download the articles from this search in an epub" %}" href="./?epub&method=search&search={{ search_term }}">{% trans "Download the articles from this search in an epub" %}</a> |
diff --git a/themes/default/js/saveLink.js b/themes/default/js/saveLink.js index bee453c0..6dbce97e 100755 --- a/themes/default/js/saveLink.js +++ b/themes/default/js/saveLink.js | |||
@@ -88,7 +88,7 @@ $.fn.ready(function() { | |||
88 | ========================================================================== */ | 88 | ========================================================================== */ |
89 | 89 | ||
90 | $("article a[href^='http']").after(function() { | 90 | $("article a[href^='http']").after(function() { |
91 | return " <a href=\"" + $(this).attr('href') + "\" class=\"add-to-wallabag-link-after\" alt=\"add to wallabag\" title=\"add to wallabag\">w</a> "; | 91 | return " <a href=\"" + $(this).attr('href') + "\" class=\"add-to-wallabag-link-after\" alt=\"add to wallabag\" title=\"add to wallabag\"></a> "; |
92 | }); | 92 | }); |
93 | 93 | ||
94 | $(".add-to-wallabag-link-after").click(function(event){ | 94 | $(".add-to-wallabag-link-after").click(function(event){ |