From 82ccd9cdceca6094ade8c03c3f4be1aae5a2a502 Mon Sep 17 00:00:00 2001 From: Yassine Doghri <yassine@doghri.fr> Date: Wed, 23 Mar 2022 09:48:22 +0000 Subject: [PATCH] refactor(rss): declare atom namespace in root rss element --- app/Helpers/rss_helper.php | 12 +++++++----- app/Libraries/SimpleRSSElement.php | 7 +++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/Helpers/rss_helper.php b/app/Helpers/rss_helper.php index 0a82031c88..075112decb 100644 --- a/app/Helpers/rss_helper.php +++ b/app/Helpers/rss_helper.php @@ -30,13 +30,15 @@ if (! function_exists('get_rss_feed')) { $podcastNamespace = 'https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md'; + $atomNamespace = 'http://www.w3.org/2005/Atom'; + $rss = new SimpleRSSElement( - "<?xml version='1.0' encoding='utf-8'?><rss version='2.0' xmlns:itunes='{$itunesNamespace}' xmlns:podcast='{$podcastNamespace}' xmlns:content='http://purl.org/rss/1.0/modules/content/'></rss>", + "<?xml version='1.0' encoding='utf-8'?><rss version='2.0' xmlns:itunes='{$itunesNamespace}' xmlns:podcast='{$podcastNamespace}' xmlns:atom='{$atomNamespace}' xmlns:content='http://purl.org/rss/1.0/modules/content/'></rss>" ); $channel = $rss->addChild('channel'); - $atomLink = $channel->addChild('atom:link', null, 'http://www.w3.org/2005/Atom'); + $atomLink = $channel->addChild('link', null, $atomNamespace); $atomLink->addAttribute('href', $podcast->feed_url); $atomLink->addAttribute('rel', 'self'); $atomLink->addAttribute('type', 'application/rss+xml'); @@ -45,7 +47,7 @@ if (! function_exists('get_rss_feed')) { $websubHubs = config('WebSub') ->hubs; foreach ($websubHubs as $websubHub) { - $atomLinkHub = $channel->addChild('atom:link', null, 'http://www.w3.org/2005/Atom'); + $atomLinkHub = $channel->addChild('link', null, $atomNamespace); $atomLinkHub->addAttribute('href', $websubHub); $atomLinkHub->addAttribute('rel', 'hub'); $atomLinkHub->addAttribute('type', 'application/rss+xml'); @@ -411,7 +413,7 @@ if (! function_exists('add_category_tag')) { { $itunesNamespace = 'http://www.itunes.com/dtds/podcast-1.0.dtd'; - $itunesCategory = $node->addChild('category', '', $itunesNamespace); + $itunesCategory = $node->addChild('category', null, $itunesNamespace); $itunesCategory->addAttribute( 'text', $category->parent !== null @@ -420,7 +422,7 @@ if (! function_exists('add_category_tag')) { ); if ($category->parent !== null) { - $itunesCategoryChild = $itunesCategory->addChild('category', '', $itunesNamespace); + $itunesCategoryChild = $itunesCategory->addChild('category', null, $itunesNamespace); $itunesCategoryChild->addAttribute('text', $category->apple_category); $node->addChild('category', $category->parent->apple_category); } diff --git a/app/Libraries/SimpleRSSElement.php b/app/Libraries/SimpleRSSElement.php index 5df1f9790a..b1bebe7cfc 100644 --- a/app/Libraries/SimpleRSSElement.php +++ b/app/Libraries/SimpleRSSElement.php @@ -26,7 +26,7 @@ class SimpleRSSElement extends SimpleXMLElement */ public function addChildWithCDATA(string $name, string $value = '', ?string $namespace = null): static { - $newChild = parent::addChild($name, '', $namespace); + $newChild = parent::addChild($name, null, $namespace); if ($newChild !== null) { $node = dom_import_simplexml($newChild); @@ -54,7 +54,7 @@ class SimpleRSSElement extends SimpleXMLElement */ public function addChild($name, $value = null, $namespace = null, $escape = true): static { - $newChild = parent::addChild($name, '', $namespace); + $newChild = parent::addChild($name, null, $namespace); if ($newChild !== null) { $node = dom_import_simplexml($newChild); @@ -69,8 +69,7 @@ class SimpleRSSElement extends SimpleXMLElement return $newChild; } - /** @noRector RecastingRemovalRector */ - $node->appendChild($no->createTextNode((string) $value)); + $node->appendChild($no->createTextNode($value)); } } -- GitLab