2016-06-09 22:46:30 +03:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
|
2017-04-07 15:51:05 +03:00
|
|
|
|
* @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
|
2016-07-21 17:49:16 +03:00
|
|
|
|
*
|
2017-11-06 17:56:42 +03:00
|
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
|
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
2020-04-29 12:57:22 +03:00
|
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2019-12-03 21:57:53 +03:00
|
|
|
|
* @author Daniel Kesselberg <mail@danielkesselberg.de>
|
|
|
|
|
* @author Guillaume COMPAGNON <gcompagnon@outlook.com>
|
2017-11-06 17:56:42 +03:00
|
|
|
|
* @author Jan-Christoph Borchardt <hey@jancborchardt.net>
|
|
|
|
|
* @author Joachim Bauch <bauch@struktur.de>
|
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
|
* @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
|
2017-11-06 17:56:42 +03:00
|
|
|
|
* @author Julius Haertl <jus@bitgrid.net>
|
|
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
|
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2019-12-03 21:57:53 +03:00
|
|
|
|
* @author Michael Weimann <mail@michael-weimann.eu>
|
2017-11-06 17:56:42 +03:00
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2019-12-03 21:57:53 +03:00
|
|
|
|
* @author Patrik Kernstock <info@pkern.at>
|
|
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2017-11-06 17:56:42 +03:00
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
|
*
|
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;
|
|
|
|
|
|
2017-09-12 10:09:45 +03:00
|
|
|
|
use OCP\App\AppPathNotFoundException;
|
|
|
|
|
use OCP\App\IAppManager;
|
2018-03-28 13:24:32 +03:00
|
|
|
|
use OCP\Files\NotFoundException;
|
2016-10-14 15:57:58 +03:00
|
|
|
|
use OCP\ICacheFactory;
|
2016-06-09 22:46:30 +03:00
|
|
|
|
use OCP\IConfig;
|
|
|
|
|
use OCP\IL10N;
|
2019-02-18 11:12:11 +03:00
|
|
|
|
use OCP\INavigationManager;
|
2016-06-09 22:46:30 +03:00
|
|
|
|
use OCP\IURLGenerator;
|
|
|
|
|
|
2016-08-12 16:30:35 +03:00
|
|
|
|
class ThemingDefaults extends \OC_Defaults {
|
|
|
|
|
|
2016-06-09 22:46:30 +03:00
|
|
|
|
/** @var IConfig */
|
|
|
|
|
private $config;
|
2016-07-28 17:07:23 +03:00
|
|
|
|
/** @var IL10N */
|
2016-06-09 22:46:30 +03:00
|
|
|
|
private $l;
|
2018-02-26 15:54:00 +03:00
|
|
|
|
/** @var ImageManager */
|
|
|
|
|
private $imageManager;
|
2016-06-09 22:46:30 +03:00
|
|
|
|
/** @var IURLGenerator */
|
|
|
|
|
private $urlGenerator;
|
2016-10-14 15:57:58 +03:00
|
|
|
|
/** @var ICacheFactory */
|
|
|
|
|
private $cacheFactory;
|
2017-09-12 10:09:45 +03:00
|
|
|
|
/** @var Util */
|
|
|
|
|
private $util;
|
|
|
|
|
/** @var IAppManager */
|
|
|
|
|
private $appManager;
|
2019-02-18 11:12:11 +03:00
|
|
|
|
/** @var INavigationManager */
|
|
|
|
|
private $navigationManager;
|
|
|
|
|
|
2016-06-09 22:46:30 +03:00
|
|
|
|
/** @var string */
|
|
|
|
|
private $name;
|
|
|
|
|
/** @var string */
|
2017-06-14 10:25:53 +03:00
|
|
|
|
private $title;
|
|
|
|
|
/** @var string */
|
|
|
|
|
private $entity;
|
|
|
|
|
/** @var string */
|
2016-06-09 22:46:30 +03:00
|
|
|
|
private $url;
|
|
|
|
|
/** @var string */
|
|
|
|
|
private $color;
|
2017-09-12 10:09:45 +03:00
|
|
|
|
|
2017-07-19 09:22:45 +03:00
|
|
|
|
/** @var string */
|
|
|
|
|
private $iTunesAppId;
|
|
|
|
|
/** @var string */
|
|
|
|
|
private $iOSClientUrl;
|
2017-07-19 11:20:47 +03:00
|
|
|
|
/** @var string */
|
|
|
|
|
private $AndroidClientUrl;
|
2016-06-09 22:46:30 +03:00
|
|
|
|
|
|
|
|
|
/**
|
2016-08-12 17:00:39 +03:00
|
|
|
|
* ThemingDefaults constructor.
|
2016-06-09 22:46:30 +03:00
|
|
|
|
*
|
|
|
|
|
* @param IConfig $config
|
|
|
|
|
* @param IL10N $l
|
2018-02-26 15:54:00 +03:00
|
|
|
|
* @param ImageManager $imageManager
|
2016-06-09 22:46:30 +03:00
|
|
|
|
* @param IURLGenerator $urlGenerator
|
2016-11-04 20:55:00 +03:00
|
|
|
|
* @param ICacheFactory $cacheFactory
|
2017-02-17 18:42:07 +03:00
|
|
|
|
* @param Util $util
|
2017-09-12 10:09:45 +03:00
|
|
|
|
* @param IAppManager $appManager
|
2016-06-09 22:46:30 +03:00
|
|
|
|
*/
|
|
|
|
|
public function __construct(IConfig $config,
|
|
|
|
|
IL10N $l,
|
|
|
|
|
IURLGenerator $urlGenerator,
|
2017-02-17 18:42:07 +03:00
|
|
|
|
ICacheFactory $cacheFactory,
|
2017-09-12 10:09:45 +03:00
|
|
|
|
Util $util,
|
2018-02-26 15:54:00 +03:00
|
|
|
|
ImageManager $imageManager,
|
2019-02-18 11:12:11 +03:00
|
|
|
|
IAppManager $appManager,
|
|
|
|
|
INavigationManager $navigationManager
|
2016-06-09 22:46:30 +03:00
|
|
|
|
) {
|
2017-04-28 19:08:51 +03:00
|
|
|
|
parent::__construct();
|
2016-06-09 22:46:30 +03:00
|
|
|
|
$this->config = $config;
|
|
|
|
|
$this->l = $l;
|
2018-02-26 15:54:00 +03:00
|
|
|
|
$this->imageManager = $imageManager;
|
2016-06-09 22:46:30 +03:00
|
|
|
|
$this->urlGenerator = $urlGenerator;
|
2016-10-14 15:57:58 +03:00
|
|
|
|
$this->cacheFactory = $cacheFactory;
|
2017-02-17 18:42:07 +03:00
|
|
|
|
$this->util = $util;
|
2017-09-12 10:09:45 +03:00
|
|
|
|
$this->appManager = $appManager;
|
2019-02-18 11:12:11 +03:00
|
|
|
|
$this->navigationManager = $navigationManager;
|
2016-06-09 22:46:30 +03:00
|
|
|
|
|
2017-04-28 19:08:51 +03:00
|
|
|
|
$this->name = parent::getName();
|
2017-06-14 10:25:53 +03:00
|
|
|
|
$this->title = parent::getTitle();
|
|
|
|
|
$this->entity = parent::getEntity();
|
2017-04-28 19:08:51 +03:00
|
|
|
|
$this->url = parent::getBaseUrl();
|
|
|
|
|
$this->color = parent::getColorPrimary();
|
2017-07-19 09:22:45 +03:00
|
|
|
|
$this->iTunesAppId = parent::getiTunesAppId();
|
|
|
|
|
$this->iOSClientUrl = parent::getiOSClientUrl();
|
2017-07-19 11:20:47 +03:00
|
|
|
|
$this->AndroidClientUrl = parent::getAndroidClientUrl();
|
2016-06-09 22:46:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getName() {
|
2017-03-16 17:01:50 +03:00
|
|
|
|
return strip_tags($this->config->getAppValue('theming', 'name', $this->name));
|
2016-06-09 22:46:30 +03:00
|
|
|
|
}
|
2016-06-21 22:21:46 +03:00
|
|
|
|
|
2016-07-15 09:45:55 +03:00
|
|
|
|
public function getHTMLName() {
|
|
|
|
|
return $this->config->getAppValue('theming', 'name', $this->name);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-11 20:36:26 +03:00
|
|
|
|
public function getTitle() {
|
2017-06-14 10:25:53 +03:00
|
|
|
|
return strip_tags($this->config->getAppValue('theming', 'name', $this->title));
|
2016-07-11 20:36:26 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 22:21:46 +03:00
|
|
|
|
public function getEntity() {
|
2017-06-14 10:25:53 +03:00
|
|
|
|
return strip_tags($this->config->getAppValue('theming', 'name', $this->entity));
|
2016-06-21 22:21:46 +03:00
|
|
|
|
}
|
2016-08-12 16:30:35 +03:00
|
|
|
|
|
2016-06-21 22:21:46 +03:00
|
|
|
|
public function getBaseUrl() {
|
2016-06-09 22:46:30 +03:00
|
|
|
|
return $this->config->getAppValue('theming', 'url', $this->url);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-31 15:02:39 +03:00
|
|
|
|
public function getSlogan(?string $lang = null) {
|
|
|
|
|
return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan($lang)));
|
2016-06-09 22:46:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-09 16:52:41 +03:00
|
|
|
|
public function getImprintUrl() {
|
2018-05-24 16:21:35 +03:00
|
|
|
|
return (string)$this->config->getAppValue('theming', 'imprintUrl', '');
|
2018-05-09 16:52:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-24 15:45:49 +03:00
|
|
|
|
public function getPrivacyUrl() {
|
2018-05-24 16:21:35 +03:00
|
|
|
|
return (string)$this->config->getAppValue('theming', 'privacyUrl', '');
|
2018-05-24 15:45:49 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 09:45:55 +03:00
|
|
|
|
public function getShortFooter() {
|
|
|
|
|
$slogan = $this->getSlogan();
|
2018-08-27 16:22:49 +03:00
|
|
|
|
$baseUrl = $this->getBaseUrl();
|
|
|
|
|
if ($baseUrl !== '') {
|
|
|
|
|
$footer = '<a href="' . $baseUrl . '" target="_blank"' .
|
2018-08-27 13:17:25 +03: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 09:45:55 +03:00
|
|
|
|
|
2018-05-24 15:45:49 +03: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 11:12:11 +03:00
|
|
|
|
$navigation = $this->navigationManager->getAll(INavigationManager::TYPE_GUEST);
|
2020-04-09 14:53:40 +03:00
|
|
|
|
$guestNavigation = array_map(function ($nav) {
|
2019-02-18 11:12:11 +03:00
|
|
|
|
return [
|
|
|
|
|
'text' => $nav['name'],
|
|
|
|
|
'url' => $nav['href']
|
|
|
|
|
];
|
|
|
|
|
}, $navigation);
|
|
|
|
|
$links = array_merge($links, $guestNavigation);
|
|
|
|
|
|
2020-04-10 15:19:56 +03:00
|
|
|
|
$legalLinks = '';
|
|
|
|
|
$divider = '';
|
|
|
|
|
foreach ($links as $link) {
|
|
|
|
|
if ($link['url'] !== ''
|
2018-09-04 01:58:44 +03:00
|
|
|
|
&& filter_var($link['url'], FILTER_VALIDATE_URL)
|
2018-05-24 15:45:49 +03:00
|
|
|
|
) {
|
|
|
|
|
$legalLinks .= $divider . '<a href="' . $link['url'] . '" class="legal" target="_blank"' .
|
|
|
|
|
' rel="noreferrer noopener">' . $link['text'] . '</a>';
|
|
|
|
|
$divider = ' · ';
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-10 15:19:56 +03:00
|
|
|
|
if ($legalLinks !== '') {
|
2018-05-24 15:45:49 +03:00
|
|
|
|
$footer .= '<br/>' . $legalLinks;
|
2018-05-09 16:52:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 09:45:55 +03:00
|
|
|
|
return $footer;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-27 11:48:23 +03:00
|
|
|
|
/**
|
|
|
|
|
* Color that is used for the header as well as for mail headers
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2017-03-28 02:37:47 +03:00
|
|
|
|
public function getColorPrimary() {
|
2016-06-09 22:46:30 +03:00
|
|
|
|
return $this->config->getAppValue('theming', 'color', $this->color);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-23 23:02:28 +03:00
|
|
|
|
/**
|
|
|
|
|
* Themed logo url
|
|
|
|
|
*
|
2017-05-08 15:51:55 +03:00
|
|
|
|
* @param bool $useSvg Whether to point to the SVG image or a fallback
|
2016-08-23 23:02:28 +03:00
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2018-02-26 15:54:00 +03:00
|
|
|
|
public function getLogo($useSvg = true): string {
|
2017-02-17 18:42:07 +03:00
|
|
|
|
$logo = $this->config->getAppValue('theming', 'logoMime', false);
|
2017-04-07 15:51:05 +03:00
|
|
|
|
|
|
|
|
|
$logoExists = true;
|
|
|
|
|
try {
|
2018-04-20 17:21:11 +03:00
|
|
|
|
$this->imageManager->getImage('logo', $useSvg);
|
2017-04-07 15:51:05 +03:00
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
$logoExists = false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-09 04:48:57 +03:00
|
|
|
|
$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
|
|
|
|
|
|
2020-04-10 15:19:56 +03:00
|
|
|
|
if (!$logo || !$logoExists) {
|
|
|
|
|
if ($useSvg) {
|
2018-08-28 16:58:27 +03:00
|
|
|
|
$logo = $this->urlGenerator->imagePath('core', 'logo/logo.svg');
|
2017-05-08 15:51:55 +03:00
|
|
|
|
} else {
|
2018-08-28 16:58:27 +03:00
|
|
|
|
$logo = $this->urlGenerator->imagePath('core', 'logo/logo.png');
|
2017-05-08 15:51:55 +03:00
|
|
|
|
}
|
|
|
|
|
return $logo . '?v=' . $cacheBusterCounter;
|
2016-08-23 23:02:28 +03:00
|
|
|
|
}
|
2017-04-07 15:51:05 +03:00
|
|
|
|
|
2018-04-20 17:21:11 +03:00
|
|
|
|
return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo', 'useSvg' => $useSvg, 'v' => $cacheBusterCounter ]);
|
2016-08-23 23:02:28 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Themed background image url
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2018-02-26 15:54:00 +03:00
|
|
|
|
public function getBackground(): string {
|
2018-03-26 19:43:05 +03:00
|
|
|
|
return $this->imageManager->getImageUrl('background');
|
2016-08-23 23:02:28 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-19 09:22:45 +03: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 11:20:47 +03:00
|
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getAndroidClientUrl() {
|
|
|
|
|
return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 18:42:07 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array scss variables to overwrite
|
|
|
|
|
*/
|
|
|
|
|
public function getScssVariables() {
|
2020-11-30 15:06:10 +03:00
|
|
|
|
$cacheBuster = $this->config->getAppValue('theming', 'cachebuster', '0');
|
|
|
|
|
$cache = $this->cacheFactory->createDistributed('theming-' . $cacheBuster . '-' . $this->urlGenerator->getBaseUrl());
|
2017-02-17 18:42:07 +03:00
|
|
|
|
if ($value = $cache->get('getScssVariables')) {
|
|
|
|
|
return $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$variables = [
|
2020-11-30 15:06:10 +03:00
|
|
|
|
'theming-cachebuster' => "'" . $cacheBuster . "'",
|
2018-02-26 15:54:00 +03: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 18:42:07 +03:00
|
|
|
|
];
|
2019-11-24 23:51:02 +03:00
|
|
|
|
|
2018-08-28 19:21:17 +03:00
|
|
|
|
$variables['image-logo'] = "url('".$this->imageManager->getImageUrl('logo')."')";
|
2019-08-21 18:18:23 +03:00
|
|
|
|
$variables['image-logoheader'] = "url('".$this->imageManager->getImageUrl('logoheader')."')";
|
|
|
|
|
$variables['image-favicon'] = "url('".$this->imageManager->getImageUrl('favicon')."')";
|
2018-06-03 12:26:06 +03:00
|
|
|
|
$variables['image-login-background'] = "url('".$this->imageManager->getImageUrl('background')."')";
|
2016-10-12 17:45:07 +03:00
|
|
|
|
$variables['image-login-plain'] = 'false';
|
2017-02-17 18:42:07 +03:00
|
|
|
|
|
|
|
|
|
if ($this->config->getAppValue('theming', 'color', null) !== null) {
|
|
|
|
|
$variables['color-primary'] = $this->getColorPrimary();
|
2017-12-08 14:16:05 +03:00
|
|
|
|
$variables['color-primary-text'] = $this->getTextColorPrimary();
|
2017-08-11 16:11:47 +03:00
|
|
|
|
$variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary());
|
2017-02-17 18:42:07 +03:00
|
|
|
|
}
|
2016-10-12 17:45:07 +03:00
|
|
|
|
|
|
|
|
|
if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') {
|
|
|
|
|
$variables['image-login-plain'] = 'true';
|
|
|
|
|
}
|
2018-05-24 16:21:35 +03:00
|
|
|
|
|
|
|
|
|
$variables['has-legal-links'] = 'false';
|
2020-04-10 15:19:56 +03:00
|
|
|
|
if ($this->getImprintUrl() !== '' || $this->getPrivacyUrl() !== '') {
|
2018-05-24 16:21:35 +03:00
|
|
|
|
$variables['has-legal-links'] = 'true';
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 18:42:07 +03:00
|
|
|
|
$cache->set('getScssVariables', $variables);
|
|
|
|
|
return $variables;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-11 16:03:47 +03: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 13:04:03 +03:00
|
|
|
|
if ($app === '' || $app === 'files_sharing') {
|
2017-09-11 16:03:47 +03:00
|
|
|
|
$app = 'core';
|
|
|
|
|
}
|
|
|
|
|
$cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
|
|
|
|
|
|
2018-03-28 13:24:51 +03:00
|
|
|
|
try {
|
|
|
|
|
$customFavicon = $this->imageManager->getImage('favicon');
|
|
|
|
|
} catch (NotFoundException $e) {
|
|
|
|
|
$customFavicon = null;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-18 19:11:34 +03:00
|
|
|
|
$route = false;
|
2018-06-05 17:59:05 +03:00
|
|
|
|
if ($image === 'favicon.ico' && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) {
|
2019-10-18 19:11:34 +03:00
|
|
|
|
$route = $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]);
|
2017-09-11 16:03:47 +03:00
|
|
|
|
}
|
2020-01-21 18:34:08 +03:00
|
|
|
|
if (($image === 'favicon-touch.png' || $image === 'favicon-fb.png') && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) {
|
2019-10-18 19:11:34 +03:00
|
|
|
|
$route = $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]);
|
2017-09-11 16:03:47 +03:00
|
|
|
|
}
|
|
|
|
|
if ($image === 'manifest.json') {
|
2017-09-12 10:09:45 +03:00
|
|
|
|
try {
|
|
|
|
|
$appPath = $this->appManager->getAppPath($app);
|
|
|
|
|
if (file_exists($appPath . '/img/manifest.json')) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-04-10 15:19:56 +03:00
|
|
|
|
} catch (AppPathNotFoundException $e) {
|
|
|
|
|
}
|
2019-10-18 19:11:34 +03:00
|
|
|
|
$route = $this->urlGenerator->linkToRoute('theming.Theming.getManifest');
|
2017-09-11 16:03:47 +03:00
|
|
|
|
}
|
2020-04-09 17:07:47 +03:00
|
|
|
|
if (strpos($image, 'filetypes/') === 0 && file_exists(\OC::$SERVERROOT . '/core/img/' . $image)) {
|
2019-10-18 19:11:34 +03:00
|
|
|
|
$route = $this->urlGenerator->linkToRoute('theming.Icon.getThemedIcon', ['app' => $app, 'image' => $image]);
|
2019-06-05 11:36:27 +03:00
|
|
|
|
}
|
2019-10-18 19:11:34 +03:00
|
|
|
|
|
|
|
|
|
if ($route) {
|
|
|
|
|
return $route . '?v=' . $cacheBusterValue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-11 16:03:47 +03:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-09-04 01:58:44 +03:00
|
|
|
|
|
2016-06-21 22:21:46 +03:00
|
|
|
|
/**
|
|
|
|
|
* Increases the cache buster key
|
|
|
|
|
*/
|
|
|
|
|
private function increaseCacheBuster() {
|
|
|
|
|
$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
|
|
|
|
|
$this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
|
2018-03-26 13:28:25 +03:00
|
|
|
|
$this->cacheFactory->createDistributed('theming-')->clear();
|
2018-03-28 13:24:51 +03:00
|
|
|
|
$this->cacheFactory->createDistributed('imagePath')->clear();
|
2016-06-09 22:46:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-06-21 22:21:46 +03:00
|
|
|
|
* Update setting in the database
|
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
|
|
|
|
*/
|
|
|
|
|
public function set($setting, $value) {
|
|
|
|
|
$this->config->setAppValue('theming', $setting, $value);
|
2016-06-21 22:21:46 +03:00
|
|
|
|
$this->increaseCacheBuster();
|
2016-06-09 22:46:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-06-21 22:21:46 +03:00
|
|
|
|
* Revert settings to the default value
|
2016-06-09 22:46:30 +03:00
|
|
|
|
*
|
|
|
|
|
* @param string $setting setting which should be reverted
|
|
|
|
|
* @return string default value
|
|
|
|
|
*/
|
|
|
|
|
public function undo($setting) {
|
2016-06-21 22:21:46 +03:00
|
|
|
|
$this->config->deleteAppValue('theming', $setting);
|
|
|
|
|
$this->increaseCacheBuster();
|
|
|
|
|
|
2020-09-23 18:48:48 +03:00
|
|
|
|
$returnValue = '';
|
2016-06-21 22:21:46 +03:00
|
|
|
|
switch ($setting) {
|
|
|
|
|
case 'name':
|
|
|
|
|
$returnValue = $this->getEntity();
|
|
|
|
|
break;
|
|
|
|
|
case 'url':
|
|
|
|
|
$returnValue = $this->getBaseUrl();
|
|
|
|
|
break;
|
|
|
|
|
case 'slogan':
|
|
|
|
|
$returnValue = $this->getSlogan();
|
|
|
|
|
break;
|
|
|
|
|
case 'color':
|
2017-03-28 02:37:47 +03:00
|
|
|
|
$returnValue = $this->getColorPrimary();
|
2016-06-21 22:21:46 +03:00
|
|
|
|
break;
|
2020-09-23 18:48:48 +03:00
|
|
|
|
case 'logo':
|
|
|
|
|
case 'logoheader':
|
|
|
|
|
case 'background':
|
|
|
|
|
case 'favicon':
|
|
|
|
|
$this->imageManager->delete($setting);
|
2016-06-21 22:21:46 +03:00
|
|
|
|
break;
|
2016-06-09 22:46:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $returnValue;
|
|
|
|
|
}
|
2017-12-08 14:16:05 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Color of text in the header and primary buttons
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getTextColorPrimary() {
|
|
|
|
|
return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff';
|
|
|
|
|
}
|
2016-06-09 22:46:30 +03:00
|
|
|
|
}
|