fix(rss): set ❬itunes:author❭ tag to owner_name if publisher not specified

some platforms require the ❬itunes:author❭ tag to be specified in order to import an rss feed

fixes #96
This commit is contained in:
Yassine Doghri 2021-04-07 10:28:07 +00:00
parent 0cd6b80847
commit 2271c1445b
No known key found for this signature in database
GPG Key ID: 3E7F89498B960C9F

View File

@ -27,7 +27,7 @@ function get_rss_feed($podcast, $serviceSlug = '')
'https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md'; 'https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md';
$rss = new SimpleRSSElement( $rss = new SimpleRSSElement(
"<?xml version='1.0' encoding='utf-8'?><rss version='2.0' xmlns:itunes='$itunes_namespace' xmlns:podcast='$podcast_namespace' xmlns:content='http://purl.org/rss/1.0/modules/content/'></rss>" "<?xml version='1.0' encoding='utf-8'?><rss version='2.0' xmlns:itunes='$itunes_namespace' xmlns:podcast='$podcast_namespace' xmlns:content='http://purl.org/rss/1.0/modules/content/'></rss>",
); );
$channel = $rss->addChild('channel'); $channel = $rss->addChild('channel');
@ -35,7 +35,7 @@ function get_rss_feed($podcast, $serviceSlug = '')
$atom_link = $channel->addChild( $atom_link = $channel->addChild(
'atom:link', 'atom:link',
null, null,
'http://www.w3.org/2005/Atom' 'http://www.w3.org/2005/Atom',
); );
$atom_link->addAttribute('href', $podcast->feed_url); $atom_link->addAttribute('href', $podcast->feed_url);
$atom_link->addAttribute('rel', 'self'); $atom_link->addAttribute('rel', 'self');
@ -45,18 +45,18 @@ function get_rss_feed($podcast, $serviceSlug = '')
$channel->addChild( $channel->addChild(
'new-feed-url', 'new-feed-url',
$podcast->new_feed_url, $podcast->new_feed_url,
$itunes_namespace $itunes_namespace,
); );
} }
// the last build date corresponds to the creation of the feed.xml cache // the last build date corresponds to the creation of the feed.xml cache
$channel->addChild( $channel->addChild(
'lastBuildDate', 'lastBuildDate',
(new Time('now'))->format(DATE_RFC1123) (new Time('now'))->format(DATE_RFC1123),
); );
$channel->addChild( $channel->addChild(
'generator', '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'); $channel->addChild('docs', 'https://cyber.harvard.edu/rss/rss.html');
@ -69,7 +69,7 @@ function get_rss_feed($podcast, $serviceSlug = '')
$locationElement = $channel->addChild( $locationElement = $channel->addChild(
'location', 'location',
htmlspecialchars($podcast->location_name), htmlspecialchars($podcast->location_name),
$podcast_namespace $podcast_namespace,
); );
if (!empty($podcast->location_geo)) { if (!empty($podcast->location_geo)) {
$locationElement->addAttribute('geo', $podcast->location_geo); $locationElement->addAttribute('geo', $podcast->location_geo);
@ -86,7 +86,7 @@ function get_rss_feed($podcast, $serviceSlug = '')
$recipientElement = $valueElement->addChild( $recipientElement = $valueElement->addChild(
'valueRecipient', 'valueRecipient',
null, null,
$podcast_namespace $podcast_namespace,
); );
$recipientElement->addAttribute('name', $podcast->owner_name); $recipientElement->addAttribute('name', $podcast->owner_name);
$recipientElement->addAttribute('type', 'ILP'); $recipientElement->addAttribute('type', 'ILP');
@ -97,14 +97,14 @@ function get_rss_feed($podcast, $serviceSlug = '')
->addChild( ->addChild(
'locked', 'locked',
$podcast->is_locked ? 'yes' : 'no', $podcast->is_locked ? 'yes' : 'no',
$podcast_namespace $podcast_namespace,
) )
->addAttribute('owner', $podcast->owner_email); ->addAttribute('owner', $podcast->owner_email);
if (!empty($podcast->imported_feed_url)) { if (!empty($podcast->imported_feed_url)) {
$channel->addChild( $channel->addChild(
'previousUrl', 'previousUrl',
$podcast->imported_feed_url, $podcast->imported_feed_url,
$podcast_namespace $podcast_namespace,
); );
} }
@ -112,22 +112,22 @@ function get_rss_feed($podcast, $serviceSlug = '')
$podcastingPlatformElement = $channel->addChild( $podcastingPlatformElement = $channel->addChild(
'id', 'id',
null, null,
$podcast_namespace $podcast_namespace,
); );
$podcastingPlatformElement->addAttribute( $podcastingPlatformElement->addAttribute(
'platform', 'platform',
$podcastingPlatform->slug $podcastingPlatform->slug,
); );
if (!empty($podcastingPlatform->link_content)) { if (!empty($podcastingPlatform->link_content)) {
$podcastingPlatformElement->addAttribute( $podcastingPlatformElement->addAttribute(
'id', 'id',
$podcastingPlatform->link_content $podcastingPlatform->link_content,
); );
} }
if (!empty($podcastingPlatform->link_url)) { if (!empty($podcastingPlatform->link_url)) {
$podcastingPlatformElement->addAttribute( $podcastingPlatformElement->addAttribute(
'url', 'url',
htmlspecialchars($podcastingPlatform->link_url) htmlspecialchars($podcastingPlatform->link_url),
); );
} }
} }
@ -136,13 +136,13 @@ function get_rss_feed($podcast, $serviceSlug = '')
$socialPlatformElement = $channel->addChild( $socialPlatformElement = $channel->addChild(
'social', 'social',
$socialPlatform->link_content, $socialPlatform->link_content,
$podcast_namespace $podcast_namespace,
); );
$socialPlatformElement->addAttribute('platform', $socialPlatform->slug); $socialPlatformElement->addAttribute('platform', $socialPlatform->slug);
if (!empty($socialPlatform->link_url)) { if (!empty($socialPlatform->link_url)) {
$socialPlatformElement->addAttribute( $socialPlatformElement->addAttribute(
'url', 'url',
htmlspecialchars($socialPlatform->link_url) htmlspecialchars($socialPlatform->link_url),
); );
} }
} }
@ -151,16 +151,16 @@ function get_rss_feed($podcast, $serviceSlug = '')
$fundingPlatformElement = $channel->addChild( $fundingPlatformElement = $channel->addChild(
'funding', 'funding',
$fundingPlatform->link_content, $fundingPlatform->link_content,
$podcast_namespace $podcast_namespace,
); );
$fundingPlatformElement->addAttribute( $fundingPlatformElement->addAttribute(
'platform', 'platform',
$fundingPlatform->slug $fundingPlatform->slug,
); );
if (!empty($socialPlatform->link_url)) { if (!empty($socialPlatform->link_url)) {
$fundingPlatformElement->addAttribute( $fundingPlatformElement->addAttribute(
'url', 'url',
htmlspecialchars($fundingPlatform->link_url) htmlspecialchars($fundingPlatform->link_url),
); );
} }
} }
@ -169,7 +169,7 @@ function get_rss_feed($podcast, $serviceSlug = '')
$podcastPersonElement = $channel->addChild( $podcastPersonElement = $channel->addChild(
'person', 'person',
htmlspecialchars($podcastPerson->person->full_name), htmlspecialchars($podcastPerson->person->full_name),
$podcast_namespace $podcast_namespace,
); );
if ( if (
!empty($podcastPerson->person_role) && !empty($podcastPerson->person_role) &&
@ -181,9 +181,9 @@ function get_rss_feed($podcast, $serviceSlug = '')
lang( lang(
"PersonsTaxonomy.persons.{$podcastPerson->person_group}.roles.{$podcastPerson->person_role}.label", "PersonsTaxonomy.persons.{$podcastPerson->person_group}.roles.{$podcastPerson->person_role}.label",
[], [],
'en' 'en',
) ),
) ),
); );
} }
if (!empty($podcastPerson->person_group)) { if (!empty($podcastPerson->person_group)) {
@ -193,19 +193,19 @@ function get_rss_feed($podcast, $serviceSlug = '')
lang( lang(
"PersonsTaxonomy.persons.{$podcastPerson->person_group}.label", "PersonsTaxonomy.persons.{$podcastPerson->person_group}.label",
[], [],
'en' 'en',
) ),
) ),
); );
} }
$podcastPersonElement->addAttribute( $podcastPersonElement->addAttribute(
'img', 'img',
$podcastPerson->person->image->large_url $podcastPerson->person->image->large_url,
); );
if (!empty($podcastPerson->person->information_url)) { if (!empty($podcastPerson->person->information_url)) {
$podcastPersonElement->addAttribute( $podcastPersonElement->addAttribute(
'href', 'href',
$podcastPerson->person->information_url $podcastPerson->person->information_url,
); );
} }
} }
@ -219,11 +219,14 @@ function get_rss_feed($podcast, $serviceSlug = '')
$channel->addChild( $channel->addChild(
'explicit', 'explicit',
$podcast->parental_advisory === 'explicit' ? 'true' : 'false', $podcast->parental_advisory === 'explicit' ? 'true' : 'false',
$itunes_namespace $itunes_namespace,
); );
$podcast->publisher && $channel->addChild(
$channel->addChild('author', $podcast->publisher, $itunes_namespace); 'author',
$podcast->publisher ? $podcast->publisher : $podcast->owner_name,
$itunes_namespace,
);
$channel->addChild('link', $podcast->link); $channel->addChild('link', $podcast->link);
$owner = $channel->addChild('owner', null, $itunes_namespace); $owner = $channel->addChild('owner', null, $itunes_namespace);
@ -247,7 +250,7 @@ function get_rss_feed($podcast, $serviceSlug = '')
[ [
'elements' => $podcast->custom_rss, 'elements' => $podcast->custom_rss,
], ],
$channel $channel,
); );
} }
@ -259,7 +262,9 @@ function get_rss_feed($podcast, $serviceSlug = '')
$enclosure->addAttribute( $enclosure->addAttribute(
'url', 'url',
$episode->enclosure_url . $episode->enclosure_url .
(empty($serviceSlug) ? '' : '?_from=' . urlencode($serviceSlug)) (empty($serviceSlug)
? ''
: '?_from=' . urlencode($serviceSlug)),
); );
$enclosure->addAttribute('length', $episode->enclosure_filesize); $enclosure->addAttribute('length', $episode->enclosure_filesize);
$enclosure->addAttribute('type', $episode->enclosure_mimetype); $enclosure->addAttribute('type', $episode->enclosure_mimetype);
@ -267,13 +272,13 @@ function get_rss_feed($podcast, $serviceSlug = '')
$item->addChild('guid', $episode->guid); $item->addChild('guid', $episode->guid);
$item->addChild( $item->addChild(
'pubDate', 'pubDate',
$episode->published_at->format(DATE_RFC1123) $episode->published_at->format(DATE_RFC1123),
); );
if (!empty($episode->location_name)) { if (!empty($episode->location_name)) {
$locationElement = $item->addChild( $locationElement = $item->addChild(
'location', 'location',
htmlspecialchars($episode->location_name), htmlspecialchars($episode->location_name),
$podcast_namespace $podcast_namespace,
); );
if (!empty($episode->location_geo)) { if (!empty($episode->location_geo)) {
$locationElement->addAttribute('geo', $episode->location_geo); $locationElement->addAttribute('geo', $episode->location_geo);
@ -284,18 +289,18 @@ function get_rss_feed($podcast, $serviceSlug = '')
} }
$item->addChildWithCDATA( $item->addChildWithCDATA(
'description', 'description',
$episode->getDescriptionHtml($serviceSlug) $episode->getDescriptionHtml($serviceSlug),
); );
$item->addChild( $item->addChild(
'duration', 'duration',
$episode->enclosure_duration, $episode->enclosure_duration,
$itunes_namespace $itunes_namespace,
); );
$item->addChild('link', $episode->link); $item->addChild('link', $episode->link);
$episode_itunes_image = $item->addChild( $episode_itunes_image = $item->addChild(
'image', 'image',
null, null,
$itunes_namespace $itunes_namespace,
); );
$episode_itunes_image->addAttribute('href', $episode->image->feed_url); $episode_itunes_image->addAttribute('href', $episode->image->feed_url);
@ -303,7 +308,7 @@ function get_rss_feed($podcast, $serviceSlug = '')
$item->addChild( $item->addChild(
'explicit', 'explicit',
$episode->parental_advisory === 'explicit' ? 'true' : 'false', $episode->parental_advisory === 'explicit' ? 'true' : 'false',
$itunes_namespace $itunes_namespace,
); );
$episode->number && $episode->number &&
@ -312,7 +317,7 @@ function get_rss_feed($podcast, $serviceSlug = '')
$item->addChild( $item->addChild(
'season', 'season',
$episode->season_number, $episode->season_number,
$itunes_namespace $itunes_namespace,
); );
$item->addChild('episodeType', $episode->type, $itunes_namespace); $item->addChild('episodeType', $episode->type, $itunes_namespace);
@ -320,18 +325,18 @@ function get_rss_feed($podcast, $serviceSlug = '')
$transcriptElement = $item->addChild( $transcriptElement = $item->addChild(
'transcript', 'transcript',
null, null,
$podcast_namespace $podcast_namespace,
); );
$transcriptElement->addAttribute('url', $episode->transcriptUrl); $transcriptElement->addAttribute('url', $episode->transcriptUrl);
$transcriptElement->addAttribute( $transcriptElement->addAttribute(
'type', 'type',
Mimes::guessTypeFromExtension( Mimes::guessTypeFromExtension(
pathinfo($episode->transcript_uri, PATHINFO_EXTENSION) pathinfo($episode->transcript_uri, PATHINFO_EXTENSION),
) ),
); );
$transcriptElement->addAttribute( $transcriptElement->addAttribute(
'language', 'language',
$podcast->language_code $podcast->language_code,
); );
} }
@ -339,7 +344,7 @@ function get_rss_feed($podcast, $serviceSlug = '')
$chaptersElement = $item->addChild( $chaptersElement = $item->addChild(
'chapters', 'chapters',
null, null,
$podcast_namespace $podcast_namespace,
); );
$chaptersElement->addAttribute('url', $episode->chaptersUrl); $chaptersElement->addAttribute('url', $episode->chaptersUrl);
$chaptersElement->addAttribute('type', 'application/json+chapters'); $chaptersElement->addAttribute('type', 'application/json+chapters');
@ -349,11 +354,11 @@ function get_rss_feed($podcast, $serviceSlug = '')
$soundbiteElement = $item->addChild( $soundbiteElement = $item->addChild(
'soundbite', 'soundbite',
empty($soundbite->label) ? null : $soundbite->label, empty($soundbite->label) ? null : $soundbite->label,
$podcast_namespace $podcast_namespace,
); );
$soundbiteElement->addAttribute( $soundbiteElement->addAttribute(
'start_time', 'start_time',
$soundbite->start_time $soundbite->start_time,
); );
$soundbiteElement->addAttribute('duration', $soundbite->duration); $soundbiteElement->addAttribute('duration', $soundbite->duration);
} }
@ -362,7 +367,7 @@ function get_rss_feed($podcast, $serviceSlug = '')
$episodePersonElement = $item->addChild( $episodePersonElement = $item->addChild(
'person', 'person',
htmlspecialchars($episodePerson->person->full_name), htmlspecialchars($episodePerson->person->full_name),
$podcast_namespace $podcast_namespace,
); );
if ( if (
!empty($episodePerson->person_role) && !empty($episodePerson->person_role) &&
@ -374,9 +379,9 @@ function get_rss_feed($podcast, $serviceSlug = '')
lang( lang(
"PersonsTaxonomy.persons.{$episodePerson->person_group}.roles.{$episodePerson->person_role}.label", "PersonsTaxonomy.persons.{$episodePerson->person_group}.roles.{$episodePerson->person_role}.label",
[], [],
'en' 'en',
) ),
) ),
); );
} }
if (!empty($episodePerson->person_group)) { if (!empty($episodePerson->person_group)) {
@ -386,19 +391,19 @@ function get_rss_feed($podcast, $serviceSlug = '')
lang( lang(
"PersonsTaxonomy.persons.{$episodePerson->person_group}.label", "PersonsTaxonomy.persons.{$episodePerson->person_group}.label",
[], [],
'en' 'en',
) ),
) ),
); );
} }
$episodePersonElement->addAttribute( $episodePersonElement->addAttribute(
'img', 'img',
$episodePerson->person->image->large_url $episodePerson->person->image->large_url,
); );
if (!empty($episodePerson->person->information_url)) { if (!empty($episodePerson->person->information_url)) {
$episodePersonElement->addAttribute( $episodePersonElement->addAttribute(
'href', 'href',
$episodePerson->person->information_url $episodePerson->person->information_url,
); );
} }
} }
@ -411,7 +416,7 @@ function get_rss_feed($podcast, $serviceSlug = '')
[ [
'elements' => $episode->custom_rss, 'elements' => $episode->custom_rss,
], ],
$item $item,
); );
} }
} }
@ -436,14 +441,14 @@ function add_category_tag($node, $category)
'text', 'text',
$category->parent $category->parent
? $category->parent->apple_category ? $category->parent->apple_category
: $category->apple_category : $category->apple_category,
); );
if ($category->parent) { if ($category->parent) {
$itunes_category_child = $itunes_category->addChild( $itunes_category_child = $itunes_category->addChild(
'category', 'category',
null, null,
$itunes_namespace $itunes_namespace,
); );
$itunes_category_child->addAttribute('text', $category->apple_category); $itunes_category_child->addAttribute('text', $category->apple_category);
$node->addChild('category', $category->parent->apple_category); $node->addChild('category', $category->parent->apple_category);
@ -503,7 +508,7 @@ function array_to_rss($arrayNode, &$xmlNode)
: null, : null,
empty($childArrayNode['namespace']) empty($childArrayNode['namespace'])
? null ? null
: current($childArrayNode['namespace']) : current($childArrayNode['namespace']),
); );
if (array_key_exists('attributes', $childArrayNode)) { if (array_key_exists('attributes', $childArrayNode)) {
foreach ( foreach (