From 24299e4db23c6dff15ca17152c0ef5cb8299a57d Mon Sep 17 00:00:00 2001 From: lsmooth Date: Sun, 9 Jun 2013 01:08:12 +0200 Subject: don't update faviconLink on feed update --- utility/feedfetcher.php | 36 +++++++++++++++++++----------------- utility/ifeedfetcher.php | 6 +++--- utility/twitterfetcher.php | 10 +++++----- 3 files changed, 27 insertions(+), 25 deletions(-) (limited to 'utility') 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('setBody(str_replace('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; } diff --git a/utility/ifeedfetcher.php b/utility/ifeedfetcher.php index 2bf663c0f..c64b0a90f 100644 --- a/utility/ifeedfetcher.php +++ b/utility/ifeedfetcher.php @@ -26,16 +26,16 @@ namespace OCA\News\Utility; interface IFeedFetcher { - + /** * @param string url the url that the user entered in the add feed dialog - * box + * box * @throws FetcherException if the fetcher encounters a problem * @return array with the first element being the feed and the * second element being an array of items. Those items will be saved into * into the database */ - function fetch($url); + function fetch($url, $getFavicon=true); /** * @param string $url the url that should be fetched diff --git a/utility/twitterfetcher.php b/utility/twitterfetcher.php index 7e09ddcb9..aad22cf8e 100644 --- a/utility/twitterfetcher.php +++ b/utility/twitterfetcher.php @@ -32,10 +32,10 @@ class TwitterFetcher implements IFeedFetcher { private $fetcher; private $regex; - + public function __construct(FeedFetcher $fetcher){ $this->fetcher = $fetcher; - + // matches the following urls and extracts the username // https://twitter.com/GeorgeTakei // https://www.twitter.com/GeorgeTakei @@ -53,16 +53,16 @@ class TwitterFetcher implements IFeedFetcher { } - public function fetch($url){ + public function fetch($url, $getFavicon=true){ preg_match($this->regex, $url, $match); // FIXME: implement twitter api to be future proof // deprecated Twitter RSS API - $rssUrl = 'https://api.twitter.com/1/statuses/user_timeline.' . + $rssUrl = 'https://api.twitter.com/1/statuses/user_timeline.' . 'rss?screen_name=' . $match[1]; // use transformed url to fetch the rss feeds with the default fetcher - return $this->fetcher->fetch($rssUrl); + return $this->fetcher->fetch($rssUrl, $getFavicon); } -- cgit v1.2.3