]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
fix for #1153, a couple of improvements and fixed bugs
authorThomas Citharel <tcit@tcit.fr>
Fri, 13 Mar 2015 15:49:20 +0000 (16:49 +0100)
committerThomas Citharel <tcit@tcit.fr>
Fri, 13 Mar 2015 15:49:20 +0000 (16:49 +0100)
inc/poche/Database.class.php
inc/poche/Poche.class.php
themes/baggy/home.twig

index 4f55a7fe20211848564d6284708acd7c0df0a1b8..823f834c866f8bac901c550f6ba77355ef44aabf 100755 (executable)
@@ -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();
 
index 4ec724f9f49ce7811d52f68df81bac102fe481f3..1a5cbe6cc9231b635113adf668cf9f9e341a0888 100755 (executable)
@@ -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
index 93d2815b3eb473a0618795485e058ba06e06d269..5f097f3f7ab2249056f69a16bd975d2dc98895bb 100755 (executable)
             {% if tag %}
                 <h3>{% trans "Tag" %}: <b>{{ tag.value }}</b></h3>
             {% endif %}
-            {% if entries is empty %}
-            <div class="messages warning"><p>{% trans "No articles found." %}</p></div>
+            {% if entries is empty%}
+            <div class="messages warning"><p>
+            {% 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 %}
+            </p></div>
             {% else %}
                  <div>
                      {% include '_display-mode.twig' %}
                 {% block pager %}
                     {% if nb_results > 1 %}
                 <div class="results">
-                    <div class="nb-results">{{ nb_results }} {% trans "results" %}{% if search_term is defined %} {% trans %}found for « {{ search_term }} »{% endtrans %}{% endif %} <a href="?action=random" class="icon icon-random"><span> {% trans "random" %}</span></a></div>
+                    <div class="nb-results">
+                    {% 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' %}
+                    <a href="?action=random&amp;view={{ view }}" class="icon icon-random"><span> {% trans "random" %}</span></a>{% endif %}
+                    </div>
                         {{ page_links | raw }}
                 </div>
                     {% elseif nb_results == 1 %}
-                        {% if search_term is defined %}
                      <div class="results">
-                        <div class="nb-results">{% trans "Only one result found for " %} « {{ search_term }} »</div>
+                        <div class="nb-results">
+                        {% 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 %}</div>
                      </div>
-                        {% endif %}
                     {% endif %}
                 {% endblock %}
             <div id="list-entries" class="list-entries">
@@ -64,6 +91,7 @@
 
             {% if tag %}<a title="{% trans "Mark all articles from this tag as read" %}" href="./?action=toggle_archive&amp;tag_id={{ tag.id }}">{% trans "Mark all articles from this tag as read" %}</a><br />{% endif %}
 
+            {% if entries is not empty %}
             {% if tag %}
             {% if constant('EPUB') == 1 %}<a title="{% trans "Download the articles from this tag in an epub file" %}" href="./?epub&amp;method=tag&amp;value={{ tag.value }}">{% trans "Download as ePub3" %}</a>{% endif %}
             {% if constant('MOBI') == 1 %}<a title="{% trans "Download the articles from this tag in a mobi file" %}" href="./?mobi&amp;method=tag&amp;value={{ tag.value }}">{% trans "Download as Mobi" %}</a>{% endif %}
             {% if constant('MOBI') == 1 %}<a title="{% trans "Download the articles from this category in a mobi file" %}" href="./?mobi&amp;method=category&amp;value={{ view }}">{% trans "Download as Mobi" %}</a>{% endif %}
             {% if constant('PDF') == 1 %}<a title="{% trans "Download the articles from this category in a pdf file" %}" href="./?pdf&amp;method=category&amp;value={{ view }}">{% trans "Download as PDF" %}</a>{% endif %}
             {% endif %}
+            {% endif %}
 {% endif %}
 {% endblock %}