@@ -66,8 +66,7 @@ discard block |
||
| 66 | 66 | $selected, |
| 67 | 67 | $storage->getName(), |
| 68 | 68 | $storage->isOnline() ? |
| 69 | - '' : |
|
| 70 | - '(' . $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:offline') . ')' |
|
| 69 | + '' : '('.$this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:offline').')' |
|
| 71 | 70 | ); |
| 72 | 71 | } |
| 73 | 72 | |
@@ -75,7 +74,7 @@ discard block |
||
| 75 | 74 | $inputs = ''; |
| 76 | 75 | foreach ($parameters as $parameter => $value) { |
| 77 | 76 | list($parameter, $value) = $this->computeParameterAndValue($parameter, $value); |
| 78 | - if ($parameter !== $this->getModuleLoader()->getParameterPrefix() . '[storage]') { |
|
| 77 | + if ($parameter !== $this->getModuleLoader()->getParameterPrefix().'[storage]') { |
|
| 79 | 78 | $inputs .= sprintf('<input type="hidden" name="%s" value="%s" />', $parameter, $value); |
| 80 | 79 | } |
| 81 | 80 | } |
@@ -19,117 +19,117 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class StorageMenu extends AbstractComponentView |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * Renders a dropdown menu for storage. |
|
| 24 | - * |
|
| 25 | - * @return string |
|
| 26 | - */ |
|
| 27 | - public function render() |
|
| 28 | - { |
|
| 29 | - $output = ''; |
|
| 30 | - if ($this->isDisplayed()) { |
|
| 31 | - $this->loadRequireJsCode(); |
|
| 32 | - |
|
| 33 | - $output = $this->renderStorageMenu(); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - return $output; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - protected function isDisplayed() |
|
| 43 | - { |
|
| 44 | - $isDisplayed = !$this->getMediaModule()->hasFolderTree() || $this->getModuleLoader()->hasPlugin(); |
|
| 45 | - return $isDisplayed; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - protected function renderStorageMenu() |
|
| 52 | - { |
|
| 53 | - $currentStorage = $this->getMediaModule()->getCurrentStorage(); |
|
| 54 | - |
|
| 55 | - /** @var $storage \TYPO3\CMS\Core\Resource\ResourceStorage */ |
|
| 56 | - $options = ''; |
|
| 57 | - foreach ($this->getMediaModule()->getAllowedStorages() as $storage) { |
|
| 58 | - $selected = ''; |
|
| 59 | - if ($currentStorage->getUid() == $storage->getUid()) { |
|
| 60 | - $selected = 'selected'; |
|
| 61 | - } |
|
| 62 | - $options .= sprintf( |
|
| 63 | - '<option value="%s" %s>%s %s</option>', |
|
| 64 | - $storage->getUid(), |
|
| 65 | - $selected, |
|
| 66 | - $storage->getName(), |
|
| 67 | - $storage->isOnline() ? |
|
| 68 | - '' : |
|
| 69 | - '(' . $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:offline') . ')' |
|
| 70 | - ); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - $parameters = GeneralUtility::_GET(); |
|
| 74 | - $inputs = ''; |
|
| 75 | - foreach ($parameters as $parameter => $value) { |
|
| 76 | - list($parameter, $value) = $this->computeParameterAndValue($parameter, $value); |
|
| 77 | - if ($parameter !== $this->getModuleLoader()->getParameterPrefix() . '[storage]') { |
|
| 78 | - $inputs .= sprintf('<input type="hidden" name="%s" value="%s" />', $parameter, $value); |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - $template = '<form action="%s" id="form-menu-storage" method="get"> |
|
| 22 | + /** |
|
| 23 | + * Renders a dropdown menu for storage. |
|
| 24 | + * |
|
| 25 | + * @return string |
|
| 26 | + */ |
|
| 27 | + public function render() |
|
| 28 | + { |
|
| 29 | + $output = ''; |
|
| 30 | + if ($this->isDisplayed()) { |
|
| 31 | + $this->loadRequireJsCode(); |
|
| 32 | + |
|
| 33 | + $output = $this->renderStorageMenu(); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + return $output; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + protected function isDisplayed() |
|
| 43 | + { |
|
| 44 | + $isDisplayed = !$this->getMediaModule()->hasFolderTree() || $this->getModuleLoader()->hasPlugin(); |
|
| 45 | + return $isDisplayed; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + protected function renderStorageMenu() |
|
| 52 | + { |
|
| 53 | + $currentStorage = $this->getMediaModule()->getCurrentStorage(); |
|
| 54 | + |
|
| 55 | + /** @var $storage \TYPO3\CMS\Core\Resource\ResourceStorage */ |
|
| 56 | + $options = ''; |
|
| 57 | + foreach ($this->getMediaModule()->getAllowedStorages() as $storage) { |
|
| 58 | + $selected = ''; |
|
| 59 | + if ($currentStorage->getUid() == $storage->getUid()) { |
|
| 60 | + $selected = 'selected'; |
|
| 61 | + } |
|
| 62 | + $options .= sprintf( |
|
| 63 | + '<option value="%s" %s>%s %s</option>', |
|
| 64 | + $storage->getUid(), |
|
| 65 | + $selected, |
|
| 66 | + $storage->getName(), |
|
| 67 | + $storage->isOnline() ? |
|
| 68 | + '' : |
|
| 69 | + '(' . $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:offline') . ')' |
|
| 70 | + ); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + $parameters = GeneralUtility::_GET(); |
|
| 74 | + $inputs = ''; |
|
| 75 | + foreach ($parameters as $parameter => $value) { |
|
| 76 | + list($parameter, $value) = $this->computeParameterAndValue($parameter, $value); |
|
| 77 | + if ($parameter !== $this->getModuleLoader()->getParameterPrefix() . '[storage]') { |
|
| 78 | + $inputs .= sprintf('<input type="hidden" name="%s" value="%s" />', $parameter, $value); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + $template = '<form action="%s" id="form-menu-storage" method="get"> |
|
| 83 | 83 | %s |
| 84 | 84 | <select name="%s[storage]" class="form-control" style="padding-right: 20px" id="menu-storage" onchange="$(\'#form-menu-storage\').submit()">%s</select> |
| 85 | 85 | </form>'; |
| 86 | 86 | |
| 87 | - return sprintf( |
|
| 88 | - $template, |
|
| 89 | - $this->getModuleLoader()->getModuleUrl(), |
|
| 90 | - $inputs, |
|
| 91 | - $this->getModuleLoader()->getParameterPrefix(), |
|
| 92 | - $options |
|
| 93 | - ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @return void |
|
| 98 | - */ |
|
| 99 | - protected function loadRequireJsCode() |
|
| 100 | - { |
|
| 101 | - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
| 102 | - |
|
| 103 | - $configuration['paths']['Fab/Media'] = '../typo3conf/ext/media/Resources/Public/JavaScript'; |
|
| 104 | - $pageRenderer->addRequireJsConfiguration($configuration); |
|
| 105 | - $pageRenderer->loadRequireJsModule('Fab/Media/EditStorage'); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Compute parameter and value to be correctly encoded by the browser. |
|
| 110 | - * |
|
| 111 | - * @param string $parameter |
|
| 112 | - * @param mixed $value |
|
| 113 | - * @return array |
|
| 114 | - */ |
|
| 115 | - protected function computeParameterAndValue($parameter, $value) |
|
| 116 | - { |
|
| 117 | - if (is_string($value)) { |
|
| 118 | - $result = array($parameter, $value); |
|
| 119 | - } else { |
|
| 120 | - $key = key($value); |
|
| 121 | - $value = current($value); |
|
| 122 | - $parameter = sprintf('%s[%s]', $parameter, $key); |
|
| 123 | - $result = $this->computeParameterAndValue($parameter, $value); |
|
| 124 | - } |
|
| 125 | - return $result; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @return MediaModule|object |
|
| 130 | - */ |
|
| 131 | - protected function getMediaModule() |
|
| 132 | - { |
|
| 133 | - return GeneralUtility::makeInstance(MediaModule::class); |
|
| 134 | - } |
|
| 87 | + return sprintf( |
|
| 88 | + $template, |
|
| 89 | + $this->getModuleLoader()->getModuleUrl(), |
|
| 90 | + $inputs, |
|
| 91 | + $this->getModuleLoader()->getParameterPrefix(), |
|
| 92 | + $options |
|
| 93 | + ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @return void |
|
| 98 | + */ |
|
| 99 | + protected function loadRequireJsCode() |
|
| 100 | + { |
|
| 101 | + $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
| 102 | + |
|
| 103 | + $configuration['paths']['Fab/Media'] = '../typo3conf/ext/media/Resources/Public/JavaScript'; |
|
| 104 | + $pageRenderer->addRequireJsConfiguration($configuration); |
|
| 105 | + $pageRenderer->loadRequireJsModule('Fab/Media/EditStorage'); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Compute parameter and value to be correctly encoded by the browser. |
|
| 110 | + * |
|
| 111 | + * @param string $parameter |
|
| 112 | + * @param mixed $value |
|
| 113 | + * @return array |
|
| 114 | + */ |
|
| 115 | + protected function computeParameterAndValue($parameter, $value) |
|
| 116 | + { |
|
| 117 | + if (is_string($value)) { |
|
| 118 | + $result = array($parameter, $value); |
|
| 119 | + } else { |
|
| 120 | + $key = key($value); |
|
| 121 | + $value = current($value); |
|
| 122 | + $parameter = sprintf('%s[%s]', $parameter, $key); |
|
| 123 | + $result = $this->computeParameterAndValue($parameter, $value); |
|
| 124 | + } |
|
| 125 | + return $result; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @return MediaModule|object |
|
| 130 | + */ |
|
| 131 | + protected function getMediaModule() |
|
| 132 | + { |
|
| 133 | + return GeneralUtility::makeInstance(MediaModule::class); |
|
| 134 | + } |
|
| 135 | 135 | } |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | { |
| 42 | 42 | $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/MissingFilesFinder/Launcher.html'; |
| 43 | 43 | $view = $this->initializeStandaloneView($templateNameAndPath); |
| 44 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
| 44 | + $view->assign('sitePath', Environment::getPublicPath().'/'); |
|
| 45 | 45 | return $view->render(); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -22,128 +22,128 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class MissingFilesFinderTool extends AbstractTool |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * Display the title of the tool on the welcome screen. |
|
| 27 | - * |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - public function getTitle() |
|
| 31 | - { |
|
| 32 | - return 'Find missing files'; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Display the description of the tool in the welcome screen. |
|
| 37 | - * |
|
| 38 | - * @return string |
|
| 39 | - */ |
|
| 40 | - public function getDescription() |
|
| 41 | - { |
|
| 42 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/MissingFilesFinder/Launcher.html'; |
|
| 43 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 44 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
| 45 | - return $view->render(); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Do the job: analyse Index. |
|
| 50 | - * |
|
| 51 | - * @param array $arguments |
|
| 52 | - * @return string |
|
| 53 | - */ |
|
| 54 | - public function work(array $arguments = []) |
|
| 55 | - { |
|
| 56 | - // Possible clean up of missing files if the User has clicked so. |
|
| 57 | - if (!empty($arguments['deleteMissingFiles'])) { |
|
| 58 | - $this->deleteMissingFilesAction($arguments['files']); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/MissingFilesFinder/WorkResult.html'; |
|
| 62 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 63 | - |
|
| 64 | - $missingReports = []; |
|
| 65 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
| 66 | - if ($storage->isOnline()) { |
|
| 67 | - $missingFiles = $this->getIndexAnalyser()->searchForMissingFiles($storage); |
|
| 68 | - |
|
| 69 | - $missingReports[] = array( |
|
| 70 | - 'storage' => $storage, |
|
| 71 | - 'missingFiles' => $missingFiles, |
|
| 72 | - 'numberOfMissingFiles' => count($missingFiles), |
|
| 73 | - ); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $view->assign('missingReports', $missingReports); |
|
| 78 | - |
|
| 79 | - return $view->render(); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Delete files given as parameter. |
|
| 84 | - * This is a special case as we have a missing file in the file system |
|
| 85 | - * As a result, we can't use $fileObject->delete(); which will |
|
| 86 | - * raise exception "Error while fetching permissions". |
|
| 87 | - * |
|
| 88 | - * @param array $files |
|
| 89 | - * @return void |
|
| 90 | - */ |
|
| 91 | - protected function deleteMissingFilesAction(array $files = []) |
|
| 92 | - { |
|
| 93 | - foreach ($files as $fileUid) { |
|
| 94 | - /** @var File $file */ |
|
| 95 | - try { |
|
| 96 | - $file = $this->getResourceFactory()->getFileObject($fileUid); |
|
| 97 | - if ($file) { |
|
| 98 | - // The case is special as we have a missing file in the file system |
|
| 99 | - // As a result, we can't use $fileObject->delete(); which will |
|
| 100 | - // raise exception "Error while fetching permissions" |
|
| 101 | - $this->getDataService()->delete('sys_file', ['uid' => $file->getUid()]); |
|
| 102 | - } |
|
| 103 | - } catch (\Exception $e) { |
|
| 104 | - continue; |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Return a pointer to the database. |
|
| 111 | - * |
|
| 112 | - * @return IndexAnalyser|object |
|
| 113 | - */ |
|
| 114 | - protected function getIndexAnalyser() |
|
| 115 | - { |
|
| 116 | - return GeneralUtility::makeInstance(IndexAnalyser::class); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @return StorageRepository|object |
|
| 121 | - */ |
|
| 122 | - protected function getStorageRepository() |
|
| 123 | - { |
|
| 124 | - return GeneralUtility::makeInstance(StorageRepository::class); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Tell whether the tools should be displayed according to the context. |
|
| 129 | - * |
|
| 130 | - * @return bool |
|
| 131 | - */ |
|
| 132 | - public function isShown() |
|
| 133 | - { |
|
| 134 | - return $this->getBackendUser()->isAdmin(); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @return object|DataService |
|
| 139 | - */ |
|
| 140 | - protected function getDataService(): DataService |
|
| 141 | - { |
|
| 142 | - return GeneralUtility::makeInstance(DataService::class); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - protected function getResourceFactory(): ResourceFactory |
|
| 146 | - { |
|
| 147 | - return GeneralUtility::makeInstance(ResourceFactory::class); |
|
| 148 | - } |
|
| 25 | + /** |
|
| 26 | + * Display the title of the tool on the welcome screen. |
|
| 27 | + * |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + public function getTitle() |
|
| 31 | + { |
|
| 32 | + return 'Find missing files'; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Display the description of the tool in the welcome screen. |
|
| 37 | + * |
|
| 38 | + * @return string |
|
| 39 | + */ |
|
| 40 | + public function getDescription() |
|
| 41 | + { |
|
| 42 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/MissingFilesFinder/Launcher.html'; |
|
| 43 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 44 | + $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
| 45 | + return $view->render(); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Do the job: analyse Index. |
|
| 50 | + * |
|
| 51 | + * @param array $arguments |
|
| 52 | + * @return string |
|
| 53 | + */ |
|
| 54 | + public function work(array $arguments = []) |
|
| 55 | + { |
|
| 56 | + // Possible clean up of missing files if the User has clicked so. |
|
| 57 | + if (!empty($arguments['deleteMissingFiles'])) { |
|
| 58 | + $this->deleteMissingFilesAction($arguments['files']); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/MissingFilesFinder/WorkResult.html'; |
|
| 62 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 63 | + |
|
| 64 | + $missingReports = []; |
|
| 65 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
| 66 | + if ($storage->isOnline()) { |
|
| 67 | + $missingFiles = $this->getIndexAnalyser()->searchForMissingFiles($storage); |
|
| 68 | + |
|
| 69 | + $missingReports[] = array( |
|
| 70 | + 'storage' => $storage, |
|
| 71 | + 'missingFiles' => $missingFiles, |
|
| 72 | + 'numberOfMissingFiles' => count($missingFiles), |
|
| 73 | + ); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $view->assign('missingReports', $missingReports); |
|
| 78 | + |
|
| 79 | + return $view->render(); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Delete files given as parameter. |
|
| 84 | + * This is a special case as we have a missing file in the file system |
|
| 85 | + * As a result, we can't use $fileObject->delete(); which will |
|
| 86 | + * raise exception "Error while fetching permissions". |
|
| 87 | + * |
|
| 88 | + * @param array $files |
|
| 89 | + * @return void |
|
| 90 | + */ |
|
| 91 | + protected function deleteMissingFilesAction(array $files = []) |
|
| 92 | + { |
|
| 93 | + foreach ($files as $fileUid) { |
|
| 94 | + /** @var File $file */ |
|
| 95 | + try { |
|
| 96 | + $file = $this->getResourceFactory()->getFileObject($fileUid); |
|
| 97 | + if ($file) { |
|
| 98 | + // The case is special as we have a missing file in the file system |
|
| 99 | + // As a result, we can't use $fileObject->delete(); which will |
|
| 100 | + // raise exception "Error while fetching permissions" |
|
| 101 | + $this->getDataService()->delete('sys_file', ['uid' => $file->getUid()]); |
|
| 102 | + } |
|
| 103 | + } catch (\Exception $e) { |
|
| 104 | + continue; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Return a pointer to the database. |
|
| 111 | + * |
|
| 112 | + * @return IndexAnalyser|object |
|
| 113 | + */ |
|
| 114 | + protected function getIndexAnalyser() |
|
| 115 | + { |
|
| 116 | + return GeneralUtility::makeInstance(IndexAnalyser::class); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @return StorageRepository|object |
|
| 121 | + */ |
|
| 122 | + protected function getStorageRepository() |
|
| 123 | + { |
|
| 124 | + return GeneralUtility::makeInstance(StorageRepository::class); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Tell whether the tools should be displayed according to the context. |
|
| 129 | + * |
|
| 130 | + * @return bool |
|
| 131 | + */ |
|
| 132 | + public function isShown() |
|
| 133 | + { |
|
| 134 | + return $this->getBackendUser()->isAdmin(); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @return object|DataService |
|
| 139 | + */ |
|
| 140 | + protected function getDataService(): DataService |
|
| 141 | + { |
|
| 142 | + return GeneralUtility::makeInstance(DataService::class); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + protected function getResourceFactory(): ResourceFactory |
|
| 146 | + { |
|
| 147 | + return GeneralUtility::makeInstance(ResourceFactory::class); |
|
| 148 | + } |
|
| 149 | 149 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | { |
| 38 | 38 | $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/CacheWarmUp/Launcher.html'; |
| 39 | 39 | $view = $this->initializeStandaloneView($templateNameAndPath); |
| 40 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
| 40 | + $view->assign('sitePath', Environment::getPublicPath().'/'); |
|
| 41 | 41 | return $view->render(); |
| 42 | 42 | } |
| 43 | 43 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | protected function getWarmUpSemaphorFile() |
| 77 | 77 | { |
| 78 | - return Environment::getPublicPath() . '/typo3temp/.media_cache_warmed_up'; |
|
| 78 | + return Environment::getPublicPath().'/typo3temp/.media_cache_warmed_up'; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -18,70 +18,70 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class CacheWarmUpTool extends AbstractTool |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Display the title of the tool on the welcome screen. |
|
| 23 | - * |
|
| 24 | - * @return string |
|
| 25 | - */ |
|
| 26 | - public function getTitle() |
|
| 27 | - { |
|
| 28 | - return 'Cache warm up'; |
|
| 29 | - } |
|
| 21 | + /** |
|
| 22 | + * Display the title of the tool on the welcome screen. |
|
| 23 | + * |
|
| 24 | + * @return string |
|
| 25 | + */ |
|
| 26 | + public function getTitle() |
|
| 27 | + { |
|
| 28 | + return 'Cache warm up'; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Display the description of the tool in the welcome screen. |
|
| 33 | - * |
|
| 34 | - * @return string |
|
| 35 | - */ |
|
| 36 | - public function getDescription() |
|
| 37 | - { |
|
| 38 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/CacheWarmUp/Launcher.html'; |
|
| 39 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 40 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
| 41 | - return $view->render(); |
|
| 42 | - } |
|
| 31 | + /** |
|
| 32 | + * Display the description of the tool in the welcome screen. |
|
| 33 | + * |
|
| 34 | + * @return string |
|
| 35 | + */ |
|
| 36 | + public function getDescription() |
|
| 37 | + { |
|
| 38 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/CacheWarmUp/Launcher.html'; |
|
| 39 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 40 | + $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
| 41 | + return $view->render(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Do the job: warm up the cache. |
|
| 46 | - * |
|
| 47 | - * @param array $arguments |
|
| 48 | - * @return string |
|
| 49 | - */ |
|
| 50 | - public function work(array $arguments = []) |
|
| 51 | - { |
|
| 52 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/CacheWarmUp/WorkResult.html'; |
|
| 53 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 44 | + /** |
|
| 45 | + * Do the job: warm up the cache. |
|
| 46 | + * |
|
| 47 | + * @param array $arguments |
|
| 48 | + * @return string |
|
| 49 | + */ |
|
| 50 | + public function work(array $arguments = []) |
|
| 51 | + { |
|
| 52 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/CacheWarmUp/WorkResult.html'; |
|
| 53 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 54 | 54 | |
| 55 | - $numberOfEntries = $this->getCacheService()->warmUp(); |
|
| 56 | - $view->assign('numberOfEntries', $numberOfEntries); |
|
| 57 | - touch($this->getWarmUpSemaphorFile()); |
|
| 55 | + $numberOfEntries = $this->getCacheService()->warmUp(); |
|
| 56 | + $view->assign('numberOfEntries', $numberOfEntries); |
|
| 57 | + touch($this->getWarmUpSemaphorFile()); |
|
| 58 | 58 | |
| 59 | - return $view->render(); |
|
| 60 | - } |
|
| 59 | + return $view->render(); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Tell whether the tools should be displayed according to the context. |
|
| 64 | - * |
|
| 65 | - * @return bool |
|
| 66 | - */ |
|
| 67 | - public function isShown() |
|
| 68 | - { |
|
| 69 | - return $this->getBackendUser()->isAdmin(); |
|
| 70 | - } |
|
| 62 | + /** |
|
| 63 | + * Tell whether the tools should be displayed according to the context. |
|
| 64 | + * |
|
| 65 | + * @return bool |
|
| 66 | + */ |
|
| 67 | + public function isShown() |
|
| 68 | + { |
|
| 69 | + return $this->getBackendUser()->isAdmin(); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @return string |
|
| 74 | - */ |
|
| 75 | - protected function getWarmUpSemaphorFile() |
|
| 76 | - { |
|
| 77 | - return Environment::getPublicPath() . '/typo3temp/.media_cache_warmed_up'; |
|
| 78 | - } |
|
| 72 | + /** |
|
| 73 | + * @return string |
|
| 74 | + */ |
|
| 75 | + protected function getWarmUpSemaphorFile() |
|
| 76 | + { |
|
| 77 | + return Environment::getPublicPath() . '/typo3temp/.media_cache_warmed_up'; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @return CacheService|object |
|
| 82 | - */ |
|
| 83 | - protected function getCacheService() |
|
| 84 | - { |
|
| 85 | - return GeneralUtility::makeInstance(CacheService::class); |
|
| 86 | - } |
|
| 80 | + /** |
|
| 81 | + * @return CacheService|object |
|
| 82 | + */ |
|
| 83 | + protected function getCacheService() |
|
| 84 | + { |
|
| 85 | + return GeneralUtility::makeInstance(CacheService::class); |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -39,7 +39,7 @@ |
||
| 39 | 39 | { |
| 40 | 40 | $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateRecordsFinder/Launcher.html'; |
| 41 | 41 | $view = $this->initializeStandaloneView($templateNameAndPath); |
| 42 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
| 42 | + $view->assign('sitePath', Environment::getPublicPath().'/'); |
|
| 43 | 43 | return $view->render(); |
| 44 | 44 | } |
| 45 | 45 | |
@@ -19,82 +19,82 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class DuplicateRecordsFinderTool extends AbstractTool |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * Display the title of the tool on the welcome screen. |
|
| 24 | - * |
|
| 25 | - * @return string |
|
| 26 | - */ |
|
| 27 | - public function getTitle() |
|
| 28 | - { |
|
| 29 | - return 'Find duplicate Records'; |
|
| 30 | - } |
|
| 22 | + /** |
|
| 23 | + * Display the title of the tool on the welcome screen. |
|
| 24 | + * |
|
| 25 | + * @return string |
|
| 26 | + */ |
|
| 27 | + public function getTitle() |
|
| 28 | + { |
|
| 29 | + return 'Find duplicate Records'; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Display the description of the tool in the welcome screen. |
|
| 34 | - * |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function getDescription() |
|
| 38 | - { |
|
| 39 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateRecordsFinder/Launcher.html'; |
|
| 40 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 41 | - $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
| 42 | - return $view->render(); |
|
| 43 | - } |
|
| 32 | + /** |
|
| 33 | + * Display the description of the tool in the welcome screen. |
|
| 34 | + * |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function getDescription() |
|
| 38 | + { |
|
| 39 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateRecordsFinder/Launcher.html'; |
|
| 40 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 41 | + $view->assign('sitePath', Environment::getPublicPath() . '/'); |
|
| 42 | + return $view->render(); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Do the job: analyse Index. |
|
| 47 | - * |
|
| 48 | - * @param array $arguments |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - public function work(array $arguments = []) |
|
| 52 | - { |
|
| 53 | - $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateRecordsFinder/WorkResult.html'; |
|
| 54 | - $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 45 | + /** |
|
| 46 | + * Do the job: analyse Index. |
|
| 47 | + * |
|
| 48 | + * @param array $arguments |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + public function work(array $arguments = []) |
|
| 52 | + { |
|
| 53 | + $templateNameAndPath = 'EXT:media/Resources/Private/Standalone/Tool/DuplicateRecordsFinder/WorkResult.html'; |
|
| 54 | + $view = $this->initializeStandaloneView($templateNameAndPath); |
|
| 55 | 55 | |
| 56 | - $duplicateRecordsReports = []; |
|
| 57 | - foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
| 58 | - if ($storage->isOnline()) { |
|
| 59 | - $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateIdentifiers($storage); |
|
| 60 | - $duplicateRecordsReports[] = array( |
|
| 61 | - 'storage' => $storage, |
|
| 62 | - 'duplicateFiles' => $duplicateFiles, |
|
| 63 | - 'numberOfDuplicateFiles' => count($duplicateFiles), |
|
| 64 | - ); |
|
| 65 | - } |
|
| 66 | - } |
|
| 56 | + $duplicateRecordsReports = []; |
|
| 57 | + foreach ($this->getStorageRepository()->findAll() as $storage) { |
|
| 58 | + if ($storage->isOnline()) { |
|
| 59 | + $duplicateFiles = $this->getIndexAnalyser()->searchForDuplicateIdentifiers($storage); |
|
| 60 | + $duplicateRecordsReports[] = array( |
|
| 61 | + 'storage' => $storage, |
|
| 62 | + 'duplicateFiles' => $duplicateFiles, |
|
| 63 | + 'numberOfDuplicateFiles' => count($duplicateFiles), |
|
| 64 | + ); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - $view->assign('duplicateRecordsReports', $duplicateRecordsReports); |
|
| 68 | + $view->assign('duplicateRecordsReports', $duplicateRecordsReports); |
|
| 69 | 69 | |
| 70 | - return $view->render(); |
|
| 71 | - } |
|
| 70 | + return $view->render(); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Return a pointer to the database. |
|
| 75 | - * |
|
| 76 | - * @return IndexAnalyser|object |
|
| 77 | - */ |
|
| 78 | - protected function getIndexAnalyser() |
|
| 79 | - { |
|
| 80 | - return GeneralUtility::makeInstance(IndexAnalyser::class); |
|
| 81 | - } |
|
| 73 | + /** |
|
| 74 | + * Return a pointer to the database. |
|
| 75 | + * |
|
| 76 | + * @return IndexAnalyser|object |
|
| 77 | + */ |
|
| 78 | + protected function getIndexAnalyser() |
|
| 79 | + { |
|
| 80 | + return GeneralUtility::makeInstance(IndexAnalyser::class); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * @return StorageRepository|object |
|
| 85 | - */ |
|
| 86 | - protected function getStorageRepository() |
|
| 87 | - { |
|
| 88 | - return GeneralUtility::makeInstance(StorageRepository::class); |
|
| 89 | - } |
|
| 83 | + /** |
|
| 84 | + * @return StorageRepository|object |
|
| 85 | + */ |
|
| 86 | + protected function getStorageRepository() |
|
| 87 | + { |
|
| 88 | + return GeneralUtility::makeInstance(StorageRepository::class); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Tell whether the tools should be displayed according to the context. |
|
| 93 | - * |
|
| 94 | - * @return bool |
|
| 95 | - */ |
|
| 96 | - public function isShown() |
|
| 97 | - { |
|
| 98 | - return $this->getBackendUser()->isAdmin(); |
|
| 99 | - } |
|
| 91 | + /** |
|
| 92 | + * Tell whether the tools should be displayed according to the context. |
|
| 93 | + * |
|
| 94 | + * @return bool |
|
| 95 | + */ |
|
| 96 | + public function isShown() |
|
| 97 | + { |
|
| 98 | + return $this->getBackendUser()->isAdmin(); |
|
| 99 | + } |
|
| 100 | 100 | } |
@@ -129,8 +129,8 @@ discard block |
||
| 129 | 129 | $uploadSize = $this->toBytes(ini_get('upload_max_filesize')); |
| 130 | 130 | |
| 131 | 131 | if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit) { |
| 132 | - $size = max(1, $this->sizeLimit / 1024 / 1024) . 'M'; |
|
| 133 | - $this->throwException('increase post_max_size and upload_max_filesize to ' . $size); |
|
| 132 | + $size = max(1, $this->sizeLimit / 1024 / 1024).'M'; |
|
| 133 | + $this->throwException('increase post_max_size and upload_max_filesize to '.$size); |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | $isAllowed = $this->checkFileExtensionPermission($fileName); |
| 199 | 199 | if (!$isAllowed) { |
| 200 | 200 | $these = PermissionUtility::getInstance()->getAllowedExtensionList(); |
| 201 | - $this->throwException('File has an invalid extension, it should be one of ' . $these . '.'); |
|
| 201 | + $this->throwException('File has an invalid extension, it should be one of '.$these.'.'); |
|
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | */ |
| 257 | 257 | public function sanitizeFileName($fileName, $slug = '-', $extra = null) |
| 258 | 258 | { |
| 259 | - return trim(preg_replace('~[^0-9a-z_' . preg_quote($extra, '~') . ']+~i', $slug, $this->unAccent($fileName)), $slug); |
|
| 259 | + return trim(preg_replace('~[^0-9a-z_'.preg_quote($extra, '~').']+~i', $slug, $this->unAccent($fileName)), $slug); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | */ |
| 295 | 295 | protected function initializeUploadFolder() |
| 296 | 296 | { |
| 297 | - $this->uploadFolder = Environment::getPublicPath() . '/' . self::UPLOAD_FOLDER; |
|
| 297 | + $this->uploadFolder = Environment::getPublicPath().'/'.self::UPLOAD_FOLDER; |
|
| 298 | 298 | |
| 299 | 299 | // Initialize the upload folder for file transfer and create it if not yet existing |
| 300 | 300 | if (!file_exists($this->uploadFolder)) { |
@@ -24,358 +24,358 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class UploadManager |
| 26 | 26 | { |
| 27 | - public const UPLOAD_FOLDER = 'typo3temp/pics'; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var int|null|string |
|
| 31 | - */ |
|
| 32 | - protected $sizeLimit; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 37 | - protected $uploadFolder; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var FormUtility |
|
| 41 | - */ |
|
| 42 | - protected $formUtility; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var ResourceStorage |
|
| 46 | - */ |
|
| 47 | - protected $storage; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Name of the file input in the DOM. |
|
| 51 | - * |
|
| 52 | - * @var string |
|
| 53 | - */ |
|
| 54 | - protected $inputName = 'qqfile'; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @param ResourceStorage $storage |
|
| 58 | - * @return UploadManager |
|
| 59 | - */ |
|
| 60 | - public function __construct($storage = null) |
|
| 61 | - { |
|
| 62 | - $this->initializeUploadFolder(); |
|
| 63 | - |
|
| 64 | - // max file size in bytes |
|
| 65 | - $this->sizeLimit = GeneralUtility::getMaxUploadFileSize() * 1024; |
|
| 66 | - $this->checkServerSettings(); |
|
| 67 | - |
|
| 68 | - $this->formUtility = FormUtility::getInstance(); |
|
| 69 | - $this->storage = $storage; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Handle the uploaded file. |
|
| 74 | - * |
|
| 75 | - * @return UploadedFileInterface |
|
| 76 | - */ |
|
| 77 | - public function handleUpload() |
|
| 78 | - { |
|
| 79 | - /** @var $uploadedFile UploadedFileInterface */ |
|
| 80 | - $uploadedFile = false; |
|
| 81 | - if ($this->formUtility->isMultiparted()) { |
|
| 82 | - // Default case |
|
| 83 | - $uploadedFile = GeneralUtility::makeInstance(MultipartedFile::class); |
|
| 84 | - } elseif ($this->formUtility->isOctetStreamed()) { |
|
| 85 | - // Fine Upload plugin would use it if forceEncoded = false and paramsInBody = false |
|
| 86 | - $uploadedFile = GeneralUtility::makeInstance(StreamedFile::class); |
|
| 87 | - } elseif ($this->formUtility->isUrlEncoded()) { |
|
| 88 | - // Used for image resizing in BE |
|
| 89 | - $uploadedFile = GeneralUtility::makeInstance(Base64File::class); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - if (!$uploadedFile) { |
|
| 93 | - $this->throwException('Could not instantiate an upload object... No file was uploaded?'); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $fileName = $this->getFileName($uploadedFile); |
|
| 97 | - |
|
| 98 | - $this->checkFileSize($uploadedFile->getSize()); |
|
| 99 | - $this->checkFileAllowed($fileName); |
|
| 100 | - |
|
| 101 | - $saved = $uploadedFile->setInputName($this->inputName) |
|
| 102 | - ->setUploadFolder($this->uploadFolder) |
|
| 103 | - ->setName($fileName) |
|
| 104 | - ->save(); |
|
| 105 | - |
|
| 106 | - if (!$saved) { |
|
| 107 | - $this->throwException('Could not save uploaded file. The upload was cancelled, or server error encountered'); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - // Optimize file if the uploaded file is an image. |
|
| 111 | - if ($uploadedFile->getType() == File::FILETYPE_IMAGE) { |
|
| 112 | - $uploadedFile = ImageOptimizer::getInstance($this->storage)->optimize($uploadedFile); |
|
| 113 | - } |
|
| 114 | - return $uploadedFile; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Internal function that checks if server's may sizes match the |
|
| 119 | - * object's maximum size for uploads. |
|
| 120 | - * |
|
| 121 | - * @return void |
|
| 122 | - */ |
|
| 123 | - protected function checkServerSettings() |
|
| 124 | - { |
|
| 125 | - $postSize = $this->toBytes(ini_get('post_max_size')); |
|
| 126 | - |
|
| 127 | - $uploadSize = $this->toBytes(ini_get('upload_max_filesize')); |
|
| 128 | - |
|
| 129 | - if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit) { |
|
| 130 | - $size = max(1, $this->sizeLimit / 1024 / 1024) . 'M'; |
|
| 131 | - $this->throwException('increase post_max_size and upload_max_filesize to ' . $size); |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Convert a given size with units to bytes. |
|
| 137 | - * |
|
| 138 | - * @param string $str |
|
| 139 | - * @return int|string |
|
| 140 | - */ |
|
| 141 | - protected function toBytes($str) |
|
| 142 | - { |
|
| 143 | - $val = trim($str); |
|
| 144 | - $last = strtolower($str[strlen($str) - 1]); |
|
| 145 | - switch ($last) { |
|
| 146 | - case 'g': |
|
| 147 | - $val *= 1024; |
|
| 148 | - // no break |
|
| 149 | - case 'm': |
|
| 150 | - $val *= 1024; |
|
| 151 | - // no break |
|
| 152 | - case 'k': |
|
| 153 | - $val *= 1024; |
|
| 154 | - } |
|
| 155 | - return $val; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Return a file name given an uploaded file |
|
| 160 | - * |
|
| 161 | - * @param UploadedFileInterface $uploadedFile |
|
| 162 | - * @return string |
|
| 163 | - */ |
|
| 164 | - public function getFileName(UploadedFileInterface $uploadedFile) |
|
| 165 | - { |
|
| 166 | - $pathInfo = pathinfo($uploadedFile->getOriginalName()); |
|
| 167 | - $fileName = $this->sanitizeFileName($pathInfo['filename']); |
|
| 168 | - $fileNameWithExtension = $fileName; |
|
| 169 | - if (!empty($pathInfo['extension'])) { |
|
| 170 | - $fileNameWithExtension = sprintf('%s.%s', $fileName, $pathInfo['extension']); |
|
| 171 | - } |
|
| 172 | - return $fileNameWithExtension; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Check whether the file size does not exceed the allowed limit |
|
| 177 | - * |
|
| 178 | - * @param int $size |
|
| 179 | - */ |
|
| 180 | - public function checkFileSize($size) |
|
| 181 | - { |
|
| 182 | - if ($size == 0) { |
|
| 183 | - $this->throwException('File is empty'); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - if ($size > $this->sizeLimit) { |
|
| 187 | - $this->throwException('File is too large'); |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Check whether the file is allowed |
|
| 193 | - * |
|
| 194 | - * @param string $fileName |
|
| 195 | - */ |
|
| 196 | - public function checkFileAllowed($fileName) |
|
| 197 | - { |
|
| 198 | - $isAllowed = $this->checkFileExtensionPermission($fileName); |
|
| 199 | - if (!$isAllowed) { |
|
| 200 | - $these = PermissionUtility::getInstance()->getAllowedExtensionList(); |
|
| 201 | - $this->throwException('File has an invalid extension, it should be one of ' . $these . '.'); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * If the fileName is given, check it against the |
|
| 207 | - * TYPO3_CONF_VARS[BE][fileDenyPattern] + and if the file extension is allowed |
|
| 208 | - * |
|
| 209 | - * @see \TYPO3\CMS\Core\Resource\ResourceStorage->checkFileExtensionPermission($fileName); |
|
| 210 | - * @param string $fileName Full filename |
|
| 211 | - * @return boolean true if extension/filename is allowed |
|
| 212 | - */ |
|
| 213 | - public function checkFileExtensionPermission($fileName) |
|
| 214 | - { |
|
| 215 | - $isAllowed = GeneralUtility::makeInstance(FileNameValidator::class)->isValid($fileName); |
|
| 216 | - if ($isAllowed) { |
|
| 217 | - $fileInfo = GeneralUtility::split_fileref($fileName); |
|
| 218 | - // Set up the permissions for the file extension |
|
| 219 | - $fileExtensionPermissions = $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']['webspace']; |
|
| 220 | - $fileExtensionPermissions['allow'] = StringUtility::uniqueList(strtolower($fileExtensionPermissions['allow'])); |
|
| 221 | - $fileExtensionPermissions['deny'] = StringUtility::uniqueList(strtolower($fileExtensionPermissions['deny'])); |
|
| 222 | - $fileExtension = strtolower($fileInfo['fileext']); |
|
| 223 | - if ($fileExtension !== '') { |
|
| 224 | - // If the extension is found amongst the allowed types, we return true immediately |
|
| 225 | - if ($fileExtensionPermissions['allow'] === '*' || GeneralUtility::inList($fileExtensionPermissions['allow'], $fileExtension)) { |
|
| 226 | - return true; |
|
| 227 | - } |
|
| 228 | - // If the extension is found amongst the denied types, we return false immediately |
|
| 229 | - if ($fileExtensionPermissions['deny'] === '*' || GeneralUtility::inList($fileExtensionPermissions['deny'], $fileExtension)) { |
|
| 230 | - return false; |
|
| 231 | - } |
|
| 232 | - // If no match we return true |
|
| 233 | - return true; |
|
| 234 | - } else { |
|
| 235 | - if ($fileExtensionPermissions['allow'] === '*') { |
|
| 236 | - return true; |
|
| 237 | - } |
|
| 238 | - if ($fileExtensionPermissions['deny'] === '*') { |
|
| 239 | - return false; |
|
| 240 | - } |
|
| 241 | - return true; |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - return false; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Sanitize the file name for the web. |
|
| 249 | - * It has been noticed issues when letting done this work by FAL. Give it a little hand. |
|
| 250 | - * |
|
| 251 | - * @see https://github.com/alixaxel/phunction/blob/master/phunction/Text.php#L252 |
|
| 252 | - * @param string $fileName |
|
| 253 | - * @param string $slug |
|
| 254 | - * @param string $extra |
|
| 255 | - * @return string |
|
| 256 | - */ |
|
| 257 | - public function sanitizeFileName($fileName, $slug = '-', $extra = null) |
|
| 258 | - { |
|
| 259 | - return trim(preg_replace('~[^0-9a-z_' . preg_quote($extra, '~') . ']+~i', $slug, $this->unAccent($fileName)), $slug); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Remove accent from a string |
|
| 264 | - * |
|
| 265 | - * @see https://github.com/alixaxel/phunction/blob/master/phunction/Text.php#L297 |
|
| 266 | - * @param $string |
|
| 267 | - * @return string |
|
| 268 | - */ |
|
| 269 | - protected function unAccent($string) |
|
| 270 | - { |
|
| 271 | - $searches = array('ç', 'æ', 'œ', 'á', 'é', 'í', 'ó', 'ú', 'à', 'è', 'ì', 'ò', 'ù', 'ä', 'ë', 'ï', 'ö', 'ü', 'ÿ', 'â', 'ê', 'î', 'ô', 'û', 'å', 'e', 'i', 'ø', 'u'); |
|
| 272 | - $replaces = array('c', 'ae', 'oe', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u', 'y', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u'); |
|
| 273 | - $sanitizedString = str_replace($searches, $replaces, $string); |
|
| 274 | - |
|
| 275 | - if (extension_loaded('intl') === true) { |
|
| 276 | - $sanitizedString = \Normalizer::normalize($sanitizedString, \Normalizer::FORM_KD); |
|
| 277 | - } |
|
| 278 | - return $sanitizedString; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * @throws FailedFileUploadException |
|
| 283 | - * @param string $message |
|
| 284 | - */ |
|
| 285 | - protected function throwException($message) |
|
| 286 | - { |
|
| 287 | - throw new FailedFileUploadException($message, 1357510420); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Initialize Upload Folder. |
|
| 292 | - * |
|
| 293 | - * @return void |
|
| 294 | - */ |
|
| 295 | - protected function initializeUploadFolder() |
|
| 296 | - { |
|
| 297 | - $this->uploadFolder = Environment::getPublicPath() . '/' . self::UPLOAD_FOLDER; |
|
| 298 | - |
|
| 299 | - // Initialize the upload folder for file transfer and create it if not yet existing |
|
| 300 | - if (!file_exists($this->uploadFolder)) { |
|
| 301 | - GeneralUtility::mkdir($this->uploadFolder); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - // Check whether the upload folder is writable |
|
| 305 | - if (!is_writable($this->uploadFolder)) { |
|
| 306 | - $this->throwException("Server error. Upload directory isn't writable."); |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * @return int|null|string |
|
| 312 | - */ |
|
| 313 | - public function getSizeLimit() |
|
| 314 | - { |
|
| 315 | - return $this->sizeLimit; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * @param int|null|string $sizeLimit |
|
| 320 | - * @return $this |
|
| 321 | - */ |
|
| 322 | - public function setSizeLimit($sizeLimit) |
|
| 323 | - { |
|
| 324 | - $this->sizeLimit = $sizeLimit; |
|
| 325 | - return $this; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * @return string |
|
| 330 | - */ |
|
| 331 | - public function getUploadFolder() |
|
| 332 | - { |
|
| 333 | - return $this->uploadFolder; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * @param string $uploadFolder |
|
| 338 | - * @return $this |
|
| 339 | - */ |
|
| 340 | - public function setUploadFolder($uploadFolder) |
|
| 341 | - { |
|
| 342 | - $this->uploadFolder = $uploadFolder; |
|
| 343 | - return $this; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * @return string |
|
| 348 | - */ |
|
| 349 | - public function getInputName() |
|
| 350 | - { |
|
| 351 | - return $this->inputName; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * @param string $inputName |
|
| 356 | - * @return $this |
|
| 357 | - */ |
|
| 358 | - public function setInputName($inputName) |
|
| 359 | - { |
|
| 360 | - $this->inputName = $inputName; |
|
| 361 | - return $this; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * @return ResourceStorage |
|
| 366 | - */ |
|
| 367 | - public function getStorage() |
|
| 368 | - { |
|
| 369 | - return $this->storage; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * @param ResourceStorage $storage |
|
| 374 | - * @return $this |
|
| 375 | - */ |
|
| 376 | - public function setStorage($storage) |
|
| 377 | - { |
|
| 378 | - $this->storage = $storage; |
|
| 379 | - return $this; |
|
| 380 | - } |
|
| 27 | + public const UPLOAD_FOLDER = 'typo3temp/pics'; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var int|null|string |
|
| 31 | + */ |
|
| 32 | + protected $sizeLimit; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | + protected $uploadFolder; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var FormUtility |
|
| 41 | + */ |
|
| 42 | + protected $formUtility; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var ResourceStorage |
|
| 46 | + */ |
|
| 47 | + protected $storage; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Name of the file input in the DOM. |
|
| 51 | + * |
|
| 52 | + * @var string |
|
| 53 | + */ |
|
| 54 | + protected $inputName = 'qqfile'; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @param ResourceStorage $storage |
|
| 58 | + * @return UploadManager |
|
| 59 | + */ |
|
| 60 | + public function __construct($storage = null) |
|
| 61 | + { |
|
| 62 | + $this->initializeUploadFolder(); |
|
| 63 | + |
|
| 64 | + // max file size in bytes |
|
| 65 | + $this->sizeLimit = GeneralUtility::getMaxUploadFileSize() * 1024; |
|
| 66 | + $this->checkServerSettings(); |
|
| 67 | + |
|
| 68 | + $this->formUtility = FormUtility::getInstance(); |
|
| 69 | + $this->storage = $storage; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Handle the uploaded file. |
|
| 74 | + * |
|
| 75 | + * @return UploadedFileInterface |
|
| 76 | + */ |
|
| 77 | + public function handleUpload() |
|
| 78 | + { |
|
| 79 | + /** @var $uploadedFile UploadedFileInterface */ |
|
| 80 | + $uploadedFile = false; |
|
| 81 | + if ($this->formUtility->isMultiparted()) { |
|
| 82 | + // Default case |
|
| 83 | + $uploadedFile = GeneralUtility::makeInstance(MultipartedFile::class); |
|
| 84 | + } elseif ($this->formUtility->isOctetStreamed()) { |
|
| 85 | + // Fine Upload plugin would use it if forceEncoded = false and paramsInBody = false |
|
| 86 | + $uploadedFile = GeneralUtility::makeInstance(StreamedFile::class); |
|
| 87 | + } elseif ($this->formUtility->isUrlEncoded()) { |
|
| 88 | + // Used for image resizing in BE |
|
| 89 | + $uploadedFile = GeneralUtility::makeInstance(Base64File::class); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + if (!$uploadedFile) { |
|
| 93 | + $this->throwException('Could not instantiate an upload object... No file was uploaded?'); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $fileName = $this->getFileName($uploadedFile); |
|
| 97 | + |
|
| 98 | + $this->checkFileSize($uploadedFile->getSize()); |
|
| 99 | + $this->checkFileAllowed($fileName); |
|
| 100 | + |
|
| 101 | + $saved = $uploadedFile->setInputName($this->inputName) |
|
| 102 | + ->setUploadFolder($this->uploadFolder) |
|
| 103 | + ->setName($fileName) |
|
| 104 | + ->save(); |
|
| 105 | + |
|
| 106 | + if (!$saved) { |
|
| 107 | + $this->throwException('Could not save uploaded file. The upload was cancelled, or server error encountered'); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + // Optimize file if the uploaded file is an image. |
|
| 111 | + if ($uploadedFile->getType() == File::FILETYPE_IMAGE) { |
|
| 112 | + $uploadedFile = ImageOptimizer::getInstance($this->storage)->optimize($uploadedFile); |
|
| 113 | + } |
|
| 114 | + return $uploadedFile; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Internal function that checks if server's may sizes match the |
|
| 119 | + * object's maximum size for uploads. |
|
| 120 | + * |
|
| 121 | + * @return void |
|
| 122 | + */ |
|
| 123 | + protected function checkServerSettings() |
|
| 124 | + { |
|
| 125 | + $postSize = $this->toBytes(ini_get('post_max_size')); |
|
| 126 | + |
|
| 127 | + $uploadSize = $this->toBytes(ini_get('upload_max_filesize')); |
|
| 128 | + |
|
| 129 | + if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit) { |
|
| 130 | + $size = max(1, $this->sizeLimit / 1024 / 1024) . 'M'; |
|
| 131 | + $this->throwException('increase post_max_size and upload_max_filesize to ' . $size); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Convert a given size with units to bytes. |
|
| 137 | + * |
|
| 138 | + * @param string $str |
|
| 139 | + * @return int|string |
|
| 140 | + */ |
|
| 141 | + protected function toBytes($str) |
|
| 142 | + { |
|
| 143 | + $val = trim($str); |
|
| 144 | + $last = strtolower($str[strlen($str) - 1]); |
|
| 145 | + switch ($last) { |
|
| 146 | + case 'g': |
|
| 147 | + $val *= 1024; |
|
| 148 | + // no break |
|
| 149 | + case 'm': |
|
| 150 | + $val *= 1024; |
|
| 151 | + // no break |
|
| 152 | + case 'k': |
|
| 153 | + $val *= 1024; |
|
| 154 | + } |
|
| 155 | + return $val; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Return a file name given an uploaded file |
|
| 160 | + * |
|
| 161 | + * @param UploadedFileInterface $uploadedFile |
|
| 162 | + * @return string |
|
| 163 | + */ |
|
| 164 | + public function getFileName(UploadedFileInterface $uploadedFile) |
|
| 165 | + { |
|
| 166 | + $pathInfo = pathinfo($uploadedFile->getOriginalName()); |
|
| 167 | + $fileName = $this->sanitizeFileName($pathInfo['filename']); |
|
| 168 | + $fileNameWithExtension = $fileName; |
|
| 169 | + if (!empty($pathInfo['extension'])) { |
|
| 170 | + $fileNameWithExtension = sprintf('%s.%s', $fileName, $pathInfo['extension']); |
|
| 171 | + } |
|
| 172 | + return $fileNameWithExtension; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Check whether the file size does not exceed the allowed limit |
|
| 177 | + * |
|
| 178 | + * @param int $size |
|
| 179 | + */ |
|
| 180 | + public function checkFileSize($size) |
|
| 181 | + { |
|
| 182 | + if ($size == 0) { |
|
| 183 | + $this->throwException('File is empty'); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + if ($size > $this->sizeLimit) { |
|
| 187 | + $this->throwException('File is too large'); |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Check whether the file is allowed |
|
| 193 | + * |
|
| 194 | + * @param string $fileName |
|
| 195 | + */ |
|
| 196 | + public function checkFileAllowed($fileName) |
|
| 197 | + { |
|
| 198 | + $isAllowed = $this->checkFileExtensionPermission($fileName); |
|
| 199 | + if (!$isAllowed) { |
|
| 200 | + $these = PermissionUtility::getInstance()->getAllowedExtensionList(); |
|
| 201 | + $this->throwException('File has an invalid extension, it should be one of ' . $these . '.'); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * If the fileName is given, check it against the |
|
| 207 | + * TYPO3_CONF_VARS[BE][fileDenyPattern] + and if the file extension is allowed |
|
| 208 | + * |
|
| 209 | + * @see \TYPO3\CMS\Core\Resource\ResourceStorage->checkFileExtensionPermission($fileName); |
|
| 210 | + * @param string $fileName Full filename |
|
| 211 | + * @return boolean true if extension/filename is allowed |
|
| 212 | + */ |
|
| 213 | + public function checkFileExtensionPermission($fileName) |
|
| 214 | + { |
|
| 215 | + $isAllowed = GeneralUtility::makeInstance(FileNameValidator::class)->isValid($fileName); |
|
| 216 | + if ($isAllowed) { |
|
| 217 | + $fileInfo = GeneralUtility::split_fileref($fileName); |
|
| 218 | + // Set up the permissions for the file extension |
|
| 219 | + $fileExtensionPermissions = $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']['webspace']; |
|
| 220 | + $fileExtensionPermissions['allow'] = StringUtility::uniqueList(strtolower($fileExtensionPermissions['allow'])); |
|
| 221 | + $fileExtensionPermissions['deny'] = StringUtility::uniqueList(strtolower($fileExtensionPermissions['deny'])); |
|
| 222 | + $fileExtension = strtolower($fileInfo['fileext']); |
|
| 223 | + if ($fileExtension !== '') { |
|
| 224 | + // If the extension is found amongst the allowed types, we return true immediately |
|
| 225 | + if ($fileExtensionPermissions['allow'] === '*' || GeneralUtility::inList($fileExtensionPermissions['allow'], $fileExtension)) { |
|
| 226 | + return true; |
|
| 227 | + } |
|
| 228 | + // If the extension is found amongst the denied types, we return false immediately |
|
| 229 | + if ($fileExtensionPermissions['deny'] === '*' || GeneralUtility::inList($fileExtensionPermissions['deny'], $fileExtension)) { |
|
| 230 | + return false; |
|
| 231 | + } |
|
| 232 | + // If no match we return true |
|
| 233 | + return true; |
|
| 234 | + } else { |
|
| 235 | + if ($fileExtensionPermissions['allow'] === '*') { |
|
| 236 | + return true; |
|
| 237 | + } |
|
| 238 | + if ($fileExtensionPermissions['deny'] === '*') { |
|
| 239 | + return false; |
|
| 240 | + } |
|
| 241 | + return true; |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + return false; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Sanitize the file name for the web. |
|
| 249 | + * It has been noticed issues when letting done this work by FAL. Give it a little hand. |
|
| 250 | + * |
|
| 251 | + * @see https://github.com/alixaxel/phunction/blob/master/phunction/Text.php#L252 |
|
| 252 | + * @param string $fileName |
|
| 253 | + * @param string $slug |
|
| 254 | + * @param string $extra |
|
| 255 | + * @return string |
|
| 256 | + */ |
|
| 257 | + public function sanitizeFileName($fileName, $slug = '-', $extra = null) |
|
| 258 | + { |
|
| 259 | + return trim(preg_replace('~[^0-9a-z_' . preg_quote($extra, '~') . ']+~i', $slug, $this->unAccent($fileName)), $slug); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Remove accent from a string |
|
| 264 | + * |
|
| 265 | + * @see https://github.com/alixaxel/phunction/blob/master/phunction/Text.php#L297 |
|
| 266 | + * @param $string |
|
| 267 | + * @return string |
|
| 268 | + */ |
|
| 269 | + protected function unAccent($string) |
|
| 270 | + { |
|
| 271 | + $searches = array('ç', 'æ', 'œ', 'á', 'é', 'í', 'ó', 'ú', 'à', 'è', 'ì', 'ò', 'ù', 'ä', 'ë', 'ï', 'ö', 'ü', 'ÿ', 'â', 'ê', 'î', 'ô', 'û', 'å', 'e', 'i', 'ø', 'u'); |
|
| 272 | + $replaces = array('c', 'ae', 'oe', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u', 'y', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u'); |
|
| 273 | + $sanitizedString = str_replace($searches, $replaces, $string); |
|
| 274 | + |
|
| 275 | + if (extension_loaded('intl') === true) { |
|
| 276 | + $sanitizedString = \Normalizer::normalize($sanitizedString, \Normalizer::FORM_KD); |
|
| 277 | + } |
|
| 278 | + return $sanitizedString; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * @throws FailedFileUploadException |
|
| 283 | + * @param string $message |
|
| 284 | + */ |
|
| 285 | + protected function throwException($message) |
|
| 286 | + { |
|
| 287 | + throw new FailedFileUploadException($message, 1357510420); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Initialize Upload Folder. |
|
| 292 | + * |
|
| 293 | + * @return void |
|
| 294 | + */ |
|
| 295 | + protected function initializeUploadFolder() |
|
| 296 | + { |
|
| 297 | + $this->uploadFolder = Environment::getPublicPath() . '/' . self::UPLOAD_FOLDER; |
|
| 298 | + |
|
| 299 | + // Initialize the upload folder for file transfer and create it if not yet existing |
|
| 300 | + if (!file_exists($this->uploadFolder)) { |
|
| 301 | + GeneralUtility::mkdir($this->uploadFolder); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + // Check whether the upload folder is writable |
|
| 305 | + if (!is_writable($this->uploadFolder)) { |
|
| 306 | + $this->throwException("Server error. Upload directory isn't writable."); |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * @return int|null|string |
|
| 312 | + */ |
|
| 313 | + public function getSizeLimit() |
|
| 314 | + { |
|
| 315 | + return $this->sizeLimit; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * @param int|null|string $sizeLimit |
|
| 320 | + * @return $this |
|
| 321 | + */ |
|
| 322 | + public function setSizeLimit($sizeLimit) |
|
| 323 | + { |
|
| 324 | + $this->sizeLimit = $sizeLimit; |
|
| 325 | + return $this; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * @return string |
|
| 330 | + */ |
|
| 331 | + public function getUploadFolder() |
|
| 332 | + { |
|
| 333 | + return $this->uploadFolder; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * @param string $uploadFolder |
|
| 338 | + * @return $this |
|
| 339 | + */ |
|
| 340 | + public function setUploadFolder($uploadFolder) |
|
| 341 | + { |
|
| 342 | + $this->uploadFolder = $uploadFolder; |
|
| 343 | + return $this; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * @return string |
|
| 348 | + */ |
|
| 349 | + public function getInputName() |
|
| 350 | + { |
|
| 351 | + return $this->inputName; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * @param string $inputName |
|
| 356 | + * @return $this |
|
| 357 | + */ |
|
| 358 | + public function setInputName($inputName) |
|
| 359 | + { |
|
| 360 | + $this->inputName = $inputName; |
|
| 361 | + return $this; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * @return ResourceStorage |
|
| 366 | + */ |
|
| 367 | + public function getStorage() |
|
| 368 | + { |
|
| 369 | + return $this->storage; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * @param ResourceStorage $storage |
|
| 374 | + * @return $this |
|
| 375 | + */ |
|
| 376 | + public function setStorage($storage) |
|
| 377 | + { |
|
| 378 | + $this->storage = $storage; |
|
| 379 | + return $this; |
|
| 380 | + } |
|
| 381 | 381 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | public function getFileWithAbsolutePath() |
| 80 | 80 | { |
| 81 | - return $this->uploadFolder . DIRECTORY_SEPARATOR . $this->name; |
|
| 81 | + return $this->uploadFolder.DIRECTORY_SEPARATOR.$this->name; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | public function getPublicUrl() |
| 90 | 90 | { |
| 91 | - $fileNameAndPath = str_replace(Environment::getPublicPath() . '/', '', $this->getFileWithAbsolutePath()); |
|
| 92 | - return '/' . ltrim($fileNameAndPath, '/'); |
|
| 91 | + $fileNameAndPath = str_replace(Environment::getPublicPath().'/', '', $this->getFileWithAbsolutePath()); |
|
| 92 | + return '/'.ltrim($fileNameAndPath, '/'); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -18,141 +18,141 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | abstract class UploadedFileAbstract implements UploadedFileInterface |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $uploadFolder; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - protected $inputName; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - protected $name; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Get the file type. |
|
| 38 | - * |
|
| 39 | - * @return int |
|
| 40 | - */ |
|
| 41 | - public function getType() |
|
| 42 | - { |
|
| 43 | - $this->checkFileExistence(); |
|
| 44 | - |
|
| 45 | - // this basically extracts the mimetype and guess the filetype based |
|
| 46 | - // on the first part of the mimetype works for 99% of all cases, and |
|
| 47 | - // we don't need to make an SQL statement like EXT:media does currently |
|
| 48 | - $mimeType = $this->getMimeType(); |
|
| 49 | - list($fileType) = explode('/', $mimeType); |
|
| 50 | - switch (strtolower($fileType)) { |
|
| 51 | - case 'text': |
|
| 52 | - $type = File::FILETYPE_TEXT; |
|
| 53 | - break; |
|
| 54 | - case 'image': |
|
| 55 | - $type = File::FILETYPE_IMAGE; |
|
| 56 | - break; |
|
| 57 | - case 'audio': |
|
| 58 | - $type = File::FILETYPE_AUDIO; |
|
| 59 | - break; |
|
| 60 | - case 'video': |
|
| 61 | - $type = File::FILETYPE_VIDEO; |
|
| 62 | - break; |
|
| 63 | - case 'application': |
|
| 64 | - case 'software': |
|
| 65 | - $type = File::FILETYPE_APPLICATION; |
|
| 66 | - break; |
|
| 67 | - default: |
|
| 68 | - $type = File::FILETYPE_UNKNOWN; |
|
| 69 | - } |
|
| 70 | - return $type; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Get the file with its absolute path. |
|
| 75 | - * |
|
| 76 | - * @return string |
|
| 77 | - */ |
|
| 78 | - public function getFileWithAbsolutePath() |
|
| 79 | - { |
|
| 80 | - return $this->uploadFolder . DIRECTORY_SEPARATOR . $this->name; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Get the file's public URL. |
|
| 85 | - * |
|
| 86 | - * @return string |
|
| 87 | - */ |
|
| 88 | - public function getPublicUrl() |
|
| 89 | - { |
|
| 90 | - $fileNameAndPath = str_replace(Environment::getPublicPath() . '/', '', $this->getFileWithAbsolutePath()); |
|
| 91 | - return '/' . ltrim($fileNameAndPath, '/'); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @return string |
|
| 96 | - */ |
|
| 97 | - public function getInputName() |
|
| 98 | - { |
|
| 99 | - return $this->inputName; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param string $inputName |
|
| 104 | - * @return UploadedFileInterface |
|
| 105 | - */ |
|
| 106 | - public function setInputName($inputName) |
|
| 107 | - { |
|
| 108 | - $this->inputName = $inputName; |
|
| 109 | - return $this; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @return string |
|
| 114 | - */ |
|
| 115 | - public function getUploadFolder() |
|
| 116 | - { |
|
| 117 | - return $this->uploadFolder; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @param string $uploadFolder |
|
| 122 | - * @return UploadedFileInterface |
|
| 123 | - */ |
|
| 124 | - public function setUploadFolder($uploadFolder) |
|
| 125 | - { |
|
| 126 | - $this->uploadFolder = $uploadFolder; |
|
| 127 | - return $this; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @return string |
|
| 132 | - */ |
|
| 133 | - public function getName() |
|
| 134 | - { |
|
| 135 | - return $this->name; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @param string $name |
|
| 140 | - * @return UploadedFileInterface |
|
| 141 | - */ |
|
| 142 | - public function setName($name) |
|
| 143 | - { |
|
| 144 | - $this->name = $name; |
|
| 145 | - return $this; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Check whether the file exists. |
|
| 150 | - */ |
|
| 151 | - protected function checkFileExistence() |
|
| 152 | - { |
|
| 153 | - if (!is_file($this->getFileWithAbsolutePath())) { |
|
| 154 | - $message = sprintf('File not found at "%s". Did you save it?', $this->getFileWithAbsolutePath()); |
|
| 155 | - throw new MissingFileException($message, 1361786958); |
|
| 156 | - } |
|
| 157 | - } |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $uploadFolder; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + protected $inputName; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + protected $name; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Get the file type. |
|
| 38 | + * |
|
| 39 | + * @return int |
|
| 40 | + */ |
|
| 41 | + public function getType() |
|
| 42 | + { |
|
| 43 | + $this->checkFileExistence(); |
|
| 44 | + |
|
| 45 | + // this basically extracts the mimetype and guess the filetype based |
|
| 46 | + // on the first part of the mimetype works for 99% of all cases, and |
|
| 47 | + // we don't need to make an SQL statement like EXT:media does currently |
|
| 48 | + $mimeType = $this->getMimeType(); |
|
| 49 | + list($fileType) = explode('/', $mimeType); |
|
| 50 | + switch (strtolower($fileType)) { |
|
| 51 | + case 'text': |
|
| 52 | + $type = File::FILETYPE_TEXT; |
|
| 53 | + break; |
|
| 54 | + case 'image': |
|
| 55 | + $type = File::FILETYPE_IMAGE; |
|
| 56 | + break; |
|
| 57 | + case 'audio': |
|
| 58 | + $type = File::FILETYPE_AUDIO; |
|
| 59 | + break; |
|
| 60 | + case 'video': |
|
| 61 | + $type = File::FILETYPE_VIDEO; |
|
| 62 | + break; |
|
| 63 | + case 'application': |
|
| 64 | + case 'software': |
|
| 65 | + $type = File::FILETYPE_APPLICATION; |
|
| 66 | + break; |
|
| 67 | + default: |
|
| 68 | + $type = File::FILETYPE_UNKNOWN; |
|
| 69 | + } |
|
| 70 | + return $type; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Get the file with its absolute path. |
|
| 75 | + * |
|
| 76 | + * @return string |
|
| 77 | + */ |
|
| 78 | + public function getFileWithAbsolutePath() |
|
| 79 | + { |
|
| 80 | + return $this->uploadFolder . DIRECTORY_SEPARATOR . $this->name; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Get the file's public URL. |
|
| 85 | + * |
|
| 86 | + * @return string |
|
| 87 | + */ |
|
| 88 | + public function getPublicUrl() |
|
| 89 | + { |
|
| 90 | + $fileNameAndPath = str_replace(Environment::getPublicPath() . '/', '', $this->getFileWithAbsolutePath()); |
|
| 91 | + return '/' . ltrim($fileNameAndPath, '/'); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @return string |
|
| 96 | + */ |
|
| 97 | + public function getInputName() |
|
| 98 | + { |
|
| 99 | + return $this->inputName; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param string $inputName |
|
| 104 | + * @return UploadedFileInterface |
|
| 105 | + */ |
|
| 106 | + public function setInputName($inputName) |
|
| 107 | + { |
|
| 108 | + $this->inputName = $inputName; |
|
| 109 | + return $this; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @return string |
|
| 114 | + */ |
|
| 115 | + public function getUploadFolder() |
|
| 116 | + { |
|
| 117 | + return $this->uploadFolder; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @param string $uploadFolder |
|
| 122 | + * @return UploadedFileInterface |
|
| 123 | + */ |
|
| 124 | + public function setUploadFolder($uploadFolder) |
|
| 125 | + { |
|
| 126 | + $this->uploadFolder = $uploadFolder; |
|
| 127 | + return $this; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @return string |
|
| 132 | + */ |
|
| 133 | + public function getName() |
|
| 134 | + { |
|
| 135 | + return $this->name; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @param string $name |
|
| 140 | + * @return UploadedFileInterface |
|
| 141 | + */ |
|
| 142 | + public function setName($name) |
|
| 143 | + { |
|
| 144 | + $this->name = $name; |
|
| 145 | + return $this; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Check whether the file exists. |
|
| 150 | + */ |
|
| 151 | + protected function checkFileExistence() |
|
| 152 | + { |
|
| 153 | + if (!is_file($this->getFileWithAbsolutePath())) { |
|
| 154 | + $message = sprintf('File not found at "%s". Did you save it?', $this->getFileWithAbsolutePath()); |
|
| 155 | + throw new MissingFileException($message, 1361786958); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | 158 | } |
@@ -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 | |
@@ -20,36 +20,36 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class TceForms extends AbstractFormElement |
| 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(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(FileUploadTceForms::class); |
|
| 51 | + $fileUpload->setValue($fileMetadataRecord['file'][0])->setPrefix(MediaModule::getParameterPrefix()); |
|
| 52 | + $result['html'] = $fileUpload->render(); |
|
| 53 | + return $result; |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -42,7 +42,7 @@ |
||
| 42 | 42 | $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
| 43 | 43 | |
| 44 | 44 | $publicResourcesPath = PathUtility::getPublicResourceWebPath('EXT:media/Resources/Public/'); |
| 45 | - $configuration['paths']['Fab/Media'] = $publicResourcesPath . 'JavaScript'; |
|
| 45 | + $configuration['paths']['Fab/Media'] = $publicResourcesPath.'JavaScript'; |
|
| 46 | 46 | |
| 47 | 47 | $pageRenderer->addRequireJsConfiguration($configuration); |
| 48 | 48 | $pageRenderer->loadRequireJsModule('Fab/Media/PluginFilePicker'); |
@@ -19,30 +19,30 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class FilePickerPlugin extends AbstractComponentView |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * Renders a hidden link for file picker. |
|
| 24 | - * |
|
| 25 | - * @return string |
|
| 26 | - */ |
|
| 27 | - public function render() |
|
| 28 | - { |
|
| 29 | - if ($this->getModuleLoader()->hasPlugin('filePicker')) { |
|
| 30 | - $this->loadRequireJsCode(); |
|
| 31 | - }; |
|
| 32 | - return ''; |
|
| 33 | - } |
|
| 22 | + /** |
|
| 23 | + * Renders a hidden link for file picker. |
|
| 24 | + * |
|
| 25 | + * @return string |
|
| 26 | + */ |
|
| 27 | + public function render() |
|
| 28 | + { |
|
| 29 | + if ($this->getModuleLoader()->hasPlugin('filePicker')) { |
|
| 30 | + $this->loadRequireJsCode(); |
|
| 31 | + }; |
|
| 32 | + return ''; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @return void |
|
| 37 | - */ |
|
| 38 | - protected function loadRequireJsCode() |
|
| 39 | - { |
|
| 40 | - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
| 35 | + /** |
|
| 36 | + * @return void |
|
| 37 | + */ |
|
| 38 | + protected function loadRequireJsCode() |
|
| 39 | + { |
|
| 40 | + $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
| 41 | 41 | |
| 42 | - $publicResourcesPath = PathUtility::getPublicResourceWebPath('EXT:media/Resources/Public/'); |
|
| 43 | - $configuration['paths']['Fab/Media'] = $publicResourcesPath . 'JavaScript'; |
|
| 42 | + $publicResourcesPath = PathUtility::getPublicResourceWebPath('EXT:media/Resources/Public/'); |
|
| 43 | + $configuration['paths']['Fab/Media'] = $publicResourcesPath . 'JavaScript'; |
|
| 44 | 44 | |
| 45 | - $pageRenderer->addRequireJsConfiguration($configuration); |
|
| 46 | - $pageRenderer->loadRequireJsModule('Fab/Media/PluginFilePicker'); |
|
| 47 | - } |
|
| 45 | + $pageRenderer->addRequireJsConfiguration($configuration); |
|
| 46 | + $pageRenderer->loadRequireJsModule('Fab/Media/PluginFilePicker'); |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -65,7 +65,7 @@ |
||
| 65 | 65 | $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
| 66 | 66 | |
| 67 | 67 | $publicResourcesPath = PathUtility::getPublicResourceWebPath('EXT:media/Resources/Public/'); |
| 68 | - $configuration['paths']['Fab/Media'] = $publicResourcesPath . 'JavaScript'; |
|
| 68 | + $configuration['paths']['Fab/Media'] = $publicResourcesPath.'JavaScript'; |
|
| 69 | 69 | |
| 70 | 70 | $pageRenderer->addRequireJsConfiguration($configuration); |
| 71 | 71 | $pageRenderer->loadRequireJsModule('Fab/Media/PluginImageEditor'); |
@@ -21,51 +21,51 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class ImageEditorPlugin extends AbstractComponentView |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * Renders a hidden link for image editor. |
|
| 26 | - * |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - public function render() |
|
| 30 | - { |
|
| 31 | - $result = ''; |
|
| 32 | - if ($this->getModuleLoader()->hasPlugin('imageEditor')) { |
|
| 33 | - // Load Require JS code |
|
| 34 | - $this->loadRequireJsCode(); |
|
| 24 | + /** |
|
| 25 | + * Renders a hidden link for image editor. |
|
| 26 | + * |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | + public function render() |
|
| 30 | + { |
|
| 31 | + $result = ''; |
|
| 32 | + if ($this->getModuleLoader()->hasPlugin('imageEditor')) { |
|
| 33 | + // Load Require JS code |
|
| 34 | + $this->loadRequireJsCode(); |
|
| 35 | 35 | |
| 36 | - $result = sprintf( |
|
| 37 | - '<a href="%s" id="btn-imageEditor-current" class="btn btn-imageEditor" style="display: none"></a>', |
|
| 38 | - $this->getImageEditorUri() |
|
| 39 | - ); |
|
| 40 | - }; |
|
| 41 | - return $result; |
|
| 42 | - } |
|
| 36 | + $result = sprintf( |
|
| 37 | + '<a href="%s" id="btn-imageEditor-current" class="btn btn-imageEditor" style="display: none"></a>', |
|
| 38 | + $this->getImageEditorUri() |
|
| 39 | + ); |
|
| 40 | + }; |
|
| 41 | + return $result; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 47 | - protected function getImageEditorUri() |
|
| 48 | - { |
|
| 49 | - $urlParameters = array( |
|
| 50 | - MediaModule::getParameterPrefix() => array( |
|
| 51 | - 'controller' => 'ImageEditor', |
|
| 52 | - 'action' => 'show', |
|
| 53 | - ), |
|
| 54 | - ); |
|
| 55 | - return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
| 56 | - } |
|
| 44 | + /** |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | + protected function getImageEditorUri() |
|
| 48 | + { |
|
| 49 | + $urlParameters = array( |
|
| 50 | + MediaModule::getParameterPrefix() => array( |
|
| 51 | + 'controller' => 'ImageEditor', |
|
| 52 | + 'action' => 'show', |
|
| 53 | + ), |
|
| 54 | + ); |
|
| 55 | + return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @return void |
|
| 60 | - */ |
|
| 61 | - protected function loadRequireJsCode() |
|
| 62 | - { |
|
| 63 | - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
| 58 | + /** |
|
| 59 | + * @return void |
|
| 60 | + */ |
|
| 61 | + protected function loadRequireJsCode() |
|
| 62 | + { |
|
| 63 | + $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
| 64 | 64 | |
| 65 | - $publicResourcesPath = PathUtility::getPublicResourceWebPath('EXT:media/Resources/Public/'); |
|
| 66 | - $configuration['paths']['Fab/Media'] = $publicResourcesPath . 'JavaScript'; |
|
| 65 | + $publicResourcesPath = PathUtility::getPublicResourceWebPath('EXT:media/Resources/Public/'); |
|
| 66 | + $configuration['paths']['Fab/Media'] = $publicResourcesPath . 'JavaScript'; |
|
| 67 | 67 | |
| 68 | - $pageRenderer->addRequireJsConfiguration($configuration); |
|
| 69 | - $pageRenderer->loadRequireJsModule('Fab/Media/PluginImageEditor'); |
|
| 70 | - } |
|
| 68 | + $pageRenderer->addRequireJsConfiguration($configuration); |
|
| 69 | + $pageRenderer->loadRequireJsModule('Fab/Media/PluginImageEditor'); |
|
| 70 | + } |
|
| 71 | 71 | } |