diff options
| author | 2022-05-12 22:15:10 +0200 | |
|---|---|---|
| committer | 2022-05-12 22:15:10 +0200 | |
| commit | 4a87206f2898665e99953590536cedc6c5505f05 (patch) | |
| tree | 398f53769048460071194d398c61c7e847f22d7e /lib/lib_opml.php | |
| parent | 9d1930d9adb4f56ae12209d3d01f4a1ed1af8503 (diff) | |
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
Diffstat (limited to 'lib/lib_opml.php')
| -rw-r--r-- | lib/lib_opml.php | 31 |
1 files changed, 24 insertions, 7 deletions
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 <dev@marienfressinaud.fr> * @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); + } } } |
