From 687b5e9a76423cd6a91e9fc41c1610ece0a1b083 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann <daniel.siepmann@typo3.org> Date: Tue, 17 Mar 2020 13:32:52 +0100 Subject: [PATCH] [BUGFIX] Show latest rss entries first in rss widget Sort rss entries before reducing to shown limit. Resolves: #90770 Releases: master Change-Id: Ia95d36a06408d115fb92786c361c21227f06c792 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63756 Tested-by: Richard Haeser <richard@maxserv.com> Tested-by: Georg Ringer <georg.ringer@gmail.com> Reviewed-by: Richard Haeser <richard@maxserv.com> Reviewed-by: Georg Ringer <georg.ringer@gmail.com> --- .../dashboard/Classes/Widgets/RssWidget.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/typo3/sysext/dashboard/Classes/Widgets/RssWidget.php b/typo3/sysext/dashboard/Classes/Widgets/RssWidget.php index 4adc6213ca54..979d1210a965 100644 --- a/typo3/sysext/dashboard/Classes/Widgets/RssWidget.php +++ b/typo3/sysext/dashboard/Classes/Widgets/RssWidget.php @@ -108,21 +108,20 @@ class RssWidget implements WidgetInterface throw new \RuntimeException('RSS URL could not be fetched', 1573385431); } $rssFeed = simplexml_load_string($rssContent); - $itemCount = 0; $items = []; foreach ($rssFeed->channel->item as $item) { - if ($itemCount >= $this->options['limit']) { - break; - } - $items[] = [ - 'title' => (string)$item->title, + 'title' => trim((string)$item->title), 'link' => trim((string)$item->link), - 'pubDate' => (string)$item->pubDate, - 'description' => (string)$item->description, + 'pubDate' => trim((string)$item->pubDate), + 'description' => trim((string)$item->description), ]; - $itemCount++; } + usort($items, function ($item1, $item2) { + return new \DateTime($item2['pubDate']) <=> new \DateTime($item1['pubDate']); + }); + $items = array_slice($items, 0, $this->options['limit']); + $this->cache->set($cacheHash, $items, ['dashboard_rss'], $this->options['lifeTime']); return $items; -- GitLab