From 8d5d1a383b5af1b1af78445362e178fced2b29c7 Mon Sep 17 00:00:00 2001
From: Jonas Heinrich <onny@project-insanity.org>
Date: Mon, 15 Mar 2021 13:05:29 +0100
Subject: [PATCH] implement exporting subscriptions (fixes #104)

---
 lib/Controller/ExportController.php |  5 ++---
 lib/Controller/ShowController.php   | 12 +++++++-----
 lib/Db/Show.php                     |  4 ++++
 lib/Service/ShowService.php         |  8 ++++++--
 src/services/ShowApi.js             |  2 ++
 5 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/lib/Controller/ExportController.php b/lib/Controller/ExportController.php
index 11712d9..0e1f151 100644
--- a/lib/Controller/ExportController.php
+++ b/lib/Controller/ExportController.php
@@ -56,15 +56,14 @@ class ExportController extends Controller {
 	public function index() {
 
 		$xml = new SimpleXMLElement('<?xml version="1.0"?><opml version="1.0"></opml>');
-		$xml->addAttribute('encoding', 'UTF-8');
 		$trackList = $xml->addChild('body');
 		foreach($this->service->findAll($this->userId) as $show) {
 			$track = $trackList->addChild('outline');
 			$track->addAttribute('type', 'rss');
 			$track->addAttribute('text', $show->getTitle());
 			$track->addAttribute('title', $show->getTitle());
-      $track->addAttribute('xmlUrl', 'FIXME');
-      $track->addAttribute('htmlUrl', 'FIXME');
+      $track->addAttribute('xmlUrl', $show->getFeedurl());
+      $track->addAttribute('htmlUrl', $show->getHomepage());
 		}
 
 		$dom = new DOMDocument("1.0");
diff --git a/lib/Controller/ShowController.php b/lib/Controller/ShowController.php
index ebb1214..fe95642 100644
--- a/lib/Controller/ShowController.php
+++ b/lib/Controller/ShowController.php
@@ -66,20 +66,22 @@ class ShowController extends Controller {
 	 * @NoAdminRequired
 	 */
 	 public function create(int $id, string $imgurl, string $author,
-	 	string $title, string $lastpub, int $dateadded): DataResponse {
+	 	string $title, string $lastpub, int $dateadded, string $homepage,
+		string $feedurl): DataResponse {
  		return new DataResponse($this->service->create($id, $imgurl, $author,
-			$title, $lastpub, $dateadded, $this->userId));
+			$title, $lastpub, $dateadded, $homepage, $feedurl, $this->userId));
  	}
 
 	/**
 	 * @NoAdminRequired
 	 */
 	public function update(int $id, string $imgurl, string $author,
-	 	string $title, string $lastpub, int $dateadded): DataResponse {
+	 	string $title, string $lastpub, int $dateadded, string $homepage,
+		string $feedurl): DataResponse {
 		return $this->handleNotFound(function () use ($id, $imgurl, $author,
-			$title, $lastpub, $dateadded) {
+			$title, $lastpub, $dateadded, $homepage, $feedurl) {
 			return $this->service->update($id, $imgurl, $author, $title, $lastpub,
-				$dateadded, $this->userId);
+				$dateadded, $homepage, $feedurl, $this->userId);
  		});
  	}
 
diff --git a/lib/Db/Show.php b/lib/Db/Show.php
index 280815f..cbd9ba9 100644
--- a/lib/Db/Show.php
+++ b/lib/Db/Show.php
@@ -33,6 +33,8 @@ class Show extends Entity implements JsonSerializable {
 	protected $title;
 	protected $lastpub;
 	protected $dateadded;
+	protected $homepage;
+	protected $feedurl;
 	protected $userId;
 
 	public function jsonSerialize(): array {
@@ -43,6 +45,8 @@ class Show extends Entity implements JsonSerializable {
 			'title' => $this->title,
 			'lastpub' => $this->lastpub,
 			'dateadded' => $this->dateadded,
+			'homepage' => $this->homepage,
+			'feedurl' => $this->feedurl,
 		];
 	}
 }
diff --git a/lib/Service/ShowService.php b/lib/Service/ShowService.php
index cd29f97..b4a386f 100644
--- a/lib/Service/ShowService.php
+++ b/lib/Service/ShowService.php
@@ -67,7 +67,7 @@ class ShowService {
 	}
 
 	public function create($id, $imgurl, $author, $title, $lastpub, $dateadded,
-		$userId) {
+		$homepage, $feedurl, $userId) {
 		$show = new Show();
 		$show->setId($id);
 		$show->setImgurl($imgurl);
@@ -75,12 +75,14 @@ class ShowService {
 		$show->setTitle($title);
 		$show->setLastpub($lastpub);
 		$show->setDateadded($dateadded);
+		$show->setHomepage($homepage);
+		$show->setFeedurl($feedurl);
 		$show->setUserId($userId);
 		return $this->mapper->insert($show);
 	}
 
 	public function update($id, $imgurl, $author, $title, $lastpub, $dateadded,
-		$userId) {
+		$homepage, $feedurl, $userId) {
 		try {
 			$show = $this->mapper->find($id, $userId);
 			$show->setImgurl($imgurl);
@@ -88,6 +90,8 @@ class ShowService {
 			$show->setTitle($title);
 			$show->setLastpub($lastpub);
 			$show->setDateadded($dateadded);
+			$show->setHomepage($homepage);
+			$show->setFeedurl($feedurl);
 			return $this->mapper->update($show);
 		} catch (Exception $e) {
 			$this->handleException($e);
diff --git a/src/services/ShowApi.js b/src/services/ShowApi.js
index 447eb56..09c62b3 100644
--- a/src/services/ShowApi.js
+++ b/src/services/ShowApi.js
@@ -41,6 +41,8 @@ export class ShowApi {
 			author: show.author,
 			lastpub: show.lastpub,
 			dateadded: Date.now(),
+			homepage: show.htmlURL,
+			feedurl: show.xmlURL,
 		}
 		axios.defaults.headers.requesttoken = getRequestToken()
 		return axios.post(this.url('/shows'), show)
-- 
GitLab