aboutsummaryrefslogtreecommitdiffstats
path: root/apps/theming/lib/ImageManager.php
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2022-10-20 13:18:06 +0200
committerJohn Molakvoæ <skjnldsv@protonmail.com>2022-11-29 11:22:13 +0100
commitcedae7c6d74e11c8aaa59b09a38db04dbebc818d (patch)
treeb95c77675542e0654084dd41f5d1f07a413b4db7 /apps/theming/lib/ImageManager.php
parenta884f311b78341612adeb6d62f707dda1bae39e7 (diff)
downloadnextcloud-server-cedae7c6d74e11c8aaa59b09a38db04dbebc818d.tar.gz
nextcloud-server-cedae7c6d74e11c8aaa59b09a38db04dbebc818d.zip
Allow to remove the background and select a custom colour
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/theming/lib/ImageManager.php')
-rw-r--r--apps/theming/lib/ImageManager.php37
1 files changed, 31 insertions, 6 deletions
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));
}
/**
@@ -137,6 +148,20 @@ class ImageManager {
}
/**
+ * @return array<string, array{mime: string, url: string}>
+ */
+ 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
*
* @return ISimpleFolder