summaryrefslogtreecommitdiff
path: root/providers/Rss.php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2025-04-08 02:23:10 +0200
committeremkael <emkael@tlen.pl>2025-04-08 02:23:10 +0200
commit8374e77678f9e6c65ff88ee602eb01f9bd2a6b6c (patch)
treee607a9dc99e37430cf16d4e22dede8627435c8e9 /providers/Rss.php
parent063a161bf7ca2bb3f5eb6a6c75d08058d158c316 (diff)
Refactoring item mapping
Diffstat (limited to 'providers/Rss.php')
-rw-r--r--providers/Rss.php29
1 files changed, 19 insertions, 10 deletions
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>', '<yt:', '</yt:', '<dc:', '</dc:', '<media:', '</media:', '<wfw:', '</wfw:'], ['content>', '<', '</', '<', '</', '<', '</', '<', '</'], $contentString);
+ $item = new \SimpleXMLElement($itemString);
+ return $item;
+ }
+
+ protected function _mapRssItem($item) {
+ $itemObject = new Item();
+ $itemObject->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>', '<yt:', '</yt:', '<dc:', '</dc:', '<media:', '</media:', '<wfw:', '</wfw:'], ['content>', '<', '</', '<', '</', '<', '</', '<', '</'], $contentString);
- $item = new \SimpleXMLElement($itemString);
- $itemObject = new Item();
- $itemObject->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;
}