aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorSimon L <szaimen@e.mail.de>2022-11-15 16:55:37 +0100
committerSimon L <szaimen@e.mail.de>2022-11-18 15:03:41 +0100
commit04b236e32061ddc0b236728363cdaeb189fc3c6a (patch)
treee54d551d426a2aabf87fc7b193768d1185568190 /apps
parentf021172eab79b6e1adaa1950009dd6446f1ddb64 (diff)
downloadnextcloud-server-04b236e32061ddc0b236728363cdaeb189fc3c6a.tar.gz
nextcloud-server-04b236e32061ddc0b236728363cdaeb189fc3c6a.zip
generate user themed icons
Signed-off-by: Simon L <szaimen@e.mail.de> Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com> Co-Authored-By: Côme Chilliet <91878298+come-nc@users.noreply.github.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/theming/lib/Controller/IconController.php7
-rw-r--r--apps/theming/lib/Service/JSDataService.php2
-rw-r--r--apps/theming/lib/Service/ThemeInjectionService.php17
-rw-r--r--apps/theming/lib/ThemingDefaults.php2
-rw-r--r--apps/theming/lib/Util.php17
-rw-r--r--apps/theming/tests/ThemingDefaultsTest.php8
6 files changed, 36 insertions, 17 deletions
diff --git a/apps/theming/lib/Controller/IconController.php b/apps/theming/lib/Controller/IconController.php
index 173b5210394..08ee71ac660 100644
--- a/apps/theming/lib/Controller/IconController.php
+++ b/apps/theming/lib/Controller/IconController.php
@@ -86,16 +86,17 @@ class IconController extends Controller {
* @throws \Exception
*/
public function getThemedIcon(string $app, string $image): Response {
+ $color = $this->themingDefaults->getColorPrimary();
try {
- $iconFile = $this->imageManager->getCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image));
+ $iconFileName = $this->imageManager->getCachedImage('icon-' . $app . '-' . $color . str_replace('/', '_', $image));
} catch (NotFoundException $exception) {
$icon = $this->iconBuilder->colorSvg($app, $image);
if ($icon === false || $icon === '') {
return new NotFoundResponse();
}
- $iconFile = $this->imageManager->setCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image), $icon);
+ $iconFileName = $this->imageManager->setCachedImage('icon-' . $app . '-' . $color . str_replace('/', '_', $image), $icon);
}
- $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
+ $response = new FileDisplayResponse($iconFileName, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
$response->cacheFor(86400, false, true);
return $response;
}
diff --git a/apps/theming/lib/Service/JSDataService.php b/apps/theming/lib/Service/JSDataService.php
index 26cda8c0012..90acd74b868 100644
--- a/apps/theming/lib/Service/JSDataService.php
+++ b/apps/theming/lib/Service/JSDataService.php
@@ -59,7 +59,7 @@ class JSDataService implements \JsonSerializable {
'imprintUrl' => $this->themingDefaults->getImprintUrl(),
'privacyUrl' => $this->themingDefaults->getPrivacyUrl(),
'inverted' => $this->util->invertTextColor($this->themingDefaults->getColorPrimary()),
- 'cacheBuster' => $this->appConfig->getAppValue(Application::APP_ID, 'cachebuster', '0'),
+ 'cacheBuster' => $this->util->getCacheBuster(),
'enabledThemes' => $this->themesService->getEnabledThemes(),
];
}
diff --git a/apps/theming/lib/Service/ThemeInjectionService.php b/apps/theming/lib/Service/ThemeInjectionService.php
index 27b65457e7f..8e55f614146 100644
--- a/apps/theming/lib/Service/ThemeInjectionService.php
+++ b/apps/theming/lib/Service/ThemeInjectionService.php
@@ -24,27 +24,30 @@ namespace OCA\Theming\Service;
use OCA\Theming\AppInfo\Application;
use OCA\Theming\Themes\DefaultTheme;
+use OCA\Theming\Util;
use OCP\IConfig;
use OCP\IURLGenerator;
use OCP\IUserSession;
-use OCP\Util;
class ThemeInjectionService {
private IURLGenerator $urlGenerator;
private ThemesService $themesService;
private DefaultTheme $defaultTheme;
+ private Util $util;
private IConfig $config;
private ?string $userId;
public function __construct(IURLGenerator $urlGenerator,
ThemesService $themesService,
DefaultTheme $defaultTheme,
+ Util $util,
IConfig $config,
IUserSession $userSession) {
$this->urlGenerator = $urlGenerator;
$this->themesService = $themesService;
$this->defaultTheme = $defaultTheme;
+ $this->util = $util;
$this->config = $config;
if ($userSession->getUser() !== null) {
$this->userId = $userSession->getUser()->getUID();
@@ -87,20 +90,12 @@ class ThemeInjectionService {
* @param string $media media query to use in the <link> element
*/
private function addThemeHeader(string $themeId, bool $plain = true, string $media = null) {
- $cacheBuster = $this->config->getAppValue('theming', 'cachebuster', '0');
- if ($this->userId !== null) {
- // need to bust the cache for the CSS file when the user background changed as its
- // URL is served in those files
- $userCacheBuster = $this->config->getUserValue($this->userId, Application::APP_ID, 'userCacheBuster', '0');
- $cacheBuster .= $this->userId . '_' . $userCacheBuster;
- }
-
$linkToCSS = $this->urlGenerator->linkToRoute('theming.Theming.getThemeStylesheet', [
'themeId' => $themeId,
'plain' => $plain,
- 'v' => substr(sha1($cacheBuster), 0, 8),
+ 'v' => $this->util->getCacheBuster(),
]);
- Util::addHeader('link', [
+ \OCP\Util::addHeader('link', [
'rel' => 'stylesheet',
'media' => $media,
'href' => $linkToCSS,
diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php
index f32faa5a8ef..16ea7a14c0f 100644
--- a/apps/theming/lib/ThemingDefaults.php
+++ b/apps/theming/lib/ThemingDefaults.php
@@ -420,7 +420,7 @@ class ThemingDefaults extends \OC_Defaults {
}
if ($route) {
- return $route . '?v=' . $cacheBusterValue;
+ return $route . '?v=' . $this->util->getCacheBuster();
}
return false;
diff --git a/apps/theming/lib/Util.php b/apps/theming/lib/Util.php
index 5ae2910f73d..a85dacd3de2 100644
--- a/apps/theming/lib/Util.php
+++ b/apps/theming/lib/Util.php
@@ -34,6 +34,7 @@ use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\IConfig;
+use OCP\IUserSession;
use Mexitek\PHPColors\Color;
class Util {
@@ -266,4 +267,20 @@ class Util {
return $this->imageManager->hasImage('logo')
|| $this->imageManager->hasImage('logoheader');
}
+
+ public function getCacheBuster(): string {
+ $userSession = \OC::$server->get(IUserSession::class);
+ $userId = '';
+ $user = $userSession->getUser();
+ if (!is_null($user)) {
+ $userId = $user->getUID();
+ }
+ $userCacheBuster = '';
+ if ($userId) {
+ $userCacheBusterValue = (int)$this->config->getUserValue($userId, 'theming', 'userCacheBuster', '0');
+ $userCacheBuster = $userId . '_' . $userCacheBusterValue;
+ }
+ $systemCacheBuster = $this->config->getAppValue('theming', 'cachebuster', '0');
+ return substr(sha1($userCacheBuster . $systemCacheBuster), 0, 8);
+ }
}
diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php
index e3e6f2d1df7..445ffd2b0a7 100644
--- a/apps/theming/tests/ThemingDefaultsTest.php
+++ b/apps/theming/tests/ThemingDefaultsTest.php
@@ -868,7 +868,7 @@ class ThemingDefaultsTest extends TestCase {
}
/** @dataProvider dataReplaceImagePath */
- public function testReplaceImagePath($app, $image, $result = 'themingRoute?v=0') {
+ public function testReplaceImagePath($app, $image, $result = 'themingRoute?v=1234abcd') {
$this->cache->expects($this->any())
->method('get')
->with('shouldReplaceIcons')
@@ -882,6 +882,12 @@ class ThemingDefaultsTest extends TestCase {
->expects($this->any())
->method('linkToRoute')
->willReturn('themingRoute');
+ if ($result) {
+ $this->util
+ ->expects($this->once())
+ ->method('getCacheBuster')
+ ->willReturn('1234abcd');
+ }
$this->assertEquals($result, $this->template->replaceImagePath($app, $image));
}
}