From 4a87206f2898665e99953590536cedc6c5505f05 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 12 May 2022 22:15:10 +0200 Subject: OPML export/import of some proprietary FreshRSS attributes (#4342) * OPML export/import of some proprietary FreshRSS attributes #fix https://github.com/FreshRSS/FreshRSS/issues/4077 And one of the TODOs of https://github.com/FreshRSS/FreshRSS/pull/4220 XPath options, CSS Selector, and action filters * Bump library patch version * OPML namespace + documentation * Add example --- lib/lib_opml.php | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'lib/lib_opml.php') diff --git a/lib/lib_opml.php b/lib/lib_opml.php index b62f988c4..04b747a05 100644 --- a/lib/lib_opml.php +++ b/lib/lib_opml.php @@ -12,7 +12,7 @@ * * @author Marien Fressinaud * @link https://github.com/marienfressinaud/lib_opml - * @version 0.2-FreshRSS~1.5.1 + * @version 0.2-FreshRSS~1.20.0 * @license public domain * * Usages: @@ -91,8 +91,20 @@ function libopml_parse_outline($outline_xml, $strict = true) { // An outline may contain any kind of attributes but "text" attribute is // required ! $text_is_present = false; - foreach ($outline_xml->attributes() as $key => $value) { - $outline[$key] = (string)$value; + + $elem = dom_import_simplexml($outline_xml); + /** @var DOMAttr $attr */ + foreach ($elem->attributes as $attr) { + $key = $attr->localName; + + if ($attr->namespaceURI == '') { + $outline[$key] = $attr->value; + } else { + $outline[$key] = [ + 'namespace' => $attr->namespaceURI, + 'value' => $attr->value, + ]; + } if ($key === 'text') { $text_is_present = true; @@ -257,17 +269,22 @@ function libopml_render_outline($parent_elt, $outline, $strict) { foreach ($value as $outline_child) { libopml_render_outline($outline_elt, $outline_child, $strict); } - } elseif (is_array($value)) { + } elseif (is_array($value) && !isset($value['namespace'])) { throw new LibOPML_Exception( - 'Type of outline elements cannot be array: ' . $key + 'Type of outline elements cannot be array (except for providing a namespace): ' . $key ); } else { // Detect text attribute is present, that's good :) if ($key === 'text') { $text_is_present = true; } - - $outline_elt->addAttribute($key, $value); + if (is_array($value)) { + if (!empty($value['namespace']) && !empty($value['value'])) { + $outline_elt->addAttribute($key, $value['value'], $value['namespace']); + } + } else { + $outline_elt->addAttribute($key, $value); + } } } -- cgit v1.2.3