]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
[RSS] introducing query param 'limit' to restrict the number of items to display... 1003/head
authorVincent Malley <vincent.malley@insalien.org>
Fri, 16 Jan 2015 16:42:39 +0000 (11:42 -0500)
committerVincent Malley <vincent.malley@insalien.org>
Fri, 16 Jan 2015 16:42:39 +0000 (11:42 -0500)
inc/poche/Poche.class.php
inc/poche/Routing.class.php

index 20897c61da7e1f60c4e0c647f4e28466bd6f3195..6a742019fbbd03d111685a1dce13acdc07e1eb7d 100755 (executable)
@@ -784,10 +784,11 @@ class Poche
      *
      * @param $token
      * @param $user_id
-     * @param $tag_id
-     * @param string $type
+     * @param $tag_id if $type is 'tag', the id of the tag to generate feed for
+     * @param string $type the type of feed to generate
+     * @param int $limit the maximum number of items (0 means all)
      */
-    public function generateFeeds($token, $user_id, $tag_id, $type = 'home')
+    public function generateFeeds($token, $user_id, $tag_id, $type = 'home', $limit = 0)
     {
         $allowed_types = array('home', 'fav', 'archive', 'tag');
         $config = $this->store->getConfigUser($user_id);
@@ -814,8 +815,13 @@ class Poche
             $entries = $this->store->getEntriesByView($type, $user_id);
         }
 
+        // if $limit is set to zero, use all entries
+        if (0 == $limit) {
+            $limit = count($entries);
+        }
         if (count($entries) > 0) {
-            foreach ($entries as $entry) {
+            for ($i = 0; $i < min(count($entries), $limit); $i++) {
+                $entry = $entries[$i];
                 $newItem = $feed->createNewItem();
                 $newItem->setTitle($entry['title']);
                 $newItem->setSource(Tools::getPocheUrl() . '?view=view&amp;id=' . $entry['id']);
index 5acd08ba608d0704b8d6a76e2152363ba4afe808..be06a433dce544c17a72c5d015a4b0f083348fe6 100755 (executable)
@@ -102,7 +102,8 @@ class Routing
                $this->wallabag->login($this->referer);
         } elseif (isset($_GET['feed']) && isset($_GET['user_id'])) {
             $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0);
-            $this->wallabag->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type']);
+            $limit = (isset($_GET['limit']) ? intval($_GET['limit']) : 0);
+            $this->wallabag->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type'], $limit);
         }
         
         //allowed ONLY to logged in user