From f76dab12c9913e0bf4bafd8f59cccdb6bf395994 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 13 Mar 2015 16:49:20 +0100 Subject: [PATCH] fix for #1153, a couple of improvements and fixed bugs --- inc/poche/Database.class.php | 18 +++++++++++++--- inc/poche/Poche.class.php | 8 ++++--- themes/baggy/home.twig | 41 ++++++++++++++++++++++++++++++------ 3 files changed, 55 insertions(+), 12 deletions(-) diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 4f55a7fe2..823f834c8 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -411,10 +411,22 @@ class Database { return $count; } - public function getRandomId($user_id) { + public function getRandomId($user_id, $view) { $random = (STORAGE == 'mysql') ? 'RAND()' : 'RANDOM()'; - $sql = "SELECT id FROM entries WHERE user_id=? ORDER BY ". $random . " LIMIT 1"; - $params = array($user_id); + switch ($view) { + case 'archive': + $sql = "SELECT id FROM entries WHERE user_id=? AND is_read=? ORDER BY ". $random . " LIMIT 1"; + $params = array($user_id,1); + break; + case 'fav': + $sql = "SELECT id FROM entries WHERE user_id=? AND is_fav=? ORDER BY ". $random . " LIMIT 1"; + $params = array($user_id,1); + break; + default: + $sql = "SELECT id FROM entries WHERE user_id=? AND is_read=? ORDER BY ". $random . " LIMIT 1"; + $params = array($user_id,0); + break; + } $query = $this->executeQuery($sql, $params); $id = $query->fetchAll(); diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 4ec724f9f..1a5cbe6cc 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -406,8 +406,9 @@ class Poche /* For some unknown reason I can't get displayView() to work here (it redirects to home view afterwards). So here's a dirty fix which redirects directly to URL */ case 'random': Tools::logm('get a random article'); - if ($this->store->getRandomId($this->user->getId())) { - $id_array = $this->store->getRandomId($this->user->getId()); + $view = $_GET['view']; + if ($this->store->getRandomId($this->user->getId(),$view)) { + $id_array = $this->store->getRandomId($this->user->getId(),$view); $id = $id_array[0]; Tools::redirect('?view=view&id=' . $id[0]); Tools::logm('got the article with id ' . $id[0]); @@ -522,7 +523,7 @@ class Poche $this->pagination->page_links('?view=' . $view . '?search=' . $search . '&sort=' . $_SESSION['sort'] . '&' )); $tpl_vars['page_links'] = $page_links; $tpl_vars['nb_results'] = $count; - $tpl_vars['searchterm'] = $search; + $tpl_vars['search_term'] = $search; } break; case 'view': @@ -578,6 +579,7 @@ class Poche 'page_links' => '', 'nb_results' => '', 'listmode' => (isset($_COOKIE['listmode']) ? true : false), + 'view' => $view, ); //if id is given - we retrieve entries by tag: id is tag id diff --git a/themes/baggy/home.twig b/themes/baggy/home.twig index 93d2815b3..5f097f3f7 100755 --- a/themes/baggy/home.twig +++ b/themes/baggy/home.twig @@ -15,8 +15,15 @@ {% if tag %}

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

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

{% trans "No articles found." %}

+ {% if entries is empty%} +

+ {% if view == 'home' %}{% trans "No articles unread. Good job !" %} + {% elseif view == 'fav' %}{% trans "No articles favourited" %} + {% elseif view == 'archive' %}{% trans "No articles marked as read" %} + {% elseif view == 'tags' %}{% trans "No articles with this tag found" %} + {% elseif search_term is defined %} {% trans %}No articles found for « {{ search_term }} »{% endtrans %} + {% else %}{% trans "No articles found" %}{% endif %} +

{% else %}
{% include '_display-mode.twig' %} @@ -25,15 +32,35 @@ {% block pager %} {% if nb_results > 1 %}
-
{{ nb_results }} {% trans "results" %}{% if search_term is defined %} {% trans %}found for « {{ search_term }} »{% endtrans %}{% endif %} {% trans "random" %}
+
+ {% if view == 'home' %} + {{ nb_results }} {% trans "articles unread" %} + {% elseif view == 'fav' %} + {{ nb_results }} {% trans "articles favourited" %} + {% elseif view == 'archive' %} + {{ nb_results }} {% trans "articles marked as read" %} + {% elseif view == 'tag' %} + {{ nb_results }} {% trans "articles with this tag" %} + {% elseif search_term is defined %}{{ nb_results }} + {% trans %}articles found for « {{ search_term }} »{% endtrans %} + {% else %} + {{ nb_results }} {% trans "articles" %} + {% endif %} + {% if view == 'home' or view == 'fav' or view == 'archive' %} + {% trans "random" %}{% endif %} +
{{ page_links | raw }}
{% elseif nb_results == 1 %} - {% if search_term is defined %}
-
{% trans "Only one result found for " %} « {{ search_term }} »
+
+ {% if view == 'home' %}{% trans "Only one article unread. Way to go !" %} + {% elseif view == 'fav' %}{% trans "Just one article favourited" %} + {% elseif view == 'archive' %}{% trans "One article marked as read" %} + {% elseif view == 'tag' %}{% trans "One article with this tag" %} + {% elseif search_term is defined %}{% trans %}Only one result found for « {{ search_term }} »{% endtrans %} + {% else %}{% trans "One article found" %}{% endif %}
- {% endif %} {% endif %} {% endblock %}
@@ -64,6 +91,7 @@ {% if tag %}{% trans "Mark all articles from this tag as read" %}
{% endif %} + {% if entries is not empty %} {% if tag %} {% if constant('EPUB') == 1 %}{% trans "Download as ePub3" %}{% endif %} {% if constant('MOBI') == 1 %}{% trans "Download as Mobi" %}{% endif %} @@ -77,5 +105,6 @@ {% if constant('MOBI') == 1 %}{% trans "Download as Mobi" %}{% endif %} {% if constant('PDF') == 1 %}{% trans "Download as PDF" %}{% endif %} {% endif %} + {% endif %} {% endif %} {% endblock %}