From cedae7c6d74e11c8aaa59b09a38db04dbebc818d Mon Sep 17 00:00:00 2001 From: John Molakvoæ Date: Thu, 20 Oct 2022 13:18:06 +0200 Subject: Allow to remove the background and select a custom colour MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- apps/theming/lib/ImageManager.php | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'apps/theming/lib/ImageManager.php') diff --git a/apps/theming/lib/ImageManager.php b/apps/theming/lib/ImageManager.php index 88a733580fc..ce9c2525802 100644 --- a/apps/theming/lib/ImageManager.php +++ b/apps/theming/lib/ImageManager.php @@ -33,6 +33,8 @@ */ namespace OCA\Theming; +use OCA\Theming\AppInfo\Application; +use OCA\Theming\Service\BackgroundService; use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; @@ -45,7 +47,7 @@ use OCP\ITempManager; use OCP\IURLGenerator; class ImageManager { - public const SupportedImageKeys = ['background', 'logo', 'logoheader', 'favicon']; + public const SUPPORTED_IMAGE_KEYS = ['background', 'logo', 'logoheader', 'favicon']; /** @var IConfig */ private $config; @@ -74,8 +76,14 @@ class ImageManager { $this->appData = $appData; } - public function getImageUrl(string $key, bool $useSvg = true): string { - $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); + /** + * Get a globally defined image (admin theming settings) + * + * @param string $key the image key + * @return string the image url + */ + public function getImageUrl(string $key): string { + $cacheBusterCounter = $this->config->getAppValue(Application::APP_ID, 'cachebuster', '0'); if ($this->hasImage($key)) { return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => $key ]) . '?v=' . $cacheBusterCounter; } @@ -86,13 +94,16 @@ class ImageManager { case 'favicon': return $this->urlGenerator->imagePath('core', 'logo/logo.png') . '?v=' . $cacheBusterCounter; case 'background': - return $this->urlGenerator->imagePath('core', 'background.png') . '?v=' . $cacheBusterCounter; + return $this->urlGenerator->linkTo(Application::APP_ID, "img/background/" . BackgroundService::DEFAULT_BACKGROUND); } return ''; } - public function getImageUrlAbsolute(string $key, bool $useSvg = true): string { - return $this->urlGenerator->getAbsoluteURL($this->getImageUrl($key, $useSvg)); + /** + * Get the absolute url. See getImageUrl + */ + public function getImageUrlAbsolute(string $key): string { + return $this->urlGenerator->getAbsoluteURL($this->getImageUrl($key)); } /** @@ -136,6 +147,20 @@ class ImageManager { return $mimeSetting !== ''; } + /** + * @return array + */ + public function getCustomImages(): array { + $images = []; + foreach (self::SUPPORTED_IMAGE_KEYS as $key) { + $images[$key] = [ + 'mime' => $this->config->getAppValue('theming', $key . 'Mime', ''), + 'url' => $this->getImageUrl($key), + ]; + } + return $images; + } + /** * Get folder for current theming files * -- cgit v1.2.3