summaryrefslogtreecommitdiffstats
path: root/utility
diff options
context:
space:
mode:
authorlsmooth <ls@lsmooth.de>2013-06-09 01:08:12 +0200
committerlsmooth <ls@lsmooth.de>2013-06-09 01:08:12 +0200
commit24299e4db23c6dff15ca17152c0ef5cb8299a57d (patch)
treeb48de96cefb09a1832ba4a8bf0171468cc87c9c0 /utility
parentf8d3c8bf0e3c93ffba4a16cc8294f6a394915360 (diff)
don't update faviconLink on feed update
Diffstat (limited to 'utility')
-rw-r--r--utility/feedfetcher.php36
-rw-r--r--utility/ifeedfetcher.php6
-rw-r--r--utility/twitterfetcher.php10
3 files changed, 27 insertions, 25 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;
}
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);
}