summaryrefslogtreecommitdiff
path: root/providers
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2017-10-15 22:49:15 +0200
committeremkael <emkael@tlen.pl>2017-10-15 22:49:15 +0200
commitc6ca59fcb238a2e408ccd20b31b75101e19a9242 (patch)
tree2b9f7827d7f6287cfccbcbb571ebe704b5a5c0d5 /providers
parent565dc428685ae4807e63cbb84e233e99137c9ae4 (diff)
* RSS-to-RSS converter for "broken" feeds
Diffstat (limited to 'providers')
-rw-r--r--providers/Rss.php69
1 files changed, 69 insertions, 0 deletions
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 @@
+<?php
+
+namespace Providers;
+
+require_once('Provider.php');
+require_once('Item.php');
+
+class Rss extends \Providers\Provider {
+
+ protected $_cacheTimeout = '1 second';
+
+ private $_feedUrl;
+ private $_feedXml;
+
+ public function __construct($feed, $options=[]) {
+ parent::__construct($feed, $options);
+ $config = json_decode(file_get_contents('../config/rss.json'), TRUE);
+ if (isset($config[$feed])) {
+ $this->_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);
+ }
+
+}
+
+?>