summaryrefslogtreecommitdiffstats
path: root/opmlexporter.php
diff options
context:
space:
mode:
authorAlessandro Cosentino <cosenal@gmail.com>2012-08-25 19:14:08 -0400
committerAlessandro Cosentino <cosenal@gmail.com>2012-08-25 19:14:08 -0400
commitc94b02a1150745fe9d62fcf351caa125fb4a1204 (patch)
treeaef0cffc29351d97c24fa12f4e2d79319f776943 /opmlexporter.php
parentca6aa3b464940cd0a012571552a4a7e9897cb35d (diff)
opml exporter. invariant test needs to be done with opml importer
Diffstat (limited to 'opmlexporter.php')
-rw-r--r--opmlexporter.php65
1 files changed, 46 insertions, 19 deletions
diff --git a/opmlexporter.php b/opmlexporter.php
index 86b8bee81..e247056c6 100644
--- a/opmlexporter.php
+++ b/opmlexporter.php
@@ -11,25 +11,52 @@
*
*/
-class OPMLExporter {
+function feedsToXML($data, $xml_el, $dom){
-
- public static function feedToXML(OCA\News\Feed $feed){
-
- }
-
- /**
- * @brief
- */
- public static function export(OCA\News\Collection $data){
- foreach($children as $child) {
- if ($child instanceOf OCA\News\Folder){
- }
- elseif ($child instanceOf OCA\News\Feed) { //onhover $(element).attr('id', 'newID');
- }
- else {
- //TODO:handle error in this case
- }
+ 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 );
}
-} \ No newline at end of file
+}
+
+$l = OC_L10N::get('news');
+
+OCP\User::checkLoggedIn();
+OCP\App::checkAppEnabled('news');
+
+$userid = OCP\USER::getUser();
+$foldermapper = new OCA\News\FolderMapper($userid);
+$allfeeds = $foldermapper->childrenOfWithFeeds(0);
+
+header('Content-Type: application/x.opml+xml');
+header('Content-Disposition: inline; filename=owncloud_news_subscriptions.xml');
+
+$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_el = $dom->createElement('title', $userid . ' ' . $l->t('subscriptions in ownCloud - News'));
+$head_el->appendChild( $title_el );
+$opml_el->appendChild( $head_el );
+
+$body_el = $dom->createElement('body');
+feedsToXML($allfeeds, $body_el, $dom);
+
+$opml_el->appendChild( $body_el );
+$dom->appendChild( $opml_el );
+
+echo $dom->saveXML(); \ No newline at end of file