[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [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 <68a31d5fa85a9_2cd6ccc9701f@gitlab-sidekiq-low-urgency-cpu-bound-v2-5b8f9fb769-rxzqt.mail>

Alvin Bauma pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki


Commits:
49f06354 by Alvin Bauma at 2025-08-18T14:24:43+02:00
[ENH] RSS Plugin : Honors max and sortBy/sortOrder for URL-based feeds.
---
* [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

See merge request tikiwiki/tiki!8322

- - - - -


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/49f0635469455283e6ab1b1e039717acf266fabf

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/49f0635469455283e6ab1b1e039717acf266fabf
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.