diff options
author | Éloi Rivard <eloi.rivard@aquilenet.fr> | 2020-02-16 16:26:06 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-16 16:26:06 +0300 |
commit | 306d3cdc608343b5739b98a7d6b1e816416489c9 (patch) | |
tree | f62b93191d0677709556c7c547d4af4e9eef19d2 | |
parent | cdd15c181875dbbc62844718365c47b099027b3a (diff) |
Basic Media-RSS support (#599)
Signed-off-by: Éloi Rivard <azmeuk@gmail.com>
-rw-r--r-- | appinfo/database.xml | 10 | ||||
-rw-r--r-- | docs/plugins/README.md | 2 | ||||
-rw-r--r-- | lib/Db/Item.php | 28 | ||||
-rwxr-xr-x | lib/Fetcher/FeedFetcher.php | 10 | ||||
-rw-r--r-- | templates/part.content.php | 6 | ||||
-rw-r--r-- | tests/Integration/Fixtures/ItemFixture.php | 2 | ||||
-rw-r--r-- | tests/Unit/Controller/ExportControllerTest.php | 6 | ||||
-rw-r--r-- | tests/Unit/Db/ItemTest.php | 16 |
8 files changed, 77 insertions, 3 deletions
diff --git a/appinfo/database.xml b/appinfo/database.xml index e9c65a947..adc8f197a 100644 --- a/appinfo/database.xml +++ b/appinfo/database.xml @@ -351,6 +351,16 @@ <notnull>false</notnull> </field> <field> + <name>media_thumbnail</name> + <type>clob</type> + <notnull>false</notnull> + </field> + <field> + <name>media_description</name> + <type>clob</type> + <notnull>false</notnull> + </field> + <field> <name>feed_id</name> <type>integer</type> <length>8</length> diff --git a/docs/plugins/README.md b/docs/plugins/README.md index 3d7f968cb..97cb792ce 100644 --- a/docs/plugins/README.md +++ b/docs/plugins/README.md @@ -112,6 +112,8 @@ The **addArticleAction** method expects a function with the following parameters * **body**: the html content * **enclosureMime**: if an enclosure is added, this is the mime type * **enclosureLink**: this is the source of the enclosure + * **mediaThumbnail**: if there is a media attached, this is its thumbnail + * **mediaDescription**: if there is a media attached, this is its description * **feedId**: the feed id it belongs to * **unread**: if the article is unread (bool) * **starred**: if the article is starred (bool) diff --git a/lib/Db/Item.php b/lib/Db/Item.php index 5491dff25..e88635435 100644 --- a/lib/Db/Item.php +++ b/lib/Db/Item.php @@ -41,6 +41,10 @@ class Item extends Entity implements IAPI, \JsonSerializable protected $enclosureMime; /** @var string|null */ protected $enclosureLink; + /** @var string|null */ + protected $mediaThumbnail; + /** @var string|null */ + protected $mediaDescription; /** @var int */ protected $feedId; /** @var int */ @@ -84,6 +88,8 @@ class Item extends Entity implements IAPI, \JsonSerializable $item->setBody($import['body']); $item->setEnclosureMime($import['enclosureMime']); $item->setEnclosureLink($import['enclosureLink']); + $item->setMediaThumbnail($import['mediaThumbnail']); + $item->setMediaDescription($import['mediaDescription']); $item->setRtl($import['rtl']); $item->setUnread($import['unread']); $item->setStarred($import['starred']); @@ -259,6 +265,8 @@ class Item extends Entity implements IAPI, \JsonSerializable 'body' => $this->getBody(), 'enclosureMime' => $this->getEnclosureMime(), 'enclosureLink' => $this->getEnclosureLink(), + 'mediaThumbnail' => $this->getMediaThumbnail(), + 'mediaDescription' => $this->getMediaDescription(), 'feedId' => $this->getFeedId(), 'unread' => $this->isUnread(), 'starred' => $this->isStarred(), @@ -315,6 +323,22 @@ class Item extends Entity implements IAPI, \JsonSerializable } } + public function setMediaThumbnail(string $mediaThumbnail = null) + { + if ($this->mediaThumbnail !== $mediaThumbnail) { + $this->mediaThumbnail = $mediaThumbnail; + $this->markFieldUpdated('mediaThumbnail'); + } + } + + public function setMediaDescription(string $mediaDescription = null) + { + if ($this->mediaDescription !== $mediaDescription) { + $this->mediaDescription = $mediaDescription; + $this->markFieldUpdated('mediaDescription'); + } + } + public function setFeedId(int $feedId) { if ($this->feedId !== $feedId) { @@ -446,6 +470,8 @@ class Item extends Entity implements IAPI, \JsonSerializable 'body' => $this->getBody(), 'enclosureMime' => $this->getEnclosureMime(), 'enclosureLink' => $this->getEnclosureLink(), + 'mediaThumbnail' => $this->getMediaThumbnail(), + 'mediaDescription' => $this->getMediaDescription(), 'feedId' => $this->getFeedId(), 'unread' => $this->isUnread(), 'starred' => $this->isStarred(), @@ -468,6 +494,8 @@ class Item extends Entity implements IAPI, \JsonSerializable 'body' => $this->getBody(), 'enclosureMime' => $this->getEnclosureMime(), 'enclosureLink' => $this->getEnclosureLink(), + 'mediaThumbnail' => $this->getMediaThumbnail(), + 'mediaDescription' => $this->getMediaDescription(), 'unread' => $this->isUnread(), 'starred' => $this->isStarred(), 'feedLink' => $feeds['feed' . $this->getFeedId()]->getLink(), diff --git a/lib/Fetcher/FeedFetcher.php b/lib/Fetcher/FeedFetcher.php index a1b7e08ec..82ad86352 100755 --- a/lib/Fetcher/FeedFetcher.php +++ b/lib/Fetcher/FeedFetcher.php @@ -256,11 +256,19 @@ class FeedFetcher implements IFeedFetcher if ($parsedItem->hasMedia()) { // TODO: Fix multiple media support foreach ($parsedItem->getMedias() as $media) { - if (!$item->isSupportedMime($media->getType())) { + if (!$item->isSupportedMime($media->getType()) + && !$media->getThumbnail() + && !$media->getDescription() + ) { continue; } $item->setEnclosureMime($media->getType()); $item->setEnclosureLink($media->getUrl()); + $item->setMediaThumbnail($media->getThumbnail()); + if ($media->getDescription()) { + $description = str_replace("\n", "<br>", $media->getDescription()); + $item->setMediaDescription($description); + } } } diff --git a/templates/part.content.php b/templates/part.content.php index b7cf52243..67cd8bf50 100644 --- a/templates/part.content.php +++ b/templates/part.content.php @@ -144,6 +144,12 @@ </a> </div> + <div class="enclosure thumbnail" ng-if="item.mediaThumbnail"> + <a ng-href="{{ ::item.enclosureLink }}"><img ng-src="{{ item.mediaThumbnail|trustUrl }}" alt="" /></a> + </div> + + <div class="enclosure description" ng-if="item.mediaDescription" news-bind-html-unsafe="item.mediaDescription"></div> + <div class="body" news-bind-html-unsafe="item.body" ng-attr-dir="{{item.rtl && 'rtl'}}"></div> </div> diff --git a/tests/Integration/Fixtures/ItemFixture.php b/tests/Integration/Fixtures/ItemFixture.php index 0d1f3561a..e84b4250b 100644 --- a/tests/Integration/Fixtures/ItemFixture.php +++ b/tests/Integration/Fixtures/ItemFixture.php @@ -30,6 +30,8 @@ class ItemFixture extends Item 'body' => 'this is a body', 'enclosureMime' => 'video/mpeg', 'enclosureLink' => 'http://google.de/web.webm', + 'mediaThumbnail' => 'https://i3.ytimg.com/vi/Zgge1O9wdPY/hqdefault.jpg', + 'mediaDescription' => 'The best video ever', 'feedId' => 0, 'unread' => true, 'starred' => false, diff --git a/tests/Unit/Controller/ExportControllerTest.php b/tests/Unit/Controller/ExportControllerTest.php index 9af641c42..84ded5c6f 100644 --- a/tests/Unit/Controller/ExportControllerTest.php +++ b/tests/Unit/Controller/ExportControllerTest.php @@ -131,10 +131,12 @@ class ExportControllerTest extends TestCase $this->assertEquals( '[{"guid":"guid","url":null,"title":null,' . '"author":null,"pubDate":null,"updatedDate":null,"body":null,"enclosureMime":null,' . - '"enclosureLink":null,"unread":false,"starred":false,' . + '"enclosureLink":null,"mediaThumbnail":null,"mediaDescription":null,'. + '"unread":false,"starred":false,' . '"feedLink":"http:\/\/goo","rtl":false},{"guid":"guid","url":null,' . '"title":null,"author":null,"pubDate":null,"updatedDate":null,"body":null,' . - '"enclosureMime":null,"enclosureLink":null,"unread":false,' . + '"enclosureMime":null,"enclosureLink":null,"mediaThumbnail":null,'. + '"mediaDescription":null,"unread":false,' . '"starred":false,"feedLink":"http:\/\/gee","rtl":false}]', $return->render() ); diff --git a/tests/Unit/Db/ItemTest.php b/tests/Unit/Db/ItemTest.php index 4c725b827..65a67733c 100644 --- a/tests/Unit/Db/ItemTest.php +++ b/tests/Unit/Db/ItemTest.php @@ -79,6 +79,8 @@ class ItemTest extends TestCase $item->setBody('body'); $item->setEnclosureMime('audio/ogg'); $item->setEnclosureLink('enclink'); + $item->setMediaThumbnail('https://i2.ytimg.com/vi/E6B3uvhrcQk/hqdefault.jpg'); + $item->setMediaDescription('The best video ever'); $item->setRtl(true); $item->setFeedId(1); $item->setStatus(0); @@ -101,6 +103,8 @@ class ItemTest extends TestCase 'body' => 'body', 'enclosureMime' => 'audio/ogg', 'enclosureLink' => 'enclink', + 'mediaThumbnail' => 'https://i2.ytimg.com/vi/E6B3uvhrcQk/hqdefault.jpg', + 'mediaDescription' => 'The best video ever', 'feedId' => 1, 'unread' => true, 'starred' => true, @@ -127,6 +131,8 @@ class ItemTest extends TestCase $item->setBody('<body><div>this is a test</body>'); $item->setEnclosureMime('audio/ogg'); $item->setEnclosureLink('enclink'); + $item->setMediaThumbnail('https://i2.ytimg.com/vi/E6B3uvhrcQk/hqdefault.jpg'); + $item->setMediaDescription('The best video ever'); $item->setFeedId(1); $item->setStatus(0); $item->setRtl(true); @@ -148,6 +154,8 @@ class ItemTest extends TestCase 'body' => '<body><div>this is a test</body>', 'enclosureMime' => 'audio/ogg', 'enclosureLink' => 'enclink', + 'mediaThumbnail' => 'https://i2.ytimg.com/vi/E6B3uvhrcQk/hqdefault.jpg', + 'mediaDescription' => 'The best video ever', 'feedId' => 1, 'unread' => true, 'starred' => true, @@ -173,6 +181,8 @@ class ItemTest extends TestCase $item->setBody('body'); $item->setEnclosureMime('audio/ogg'); $item->setEnclosureLink('enclink'); + $item->setMediaThumbnail('https://i2.ytimg.com/vi/E6B3uvhrcQk/hqdefault.jpg'); + $item->setMediaDescription('The best video ever'); $item->setFeedId(1); $item->setRtl(true); $item->setStatus(0); @@ -195,6 +205,8 @@ class ItemTest extends TestCase 'body' => 'body', 'enclosureMime' => 'audio/ogg', 'enclosureLink' => 'enclink', + 'mediaThumbnail' => 'https://i2.ytimg.com/vi/E6B3uvhrcQk/hqdefault.jpg', + 'mediaDescription' => 'The best video ever', 'unread' => false, 'starred' => true, 'feedLink' => 'http://test', @@ -257,6 +269,8 @@ class ItemTest extends TestCase 'body' => $item->getBody(), 'enclosureMime' => $item->getEnclosureMime(), 'enclosureLink' => $item->getEnclosureLink(), + 'mediaThumbnail' => $item->getMediaThumbnail(), + 'mediaDescription' => $item->getMediaDescription(), 'unread' => $item->isUnread(), 'starred' => $item->isStarred(), 'rtl' => $item->getRtl() @@ -282,6 +296,8 @@ class ItemTest extends TestCase 'body' => $item->getBody(), 'enclosureMime' => $item->getEnclosureMime(), 'enclosureLink' => $item->getEnclosureLink(), + 'mediaThumbnail' => $item->getMediaThumbnail(), + 'mediaDescription' => $item->getMediaDescription(), 'unread' => $item->isUnread(), 'starred' => $item->isStarred(), 'rtl' => $item->getRtl() |