@@ -3,39 +3,39 @@ |
||
| 3 | 3 | |
| 4 | 4 | call_user_func(function () { |
| 5 | 5 | |
| 6 | - $configuration = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( |
|
| 7 | - \TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class |
|
| 8 | - )->get('media'); |
|
| 6 | + $configuration = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( |
|
| 7 | + \TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class |
|
| 8 | + )->get('media'); |
|
| 9 | 9 | |
| 10 | - $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][1547054767] = [ |
|
| 11 | - 'nodeName' => 'findUploader', |
|
| 12 | - 'priority' => 40, |
|
| 13 | - 'class' => \Fab\Media\Backend\TceForms::class, |
|
| 14 | - ]; |
|
| 10 | + $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][1547054767] = [ |
|
| 11 | + 'nodeName' => 'findUploader', |
|
| 12 | + 'priority' => 40, |
|
| 13 | + 'class' => \Fab\Media\Backend\TceForms::class, |
|
| 14 | + ]; |
|
| 15 | 15 | |
| 16 | - $disableTitleMetadataExtractor = isset($configuration['disable_title_metadata_extractor']) ? $configuration['disable_title_metadata_extractor'] : FALSE; |
|
| 17 | - if (!$disableTitleMetadataExtractor) { |
|
| 16 | + $disableTitleMetadataExtractor = isset($configuration['disable_title_metadata_extractor']) ? $configuration['disable_title_metadata_extractor'] : FALSE; |
|
| 17 | + if (!$disableTitleMetadataExtractor) { |
|
| 18 | 18 | |
| 19 | - // Register basic metadata extractor. Will feed the file with a "title" when indexing, e.g. upload, through scheduler |
|
| 20 | - \TYPO3\CMS\Core\Resource\Index\ExtractorRegistry::getInstance()->registerExtractionService(\Fab\Media\Index\TitleMetadataExtractor::class ); |
|
| 21 | - } |
|
| 19 | + // Register basic metadata extractor. Will feed the file with a "title" when indexing, e.g. upload, through scheduler |
|
| 20 | + \TYPO3\CMS\Core\Resource\Index\ExtractorRegistry::getInstance()->registerExtractionService(\Fab\Media\Index\TitleMetadataExtractor::class ); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - // Hook for traditional file upload, trigger metadata indexing as well. |
|
| 24 | - // Could be done at the Core level in the future... |
|
| 25 | - $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_extfilefunc.php']['processData'][] = 'Fab\Media\Hook\FileUploadHook'; |
|
| 23 | + // Hook for traditional file upload, trigger metadata indexing as well. |
|
| 24 | + // Could be done at the Core level in the future... |
|
| 25 | + $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_extfilefunc.php']['processData'][] = 'Fab\Media\Hook\FileUploadHook'; |
|
| 26 | 26 | |
| 27 | - if (TYPO3_MODE === 'BE') { |
|
| 27 | + if (TYPO3_MODE === 'BE') { |
|
| 28 | 28 | |
| 29 | - // Special process to fill column "usage" which indicates the total number of file reference including soft references. |
|
| 30 | - $GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = 'Fab\Media\Hook\DataHandlerHook'; |
|
| 29 | + // Special process to fill column "usage" which indicates the total number of file reference including soft references. |
|
| 30 | + $GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = 'Fab\Media\Hook\DataHandlerHook'; |
|
| 31 | 31 | |
| 32 | - $hasMediaFilePicker = isset($configuration['has_media_file_picker']) ? $configuration['has_media_file_picker'] : FALSE; |
|
| 33 | - if ($hasMediaFilePicker) { |
|
| 32 | + $hasMediaFilePicker = isset($configuration['has_media_file_picker']) ? $configuration['has_media_file_picker'] : FALSE; |
|
| 33 | + if ($hasMediaFilePicker) { |
|
| 34 | 34 | |
| 35 | - // Override classes for the Object Manager. |
|
| 36 | - $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\TYPO3\CMS\Backend\Form\FormResultCompiler::class] = array( |
|
| 37 | - 'className' => \Fab\Media\Override\Backend\Form\FormResultCompiler::class |
|
| 38 | - ); |
|
| 39 | - } |
|
| 40 | - } |
|
| 35 | + // Override classes for the Object Manager. |
|
| 36 | + $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\TYPO3\CMS\Backend\Form\FormResultCompiler::class] = array( |
|
| 37 | + 'className' => \Fab\Media\Override\Backend\Form\FormResultCompiler::class |
|
| 38 | + ); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | }); |
| 42 | 42 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | defined('TYPO3_MODE') or die(); |
| 3 | 3 | |
| 4 | -call_user_func(function () { |
|
| 4 | +call_user_func(function() { |
|
| 5 | 5 | |
| 6 | 6 | $configuration = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( |
| 7 | 7 | \TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | if (!$disableTitleMetadataExtractor) { |
| 18 | 18 | |
| 19 | 19 | // Register basic metadata extractor. Will feed the file with a "title" when indexing, e.g. upload, through scheduler |
| 20 | - \TYPO3\CMS\Core\Resource\Index\ExtractorRegistry::getInstance()->registerExtractionService(\Fab\Media\Index\TitleMetadataExtractor::class ); |
|
| 20 | + \TYPO3\CMS\Core\Resource\Index\ExtractorRegistry::getInstance()->registerExtractionService(\Fab\Media\Index\TitleMetadataExtractor::class); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | // Hook for traditional file upload, trigger metadata indexing as well. |
@@ -1,30 +1,30 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | $EM_CONF[$_EXTKEY] = [ |
| 4 | - 'title' => 'Media management', |
|
| 5 | - 'description' => 'Media management system for TYPO3 CMS.', |
|
| 6 | - 'category' => 'module', |
|
| 7 | - 'author' => 'Fabien Udriot', |
|
| 8 | - 'author_email' => '[email protected]', |
|
| 9 | - 'state' => 'stable', |
|
| 10 | - 'version' => '5.2.0-dev', |
|
| 11 | - 'autoload' => [ |
|
| 12 | - 'psr-4' => ['Fab\\Media\\' => 'Classes'] |
|
| 13 | - ], |
|
| 14 | - 'constraints' => |
|
| 15 | - [ |
|
| 16 | - 'depends' => |
|
| 17 | - [ |
|
| 18 | - 'typo3' => '10.4.0-10.4.99', |
|
| 19 | - 'vidi' => '4.0.0-0.0.0', |
|
| 20 | - ], |
|
| 21 | - 'conflicts' => |
|
| 22 | - [ |
|
| 23 | - ], |
|
| 24 | - 'suggests' => |
|
| 25 | - [ |
|
| 26 | - 'metadata' => '', |
|
| 27 | - 'filemetadata' => '', |
|
| 28 | - ], |
|
| 29 | - ] |
|
| 4 | + 'title' => 'Media management', |
|
| 5 | + 'description' => 'Media management system for TYPO3 CMS.', |
|
| 6 | + 'category' => 'module', |
|
| 7 | + 'author' => 'Fabien Udriot', |
|
| 8 | + 'author_email' => '[email protected]', |
|
| 9 | + 'state' => 'stable', |
|
| 10 | + 'version' => '5.2.0-dev', |
|
| 11 | + 'autoload' => [ |
|
| 12 | + 'psr-4' => ['Fab\\Media\\' => 'Classes'] |
|
| 13 | + ], |
|
| 14 | + 'constraints' => |
|
| 15 | + [ |
|
| 16 | + 'depends' => |
|
| 17 | + [ |
|
| 18 | + 'typo3' => '10.4.0-10.4.99', |
|
| 19 | + 'vidi' => '4.0.0-0.0.0', |
|
| 20 | + ], |
|
| 21 | + 'conflicts' => |
|
| 22 | + [ |
|
| 23 | + ], |
|
| 24 | + 'suggests' => |
|
| 25 | + [ |
|
| 26 | + 'metadata' => '', |
|
| 27 | + 'filemetadata' => '', |
|
| 28 | + ], |
|
| 29 | + ] |
|
| 30 | 30 | ]; |
@@ -20,37 +20,37 @@ |
||
| 20 | 20 | class TceForms extends AbstractFormElement |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @return array |
|
| 25 | - */ |
|
| 26 | - public function render() |
|
| 27 | - { |
|
| 28 | - // Load StyleSheets in the Page Renderer |
|
| 29 | - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
| 30 | - $cssFile = ExtensionManagementUtility::extPath('media') . 'Resources/Public/StyleSheets/fineuploader.tce.css'; |
|
| 31 | - $pageRenderer->addCssFile($cssFile); |
|
| 32 | - |
|
| 33 | - // language labels for JavaScript files |
|
| 34 | - $pageRenderer->addInlineLanguageLabelFile(ExtensionManagementUtility::extPath('media') . 'Resources/Private/Language/locallang.xlf', 'media_file_upload'); |
|
| 35 | - |
|
| 36 | - // js files to be loaded |
|
| 37 | - $pageRenderer->addJsFile(ExtensionManagementUtility::extPath('core') . 'Resources/Public/JavaScript/Contrib/jquery/jquery.min.js'); |
|
| 38 | - $pageRenderer->addJsFile(ExtensionManagementUtility::extPath('media') . 'Resources/Public/JavaScript/Encoder.js'); |
|
| 39 | - $pageRenderer->addJsFile(ExtensionManagementUtility::extPath('media') . 'Resources/Public/Libraries/Fineuploader/jquery.fineuploader-5.0.9.min.js'); |
|
| 40 | - |
|
| 41 | - $result = $this->initializeResultArray(); |
|
| 42 | - |
|
| 43 | - $fileMetadataRecord = $this->data['databaseRow']; |
|
| 44 | - |
|
| 45 | - if ($fileMetadataRecord['file'] <= 0) { |
|
| 46 | - throw new \Exception('I could not find a valid file identifier', 1392926871); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** @var $fileUpload \Fab\Media\Form\FileUploadTceForms */ |
|
| 50 | - $fileUpload = GeneralUtility::makeInstance(\Fab\Media\Form\FileUploadTceForms::class); |
|
| 51 | - $fileUpload->setValue($fileMetadataRecord['file'][0])->setPrefix(MediaModule::getParameterPrefix()); |
|
| 52 | - $result['html'] = $fileUpload->render(); |
|
| 53 | - return $result; |
|
| 54 | - } |
|
| 23 | + /** |
|
| 24 | + * @return array |
|
| 25 | + */ |
|
| 26 | + public function render() |
|
| 27 | + { |
|
| 28 | + // Load StyleSheets in the Page Renderer |
|
| 29 | + $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
| 30 | + $cssFile = ExtensionManagementUtility::extPath('media') . 'Resources/Public/StyleSheets/fineuploader.tce.css'; |
|
| 31 | + $pageRenderer->addCssFile($cssFile); |
|
| 32 | + |
|
| 33 | + // language labels for JavaScript files |
|
| 34 | + $pageRenderer->addInlineLanguageLabelFile(ExtensionManagementUtility::extPath('media') . 'Resources/Private/Language/locallang.xlf', 'media_file_upload'); |
|
| 35 | + |
|
| 36 | + // js files to be loaded |
|
| 37 | + $pageRenderer->addJsFile(ExtensionManagementUtility::extPath('core') . 'Resources/Public/JavaScript/Contrib/jquery/jquery.min.js'); |
|
| 38 | + $pageRenderer->addJsFile(ExtensionManagementUtility::extPath('media') . 'Resources/Public/JavaScript/Encoder.js'); |
|
| 39 | + $pageRenderer->addJsFile(ExtensionManagementUtility::extPath('media') . 'Resources/Public/Libraries/Fineuploader/jquery.fineuploader-5.0.9.min.js'); |
|
| 40 | + |
|
| 41 | + $result = $this->initializeResultArray(); |
|
| 42 | + |
|
| 43 | + $fileMetadataRecord = $this->data['databaseRow']; |
|
| 44 | + |
|
| 45 | + if ($fileMetadataRecord['file'] <= 0) { |
|
| 46 | + throw new \Exception('I could not find a valid file identifier', 1392926871); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** @var $fileUpload \Fab\Media\Form\FileUploadTceForms */ |
|
| 50 | + $fileUpload = GeneralUtility::makeInstance(\Fab\Media\Form\FileUploadTceForms::class); |
|
| 51 | + $fileUpload->setValue($fileMetadataRecord['file'][0])->setPrefix(MediaModule::getParameterPrefix()); |
|
| 52 | + $result['html'] = $fileUpload->render(); |
|
| 53 | + return $result; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | 56 | } |
@@ -27,16 +27,16 @@ |
||
| 27 | 27 | { |
| 28 | 28 | // Load StyleSheets in the Page Renderer |
| 29 | 29 | $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
| 30 | - $cssFile = ExtensionManagementUtility::extPath('media') . 'Resources/Public/StyleSheets/fineuploader.tce.css'; |
|
| 30 | + $cssFile = ExtensionManagementUtility::extPath('media').'Resources/Public/StyleSheets/fineuploader.tce.css'; |
|
| 31 | 31 | $pageRenderer->addCssFile($cssFile); |
| 32 | 32 | |
| 33 | 33 | // language labels for JavaScript files |
| 34 | - $pageRenderer->addInlineLanguageLabelFile(ExtensionManagementUtility::extPath('media') . 'Resources/Private/Language/locallang.xlf', 'media_file_upload'); |
|
| 34 | + $pageRenderer->addInlineLanguageLabelFile(ExtensionManagementUtility::extPath('media').'Resources/Private/Language/locallang.xlf', 'media_file_upload'); |
|
| 35 | 35 | |
| 36 | 36 | // js files to be loaded |
| 37 | - $pageRenderer->addJsFile(ExtensionManagementUtility::extPath('core') . 'Resources/Public/JavaScript/Contrib/jquery/jquery.min.js'); |
|
| 38 | - $pageRenderer->addJsFile(ExtensionManagementUtility::extPath('media') . 'Resources/Public/JavaScript/Encoder.js'); |
|
| 39 | - $pageRenderer->addJsFile(ExtensionManagementUtility::extPath('media') . 'Resources/Public/Libraries/Fineuploader/jquery.fineuploader-5.0.9.min.js'); |
|
| 37 | + $pageRenderer->addJsFile(ExtensionManagementUtility::extPath('core').'Resources/Public/JavaScript/Contrib/jquery/jquery.min.js'); |
|
| 38 | + $pageRenderer->addJsFile(ExtensionManagementUtility::extPath('media').'Resources/Public/JavaScript/Encoder.js'); |
|
| 39 | + $pageRenderer->addJsFile(ExtensionManagementUtility::extPath('media').'Resources/Public/Libraries/Fineuploader/jquery.fineuploader-5.0.9.min.js'); |
|
| 40 | 40 | |
| 41 | 41 | $result = $this->initializeResultArray(); |
| 42 | 42 | |
@@ -42,314 +42,314 @@ |
||
| 42 | 42 | class AssetController extends ActionController |
| 43 | 43 | { |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 48 | - protected $dataType = 'sys_file'; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @throws \Fab\Media\Exception\StorageNotOnlineException |
|
| 52 | - * @throws \InvalidArgumentException |
|
| 53 | - * @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException |
|
| 54 | - */ |
|
| 55 | - public function initializeAction() |
|
| 56 | - { |
|
| 57 | - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
| 58 | - $pageRenderer->addInlineLanguageLabelFile('EXT:media/Resources/Private/Language/locallang.xlf'); |
|
| 59 | - |
|
| 60 | - // Configure property mapping to retrieve the file object. |
|
| 61 | - if ($this->arguments->hasArgument('file')) { |
|
| 62 | - |
|
| 63 | - /** @var FileConverter $typeConverter */ |
|
| 64 | - $typeConverter = $this->objectManager->get(FileConverter::class); |
|
| 65 | - |
|
| 66 | - $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
| 67 | - $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Force download of the file. |
|
| 73 | - * |
|
| 74 | - * @param File $file |
|
| 75 | - * @param bool $forceDownload |
|
| 76 | - * @return bool|string |
|
| 77 | - * @throws \RuntimeException |
|
| 78 | - */ |
|
| 79 | - public function downloadAction(File $file, $forceDownload = false) |
|
| 80 | - { |
|
| 81 | - |
|
| 82 | - if ($file->exists() && $file->getStorage()->isWithinFileMountBoundaries($file->getParentFolder())) { |
|
| 83 | - |
|
| 84 | - // Emit signal before downloading the file. |
|
| 85 | - $this->emitBeforeDownloadSignal($file); |
|
| 86 | - |
|
| 87 | - // Read the file and dump it with the flag "forceDownload" set to true or false. |
|
| 88 | - $file->getStorage()->dumpFileContents($file, $forceDownload); |
|
| 89 | - |
|
| 90 | - $result = true; |
|
| 91 | - } else { |
|
| 92 | - $result = 'Access denied!'; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return $result; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Handle file upload for a new file. |
|
| 100 | - * |
|
| 101 | - * @param string $combinedIdentifier |
|
| 102 | - * @Extbase\Validate("\Fab\Media\Domain\Validator\StorageValidator", param="combinedIdentifier") |
|
| 103 | - * @return string |
|
| 104 | - */ |
|
| 105 | - public function createAction($combinedIdentifier) |
|
| 106 | - { |
|
| 107 | - /** @var UploadedFileInterface $uploadedFile */ |
|
| 108 | - $uploadedFile = $this->handleUpload(); |
|
| 109 | - if (!is_object($uploadedFile)) { |
|
| 110 | - return htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - // Get the target folder. |
|
| 114 | - if ($this->getMediaModule()->hasFolderTree()) { |
|
| 115 | - $targetFolder = $this->getMediaModule()->getFolderForCombinedIdentifier($combinedIdentifier); |
|
| 116 | - } else { |
|
| 117 | - $storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier); |
|
| 118 | - $targetFolder = $this->getMediaModule()->getTargetFolderForUploadedFile($uploadedFile, $storage); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - try { |
|
| 122 | - $conflictMode = DuplicationBehavior::RENAME; |
|
| 123 | - $fileName = $uploadedFile->getName(); |
|
| 124 | - $file = $targetFolder->addFile($uploadedFile->getFileWithAbsolutePath(), $fileName, $conflictMode); |
|
| 125 | - |
|
| 126 | - // Run the indexer for extracting metadata. |
|
| 127 | - $this->getMediaIndexer($file->getStorage()) |
|
| 128 | - ->extractMetadata($file) |
|
| 129 | - ->applyDefaultCategories($file); |
|
| 130 | - |
|
| 131 | - $response = array( |
|
| 132 | - 'success' => true, |
|
| 133 | - 'uid' => $file->getUid(), |
|
| 134 | - 'name' => $file->getName(), |
|
| 135 | - 'thumbnail' => $this->getThumbnailService($file)->create(), |
|
| 136 | - ); |
|
| 137 | - } catch (UploadException $e) { |
|
| 138 | - $response = array('error' => 'The upload has failed, no uploaded file found!'); |
|
| 139 | - } catch (InsufficientUserPermissionsException $e) { |
|
| 140 | - $response = array('error' => 'You are not allowed to upload files!'); |
|
| 141 | - } catch (UploadSizeException $e) { |
|
| 142 | - $response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName()))); |
|
| 143 | - } catch (InsufficientFolderWritePermissionsException $e) { |
|
| 144 | - $response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier()))); |
|
| 145 | - } catch (IllegalFileExtensionException $e) { |
|
| 146 | - $response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier()))); |
|
| 147 | - } catch (ExistingTargetFileNameException $e) { |
|
| 148 | - $response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier()))); |
|
| 149 | - } catch (\RuntimeException $e) { |
|
| 150 | - $response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier()))); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // to pass data through iframe you will need to encode all html tags |
|
| 154 | - header("Content-Type: text/plain"); |
|
| 155 | - return htmlspecialchars(json_encode($response), ENT_NOQUOTES); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Handle file upload for an existing file. |
|
| 160 | - * |
|
| 161 | - * @param File $file |
|
| 162 | - * @return string |
|
| 163 | - * @throws \InvalidArgumentException |
|
| 164 | - * @throws \RuntimeException |
|
| 165 | - */ |
|
| 166 | - public function updateAction(File $file) |
|
| 167 | - { |
|
| 168 | - $uploadedFile = $this->handleUpload(); |
|
| 169 | - if (!is_object($uploadedFile)) { |
|
| 170 | - return htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** @var $file File */ |
|
| 174 | - $targetFolder = $file->getStorage()->getFolder(dirname($file->getIdentifier())); |
|
| 175 | - |
|
| 176 | - try { |
|
| 177 | - $storage = $file->getStorage(); |
|
| 178 | - $storage->replaceFile($file, $uploadedFile->getFileWithAbsolutePath()); |
|
| 179 | - |
|
| 180 | - // Run the indexer for extracting metadata. |
|
| 181 | - $this->getMediaIndexer($file->getStorage()) |
|
| 182 | - ->updateIndex($file) |
|
| 183 | - ->extractMetadata($file); |
|
| 184 | - |
|
| 185 | - // Clear cache on pages holding a reference to this file. |
|
| 186 | - $this->getCacheService()->clearCache($file); |
|
| 187 | - |
|
| 188 | - $response = array( |
|
| 189 | - 'success' => true, |
|
| 190 | - 'uid' => $file->getUid(), |
|
| 191 | - 'name' => $file->getName(), |
|
| 192 | - 'thumbnail' => $this->getThumbnailService($file)->create(), |
|
| 193 | - 'fileInfo' => $this->getMetadataViewHelper()->render($file), |
|
| 194 | - ); |
|
| 195 | - } catch (UploadException $e) { |
|
| 196 | - $response = array('error' => 'The upload has failed, no uploaded file found!'); |
|
| 197 | - } catch (InsufficientUserPermissionsException $e) { |
|
| 198 | - $response = array('error' => 'You are not allowed to upload files!'); |
|
| 199 | - } catch (UploadSizeException $e) { |
|
| 200 | - $response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName()))); |
|
| 201 | - } catch (InsufficientFolderWritePermissionsException $e) { |
|
| 202 | - $response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier()))); |
|
| 203 | - } catch (IllegalFileExtensionException $e) { |
|
| 204 | - $response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier()))); |
|
| 205 | - } catch (ExistingTargetFileNameException $e) { |
|
| 206 | - $response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier()))); |
|
| 207 | - } catch (\RuntimeException $e) { |
|
| 208 | - $response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier()))); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - // to pass data through iframe you will need to encode all html tags |
|
| 212 | - header("Content-Type: text/plain"); |
|
| 213 | - return htmlspecialchars(json_encode($response), ENT_NOQUOTES); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Returns an editing form for moving Files between storage. |
|
| 218 | - * |
|
| 219 | - * @param array $matches |
|
| 220 | - * @throws \Exception |
|
| 221 | - */ |
|
| 222 | - public function editStorageAction(array $matches = []) |
|
| 223 | - { |
|
| 224 | - |
|
| 225 | - $this->view->assign('storages', $this->getMediaModule()->getAllowedStorages()); |
|
| 226 | - $this->view->assign('storageTitle', Tca::table('sys_file_storage')->getTitle()); |
|
| 227 | - |
|
| 228 | - $fieldName = 'storage'; |
|
| 229 | - |
|
| 230 | - // Instantiate the Matcher object according different rules. |
|
| 231 | - $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches, $this->dataType); |
|
| 232 | - |
|
| 233 | - // Fetch objects via the Content Service. |
|
| 234 | - $contentService = $this->getContentService()->findBy($matcher); |
|
| 235 | - |
|
| 236 | - $fieldType = Tca::table($this->dataType)->field($fieldName)->getType(); |
|
| 237 | - |
|
| 238 | - $this->view->assign('fieldType', ucfirst($fieldType)); |
|
| 239 | - $this->view->assign('dataType', $this->dataType); |
|
| 240 | - $this->view->assign('matches', $matches); |
|
| 241 | - $this->view->assign('fieldNameAndPath', $fieldName); |
|
| 242 | - $this->view->assign('numberOfObjects', $contentService->getNumberOfObjects()); |
|
| 243 | - $this->view->assign('editWholeSelection', empty($matches['uid'])); // necessary?? |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * Handle file upload. |
|
| 248 | - * |
|
| 249 | - * @return \Fab\Media\FileUpload\UploadedFileInterface|array |
|
| 250 | - * @throws \InvalidArgumentException |
|
| 251 | - */ |
|
| 252 | - protected function handleUpload() |
|
| 253 | - { |
|
| 254 | - |
|
| 255 | - /** @var $uploadManager UploadManager */ |
|
| 256 | - $uploadManager = GeneralUtility::makeInstance(UploadManager::class); |
|
| 257 | - |
|
| 258 | - try { |
|
| 259 | - /** @var $result \Fab\Media\FileUpload\UploadedFileInterface */ |
|
| 260 | - $result = $uploadManager->handleUpload(); |
|
| 261 | - } catch (\Exception $e) { |
|
| 262 | - $result = array('error' => $e->getMessage()); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - return $result; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * @return MetadataViewHelper |
|
| 270 | - * @throws \InvalidArgumentException |
|
| 271 | - */ |
|
| 272 | - protected function getMetadataViewHelper() |
|
| 273 | - { |
|
| 274 | - return GeneralUtility::makeInstance(MetadataViewHelper::class); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * @param File $file |
|
| 279 | - * @return ThumbnailService |
|
| 280 | - * @throws \Fab\Media\Exception\InvalidKeyInArrayException |
|
| 281 | - * @throws \InvalidArgumentException |
|
| 282 | - */ |
|
| 283 | - protected function getThumbnailService(File $file) |
|
| 284 | - { |
|
| 285 | - |
|
| 286 | - /** @var $thumbnailService ThumbnailService */ |
|
| 287 | - $thumbnailService = GeneralUtility::makeInstance(ThumbnailService::class, $file); |
|
| 288 | - $thumbnailService->setAppendTimeStamp(true) |
|
| 289 | - ->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED); |
|
| 290 | - return $thumbnailService; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Get the instance of the Indexer service to update the metadata of the file. |
|
| 295 | - * |
|
| 296 | - * @param int|ResourceStorage $storage |
|
| 297 | - * @return MediaIndexer |
|
| 298 | - * @throws \InvalidArgumentException |
|
| 299 | - */ |
|
| 300 | - protected function getMediaIndexer($storage) |
|
| 301 | - { |
|
| 302 | - return GeneralUtility::makeInstance(MediaIndexer::class, $storage); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * @return CacheService |
|
| 307 | - * @throws \InvalidArgumentException |
|
| 308 | - */ |
|
| 309 | - protected function getCacheService() |
|
| 310 | - { |
|
| 311 | - return GeneralUtility::makeInstance(CacheService::class); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * Signal that is emitted before a file is downloaded. |
|
| 316 | - * |
|
| 317 | - * @param File $file |
|
| 318 | - * @return void |
|
| 319 | - * @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException |
|
| 320 | - * @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException |
|
| 321 | - */ |
|
| 322 | - protected function emitBeforeDownloadSignal(File $file) |
|
| 323 | - { |
|
| 324 | - $this->getSignalSlotDispatcher()->dispatch('Fab\Media\Controller\Backend\AssetController', 'beforeDownload', array($file)); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * Get the SignalSlot dispatcher. |
|
| 329 | - * |
|
| 330 | - * @return Dispatcher |
|
| 331 | - */ |
|
| 332 | - protected function getSignalSlotDispatcher() |
|
| 333 | - { |
|
| 334 | - return $this->objectManager->get(Dispatcher::class); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * @return ContentService |
|
| 339 | - * @throws \InvalidArgumentException |
|
| 340 | - */ |
|
| 341 | - protected function getContentService() |
|
| 342 | - { |
|
| 343 | - return GeneralUtility::makeInstance(ContentService::class, $this->dataType); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * @return MediaModule|object |
|
| 348 | - * @throws \InvalidArgumentException |
|
| 349 | - */ |
|
| 350 | - protected function getMediaModule() |
|
| 351 | - { |
|
| 352 | - return GeneralUtility::makeInstance(MediaModule::class); |
|
| 353 | - } |
|
| 45 | + /** |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | + protected $dataType = 'sys_file'; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @throws \Fab\Media\Exception\StorageNotOnlineException |
|
| 52 | + * @throws \InvalidArgumentException |
|
| 53 | + * @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException |
|
| 54 | + */ |
|
| 55 | + public function initializeAction() |
|
| 56 | + { |
|
| 57 | + $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
| 58 | + $pageRenderer->addInlineLanguageLabelFile('EXT:media/Resources/Private/Language/locallang.xlf'); |
|
| 59 | + |
|
| 60 | + // Configure property mapping to retrieve the file object. |
|
| 61 | + if ($this->arguments->hasArgument('file')) { |
|
| 62 | + |
|
| 63 | + /** @var FileConverter $typeConverter */ |
|
| 64 | + $typeConverter = $this->objectManager->get(FileConverter::class); |
|
| 65 | + |
|
| 66 | + $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
| 67 | + $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Force download of the file. |
|
| 73 | + * |
|
| 74 | + * @param File $file |
|
| 75 | + * @param bool $forceDownload |
|
| 76 | + * @return bool|string |
|
| 77 | + * @throws \RuntimeException |
|
| 78 | + */ |
|
| 79 | + public function downloadAction(File $file, $forceDownload = false) |
|
| 80 | + { |
|
| 81 | + |
|
| 82 | + if ($file->exists() && $file->getStorage()->isWithinFileMountBoundaries($file->getParentFolder())) { |
|
| 83 | + |
|
| 84 | + // Emit signal before downloading the file. |
|
| 85 | + $this->emitBeforeDownloadSignal($file); |
|
| 86 | + |
|
| 87 | + // Read the file and dump it with the flag "forceDownload" set to true or false. |
|
| 88 | + $file->getStorage()->dumpFileContents($file, $forceDownload); |
|
| 89 | + |
|
| 90 | + $result = true; |
|
| 91 | + } else { |
|
| 92 | + $result = 'Access denied!'; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return $result; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Handle file upload for a new file. |
|
| 100 | + * |
|
| 101 | + * @param string $combinedIdentifier |
|
| 102 | + * @Extbase\Validate("\Fab\Media\Domain\Validator\StorageValidator", param="combinedIdentifier") |
|
| 103 | + * @return string |
|
| 104 | + */ |
|
| 105 | + public function createAction($combinedIdentifier) |
|
| 106 | + { |
|
| 107 | + /** @var UploadedFileInterface $uploadedFile */ |
|
| 108 | + $uploadedFile = $this->handleUpload(); |
|
| 109 | + if (!is_object($uploadedFile)) { |
|
| 110 | + return htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + // Get the target folder. |
|
| 114 | + if ($this->getMediaModule()->hasFolderTree()) { |
|
| 115 | + $targetFolder = $this->getMediaModule()->getFolderForCombinedIdentifier($combinedIdentifier); |
|
| 116 | + } else { |
|
| 117 | + $storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier); |
|
| 118 | + $targetFolder = $this->getMediaModule()->getTargetFolderForUploadedFile($uploadedFile, $storage); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + try { |
|
| 122 | + $conflictMode = DuplicationBehavior::RENAME; |
|
| 123 | + $fileName = $uploadedFile->getName(); |
|
| 124 | + $file = $targetFolder->addFile($uploadedFile->getFileWithAbsolutePath(), $fileName, $conflictMode); |
|
| 125 | + |
|
| 126 | + // Run the indexer for extracting metadata. |
|
| 127 | + $this->getMediaIndexer($file->getStorage()) |
|
| 128 | + ->extractMetadata($file) |
|
| 129 | + ->applyDefaultCategories($file); |
|
| 130 | + |
|
| 131 | + $response = array( |
|
| 132 | + 'success' => true, |
|
| 133 | + 'uid' => $file->getUid(), |
|
| 134 | + 'name' => $file->getName(), |
|
| 135 | + 'thumbnail' => $this->getThumbnailService($file)->create(), |
|
| 136 | + ); |
|
| 137 | + } catch (UploadException $e) { |
|
| 138 | + $response = array('error' => 'The upload has failed, no uploaded file found!'); |
|
| 139 | + } catch (InsufficientUserPermissionsException $e) { |
|
| 140 | + $response = array('error' => 'You are not allowed to upload files!'); |
|
| 141 | + } catch (UploadSizeException $e) { |
|
| 142 | + $response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName()))); |
|
| 143 | + } catch (InsufficientFolderWritePermissionsException $e) { |
|
| 144 | + $response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier()))); |
|
| 145 | + } catch (IllegalFileExtensionException $e) { |
|
| 146 | + $response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier()))); |
|
| 147 | + } catch (ExistingTargetFileNameException $e) { |
|
| 148 | + $response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier()))); |
|
| 149 | + } catch (\RuntimeException $e) { |
|
| 150 | + $response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier()))); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // to pass data through iframe you will need to encode all html tags |
|
| 154 | + header("Content-Type: text/plain"); |
|
| 155 | + return htmlspecialchars(json_encode($response), ENT_NOQUOTES); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Handle file upload for an existing file. |
|
| 160 | + * |
|
| 161 | + * @param File $file |
|
| 162 | + * @return string |
|
| 163 | + * @throws \InvalidArgumentException |
|
| 164 | + * @throws \RuntimeException |
|
| 165 | + */ |
|
| 166 | + public function updateAction(File $file) |
|
| 167 | + { |
|
| 168 | + $uploadedFile = $this->handleUpload(); |
|
| 169 | + if (!is_object($uploadedFile)) { |
|
| 170 | + return htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** @var $file File */ |
|
| 174 | + $targetFolder = $file->getStorage()->getFolder(dirname($file->getIdentifier())); |
|
| 175 | + |
|
| 176 | + try { |
|
| 177 | + $storage = $file->getStorage(); |
|
| 178 | + $storage->replaceFile($file, $uploadedFile->getFileWithAbsolutePath()); |
|
| 179 | + |
|
| 180 | + // Run the indexer for extracting metadata. |
|
| 181 | + $this->getMediaIndexer($file->getStorage()) |
|
| 182 | + ->updateIndex($file) |
|
| 183 | + ->extractMetadata($file); |
|
| 184 | + |
|
| 185 | + // Clear cache on pages holding a reference to this file. |
|
| 186 | + $this->getCacheService()->clearCache($file); |
|
| 187 | + |
|
| 188 | + $response = array( |
|
| 189 | + 'success' => true, |
|
| 190 | + 'uid' => $file->getUid(), |
|
| 191 | + 'name' => $file->getName(), |
|
| 192 | + 'thumbnail' => $this->getThumbnailService($file)->create(), |
|
| 193 | + 'fileInfo' => $this->getMetadataViewHelper()->render($file), |
|
| 194 | + ); |
|
| 195 | + } catch (UploadException $e) { |
|
| 196 | + $response = array('error' => 'The upload has failed, no uploaded file found!'); |
|
| 197 | + } catch (InsufficientUserPermissionsException $e) { |
|
| 198 | + $response = array('error' => 'You are not allowed to upload files!'); |
|
| 199 | + } catch (UploadSizeException $e) { |
|
| 200 | + $response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName()))); |
|
| 201 | + } catch (InsufficientFolderWritePermissionsException $e) { |
|
| 202 | + $response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier()))); |
|
| 203 | + } catch (IllegalFileExtensionException $e) { |
|
| 204 | + $response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier()))); |
|
| 205 | + } catch (ExistingTargetFileNameException $e) { |
|
| 206 | + $response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier()))); |
|
| 207 | + } catch (\RuntimeException $e) { |
|
| 208 | + $response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier()))); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + // to pass data through iframe you will need to encode all html tags |
|
| 212 | + header("Content-Type: text/plain"); |
|
| 213 | + return htmlspecialchars(json_encode($response), ENT_NOQUOTES); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Returns an editing form for moving Files between storage. |
|
| 218 | + * |
|
| 219 | + * @param array $matches |
|
| 220 | + * @throws \Exception |
|
| 221 | + */ |
|
| 222 | + public function editStorageAction(array $matches = []) |
|
| 223 | + { |
|
| 224 | + |
|
| 225 | + $this->view->assign('storages', $this->getMediaModule()->getAllowedStorages()); |
|
| 226 | + $this->view->assign('storageTitle', Tca::table('sys_file_storage')->getTitle()); |
|
| 227 | + |
|
| 228 | + $fieldName = 'storage'; |
|
| 229 | + |
|
| 230 | + // Instantiate the Matcher object according different rules. |
|
| 231 | + $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches, $this->dataType); |
|
| 232 | + |
|
| 233 | + // Fetch objects via the Content Service. |
|
| 234 | + $contentService = $this->getContentService()->findBy($matcher); |
|
| 235 | + |
|
| 236 | + $fieldType = Tca::table($this->dataType)->field($fieldName)->getType(); |
|
| 237 | + |
|
| 238 | + $this->view->assign('fieldType', ucfirst($fieldType)); |
|
| 239 | + $this->view->assign('dataType', $this->dataType); |
|
| 240 | + $this->view->assign('matches', $matches); |
|
| 241 | + $this->view->assign('fieldNameAndPath', $fieldName); |
|
| 242 | + $this->view->assign('numberOfObjects', $contentService->getNumberOfObjects()); |
|
| 243 | + $this->view->assign('editWholeSelection', empty($matches['uid'])); // necessary?? |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * Handle file upload. |
|
| 248 | + * |
|
| 249 | + * @return \Fab\Media\FileUpload\UploadedFileInterface|array |
|
| 250 | + * @throws \InvalidArgumentException |
|
| 251 | + */ |
|
| 252 | + protected function handleUpload() |
|
| 253 | + { |
|
| 254 | + |
|
| 255 | + /** @var $uploadManager UploadManager */ |
|
| 256 | + $uploadManager = GeneralUtility::makeInstance(UploadManager::class); |
|
| 257 | + |
|
| 258 | + try { |
|
| 259 | + /** @var $result \Fab\Media\FileUpload\UploadedFileInterface */ |
|
| 260 | + $result = $uploadManager->handleUpload(); |
|
| 261 | + } catch (\Exception $e) { |
|
| 262 | + $result = array('error' => $e->getMessage()); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + return $result; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * @return MetadataViewHelper |
|
| 270 | + * @throws \InvalidArgumentException |
|
| 271 | + */ |
|
| 272 | + protected function getMetadataViewHelper() |
|
| 273 | + { |
|
| 274 | + return GeneralUtility::makeInstance(MetadataViewHelper::class); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * @param File $file |
|
| 279 | + * @return ThumbnailService |
|
| 280 | + * @throws \Fab\Media\Exception\InvalidKeyInArrayException |
|
| 281 | + * @throws \InvalidArgumentException |
|
| 282 | + */ |
|
| 283 | + protected function getThumbnailService(File $file) |
|
| 284 | + { |
|
| 285 | + |
|
| 286 | + /** @var $thumbnailService ThumbnailService */ |
|
| 287 | + $thumbnailService = GeneralUtility::makeInstance(ThumbnailService::class, $file); |
|
| 288 | + $thumbnailService->setAppendTimeStamp(true) |
|
| 289 | + ->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED); |
|
| 290 | + return $thumbnailService; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Get the instance of the Indexer service to update the metadata of the file. |
|
| 295 | + * |
|
| 296 | + * @param int|ResourceStorage $storage |
|
| 297 | + * @return MediaIndexer |
|
| 298 | + * @throws \InvalidArgumentException |
|
| 299 | + */ |
|
| 300 | + protected function getMediaIndexer($storage) |
|
| 301 | + { |
|
| 302 | + return GeneralUtility::makeInstance(MediaIndexer::class, $storage); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * @return CacheService |
|
| 307 | + * @throws \InvalidArgumentException |
|
| 308 | + */ |
|
| 309 | + protected function getCacheService() |
|
| 310 | + { |
|
| 311 | + return GeneralUtility::makeInstance(CacheService::class); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * Signal that is emitted before a file is downloaded. |
|
| 316 | + * |
|
| 317 | + * @param File $file |
|
| 318 | + * @return void |
|
| 319 | + * @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException |
|
| 320 | + * @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException |
|
| 321 | + */ |
|
| 322 | + protected function emitBeforeDownloadSignal(File $file) |
|
| 323 | + { |
|
| 324 | + $this->getSignalSlotDispatcher()->dispatch('Fab\Media\Controller\Backend\AssetController', 'beforeDownload', array($file)); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * Get the SignalSlot dispatcher. |
|
| 329 | + * |
|
| 330 | + * @return Dispatcher |
|
| 331 | + */ |
|
| 332 | + protected function getSignalSlotDispatcher() |
|
| 333 | + { |
|
| 334 | + return $this->objectManager->get(Dispatcher::class); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * @return ContentService |
|
| 339 | + * @throws \InvalidArgumentException |
|
| 340 | + */ |
|
| 341 | + protected function getContentService() |
|
| 342 | + { |
|
| 343 | + return GeneralUtility::makeInstance(ContentService::class, $this->dataType); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * @return MediaModule|object |
|
| 348 | + * @throws \InvalidArgumentException |
|
| 349 | + */ |
|
| 350 | + protected function getMediaModule() |
|
| 351 | + { |
|
| 352 | + return GeneralUtility::makeInstance(MediaModule::class); |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | 355 | } |
@@ -23,154 +23,154 @@ |
||
| 23 | 23 | class MediaIndexer |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var ResourceStorage |
|
| 28 | - */ |
|
| 29 | - protected $storage = null; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @param ResourceStorage $storage |
|
| 33 | - */ |
|
| 34 | - public function __construct(ResourceStorage $storage) |
|
| 35 | - { |
|
| 36 | - $this->storage = $storage; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @param \TYPO3\CMS\Core\Resource\File $file |
|
| 41 | - * @return $this |
|
| 42 | - */ |
|
| 43 | - public function updateIndex(File $file) |
|
| 44 | - { |
|
| 45 | - $this->getCoreIndexer()->updateIndexEntry($file); |
|
| 46 | - return $this; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @param \TYPO3\CMS\Core\Resource\File $file |
|
| 51 | - * @return $this |
|
| 52 | - */ |
|
| 53 | - public function extractMetadata(File $file) |
|
| 54 | - { |
|
| 55 | - |
|
| 56 | - $extractionServices = $this->getExtractorRegistry()->getExtractorsWithDriverSupport($this->storage->getDriverType()); |
|
| 57 | - |
|
| 58 | - $newMetaData = array( |
|
| 59 | - 0 => $file->_getMetaData() |
|
| 60 | - ); |
|
| 61 | - |
|
| 62 | - foreach ($extractionServices as $services) { |
|
| 63 | - if (is_array($services)) { |
|
| 64 | - foreach ($services as $service) { |
|
| 65 | - if ($service->canProcess($file)) { |
|
| 66 | - $newMetaData[$service->getPriority()] = $service->extractMetaData($file, $newMetaData); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - } else { |
|
| 70 | - $service = $services; |
|
| 71 | - // We could optimise here for not repeating this bit |
|
| 72 | - if ($service->canProcess($file)) { |
|
| 73 | - $newMetaData[$service->getPriority()] = $service->extractMetaData($file, $newMetaData); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - ksort($newMetaData); |
|
| 79 | - $metaData = []; |
|
| 80 | - foreach ($newMetaData as $data) { |
|
| 81 | - $metaData = array_merge($metaData, $data); |
|
| 82 | - } |
|
| 83 | - $file->updateProperties($metaData); |
|
| 84 | - $this->getMetaDataRepository()->update($file->getUid(), $metaData); |
|
| 85 | - $this->getFileIndexRepository()->updateIndexingTime($file->getUid()); |
|
| 86 | - |
|
| 87 | - return $this; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @param \TYPO3\CMS\Core\Resource\File $file |
|
| 92 | - * @return $this |
|
| 93 | - */ |
|
| 94 | - public function applyDefaultCategories(File $file) |
|
| 95 | - { |
|
| 96 | - |
|
| 97 | - $categoryList = ConfigurationUtility::getInstance()->get('default_categories'); |
|
| 98 | - $categories = GeneralUtility::trimExplode(',', $categoryList, true); |
|
| 99 | - |
|
| 100 | - foreach ($categories as $category) { |
|
| 101 | - $values = array( |
|
| 102 | - 'uid_local' => $category, |
|
| 103 | - 'uid_foreign' => $this->getFileMetadataIdentifier($file), |
|
| 104 | - 'tablenames' => 'sys_file_metadata', |
|
| 105 | - 'fieldname' => 'categories', |
|
| 106 | - ); |
|
| 107 | - $this->getDataService()->insert('sys_category_record_mm', $values); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $metaData['categories'] = count($categories); |
|
| 111 | - $file->updateProperties($metaData); |
|
| 112 | - $this->getMetaDataRepository()->update($file->getUid(), $metaData); |
|
| 113 | - $this->getFileIndexRepository()->updateIndexingTime($file->getUid()); |
|
| 114 | - return $this; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Retrieve the file metadata uid which is different from the file uid. |
|
| 119 | - * |
|
| 120 | - * @param \TYPO3\CMS\Core\Resource\File $file |
|
| 121 | - * @return int |
|
| 122 | - */ |
|
| 123 | - protected function getFileMetadataIdentifier(File $file) |
|
| 124 | - { |
|
| 125 | - $metadataProperties = $file->_getMetaData(); |
|
| 126 | - return isset($metadataProperties['_ORIG_uid']) ? (int)$metadataProperties['_ORIG_uid'] : (int)$metadataProperties['uid']; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Returns an instance of the FileIndexRepository |
|
| 132 | - * |
|
| 133 | - * @return FileIndexRepository |
|
| 134 | - */ |
|
| 135 | - protected function getFileIndexRepository() |
|
| 136 | - { |
|
| 137 | - return FileIndexRepository::getInstance(); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Returns an instance of the FileIndexRepository |
|
| 142 | - * |
|
| 143 | - * @return MetaDataRepository |
|
| 144 | - */ |
|
| 145 | - protected function getMetaDataRepository() |
|
| 146 | - { |
|
| 147 | - return MetaDataRepository::getInstance(); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Returns an instance of the FileIndexRepository |
|
| 152 | - * |
|
| 153 | - * @return ExtractorRegistry |
|
| 154 | - */ |
|
| 155 | - protected function getExtractorRegistry() |
|
| 156 | - { |
|
| 157 | - return ExtractorRegistry::getInstance(); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @return object|DataService |
|
| 162 | - */ |
|
| 163 | - protected function getDataService(): DataService |
|
| 164 | - { |
|
| 165 | - return GeneralUtility::makeInstance(DataService::class); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @return \TYPO3\CMS\Core\Resource\Index\Indexer|object |
|
| 170 | - */ |
|
| 171 | - protected function getCoreIndexer() |
|
| 172 | - { |
|
| 173 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Index\Indexer::class, $this->storage); |
|
| 174 | - } |
|
| 26 | + /** |
|
| 27 | + * @var ResourceStorage |
|
| 28 | + */ |
|
| 29 | + protected $storage = null; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @param ResourceStorage $storage |
|
| 33 | + */ |
|
| 34 | + public function __construct(ResourceStorage $storage) |
|
| 35 | + { |
|
| 36 | + $this->storage = $storage; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @param \TYPO3\CMS\Core\Resource\File $file |
|
| 41 | + * @return $this |
|
| 42 | + */ |
|
| 43 | + public function updateIndex(File $file) |
|
| 44 | + { |
|
| 45 | + $this->getCoreIndexer()->updateIndexEntry($file); |
|
| 46 | + return $this; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @param \TYPO3\CMS\Core\Resource\File $file |
|
| 51 | + * @return $this |
|
| 52 | + */ |
|
| 53 | + public function extractMetadata(File $file) |
|
| 54 | + { |
|
| 55 | + |
|
| 56 | + $extractionServices = $this->getExtractorRegistry()->getExtractorsWithDriverSupport($this->storage->getDriverType()); |
|
| 57 | + |
|
| 58 | + $newMetaData = array( |
|
| 59 | + 0 => $file->_getMetaData() |
|
| 60 | + ); |
|
| 61 | + |
|
| 62 | + foreach ($extractionServices as $services) { |
|
| 63 | + if (is_array($services)) { |
|
| 64 | + foreach ($services as $service) { |
|
| 65 | + if ($service->canProcess($file)) { |
|
| 66 | + $newMetaData[$service->getPriority()] = $service->extractMetaData($file, $newMetaData); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + } else { |
|
| 70 | + $service = $services; |
|
| 71 | + // We could optimise here for not repeating this bit |
|
| 72 | + if ($service->canProcess($file)) { |
|
| 73 | + $newMetaData[$service->getPriority()] = $service->extractMetaData($file, $newMetaData); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + ksort($newMetaData); |
|
| 79 | + $metaData = []; |
|
| 80 | + foreach ($newMetaData as $data) { |
|
| 81 | + $metaData = array_merge($metaData, $data); |
|
| 82 | + } |
|
| 83 | + $file->updateProperties($metaData); |
|
| 84 | + $this->getMetaDataRepository()->update($file->getUid(), $metaData); |
|
| 85 | + $this->getFileIndexRepository()->updateIndexingTime($file->getUid()); |
|
| 86 | + |
|
| 87 | + return $this; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @param \TYPO3\CMS\Core\Resource\File $file |
|
| 92 | + * @return $this |
|
| 93 | + */ |
|
| 94 | + public function applyDefaultCategories(File $file) |
|
| 95 | + { |
|
| 96 | + |
|
| 97 | + $categoryList = ConfigurationUtility::getInstance()->get('default_categories'); |
|
| 98 | + $categories = GeneralUtility::trimExplode(',', $categoryList, true); |
|
| 99 | + |
|
| 100 | + foreach ($categories as $category) { |
|
| 101 | + $values = array( |
|
| 102 | + 'uid_local' => $category, |
|
| 103 | + 'uid_foreign' => $this->getFileMetadataIdentifier($file), |
|
| 104 | + 'tablenames' => 'sys_file_metadata', |
|
| 105 | + 'fieldname' => 'categories', |
|
| 106 | + ); |
|
| 107 | + $this->getDataService()->insert('sys_category_record_mm', $values); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $metaData['categories'] = count($categories); |
|
| 111 | + $file->updateProperties($metaData); |
|
| 112 | + $this->getMetaDataRepository()->update($file->getUid(), $metaData); |
|
| 113 | + $this->getFileIndexRepository()->updateIndexingTime($file->getUid()); |
|
| 114 | + return $this; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Retrieve the file metadata uid which is different from the file uid. |
|
| 119 | + * |
|
| 120 | + * @param \TYPO3\CMS\Core\Resource\File $file |
|
| 121 | + * @return int |
|
| 122 | + */ |
|
| 123 | + protected function getFileMetadataIdentifier(File $file) |
|
| 124 | + { |
|
| 125 | + $metadataProperties = $file->_getMetaData(); |
|
| 126 | + return isset($metadataProperties['_ORIG_uid']) ? (int)$metadataProperties['_ORIG_uid'] : (int)$metadataProperties['uid']; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Returns an instance of the FileIndexRepository |
|
| 132 | + * |
|
| 133 | + * @return FileIndexRepository |
|
| 134 | + */ |
|
| 135 | + protected function getFileIndexRepository() |
|
| 136 | + { |
|
| 137 | + return FileIndexRepository::getInstance(); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Returns an instance of the FileIndexRepository |
|
| 142 | + * |
|
| 143 | + * @return MetaDataRepository |
|
| 144 | + */ |
|
| 145 | + protected function getMetaDataRepository() |
|
| 146 | + { |
|
| 147 | + return MetaDataRepository::getInstance(); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Returns an instance of the FileIndexRepository |
|
| 152 | + * |
|
| 153 | + * @return ExtractorRegistry |
|
| 154 | + */ |
|
| 155 | + protected function getExtractorRegistry() |
|
| 156 | + { |
|
| 157 | + return ExtractorRegistry::getInstance(); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @return object|DataService |
|
| 162 | + */ |
|
| 163 | + protected function getDataService(): DataService |
|
| 164 | + { |
|
| 165 | + return GeneralUtility::makeInstance(DataService::class); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @return \TYPO3\CMS\Core\Resource\Index\Indexer|object |
|
| 170 | + */ |
|
| 171 | + protected function getCoreIndexer() |
|
| 172 | + { |
|
| 173 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Index\Indexer::class, $this->storage); |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | 176 | } |
@@ -18,153 +18,153 @@ |
||
| 18 | 18 | class Rotate implements ImageOptimizerInterface |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var \TYPO3\CMS\Frontend\Imaging\GifBuilder |
|
| 23 | - */ |
|
| 24 | - protected $gifCreator; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Constructor |
|
| 28 | - */ |
|
| 29 | - public function __construct() |
|
| 30 | - { |
|
| 31 | - $this->gifCreator = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Imaging\GifBuilder::class); |
|
| 32 | - $this->gifCreator->absPrefix = Environment::getPublicPath() . '/'; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Optimize the given uploaded image |
|
| 37 | - * |
|
| 38 | - * @param \Fab\Media\FileUpload\UploadedFileInterface $uploadedFile |
|
| 39 | - * @return \Fab\Media\FileUpload\UploadedFileInterface |
|
| 40 | - */ |
|
| 41 | - public function optimize($uploadedFile) |
|
| 42 | - { |
|
| 43 | - |
|
| 44 | - $orientation = $this->getOrientation($uploadedFile->getFileWithAbsolutePath()); |
|
| 45 | - $isRotated = $this->isRotated($orientation); |
|
| 46 | - |
|
| 47 | - // Only rotate image if necessary! |
|
| 48 | - if ($isRotated > 0) { |
|
| 49 | - $transformation = $this->getTransformation($orientation); |
|
| 50 | - |
|
| 51 | - $imParams = '###SkipStripProfile###'; |
|
| 52 | - if ($transformation !== '') { |
|
| 53 | - $imParams .= ' ' . $transformation; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - $tempFileInfo = $this->gifCreator->imageMagickConvert($uploadedFile->getFileWithAbsolutePath(), '', '', '', $imParams, '', [], true); |
|
| 57 | - if ($tempFileInfo) { |
|
| 58 | - // Replace original file |
|
| 59 | - @unlink($uploadedFile->getFileWithAbsolutePath()); |
|
| 60 | - @rename($tempFileInfo[3], $uploadedFile->getFileWithAbsolutePath()); |
|
| 61 | - |
|
| 62 | - if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] === 'gm') { |
|
| 63 | - $this->resetOrientation($uploadedFile->getFileWithAbsolutePath()); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - return $uploadedFile; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Returns the EXIF orientation of a given picture. |
|
| 72 | - * |
|
| 73 | - * @param string $filename |
|
| 74 | - * @return integer |
|
| 75 | - */ |
|
| 76 | - protected function getOrientation($filename) |
|
| 77 | - { |
|
| 78 | - $extension = strtolower(substr($filename, strrpos($filename, '.') + 1)); |
|
| 79 | - $orientation = 1; // Fallback to "straight" |
|
| 80 | - if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('jpg,jpeg,tif,tiff', $extension) && function_exists('exif_read_data')) { |
|
| 81 | - try { |
|
| 82 | - $exif = exif_read_data($filename); |
|
| 83 | - if ($exif) { |
|
| 84 | - $orientation = $exif['Orientation']; |
|
| 85 | - } |
|
| 86 | - } catch (\Exception $e) {} |
|
| 87 | - } |
|
| 88 | - return $orientation; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Returns true if the given picture is rotated. |
|
| 93 | - * |
|
| 94 | - * @param integer $orientation EXIF orientation |
|
| 95 | - * @return integer |
|
| 96 | - * @see http://www.impulseadventure.com/photo/exif-orientation.html |
|
| 97 | - */ |
|
| 98 | - protected function isRotated($orientation) |
|
| 99 | - { |
|
| 100 | - $ret = false; |
|
| 101 | - switch ($orientation) { |
|
| 102 | - case 2: // horizontal flip |
|
| 103 | - case 3: // 180° |
|
| 104 | - case 4: // vertical flip |
|
| 105 | - case 5: // vertical flip + 90 rotate right |
|
| 106 | - case 6: // 90° rotate right |
|
| 107 | - case 7: // horizontal flip + 90 rotate right |
|
| 108 | - case 8: // 90° rotate left |
|
| 109 | - $ret = true; |
|
| 110 | - break; |
|
| 111 | - } |
|
| 112 | - return $ret; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Returns a command line parameter to fix the orientation of a rotated picture. |
|
| 117 | - * |
|
| 118 | - * @param integer $orientation |
|
| 119 | - * @return string |
|
| 120 | - */ |
|
| 121 | - protected function getTransformation($orientation) |
|
| 122 | - { |
|
| 123 | - $transformation = ''; |
|
| 124 | - if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] !== 'gm') { |
|
| 125 | - // ImageMagick |
|
| 126 | - if ($orientation >= 2 && $orientation <= 8) { |
|
| 127 | - $transformation = '-auto-orient'; |
|
| 128 | - } |
|
| 129 | - } else { |
|
| 130 | - // GraphicsMagick |
|
| 131 | - switch ($orientation) { |
|
| 132 | - case 2: // horizontal flip |
|
| 133 | - $transformation = '-flip horizontal'; |
|
| 134 | - break; |
|
| 135 | - case 3: // 180° |
|
| 136 | - $transformation = '-rotate 180'; |
|
| 137 | - break; |
|
| 138 | - case 4: // vertical flip |
|
| 139 | - $transformation = '-flip vertical'; |
|
| 140 | - break; |
|
| 141 | - case 5: // vertical flip + 90 rotate right |
|
| 142 | - $transformation = '-transpose'; |
|
| 143 | - break; |
|
| 144 | - case 6: // 90° rotate right |
|
| 145 | - $transformation = '-rotate 90'; |
|
| 146 | - break; |
|
| 147 | - case 7: // horizontal flip + 90 rotate right |
|
| 148 | - $transformation = '-transverse'; |
|
| 149 | - break; |
|
| 150 | - case 8: // 90° rotate left |
|
| 151 | - $transformation = '-rotate 270'; |
|
| 152 | - break; |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - return $transformation; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Resets the EXIF orientation flag of a picture. |
|
| 160 | - * |
|
| 161 | - * @param string $filename |
|
| 162 | - * @return void |
|
| 163 | - * @see http://sylvana.net/jpegcrop/exif_orientation.html |
|
| 164 | - */ |
|
| 165 | - protected function resetOrientation($filename) |
|
| 166 | - { |
|
| 167 | - JpegExifOrient::setOrientation($filename, 1); |
|
| 168 | - } |
|
| 21 | + /** |
|
| 22 | + * @var \TYPO3\CMS\Frontend\Imaging\GifBuilder |
|
| 23 | + */ |
|
| 24 | + protected $gifCreator; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Constructor |
|
| 28 | + */ |
|
| 29 | + public function __construct() |
|
| 30 | + { |
|
| 31 | + $this->gifCreator = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Imaging\GifBuilder::class); |
|
| 32 | + $this->gifCreator->absPrefix = Environment::getPublicPath() . '/'; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Optimize the given uploaded image |
|
| 37 | + * |
|
| 38 | + * @param \Fab\Media\FileUpload\UploadedFileInterface $uploadedFile |
|
| 39 | + * @return \Fab\Media\FileUpload\UploadedFileInterface |
|
| 40 | + */ |
|
| 41 | + public function optimize($uploadedFile) |
|
| 42 | + { |
|
| 43 | + |
|
| 44 | + $orientation = $this->getOrientation($uploadedFile->getFileWithAbsolutePath()); |
|
| 45 | + $isRotated = $this->isRotated($orientation); |
|
| 46 | + |
|
| 47 | + // Only rotate image if necessary! |
|
| 48 | + if ($isRotated > 0) { |
|
| 49 | + $transformation = $this->getTransformation($orientation); |
|
| 50 | + |
|
| 51 | + $imParams = '###SkipStripProfile###'; |
|
| 52 | + if ($transformation !== '') { |
|
| 53 | + $imParams .= ' ' . $transformation; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + $tempFileInfo = $this->gifCreator->imageMagickConvert($uploadedFile->getFileWithAbsolutePath(), '', '', '', $imParams, '', [], true); |
|
| 57 | + if ($tempFileInfo) { |
|
| 58 | + // Replace original file |
|
| 59 | + @unlink($uploadedFile->getFileWithAbsolutePath()); |
|
| 60 | + @rename($tempFileInfo[3], $uploadedFile->getFileWithAbsolutePath()); |
|
| 61 | + |
|
| 62 | + if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] === 'gm') { |
|
| 63 | + $this->resetOrientation($uploadedFile->getFileWithAbsolutePath()); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + return $uploadedFile; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Returns the EXIF orientation of a given picture. |
|
| 72 | + * |
|
| 73 | + * @param string $filename |
|
| 74 | + * @return integer |
|
| 75 | + */ |
|
| 76 | + protected function getOrientation($filename) |
|
| 77 | + { |
|
| 78 | + $extension = strtolower(substr($filename, strrpos($filename, '.') + 1)); |
|
| 79 | + $orientation = 1; // Fallback to "straight" |
|
| 80 | + if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('jpg,jpeg,tif,tiff', $extension) && function_exists('exif_read_data')) { |
|
| 81 | + try { |
|
| 82 | + $exif = exif_read_data($filename); |
|
| 83 | + if ($exif) { |
|
| 84 | + $orientation = $exif['Orientation']; |
|
| 85 | + } |
|
| 86 | + } catch (\Exception $e) {} |
|
| 87 | + } |
|
| 88 | + return $orientation; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Returns true if the given picture is rotated. |
|
| 93 | + * |
|
| 94 | + * @param integer $orientation EXIF orientation |
|
| 95 | + * @return integer |
|
| 96 | + * @see http://www.impulseadventure.com/photo/exif-orientation.html |
|
| 97 | + */ |
|
| 98 | + protected function isRotated($orientation) |
|
| 99 | + { |
|
| 100 | + $ret = false; |
|
| 101 | + switch ($orientation) { |
|
| 102 | + case 2: // horizontal flip |
|
| 103 | + case 3: // 180° |
|
| 104 | + case 4: // vertical flip |
|
| 105 | + case 5: // vertical flip + 90 rotate right |
|
| 106 | + case 6: // 90° rotate right |
|
| 107 | + case 7: // horizontal flip + 90 rotate right |
|
| 108 | + case 8: // 90° rotate left |
|
| 109 | + $ret = true; |
|
| 110 | + break; |
|
| 111 | + } |
|
| 112 | + return $ret; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Returns a command line parameter to fix the orientation of a rotated picture. |
|
| 117 | + * |
|
| 118 | + * @param integer $orientation |
|
| 119 | + * @return string |
|
| 120 | + */ |
|
| 121 | + protected function getTransformation($orientation) |
|
| 122 | + { |
|
| 123 | + $transformation = ''; |
|
| 124 | + if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] !== 'gm') { |
|
| 125 | + // ImageMagick |
|
| 126 | + if ($orientation >= 2 && $orientation <= 8) { |
|
| 127 | + $transformation = '-auto-orient'; |
|
| 128 | + } |
|
| 129 | + } else { |
|
| 130 | + // GraphicsMagick |
|
| 131 | + switch ($orientation) { |
|
| 132 | + case 2: // horizontal flip |
|
| 133 | + $transformation = '-flip horizontal'; |
|
| 134 | + break; |
|
| 135 | + case 3: // 180° |
|
| 136 | + $transformation = '-rotate 180'; |
|
| 137 | + break; |
|
| 138 | + case 4: // vertical flip |
|
| 139 | + $transformation = '-flip vertical'; |
|
| 140 | + break; |
|
| 141 | + case 5: // vertical flip + 90 rotate right |
|
| 142 | + $transformation = '-transpose'; |
|
| 143 | + break; |
|
| 144 | + case 6: // 90° rotate right |
|
| 145 | + $transformation = '-rotate 90'; |
|
| 146 | + break; |
|
| 147 | + case 7: // horizontal flip + 90 rotate right |
|
| 148 | + $transformation = '-transverse'; |
|
| 149 | + break; |
|
| 150 | + case 8: // 90° rotate left |
|
| 151 | + $transformation = '-rotate 270'; |
|
| 152 | + break; |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + return $transformation; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Resets the EXIF orientation flag of a picture. |
|
| 160 | + * |
|
| 161 | + * @param string $filename |
|
| 162 | + * @return void |
|
| 163 | + * @see http://sylvana.net/jpegcrop/exif_orientation.html |
|
| 164 | + */ |
|
| 165 | + protected function resetOrientation($filename) |
|
| 166 | + { |
|
| 167 | + JpegExifOrient::setOrientation($filename, 1); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | 170 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | public function __construct() |
| 30 | 30 | { |
| 31 | 31 | $this->gifCreator = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Imaging\GifBuilder::class); |
| 32 | - $this->gifCreator->absPrefix = Environment::getPublicPath() . '/'; |
|
| 32 | + $this->gifCreator->absPrefix = Environment::getPublicPath().'/'; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | $imParams = '###SkipStripProfile###'; |
| 52 | 52 | if ($transformation !== '') { |
| 53 | - $imParams .= ' ' . $transformation; |
|
| 53 | + $imParams .= ' '.$transformation; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | $tempFileInfo = $this->gifCreator->imageMagickConvert($uploadedFile->getFileWithAbsolutePath(), '', '', '', $imParams, '', [], true); |
@@ -19,116 +19,116 @@ |
||
| 19 | 19 | class Resize implements ImageOptimizerInterface |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var \TYPO3\CMS\Frontend\Imaging\GifBuilder |
|
| 24 | - */ |
|
| 25 | - protected $gifCreator; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var \TYPO3\CMS\Core\Resource\ResourceStorage |
|
| 29 | - */ |
|
| 30 | - protected $storage; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Constructor |
|
| 34 | - */ |
|
| 35 | - public function __construct($storage = null) |
|
| 36 | - { |
|
| 37 | - $this->storage = $storage; |
|
| 38 | - $this->gifCreator = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Imaging\GifBuilder::class); |
|
| 39 | - $this->gifCreator->absPrefix = Environment::getPublicPath() . '/'; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Optimize the given uploaded image. |
|
| 44 | - * |
|
| 45 | - * @param \Fab\Media\FileUpload\UploadedFileInterface $uploadedFile |
|
| 46 | - * @return \Fab\Media\FileUpload\UploadedFileInterface |
|
| 47 | - */ |
|
| 48 | - public function optimize($uploadedFile) |
|
| 49 | - { |
|
| 50 | - |
|
| 51 | - $imageInfo = getimagesize($uploadedFile->getFileWithAbsolutePath()); |
|
| 52 | - |
|
| 53 | - $currentWidth = $imageInfo[0]; |
|
| 54 | - $currentHeight = $imageInfo[1]; |
|
| 55 | - |
|
| 56 | - // resize an image if this one is bigger than telling by the settings. |
|
| 57 | - if (is_object($this->storage)) { |
|
| 58 | - $storageRecord = $this->storage->getStorageRecord(); |
|
| 59 | - } else { |
|
| 60 | - // Will only work in the BE for now. |
|
| 61 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 62 | - $storageRecord = $storage->getStorageRecord(); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - if (strlen($storageRecord['maximum_dimension_original_image']) > 0) { |
|
| 66 | - |
|
| 67 | - /** @var \Fab\Media\Dimension $imageDimension */ |
|
| 68 | - $imageDimension = GeneralUtility::makeInstance(\Fab\Media\Dimension::class, $storageRecord['maximum_dimension_original_image']); |
|
| 69 | - if ($currentWidth > $imageDimension->getWidth() || $currentHeight > $imageDimension->getHeight()) { |
|
| 70 | - |
|
| 71 | - // resize taking the width as reference |
|
| 72 | - $this->resize($uploadedFile->getFileWithAbsolutePath(), $imageDimension->getWidth(), $imageDimension->getHeight()); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - return $uploadedFile; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Resize an image according to given parameter. |
|
| 80 | - * |
|
| 81 | - * @throws \Exception |
|
| 82 | - * @param string $fileNameAndPath |
|
| 83 | - * @param int $width |
|
| 84 | - * @param int $height |
|
| 85 | - * @return void |
|
| 86 | - */ |
|
| 87 | - public function resize($fileNameAndPath, $width = 0, $height = 0) |
|
| 88 | - { |
|
| 89 | - |
|
| 90 | - // Skip profile of the image |
|
| 91 | - $imParams = '###SkipStripProfile###'; |
|
| 92 | - $options = array( |
|
| 93 | - 'maxW' => $width, |
|
| 94 | - 'maxH' => $height, |
|
| 95 | - ); |
|
| 96 | - |
|
| 97 | - $tempFileInfo = $this->gifCreator->imageMagickConvert($fileNameAndPath, '', '', '', $imParams, '', $options, true); |
|
| 98 | - if ($tempFileInfo) { |
|
| 99 | - |
|
| 100 | - // Overwrite original file |
|
| 101 | - @unlink($fileNameAndPath); |
|
| 102 | - @rename($tempFileInfo[3], $fileNameAndPath); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Escapes a file name so it can safely be used on the command line. |
|
| 108 | - * |
|
| 109 | - * @see \TYPO3\CMS\Core\Imaging\GraphicalFunctions |
|
| 110 | - * @param string $inputName filename to safeguard, must not be empty |
|
| 111 | - * @return string $inputName escaped as needed |
|
| 112 | - */ |
|
| 113 | - protected function wrapFileName($inputName) |
|
| 114 | - { |
|
| 115 | - if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) { |
|
| 116 | - $currentLocale = setlocale(LC_CTYPE, 0); |
|
| 117 | - setlocale(LC_CTYPE, $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale']); |
|
| 118 | - } |
|
| 119 | - $escapedInputName = escapeshellarg($inputName); |
|
| 120 | - if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) { |
|
| 121 | - setlocale(LC_CTYPE, $currentLocale); |
|
| 122 | - } |
|
| 123 | - return $escapedInputName; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @return MediaModule|object |
|
| 128 | - */ |
|
| 129 | - protected function getMediaModule() |
|
| 130 | - { |
|
| 131 | - return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
| 132 | - } |
|
| 22 | + /** |
|
| 23 | + * @var \TYPO3\CMS\Frontend\Imaging\GifBuilder |
|
| 24 | + */ |
|
| 25 | + protected $gifCreator; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var \TYPO3\CMS\Core\Resource\ResourceStorage |
|
| 29 | + */ |
|
| 30 | + protected $storage; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Constructor |
|
| 34 | + */ |
|
| 35 | + public function __construct($storage = null) |
|
| 36 | + { |
|
| 37 | + $this->storage = $storage; |
|
| 38 | + $this->gifCreator = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Imaging\GifBuilder::class); |
|
| 39 | + $this->gifCreator->absPrefix = Environment::getPublicPath() . '/'; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Optimize the given uploaded image. |
|
| 44 | + * |
|
| 45 | + * @param \Fab\Media\FileUpload\UploadedFileInterface $uploadedFile |
|
| 46 | + * @return \Fab\Media\FileUpload\UploadedFileInterface |
|
| 47 | + */ |
|
| 48 | + public function optimize($uploadedFile) |
|
| 49 | + { |
|
| 50 | + |
|
| 51 | + $imageInfo = getimagesize($uploadedFile->getFileWithAbsolutePath()); |
|
| 52 | + |
|
| 53 | + $currentWidth = $imageInfo[0]; |
|
| 54 | + $currentHeight = $imageInfo[1]; |
|
| 55 | + |
|
| 56 | + // resize an image if this one is bigger than telling by the settings. |
|
| 57 | + if (is_object($this->storage)) { |
|
| 58 | + $storageRecord = $this->storage->getStorageRecord(); |
|
| 59 | + } else { |
|
| 60 | + // Will only work in the BE for now. |
|
| 61 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 62 | + $storageRecord = $storage->getStorageRecord(); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + if (strlen($storageRecord['maximum_dimension_original_image']) > 0) { |
|
| 66 | + |
|
| 67 | + /** @var \Fab\Media\Dimension $imageDimension */ |
|
| 68 | + $imageDimension = GeneralUtility::makeInstance(\Fab\Media\Dimension::class, $storageRecord['maximum_dimension_original_image']); |
|
| 69 | + if ($currentWidth > $imageDimension->getWidth() || $currentHeight > $imageDimension->getHeight()) { |
|
| 70 | + |
|
| 71 | + // resize taking the width as reference |
|
| 72 | + $this->resize($uploadedFile->getFileWithAbsolutePath(), $imageDimension->getWidth(), $imageDimension->getHeight()); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + return $uploadedFile; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Resize an image according to given parameter. |
|
| 80 | + * |
|
| 81 | + * @throws \Exception |
|
| 82 | + * @param string $fileNameAndPath |
|
| 83 | + * @param int $width |
|
| 84 | + * @param int $height |
|
| 85 | + * @return void |
|
| 86 | + */ |
|
| 87 | + public function resize($fileNameAndPath, $width = 0, $height = 0) |
|
| 88 | + { |
|
| 89 | + |
|
| 90 | + // Skip profile of the image |
|
| 91 | + $imParams = '###SkipStripProfile###'; |
|
| 92 | + $options = array( |
|
| 93 | + 'maxW' => $width, |
|
| 94 | + 'maxH' => $height, |
|
| 95 | + ); |
|
| 96 | + |
|
| 97 | + $tempFileInfo = $this->gifCreator->imageMagickConvert($fileNameAndPath, '', '', '', $imParams, '', $options, true); |
|
| 98 | + if ($tempFileInfo) { |
|
| 99 | + |
|
| 100 | + // Overwrite original file |
|
| 101 | + @unlink($fileNameAndPath); |
|
| 102 | + @rename($tempFileInfo[3], $fileNameAndPath); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Escapes a file name so it can safely be used on the command line. |
|
| 108 | + * |
|
| 109 | + * @see \TYPO3\CMS\Core\Imaging\GraphicalFunctions |
|
| 110 | + * @param string $inputName filename to safeguard, must not be empty |
|
| 111 | + * @return string $inputName escaped as needed |
|
| 112 | + */ |
|
| 113 | + protected function wrapFileName($inputName) |
|
| 114 | + { |
|
| 115 | + if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) { |
|
| 116 | + $currentLocale = setlocale(LC_CTYPE, 0); |
|
| 117 | + setlocale(LC_CTYPE, $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale']); |
|
| 118 | + } |
|
| 119 | + $escapedInputName = escapeshellarg($inputName); |
|
| 120 | + if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) { |
|
| 121 | + setlocale(LC_CTYPE, $currentLocale); |
|
| 122 | + } |
|
| 123 | + return $escapedInputName; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @return MediaModule|object |
|
| 128 | + */ |
|
| 129 | + protected function getMediaModule() |
|
| 130 | + { |
|
| 131 | + return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | 134 | } |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | { |
| 37 | 37 | $this->storage = $storage; |
| 38 | 38 | $this->gifCreator = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Imaging\GifBuilder::class); |
| 39 | - $this->gifCreator->absPrefix = Environment::getPublicPath() . '/'; |
|
| 39 | + $this->gifCreator->absPrefix = Environment::getPublicPath().'/'; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |