зеркало из https://github.com/nextcloud/news.git
also set the feed location
This commit is contained in:
Родитель
b1e7d7b084
Коммит
91f302245e
|
@ -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();
|
||||
|
||||
$link = $parsedFeed->getUrl();
|
||||
|
||||
if (!$link) {
|
||||
$link = $location;
|
||||
}
|
||||
|
||||
// unescape content because angularjs helps against XSS
|
||||
$title = strip_tags($this->decodeTwice($parsedFeed->getTitle()));
|
||||
|
||||
// if there is no title use the url
|
||||
if(!$title) {
|
||||
$title = $url;
|
||||
}
|
||||
|
||||
$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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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');
|
||||
|
|
Загрузка…
Ссылка в новой задаче