diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php old mode 100644 new mode 100755 index a366e86..c998fe1 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -10,8 +10,15 @@ class Database { var $handle; + private $order = array( + 'ia' => 'ORDER BY entries.id', + 'id' => 'ORDER BY entries.id DESC', + 'ta' => 'ORDER BY lower(entries.title)', + 'td' => 'ORDER BY lower(entries.title) DESC', + 'default' => 'ORDER BY entries.id' + ); - function __construct() + function __construct() { switch (STORAGE) { case 'sqlite': @@ -257,48 +264,62 @@ class Database { $query = $this->executeQuery($sql, $params); } - public function getEntriesByView($view, $user_id, $limit = '') { - switch ($_SESSION['sort']) - { - case 'ia': - $order = 'ORDER BY id'; - break; - case 'id': - $order = 'ORDER BY id DESC'; - break; - case 'ta': - $order = 'ORDER BY lower(title)'; - break; - case 'td': - $order = 'ORDER BY lower(title) DESC'; - break; - default: - $order = 'ORDER BY id'; - break; - } - - switch ($view) - { + public function getEntriesByView($view, $user_id, $limit = '', $tag_id = 0) { + switch ($view) { case 'archive': - $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order; + $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? "; $params = array($user_id, 1); break; case 'fav' : - $sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? " . $order; + $sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? "; $params = array($user_id, 1); break; + case 'tag' : + $sql = "SELECT entries.* FROM entries + LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id + WHERE entries.user_id=? AND tags_entries.tag_id = ? "; + $params = array($user_id, $tag_id); + break; default: - $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order; + $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? "; $params = array($user_id, 0); break; } - $sql .= ' ' . $limit; + $sql .= $this->getEntriesOrder().' ' . $limit; + + $query = $this->executeQuery($sql, $params); + $entries = $query->fetchAll(); + + return $entries; + } + + public function getEntriesByViewCount($view, $user_id, $tag_id = 0) { + switch ($view) { + case 'archive': + $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? "; + $params = array($user_id, 1); + break; + case 'fav' : + $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_fav=? "; + $params = array($user_id, 1); + break; + case 'tag' : + $sql = "SELECT count(*) FROM entries + LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id + WHERE entries.user_id=? AND tags_entries.tag_id = ? "; + $params = array($user_id, $tag_id); + break; + default: + $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? "; + $params = array($user_id, 0); + break; + } $query = $this->executeQuery($sql, $params); - $entries = $query->fetchAll(); + list($count) = $query->fetch(); - return $entries; + return $count; } public function updateContent($id, $content, $user_id) { @@ -420,4 +441,14 @@ class Database { $query = $this->executeQuery($sql_action, $params_action); return $query; } + + private function getEntriesOrder() { + if (isset($_SESSION['sort']) and array_key_exists($_SESSION['sort'], $this->order)) { + return $this->order[$_SESSION['sort']]; + } + else { + return $this->order['default']; + } + } + } diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index fc9a455..23e51c7 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -585,14 +585,7 @@ class Poche $tpl_vars = array( 'entry_id' => $id, 'tags' => $tags, - ); - break; - case 'tag': - $entries = $this->store->retrieveEntriesByTag($id, $this->user->getId()); - $tag = $this->store->retrieveTag($id, $this->user->getId()); - $tpl_vars = array( - 'tag' => $tag, - 'entries' => $entries, + 'entry' => $entry, ); break; case 'tags': @@ -633,22 +626,28 @@ class Poche Tools::logm('error in view call : entry is null'); } break; - default: # home, favorites and archive views - $entries = $this->store->getEntriesByView($view, $this->user->getId()); + default: # home, favorites, archive and tag views $tpl_vars = array( 'entries' => '', 'page_links' => '', 'nb_results' => '', ); - if (count($entries) > 0) { - $this->pagination->set_total(count($entries)); + //if id is given - we retrive entries by tag: id is tag id + if ($id) { + $tpl_vars['tag'] = $this->store->retrieveTag($id, $this->user->getId()); + $tpl_vars['id'] = intval($id); + } + + $count = $this->store->getEntriesByViewCount($view, $this->user->getId(), $id); + + if ($count > 0) { + $this->pagination->set_total($count); $page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')), - $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&')); - $datas = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit()); - $tpl_vars['entries'] = $datas; + $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . (($id)?'&id='.$id:'') . '&' )); + $tpl_vars['entries'] = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit(), $id); $tpl_vars['page_links'] = $page_links; - $tpl_vars['nb_results'] = count($entries); + $tpl_vars['nb_results'] = $count; } Tools::logm('display ' . $view . ' view'); break; diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 515a08a..4ed28ed 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -92,7 +92,7 @@ class Tools { $views = array( 'install', 'import', 'export', 'config', 'tags', - 'edit-tags', 'view', 'login', 'error', 'tag' + 'edit-tags', 'view', 'login', 'error' ); if (in_array($view, $views)) { diff --git a/themes/baggy/_menu.twig b/themes/baggy/_menu.twig index 3e7a2cb..e9cd9d4 100644 --- a/themes/baggy/_menu.twig +++ b/themes/baggy/_menu.twig @@ -4,6 +4,9 @@
  • {% trans "favorites" %}
  • {% trans "archive" %}
  • {% trans "tags" %}
  • +
  • {% trans "save a link" %}
  • {% trans "config" %}
  • {% trans "logout" %}
  • - \ No newline at end of file + + + {% include '_pocheit-form.twig' %} diff --git a/themes/baggy/css/main.css b/themes/baggy/css/main.css index 45211a8..3b8220d 100755 --- a/themes/baggy/css/main.css +++ b/themes/baggy/css/main.css @@ -563,7 +563,8 @@ footer a { ========================================================================== */ .messages { - text-align: center; + text-align: left; + margin-top: 1em; } .messages > * { display: inline-block;} @@ -818,4 +819,4 @@ blockquote { #article_toolbar a { padding: 0.3em 0.4em 0.2em; } -} \ No newline at end of file +} diff --git a/themes/baggy/edit-tags.twig b/themes/baggy/edit-tags.twig index 9f11a2c..9e9012e 100644 --- a/themes/baggy/edit-tags.twig +++ b/themes/baggy/edit-tags.twig @@ -4,6 +4,9 @@ {% include '_menu.twig' %} {% endblock %} {% block content %} +
    +

    {{ entry.title|raw }} +

    {% if tags is empty %}
    no tags
    {% endif %} @@ -11,10 +14,10 @@ {% for tag in tags %}
  • {{ tag.value }}
  • {% endfor %}
    - -

    {% trans "You can enter multiple tags, separated by commas." %}

    + +

    {% trans "You can enter multiple tags, separated by commas." %}

    {% trans "return to article" %} {% endblock %} diff --git a/themes/baggy/home.twig b/themes/baggy/home.twig index 33afdbb..4f9db06 100644 --- a/themes/baggy/home.twig +++ b/themes/baggy/home.twig @@ -12,6 +12,9 @@ {% include '_menu.twig' %} {% endblock %} {% block content %} + {% if tag %} +

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

    + {% endif %} {% if entries is empty %}

    {% trans "No articles found." %}

    {% else %} @@ -40,7 +43,7 @@

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

    - + {% endfor %} {% if view == 'home' %}{% if nb_results > 1 %}{{ "Mark all the entries as read" }}{% endif %}{% endif %} diff --git a/themes/baggy/tag.twig b/themes/baggy/tag.twig deleted file mode 100644 index 141ac90..0000000 --- a/themes/baggy/tag.twig +++ /dev/null @@ -1,34 +0,0 @@ -{% 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/courgette/home.twig b/themes/courgette/home.twig index 1367ebe..416cfa4 100755 --- a/themes/courgette/home.twig +++ b/themes/courgette/home.twig @@ -14,8 +14,8 @@ {% block precontent %} {% if entries|length > 1 %} {% endif %} {% endblock %} diff --git a/themes/default/edit-tags.twig b/themes/default/edit-tags.twig index 53852d3..83f04aa 100644 --- a/themes/default/edit-tags.twig +++ b/themes/default/edit-tags.twig @@ -4,6 +4,13 @@ {% include '_menu.twig' %} {% endblock %} {% block content %} + +
    +
    +

    {{ entry.title|raw }}

    +
    +
    + {% if tags is empty %} no tags {% endif %} @@ -11,10 +18,12 @@ no tags {% for tag in tags %}
  • {{ tag.value }}
  • {% endfor %}
    - -

    {% trans "You can enter multiple tags, separated by commas." %}

    + + +

    {% trans "You can enter multiple tags, separated by commas." %}

    +
    -{% trans "return to article" %} +« {% trans "return to article" %} {% endblock %} diff --git a/themes/default/home.twig b/themes/default/home.twig index 21013ec..165fecc 100644 --- a/themes/default/home.twig +++ b/themes/default/home.twig @@ -14,12 +14,16 @@ {% block precontent %} {% if entries|length > 1 %} {% endif %} {% endblock %} {% block content %} + {% if tag %} +

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

    + {% endif %} + {% if entries is empty %}

    {% trans "No articles found." %}

    {% else %} diff --git a/themes/default/tag.twig b/themes/default/tag.twig deleted file mode 100644 index 364c7cd..0000000 --- a/themes/default/tag.twig +++ /dev/null @@ -1,33 +0,0 @@ -{% 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/view.twig b/themes/default/view.twig index 9858996..916abe0 100644 --- a/themes/default/view.twig +++ b/themes/default/view.twig @@ -20,12 +20,15 @@

    {{ entry.title|raw }}

    - + {% block tags %} + + {% endblock %}
    {{ content | raw }}
    + {{ block('tags') }} + {% endblock %} diff --git a/themes/solarized-dark/css/style-solarized-dark.css b/themes/solarized-dark/css/style-solarized-dark.css index 3b0feb2..77a97d3 100644 --- a/themes/solarized-dark/css/style-solarized-dark.css +++ b/themes/solarized-dark/css/style-solarized-dark.css @@ -217,4 +217,16 @@ a.link span { a.bad-display span { background-image: url('../img/solarized-dark/bad-display.png'); +} + +.arrow-down { + width: 0px; + height: 0px; + border-style: solid; + border-width: 10px 10px 0 10px; + border-color: #586E75 transparent transparent transparent; + + position: absolute; + margin-top: 1.5em; + margin-left: -30px; } \ No newline at end of file diff --git a/themes/solarized/css/style-solarized.css b/themes/solarized/css/style-solarized.css index 6058d05..cf16338 100644 --- a/themes/solarized/css/style-solarized.css +++ b/themes/solarized/css/style-solarized.css @@ -217,4 +217,16 @@ a.link span { a.bad-display span { background-image: url('../img/solarized/bad-display.png'); +} + +.arrow-down { + width: 0px; + height: 0px; + border-style: solid; + border-width: 10px 10px 0 10px; + border-color: #93A1A1 transparent transparent transparent; + + position: absolute; + margin-top: 1.5em; + margin-left: -30px; } \ No newline at end of file