Allow multiple authors on enclosures (#6272)

fix https://github.com/FreshRSS/FreshRSS/issues/5066
This commit is contained in:
Alexandre Alapetite 2024-04-08 11:10:10 +02:00 committed by GitHub
parent c052149e5a
commit 283341e75e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 8 deletions

View File

@ -201,7 +201,7 @@ HTML;
if (!$allowDuplicateEnclosures && self::containsLink($content, $elink)) {
continue;
}
$credit = $enclosure['credit'] ?? '';
$credits = $enclosure['credit'] ?? '';
$description = nl2br($enclosure['description'] ?? '', true);
$length = $enclosure['length'] ?? 0;
$medium = $enclosure['medium'] ?? '';
@ -238,8 +238,13 @@ HTML;
. '" title="' . $etitle . '">💾</a></p>';
}
if ($credit != '') {
$content .= '<p class="enclosure-credits">© ' . $credit . '</p>';
if ($credits != '') {
if (!is_array($credits)) {
$credits = [$credits];
}
foreach ($credits as $credit) {
$content .= '<p class="enclosure-credits">© ' . $credit . '</p>';
}
}
if ($description != '') {
$content .= '<figcaption class="enclosure-description">' . $description . '</figcaption>';
@ -250,7 +255,7 @@ HTML;
return $content;
}
/** @return Traversable<array{'url':string,'type'?:string,'medium'?:string,'length'?:int,'title'?:string,'description'?:string,'credit'?:string,'height'?:int,'width'?:int,'thumbnails'?:array<string>}> */
/** @return Traversable<array{'url':string,'type'?:string,'medium'?:string,'length'?:int,'title'?:string,'description'?:string,'credit'?:string|array<string>,'height'?:int,'width'?:int,'thumbnails'?:array<string>}> */
public function enclosures(bool $searchBodyImages = false): Traversable {
$attributeEnclosures = $this->attributeArray('enclosures');
if (is_iterable($attributeEnclosures)) {

View File

@ -520,7 +520,7 @@ class FreshRSS_Feed extends Minz_Model {
$elink = $enclosure->get_link();
if ($elink != '') {
$etitle = $enclosure->get_title() ?? '';
$credit = $enclosure->get_credit() ?? null;
$credits = $enclosure->get_credits() ?? null;
$description = $enclosure->get_description() ?? '';
$mime = strtolower($enclosure->get_type() ?? '');
$medium = strtolower($enclosure->get_medium() ?? '');
@ -534,8 +534,11 @@ class FreshRSS_Feed extends Minz_Model {
if ($etitle != '') {
$attributeEnclosure['title'] = $etitle;
}
if ($credit != null) {
$attributeEnclosure['credit'] = $credit->get_name();
if (is_array($credits)) {
$attributeEnclosure['credit'] = [];
foreach ($credits as $credit) {
$attributeEnclosure['credit'][] = $credit->get_name();
}
}
if ($description != '') {
$attributeEnclosure['description'] = $description;

View File

@ -60,6 +60,16 @@ foreach ($this->entries as $item) {
continue;
}
$urls[$enclosure['url']] = true;
$credits = $enclosure['credit'] ?? [];
if (!is_array($credits)) { // For entries < FreshRSS 1.24
$credits = [$credits];
}
$mediaCredits = '';
foreach ($credits as $credit) {
$mediaCredits = '<media:credit>' . $credit . '</media:credit>';
}
// https://www.rssboard.org/media-rss
echo "\t\t\t", '<media:content url="' . $enclosure['url']
. (empty($enclosure['medium']) ? '' : '" medium="' . $enclosure['medium'])
@ -69,7 +79,7 @@ foreach ($this->entries as $item) {
. (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>')
. $mediaCredits
. '</media:content>', "\n";
}
?>