[TikiWiki-commits] [Git][tikiwiki/tiki][28.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 <68a31a6b76fe4_2cd6ca4418dd@gitlab-sidekiq-low-urgency-cpu-bound-v2-5b8f9fb769-8mstj.mail>

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


Commits:
7c97bd1c by Alvin Bauma at 2025-08-18T14:13:17+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!8320

- - - - -


1 changed file:

- lib/rss/rsslib.php


Changes:

=====================================
lib/rss/rsslib.php
=====================================
@@ -363,7 +363,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;
         }
 
@@ -423,7 +423,7 @@ class RSSLib extends TikiDb_Bridge
      */
     public function refresh_rss_module($rssId)
     {
-        return $this->update_feeds([ $rssId ], true);
+        return $this->update_feeds([$rssId], true);
     }
 
     /**
@@ -1080,9 +1080,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);
 
@@ -1090,7 +1095,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));
@@ -1102,6 +1107,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/7c97bd1cd59d15bac9ad3ecfe2a1aa646f512b37

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