[TikiWiki-commits] [Git][tikiwiki/tiki][master] [ENH] RSS Plugin : Honors max and sortBy/sortOrder for URL-based feeds.

"Alvin Bauma \(@alvinBM\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68a30b3b525d4_2ca87c449352@gitlab-sidekiq-low-urgency-cpu-bound-v2-5b8f9fb769-btl9h.mail>

Alvin Bauma pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
19f3541f by Alvin Bauma at 2025-08-18T13:07:13+02:00
[ENH] RSS Plugin : Honors max and sortBy/sortOrder for URL-based feeds.
---
* [ENH] RSS Plugin : Add Force Refresh parameter to RSS plugin for immediate feed updates and honor max for URL

See merge request tikiwiki/tiki!8303

- - - - -


1 changed file:

- lib/rss/rsslib.php


Changes:

=====================================
lib/rss/rsslib.php
=====================================
@@ -358,7 +358,7 @@ class RSSLib extends TikiDb_Bridge
 
         $ret = $this->modules->fetchAll($this->modules->all(), $conditions, $maxRecords, $offset, $this->modules->sortMode($sort_mode));
 
-        foreach ($ret as & $res) {
+        foreach ($ret as &$res) {
             $res["minutes"] = $res["refresh"] / 60;
         }
 
@@ -418,7 +418,7 @@ class RSSLib extends TikiDb_Bridge
      */
     public function refresh_rss_module($rssId)
     {
-        return $this->update_feeds([ $rssId ], true);
+        return $this->update_feeds([$rssId], true);
     }
 
     /**
@@ -1070,9 +1070,14 @@ class RSSLib extends TikiDb_Bridge
     {
         global $tikilib;
 
+        $url = $params['url'] ?? '';
+        if (! $url) {
+            return ['params' => $params, 'items' => [], 'meta' => null];
+        }
+
+        $cache_feed_key = self::$cache_feed_key . md5($url);
+        $cache_meta_key = self::$cache_meta_Key . md5($url);
         $refresh_time = $tikilib->now - $params['refresh'] * 60;
-        $cache_feed_key = self::$cache_feed_key . md5($params['url']);
-        $cache_meta_key = self::$cache_meta_Key . md5($params['url']);
         $cache_feed_items = self::$cachelib->getSerialized($cache_feed_key, '', $refresh_time);
         $cache_meta = self::$cachelib->getSerialized($cache_meta_key, '', $refresh_time);
 
@@ -1080,7 +1085,7 @@ class RSSLib extends TikiDb_Bridge
             $items = $cache_feed_items;
             $title = $cache_meta;
         } else {
-            $result = $this->update_feed($params['url']);
+            $result = $this->update_feed($url);
             $items = $result['feedData'];
             $title = $result['siteMeta'];
             self::$cachelib->cacheItem($cache_feed_key, serialize($items));
@@ -1092,6 +1097,27 @@ class RSSLib extends TikiDb_Bridge
             'author' => 1,
             'ticker' => 1,
         ]);
+
+        if (! empty($params['sortBy'])) {
+            $sortBy = $params['sortBy'];
+            $sortOrder = ! empty($params['sortOrder']) ? strtoupper($params['sortOrder']) : 'DESC';
+            if (in_array($sortBy, ['title', 'publication_date', 'author'], true)) {
+                usort($items, function ($a, $b) use ($sortBy, $sortOrder) {
+                    $va = $a[$sortBy] ?? null;
+                    $vb = $b[$sortBy] ?? null;
+                    $cmp = $sortBy === 'publication_date' ? ($va <=> $vb) : strcasecmp((string)$va, (string)$vb);
+                    return $sortOrder === 'ASC' ? $cmp : -$cmp;
+                });
+            }
+        }
+
+        if (! empty($params['max'])) {
+            $m = (int)$params['max'];
+            if ($m > 0 && count($items) > $m) {
+                $items = array_slice($items, 0, $m);
+            }
+        }
+
         return ['params' => $params, 'items' => $items, 'meta' => $title];
     }
 }



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/19f3541ff55e6e4f07c4676661e21acf07c7c86a

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/19f3541ff55e6e4f07c4676661e21acf07c7c86a
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.