summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-10-30 11:30:12 +0100
committerBernhard Posselt <dev@bernhard-posselt.com>2014-10-30 11:30:12 +0100
commit91f302245e14f4d40f9daa83aaef3000753d71d8 (patch)
tree3324982a3c590c855f0737b9ec606caf1f6722a7
parentb1e7d7b084b1feb579f37203d4a7c7880c970278 (diff)
also set the feed location
-rw-r--r--fetcher/feedfetcher.php46
-rw-r--r--service/feedservice.php1
-rw-r--r--tests/unit/fetcher/FeedFetcherTest.php29
3 files changed, 22 insertions, 54 deletions
diff --git a/fetcher/feedfetcher.php b/fetcher/feedfetcher.php
index 0a0f295b9..733506187 100644
--- a/fetcher/feedfetcher.php
+++ b/fetcher/feedfetcher.php
@@ -63,6 +63,7 @@ class FeedFetcher implements IFeedFetcher {
$modified = $resource->getLastModified();
$etag = $resource->getEtag();
+ $location = $resource->getUrl();
if (!$resource->isModified()) {
return [null, null];
@@ -85,14 +86,12 @@ class FeedFetcher implements IFeedFetcher {
}
$items = [];
-
- $link = $parsedFeed->getUrl();
foreach($parsedFeed->getItems() as $item) {
$items[] = $this->buildItem($item);
}
$feed = $this->buildFeed(
- $parsedFeed, $url, $getFavicon, $modified, $etag
+ $parsedFeed, $url, $getFavicon, $modified, $etag, $location
);
return [$feed, $items];
@@ -120,14 +119,15 @@ class FeedFetcher implements IFeedFetcher {
protected function buildItem($parsedItem) {
$item = new Item();
- $item->setStatus(0);
$item->setUnread();
$item->setUrl($parsedItem->getUrl());
+ $item->setGuid($parsedItem->getId());
+ $item->setPubDate($parsedItem->getDate());
+ $item->setLastModified($this->time->getTime());
// unescape content because angularjs helps against XSS
$item->setTitle($this->decodeTwice($parsedItem->getTitle()));
- $guid = $parsedItem->getId();
- $item->setGuid($guid);
+ $item->setAuthor($this->decodeTwice($parsedItem->getAuthor()));
// purification is done in the service layer
$body = $parsedItem->getContent();
@@ -135,17 +135,6 @@ class FeedFetcher implements IFeedFetcher {
mb_detect_encoding($body));
$item->setBody($body);
- // pubdate is not required. if not given use the current date
- $date = $parsedItem->getDate();
-
- $item->setPubDate($date);
-
- $item->setLastModified($this->time->getTime());
-
- $author = $parsedItem->getAuthor();
- $item->setAuthor($this->decodeTwice($author));
-
- // TODO: make it work for video files also
$enclosureUrl = $parsedItem->getEnclosureUrl();
if($enclosureUrl) {
$enclosureType = $parsedItem->getEnclosureType();
@@ -161,28 +150,23 @@ class FeedFetcher implements IFeedFetcher {
protected function buildFeed($parsedFeed, $url, $getFavicon, $modified,
- $etag) {
+ $etag, $location) {
$feed = new Feed();
- // unescape content because angularjs helps against XSS
- $title = strip_tags($this->decodeTwice($parsedFeed->getTitle()));
+ $link = $parsedFeed->getUrl();
- // if there is no title use the url
- if(!$title) {
- $title = $url;
+ if (!$link) {
+ $link = $location;
}
+ // unescape content because angularjs helps against XSS
+ $title = strip_tags($this->decodeTwice($parsedFeed->getTitle()));
$feed->setTitle($title);
- $feed->setUrl($url);
+ $feed->setUrl($url); // the url used to add the feed
+ $feed->setLocation($location); // the url where the feed was found
+ $feed->setLink($link); // <link> attribute in the feed
$feed->setLastModified($modified);
$feed->setEtag($etag);
-
- $link = $parsedFeed->getUrl();
- if (!$link) {
- $link = $url;
- }
- $feed->setLink($link);
-
$feed->setAdded($this->time->getTime());
if ($getFavicon) {
diff --git a/service/feedservice.php b/service/feedservice.php
index 4ee7cb92d..012534421 100644
--- a/service/feedservice.php
+++ b/service/feedservice.php
@@ -219,6 +219,7 @@ class FeedService extends Service {
$existingFeed->setLastModified($fetchedFeed->getLastModified());
$existingFeed->setEtag($fetchedFeed->getEtag());
+ $existingFeed->setLocation($fetchedFeed->getLocation());
$this->feedMapper->update($existingFeed);
// insert items in reverse order because the first one is
diff --git a/tests/unit/fetcher/FeedFetcherTest.php b/tests/unit/fetcher/FeedFetcherTest.php
index fad468d7a..3f837cdd8 100644
--- a/tests/unit/fetcher/FeedFetcherTest.php
+++ b/tests/unit/fetcher/FeedFetcherTest.php
@@ -47,6 +47,7 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase {
private $webFavicon;
private $modified;
private $etag;
+ private $location;
protected function setUp(){
$this->reader = $this->getMockBuilder(
@@ -133,6 +134,9 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase {
$this->client->expects($this->once())
->method('getEtag')
->will($this->returnValue($this->etag));
+ $this->client->expects($this->once())
+ ->method('getUrl')
+ ->will($this->returnValue($this->location));
if (!$modified) {
$this->reader->expects($this->never())
@@ -211,7 +215,7 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase {
private function createFeed($hasFavicon=false) {
$this->expectFeed('getTitle', $this->feedTitle);
- $this->expectFeed('getUrl', $this->feedLink, 2);
+ $this->expectFeed('getUrl', $this->feedLink);
$feed = new Feed();
$feed->setTitle('&its a title');
@@ -220,6 +224,7 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase {
$feed->setAdded($this->time);
$feed->setLastModified($this->modified);
$feed->setEtag($this->etag);
+ $feed->setLocation($this->location);
if($hasFavicon) {
$this->faviconFactory->expects($this->once())
@@ -267,28 +272,6 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase {
}
- public function testNoTitleUsesUrl(){
- $this->setUpReader($this->url);
- $this->expectFeed('getTitle', '');
- $this->expectFeed('getUrl', $this->feedLink, 2);
-
- $feed = new Feed();
- $feed->setTitle($this->url);
- $feed->setUrl($this->url);
- $feed->setLink($this->feedLink);
- $feed->setAdded($this->time);
- $feed->setFaviconLink(null);
- $feed->setLastModified($this->modified);
- $feed->setEtag($this->etag);
-
- $item = $this->createItem();
- $this->expectFeed('getItems', [$this->item]);
- $result = $this->fetcher->fetch($this->url, false);
-
- $this->assertEquals([$feed, [$item]], $result);
- }
-
-
public function testAudioEnclosure(){
$this->setUpReader($this->url);
$item = $this->createItem('audio/ogg');