2020-06-26 14:34:52 +00:00
|
|
|
<?php
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2020-06-26 14:34:52 +00:00
|
|
|
/**
|
2021-04-02 17:20:02 +00:00
|
|
|
* @copyright 2021 Podlibre
|
2020-06-26 14:34:52 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
2020-08-04 11:25:22 +00:00
|
|
|
namespace App\Libraries;
|
|
|
|
|
|
|
|
use SimpleXMLElement;
|
|
|
|
|
2020-06-26 14:34:52 +00:00
|
|
|
class SimpleRSSElement extends SimpleXMLElement
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Adds a child with $value inside CDATA
|
2020-10-12 19:21:50 +00:00
|
|
|
*
|
|
|
|
* @param string $name — The name of the child element to add.
|
2021-05-12 14:00:25 +00:00
|
|
|
* @param string $value — [optional] If specified, the value of the child element.
|
2021-05-06 14:00:48 +00:00
|
|
|
* @param string|null $namespace [optional] If specified, the namespace to which the child element belongs.
|
|
|
|
*
|
2021-05-12 14:00:25 +00:00
|
|
|
* @return static The addChild method returns a SimpleXMLElement object representing the child added to the XML node.
|
2020-06-26 14:34:52 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function addChildWithCDATA(
|
|
|
|
string $name,
|
2021-05-12 14:00:25 +00:00
|
|
|
string $value = '',
|
2021-05-06 14:00:48 +00:00
|
|
|
?string $namespace = null
|
|
|
|
) {
|
2021-05-12 14:00:25 +00:00
|
|
|
$new_child = parent::addChild($name, '', $namespace);
|
2020-06-26 14:34:52 +00:00
|
|
|
|
|
|
|
if ($new_child !== null) {
|
|
|
|
$node = dom_import_simplexml($new_child);
|
|
|
|
$no = $node->ownerDocument;
|
|
|
|
$node->appendChild($no->createCDATASection($value));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $new_child;
|
|
|
|
}
|
2020-10-12 19:21:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a child element to the XML node with escaped $value if specified.
|
|
|
|
* Override of addChild method as SimpleXMLElement's addChild method doesn't escape ampersand
|
|
|
|
*
|
|
|
|
* @param string $name — The name of the child element to add.
|
|
|
|
* @param string $value — [optional] If specified, the value of the child element.
|
|
|
|
* @param string $namespace [optional] If specified, the namespace to which the child element belongs.
|
2021-05-12 14:00:25 +00:00
|
|
|
*
|
|
|
|
* @return static The addChild method returns a SimpleXMLElement object representing the child added to the XML node.
|
2020-10-12 19:21:50 +00:00
|
|
|
*/
|
|
|
|
public function addChild($name, $value = null, $namespace = null)
|
|
|
|
{
|
2021-05-12 14:00:25 +00:00
|
|
|
$new_child = parent::addChild($name, '', $namespace);
|
2020-10-12 19:21:50 +00:00
|
|
|
|
|
|
|
if ($new_child !== null) {
|
|
|
|
$node = dom_import_simplexml($new_child);
|
|
|
|
$no = $node->ownerDocument;
|
|
|
|
$node->appendChild($no->createTextNode(esc($value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $new_child;
|
|
|
|
}
|
2020-06-26 14:34:52 +00:00
|
|
|
}
|