Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/theming/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'OCA\\Theming\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
'OCA\\Theming\\Capabilities' => $baseDir . '/../lib/Capabilities.php',
'OCA\\Theming\\Command\\UpdateConfig' => $baseDir . '/../lib/Command/UpdateConfig.php',
'OCA\\Theming\\ConfigLexicon' => $baseDir . '/../lib/ConfigLexicon.php',
'OCA\\Theming\\Controller\\IconController' => $baseDir . '/../lib/Controller/IconController.php',
'OCA\\Theming\\Controller\\ThemingController' => $baseDir . '/../lib/Controller/ThemingController.php',
'OCA\\Theming\\Controller\\UserThemeController' => $baseDir . '/../lib/Controller/UserThemeController.php',
Expand Down
1 change: 1 addition & 0 deletions apps/theming/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ComposerStaticInitTheming
'OCA\\Theming\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
'OCA\\Theming\\Capabilities' => __DIR__ . '/..' . '/../lib/Capabilities.php',
'OCA\\Theming\\Command\\UpdateConfig' => __DIR__ . '/..' . '/../lib/Command/UpdateConfig.php',
'OCA\\Theming\\ConfigLexicon' => __DIR__ . '/..' . '/../lib/ConfigLexicon.php',
'OCA\\Theming\\Controller\\IconController' => __DIR__ . '/..' . '/../lib/Controller/IconController.php',
'OCA\\Theming\\Controller\\ThemingController' => __DIR__ . '/..' . '/../lib/Controller/ThemingController.php',
'OCA\\Theming\\Controller\\UserThemeController' => __DIR__ . '/..' . '/../lib/Controller/UserThemeController.php',
Expand Down
116 changes: 116 additions & 0 deletions apps/theming/lib/ConfigLexicon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Theming;

use OCP\Config\Lexicon\Entry;
use OCP\Config\Lexicon\ILexicon;
use OCP\Config\Lexicon\Strictness;
use OCP\Config\ValueType;

/**
* Config Lexicon for theming.
*
* Please Add & Manage your Config Keys in that file and keep the Lexicon up to date!
*
* {@see ILexicon}
*/
class ConfigLexicon implements ILexicon {
/** The cache buster index */
public const CACHE_BUSTER = 'cachebuster';
public const USER_THEMING_DISABLED = 'disable-user-theming';

/** Name of the software running on this instance (usually "Nextcloud") */
public const PRODUCT_NAME = 'productName';
/** Short name of this instance */
public const INSTANCE_NAME = 'name';
/** Slogan of this instance */
public const INSTANCE_SLOGAN = 'slogan';
/** Imprint URL of this instance */
public const INSTANCE_IMPRINT_URL = 'imprintUrl';
/** Privacy URL of this instance */
public const INSTANCE_PRIVACY_URL = 'privacyUrl';

// legacy theming
/** Base URL of this instance */
public const BASE_URL = 'url';
/** Base URL for documentation */
public const DOC_BASE_URL = 'docBaseUrl';

public function getStrictness(): Strictness {
return Strictness::NOTICE;
}

public function getAppConfigs(): array {
return [
// internals
new Entry(
self::CACHE_BUSTER,
ValueType::INT,
defaultRaw: 0,
definition: 'The current cache buster key for theming assets.',
),
new Entry(
self::USER_THEMING_DISABLED,
ValueType::BOOL,
defaultRaw: false,
definition: 'Whether user theming is disabled.',
),

// instance theming
new Entry(
self::PRODUCT_NAME,
ValueType::STRING,
defaultRaw: 'Nextcloud',
definition: 'The name of the software running on this instance (usually "Nextcloud").',
),
new Entry(
self::INSTANCE_NAME,
ValueType::STRING,
defaultRaw: '',
definition: 'Short name of this instance.',
),
new Entry(
self::INSTANCE_SLOGAN,
ValueType::STRING,
defaultRaw: '',
definition: 'Slogan of this instance.',
),
new Entry(
self::INSTANCE_IMPRINT_URL,
ValueType::STRING,
defaultRaw: '',
definition: 'Imprint URL of this instance.',
),
new Entry(
self::INSTANCE_PRIVACY_URL,
ValueType::STRING,
defaultRaw: '',
definition: 'Privacy URL of this instance.',
),

// legacy theming
new Entry(
self::BASE_URL,
ValueType::STRING,
defaultRaw: '',
definition: 'Base URL of this instance.',
),
new Entry(
self::DOC_BASE_URL,
ValueType::STRING,
defaultRaw: '',
definition: 'Base URL for documentation.',
),
];
}

public function getUserConfigs(): array {
return [];
}
}
91 changes: 50 additions & 41 deletions apps/theming/lib/ThemingDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,48 +69,48 @@ public function __construct(
}

public function getName() {
return strip_tags($this->config->getAppValue('theming', 'name', $this->name));
return strip_tags($this->appConfig->getValueString('theming', ConfigLexicon::INSTANCE_NAME, $this->name));
}

public function getHTMLName() {
return $this->config->getAppValue('theming', 'name', $this->name);
return $this->appConfig->getValueString('theming', ConfigLexicon::INSTANCE_NAME, $this->name);
}

public function getTitle() {
return strip_tags($this->config->getAppValue('theming', 'name', $this->title));
return strip_tags($this->appConfig->getValueString('theming', ConfigLexicon::INSTANCE_NAME, $this->title));
}

public function getEntity() {
return strip_tags($this->config->getAppValue('theming', 'name', $this->entity));
return strip_tags($this->appConfig->getValueString('theming', ConfigLexicon::INSTANCE_NAME, $this->entity));
}

public function getProductName() {
return strip_tags($this->config->getAppValue('theming', 'productName', $this->productName));
return strip_tags($this->appConfig->getValueString('theming', ConfigLexicon::PRODUCT_NAME, $this->productName));
}

public function getBaseUrl() {
return $this->config->getAppValue('theming', 'url', $this->url);
return $this->appConfig->getValueString('theming', ConfigLexicon::BASE_URL, $this->url);
}

/**
* We pass a string and sanitizeHTML will return a string too in that case
* @psalm-suppress InvalidReturnStatement
* @psalm-suppress InvalidReturnType
*/
public function getSlogan(?string $lang = null) {
return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan($lang)));
public function getSlogan(?string $lang = null): string {
return \OCP\Util::sanitizeHTML($this->appConfig->getValueString('theming', ConfigLexicon::INSTANCE_SLOGAN, parent::getSlogan($lang)));
}

public function getImprintUrl() {
return (string)$this->config->getAppValue('theming', 'imprintUrl', '');
public function getImprintUrl(): string {
return $this->appConfig->getValueString('theming', ConfigLexicon::INSTANCE_IMPRINT_URL, '');
}

public function getPrivacyUrl() {
return (string)$this->config->getAppValue('theming', 'privacyUrl', '');
public function getPrivacyUrl(): string {
return $this->appConfig->getValueString('theming', ConfigLexicon::INSTANCE_PRIVACY_URL, '');
}

public function getDocBaseUrl() {
return (string)$this->config->getAppValue('theming', 'docBaseUrl', $this->docBaseUrl);
public function getDocBaseUrl(): string {
return $this->appConfig->getValueString('theming', ConfigLexicon::DOC_BASE_URL, $this->docBaseUrl);
}

public function getShortFooter() {
Expand All @@ -132,11 +132,11 @@ public function getShortFooter() {
$links = [
[
'text' => $this->l->t('Legal notice'),
'url' => (string)$this->getImprintUrl()
'url' => $this->getImprintUrl()
],
[
'text' => $this->l->t('Privacy policy'),
'url' => (string)$this->getPrivacyUrl()
'url' => $this->getPrivacyUrl()
],
];

Expand Down Expand Up @@ -252,14 +252,14 @@ public function getDefaultColorBackground(): string {
* @return string
*/
public function getLogo($useSvg = true): string {
$logo = $this->config->getAppValue('theming', 'logoMime', '');
$logo = $this->appConfig->getValueString('theming', 'logoMime', '');

// 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) {
if ($useSvg === true && $logo !== '') {
$logoExists = true;
} else {
try {
Expand All @@ -270,8 +270,7 @@ public function getLogo($useSvg = true): string {
}
}

$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');

$cacheBusterCounter = (string)$this->appConfig->getValueInt('theming', ConfigLexicon::CACHE_BUSTER);
if (!$logo || !$logoExists) {
if ($useSvg) {
$logo = $this->urlGenerator->imagePath('core', 'logo/logo.svg');
Expand All @@ -298,47 +297,47 @@ public function getBackground(bool $darkVariant = false): string {
* @return string
*/
public function getiTunesAppId() {
return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId);
return $this->appConfig->getValueString('theming', 'iTunesAppId', $this->iTunesAppId);
}

/**
* @return string
*/
public function getiOSClientUrl() {
return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl);
return $this->appConfig->getValueString('theming', 'iOSClientUrl', $this->iOSClientUrl);
}

/**
* @return string
*/
public function getAndroidClientUrl() {
return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl);
return $this->appConfig->getValueString('theming', 'AndroidClientUrl', $this->AndroidClientUrl);
}

/**
* @return string
*/
public function getFDroidClientUrl() {
return $this->config->getAppValue('theming', 'FDroidClientUrl', $this->FDroidClientUrl);
return $this->appConfig->getValueString('theming', 'FDroidClientUrl', $this->FDroidClientUrl);
}

/**
* @return array scss variables to overwrite
* @deprecated since Nextcloud 22 - https://github.com/nextcloud/server/issues/9940
*/
public function getScssVariables() {
$cacheBuster = $this->config->getAppValue('theming', 'cachebuster', '0');
$cache = $this->cacheFactory->createDistributed('theming-' . $cacheBuster . '-' . $this->urlGenerator->getBaseUrl());
$cacheBuster = $this->appConfig->getValueInt('theming', ConfigLexicon::CACHE_BUSTER);
$cache = $this->cacheFactory->createDistributed('theming-' . (string)$cacheBuster . '-' . $this->urlGenerator->getBaseUrl());
if ($value = $cache->get('getScssVariables')) {
return $value;
}

$variables = [
'theming-cachebuster' => "'" . $cacheBuster . "'",
'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') . "'"
'theming-logo-mime' => "'" . $this->appConfig->getValueString('theming', 'logoMime') . "'",
'theming-background-mime' => "'" . $this->appConfig->getValueString('theming', 'backgroundMime') . "'",
'theming-logoheader-mime' => "'" . $this->appConfig->getValueString('theming', 'logoheaderMime') . "'",
'theming-favicon-mime' => "'" . $this->appConfig->getValueString('theming', 'faviconMime') . "'"
];

$variables['image-logo'] = "url('" . $this->imageManager->getImageUrl('logo') . "')";
Expand All @@ -353,7 +352,7 @@ public function getScssVariables() {
$variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary());
}

if ($this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor') {
if ($this->appConfig->getValueString('theming', 'backgroundMime', '') === 'backgroundColor') {
$variables['image-login-plain'] = 'true';
}

Expand All @@ -378,7 +377,6 @@ public function replaceImagePath($app, $image) {
if ($app === '' || $app === 'files_sharing') {
$app = 'core';
}
$cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');

$route = false;
if ($image === 'favicon.ico' && ($this->imageManager->shouldReplaceIcons() || $this->getCustomFavicon() !== null)) {
Expand Down Expand Up @@ -420,8 +418,8 @@ protected function getCustomFavicon(): ?ISimpleFile {
* Increases the cache buster key
*/
public function increaseCacheBuster(): void {
$cacheBusterKey = (int)$this->config->getAppValue('theming', 'cachebuster', '0');
$this->config->setAppValue('theming', 'cachebuster', (string)($cacheBusterKey + 1));
$cacheBusterKey = $this->appConfig->getValueInt('theming', ConfigLexicon::CACHE_BUSTER);
$this->appConfig->setValueInt('theming', ConfigLexicon::CACHE_BUSTER, $cacheBusterKey + 1);
$this->cacheFactory->createDistributed('theming-')->clear();
$this->cacheFactory->createDistributed('imagePath')->clear();
}
Expand All @@ -433,7 +431,18 @@ public function increaseCacheBuster(): void {
* @param string $value
*/
public function set($setting, $value): void {
$this->appConfig->setValueString('theming', $setting, $value);
switch ($value) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈 #56626

case ConfigLexicon::CACHE_BUSTER:
$this->appConfig->setValueInt('theming', ConfigLexicon::CACHE_BUSTER, (int)$value);
break;
case ConfigLexicon::USER_THEMING_DISABLED:
$value = $value === 'true' || $value === 'yes' || $value === '1';
$this->appConfig->setValueBool('theming', ConfigLexicon::USER_THEMING_DISABLED, $value);
break;
default:
$this->appConfig->setValueString('theming', $setting, $value);
break;
}
$this->increaseCacheBuster();
}

Expand All @@ -443,9 +452,9 @@ public function set($setting, $value): void {
public function undoAll(): void {
// Remember the current cachebuster value, as we do not want to reset this value
// Otherwise this can lead to caching issues as the value might be known to a browser already
$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
$this->config->deleteAppValues('theming');
$this->config->setAppValue('theming', 'cachebuster', $cacheBusterKey);
$cacheBusterKey = $this->appConfig->getValueInt('theming', ConfigLexicon::CACHE_BUSTER);
$this->appConfig->deleteApp('theming');
$this->appConfig->setValueInt('theming', ConfigLexicon::CACHE_BUSTER, $cacheBusterKey);
$this->increaseCacheBuster();
}

Expand All @@ -456,7 +465,7 @@ public function undoAll(): void {
* @return string default value
*/
public function undo($setting): string {
$this->config->deleteAppValue('theming', $setting);
$this->appConfig->deleteKey('theming', $setting);
$this->increaseCacheBuster();

$returnValue = '';
Expand Down Expand Up @@ -485,7 +494,7 @@ public function undo($setting): string {
case 'background':
case 'favicon':
$this->imageManager->delete($setting);
$this->config->deleteAppValue('theming', $setting . 'Mime');
$this->appConfig->deleteKey('theming', $setting . 'Mime');
break;
}

Expand Down Expand Up @@ -523,6 +532,6 @@ public function getDefaultTextColorPrimary() {
* Has the admin disabled user customization
*/
public function isUserThemingDisabled(): bool {
return $this->appConfig->getValueBool(Application::APP_ID, 'disable-user-theming');
return $this->appConfig->getValueBool(Application::APP_ID, ConfigLexicon::USER_THEMING_DISABLED, false);
}
}
Loading
Loading