From 38ea5d14b38d86fe09acf0df34857c9eba6e1c6f Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Sun, 2 Sep 2018 14:17:17 +0200 Subject: Disables SVG favicon uploads when imagemagick is missing. Signed-off-by: Michael Weimann --- apps/theming/lib/Controller/IconController.php | 2 +- apps/theming/lib/Controller/ThemingController.php | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'apps/theming/lib/Controller') diff --git a/apps/theming/lib/Controller/IconController.php b/apps/theming/lib/Controller/IconController.php index a2727546e09..bffabf43dd7 100644 --- a/apps/theming/lib/Controller/IconController.php +++ b/apps/theming/lib/Controller/IconController.php @@ -115,7 +115,7 @@ class IconController extends Controller { $response = null; $iconFile = null; try { - $iconFile = $this->imageManager->getImage('favicon'); + $iconFile = $this->imageManager->getImage('favicon', false); $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); } catch (NotFoundException $e) { } diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php index 44f1ea51c06..a1fa5e57836 100644 --- a/apps/theming/lib/Controller/ThemingController.php +++ b/apps/theming/lib/Controller/ThemingController.php @@ -265,7 +265,7 @@ class ThemingController extends Controller { $this->imageManager->delete($key); $target = $folder->newFile($key); - $supportedFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'image/svg']; + $supportedFormats = $this->getSupportedUploadImageFormats($key); $detectedMimeType = mime_content_type($image['tmp_name']); if (!in_array($image['type'], $supportedFormats) || !in_array($detectedMimeType, $supportedFormats)) { return new DataResponse( @@ -318,6 +318,24 @@ class ThemingController extends Controller { ); } + /** + * Returns a list of supported mime types for image uploads. + * "favicon" images are only allowed to be SVG when imagemagick with SVG support is available. + * + * @param string $key The image key, e.g. "favicon" + * @return array + */ + private function getSupportedUploadImageFormats(string $key): array { + $supportedFormats = ['image/jpeg', 'image/png', 'image/gif',]; + + if ($key !== 'favicon' || $this->imageManager->shouldReplaceIcons() === true) { + $supportedFormats[] = 'image/svg+xml'; + $supportedFormats[] = 'image/svg'; + } + + return $supportedFormats; + } + /** * Revert setting to default value * -- cgit v1.2.3