aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2022-10-19 12:23:24 +0200
committerJohn Molakvoæ <skjnldsv@protonmail.com>2022-10-19 12:59:16 +0200
commitd89da9b898ae25d7aadde7cf22063a487e7a8ace (patch)
tree85f1ac03f25e55fec258749d67b35b6a2b97db83 /apps
parent746710ad5b55127826bb52d5c9923002ea443b0a (diff)
downloadnextcloud-server-d89da9b898ae25d7aadde7cf22063a487e7a8ace.tar.gz
nextcloud-server-d89da9b898ae25d7aadde7cf22063a487e7a8ace.zip
Simplify variable names
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/theming/lib/ImageManager.php4
-rw-r--r--apps/theming/lib/Themes/CommonThemeTrait.php90
-rw-r--r--apps/theming/lib/Themes/DefaultTheme.php70
3 files changed, 100 insertions, 64 deletions
diff --git a/apps/theming/lib/ImageManager.php b/apps/theming/lib/ImageManager.php
index 60b695f1c90..560a4c981fe 100644
--- a/apps/theming/lib/ImageManager.php
+++ b/apps/theming/lib/ImageManager.php
@@ -45,6 +45,7 @@ use OCP\ITempManager;
use OCP\IURLGenerator;
class ImageManager {
+ public const SupportedImageKeys = ['background', 'logo', 'logoheader', 'favicon'];
/** @var IConfig */
private $config;
@@ -53,7 +54,6 @@ class ImageManager {
/** @var IURLGenerator */
private $urlGenerator;
/** @var array */
- private $supportedImageKeys = ['background', 'logo', 'logoheader', 'favicon'];
/** @var ICacheFactory */
private $cacheFactory;
/** @var ILogger */
@@ -142,7 +142,7 @@ class ImageManager {
*/
public function getCustomImages(): array {
$images = [];
- foreach ($this->supportedImageKeys as $key) {
+ foreach ($this::SupportedImageKeys as $key) {
$images[$key] = [
'mime' => $this->config->getAppValue('theming', $key . 'Mime', ''),
'url' => $this->getImageUrl($key),
diff --git a/apps/theming/lib/Themes/CommonThemeTrait.php b/apps/theming/lib/Themes/CommonThemeTrait.php
index d88a6a319fb..8802933d24d 100644
--- a/apps/theming/lib/Themes/CommonThemeTrait.php
+++ b/apps/theming/lib/Themes/CommonThemeTrait.php
@@ -24,6 +24,9 @@ declare(strict_types=1);
*/
namespace OCA\Theming\Themes;
+use OCA\Theming\AppInfo\Application;
+use OCA\Theming\ImageManager;
+use OCA\Theming\Service\BackgroundService;
use OCA\Theming\Util;
trait CommonThemeTrait {
@@ -41,6 +44,15 @@ trait CommonThemeTrait {
// primary related colours
return [
+ // invert filter if primary is too bright
+ // to be used for legacy reasons only. Use inline
+ // svg with proper css variable instead or material
+ // design icons.
+ // ⚠️ Using 'no' as a value to make sure we specify an
+ // invalid one with no fallback. 'unset' could here fallback to some
+ // other theme with media queries
+ '--primary-invert-if-bright' => $this->util->invertTextColor($this->primaryColor) ? 'invert(100%)' : 'no',
+
'--color-primary' => $this->primaryColor,
'--color-primary-default' => $this->defaultPrimaryColor,
'--color-primary-text' => $this->util->invertTextColor($this->primaryColor) ? '#000000' : '#ffffff',
@@ -63,4 +75,82 @@ trait CommonThemeTrait {
'--gradient-primary-background' => 'linear-gradient(40deg, var(--color-primary) 0%, var(--color-primary-hover) 100%)',
];
}
+
+ /**
+ * Generate admin theming background-related variables
+ */
+ protected function generateGlobalBackgroundVariables(): array {
+ $backgroundDeleted = $this->config->getAppValue(Application::APP_ID, 'backgroundMime', '') === 'backgroundColor';
+ $hasCustomLogoHeader = $this->imageManager->hasImage('logo') || $this->imageManager->hasImage('logoheader');
+
+ $variables = [];
+
+ // If primary as background has been request or if we have a custom primary colour
+ // let's not define the background image
+ if ($backgroundDeleted && $this->themingDefaults->isUserThemingDisabled()) {
+ $variables['--image-background-plain'] = 'true';
+ $variables['--color-background-plain'] = $this->themingDefaults->getColorPrimary();
+ }
+
+ // Register image variables only if custom-defined
+ foreach (ImageManager::SupportedImageKeys as $image) {
+ if ($this->imageManager->hasImage($image)) {
+ $imageUrl = $this->imageManager->getImageUrl($image);
+ if ($image === 'background') {
+ // If background deleted is set, ignoring variable
+ if ($backgroundDeleted) {
+ continue;
+ }
+ $variables['--image-background-size'] = 'cover';
+ }
+ $variables["--image-$image"] = "url('" . $imageUrl . "')";
+ }
+ }
+
+ if ($hasCustomLogoHeader) {
+ $variables["--image-logoheader-custom"] = 'true';
+ }
+
+ return $variables;
+ }
+
+ /**
+ * Generate user theming background-related variables
+ */
+ protected function generateUserBackgroundVariables(): array {
+ $user = $this->userSession->getUser();
+ if ($user !== null
+ && !$this->themingDefaults->isUserThemingDisabled()
+ && $this->appManager->isEnabledForUser(Application::APP_ID)) {
+ $themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background', 'default');
+ $currentVersion = (int)$this->config->getUserValue($user->getUID(), Application::APP_ID, 'userCacheBuster', '0');
+
+ // The user uploaded a custom background
+ if ($themingBackground === 'custom') {
+ $cacheBuster = substr(sha1($user->getUID() . '_' . $currentVersion), 0, 8);
+ return [
+ '--image-background' => "url('" . $this->urlGenerator->linkToRouteAbsolute('theming.userTheme.getBackground') . "?v=$cacheBuster')",
+ // TODO: implement primary color from custom background --color-background-plain
+ ];
+ }
+
+ // The user picked a shipped background
+ if (isset(BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground])) {
+ return [
+ '--image-background' => "url('" . $this->urlGenerator->linkTo(Application::APP_ID, "/img/background/$themingBackground") . "')",
+ '--color-background-plain' => $this->themingDefaults->getColorPrimary(),
+ ];
+ }
+
+ // The user picked a static colour
+ if (substr($themingBackground, 0, 1) === '#') {
+ return [
+ '--image-background' => 'no',
+ '--color-background-plain' => $this->themingDefaults->getColorPrimary(),
+ ];
+ }
+ }
+
+ return [];
+ }
}
diff --git a/apps/theming/lib/Themes/DefaultTheme.php b/apps/theming/lib/Themes/DefaultTheme.php
index ec985abdb18..11d65de9a80 100644
--- a/apps/theming/lib/Themes/DefaultTheme.php
+++ b/apps/theming/lib/Themes/DefaultTheme.php
@@ -24,7 +24,6 @@ declare(strict_types=1);
*/
namespace OCA\Theming\Themes;
-use OCA\Theming\AppInfo\Application;
use OCA\Theming\ImageManager;
use OCA\Theming\ITheme;
use OCA\Theming\Service\BackgroundService;
@@ -35,7 +34,6 @@ use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserSession;
-use OCP\Server;
class DefaultTheme implements ITheme {
use CommonThemeTrait;
@@ -47,6 +45,7 @@ class DefaultTheme implements ITheme {
public ImageManager $imageManager;
public IConfig $config;
public IL10N $l;
+ public IAppManager $appManager;
public string $defaultPrimaryColor;
public string $primaryColor;
@@ -57,7 +56,8 @@ class DefaultTheme implements ITheme {
IURLGenerator $urlGenerator,
ImageManager $imageManager,
IConfig $config,
- IL10N $l) {
+ IL10N $l,
+ IAppManager $appManager) {
$this->util = $util;
$this->themingDefaults = $themingDefaults;
$this->userSession = $userSession;
@@ -65,6 +65,7 @@ class DefaultTheme implements ITheme {
$this->imageManager = $imageManager;
$this->config = $config;
$this->l = $l;
+ $this->appManager = $appManager;
$this->defaultPrimaryColor = $this->themingDefaults->getDefaultColorPrimary();
$this->primaryColor = $this->themingDefaults->getColorPrimary();
@@ -108,8 +109,6 @@ class DefaultTheme implements ITheme {
$colorBoxShadow = $this->util->darken($colorMainBackground, 70);
$colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow));
- $hasCustomLogoHeader = $this->imageManager->hasImage('logo') || $this->imageManager->hasImage('logoheader');
-
$variables = [
'--color-main-background' => $colorMainBackground,
'--color-main-background-rgb' => $colorMainBackgroundRGB,
@@ -188,71 +187,18 @@ class DefaultTheme implements ITheme {
// mobile. Keep in sync with core/js/js.js
'--breakpoint-mobile' => '1024px',
-
- // invert filter if primary is too bright
- // to be used for legacy reasons only. Use inline
- // svg with proper css variable instead or material
- // design icons.
- // ⚠️ Using 'no' as a value to make sure we specify an
- // invalid one with no fallback. 'unset' could here fallback to some
- // other theme with media queries
- '--primary-invert-if-bright' => $this->util->invertTextColor($this->primaryColor) ? 'invert(100%)' : 'no',
'--background-invert-if-dark' => 'no',
'--background-invert-if-bright' => 'invert(100%)',
// Default last fallback values
- '--image-main-background' => "url('" . $this->urlGenerator->imagePath('core', 'app-background.jpg') . "')",
- '--color-main-background-plain' => $this->defaultPrimaryColor,
+ '--image-background' => "url('" . $this->urlGenerator->imagePath('core', 'app-background.jpg') . "')",
+ '--color-background-plain' => $this->defaultPrimaryColor,
];
// Primary variables
$variables = array_merge($variables, $this->generatePrimaryVariables($colorMainBackground, $colorMainText));
-
- $backgroundDeleted = $this->config->getAppValue(Application::APP_ID, 'backgroundMime', '') === 'backgroundColor';
- // If primary as background has been request or if we have a custom primary colour
- // let's not define the background image
- if ($backgroundDeleted && $this->themingDefaults->isUserThemingDisabled()) {
- $variables['--image-background-plain'] = 'true';
- $variables['--color-main-background-plain'] = $this->themingDefaults->getColorPrimary();
- }
-
- // Register image variables only if custom-defined
- foreach (['logo', 'logoheader', 'favicon', 'background'] as $image) {
- if ($this->imageManager->hasImage($image)) {
- $imageUrl = $this->imageManager->getImageUrl($image);
- if ($image === 'background') {
- // If background deleted is set, ignoring variable
- if ($backgroundDeleted) {
- continue;
- }
- $variables['--image-background-size'] = 'cover';
- $variables['--image-main-background'] = "url('" . $imageUrl . "')";
- }
- $variables["--image-$image"] = "url('" . $imageUrl . "')";
- }
- }
-
- if ($hasCustomLogoHeader) {
- $variables["--image-logoheader-custom"] = 'true';
- }
-
- $appManager = Server::get(IAppManager::class);
- $user = $this->userSession->getUser();
- if (!$this->themingDefaults->isUserThemingDisabled() && $appManager->isEnabledForUser(Application::APP_ID) && $user !== null) {
- $themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background', 'default');
- $currentVersion = (int)$this->config->getUserValue($user->getUID(), Application::APP_ID, 'userCacheBuster', '0');
-
-
- if ($themingBackground === 'custom') {
- $cacheBuster = substr(sha1($user->getUID() . '_' . $currentVersion), 0, 8);
- $variables['--image-main-background'] = "url('" . $this->urlGenerator->linkToRouteAbsolute('theming.userTheme.getBackground') . "?v=$cacheBuster')";
- } elseif (isset(BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground])) {
- $variables['--image-main-background'] = "url('" . $this->urlGenerator->linkTo(Application::APP_ID, "/img/background/$themingBackground") . "')";
- } elseif (substr($themingBackground, 0, 1) === '#') {
- unset($variables['--image-main-background']);
- $variables['--color-main-background-plain'] = $this->themingDefaults->getColorPrimary();
- }
- }
+ $variables = array_merge($variables, $this->generateGlobalBackgroundVariables());
+ $variables = array_merge($variables, $this->generateUserBackgroundVariables());
return $variables;
}