diff options
Diffstat (limited to 'app/Models/Entry.php')
| -rw-r--r-- | app/Models/Entry.php | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/app/Models/Entry.php b/app/Models/Entry.php index fe0cf7429..2454e4831 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -65,7 +65,9 @@ class FreshRSS_Entry extends Minz_Model { } $dao['attributes'] = empty($dao['attributes']) ? [] : json_decode($dao['attributes'], true); - if (!is_array($dao['attributes'])) { + if (is_array($dao['attributes'])) { + $dao['attributes'] = array_filter($dao['attributes'], 'is_string', ARRAY_FILTER_USE_KEY); + } else { $dao['attributes'] = []; } @@ -168,7 +170,7 @@ class FreshRSS_Entry extends Minz_Model { return preg_match('/(?P<delim>[\'"])' . preg_quote($link, '/') . '(?P=delim)/', $html) == 1; } - /** @param array{'url'?:string,'length'?:int,'medium'?:string,'type'?:string} $enclosure */ + /** @param array{url?:string,length?:int,medium?:string,type?:string} $enclosure */ private static function enclosureIsImage(array $enclosure): bool { $elink = $enclosure['url'] ?? ''; $length = $enclosure['length'] ?? 0; @@ -230,15 +232,15 @@ HTML; continue; } $credits = $enclosure['credit'] ?? ''; - $description = nl2br($enclosure['description'] ?? '', true); - $length = $enclosure['length'] ?? 0; - $medium = $enclosure['medium'] ?? ''; - $mime = $enclosure['type'] ?? ''; + $description = is_string($enclosure['description'] ?? null) ? nl2br($enclosure['description'], true) : ''; + $length = is_numeric($enclosure['length'] ?? null) ? (int)$enclosure['length'] : 0; + $medium = is_string($enclosure['medium'] ?? null) ? $enclosure['medium'] : ''; + $mime = is_string($enclosure['type'] ?? null) ? $enclosure['type'] : ''; $thumbnails = $enclosure['thumbnails'] ?? null; if (!is_array($thumbnails)) { $thumbnails = []; } - $etitle = $enclosure['title'] ?? ''; + $etitle = is_string($enclosure['title'] ?? null) ? $enclosure['title'] : ''; $content .= "\n"; $content .= '<figure class="enclosure">'; @@ -249,16 +251,16 @@ HTML; } } - if (self::enclosureIsImage($enclosure)) { + if (self::enclosureIsImage(['url' => $elink, 'length' => $length, 'medium' => $medium, 'type' => $mime])) { $content .= '<p class="enclosure-content"><img src="' . $elink . '" alt="" title="' . $etitle . '" /></p>'; } elseif ($medium === 'audio' || str_starts_with($mime, 'audio')) { $content .= '<p class="enclosure-content"><audio preload="none" src="' . $elink - . ($length == null ? '' : '" data-length="' . (int)$length) + . ($length == null ? '' : '" data-length="' . $length) . ($mime == '' ? '' : '" data-type="' . htmlspecialchars($mime, ENT_COMPAT, 'UTF-8')) . '" controls="controls" title="' . $etitle . '"></audio> <a download="" href="' . $elink . '">💾</a></p>'; } elseif ($medium === 'video' || str_starts_with($mime, 'video')) { $content .= '<p class="enclosure-content"><video preload="none" src="' . $elink - . ($length == null ? '' : '" data-length="' . (int)$length) + . ($length == null ? '' : '" data-length="' . $length) . ($mime == '' ? '' : '" data-type="' . htmlspecialchars($mime, ENT_COMPAT, 'UTF-8')) . '" controls="controls" title="' . $etitle . '"></video> <a download="" href="' . $elink . '">💾</a></p>'; } else { //e.g. application, text, unknown @@ -273,7 +275,9 @@ HTML; $credits = [$credits]; } foreach ($credits as $credit) { - $content .= '<p class="enclosure-credits">© ' . $credit . '</p>'; + if (is_string($credit)) { + $content .= '<p class="enclosure-credits">© ' . $credit . '</p>'; + } } } if ($description != '') { |
