bookmarks/lib/ExportResponse.php

42 lines
1.2 KiB
PHP
Raw Normal View History

<?php
2020-09-21 12:25:50 +00:00
/*
* Copyright (c) 2020-2024. The Nextcloud Bookmarks contributors.
2016-12-07 12:00:43 +00:00
*
2020-09-21 12:25:50 +00:00
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
2016-12-07 12:00:43 +00:00
*/
2019-01-27 16:32:37 +00:00
namespace OCA\Bookmarks;
2020-09-21 12:17:46 +00:00
use OC;
2016-12-07 12:00:43 +00:00
use OC\HintException;
use OCP\AppFramework\Http\Response;
class ExportResponse extends Response {
private $returnstring;
public function __construct($returnstring) {
2020-09-21 12:17:46 +00:00
parent::__construct();
$user = OC::$server->getUserSession()->getUser();
if (is_null($user)) {
2016-12-07 12:00:43 +00:00
throw new HintException('User not logged in');
}
$userName = $user->getDisplayName();
2020-09-21 12:17:46 +00:00
$productName = OC::$server->getThemingDefaults()->getName();
$dateTime = OC::$server->getDateTimeFormatter();
2016-12-07 12:00:43 +00:00
2019-01-27 16:32:37 +00:00
$export_name = '"' . $productName . ' Bookmarks (' . $userName . ') (' . $dateTime->formatDate(time()) . ').html"';
$this->addHeader("Cache-Control", "private");
$this->addHeader("Content-Type", " application/stream");
$this->addHeader("Content-Length", strlen($returnstring));
$this->addHeader("Content-Disposition", "attachment; filename=" . $export_name);
$this->returnstring = $returnstring;
}
public function render() {
return $this->returnstring;
}
2016-12-07 12:00:43 +00:00
}