2016-06-09 19:46:30 +00:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
|
2017-04-07 12:51:05 +00:00
|
|
|
|
* @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
|
2016-07-21 14:49:16 +00:00
|
|
|
|
*
|
2017-11-06 14:56:42 +00:00
|
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
|
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
2020-04-29 09:57:22 +00:00
|
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2019-12-03 18:57:53 +00:00
|
|
|
|
* @author Daniel Kesselberg <mail@danielkesselberg.de>
|
|
|
|
|
* @author Guillaume COMPAGNON <gcompagnon@outlook.com>
|
2017-11-06 14:56:42 +00:00
|
|
|
|
* @author Jan-Christoph Borchardt <hey@jancborchardt.net>
|
|
|
|
|
* @author Joachim Bauch <bauch@struktur.de>
|
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2021-06-04 19:52:51 +00:00
|
|
|
|
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
2020-12-16 13:54:15 +00:00
|
|
|
|
* @author Julien Veyssier <eneiluj@posteo.net>
|
2017-11-06 14:56:42 +00:00
|
|
|
|
* @author Julius Haertl <jus@bitgrid.net>
|
|
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
|
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2019-12-03 18:57:53 +00:00
|
|
|
|
* @author Michael Weimann <mail@michael-weimann.eu>
|
2017-11-06 14:56:42 +00:00
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2019-12-03 18:57:53 +00:00
|
|
|
|
* @author Patrik Kernstock <info@pkern.at>
|
|
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2017-11-06 14:56:42 +00:00
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
|
*
|
2016-06-09 19:46:30 +00: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
|
2021-06-04 19:52:51 +00:00
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2016-06-09 19:46:30 +00:00
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 18:57:53 +00:00
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-06-09 19:46:30 +00:00
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
namespace OCA\Theming;
|
|
|
|
|
|
2022-09-28 02:35:51 +00:00
|
|
|
|
use OCA\Theming\AppInfo\Application;
|
|
|
|
|
use OCA\Theming\Service\BackgroundService;
|
2017-09-12 07:09:45 +00:00
|
|
|
|
use OCP\App\AppPathNotFoundException;
|
|
|
|
|
use OCP\App\IAppManager;
|
2018-03-28 10:24:32 +00:00
|
|
|
|
use OCP\Files\NotFoundException;
|
2021-10-13 13:45:42 +00:00
|
|
|
|
use OCP\Files\SimpleFS\ISimpleFile;
|
2016-10-14 12:57:58 +00:00
|
|
|
|
use OCP\ICacheFactory;
|
2016-06-09 19:46:30 +00:00
|
|
|
|
use OCP\IConfig;
|
|
|
|
|
use OCP\IL10N;
|
2019-02-18 08:12:11 +00:00
|
|
|
|
use OCP\INavigationManager;
|
2016-06-09 19:46:30 +00:00
|
|
|
|
use OCP\IURLGenerator;
|
2022-09-28 02:35:51 +00:00
|
|
|
|
use OCP\IUserSession;
|
2016-06-09 19:46:30 +00:00
|
|
|
|
|
2016-08-12 13:30:35 +00:00
|
|
|
|
class ThemingDefaults extends \OC_Defaults {
|
|
|
|
|
|
2022-09-28 02:35:51 +00:00
|
|
|
|
private IConfig $config;
|
|
|
|
|
private IL10N $l;
|
|
|
|
|
private ImageManager $imageManager;
|
|
|
|
|
private IUserSession $userSession;
|
|
|
|
|
private IURLGenerator $urlGenerator;
|
|
|
|
|
private ICacheFactory $cacheFactory;
|
|
|
|
|
private Util $util;
|
|
|
|
|
private IAppManager $appManager;
|
|
|
|
|
private INavigationManager $navigationManager;
|
|
|
|
|
|
|
|
|
|
private string $name;
|
|
|
|
|
private string $title;
|
|
|
|
|
private string $entity;
|
|
|
|
|
private string $productName;
|
|
|
|
|
private string $url;
|
|
|
|
|
private string $color;
|
|
|
|
|
|
|
|
|
|
private string $iTunesAppId;
|
|
|
|
|
private string $iOSClientUrl;
|
|
|
|
|
private string $AndroidClientUrl;
|
|
|
|
|
private string $FDroidClientUrl;
|
2016-06-09 19:46:30 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2016-08-12 14:00:39 +00:00
|
|
|
|
* ThemingDefaults constructor.
|
2016-06-09 19:46:30 +00:00
|
|
|
|
*
|
|
|
|
|
* @param IConfig $config
|
|
|
|
|
* @param IL10N $l
|
2018-02-26 12:54:00 +00:00
|
|
|
|
* @param ImageManager $imageManager
|
2022-09-28 02:35:51 +00:00
|
|
|
|
* @param IUserSession $userSession
|
2016-06-09 19:46:30 +00:00
|
|
|
|
* @param IURLGenerator $urlGenerator
|
2016-11-04 17:55:00 +00:00
|
|
|
|
* @param ICacheFactory $cacheFactory
|
2017-02-17 15:42:07 +00:00
|
|
|
|
* @param Util $util
|
2017-09-12 07:09:45 +00:00
|
|
|
|
* @param IAppManager $appManager
|
2016-06-09 19:46:30 +00:00
|
|
|
|
*/
|
|
|
|
|
public function __construct(IConfig $config,
|
|
|
|
|
IL10N $l,
|
2022-09-28 02:35:51 +00:00
|
|
|
|
IUserSession $userSession,
|
2016-06-09 19:46:30 +00:00
|
|
|
|
IURLGenerator $urlGenerator,
|
2017-02-17 15:42:07 +00:00
|
|
|
|
ICacheFactory $cacheFactory,
|
2017-09-12 07:09:45 +00:00
|
|
|
|
Util $util,
|
2018-02-26 12:54:00 +00:00
|
|
|
|
ImageManager $imageManager,
|
2019-02-18 08:12:11 +00:00
|
|
|
|
IAppManager $appManager,
|
|
|
|
|
INavigationManager $navigationManager
|
2016-06-09 19:46:30 +00:00
|
|
|
|
) {
|
2017-04-28 16:08:51 +00:00
|
|
|
|
parent::__construct();
|
2016-06-09 19:46:30 +00:00
|
|
|
|
$this->config = $config;
|
|
|
|
|
$this->l = $l;
|
2018-02-26 12:54:00 +00:00
|
|
|
|
$this->imageManager = $imageManager;
|
2022-09-28 02:35:51 +00:00
|
|
|
|
$this->userSession = $userSession;
|
2016-06-09 19:46:30 +00:00
|
|
|
|
$this->urlGenerator = $urlGenerator;
|
2016-10-14 12:57:58 +00:00
|
|
|
|
$this->cacheFactory = $cacheFactory;
|
2017-02-17 15:42:07 +00:00
|
|
|
|
$this->util = $util;
|
2017-09-12 07:09:45 +00:00
|
|
|
|
$this->appManager = $appManager;
|
2019-02-18 08:12:11 +00:00
|
|
|
|
$this->navigationManager = $navigationManager;
|
2016-06-09 19:46:30 +00:00
|
|
|
|
|
2017-04-28 16:08:51 +00:00
|
|
|
|
$this->name = parent::getName();
|
2017-06-14 07:25:53 +00:00
|
|
|
|
$this->title = parent::getTitle();
|
|
|
|
|
$this->entity = parent::getEntity();
|
2021-06-16 13:52:49 +00:00
|
|
|
|
$this->productName = parent::getProductName();
|
2017-04-28 16:08:51 +00:00
|
|
|
|
$this->url = parent::getBaseUrl();
|
|
|
|
|
$this->color = parent::getColorPrimary();
|
2017-07-19 06:22:45 +00:00
|
|
|
|
$this->iTunesAppId = parent::getiTunesAppId();
|
|
|
|
|
$this->iOSClientUrl = parent::getiOSClientUrl();
|
2017-07-19 08:20:47 +00:00
|
|
|
|
$this->AndroidClientUrl = parent::getAndroidClientUrl();
|
2021-04-10 05:43:22 +00:00
|
|
|
|
$this->FDroidClientUrl = parent::getFDroidClientUrl();
|
2016-06-09 19:46:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getName() {
|
2017-03-16 14:01:50 +00:00
|
|
|
|
return strip_tags($this->config->getAppValue('theming', 'name', $this->name));
|
2016-06-09 19:46:30 +00:00
|
|
|
|
}
|
2016-06-21 19:21:46 +00:00
|
|
|
|
|
2016-07-15 06:45:55 +00:00
|
|
|
|
public function getHTMLName() {
|
|
|
|
|
return $this->config->getAppValue('theming', 'name', $this->name);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-11 17:36:26 +00:00
|
|
|
|
public function getTitle() {
|
2017-06-14 07:25:53 +00:00
|
|
|
|
return strip_tags($this->config->getAppValue('theming', 'name', $this->title));
|
2016-07-11 17:36:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 19:21:46 +00:00
|
|
|
|
public function getEntity() {
|
2017-06-14 07:25:53 +00:00
|
|
|
|
return strip_tags($this->config->getAppValue('theming', 'name', $this->entity));
|
2016-06-21 19:21:46 +00:00
|
|
|
|
}
|
2016-08-12 13:30:35 +00:00
|
|
|
|
|
2021-03-05 09:03:26 +00:00
|
|
|
|
public function getProductName() {
|
|
|
|
|
return strip_tags($this->config->getAppValue('theming', 'productName', $this->productName));
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 19:21:46 +00:00
|
|
|
|
public function getBaseUrl() {
|
2016-06-09 19:46:30 +00:00
|
|
|
|
return $this->config->getAppValue('theming', 'url', $this->url);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-26 13:26:58 +00:00
|
|
|
|
/**
|
2022-01-27 15:55:53 +00:00
|
|
|
|
* We pass a string and sanitizeHTML will return a string too in that case
|
2022-01-26 13:26:58 +00:00
|
|
|
|
* @psalm-suppress InvalidReturnStatement
|
|
|
|
|
* @psalm-suppress InvalidReturnType
|
|
|
|
|
*/
|
2020-03-31 12:02:39 +00:00
|
|
|
|
public function getSlogan(?string $lang = null) {
|
|
|
|
|
return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan($lang)));
|
2016-06-09 19:46:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-09 13:52:41 +00:00
|
|
|
|
public function getImprintUrl() {
|
2018-05-24 13:21:35 +00:00
|
|
|
|
return (string)$this->config->getAppValue('theming', 'imprintUrl', '');
|
2018-05-09 13:52:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-24 12:45:49 +00:00
|
|
|
|
public function getPrivacyUrl() {
|
2018-05-24 13:21:35 +00:00
|
|
|
|
return (string)$this->config->getAppValue('theming', 'privacyUrl', '');
|
2018-05-24 12:45:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 06:45:55 +00:00
|
|
|
|
public function getShortFooter() {
|
|
|
|
|
$slogan = $this->getSlogan();
|
2018-08-27 13:22:49 +00:00
|
|
|
|
$baseUrl = $this->getBaseUrl();
|
|
|
|
|
if ($baseUrl !== '') {
|
|
|
|
|
$footer = '<a href="' . $baseUrl . '" target="_blank"' .
|
2018-08-27 10:17:25 +00:00
|
|
|
|
' rel="noreferrer noopener" class="entity-name">' . $this->getEntity() . '</a>';
|
|
|
|
|
} else {
|
|
|
|
|
$footer = '<span class="entity-name">' .$this->getEntity() . '</span>';
|
|
|
|
|
}
|
|
|
|
|
$footer .= ($slogan !== '' ? ' – ' . $slogan : '');
|
2016-07-15 06:45:55 +00:00
|
|
|
|
|
2018-05-24 12:45:49 +00:00
|
|
|
|
$links = [
|
|
|
|
|
[
|
|
|
|
|
'text' => $this->l->t('Legal notice'),
|
|
|
|
|
'url' => (string)$this->getImprintUrl()
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'text' => $this->l->t('Privacy policy'),
|
|
|
|
|
'url' => (string)$this->getPrivacyUrl()
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
2019-02-18 08:12:11 +00:00
|
|
|
|
$navigation = $this->navigationManager->getAll(INavigationManager::TYPE_GUEST);
|
2020-04-09 11:53:40 +00:00
|
|
|
|
$guestNavigation = array_map(function ($nav) {
|
2019-02-18 08:12:11 +00:00
|
|
|
|
return [
|
|
|
|
|
'text' => $nav['name'],
|
|
|
|
|
'url' => $nav['href']
|
|
|
|
|
];
|
|
|
|
|
}, $navigation);
|
|
|
|
|
$links = array_merge($links, $guestNavigation);
|
|
|
|
|
|
2020-04-10 12:19:56 +00:00
|
|
|
|
$legalLinks = '';
|
|
|
|
|
$divider = '';
|
|
|
|
|
foreach ($links as $link) {
|
|
|
|
|
if ($link['url'] !== ''
|
2018-09-03 22:58:44 +00:00
|
|
|
|
&& filter_var($link['url'], FILTER_VALIDATE_URL)
|
2018-05-24 12:45:49 +00:00
|
|
|
|
) {
|
|
|
|
|
$legalLinks .= $divider . '<a href="' . $link['url'] . '" class="legal" target="_blank"' .
|
|
|
|
|
' rel="noreferrer noopener">' . $link['text'] . '</a>';
|
|
|
|
|
$divider = ' · ';
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-10 12:19:56 +00:00
|
|
|
|
if ($legalLinks !== '') {
|
2018-05-24 12:45:49 +00:00
|
|
|
|
$footer .= '<br/>' . $legalLinks;
|
2018-05-09 13:52:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 06:45:55 +00:00
|
|
|
|
return $footer;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-27 08:48:23 +00:00
|
|
|
|
/**
|
|
|
|
|
* Color that is used for the header as well as for mail headers
|
|
|
|
|
*/
|
2022-10-13 10:10:56 +00:00
|
|
|
|
public function getColorPrimary(): string {
|
2022-09-28 02:35:51 +00:00
|
|
|
|
$user = $this->userSession->getUser();
|
|
|
|
|
|
2022-10-05 10:14:03 +00:00
|
|
|
|
// admin-defined primary color
|
|
|
|
|
$defaultColor = $this->getDefaultColorPrimary();
|
2022-10-13 12:22:04 +00:00
|
|
|
|
|
|
|
|
|
if ($this->isUserThemingDisabled()) {
|
|
|
|
|
return $defaultColor;
|
|
|
|
|
}
|
2022-10-01 03:04:39 +00:00
|
|
|
|
|
2022-10-05 10:14:03 +00:00
|
|
|
|
// user-defined primary color
|
|
|
|
|
if (!empty($user)) {
|
2022-10-20 11:18:06 +00:00
|
|
|
|
$themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background_color', '');
|
2022-10-05 10:14:03 +00:00
|
|
|
|
// If the user selected a specific colour
|
|
|
|
|
if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $themingBackground)) {
|
|
|
|
|
return $themingBackground;
|
|
|
|
|
}
|
2022-10-05 09:34:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the default color is not valid, return the default background one
|
|
|
|
|
if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $defaultColor)) {
|
2022-09-29 01:38:23 +00:00
|
|
|
|
return BackgroundService::DEFAULT_COLOR;
|
2021-06-25 14:58:29 +00:00
|
|
|
|
}
|
2022-09-28 02:35:51 +00:00
|
|
|
|
|
2022-10-05 09:34:05 +00:00
|
|
|
|
// Finally, return the system global primary color
|
|
|
|
|
return $defaultColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the default color primary
|
|
|
|
|
*/
|
2022-10-13 10:10:56 +00:00
|
|
|
|
public function getDefaultColorPrimary(): string {
|
2022-10-20 14:03:19 +00:00
|
|
|
|
$color = $this->config->getAppValue(Application::APP_ID, 'color', '');
|
2022-10-05 09:34:05 +00:00
|
|
|
|
if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) {
|
|
|
|
|
$color = '#0082c9';
|
|
|
|
|
}
|
2021-06-25 14:58:29 +00:00
|
|
|
|
return $color;
|
2016-06-09 19:46:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-23 20:02:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* Themed logo url
|
|
|
|
|
*
|
2017-05-08 12:51:55 +00:00
|
|
|
|
* @param bool $useSvg Whether to point to the SVG image or a fallback
|
2016-08-23 20:02:28 +00:00
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2018-02-26 12:54:00 +00:00
|
|
|
|
public function getLogo($useSvg = true): string {
|
2020-10-20 10:36:41 +00:00
|
|
|
|
$logo = $this->config->getAppValue('theming', 'logoMime', '');
|
2017-04-07 12:51:05 +00:00
|
|
|
|
|
2020-11-04 08:59:32 +00:00
|
|
|
|
// short cut to avoid setting up the filesystem just to check if the logo is there
|
|
|
|
|
//
|
|
|
|
|
// explanation: if an SVG is requested and the app config value for logoMime is set then the logo is there.
|
|
|
|
|
// otherwise we need to check it and maybe also generate a PNG from the SVG (that's done in getImage() which
|
|
|
|
|
// needs to be called then)
|
|
|
|
|
if ($useSvg === true && $logo !== false) {
|
|
|
|
|
$logoExists = true;
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
$this->imageManager->getImage('logo', $useSvg);
|
|
|
|
|
$logoExists = true;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
$logoExists = false;
|
|
|
|
|
}
|
2017-04-07 12:51:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-09 01:48:57 +00:00
|
|
|
|
$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
|
|
|
|
|
|
2020-04-10 12:19:56 +00:00
|
|
|
|
if (!$logo || !$logoExists) {
|
|
|
|
|
if ($useSvg) {
|
2018-08-28 13:58:27 +00:00
|
|
|
|
$logo = $this->urlGenerator->imagePath('core', 'logo/logo.svg');
|
2017-05-08 12:51:55 +00:00
|
|
|
|
} else {
|
2018-08-28 13:58:27 +00:00
|
|
|
|
$logo = $this->urlGenerator->imagePath('core', 'logo/logo.png');
|
2017-05-08 12:51:55 +00:00
|
|
|
|
}
|
|
|
|
|
return $logo . '?v=' . $cacheBusterCounter;
|
2016-08-23 20:02:28 +00:00
|
|
|
|
}
|
2017-04-07 12:51:05 +00:00
|
|
|
|
|
2018-04-20 14:21:11 +00:00
|
|
|
|
return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo', 'useSvg' => $useSvg, 'v' => $cacheBusterCounter ]);
|
2016-08-23 20:02:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Themed background image url
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2018-02-26 12:54:00 +00:00
|
|
|
|
public function getBackground(): string {
|
2018-03-26 16:43:05 +00:00
|
|
|
|
return $this->imageManager->getImageUrl('background');
|
2016-08-23 20:02:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-19 06:22:45 +00:00
|
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getiTunesAppId() {
|
|
|
|
|
return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getiOSClientUrl() {
|
|
|
|
|
return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-19 08:20:47 +00:00
|
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getAndroidClientUrl() {
|
|
|
|
|
return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-10 05:43:22 +00:00
|
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getFDroidClientUrl() {
|
|
|
|
|
return $this->config->getAppValue('theming', 'FDroidClientUrl', $this->FDroidClientUrl);
|
|
|
|
|
}
|
2017-02-17 15:42:07 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array scss variables to overwrite
|
|
|
|
|
*/
|
|
|
|
|
public function getScssVariables() {
|
2020-11-30 12:06:10 +00:00
|
|
|
|
$cacheBuster = $this->config->getAppValue('theming', 'cachebuster', '0');
|
|
|
|
|
$cache = $this->cacheFactory->createDistributed('theming-' . $cacheBuster . '-' . $this->urlGenerator->getBaseUrl());
|
2017-02-17 15:42:07 +00:00
|
|
|
|
if ($value = $cache->get('getScssVariables')) {
|
|
|
|
|
return $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$variables = [
|
2020-11-30 12:06:10 +00:00
|
|
|
|
'theming-cachebuster' => "'" . $cacheBuster . "'",
|
2018-02-26 12:54:00 +00:00
|
|
|
|
'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'",
|
|
|
|
|
'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'",
|
|
|
|
|
'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'",
|
|
|
|
|
'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'"
|
2017-02-17 15:42:07 +00:00
|
|
|
|
];
|
2019-11-24 20:51:02 +00:00
|
|
|
|
|
2018-08-28 16:21:17 +00:00
|
|
|
|
$variables['image-logo'] = "url('".$this->imageManager->getImageUrl('logo')."')";
|
2019-08-21 15:18:23 +00:00
|
|
|
|
$variables['image-logoheader'] = "url('".$this->imageManager->getImageUrl('logoheader')."')";
|
|
|
|
|
$variables['image-favicon'] = "url('".$this->imageManager->getImageUrl('favicon')."')";
|
2018-06-03 09:26:06 +00:00
|
|
|
|
$variables['image-login-background'] = "url('".$this->imageManager->getImageUrl('background')."')";
|
2016-10-12 14:45:07 +00:00
|
|
|
|
$variables['image-login-plain'] = 'false';
|
2017-02-17 15:42:07 +00:00
|
|
|
|
|
2020-10-20 10:36:41 +00:00
|
|
|
|
if ($this->config->getAppValue('theming', 'color', '') !== '') {
|
2017-02-17 15:42:07 +00:00
|
|
|
|
$variables['color-primary'] = $this->getColorPrimary();
|
2017-12-08 11:16:05 +00:00
|
|
|
|
$variables['color-primary-text'] = $this->getTextColorPrimary();
|
2017-08-11 13:11:47 +00:00
|
|
|
|
$variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary());
|
2017-02-17 15:42:07 +00:00
|
|
|
|
}
|
2016-10-12 14:45:07 +00:00
|
|
|
|
|
2020-10-20 10:36:41 +00:00
|
|
|
|
if ($this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor') {
|
2016-10-12 14:45:07 +00:00
|
|
|
|
$variables['image-login-plain'] = 'true';
|
|
|
|
|
}
|
2018-05-24 13:21:35 +00:00
|
|
|
|
|
|
|
|
|
$variables['has-legal-links'] = 'false';
|
2020-04-10 12:19:56 +00:00
|
|
|
|
if ($this->getImprintUrl() !== '' || $this->getPrivacyUrl() !== '') {
|
2018-05-24 13:21:35 +00:00
|
|
|
|
$variables['has-legal-links'] = 'true';
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 15:42:07 +00:00
|
|
|
|
$cache->set('getScssVariables', $variables);
|
|
|
|
|
return $variables;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-11 13:03:47 +00:00
|
|
|
|
/**
|
|
|
|
|
* Check if the image should be replaced by the theming app
|
|
|
|
|
* and return the new image location then
|
|
|
|
|
*
|
|
|
|
|
* @param string $app name of the app
|
|
|
|
|
* @param string $image filename of the image
|
|
|
|
|
* @return bool|string false if image should not replaced, otherwise the location of the image
|
|
|
|
|
*/
|
|
|
|
|
public function replaceImagePath($app, $image) {
|
2018-10-11 10:04:03 +00:00
|
|
|
|
if ($app === '' || $app === 'files_sharing') {
|
2017-09-11 13:03:47 +00:00
|
|
|
|
$app = 'core';
|
|
|
|
|
}
|
|
|
|
|
$cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
|
|
|
|
|
|
2019-10-18 16:11:34 +00:00
|
|
|
|
$route = false;
|
2021-10-13 13:45:42 +00:00
|
|
|
|
if ($image === 'favicon.ico' && ($this->imageManager->shouldReplaceIcons() || $this->getCustomFavicon() !== null)) {
|
2019-10-18 16:11:34 +00:00
|
|
|
|
$route = $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]);
|
2017-09-11 13:03:47 +00:00
|
|
|
|
}
|
2021-10-13 13:45:42 +00:00
|
|
|
|
if (($image === 'favicon-touch.png' || $image === 'favicon-fb.png') && ($this->imageManager->shouldReplaceIcons() || $this->getCustomFavicon() !== null)) {
|
2019-10-18 16:11:34 +00:00
|
|
|
|
$route = $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]);
|
2017-09-11 13:03:47 +00:00
|
|
|
|
}
|
|
|
|
|
if ($image === 'manifest.json') {
|
2017-09-12 07:09:45 +00:00
|
|
|
|
try {
|
|
|
|
|
$appPath = $this->appManager->getAppPath($app);
|
|
|
|
|
if (file_exists($appPath . '/img/manifest.json')) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-04-10 12:19:56 +00:00
|
|
|
|
} catch (AppPathNotFoundException $e) {
|
|
|
|
|
}
|
2021-08-16 19:39:55 +00:00
|
|
|
|
$route = $this->urlGenerator->linkToRoute('theming.Theming.getManifest', ['app' => $app ]);
|
2017-09-11 13:03:47 +00:00
|
|
|
|
}
|
2020-04-09 14:07:47 +00:00
|
|
|
|
if (strpos($image, 'filetypes/') === 0 && file_exists(\OC::$SERVERROOT . '/core/img/' . $image)) {
|
2019-10-18 16:11:34 +00:00
|
|
|
|
$route = $this->urlGenerator->linkToRoute('theming.Icon.getThemedIcon', ['app' => $app, 'image' => $image]);
|
2019-06-05 08:36:27 +00:00
|
|
|
|
}
|
2019-10-18 16:11:34 +00:00
|
|
|
|
|
|
|
|
|
if ($route) {
|
2022-11-15 15:55:37 +00:00
|
|
|
|
return $route . '?v=' . $this->util->getCacheBuster();
|
2019-10-18 16:11:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-11 13:03:47 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-09-03 22:58:44 +00:00
|
|
|
|
|
2021-10-13 13:45:42 +00:00
|
|
|
|
protected function getCustomFavicon(): ?ISimpleFile {
|
|
|
|
|
try {
|
|
|
|
|
return $this->imageManager->getImage('favicon');
|
|
|
|
|
} catch (NotFoundException $e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 19:21:46 +00:00
|
|
|
|
/**
|
|
|
|
|
* Increases the cache buster key
|
|
|
|
|
*/
|
2022-10-08 00:52:09 +00:00
|
|
|
|
public function increaseCacheBuster(): void {
|
2022-01-26 13:26:58 +00:00
|
|
|
|
$cacheBusterKey = (int)$this->config->getAppValue('theming', 'cachebuster', '0');
|
|
|
|
|
$this->config->setAppValue('theming', 'cachebuster', (string)($cacheBusterKey + 1));
|
2018-03-26 10:28:25 +00:00
|
|
|
|
$this->cacheFactory->createDistributed('theming-')->clear();
|
2018-03-28 10:24:51 +00:00
|
|
|
|
$this->cacheFactory->createDistributed('imagePath')->clear();
|
2016-06-09 19:46:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-06-21 19:21:46 +00:00
|
|
|
|
* Update setting in the database
|
2016-06-09 19:46:30 +00:00
|
|
|
|
*
|
2016-06-21 19:21:46 +00:00
|
|
|
|
* @param string $setting
|
|
|
|
|
* @param string $value
|
2016-06-09 19:46:30 +00:00
|
|
|
|
*/
|
|
|
|
|
public function set($setting, $value) {
|
|
|
|
|
$this->config->setAppValue('theming', $setting, $value);
|
2016-06-21 19:21:46 +00:00
|
|
|
|
$this->increaseCacheBuster();
|
2016-06-09 19:46:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-06-21 19:21:46 +00:00
|
|
|
|
* Revert settings to the default value
|
2016-06-09 19:46:30 +00:00
|
|
|
|
*
|
|
|
|
|
* @param string $setting setting which should be reverted
|
|
|
|
|
* @return string default value
|
|
|
|
|
*/
|
|
|
|
|
public function undo($setting) {
|
2016-06-21 19:21:46 +00:00
|
|
|
|
$this->config->deleteAppValue('theming', $setting);
|
|
|
|
|
$this->increaseCacheBuster();
|
|
|
|
|
|
2020-09-23 15:48:48 +00:00
|
|
|
|
$returnValue = '';
|
2016-06-21 19:21:46 +00:00
|
|
|
|
switch ($setting) {
|
|
|
|
|
case 'name':
|
|
|
|
|
$returnValue = $this->getEntity();
|
|
|
|
|
break;
|
|
|
|
|
case 'url':
|
|
|
|
|
$returnValue = $this->getBaseUrl();
|
|
|
|
|
break;
|
|
|
|
|
case 'slogan':
|
|
|
|
|
$returnValue = $this->getSlogan();
|
|
|
|
|
break;
|
|
|
|
|
case 'color':
|
2022-10-20 11:18:06 +00:00
|
|
|
|
$returnValue = $this->getDefaultColorPrimary();
|
2016-06-21 19:21:46 +00:00
|
|
|
|
break;
|
2020-09-23 15:48:48 +00:00
|
|
|
|
case 'logo':
|
|
|
|
|
case 'logoheader':
|
|
|
|
|
case 'background':
|
|
|
|
|
case 'favicon':
|
|
|
|
|
$this->imageManager->delete($setting);
|
2016-06-21 19:21:46 +00:00
|
|
|
|
break;
|
2016-06-09 19:46:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $returnValue;
|
|
|
|
|
}
|
2017-12-08 11:16:05 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Color of text in the header and primary buttons
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getTextColorPrimary() {
|
|
|
|
|
return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff';
|
|
|
|
|
}
|
2022-10-13 12:22:04 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Has the admin disabled user customization
|
|
|
|
|
*/
|
|
|
|
|
public function isUserThemingDisabled(): bool {
|
|
|
|
|
return $this->config->getAppValue('theming', 'disable-user-theming', 'no') === 'yes';
|
|
|
|
|
}
|
2016-06-09 19:46:30 +00:00
|
|
|
|
}
|