diff options
| -rw-r--r-- | app/Models/Entry.php | 2 | ||||
| -rw-r--r-- | app/views/index/rss.phtml | 36 |
2 files changed, 24 insertions, 14 deletions
diff --git a/app/Models/Entry.php b/app/Models/Entry.php index d3cfa07de..9caca1fb7 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -314,7 +314,7 @@ HTML; } /** - * @return array{'url':string,'type'?:string,'medium'?:string,'length'?:int,'title'?:string,'description'?:string,'credit'?:string,'height'?:int,'width'?:int,'thumbnails'?:array<string>}|null + * @return array{'url':string,'height'?:int,'width'?:int,'time'?:string}|null */ public function thumbnail(bool $searchEnclosures = true): ?array { $thumbnail = $this->attributeArray('thumbnail') ?? []; diff --git a/app/views/index/rss.phtml b/app/views/index/rss.phtml index 0205b0703..1c036abd2 100644 --- a/app/views/index/rss.phtml +++ b/app/views/index/rss.phtml @@ -41,28 +41,38 @@ foreach ($this->entries as $item) { echo "\t\t\t", '<category>', $category, '</category>', "\n"; } } + + $enclosures = iterator_to_array($item->enclosures(false)); $thumbnail = $item->thumbnail(false); if (!empty($thumbnail['url'])) { // https://www.rssboard.org/media-rss#media-thumbnails echo "\t\t\t", '<media:thumbnail url="' . $thumbnail['url'] . (empty($thumbnail['width']) ? '' : '" width="' . $thumbnail['width']) . (empty($thumbnail['height']) ? '' : '" height="' . $thumbnail['height']) - . (empty($thumbnail['type']) ? '' : '" type="' . $thumbnail['type']) + . (empty($thumbnail['time']) ? '' : '" time="' . $thumbnail['time']) . '" />', "\n"; + // Mostly for MailChimp + Feedbro which do not support <media:thumbnail> https://mailchimp.com/help/rss-merge-tags/ + $thumbnail['medium'] ??= 'image'; + array_unshift($enclosures, $thumbnail); } - $enclosures = $item->enclosures(false); - if (is_iterable($enclosures)) { - foreach ($enclosures as $enclosure) { - // https://www.rssboard.org/media-rss - echo "\t\t\t", '<media:content url="' . $enclosure['url'] - . (empty($enclosure['medium']) ? '' : '" medium="' . $enclosure['medium']) - . (empty($enclosure['type']) ? '' : '" type="' . $enclosure['type']) - . (empty($enclosure['length']) ? '' : '" length="' . $enclosure['length']) - . '">' - . (empty($enclosure['title']) ? '' : '<media:title type="html">' . $enclosure['title'] . '</media:title>') - . (empty($enclosure['credit']) ? '' : '<media:credit>' . $enclosure['credit'] . '</media:credit>') - . '</media:content>', "\n"; + + $urls = []; + foreach ($enclosures as $enclosure) { + if (empty($enclosure['url']) || isset($urls[$enclosure['url']])) { + continue; } + $urls[$enclosure['url']] = true; + // https://www.rssboard.org/media-rss + echo "\t\t\t", '<media:content url="' . $enclosure['url'] + . (empty($enclosure['medium']) ? '' : '" medium="' . $enclosure['medium']) + . (empty($enclosure['type']) ? '' : '" type="' . $enclosure['type']) + . (empty($enclosure['length']) ? '' : '" length="' . $enclosure['length']) + . (empty($enclosure['height']) ? '' : '" height="' . $enclosure['height']) + . (empty($enclosure['width']) ? '' : '" width="' . $enclosure['width']) + . '">' + . (empty($enclosure['title']) ? '' : '<media:title type="html">' . $enclosure['title'] . '</media:title>') + . (empty($enclosure['credit']) ? '' : '<media:credit>' . $enclosure['credit'] . '</media:credit>') + . '</media:content>', "\n"; } ?> <description><