2020-04-09 09:55:45 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\SideMenu\Controller;
|
|
|
|
|
2020-08-13 11:21:59 +02:00
|
|
|
use OC;
|
2020-09-20 20:53:03 +02:00
|
|
|
use OC\User\User;
|
2020-09-22 14:35:09 +02:00
|
|
|
use OCA\SideMenu\AppInfo\Application;
|
|
|
|
use OCA\SideMenu\Service\ConfigProxy;
|
2020-04-09 09:55:45 +02:00
|
|
|
use OCP\AppFramework\Controller;
|
|
|
|
use OCP\AppFramework\Http\Response;
|
2020-08-13 11:21:59 +02:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
2020-04-09 09:55:45 +02:00
|
|
|
use OCP\IRequest;
|
2020-08-12 16:16:50 +02:00
|
|
|
use OCP\IUserSession;
|
2022-01-09 16:43:12 +01:00
|
|
|
use OCA\Theming\ThemingDefaults;
|
|
|
|
use OCA\SideMenu\Service\Color;
|
2020-04-09 09:55:45 +02:00
|
|
|
|
|
|
|
class CssController extends Controller
|
|
|
|
{
|
2020-05-11 22:51:27 +02:00
|
|
|
/**
|
2020-09-22 14:24:53 +02:00
|
|
|
* @var ConfigProxy
|
2020-05-11 22:51:27 +02:00
|
|
|
*/
|
2020-04-09 09:55:45 +02:00
|
|
|
protected $config;
|
|
|
|
|
2020-09-20 20:53:03 +02:00
|
|
|
/**
|
|
|
|
* @var User
|
|
|
|
*/
|
|
|
|
protected $user;
|
|
|
|
|
2022-01-09 16:43:12 +01:00
|
|
|
/**
|
|
|
|
* @var ThemingDefaults
|
|
|
|
*/
|
|
|
|
protected $theming;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Color
|
|
|
|
*/
|
|
|
|
protected $color;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
string $appName,
|
|
|
|
IRequest $request,
|
|
|
|
ConfigProxy $config,
|
|
|
|
ThemingDefaults $theming,
|
|
|
|
Color $color
|
|
|
|
)
|
2020-04-09 09:55:45 +02:00
|
|
|
{
|
|
|
|
parent::__construct($appName, $request);
|
2020-04-16 12:18:10 +02:00
|
|
|
|
2020-09-20 20:53:03 +02:00
|
|
|
$this->user = OC::$server[IUserSession::class]->getUser();
|
2020-04-09 09:55:45 +02:00
|
|
|
$this->config = $config;
|
2022-01-09 16:43:12 +01:00
|
|
|
$this->theming = $theming;
|
|
|
|
$this->color = $color;
|
2020-04-09 09:55:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
* @NoCSRFRequired
|
|
|
|
* @PublicPage
|
|
|
|
*
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function stylesheet()
|
2020-09-20 20:53:03 +02:00
|
|
|
{
|
2020-09-21 11:28:55 +02:00
|
|
|
$response = new TemplateResponse(Application::APP_ID, 'css/stylesheet', $this->getConfig(), 'blank');
|
2020-09-20 20:53:03 +02:00
|
|
|
$response->addHeader('Content-Type', 'text/css');
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getConfig(): array
|
2020-04-09 09:55:45 +02:00
|
|
|
{
|
2020-09-24 14:26:25 +02:00
|
|
|
$isForced = $this->config->getAppValueBool('force', '0');
|
2020-09-22 14:24:53 +02:00
|
|
|
$topMenuApps = $this->config->getAppValueArray('top-menu-apps', '[]');
|
2022-01-12 14:11:38 +01:00
|
|
|
$topSideMenuApps = $this->config->getAppValueArray('top-side-menu-apps', '[]');
|
2020-08-12 16:16:50 +02:00
|
|
|
|
2021-02-27 14:21:55 +01:00
|
|
|
$isAccessibilityAppEnabled = $this->config->getAppValueBool('enabled', '0', 'accessibility');
|
|
|
|
$isBreezeDarkAppEnabled = $this->config->getAppValueBool('enabled', '0', 'breezedark');
|
|
|
|
$isBreezeDarkGlobalEnabled = $this->config->getAppValueBool('theme_enabled', '0', 'breezedark');
|
|
|
|
|
2020-09-20 20:53:03 +02:00
|
|
|
if ($this->user) {
|
2020-09-22 14:24:53 +02:00
|
|
|
$userTopMenuApps = $this->config->getUserValueArray($this->user, 'top-menu-apps', '[]');
|
2022-01-12 14:11:38 +01:00
|
|
|
$userTopSideMenuApps = $this->config->getUserValueArray($this->user, 'top-side-menu-apps', '[]');
|
2020-08-12 16:16:50 +02:00
|
|
|
|
2020-09-24 14:26:25 +02:00
|
|
|
if (!empty($userTopMenuApps) && !$isForced) {
|
2020-08-12 16:16:50 +02:00
|
|
|
$topMenuApps = $userTopMenuApps;
|
|
|
|
}
|
2021-02-27 14:21:55 +01:00
|
|
|
|
2022-01-12 14:11:38 +01:00
|
|
|
if (!empty($userTopSideMenuApps) && !$isForced) {
|
|
|
|
$topSideMenuApps = $userTopSideMenuApps;
|
|
|
|
}
|
|
|
|
|
2021-02-27 14:21:55 +01:00
|
|
|
$isDarkThemeUserEnabled = $this->config->getUserValue($this->user, 'theme', '', 'accessibility') === 'dark';
|
|
|
|
$isBreezeDarkUserEnabled = $this->config->getUserValue($this->user, 'theme_enabled', '', 'breezedark');
|
|
|
|
|
|
|
|
$isBreezeDarkUserEnabled = $isBreezeDarkUserEnabled === '1' || ($isBreezeDarkGlobalEnabled && $isBreezeDarkUserEnabled === '');
|
|
|
|
} else {
|
|
|
|
$isDarkThemeUserEnabled = false;
|
|
|
|
$isBreezeDarkUserEnabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$isDarkMode = ($isAccessibilityAppEnabled && $isDarkThemeUserEnabled) || ($isBreezeDarkAppEnabled && $isBreezeDarkUserEnabled);
|
|
|
|
|
2022-01-09 16:43:12 +01:00
|
|
|
$primaryColor = $this->theming->getColorPrimary();
|
|
|
|
$lightenPrimaryColor = $this->color->adjustBrightness($primaryColor, 0.2);
|
|
|
|
$darkenPrimaryColor = $this->color->adjustBrightness($primaryColor, -0.2);
|
|
|
|
$darkenPrimaryColor2 = $this->color->adjustBrightness($primaryColor, -0.3);
|
|
|
|
$textColor = $this->theming->getTextColorPrimary();
|
|
|
|
|
2021-02-27 14:21:55 +01:00
|
|
|
if ($isDarkMode) {
|
2022-01-09 16:43:12 +01:00
|
|
|
$backgroundColor = $this->config->getAppValue('dark-mode-background-color', $darkenPrimaryColor);
|
|
|
|
$backgroundColorTo = $this->config->getAppValue('dark-mode-background-color-to', $darkenPrimaryColor);
|
|
|
|
$currentAppBackgroundColor = $this->config->getAppValue('dark-mode-current-app-background-color', $darkenPrimaryColor2);
|
|
|
|
$loaderColor = $this->config->getAppValue('dark-mode-loader-color', $lightenPrimaryColor);
|
|
|
|
$textColor = $this->config->getAppValue('dark-mode-text-color', $textColor);
|
2021-02-27 14:21:55 +01:00
|
|
|
$iconInvertFilter = abs($this->config->getAppValueInt('dark-mode-icon-invert-filter', '0')).'%';
|
|
|
|
$iconOpacity = abs($this->config->getAppValueInt('dark-mode-icon-opacity', '100') / 100);
|
|
|
|
$opener = $this->config->getAppValue('dark-mode-opener', 'side-menu-opener');
|
2021-07-03 20:23:39 +02:00
|
|
|
|
|
|
|
$backgroundOpacity = dechex($this->config->getAppValueInt('dark-mode-background-color-opacity', '100') * 255 / 100);
|
2021-02-27 14:21:55 +01:00
|
|
|
} else {
|
2022-01-09 16:43:12 +01:00
|
|
|
$backgroundColor = $this->config->getAppValue('background-color', $darkenPrimaryColor);
|
|
|
|
$backgroundColorTo = $this->config->getAppValue('background-color-to', $darkenPrimaryColor);
|
|
|
|
$currentAppBackgroundColor = $this->config->getAppValue('current-app-background-color', $darkenPrimaryColor2);
|
|
|
|
$loaderColor = $this->config->getAppValue('loader-color', $lightenPrimaryColor);
|
|
|
|
$textColor = $this->config->getAppValue('text-color', $textColor);
|
2021-02-27 14:21:55 +01:00
|
|
|
$iconInvertFilter = abs($this->config->getAppValueInt('icon-invert-filter', '0')).'%';
|
|
|
|
$iconOpacity = abs($this->config->getAppValueInt('icon-opacity', '100') / 100);
|
|
|
|
$opener = $this->config->getAppValue('opener', 'side-menu-opener');
|
2021-07-03 20:23:39 +02:00
|
|
|
|
|
|
|
$backgroundOpacity = dechex($this->config->getAppValueInt('background-color-opacity', '100') * 255 / 100);
|
2020-08-12 16:16:50 +02:00
|
|
|
}
|
|
|
|
|
2021-07-03 20:23:39 +02:00
|
|
|
$backgroundColor .= $backgroundOpacity;
|
|
|
|
$backgroundColorTo .= $backgroundOpacity;
|
|
|
|
|
2020-09-20 20:53:03 +02:00
|
|
|
return [
|
2020-04-15 12:17:17 +02:00
|
|
|
'vars' => [
|
2020-04-25 13:05:01 +02:00
|
|
|
'background-color' => $backgroundColor,
|
|
|
|
'background-color-to' => $backgroundColorTo,
|
2021-02-27 14:21:55 +01:00
|
|
|
'current-app-background-color' => $currentAppBackgroundColor,
|
|
|
|
'loader-color' => $loaderColor,
|
|
|
|
'text-color' => $textColor,
|
|
|
|
'opener' => $opener,
|
|
|
|
'icon-invert-filter' => $iconInvertFilter,
|
|
|
|
'icon-opacity' => $iconOpacity,
|
2020-04-15 12:17:17 +02:00
|
|
|
],
|
2020-09-23 12:51:55 +02:00
|
|
|
'display-logo' => $this->config->getAppValueBool('display-logo', '1'),
|
|
|
|
'opener-only' => $this->config->getAppValueBool('opener-only', '0'),
|
|
|
|
'external-sites-in-top-menu' => $this->config->getAppValueBool('external-sites-in-top-menu', '0'),
|
2020-09-22 14:24:53 +02:00
|
|
|
'size-icon' => $this->config->getAppValue('size-icon', 'normal'),
|
|
|
|
'size-text' => $this->config->getAppValue('size-text', 'normal'),
|
|
|
|
'always-displayed' => $this->config->getAppValueBool('always-displayed', '0'),
|
|
|
|
'big-menu' => $this->config->getAppValueBool('big-menu', '0'),
|
2020-08-12 16:16:50 +02:00
|
|
|
'top-menu-apps' => $topMenuApps,
|
2022-01-12 14:11:38 +01:00
|
|
|
'top-side-menu-apps' => $topSideMenuApps,
|
2020-04-09 09:55:45 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|