2016-06-09 22:46:30 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
|
2016-06-21 22:21:46 +03:00
|
|
|
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
|
2016-06-09 22:46:30 +03:00
|
|
|
*
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
2020-04-29 12:57:22 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Daniel Calviño Sánchez <danxuliu@gmail.com>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Daniel Kesselberg <mail@danielkesselberg.de>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Jan-Christoph Borchardt <hey@jancborchardt.net>
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Julius Haertl <jus@bitgrid.net>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Kyle Fazzari <kyrofa@ubuntu.com>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Michael Weimann <mail@michael-weimann.eu>
|
|
|
|
* @author rakekniven <mark.ziegler@rakekniven.de>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Thomas Citharel <nextcloud@tcit.fr>
|
2016-07-21 17:49:16 +03:00
|
|
|
*
|
2016-06-09 22:46:30 +03:00
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-06-09 22:46:30 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Theming\Controller;
|
|
|
|
|
2017-02-17 18:42:07 +03:00
|
|
|
use OC\Template\SCSSCacher;
|
2018-02-26 15:54:00 +03:00
|
|
|
use OCA\Theming\ImageManager;
|
2016-08-12 17:00:39 +03:00
|
|
|
use OCA\Theming\ThemingDefaults;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\App\IAppManager;
|
2016-06-09 22:46:30 +03:00
|
|
|
use OCP\AppFramework\Controller;
|
2016-06-16 18:30:18 +03:00
|
|
|
use OCP\AppFramework\Http;
|
2016-06-09 22:46:30 +03:00
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\AppFramework\Http\FileDisplayResponse;
|
2016-10-27 15:48:42 +03:00
|
|
|
use OCP\AppFramework\Http\NotFoundResponse;
|
2017-02-09 12:55:28 +03:00
|
|
|
use OCP\Files\IAppData;
|
2016-10-27 15:48:42 +03:00
|
|
|
use OCP\Files\NotFoundException;
|
2017-04-29 12:22:34 +03:00
|
|
|
use OCP\Files\NotPermittedException;
|
2016-06-21 22:21:46 +03:00
|
|
|
use OCP\IConfig;
|
2016-06-16 18:30:18 +03:00
|
|
|
use OCP\IL10N;
|
2016-06-09 22:46:30 +03:00
|
|
|
use OCP\IRequest;
|
2016-08-27 22:38:41 +03:00
|
|
|
use OCP\ITempManager;
|
2017-02-17 18:42:07 +03:00
|
|
|
use OCP\IURLGenerator;
|
2016-06-09 22:46:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ThemingController
|
|
|
|
*
|
|
|
|
* handle ajax requests to update the theme
|
|
|
|
*
|
|
|
|
* @package OCA\Theming\Controller
|
|
|
|
*/
|
|
|
|
class ThemingController extends Controller {
|
2016-08-12 17:00:39 +03:00
|
|
|
/** @var ThemingDefaults */
|
2017-02-17 18:42:07 +03:00
|
|
|
private $themingDefaults;
|
2016-06-16 18:30:18 +03:00
|
|
|
/** @var IL10N */
|
2017-02-17 18:42:07 +03:00
|
|
|
private $l10n;
|
2016-06-21 22:21:46 +03:00
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
2016-08-27 22:38:41 +03:00
|
|
|
/** @var ITempManager */
|
|
|
|
private $tempManager;
|
2017-02-09 12:55:28 +03:00
|
|
|
/** @var IAppData */
|
|
|
|
private $appData;
|
2017-02-17 18:42:07 +03:00
|
|
|
/** @var SCSSCacher */
|
|
|
|
private $scssCacher;
|
2017-08-10 12:33:12 +03:00
|
|
|
/** @var IURLGenerator */
|
|
|
|
private $urlGenerator;
|
2018-02-21 09:44:37 +03:00
|
|
|
/** @var IAppManager */
|
|
|
|
private $appManager;
|
2018-02-26 15:54:00 +03:00
|
|
|
/** @var ImageManager */
|
|
|
|
private $imageManager;
|
2016-06-16 18:30:18 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ThemingController constructor.
|
|
|
|
*
|
|
|
|
* @param string $appName
|
|
|
|
* @param IRequest $request
|
2016-06-21 22:21:46 +03:00
|
|
|
* @param IConfig $config
|
2017-02-17 18:42:07 +03:00
|
|
|
* @param ThemingDefaults $themingDefaults
|
2016-06-16 18:30:18 +03:00
|
|
|
* @param IL10N $l
|
2016-08-27 22:38:41 +03:00
|
|
|
* @param ITempManager $tempManager
|
2017-02-09 12:55:28 +03:00
|
|
|
* @param IAppData $appData
|
2017-02-17 18:42:07 +03:00
|
|
|
* @param SCSSCacher $scssCacher
|
2017-08-10 12:33:12 +03:00
|
|
|
* @param IURLGenerator $urlGenerator
|
2018-02-21 09:44:37 +03:00
|
|
|
* @param IAppManager $appManager
|
2018-03-28 15:56:31 +03:00
|
|
|
* @param ImageManager $imageManager
|
2016-06-16 18:30:18 +03:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
$appName,
|
|
|
|
IRequest $request,
|
2016-06-21 22:21:46 +03:00
|
|
|
IConfig $config,
|
2017-02-17 18:42:07 +03:00
|
|
|
ThemingDefaults $themingDefaults,
|
2016-06-27 11:47:44 +03:00
|
|
|
IL10N $l,
|
2017-02-09 12:55:28 +03:00
|
|
|
ITempManager $tempManager,
|
2017-02-17 18:42:07 +03:00
|
|
|
IAppData $appData,
|
2017-08-10 12:33:12 +03:00
|
|
|
SCSSCacher $scssCacher,
|
2018-02-21 09:44:37 +03:00
|
|
|
IURLGenerator $urlGenerator,
|
2018-02-26 15:54:00 +03:00
|
|
|
IAppManager $appManager,
|
|
|
|
ImageManager $imageManager
|
2016-06-16 18:30:18 +03:00
|
|
|
) {
|
2016-06-09 22:46:30 +03:00
|
|
|
parent::__construct($appName, $request);
|
2016-07-22 16:38:37 +03:00
|
|
|
|
2017-02-17 18:42:07 +03:00
|
|
|
$this->themingDefaults = $themingDefaults;
|
|
|
|
$this->l10n = $l;
|
2016-06-21 22:21:46 +03:00
|
|
|
$this->config = $config;
|
2016-08-27 22:38:41 +03:00
|
|
|
$this->tempManager = $tempManager;
|
2017-02-09 12:55:28 +03:00
|
|
|
$this->appData = $appData;
|
2017-02-17 18:42:07 +03:00
|
|
|
$this->scssCacher = $scssCacher;
|
2017-08-10 12:33:12 +03:00
|
|
|
$this->urlGenerator = $urlGenerator;
|
2018-02-25 18:08:59 +03:00
|
|
|
$this->appManager = $appManager;
|
2018-02-26 15:54:00 +03:00
|
|
|
$this->imageManager = $imageManager;
|
2016-06-09 22:46:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-06-21 22:21:46 +03:00
|
|
|
* @param string $setting
|
|
|
|
* @param string $value
|
2016-06-09 22:46:30 +03:00
|
|
|
* @return DataResponse
|
2018-02-26 15:54:00 +03:00
|
|
|
* @throws NotPermittedException
|
2016-06-09 22:46:30 +03:00
|
|
|
*/
|
|
|
|
public function updateStylesheet($setting, $value) {
|
2016-08-01 10:37:12 +03:00
|
|
|
$value = trim($value);
|
2019-07-31 11:05:46 +03:00
|
|
|
$error = null;
|
2016-08-01 10:37:12 +03:00
|
|
|
switch ($setting) {
|
|
|
|
case 'name':
|
|
|
|
if (strlen($value) > 250) {
|
2019-07-31 11:05:46 +03:00
|
|
|
$error = $this->l10n->t('The given name is too long');
|
2016-08-01 10:37:12 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'url':
|
|
|
|
if (strlen($value) > 500) {
|
2019-07-31 11:05:46 +03:00
|
|
|
$error = $this->l10n->t('The given web address is too long');
|
|
|
|
}
|
|
|
|
if (!$this->isValidUrl($value)) {
|
|
|
|
$error = $this->l10n->t('The given web address is not a valid URL');
|
2016-08-01 10:37:12 +03:00
|
|
|
}
|
|
|
|
break;
|
2018-05-09 16:52:41 +03:00
|
|
|
case 'imprintUrl':
|
|
|
|
if (strlen($value) > 500) {
|
2019-07-31 11:05:46 +03:00
|
|
|
$error = $this->l10n->t('The given legal notice address is too long');
|
|
|
|
}
|
|
|
|
if (!$this->isValidUrl($value)) {
|
|
|
|
$error = $this->l10n->t('The given legal notice address is not a valid URL');
|
2018-05-09 16:52:41 +03:00
|
|
|
}
|
|
|
|
break;
|
2018-05-24 15:45:49 +03:00
|
|
|
case 'privacyUrl':
|
|
|
|
if (strlen($value) > 500) {
|
2019-07-31 11:05:46 +03:00
|
|
|
$error = $this->l10n->t('The given privacy policy address is too long');
|
|
|
|
}
|
|
|
|
if (!$this->isValidUrl($value)) {
|
|
|
|
$error = $this->l10n->t('The given privacy policy address is not a valid URL');
|
2018-05-24 15:45:49 +03:00
|
|
|
}
|
|
|
|
break;
|
2016-08-01 10:37:12 +03:00
|
|
|
case 'slogan':
|
|
|
|
if (strlen($value) > 500) {
|
2019-07-31 11:05:46 +03:00
|
|
|
$error = $this->l10n->t('The given slogan is too long');
|
2016-08-01 10:37:12 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'color':
|
|
|
|
if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
|
2019-07-31 11:05:46 +03:00
|
|
|
$error = $this->l10n->t('The given color is invalid');
|
2016-08-01 10:37:12 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2019-07-31 11:05:46 +03:00
|
|
|
if ($error !== null) {
|
|
|
|
return new DataResponse([
|
|
|
|
'data' => [
|
|
|
|
'message' => $error,
|
|
|
|
],
|
|
|
|
'status' => 'error'
|
|
|
|
], Http::STATUS_BAD_REQUEST);
|
|
|
|
}
|
2016-08-01 10:37:12 +03:00
|
|
|
|
2017-02-17 18:42:07 +03:00
|
|
|
$this->themingDefaults->set($setting, $value);
|
2017-04-28 18:55:59 +03:00
|
|
|
|
|
|
|
// reprocess server scss for preview
|
2018-06-14 16:55:07 +03:00
|
|
|
$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/css-variables.scss', 'core');
|
2017-04-28 18:55:59 +03:00
|
|
|
|
2016-06-16 18:30:18 +03:00
|
|
|
return new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
2017-08-10 12:33:12 +03:00
|
|
|
'message' => $this->l10n->t('Saved'),
|
2018-06-14 16:55:07 +03:00
|
|
|
'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/css-variables.scss'))
|
2016-06-16 18:30:18 +03:00
|
|
|
],
|
|
|
|
'status' => 'success'
|
|
|
|
]
|
|
|
|
);
|
2016-06-09 22:46:30 +03:00
|
|
|
}
|
|
|
|
|
2019-07-31 11:05:46 +03:00
|
|
|
/**
|
|
|
|
* Check that a string is a valid http/https url
|
|
|
|
*/
|
|
|
|
private function isValidUrl(string $url): bool {
|
|
|
|
return ((strpos($url, 'http://') === 0 || strpos($url, 'https://') === 0) &&
|
|
|
|
filter_var($url, FILTER_VALIDATE_URL) !== false);
|
|
|
|
}
|
|
|
|
|
2016-06-09 22:46:30 +03:00
|
|
|
/**
|
|
|
|
* @return DataResponse
|
2018-02-26 15:54:00 +03:00
|
|
|
* @throws NotPermittedException
|
2016-06-09 22:46:30 +03:00
|
|
|
*/
|
2018-02-26 15:54:00 +03:00
|
|
|
public function uploadImage(): DataResponse {
|
|
|
|
$key = $this->request->getParam('key');
|
|
|
|
$image = $this->request->getUploadedFile('image');
|
2017-09-20 13:32:41 +03:00
|
|
|
$error = null;
|
2017-09-21 12:36:27 +03:00
|
|
|
$phpFileUploadErrors = [
|
2018-03-16 20:45:20 +03:00
|
|
|
UPLOAD_ERR_OK => $this->l10n->t('The file was uploaded'),
|
2017-09-21 12:36:27 +03:00
|
|
|
UPLOAD_ERR_INI_SIZE => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'),
|
|
|
|
UPLOAD_ERR_FORM_SIZE => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'),
|
2018-03-02 19:46:12 +03:00
|
|
|
UPLOAD_ERR_PARTIAL => $this->l10n->t('The file was only partially uploaded'),
|
2017-09-21 12:36:27 +03:00
|
|
|
UPLOAD_ERR_NO_FILE => $this->l10n->t('No file was uploaded'),
|
|
|
|
UPLOAD_ERR_NO_TMP_DIR => $this->l10n->t('Missing a temporary folder'),
|
2018-03-19 17:00:27 +03:00
|
|
|
UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Could not write file to disk'),
|
2018-03-16 20:45:20 +03:00
|
|
|
UPLOAD_ERR_EXTENSION => $this->l10n->t('A PHP extension stopped the file upload'),
|
2017-09-21 12:36:27 +03:00
|
|
|
];
|
2018-02-26 15:54:00 +03:00
|
|
|
if (empty($image)) {
|
2017-09-20 13:32:41 +03:00
|
|
|
$error = $this->l10n->t('No file uploaded');
|
|
|
|
}
|
2018-02-26 15:54:00 +03:00
|
|
|
if (!empty($image) && array_key_exists('error', $image) && $image['error'] !== UPLOAD_ERR_OK) {
|
|
|
|
$error = $phpFileUploadErrors[$image['error']];
|
2017-09-20 13:32:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($error !== null) {
|
2016-06-16 18:30:18 +03:00
|
|
|
return new DataResponse(
|
|
|
|
[
|
|
|
|
'data' => [
|
2017-09-20 13:32:41 +03:00
|
|
|
'message' => $error
|
2017-09-21 12:36:27 +03:00
|
|
|
],
|
|
|
|
'status' => 'failure',
|
2016-06-16 18:30:18 +03:00
|
|
|
],
|
2016-08-27 13:38:15 +03:00
|
|
|
Http::STATUS_UNPROCESSABLE_ENTITY
|
|
|
|
);
|
2016-06-09 22:46:30 +03:00
|
|
|
}
|
2017-02-09 12:55:28 +03:00
|
|
|
|
|
|
|
try {
|
2020-09-23 18:48:48 +03:00
|
|
|
$mime = $this->imageManager->updateImage($key, $image['tmp_name']);
|
|
|
|
$this->themingDefaults->set($key . 'Mime', $mime);
|
|
|
|
} catch (\Exception $e) {
|
2018-02-26 15:54:00 +03:00
|
|
|
return new DataResponse(
|
|
|
|
[
|
|
|
|
'data' => [
|
2020-09-23 18:48:48 +03:00
|
|
|
'message' => $e->getMessage()
|
2017-09-20 14:33:42 +03:00
|
|
|
],
|
2018-02-26 15:54:00 +03:00
|
|
|
'status' => 'failure',
|
|
|
|
],
|
|
|
|
Http::STATUS_UNPROCESSABLE_ENTITY
|
|
|
|
);
|
2016-06-21 22:21:46 +03:00
|
|
|
}
|
2016-08-27 13:38:15 +03:00
|
|
|
|
2018-02-26 15:54:00 +03:00
|
|
|
$name = $image['name'];
|
2018-06-14 16:55:07 +03:00
|
|
|
$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/css-variables.scss', 'core');
|
2016-06-21 22:21:46 +03:00
|
|
|
|
2016-06-16 18:30:18 +03:00
|
|
|
return new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
2016-06-21 22:21:46 +03:00
|
|
|
'name' => $name,
|
2018-02-26 15:54:00 +03:00
|
|
|
'url' => $this->imageManager->getImageUrl($key),
|
|
|
|
'message' => $this->l10n->t('Saved'),
|
2018-06-14 16:55:07 +03:00
|
|
|
'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/css-variables.scss'))
|
2016-06-16 18:30:18 +03:00
|
|
|
],
|
|
|
|
'status' => 'success'
|
|
|
|
]
|
|
|
|
);
|
2016-06-09 22:46:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-06-21 22:21:46 +03:00
|
|
|
* Revert setting to default value
|
2016-06-09 22:46:30 +03:00
|
|
|
*
|
|
|
|
* @param string $setting setting which should be reverted
|
|
|
|
* @return DataResponse
|
2018-02-26 15:54:00 +03:00
|
|
|
* @throws NotPermittedException
|
2016-06-09 22:46:30 +03:00
|
|
|
*/
|
2018-02-26 15:54:00 +03:00
|
|
|
public function undo(string $setting): DataResponse {
|
2017-02-17 18:42:07 +03:00
|
|
|
$value = $this->themingDefaults->undo($setting);
|
2017-04-28 19:23:15 +03:00
|
|
|
// reprocess server scss for preview
|
2018-06-14 16:55:07 +03:00
|
|
|
$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/css-variables.scss', 'core');
|
2017-04-29 12:22:34 +03:00
|
|
|
|
2016-06-16 18:30:18 +03:00
|
|
|
return new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'value' => $value,
|
2017-08-10 12:33:12 +03:00
|
|
|
'message' => $this->l10n->t('Saved'),
|
2018-06-14 16:55:07 +03:00
|
|
|
'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/css-variables.scss'))
|
2016-06-16 18:30:18 +03:00
|
|
|
],
|
|
|
|
'status' => 'success'
|
|
|
|
]
|
|
|
|
);
|
2016-06-09 22:46:30 +03:00
|
|
|
}
|
2016-06-21 22:21:46 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @PublicPage
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*
|
2018-02-26 15:54:00 +03:00
|
|
|
* @param string $key
|
2018-05-08 14:06:31 +03:00
|
|
|
* @param bool $useSvg
|
2017-02-09 19:12:00 +03:00
|
|
|
* @return FileDisplayResponse|NotFoundResponse
|
2018-05-08 14:06:31 +03:00
|
|
|
* @throws NotPermittedException
|
2016-06-21 22:21:46 +03:00
|
|
|
*/
|
2018-05-08 14:06:31 +03:00
|
|
|
public function getImage(string $key, bool $useSvg = true) {
|
2016-10-27 15:48:42 +03:00
|
|
|
try {
|
2018-05-08 14:06:31 +03:00
|
|
|
$file = $this->imageManager->getImage($key, $useSvg);
|
2016-10-27 15:48:42 +03:00
|
|
|
} catch (NotFoundException $e) {
|
|
|
|
return new NotFoundResponse();
|
2016-06-21 22:21:46 +03:00
|
|
|
}
|
|
|
|
|
2017-02-09 12:55:28 +03:00
|
|
|
$response = new FileDisplayResponse($file);
|
2019-11-27 22:26:57 +03:00
|
|
|
$csp = new Http\ContentSecurityPolicy();
|
|
|
|
$csp->allowInlineStyle();
|
|
|
|
$response->setContentSecurityPolicy($csp);
|
2016-06-21 22:21:46 +03:00
|
|
|
$response->cacheFor(3600);
|
2018-02-26 15:54:00 +03:00
|
|
|
$response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', ''));
|
2018-05-17 12:46:28 +03:00
|
|
|
$response->addHeader('Content-Disposition', 'attachment; filename="' . $key . '"');
|
2018-05-08 14:06:31 +03:00
|
|
|
if (!$useSvg) {
|
2018-04-20 17:21:11 +03:00
|
|
|
$response->addHeader('Content-Type', 'image/png');
|
|
|
|
} else {
|
|
|
|
$response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', ''));
|
|
|
|
}
|
2016-06-21 22:21:46 +03:00
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoCSRFRequired
|
|
|
|
* @PublicPage
|
2018-10-17 10:24:21 +03:00
|
|
|
* @NoSameSiteCookieRequired
|
2016-06-21 22:21:46 +03:00
|
|
|
*
|
2017-02-17 18:42:07 +03:00
|
|
|
* @return FileDisplayResponse|NotFoundResponse
|
2018-02-26 15:54:00 +03:00
|
|
|
* @throws NotPermittedException
|
|
|
|
* @throws \Exception
|
|
|
|
* @throws \OCP\App\AppPathNotFoundException
|
2016-06-21 22:21:46 +03:00
|
|
|
*/
|
|
|
|
public function getStylesheet() {
|
2018-02-21 09:44:37 +03:00
|
|
|
$appPath = $this->appManager->getAppPath('theming');
|
|
|
|
|
2017-02-17 18:42:07 +03:00
|
|
|
/* SCSSCacher is required here
|
|
|
|
* We cannot rely on automatic caching done by \OC_Util::addStyle,
|
|
|
|
* since we need to add the cacheBuster value to the url
|
|
|
|
*/
|
2018-02-21 09:44:37 +03:00
|
|
|
$cssCached = $this->scssCacher->process($appPath, 'css/theming.scss', 'theming');
|
2020-04-10 15:19:56 +03:00
|
|
|
if (!$cssCached) {
|
2017-02-17 18:42:07 +03:00
|
|
|
return new NotFoundResponse();
|
2016-07-12 15:59:28 +03:00
|
|
|
}
|
2016-06-21 22:21:46 +03:00
|
|
|
|
2017-02-17 18:42:07 +03:00
|
|
|
try {
|
|
|
|
$cssFile = $this->scssCacher->getCachedCSS('theming', 'theming.css');
|
|
|
|
$response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']);
|
|
|
|
$response->cacheFor(86400);
|
|
|
|
return $response;
|
|
|
|
} catch (NotFoundException $e) {
|
|
|
|
return new NotFoundResponse();
|
2016-08-14 13:54:06 +03:00
|
|
|
}
|
2016-06-21 22:21:46 +03:00
|
|
|
}
|
2017-02-17 18:42:07 +03:00
|
|
|
|
2017-09-11 16:04:26 +03:00
|
|
|
/**
|
|
|
|
* @NoCSRFRequired
|
|
|
|
* @PublicPage
|
|
|
|
*
|
|
|
|
* @return Http\JSONResponse
|
|
|
|
*/
|
|
|
|
public function getManifest($app) {
|
|
|
|
$cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
|
|
|
|
$responseJS = [
|
|
|
|
'name' => $this->themingDefaults->getName(),
|
|
|
|
'start_url' => $this->urlGenerator->getBaseUrl(),
|
|
|
|
'icons' =>
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon',
|
|
|
|
['app' => $app]) . '?v=' . $cacheBusterValue,
|
2020-10-05 16:12:57 +03:00
|
|
|
'type' => 'image/png',
|
|
|
|
'sizes' => '128x128'
|
2017-09-11 16:04:26 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon',
|
|
|
|
['app' => $app]) . '?v=' . $cacheBusterValue,
|
|
|
|
'type' => 'image/svg+xml',
|
|
|
|
'sizes' => '16x16'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'display' => 'standalone'
|
|
|
|
];
|
|
|
|
$response = new Http\JSONResponse($responseJS);
|
|
|
|
$response->cacheFor(3600);
|
|
|
|
return $response;
|
|
|
|
}
|
2016-06-09 22:46:30 +03:00
|
|
|
}
|