From 25b7b47e0a9ca1448582aad7ea2d7ea03bd15699 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Thu, 28 Mar 2019 21:53:04 -0400 Subject: [PATCH] Prototype OPML exporter --- lib/ImportExport/OPML.php | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 lib/ImportExport/OPML.php diff --git a/lib/ImportExport/OPML.php b/lib/ImportExport/OPML.php new file mode 100644 index 00000000..e3053a01 --- /dev/null +++ b/lib/ImportExport/OPML.php @@ -0,0 +1,59 @@ + null]; + $tags = []; + $document = new \DOMDocument("1.0", "utf-8"); + $document->formatOutput = true; + $document->appendChild($document->createElement("opml")); + $document->documentElement->setAttribute("version", "2.0"); + $document->documentElement->appendChild($document->createElement("head")); + // create the "root folder" node (the body node, in OPML terms) + $folders[0] = $document->createElement("body"); + $transaction = Arsse::$db->begin(); + foreach (Arsse::$db->tagSummarize($user) as $r) { + $sub = $r['subscription']; + $tag = $r['name']; + $tag = str_replace(",", "", $tag); + if (!isset($tags[$sub])) { + $tags[$sub] = []; + } + $tags[$sub][] = $tag; + } + if (!$flat) { + foreach (Arsse::$db->folderList($user) as $r) { + $parents[$r['id']] = $r['parent'] ?? 0; + $el = $document->createElement("outline"); + $el->setAttribute("text", $r['name']); + $folders[$r['id']] = $el; + } + } + foreach (Arsse::$db->subscriptionList($user) as $r) { + $el = $document->createElement(("outline")); + $el->setAttribute("text", $r['title']); + $el->setAttribute("type", "rss"); + $el->setAttribute("xmlUrl", $r['url']); + if (sizeof($tags[$r['id']])) { + $el->setAttribute("category", implode(",", $tags[$r['id']])); + } + ($folders[$r['folder'] ?? 0] ?? $folders[0])->appendChild($el); + } + $transaction->rollback(); + foreach ($folders as $id => $el) { + $parent = $parents[$id] ?? $document->documentElement; + $parent->appendChild($el); + } + // return the serialization + return $document->saveXML(); + } +}