From 2271c1445b1ded12bc53b5d23b5e59d12b17c71a Mon Sep 17 00:00:00 2001 From: Yassine Doghri Date: Wed, 7 Apr 2021 10:28:07 +0000 Subject: [PATCH] =?UTF-8?q?fix(rss):=20set=20=E2=9D=ACitunes:author?= =?UTF-8?q?=E2=9D=AD=20tag=20to=20owner=5Fname=20if=20publisher=20not=20sp?= =?UTF-8?q?ecified?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit some platforms require the ❬itunes:author❭ tag to be specified in order to import an rss feed fixes #96 --- app/Helpers/rss_helper.php | 123 +++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 59 deletions(-) diff --git a/app/Helpers/rss_helper.php b/app/Helpers/rss_helper.php index 90767aae..72e5a154 100644 --- a/app/Helpers/rss_helper.php +++ b/app/Helpers/rss_helper.php @@ -27,7 +27,7 @@ function get_rss_feed($podcast, $serviceSlug = '') 'https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md'; $rss = new SimpleRSSElement( - "" + "", ); $channel = $rss->addChild('channel'); @@ -35,7 +35,7 @@ function get_rss_feed($podcast, $serviceSlug = '') $atom_link = $channel->addChild( 'atom:link', null, - 'http://www.w3.org/2005/Atom' + 'http://www.w3.org/2005/Atom', ); $atom_link->addAttribute('href', $podcast->feed_url); $atom_link->addAttribute('rel', 'self'); @@ -45,18 +45,18 @@ function get_rss_feed($podcast, $serviceSlug = '') $channel->addChild( 'new-feed-url', $podcast->new_feed_url, - $itunes_namespace + $itunes_namespace, ); } // the last build date corresponds to the creation of the feed.xml cache $channel->addChild( 'lastBuildDate', - (new Time('now'))->format(DATE_RFC1123) + (new Time('now'))->format(DATE_RFC1123), ); $channel->addChild( 'generator', - 'Castopod 0.0.0-development - https://castopod.org/' + 'Castopod 0.0.0-development - https://castopod.org/', ); $channel->addChild('docs', 'https://cyber.harvard.edu/rss/rss.html'); @@ -69,7 +69,7 @@ function get_rss_feed($podcast, $serviceSlug = '') $locationElement = $channel->addChild( 'location', htmlspecialchars($podcast->location_name), - $podcast_namespace + $podcast_namespace, ); if (!empty($podcast->location_geo)) { $locationElement->addAttribute('geo', $podcast->location_geo); @@ -86,7 +86,7 @@ function get_rss_feed($podcast, $serviceSlug = '') $recipientElement = $valueElement->addChild( 'valueRecipient', null, - $podcast_namespace + $podcast_namespace, ); $recipientElement->addAttribute('name', $podcast->owner_name); $recipientElement->addAttribute('type', 'ILP'); @@ -97,14 +97,14 @@ function get_rss_feed($podcast, $serviceSlug = '') ->addChild( 'locked', $podcast->is_locked ? 'yes' : 'no', - $podcast_namespace + $podcast_namespace, ) ->addAttribute('owner', $podcast->owner_email); if (!empty($podcast->imported_feed_url)) { $channel->addChild( 'previousUrl', $podcast->imported_feed_url, - $podcast_namespace + $podcast_namespace, ); } @@ -112,22 +112,22 @@ function get_rss_feed($podcast, $serviceSlug = '') $podcastingPlatformElement = $channel->addChild( 'id', null, - $podcast_namespace + $podcast_namespace, ); $podcastingPlatformElement->addAttribute( 'platform', - $podcastingPlatform->slug + $podcastingPlatform->slug, ); if (!empty($podcastingPlatform->link_content)) { $podcastingPlatformElement->addAttribute( 'id', - $podcastingPlatform->link_content + $podcastingPlatform->link_content, ); } if (!empty($podcastingPlatform->link_url)) { $podcastingPlatformElement->addAttribute( 'url', - htmlspecialchars($podcastingPlatform->link_url) + htmlspecialchars($podcastingPlatform->link_url), ); } } @@ -136,13 +136,13 @@ function get_rss_feed($podcast, $serviceSlug = '') $socialPlatformElement = $channel->addChild( 'social', $socialPlatform->link_content, - $podcast_namespace + $podcast_namespace, ); $socialPlatformElement->addAttribute('platform', $socialPlatform->slug); if (!empty($socialPlatform->link_url)) { $socialPlatformElement->addAttribute( 'url', - htmlspecialchars($socialPlatform->link_url) + htmlspecialchars($socialPlatform->link_url), ); } } @@ -151,16 +151,16 @@ function get_rss_feed($podcast, $serviceSlug = '') $fundingPlatformElement = $channel->addChild( 'funding', $fundingPlatform->link_content, - $podcast_namespace + $podcast_namespace, ); $fundingPlatformElement->addAttribute( 'platform', - $fundingPlatform->slug + $fundingPlatform->slug, ); if (!empty($socialPlatform->link_url)) { $fundingPlatformElement->addAttribute( 'url', - htmlspecialchars($fundingPlatform->link_url) + htmlspecialchars($fundingPlatform->link_url), ); } } @@ -169,7 +169,7 @@ function get_rss_feed($podcast, $serviceSlug = '') $podcastPersonElement = $channel->addChild( 'person', htmlspecialchars($podcastPerson->person->full_name), - $podcast_namespace + $podcast_namespace, ); if ( !empty($podcastPerson->person_role) && @@ -181,9 +181,9 @@ function get_rss_feed($podcast, $serviceSlug = '') lang( "PersonsTaxonomy.persons.{$podcastPerson->person_group}.roles.{$podcastPerson->person_role}.label", [], - 'en' - ) - ) + 'en', + ), + ), ); } if (!empty($podcastPerson->person_group)) { @@ -193,19 +193,19 @@ function get_rss_feed($podcast, $serviceSlug = '') lang( "PersonsTaxonomy.persons.{$podcastPerson->person_group}.label", [], - 'en' - ) - ) + 'en', + ), + ), ); } $podcastPersonElement->addAttribute( 'img', - $podcastPerson->person->image->large_url + $podcastPerson->person->image->large_url, ); if (!empty($podcastPerson->person->information_url)) { $podcastPersonElement->addAttribute( 'href', - $podcastPerson->person->information_url + $podcastPerson->person->information_url, ); } } @@ -219,11 +219,14 @@ function get_rss_feed($podcast, $serviceSlug = '') $channel->addChild( 'explicit', $podcast->parental_advisory === 'explicit' ? 'true' : 'false', - $itunes_namespace + $itunes_namespace, ); - $podcast->publisher && - $channel->addChild('author', $podcast->publisher, $itunes_namespace); + $channel->addChild( + 'author', + $podcast->publisher ? $podcast->publisher : $podcast->owner_name, + $itunes_namespace, + ); $channel->addChild('link', $podcast->link); $owner = $channel->addChild('owner', null, $itunes_namespace); @@ -247,7 +250,7 @@ function get_rss_feed($podcast, $serviceSlug = '') [ 'elements' => $podcast->custom_rss, ], - $channel + $channel, ); } @@ -259,7 +262,9 @@ function get_rss_feed($podcast, $serviceSlug = '') $enclosure->addAttribute( 'url', $episode->enclosure_url . - (empty($serviceSlug) ? '' : '?_from=' . urlencode($serviceSlug)) + (empty($serviceSlug) + ? '' + : '?_from=' . urlencode($serviceSlug)), ); $enclosure->addAttribute('length', $episode->enclosure_filesize); $enclosure->addAttribute('type', $episode->enclosure_mimetype); @@ -267,13 +272,13 @@ function get_rss_feed($podcast, $serviceSlug = '') $item->addChild('guid', $episode->guid); $item->addChild( 'pubDate', - $episode->published_at->format(DATE_RFC1123) + $episode->published_at->format(DATE_RFC1123), ); if (!empty($episode->location_name)) { $locationElement = $item->addChild( 'location', htmlspecialchars($episode->location_name), - $podcast_namespace + $podcast_namespace, ); if (!empty($episode->location_geo)) { $locationElement->addAttribute('geo', $episode->location_geo); @@ -284,18 +289,18 @@ function get_rss_feed($podcast, $serviceSlug = '') } $item->addChildWithCDATA( 'description', - $episode->getDescriptionHtml($serviceSlug) + $episode->getDescriptionHtml($serviceSlug), ); $item->addChild( 'duration', $episode->enclosure_duration, - $itunes_namespace + $itunes_namespace, ); $item->addChild('link', $episode->link); $episode_itunes_image = $item->addChild( 'image', null, - $itunes_namespace + $itunes_namespace, ); $episode_itunes_image->addAttribute('href', $episode->image->feed_url); @@ -303,7 +308,7 @@ function get_rss_feed($podcast, $serviceSlug = '') $item->addChild( 'explicit', $episode->parental_advisory === 'explicit' ? 'true' : 'false', - $itunes_namespace + $itunes_namespace, ); $episode->number && @@ -312,7 +317,7 @@ function get_rss_feed($podcast, $serviceSlug = '') $item->addChild( 'season', $episode->season_number, - $itunes_namespace + $itunes_namespace, ); $item->addChild('episodeType', $episode->type, $itunes_namespace); @@ -320,18 +325,18 @@ function get_rss_feed($podcast, $serviceSlug = '') $transcriptElement = $item->addChild( 'transcript', null, - $podcast_namespace + $podcast_namespace, ); $transcriptElement->addAttribute('url', $episode->transcriptUrl); $transcriptElement->addAttribute( 'type', Mimes::guessTypeFromExtension( - pathinfo($episode->transcript_uri, PATHINFO_EXTENSION) - ) + pathinfo($episode->transcript_uri, PATHINFO_EXTENSION), + ), ); $transcriptElement->addAttribute( 'language', - $podcast->language_code + $podcast->language_code, ); } @@ -339,7 +344,7 @@ function get_rss_feed($podcast, $serviceSlug = '') $chaptersElement = $item->addChild( 'chapters', null, - $podcast_namespace + $podcast_namespace, ); $chaptersElement->addAttribute('url', $episode->chaptersUrl); $chaptersElement->addAttribute('type', 'application/json+chapters'); @@ -349,11 +354,11 @@ function get_rss_feed($podcast, $serviceSlug = '') $soundbiteElement = $item->addChild( 'soundbite', empty($soundbite->label) ? null : $soundbite->label, - $podcast_namespace + $podcast_namespace, ); $soundbiteElement->addAttribute( 'start_time', - $soundbite->start_time + $soundbite->start_time, ); $soundbiteElement->addAttribute('duration', $soundbite->duration); } @@ -362,7 +367,7 @@ function get_rss_feed($podcast, $serviceSlug = '') $episodePersonElement = $item->addChild( 'person', htmlspecialchars($episodePerson->person->full_name), - $podcast_namespace + $podcast_namespace, ); if ( !empty($episodePerson->person_role) && @@ -374,9 +379,9 @@ function get_rss_feed($podcast, $serviceSlug = '') lang( "PersonsTaxonomy.persons.{$episodePerson->person_group}.roles.{$episodePerson->person_role}.label", [], - 'en' - ) - ) + 'en', + ), + ), ); } if (!empty($episodePerson->person_group)) { @@ -386,19 +391,19 @@ function get_rss_feed($podcast, $serviceSlug = '') lang( "PersonsTaxonomy.persons.{$episodePerson->person_group}.label", [], - 'en' - ) - ) + 'en', + ), + ), ); } $episodePersonElement->addAttribute( 'img', - $episodePerson->person->image->large_url + $episodePerson->person->image->large_url, ); if (!empty($episodePerson->person->information_url)) { $episodePersonElement->addAttribute( 'href', - $episodePerson->person->information_url + $episodePerson->person->information_url, ); } } @@ -411,7 +416,7 @@ function get_rss_feed($podcast, $serviceSlug = '') [ 'elements' => $episode->custom_rss, ], - $item + $item, ); } } @@ -436,14 +441,14 @@ function add_category_tag($node, $category) 'text', $category->parent ? $category->parent->apple_category - : $category->apple_category + : $category->apple_category, ); if ($category->parent) { $itunes_category_child = $itunes_category->addChild( 'category', null, - $itunes_namespace + $itunes_namespace, ); $itunes_category_child->addAttribute('text', $category->apple_category); $node->addChild('category', $category->parent->apple_category); @@ -503,7 +508,7 @@ function array_to_rss($arrayNode, &$xmlNode) : null, empty($childArrayNode['namespace']) ? null - : current($childArrayNode['namespace']) + : current($childArrayNode['namespace']), ); if (array_key_exists('attributes', $childArrayNode)) { foreach (