summaryrefslogtreecommitdiffstats
path: root/opmlexporter.php
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-01-27 04:15:53 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-01-27 04:15:53 +0100
commitae7393db3d99a7ac223ae917129cccd9f49888e3 (patch)
tree7f54b72b0d01c38afd1378365a67e4f192922423 /opmlexporter.php
parent483784caa38bd6131405ac474347a215584e30a5 (diff)
merged the angularjs branch
Diffstat (limited to 'opmlexporter.php')
-rw-r--r--opmlexporter.php99
1 files changed, 60 insertions, 39 deletions
diff --git a/opmlexporter.php b/opmlexporter.php
index 93f95a74e..d9d404ff1 100644
--- a/opmlexporter.php
+++ b/opmlexporter.php
@@ -11,53 +11,74 @@
*
*/
-function feedsToXML($data, $xml_el, $dom) {
-
- foreach($data as $collection) {
- $outline_el = $dom->createElement('outline');
- if ($collection instanceOf OCA\News\Folder) {
- $outline_el->setAttribute('title', $collection->getName());
- $outline_el->setAttribute('text', $collection->getName());
- feedsToXML($collection->getChildren(), $outline_el, $dom);
- }
- elseif ($collection instanceOf OCA\News\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 );
+namespace OCA\News;
+
+/**
+* Exports the OPML
+*/
+class OPMLExporter {
+
+ private $api;
+ private $trans;
+
+ public function __construct($api){
+ $this->api = $api;
+ $this->trans = $api->getTrans();
}
-}
-$l = OC_L10N::get('news');
-OCP\User::checkLoggedIn();
-OCP\App::checkAppEnabled('news');
+ /**
+ * 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');
-$userid = OCP\USER::getUser();
-$foldermapper = new OCA\News\FolderMapper($userid);
-$allfeeds = $foldermapper->childrenOfWithFeeds(0);
+ $head_el = $dom->createElement('head');
-header('Content-Type: application/x.opml+xml');
-$filename = 'ownCloud ' . $l->t('News') . ' ' . $userid;
-header('Content-Disposition: inline; filename="' . $filename . '.opml"');
+ $title = $this->api->getUserId() . ' ' .
+ $this->trans->t('subscriptions in ownCloud - News');
+ $title_el = $dom->createElement('title', $title);
-$dom = new DomDocument('1.0', 'UTF-8');
-$dom->formatOutput = true;
+ $head_el->appendChild( $title_el );
+ $opml_el->appendChild( $head_el );
+ $body_el = $dom->createElement('body');
-$opml_el = $dom->createElement('opml');
-$opml_el->setAttribute('version', '2.0');
+ $this->feedsToXML($feeds, $body_el, $dom);
-$head_el = $dom->createElement('head');
-$title_el = $dom->createElement('title', $userid . ' ' . $l->t('subscriptions in ownCloud - News'));
-$head_el->appendChild( $title_el );
-$opml_el->appendChild( $head_el );
+ $opml_el->appendChild( $body_el );
+ $dom->appendChild( $opml_el );
-$body_el = $dom->createElement('body');
-feedsToXML($allfeeds, $body_el, $dom);
+ 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 );
+ }
+ }
-$opml_el->appendChild( $body_el );
-$dom->appendChild( $opml_el );
-echo $dom->saveXML(); \ No newline at end of file
+}
+