diff options
Diffstat (limited to 'utility/feedfetcher.php')
-rw-r--r-- | utility/feedfetcher.php | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/utility/feedfetcher.php b/utility/feedfetcher.php index 63e666f65..e4a9019ac 100644 --- a/utility/feedfetcher.php +++ b/utility/feedfetcher.php @@ -44,11 +44,11 @@ class FeedFetcher implements IFeedFetcher { private $time; private $purifier; - public function __construct(API $api, + public function __construct(API $api, SimplePieAPIFactory $simplePieFactory, FaviconFetcher $faviconFetcher, TimeFactory $time, - $cacheDirectory, + $cacheDirectory, $cacheDuration, $purifier){ $this->api = $api; @@ -75,13 +75,13 @@ class FeedFetcher implements IFeedFetcher { * @throws FetcherException if simple pie fails * @return array an array containing the new feed and its items */ - public function fetch($url) { + public function fetch($url, $getFavicon=true) { $simplePie = $this->simplePieFactory->getCore(); $simplePie->set_feed_url($url); $simplePie->enable_cache(true); $simplePie->set_cache_location($this->cacheDirectory); $simplePie->set_cache_duration($this->cacheDuration); - + if (!$simplePie->init()) { throw new FetcherException('Could not initialize simple pie'); } @@ -96,7 +96,7 @@ class FeedFetcher implements IFeedFetcher { } } - $feed = $this->buildFeed($simplePie, $url); + $feed = $this->buildFeed($simplePie, $url, $getFavicon); return array($feed, $items); @@ -119,7 +119,7 @@ class FeedFetcher implements IFeedFetcher { $guid = $simplePieItem->get_id(); $item->setGuid($guid); $item->setGuidHash(md5($guid)); - $item->setBody(str_replace('<a', '<a target="_blank"', + $item->setBody(str_replace('<a', '<a target="_blank"', // escape XSS $this->purifier->purify($simplePieItem->get_content()))); $item->setPubDate($simplePieItem->get_date('U')); @@ -127,12 +127,12 @@ class FeedFetcher implements IFeedFetcher { $author = $simplePieItem->get_author(); if ($author !== null) { - $name = html_entity_decode($author->get_name(), + $name = html_entity_decode($author->get_name(), ENT_COMPAT, 'UTF-8' ); if ($name) { $item->setAuthor($name); } else { - $item->setAuthor(html_entity_decode($author->get_email()), + $item->setAuthor(html_entity_decode($author->get_email()), ENT_COMPAT, 'UTF-8' ); } } @@ -151,13 +151,13 @@ class FeedFetcher implements IFeedFetcher { } - protected function buildFeed($simplePieFeed, $url) { + protected function buildFeed($simplePieFeed, $url, $getFavicon) { $feed = new Feed(); // unescape content because angularjs helps against XSS - $title = html_entity_decode($simplePieFeed->get_title(), + $title = html_entity_decode($simplePieFeed->get_title(), ENT_COMPAT, 'UTF-8' ); - + // if there is no title use the url if(!$title) { $title = $url; @@ -169,14 +169,16 @@ class FeedFetcher implements IFeedFetcher { $feed->setUrlHash(md5($url)); $feed->setAdded($this->time->getTime()); - // use the favicon from the page first since most feeds use a weird image - $favicon = $this->faviconFetcher->fetch($feed->getLink()); + if ($getFavicon) { + // use the favicon from the page first since most feeds use a weird image + $favicon = $this->faviconFetcher->fetch($feed->getLink()); + + if (!$favicon) { + $favicon = $simplePieFeed->get_image_url(); + } - if (!$favicon) { - $favicon = $simplePieFeed->get_image_url(); + $feed->setFaviconLink($favicon); } - - $feed->setFaviconLink($favicon); return $feed; } |