Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add MIME type and file extension Helper methods #1420

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Classes/Common/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
use TYPO3\CMS\Core\Resource\MimeTypeCollection;
use TYPO3\CMS\Core\Resource\MimeTypeDetector;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
Expand Down Expand Up @@ -988,4 +989,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);
}
}
14 changes: 4 additions & 10 deletions Classes/Controller/ToolboxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down