From c6ca59fcb238a2e408ccd20b31b75101e19a9242 Mon Sep 17 00:00:00 2001 From: emkael Date: Sun, 15 Oct 2017 22:49:15 +0200 Subject: * RSS-to-RSS converter for "broken" feeds --- providers/Rss.php | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 providers/Rss.php (limited to 'providers') diff --git a/providers/Rss.php b/providers/Rss.php new file mode 100644 index 0000000..6fdae6c --- /dev/null +++ b/providers/Rss.php @@ -0,0 +1,69 @@ +_feedUrl = $config[$feed]; + } else { + throw new Exception('RSS feed "' . $feed . '" undefined'); + } + } + + protected function _getCachePath() { + return '../cache/rss.%s'; + } + + protected function _fetchItems() { + $this->_feedXml = new \SimpleXMLElement($this->_feedUrl, 0, TRUE); + $feedItems = $this->_feedXml->channel->item ?: $this->_feedXml->entry; + $items = []; + foreach ($feedItems as $item) { + $items[] = $item->asXML(); + } + return $items; + } + + protected function _mapItems($content) { + $items = []; + foreach ($content as $contentString) { + $item = new \SimpleXMLElement($contentString); + $itemObject = new Item(); + $itemObject->ID = strval($item->id ?: $item->guid); + $itemObject->Title = strval($item->title); + $itemObject->Time = strval($item->updated ?: $item->pubDate); + $itemObject->Text = strval($item->summary ?: $item->description); + $itemObject->Link = strval(is_string($item->link) ? $item->link : $item->link->attributes()['href']); + $itemObject->Author = strval(is_string($item->author) ? $item->author : $item->author->name); + $items[] = $itemObject; + } + return $items; + } + + protected function _spamFilter($content) { + return $content; + } + + protected function _sortContent($content) { + return $content; + } + + public function title() { + return strval($this->_feedXml->title ?: $this->_feedXml->channel->title); + } + +} + +?> -- cgit v1.2.3