diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 8e9ee0b..a89bce4 100644 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -258,6 +258,27 @@ class Database { return $tags; } + public function retrieveTag($id) { + $tag = NULL; + $sql = "SELECT * FROM tags WHERE id=?"; + $params = array(intval($id)); + $query = $this->executeQuery($sql, $params); + $tag = $query->fetchAll(); + + return isset($tag[0]) ? $tag[0] : null; + } + + public function retrieveEntriesByTag($tag_id) { + $sql = + "SELECT * FROM entries + LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id + WHERE tags_entries.tag_id = ?"; + $query = $this->executeQuery($sql, array($tag_id)); + $entries = $query->fetchAll(); + + return $entries; + } + public function retrieveTagsByEntry($entry_id) { $sql = "SELECT * FROM tags diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 5d36884..fefbb02 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -437,6 +437,14 @@ class Poche 'tags' => $tags, ); break; + case 'tag': + $entries = $this->store->retrieveEntriesByTag($id); + $tag = $this->store->retrieveTag($id); + $tpl_vars = array( + 'tag' => $tag, + 'entries' => $entries, + ); + break; case 'tags': $tags = $this->store->retrieveAllTags(); $tpl_vars = array( diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index b0ef55f..6da5302 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -90,7 +90,7 @@ class Tools { $views = array( 'install', 'import', 'export', 'config', 'tags', - 'edit-tags', 'view', 'login', 'error' + 'edit-tags', 'view', 'login', 'error', 'tag' ); if (in_array($view, $views)) { diff --git a/themes/default/tag.twig b/themes/default/tag.twig new file mode 100644 index 0000000..364c7cd --- /dev/null +++ b/themes/default/tag.twig @@ -0,0 +1,33 @@ +{% extends "layout.twig" %} +{% block title %}tag {% endblock %} +{% block menu %} +{% include '_menu.twig' %} +{% endblock %} +{% block content %} +

{% trans "Tag" %} {{ tag.value }}

+ {% if entries is empty %} +

{% trans "No link available here!" %}

+ {% else %} + {% block pager %} + {% if nb_results > 1 %} +
+
{{ nb_results }} {% trans "results" %}
+ {{ page_links | raw }} +
+ {% endif %} + {% endblock %} + {% for entry in entries %} +
+

{{ entry.title|raw }}

+ +

{{ entry.content|striptags|slice(0, 300) }}...

+
+ {% endfor %} + {% endif %} +{% endblock %} \ No newline at end of file diff --git a/themes/default/tags.twig b/themes/default/tags.twig index 9421fe3..e179143 100644 --- a/themes/default/tags.twig +++ b/themes/default/tags.twig @@ -4,5 +4,5 @@ {% include '_menu.twig' %} {% endblock %} {% block content %} -{% for tag in tags %}{{ tag.value }} {% endfor %} +{% for tag in tags %}{{ tag.value }} {% endfor %} {% endblock %} \ No newline at end of file diff --git a/themes/default/view.twig b/themes/default/view.twig index 9f9e23c..7e096a9 100644 --- a/themes/default/view.twig +++ b/themes/default/view.twig @@ -21,7 +21,7 @@

{{ entry.title|raw }}

{{ content | raw }}