From db63a940791b2df3fb0363867372c60971c57dde Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Fri, 29 Nov 2024 16:30:12 +0100 Subject: [PATCH] Ensure that the enclosure is saved right (#404) --- feed-parsers/class-feed-item.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/feed-parsers/class-feed-item.php b/feed-parsers/class-feed-item.php index 0f3457fe..031676bd 100644 --- a/feed-parsers/class-feed-item.php +++ b/feed-parsers/class-feed-item.php @@ -59,6 +59,28 @@ public function __get( $key ) { case 'updated_date': case 'date': return gmdate( 'Y-m-d H:i:s', $this->data[ $key ] ); + case 'meta': + $meta = $this->data['meta']; + if ( isset( $meta['enclosure'] ) ) { + if ( isset( $meta['enclosure']['url'] ) ) { + $url = $meta['enclosure']['url']; + $len = ''; + if ( isset( $meta['enclosure']['length'] ) ) { + $len = $meta['enclosure']['length']; + } + $mime = ''; + if ( isset( $meta['enclosure']['mime'] ) ) { + $mime = $meta['enclosure']['mime']; + } + + $meta['enclosure'] = "$url\n$len\n$mime\n"; + } else { + // An enclosure only makes sense if it has a URL. + unset( $meta['enclosure'] ); + } + } + + return $meta; } return $this->data[ $key ];