Skip to content

Commit 6676b95

Browse files
committed
fix(theming): use IAppConfig for all ThemingDefaults
Fixes issues where values have the wrong type. Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 4b274a8 commit 6676b95

File tree

5 files changed

+321
-176
lines changed

5 files changed

+321
-176
lines changed

apps/theming/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'OCA\\Theming\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
1111
'OCA\\Theming\\Capabilities' => $baseDir . '/../lib/Capabilities.php',
1212
'OCA\\Theming\\Command\\UpdateConfig' => $baseDir . '/../lib/Command/UpdateConfig.php',
13+
'OCA\\Theming\\ConfigLexicon' => $baseDir . '/../lib/ConfigLexicon.php',
1314
'OCA\\Theming\\Controller\\IconController' => $baseDir . '/../lib/Controller/IconController.php',
1415
'OCA\\Theming\\Controller\\ThemingController' => $baseDir . '/../lib/Controller/ThemingController.php',
1516
'OCA\\Theming\\Controller\\UserThemeController' => $baseDir . '/../lib/Controller/UserThemeController.php',

apps/theming/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class ComposerStaticInitTheming
2525
'OCA\\Theming\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
2626
'OCA\\Theming\\Capabilities' => __DIR__ . '/..' . '/../lib/Capabilities.php',
2727
'OCA\\Theming\\Command\\UpdateConfig' => __DIR__ . '/..' . '/../lib/Command/UpdateConfig.php',
28+
'OCA\\Theming\\ConfigLexicon' => __DIR__ . '/..' . '/../lib/ConfigLexicon.php',
2829
'OCA\\Theming\\Controller\\IconController' => __DIR__ . '/..' . '/../lib/Controller/IconController.php',
2930
'OCA\\Theming\\Controller\\ThemingController' => __DIR__ . '/..' . '/../lib/Controller/ThemingController.php',
3031
'OCA\\Theming\\Controller\\UserThemeController' => __DIR__ . '/..' . '/../lib/Controller/UserThemeController.php',

apps/theming/lib/ConfigLexicon.php

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\Theming;
10+
11+
use OCP\Config\Lexicon\Entry;
12+
use OCP\Config\Lexicon\ILexicon;
13+
use OCP\Config\Lexicon\Strictness;
14+
use OCP\Config\ValueType;
15+
16+
/**
17+
* Config Lexicon for theming.
18+
*
19+
* Please Add & Manage your Config Keys in that file and keep the Lexicon up to date!
20+
*
21+
* {@see ILexicon}
22+
*/
23+
class ConfigLexicon implements ILexicon {
24+
/** The cache buster index */
25+
public const CACHE_BUSTER = 'cachebuster';
26+
public const USER_THEMING_DISABLED = 'disable-user-theming';
27+
28+
/** Name of the software running on this instance (usually "Nextcloud") */
29+
public const PRODUCT_NAME = 'productName';
30+
/** Short name of this instance */
31+
public const INSTANCE_NAME = 'name';
32+
/** Slogan of this instance */
33+
public const INSTANCE_SLOGAN = 'slogan';
34+
/** Imprint URL of this instance */
35+
public const INSTANCE_IMPRINT_URL = 'imprintUrl';
36+
/** Privacy URL of this instance */
37+
public const INSTANCE_PRIVACY_URL = 'privacyUrl';
38+
39+
// legacy theming
40+
/** Base URL of this instance */
41+
public const BASE_URL = 'url';
42+
/** Base URL for documentation */
43+
public const DOC_BASE_URL = 'docBaseUrl';
44+
45+
public function getStrictness(): Strictness {
46+
return Strictness::NOTICE;
47+
}
48+
49+
public function getAppConfigs(): array {
50+
return [
51+
// internals
52+
new Entry(
53+
self::CACHE_BUSTER,
54+
ValueType::INT,
55+
defaultRaw: 0,
56+
definition: 'The current cache buster key for theming assets.',
57+
),
58+
new Entry(
59+
self::USER_THEMING_DISABLED,
60+
ValueType::BOOL,
61+
defaultRaw: false,
62+
definition: 'Whether user theming is disabled.',
63+
),
64+
65+
// instance theming
66+
new Entry(
67+
self::PRODUCT_NAME,
68+
ValueType::STRING,
69+
defaultRaw: 'Nextcloud',
70+
definition: 'The name of the software running on this instance (usually "Nextcloud").',
71+
),
72+
new Entry(
73+
self::INSTANCE_NAME,
74+
ValueType::STRING,
75+
defaultRaw: '',
76+
definition: 'Short name of this instance.',
77+
),
78+
new Entry(
79+
self::INSTANCE_SLOGAN,
80+
ValueType::STRING,
81+
defaultRaw: '',
82+
definition: 'Slogan of this instance.',
83+
),
84+
new Entry(
85+
self::INSTANCE_IMPRINT_URL,
86+
ValueType::STRING,
87+
defaultRaw: '',
88+
definition: 'Imprint URL of this instance.',
89+
),
90+
new Entry(
91+
self::INSTANCE_PRIVACY_URL,
92+
ValueType::STRING,
93+
defaultRaw: '',
94+
definition: 'Privacy URL of this instance.',
95+
),
96+
97+
// legacy theming
98+
new Entry(
99+
self::BASE_URL,
100+
ValueType::STRING,
101+
defaultRaw: '',
102+
definition: 'Base URL of this instance.',
103+
),
104+
new Entry(
105+
self::DOC_BASE_URL,
106+
ValueType::STRING,
107+
defaultRaw: '',
108+
definition: 'Base URL for documentation.',
109+
),
110+
];
111+
}
112+
113+
public function getUserConfigs(): array {
114+
return [];
115+
}
116+
}

apps/theming/lib/ThemingDefaults.php

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,27 @@ public function __construct(
6969
}
7070

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

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

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

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

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

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

9595
/**
@@ -98,19 +98,19 @@ public function getBaseUrl() {
9898
* @psalm-suppress InvalidReturnType
9999
*/
100100
public function getSlogan(?string $lang = null) {
101-
return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan($lang)));
101+
return \OCP\Util::sanitizeHTML($this->appConfig->getValueString('theming', ConfigLexicon::INSTANCE_SLOGAN, parent::getSlogan($lang)));
102102
}
103103

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

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

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

116116
public function getShortFooter() {
@@ -252,7 +252,7 @@ public function getDefaultColorBackground(): string {
252252
* @return string
253253
*/
254254
public function getLogo($useSvg = true): string {
255-
$logo = $this->config->getAppValue('theming', 'logoMime', '');
255+
$logo = $this->appConfig->getValueString('theming', 'logoMime', '');
256256

257257
// short cut to avoid setting up the filesystem just to check if the logo is there
258258
//
@@ -270,18 +270,17 @@ public function getLogo($useSvg = true): string {
270270
}
271271
}
272272

273-
$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
274-
273+
$cacheBusterCounter = $this->appConfig->getValueInt('theming', ConfigLexicon::CACHE_BUSTER);
275274
if (!$logo || !$logoExists) {
276275
if ($useSvg) {
277276
$logo = $this->urlGenerator->imagePath('core', 'logo/logo.svg');
278277
} else {
279278
$logo = $this->urlGenerator->imagePath('core', 'logo/logo.png');
280279
}
281-
return $logo . '?v=' . $cacheBusterCounter;
280+
return $logo . '?v=' . (string)$cacheBusterCounter;
282281
}
283282

284-
return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo', 'useSvg' => $useSvg, 'v' => $cacheBusterCounter ]);
283+
return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo', 'useSvg' => $useSvg, 'v' => (string)$cacheBusterCounter ]);
285284
}
286285

287286
/**
@@ -298,47 +297,47 @@ public function getBackground(bool $darkVariant = false): string {
298297
* @return string
299298
*/
300299
public function getiTunesAppId() {
301-
return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId);
300+
return $this->appConfig->getValueString('theming', 'iTunesAppId', $this->iTunesAppId);
302301
}
303302

304303
/**
305304
* @return string
306305
*/
307306
public function getiOSClientUrl() {
308-
return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl);
307+
return $this->appConfig->getValueString('theming', 'iOSClientUrl', $this->iOSClientUrl);
309308
}
310309

311310
/**
312311
* @return string
313312
*/
314313
public function getAndroidClientUrl() {
315-
return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl);
314+
return $this->appConfig->getValueString('theming', 'AndroidClientUrl', $this->AndroidClientUrl);
316315
}
317316

318317
/**
319318
* @return string
320319
*/
321320
public function getFDroidClientUrl() {
322-
return $this->config->getAppValue('theming', 'FDroidClientUrl', $this->FDroidClientUrl);
321+
return $this->appConfig->getValueString('theming', 'FDroidClientUrl', $this->FDroidClientUrl);
323322
}
324323

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

336335
$variables = [
337336
'theming-cachebuster' => "'" . $cacheBuster . "'",
338-
'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'",
339-
'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'",
340-
'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'",
341-
'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'"
337+
'theming-logo-mime' => "'" . $this->appConfig->getValueString('theming', 'logoMime') . "'",
338+
'theming-background-mime' => "'" . $this->appConfig->getValueString('theming', 'backgroundMime') . "'",
339+
'theming-logoheader-mime' => "'" . $this->appConfig->getValueString('theming', 'logoheaderMime') . "'",
340+
'theming-favicon-mime' => "'" . $this->appConfig->getValueString('theming', 'faviconMime') . "'"
342341
];
343342

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

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

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

383381
$route = false;
384382
if ($image === 'favicon.ico' && ($this->imageManager->shouldReplaceIcons() || $this->getCustomFavicon() !== null)) {
@@ -420,8 +418,8 @@ protected function getCustomFavicon(): ?ISimpleFile {
420418
* Increases the cache buster key
421419
*/
422420
public function increaseCacheBuster(): void {
423-
$cacheBusterKey = (int)$this->config->getAppValue('theming', 'cachebuster', '0');
424-
$this->config->setAppValue('theming', 'cachebuster', (string)($cacheBusterKey + 1));
421+
$cacheBusterKey = $this->appConfig->getValueInt('theming', ConfigLexicon::CACHE_BUSTER);
422+
$this->appConfig->setValueInt('theming', ConfigLexicon::CACHE_BUSTER, $cacheBusterKey + 1);
425423
$this->cacheFactory->createDistributed('theming-')->clear();
426424
$this->cacheFactory->createDistributed('imagePath')->clear();
427425
}
@@ -433,7 +431,18 @@ public function increaseCacheBuster(): void {
433431
* @param string $value
434432
*/
435433
public function set($setting, $value): void {
436-
$this->appConfig->setValueString('theming', $setting, $value);
434+
switch ($value) {
435+
case ConfigLexicon::CACHE_BUSTER:
436+
$this->appConfig->setValueInt('theming', ConfigLexicon::CACHE_BUSTER, (int)$value);
437+
break;
438+
case ConfigLexicon::USER_THEMING_DISABLED:
439+
$value = $value === 'true' || $value === 'yes' || $value === '1';
440+
$this->appConfig->setValueBool('theming', ConfigLexicon::USER_THEMING_DISABLED, $value);
441+
break;
442+
default:
443+
$this->appConfig->setValueString('theming', $setting, $value);
444+
break;
445+
}
437446
$this->increaseCacheBuster();
438447
}
439448

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

@@ -456,7 +465,7 @@ public function undoAll(): void {
456465
* @return string default value
457466
*/
458467
public function undo($setting): string {
459-
$this->config->deleteAppValue('theming', $setting);
468+
$this->appConfig->deleteKey('theming', $setting);
460469
$this->increaseCacheBuster();
461470

462471
$returnValue = '';
@@ -485,7 +494,7 @@ public function undo($setting): string {
485494
case 'background':
486495
case 'favicon':
487496
$this->imageManager->delete($setting);
488-
$this->config->deleteAppValue('theming', $setting . 'Mime');
497+
$this->appConfig->deleteKey('theming', $setting . 'Mime');
489498
break;
490499
}
491500

@@ -523,6 +532,6 @@ public function getDefaultTextColorPrimary() {
523532
* Has the admin disabled user customization
524533
*/
525534
public function isUserThemingDisabled(): bool {
526-
return $this->appConfig->getValueBool(Application::APP_ID, 'disable-user-theming');
535+
return $this->appConfig->getValueBool(Application::APP_ID, ConfigLexicon::USER_THEMING_DISABLED, false);
527536
}
528537
}

0 commit comments

Comments
 (0)