diff --git a/lib/Controller/ExportController.php b/lib/Controller/ExportController.php
index c365a44..383673f 100644
--- a/lib/Controller/ExportController.php
+++ b/lib/Controller/ExportController.php
@@ -24,11 +24,11 @@
namespace OCA\Radio\Controller;
use OC;
+use OCA\Radio\ExportResponse;
use OCA\Radio\AppInfo\Application;
use OCA\Radio\Service\FavoriteService;
use OCP\AppFramework\Controller;
-use OCP\AppFramework\Http\DataResponse; // FIXME: Remove if not required
-use OCP\AppFramework\Http\Response;
+use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
use SimpleXMLElement;
@@ -53,6 +53,7 @@ class ExportController extends Controller {
* @NoAdminRequired
*/
public function index() {
+
$xml = new SimpleXMLElement('');
$xml->addAttribute('encoding', 'UTF-8');
$trackList = $xml->addChild('trackList');
@@ -61,24 +62,8 @@ class ExportController extends Controller {
$track->addChild('title', 'Radio Test 404fm');
$track->addChild('image', 'http://localhost/favicon.ico');
- $user = OC::$server->getUserSession()->getUser();
- if (is_null($user)) {
- throw new HintException('User not logged in');
- }
+ return new ExportResponse($xml->asXML());
- $userName = $user->getDisplayName();
- $productName = OC::$server->getThemingDefaults()->getName();
- $dateTime = OC::$server->getDateTimeFormatter();
-
- $export_name = '"' . $productName . ' Radio Favorites (' . $userName . ') (' . $dateTime->formatDate(time()) . ').xspf"';
-
- $response = new Response();
- $response->addHeader('Content-Type', 'application/xspf+xml');
- $response->addHeader('Content-Disposition', 'attachment; filename=' . $export_name);
- $response->render();
- //return new DataResponse($this->service->findAll($this->userId));
- return $response;
- //return $xml->asXML();
}
}
diff --git a/lib/ExportResponse.php b/lib/ExportResponse.php
new file mode 100644
index 0000000..ca77478
--- /dev/null
+++ b/lib/ExportResponse.php
@@ -0,0 +1,56 @@
+
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see .
+ *
+ */
+
+namespace OCA\Radio;
+
+use OC;
+use OC\HintException;
+use OCP\AppFramework\Http\Response;
+
+class ExportResponse extends Response {
+ private $returnstring;
+
+ public function __construct($returnstring) {
+ parent::__construct();
+
+ $user = OC::$server->getUserSession()->getUser();
+ if (is_null($user)) {
+ throw new HintException('User not logged in');
+ }
+
+ $userName = $user->getDisplayName();
+ $productName = OC::$server->getThemingDefaults()->getName();
+ $dateTime = OC::$server->getDateTimeFormatter();
+
+ $export_name = '"' . $productName . ' Radio Favorites (' . $userName . ') (' . $dateTime->formatDate(time()) . ').xspf"';
+ $this->addHeader("Cache-Control", "private");
+ $this->addHeader("Content-Type", " application/xspf+xml");
+ $this->addHeader("Content-Length", strlen($returnstring));
+ $this->addHeader("Content-Disposition", "attachment; filename=" . $export_name);
+ $this->returnstring = $returnstring;
+ }
+
+ public function render() {
+ return $this->returnstring;
+ }
+}