From c28abc75649c1a00d848a75dcfe77c216b5079f9 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Thu, 18 Jan 2024 13:28:06 +0100 Subject: [PATCH] feat: add export opml --- appinfo/routes.php | 1 + lib/Controller/OpmlController.php | 75 +++++++++++++++++++++++++++++ src/components/Sidebar/Settings.vue | 53 ++++++++++++-------- 3 files changed, 109 insertions(+), 20 deletions(-) create mode 100644 lib/Controller/OpmlController.php diff --git a/appinfo/routes.php b/appinfo/routes.php index daf2f30..7779d0f 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -15,6 +15,7 @@ return [ ['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], ['name' => 'episodes#action', 'url' => '/episodes/action', 'verb' => 'GET'], ['name' => 'episodes#list', 'url' => '/episodes/list', 'verb' => 'GET'], + ['name' => 'opml#export', 'url' => '/opml/export', 'verb' => 'GET'], ['name' => 'podcast#index', 'url' => '/podcast', 'verb' => 'GET'], ['name' => 'search#index', 'url' => '/search', 'verb' => 'GET'], ['name' => 'tops#hot', 'url' => '/tops/hot', 'verb' => 'GET'], diff --git a/lib/Controller/OpmlController.php b/lib/Controller/OpmlController.php new file mode 100644 index 0000000..ccb31fe --- /dev/null +++ b/lib/Controller/OpmlController.php @@ -0,0 +1,75 @@ +', namespaceOrPrefix: 'http://xmlpull.org/v1/doc/features.html#indent-output'); + $xml->addAttribute('version', '2.0'); + + $dateCreated = new \DateTime(); + $head = $xml->addChild('head'); + + if (isset($head)) { + $head->addChild('title', $this->l10n->t('RePod Subscriptions')); + $head->addChild('dateCreated', $dateCreated->format(\DateTime::RFC822)); + } + + $body = $xml->addChild('body'); + + if (isset($body)) { + $subscriptions = $this->podcastMetricsReader->metrics($this->userService->getUserUID()); + + foreach ($subscriptions as $subscription) { + $podcast = $this->podcastDataReader->getCachedOrFetchPodcastData($subscription->getUrl(), $this->userService->getUserUID()); + + if ($podcast) { + $outline = $body->addChild('outline'); + + if (isset($outline)) { + $title = $podcast->getTitle(); + $link = $podcast->getLink(); + + if ($title) { + $outline->addAttribute('text', $title); + $outline->addAttribute('title', $title); + } + + if ($link) { + $outline->addAttribute('xmlUrl', $link); + } + } + } + } + } + + return new DataDownloadResponse((string) $xml->asXML(), 'repod-'.$dateCreated->getTimestamp().'.opml', ' application/xml'); + } +} diff --git a/src/components/Sidebar/Settings.vue b/src/components/Sidebar/Settings.vue index c053225..e8199bb 100644 --- a/src/components/Sidebar/Settings.vue +++ b/src/components/Sidebar/Settings.vue @@ -1,33 +1,46 @@