1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

More OPML tests and fixes

This commit is contained in:
J. King 2019-05-06 19:36:39 -04:00
parent 644750487c
commit 0f7d49c21e
4 changed files with 67 additions and 6 deletions

View file

@ -78,9 +78,8 @@ Commands:
user set-pass <username> [<password>] user set-pass <username> [<password>]
Changes <username>'s password to <password>. If not password is Changes <username>'s password to <password>. If no password is specified,
specified, a random password will be generated and printed to standard a random password will be generated and printed to standard output.
output.
The --oldpass=<pass> option can be used to supply a user's exiting The --oldpass=<pass> option can be used to supply a user's exiting
password if this is required by the authentication driver to change a password if this is required by the authentication driver to change a

View file

@ -151,6 +151,23 @@ class OPML {
throw new Exception("invalidSemantics", ['type' => "OPML"]); throw new Exception("invalidSemantics", ['type' => "OPML"]);
} }
$body = $body->item(0); $body = $body->item(0);
// function to find the next node in the tree
$next = function(\DOMNode $node, bool $visitChildren = true) use ($body) {
if ($visitChildren && $node->hasChildNodes()) {
return $node->firstChild;
} elseif ($node->nextSibling) {
return $node->nextSibling;
} else {
while (!$node->nextSibling && !$node->isSameNode($body)) {
$node = $node->parentNode;
}
if (!$node->isSameNode($body)) {
return $node->nextSibling;
} else {
return null;
}
}
};
$folders = []; $folders = [];
$feeds = []; $feeds = [];
// add the root folder to a map from folder DOM nodes to folder ID numbers // add the root folder to a map from folder DOM nodes to folder ID numbers
@ -158,7 +175,7 @@ class OPML {
$folderMap[$body] = sizeof($folderMap); $folderMap[$body] = sizeof($folderMap);
// iterate through each node in the body // iterate through each node in the body
$node = $body->firstChild; $node = $body->firstChild;
while ($node && !$node->isSameNode($body)) { while ($node) {
if ($node->nodeType == \XML_ELEMENT_NODE && $node->nodeName === "outline") { if ($node->nodeType == \XML_ELEMENT_NODE && $node->nodeName === "outline") {
// process any nodes which are outlines // process any nodes which are outlines
if ($node->getAttribute("type") === "rss") { if ($node->getAttribute("type") === "rss") {
@ -187,11 +204,11 @@ class OPML {
$folders[$id] = ['id' => $id, 'name' => $node->getAttribute("text"), 'parent' => $folderMap[$node->parentNode]]; $folders[$id] = ['id' => $id, 'name' => $node->getAttribute("text"), 'parent' => $folderMap[$node->parentNode]];
} }
// proceed to child nodes, if any // proceed to child nodes, if any
$node = $node->hasChildNodes() ? $node->firstChild : ($node->nextSibling ?: $node->parentNode); $node = $next($node);
} }
} else { } else {
// skip any node which is not an outline element; if the node has descendents they are skipped as well // skip any node which is not an outline element; if the node has descendents they are skipped as well
$node = $node->nextSibling ?: $node->parentNode; $node = $next($node, false);
} }
} }
return [$feeds, $folders]; return [$feeds, $folders];

View file

@ -166,6 +166,39 @@ OPML_EXPORT_SERIALIZATION;
'tags' => ["whee", "whoo", ""], 'tags' => ["whee", "whoo", ""],
], ],
], []]], ], []]],
["FoldersOnly.opml", true, [[], []]],
["FoldersOnly.opml", false, [[], [1 =>
[
'id' => 1,
'name' => "Folder 1",
'parent' => 0,
],
[
'id' => 2,
'name' => "Folder 2",
'parent' => 0,
],
[
'id' => 3,
'name' => "Also a folder",
'parent' => 2,
],
[
'id' => 4,
'name' => "Still a folder",
'parent' => 2,
],
[
'id' => 5,
'name' => "Folder 5",
'parent' => 4,
],
[
'id' => 6,
'name' => "Folder 6",
'parent' => 0,
],
]]],
]; ];
} }
} }

View file

@ -0,0 +1,12 @@
<opml>
<body>
<outline text="Folder 1"/>
<outline text="Folder 2">
<outline type="atom" text="Also a folder"/>
<outline type=" rss " text="Still a folder">
<outline text="Folder 5"/>
</outline>
</outline>
<outline text="Folder 6"/>
</body>
</opml>