Skip to content
Snippets Groups Projects
Commit 82ccd9cd authored by Yassine Doghri's avatar Yassine Doghri
Browse files

refactor(rss): declare atom namespace in root rss element

parent 8646b4d8
Branches
Tags
No related merge requests found
...@@ -30,13 +30,15 @@ if (! function_exists('get_rss_feed')) { ...@@ -30,13 +30,15 @@ if (! function_exists('get_rss_feed')) {
$podcastNamespace = $podcastNamespace =
'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';
$atomNamespace = 'http://www.w3.org/2005/Atom';
$rss = new SimpleRSSElement( $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'); $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('href', $podcast->feed_url);
$atomLink->addAttribute('rel', 'self'); $atomLink->addAttribute('rel', 'self');
$atomLink->addAttribute('type', 'application/rss+xml'); $atomLink->addAttribute('type', 'application/rss+xml');
...@@ -45,7 +47,7 @@ if (! function_exists('get_rss_feed')) { ...@@ -45,7 +47,7 @@ if (! function_exists('get_rss_feed')) {
$websubHubs = config('WebSub') $websubHubs = config('WebSub')
->hubs; ->hubs;
foreach ($websubHubs as $websubHub) { 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('href', $websubHub);
$atomLinkHub->addAttribute('rel', 'hub'); $atomLinkHub->addAttribute('rel', 'hub');
$atomLinkHub->addAttribute('type', 'application/rss+xml'); $atomLinkHub->addAttribute('type', 'application/rss+xml');
...@@ -411,7 +413,7 @@ if (! function_exists('add_category_tag')) { ...@@ -411,7 +413,7 @@ if (! function_exists('add_category_tag')) {
{ {
$itunesNamespace = 'http://www.itunes.com/dtds/podcast-1.0.dtd'; $itunesNamespace = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
$itunesCategory = $node->addChild('category', '', $itunesNamespace); $itunesCategory = $node->addChild('category', null, $itunesNamespace);
$itunesCategory->addAttribute( $itunesCategory->addAttribute(
'text', 'text',
$category->parent !== null $category->parent !== null
...@@ -420,7 +422,7 @@ if (! function_exists('add_category_tag')) { ...@@ -420,7 +422,7 @@ if (! function_exists('add_category_tag')) {
); );
if ($category->parent !== null) { if ($category->parent !== null) {
$itunesCategoryChild = $itunesCategory->addChild('category', '', $itunesNamespace); $itunesCategoryChild = $itunesCategory->addChild('category', null, $itunesNamespace);
$itunesCategoryChild->addAttribute('text', $category->apple_category); $itunesCategoryChild->addAttribute('text', $category->apple_category);
$node->addChild('category', $category->parent->apple_category); $node->addChild('category', $category->parent->apple_category);
} }
......
...@@ -26,7 +26,7 @@ class SimpleRSSElement extends SimpleXMLElement ...@@ -26,7 +26,7 @@ class SimpleRSSElement extends SimpleXMLElement
*/ */
public function addChildWithCDATA(string $name, string $value = '', ?string $namespace = null): static 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) { if ($newChild !== null) {
$node = dom_import_simplexml($newChild); $node = dom_import_simplexml($newChild);
...@@ -54,7 +54,7 @@ class SimpleRSSElement extends SimpleXMLElement ...@@ -54,7 +54,7 @@ class SimpleRSSElement extends SimpleXMLElement
*/ */
public function addChild($name, $value = null, $namespace = null, $escape = true): static 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) { if ($newChild !== null) {
$node = dom_import_simplexml($newChild); $node = dom_import_simplexml($newChild);
...@@ -69,8 +69,7 @@ class SimpleRSSElement extends SimpleXMLElement ...@@ -69,8 +69,7 @@ class SimpleRSSElement extends SimpleXMLElement
return $newChild; return $newChild;
} }
/** @noRector RecastingRemovalRector */ $node->appendChild($no->createTextNode($value));
$node->appendChild($no->createTextNode((string) $value));
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment