From e0565dc42ca83827f8c3607aa7c862518ec41f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Sch=C3=B6lzel?= Date: Thu, 2 Jan 2025 14:33:56 +0100 Subject: [PATCH] [FEATURE] Add MIME type and file extension Helper methods; simplify image mimetypeLabel logic --- Classes/Common/Helper.php | 24 ++++++++++++++++++++++++ Classes/Controller/ToolboxController.php | 14 ++++---------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Classes/Common/Helper.php b/Classes/Common/Helper.php index d1f182944..4c004a924 100644 --- a/Classes/Common/Helper.php +++ b/Classes/Common/Helper.php @@ -988,4 +988,28 @@ function ($mimeType) use ($categories) { } return false; } + + /** + * Get file extensions for a given MIME type + * + * @param string $mimeType + * @return array + */ + public static function getFileExtensionsForMimeType(string $mimeType): array + { + $mimeTypeDetector = GeneralUtility::makeInstance(MimeTypeDetector::class); + return $mimeTypeDetector->getFileExtensionsForMimeType($mimeType); + } + + /** + * Get MIME types for a given file extension + * + * @param string $fileExtension + * @return array + */ + public static function getMimeTypesForFileExtension(string $fileExtension): array + { + $mimeTypeDetector = GeneralUtility::makeInstance(MimeTypeDetector::class); + return $mimeTypeDetector->getMimeTypesForFileExtension($fileExtension); + } } diff --git a/Classes/Controller/ToolboxController.php b/Classes/Controller/ToolboxController.php index cb93c6d62..87ca43bab 100644 --- a/Classes/Controller/ToolboxController.php +++ b/Classes/Controller/ToolboxController.php @@ -139,19 +139,13 @@ private function renderToolByName(string $tool): void * * @return array Array of image information's. */ - public function getImage(int $page): array + private function getImage(int $page): array { // Get @USE value of METS fileGroup. $image = $this->getFile($page, GeneralUtility::trimExplode(',', $this->settings['fileGrpsImageDownload'])); - switch ($image['mimetype']) { - case 'image/jpeg': - $image['mimetypeLabel'] = ' (JPG)'; - break; - case 'image/tiff': - $image['mimetypeLabel'] = ' (TIFF)'; - break; - default: - $image['mimetypeLabel'] = ''; + if (isset($image['mimetype'])) { + $fileExtension = Helper::getFileExtensionsForMimeType($image['mimetype']); + $image['mimetypeLabel'] = !empty($fileExtension) ? ' (' . strtoupper($fileExtension[0]) . ')' : ''; } return $image; }