diff options
| author | 2016-08-29 19:52:52 +0200 | |
|---|---|---|
| committer | 2016-08-29 19:52:52 +0200 | |
| commit | 17c8c039df675b3b0f8d88d14f7316a240eabe76 (patch) | |
| tree | 3dd3da3e8f21b5e82905f756098b86e0d15b3935 /lib/lib_opml.php | |
| parent | 92d4ad32c9eb165dee6dc6d4b8cf510428dde9ec (diff) | |
| parent | aea7cd78367ef867cdac7082ac1e9f61c4de7e19 (diff) | |
Merge pull request #1233 from FreshRSS/dev1.5.0
Release 1.5.0
Diffstat (limited to 'lib/lib_opml.php')
| -rw-r--r-- | lib/lib_opml.php | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/lib/lib_opml.php b/lib/lib_opml.php index 66b854313..b89e92977 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 + * @version 0.2-FreshRSS~1.5.1 * @license public domain * * Usages: @@ -123,6 +123,32 @@ function libopml_parse_outline($outline_xml, $strict = true) { return $outline; } +/** + * Reformat the XML document as a hierarchy when + * the OPML 2.0 category attribute is used + */ +function preprocessing_categories($doc) { + $outline_categories = array(); + $body = $doc->getElementsByTagName('body')->item(0); + $xpath = new DOMXpath($doc); + $outlines = $xpath->query('/opml/body/outline[@category]'); + foreach ($outlines as $outline) { + $category = trim($outline->getAttribute('category')); + if ($category != '') { + $outline_categorie = null; + if (!isset($outline_categories[$category])) { + $outline_categorie = $doc->createElement('outline'); + $outline_categorie->setAttribute('text', $category); + $body->insertBefore($outline_categorie, $body->firstChild); + $outline_categories[$category] = $outline_categorie; + } else { + $outline_categorie = $outline_categories[$category]; + } + $outline->parentNode->removeChild($outline); + $outline_categorie->appendChild($outline); + } + } +} /** * Parse a string as a XML one and returns the corresponding array @@ -140,6 +166,9 @@ function libopml_parse_string($xml, $strict = true) { $dom->loadXML($xml); $dom->encoding = 'UTF-8'; + //Partial compatibility with the category attribute of OPML 2.0 + preprocessing_categories($dom); + $opml = simplexml_import_dom($dom); if (!$opml) { |
