summaryrefslogtreecommitdiffstats
path: root/utility/opmlexporter.php
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-03-21 16:32:36 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-03-21 16:32:36 +0100
commitac84b27965f5a1aec859e389f099fb844e33de46 (patch)
treec98d7aace90fcb442208349918a3e71cd9a7691a /utility/opmlexporter.php
parentf475d882d0a76908400e9857f7e8a4ae8ad8a752 (diff)
reorganize folder
Diffstat (limited to 'utility/opmlexporter.php')
-rw-r--r--utility/opmlexporter.php84
1 files changed, 84 insertions, 0 deletions
diff --git a/utility/opmlexporter.php b/utility/opmlexporter.php
new file mode 100644
index 000000000..d9d404ff1
--- /dev/null
+++ b/utility/opmlexporter.php
@@ -0,0 +1,84 @@
+<?php
+
+/**
+* ownCloud - News app
+*
+* @author Alessandro Cosentino
+* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com>
+*
+* This file is licensed under the Affero General Public License version 3 or later.
+* See the COPYING-README file
+*
+*/
+
+namespace OCA\News;
+
+/**
+* Exports the OPML
+*/
+class OPMLExporter {
+
+ private $api;
+ private $trans;
+
+ public function __construct($api){
+ $this->api = $api;
+ $this->trans = $api->getTrans();
+ }
+
+
+ /**
+ * Generates the OPML for the active user
+ * @return the OPML as string
+ */
+ public function buildOPML($feeds){
+ $dom = new \DomDocument('1.0', 'UTF-8');
+ $dom->formatOutput = true;
+
+ $opml_el = $dom->createElement('opml');
+ $opml_el->setAttribute('version', '2.0');
+
+ $head_el = $dom->createElement('head');
+
+ $title = $this->api->getUserId() . ' ' .
+ $this->trans->t('subscriptions in ownCloud - News');
+ $title_el = $dom->createElement('title', $title);
+
+ $head_el->appendChild( $title_el );
+ $opml_el->appendChild( $head_el );
+ $body_el = $dom->createElement('body');
+
+ $this->feedsToXML($feeds, $body_el, $dom);
+
+ $opml_el->appendChild( $body_el );
+ $dom->appendChild( $opml_el );
+
+ return $dom->saveXML();
+ }
+
+
+ /**
+ * Creates the OPML content recursively
+ */
+ protected function feedsToXML($data, $xml_el, $dom) {
+
+ foreach($data as $collection) {
+ $outline_el = $dom->createElement('outline');
+ if ($collection instanceOf Folder) {
+ $outline_el->setAttribute('title', $collection->getName());
+ $outline_el->setAttribute('text', $collection->getName());
+ $this->feedsToXML($collection->getChildren(), $outline_el, $dom);
+ }
+ elseif ($collection instanceOf Feed) {
+ $outline_el->setAttribute('title', $collection->getTitle());
+ $outline_el->setAttribute('text', $collection->getTitle());
+ $outline_el->setAttribute('type', 'rss');
+ $outline_el->setAttribute('xmlUrl', $collection->getUrl());
+ }
+ $xml_el->appendChild( $outline_el );
+ }
+ }
+
+
+}
+
>279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345