From 8374e77678f9e6c65ff88ee602eb01f9bd2a6b6c Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 8 Apr 2025 02:23:10 +0200 Subject: Refactoring item mapping --- providers/Rss.php | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'providers') diff --git a/providers/Rss.php b/providers/Rss.php index 61e5321..9ef7286 100644 --- a/providers/Rss.php +++ b/providers/Rss.php @@ -28,19 +28,28 @@ class Rss extends \Providers\XmlFeed { return $items; } + protected function _parseRssItem($contentString) { + $itemString = str_replace(['content:encoded>', '', '<', 'ID = strval($item->id ?: $item->guid) ?: ltrim(parse_url(strval($item->link))['path'], '/'); + $itemObject->Title = strval($item->title); + $itemObject->Time = strval($item->published ?: $item->pubDate ?: $item->updated); + $itemObject->Text = strval($item->summary ?: $item->description ?: $item->content ?: $item->group->description); + $itemObject->Link = strval(isset($item->link['href']) ? $item->link->attributes()['href'] : $item->link); + $itemObject->Author = strval($item->creator ? $item->creator : (is_string($item->author) ? $item->author : $item->author->name)); + return $itemObject; + } + protected function _mapItems($content) { $items = []; foreach ($content as $contentString) { - $itemString = str_replace(['content:encoded>', '', '<', 'ID = strval($item->id ?: $item->guid) ?: ltrim(parse_url(strval($item->link))['path'], '/'); - $itemObject->Title = strval($item->title); - $itemObject->Time = strval($item->published ?: $item->pubDate ?: $item->updated); - $itemObject->Text = strval($item->summary ?: $item->description ?: $item->content ?: $item->group->description); - $itemObject->Link = strval(isset($item->link['href']) ? $item->link->attributes()['href'] : $item->link); - $itemObject->Author = strval($item->creator ? $item->creator : (is_string($item->author) ? $item->author : $item->author->name)); - $items[] = $itemObject; + $item = $this->_parseRssItem($contentString); + $items[] = $this->_mapRssItem($item); } return $items; } -- cgit v1.2.3