diff --git a/Classes/Command/TemporaryFileCommand.php b/Classes/Command/TemporaryFileCommand.php index cabba47..5008ff4 100644 --- a/Classes/Command/TemporaryFileCommand.php +++ b/Classes/Command/TemporaryFileCommand.php @@ -2,14 +2,10 @@ namespace Fab\MediaUpload\Command; use Fab\MediaUpload\FileUpload\UploadManager; -use Symfony\Component\Console\Input\InputOption; -use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; -use TYPO3\CMS\Core\Exception; use TYPO3\CMS\Core\Utility\GeneralUtility; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; use SplFileInfo; - use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -19,90 +15,69 @@ /** * Class TemporaryFileCommand * @author Jörg Velletti - * @package Fab\MediaUpload\Command; + * @package Fab\MediaUpload\Command */ -class TemporaryFileCommand extends Command { - - /** - * @var array - */ - private $allowedTables = [] ; - - /** - * @var array - */ - private $extConf = [] ; - - - +class TemporaryFileCommand extends Command +{ /** * Configure the command by defining the name, options and arguments */ - protected function configure() + protected function configure(): void { - $this->setDescription('Remove temporarely files from Media Upload.') - ->setHelp('Get list of Options: .' . LF . 'use the --help option.') + $this->setDescription('Remove temporary files from Media Upload.') + ->setHelp('Get list of Options: ' . PHP_EOL . 'use the --help option.') ->addArgument( 'rundry', InputArgument::OPTIONAL, 'if rundry is given, will only List files ', - '0' ); + '0' + ); } /** * Executes the current command. - * - * This method is not abstract because you can use this class - * as a concrete class. In this case, instead of defining the - * execute() method, you set the code to execute by passing - * a Closure to the setCode() method. - * - * @param InputInterface $input - * @param OutputInterface $output - * @return int 0 if everything went fine, or an exit code - * - * @see setCode() */ protected function execute(InputInterface $input, OutputInterface $output): int { - $io = new SymfonyStyle($input, $output); $io->title($this->getDescription()); - // Bootstrap::initializeBackendAuthentication(); - $structure = $this->getStructureOfFiles(); + $structure = $this->getStructureOfFiles(); - if ($input->getArgument('rundry') ) { - $io->writeln('Argument rundry given. Only list temp files ' ); - $io->writeln('' ); - if( is_array($structure['files'])) { - $io->writeln( implode(PHP_EOL, $structure['files']) ); - $io->writeln('' ); + if ($input->getArgument('rundry')) { + $io->writeln('Argument rundry given. Only list temp files'); + $io->writeln(''); + if (is_array($structure['files'])) { + $io->writeln(implode(PHP_EOL, $structure['files'])); + $io->writeln(''); } - $io->writeln(sprintf('%s temporary file(s).', $structure['numberOfFiles']) ); - return 0 ; + $io->writeln(sprintf('%s temporary file(s).', $structure['numberOfFiles'])); + return Command::SUCCESS; } else { GeneralUtility::rmdir(GeneralUtility::getFileAbsFileName(UploadManager::UPLOAD_FOLDER), true); GeneralUtility::mkdir_deep(GeneralUtility::getFileAbsFileName(UploadManager::UPLOAD_FOLDER)); - $io->writeln(sprintf(sprintf('I have removed %s file(s).', $structure['numberOfFiles']) ) ); - return 0 ; + $io->writeln(sprintf('I have removed %s file(s).', $structure['numberOfFiles'])); + return Command::SUCCESS; } - } /** * @return array */ - protected function getStructureOfFiles() + protected function getStructureOfFiles(): array { - if( !is_dir(GeneralUtility::getFileAbsFileName(UploadManager::UPLOAD_FOLDER))) { - mkdir(GeneralUtility::getFileAbsFileName(UploadManager::UPLOAD_FOLDER)) ; + $uploadFolderPath = GeneralUtility::getFileAbsFileName(UploadManager::UPLOAD_FOLDER); + + if (!is_dir($uploadFolderPath)) { + mkdir($uploadFolderPath, 0755, true); } - $Directory = new RecursiveDirectoryIterator(GeneralUtility::getFileAbsFileName(UploadManager::UPLOAD_FOLDER)); + + $Directory = new RecursiveDirectoryIterator($uploadFolderPath); $iterator = new RecursiveIteratorIterator($Directory); $counter = 0; $structure = []; + /** @var SplFileInfo $file */ foreach ($iterator as $file) { if ($file->isFile()) { @@ -115,5 +90,4 @@ protected function getStructureOfFiles() return $structure; } - -} \ No newline at end of file +} diff --git a/Classes/Controller/MediaUploadController.php b/Classes/Controller/MediaUploadController.php index 768ea59..fcb18c4 100644 --- a/Classes/Controller/MediaUploadController.php +++ b/Classes/Controller/MediaUploadController.php @@ -10,11 +10,14 @@ use Fab\MediaUpload\FileUpload\UploadManager; use Fab\MediaUpload\Utility\UuidUtility; +use Psr\EventDispatcher\EventDispatcherInterface; +use Psr\Http\Message\ResponseInterface; +use TYPO3\CMS\Core\Http\Response; +use TYPO3\CMS\Core\Http\Stream; use TYPO3\CMS\Core\Resource\Exception; use TYPO3\CMS\Core\Resource\ResourceFactory; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; -use TYPO3\CMS\Extbase\SignalSlot\Dispatcher; use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication; /** @@ -23,10 +26,18 @@ class MediaUploadController extends ActionController { + protected EventDispatcherInterface $eventDispatcher; + + public function __construct(EventDispatcherInterface $eventDispatcher) + { + parent::__construct(); + $this->eventDispatcher = $eventDispatcher; + } + /** * Initialize actions. These actions are meant to be called by an logged-in FE User. */ - public function initializeAction() + public function initializeAction(): void { // Perhaps it should go into a validator? @@ -38,11 +49,11 @@ public function initializeAction() } } elseif (!empty($allowedFrontendGroups)) { - $isAllowed = FALSE; - $frontendGroups = GeneralUtility::trimExplode(',', $allowedFrontendGroups, TRUE); + $isAllowed = false; + $frontendGroups = GeneralUtility::trimExplode(',', $allowedFrontendGroups, true); foreach ($frontendGroups as $frontendGroup) { if (GeneralUtility::inList($this->getFrontendUser()->user['usergroup'], $frontendGroup)) { - $isAllowed = TRUE; + $isAllowed = true; break; } } @@ -53,17 +64,16 @@ public function initializeAction() } } - $this->emitBeforeHandleUploadSignal(); + // Note: Signal replaced by PSR-14 events in TYPO3 v12 + // You would need to create a custom event class if needed } /** * Delete a file being just uploaded. - * - * @return string */ - public function deleteAction() + public function deleteAction(): ResponseInterface { - $folderIdentifier = GeneralUtility::_POST('qquuid'); + $folderIdentifier = $this->request->getParsedBody()['qquuid'] ?? ''; $error = ''; @@ -87,19 +97,24 @@ public function deleteAction() } if ($error !== '') { - $this->throwStatus(404, $error); + throw new \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException('File operation failed: ' . $error, 1387123456); } - return json_encode(['success' => true]); + $jsonResponse = json_encode(['success' => true]); + + $body = new Stream('php://temp', 'rw'); + $body->write($jsonResponse); + + return (new Response()) + ->withHeader('content-type', 'application/json; charset=utf-8') + ->withBody($body) + ->withStatus(200); } /** * Handle file upload. - * - * @param int $storageIdentifier - * @return string */ - public function uploadAction(int $storageIdentifier): string + public function uploadAction(int $storageIdentifier): ResponseInterface { /** @var ResourceFactory $factory */ $factory = GeneralUtility::makeInstance(ResourceFactory::class) ; @@ -120,36 +135,22 @@ public function uploadAction(int $storageIdentifier): string $result = ['error' => $e->getMessage()]; } - return json_encode($result); - } + $jsonResponse = json_encode($result); - /** - * Returns an instance of the current Frontend User. - * - * @return FrontendUserAuthentication - */ - protected function getFrontendUser() - { - return $GLOBALS['TSFE']->fe_user; - } + $body = new Stream('php://temp', 'rw'); + $body->write($jsonResponse); - /** - * Signal that is emitted before upload processing is called. - * - * @return void - */ - protected function emitBeforeHandleUploadSignal() - { - $this->getSignalSlotDispatcher()->dispatch(MediaUploadController::class, 'beforeHandleUpload'); + return (new Response()) + ->withHeader('content-type', 'application/json; charset=utf-8') + ->withBody($body) + ->withStatus(200); } /** - * Get the SignalSlot dispatcher. - * - * @return Dispatcher + * Returns an instance of the current Frontend User. */ - protected function getSignalSlotDispatcher() + protected function getFrontendUser(): FrontendUserAuthentication { - return $this->objectManager->get(Dispatcher::class); + return $GLOBALS['TSFE']->fe_user; } } diff --git a/Classes/FileUpload/Base64File.php b/Classes/FileUpload/Base64File.php index 14fcd5c..fe57b22 100644 --- a/Classes/FileUpload/Base64File.php +++ b/Classes/FileUpload/Base64File.php @@ -43,14 +43,20 @@ class Base64File extends \Fab\MediaUpload\FileUpload\UploadedFileAbstract protected $extension; /** + * @param array $postData * @return \Fab\MediaUpload\FileUpload\Base64File * @throws RuntimeException */ - public function __construct() + public function __construct(array $postData = []) { // Processes the encoded image data and returns the decoded image - $encodedImage = GeneralUtility::_POST($this->inputName); + $encodedImage = $postData[$this->inputName] ?? $_POST[$this->inputName] ?? ''; + + if (empty($encodedImage)) { + throw new RuntimeException('No image data provided', 1469376025); + } + if (preg_match('/^data:image\/(jpg|jpeg|png)/i', $encodedImage, $matches)) { $this->extension = $matches[1]; } else { @@ -58,7 +64,8 @@ public function __construct() } // Remove the mime-type header - $data = reset(array_reverse(explode('base64,', $encodedImage))); + $array = array_reverse(explode('base64,', $encodedImage)); + $data = reset($array); // Use strict mode to prevent characters from outside the base64 range $this->image = base64_decode($data, true); @@ -76,7 +83,7 @@ public function __construct() * @return boolean TRUE on success * @throws RuntimeException */ - public function save() + public function save(): bool { if (is_null($this->uploadFolder)) { @@ -111,7 +118,7 @@ public function getSize() if (isset($GLOBALS['_SERVER']['CONTENT_LENGTH'])) { return (int)$GLOBALS['_SERVER']['CONTENT_LENGTH']; } else { - throw new RuntimeException('Getting content length is not supported.'); + throw new RuntimeException('Getting content length is not supported.', 7658672952); } } diff --git a/Classes/FileUpload/ImageOptimizer.php b/Classes/FileUpload/ImageOptimizer.php index 42908c3..3709745 100644 --- a/Classes/FileUpload/ImageOptimizer.php +++ b/Classes/FileUpload/ImageOptimizer.php @@ -57,7 +57,7 @@ public function __construct($storage = NULL) * @param string $className * @return void */ - public function add($className) + public function add($className): void { $this->optimizers[] = $className; } @@ -68,7 +68,7 @@ public function add($className) * @param string $className * @return void */ - public function remove($className) + public function remove($className): void { if (in_array($className, $this->optimizers)) { $key = array_search($className, $this->optimizers); diff --git a/Classes/FileUpload/Optimizer/JpegExifOrient.php b/Classes/FileUpload/Optimizer/JpegExifOrient.php index 52878c1..bca1f43 100644 --- a/Classes/FileUpload/Optimizer/JpegExifOrient.php +++ b/Classes/FileUpload/Optimizer/JpegExifOrient.php @@ -53,7 +53,7 @@ class JpegExifOrient * @return void * @throws \RuntimeException */ - public static function setOrientation($filename, $orientation) + public static function setOrientation(string $filename, int $orientation): void { $exif_data = array(); // Buffer $offsetJfif = 0; @@ -242,7 +242,7 @@ public static function setOrientation($filename, $orientation) * @return integer * @throws \RuntimeException */ - protected static function read_1_byte($handle) + protected static function read_1_byte($handle): int { $c = fgetc($handle); if ($c === FALSE) { @@ -259,7 +259,7 @@ protected static function read_1_byte($handle) * @return integer * @throws \RuntimeException */ - protected static function read_2_bytes($handle) + protected static function read_2_bytes($handle): int { $c1 = fgetc($handle); if ($c1 === FALSE) { diff --git a/Classes/FileUpload/Optimizer/Resize.php b/Classes/FileUpload/Optimizer/Resize.php index c7885b8..137d8f8 100644 --- a/Classes/FileUpload/Optimizer/Resize.php +++ b/Classes/FileUpload/Optimizer/Resize.php @@ -76,13 +76,13 @@ public function optimize($uploadedFile) /** * Resize an image according to given parameter. * - * @throws \Exception * @param string $fileNameAndPath * @param int $width * @param int $height * @return void + *@throws \Exception */ - public function resize($fileNameAndPath, $width = 0, $height = 0) + public function resize(string $fileNameAndPath, int $width = 0, int $height = 0): void { // Skip profile of the image @@ -104,11 +104,11 @@ public function resize($fileNameAndPath, $width = 0, $height = 0) /** * Escapes a file name so it can safely be used on the command line. * - * @see \TYPO3\CMS\Core\Imaging\GraphicalFunctions * @param string $inputName filename to safeguard, must not be empty - * @return string $inputName escaped as needed + * @return string $inputName escaped as needed + *@see \TYPO3\CMS\Core\Imaging\GraphicalFunctions */ - protected function wrapFileName($inputName) + protected function wrapFileName(string $inputName): string { $currentLocale = ''; if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) { diff --git a/Classes/FileUpload/Optimizer/Rotate.php b/Classes/FileUpload/Optimizer/Rotate.php index cad61f8..2798ea9 100644 --- a/Classes/FileUpload/Optimizer/Rotate.php +++ b/Classes/FileUpload/Optimizer/Rotate.php @@ -72,7 +72,7 @@ public function optimize($uploadedFile) * @param string $filename * @return integer */ - protected function getOrientation($filename) + protected function getOrientation(string $filename): int { $extension = strtolower(substr($filename, strrpos($filename, '.') + 1)); $orientation = 1; // Fallback to "straight" @@ -92,7 +92,7 @@ protected function getOrientation($filename) * @return integer * @see http://www.impulseadventure.com/photo/exif-orientation.html */ - protected function isRotated($orientation) + protected function isRotated(int $orientation) { $ret = FALSE; switch ($orientation) { @@ -115,7 +115,7 @@ protected function isRotated($orientation) * @param integer $orientation * @return string */ - protected function getTransformation($orientation) + protected function getTransformation(int $orientation): string { $transformation = ''; if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] !== 'gm') { @@ -159,7 +159,7 @@ protected function getTransformation($orientation) * @return void * @see http://sylvana.net/jpegcrop/exif_orientation.html */ - protected function resetOrientation($filename) + protected function resetOrientation(string $filename) { JpegExifOrient::setOrientation($filename, 1); } diff --git a/Classes/FileUpload/StreamedFile.php b/Classes/FileUpload/StreamedFile.php index ee2b05f..9445498 100644 --- a/Classes/FileUpload/StreamedFile.php +++ b/Classes/FileUpload/StreamedFile.php @@ -87,7 +87,7 @@ public function getSize() if (isset($GLOBALS['_SERVER']['CONTENT_LENGTH'])) { return (int)$GLOBALS['_SERVER']['CONTENT_LENGTH']; } else { - throw new \Exception('Getting content length is not supported.'); + throw new \Exception('Getting content length is not supported.', 7074423571); } } diff --git a/Classes/FileUpload/UploadManager.php b/Classes/FileUpload/UploadManager.php index aa8a13a..68e2dcc 100644 --- a/Classes/FileUpload/UploadManager.php +++ b/Classes/FileUpload/UploadManager.php @@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Resource\Security\FileNameValidator; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\StringUtility; /** * Class that encapsulates the file-upload internals @@ -52,19 +53,26 @@ class UploadManager */ protected $inputName = 'qqfile'; + /** + * @var array + */ + protected $requestParameters = []; + /** * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage + * @param array $requestParameters * @return UploadManager * @throws \InvalidArgumentException * @throws \RuntimeException */ - public function __construct($storage = null) + public function __construct($storage = null, array $requestParameters = []) { $this->checkServerSettings(); // max file size in bytes $this->sizeLimit = GeneralUtility::getMaxUploadFileSize() * 1024; $this->storage = $storage; + $this->requestParameters = $requestParameters; } /** @@ -277,8 +285,8 @@ protected function checkFileExtensionPermission($fileName) $fileExtensionPermissions = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class) ->get('media_upload'); - $allow = GeneralUtility::uniqueList(strtolower($fileExtensionPermissions['fileExtensionsAllow'])); - $deny = GeneralUtility::uniqueList(strtolower($fileExtensionPermissions['fileExtensionsDeny'])); + $allow = StringUtility::uniqueList(strtolower($fileExtensionPermissions['fileExtensionsAllow'])); + $deny = StringUtility::uniqueList(strtolower($fileExtensionPermissions['fileExtensionsDeny'])); $fileExtension = $this->getFileExtension($fileName); if ($fileExtension !== '') { // If the extension is found amongst the allowed types, we return true immediately @@ -395,7 +403,15 @@ public function getUploadFolder() if ($this->uploadFolder === null) { $this->uploadFolder = \TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/' . self::UPLOAD_FOLDER; - $possibleSubFolder = GeneralUtility::_GP('qquuid'); + // Use injected request parameters or fallback to superglobals for backwards compatibility + $possibleSubFolder = null; + if (!empty($this->requestParameters)) { + $possibleSubFolder = $this->requestParameters['qquuid'] ?? null; + } else { + // Fallback to direct superglobal access + $possibleSubFolder = $_GET['qquuid'] ?? $_POST['qquuid'] ?? null; + } + if (UuidUtility::getInstance()->isValid($possibleSubFolder)) { $this->uploadFolder = $this->uploadFolder . DIRECTORY_SEPARATOR . $possibleSubFolder; } diff --git a/Classes/Service/UploadFileService.php b/Classes/Service/UploadFileService.php index e427e5e..90f7c41 100644 --- a/Classes/Service/UploadFileService.php +++ b/Classes/Service/UploadFileService.php @@ -17,6 +17,20 @@ */ class UploadFileService { + /** + * @var array + */ + protected $requestParameters = []; + + /** + * Constructor to inject request parameters + * + * @param array $requestParameters + */ + public function __construct(array $requestParameters = []) + { + $this->requestParameters = $requestParameters; + } /** * Return the list of uploaded files. @@ -26,7 +40,16 @@ class UploadFileService */ public function getUploadedFileList($property = '') { - $parameters = GeneralUtility::_GPmerged('tx_mediaupload_upload'); + // Use injected parameters or fallback to legacy method for backwards compatibility + if (!empty($this->requestParameters)) { + $parameters = $this->requestParameters['tx_mediaupload_upload'] ?? []; + } else { + // Fallback for backwards compatibility - direct access to superglobals + $getParams = $_GET['tx_mediaupload_upload'] ?? []; + $postParams = $_POST['tx_mediaupload_upload'] ?? []; + $parameters = array_merge($getParams, $postParams); // POST takes precedence + } + return empty($parameters['uploadedFiles'][$property]) ? '' : $parameters['uploadedFiles'][$property]; } @@ -61,7 +84,8 @@ public function getUploadedFiles($property = '') throw new \RuntimeException($message, 1389550006); } - $fileSize = round(filesize($sanitizedFileNameAndPath) / 1000); + $fileSize = filesize($sanitizedFileNameAndPath); + $fileSize = $fileSize !== false ? round($fileSize / 1000) : 0; /** @var UploadedFile $uploadedFile */ $uploadedFile = GeneralUtility::makeInstance(UploadedFile::class); @@ -127,5 +151,4 @@ public function countUploadedFiles($property = '') { return count(GeneralUtility::trimExplode(',', $this->getUploadedFileList($property), TRUE)); } - } diff --git a/Classes/ViewHelpers/Widget/Controller/ShowUploadedController.php b/Classes/ViewHelpers/Widget/Controller/ShowUploadedController.php index 5435f27..8e79e70 100644 --- a/Classes/ViewHelpers/Widget/Controller/ShowUploadedController.php +++ b/Classes/ViewHelpers/Widget/Controller/ShowUploadedController.php @@ -21,17 +21,15 @@ class ShowUploadedController extends AbstractWidgetController */ protected $uploadFileService; - /** - * @param \Fab\MediaUpload\Service\UploadFileService $uploadFileService - */ - public function injectController(\Fab\MediaUpload\Service\UploadFileService $uploadFileService ) { - $this->uploadFileService = $uploadFileService ; + public function __construct(\Fab\MediaUpload\Service\UploadFileService $uploadFileService) + { + $this->uploadFileService = $uploadFileService; } /** * @return void */ - public function indexAction() + public function indexAction(): void { $property = $this->widgetConfiguration['property']; $this->view->assign('property', $property); diff --git a/Classes/ViewHelpers/Widget/Controller/UploadController.php b/Classes/ViewHelpers/Widget/Controller/UploadController.php index ed8de2a..e341c6a 100644 --- a/Classes/ViewHelpers/Widget/Controller/UploadController.php +++ b/Classes/ViewHelpers/Widget/Controller/UploadController.php @@ -21,22 +21,19 @@ class UploadController extends AbstractWidgetController /** * @var \Fab\MediaUpload\Service\UploadFileService - * @TYPO3\CMS\Extbase\Annotation\Inject */ protected $uploadFileService; - /** - * @param \Fab\MediaUpload\Service\UploadFileService $uploadFileService - */ - public function injectController(\Fab\MediaUpload\Service\UploadFileService $uploadFileService ) { - $this->uploadFileService = $uploadFileService ; + public function __construct(\Fab\MediaUpload\Service\UploadFileService $uploadFileService) + { + $this->uploadFileService = $uploadFileService; } /** * @return void */ - public function indexAction() + public function indexAction(): void { $this->view->assign('allowedExtensions', $this->getAllowedExtensions()); $this->view->assign('maximumSize', $this->getMaximumSize()); @@ -114,4 +111,5 @@ public function getAllowedExtensions() return $allowedExtensions; } + } diff --git a/Classes/ViewHelpers/Widget/ShowUploadedViewHelper.php b/Classes/ViewHelpers/Widget/ShowUploadedViewHelper.php index fcb423c..5ad2bea 100644 --- a/Classes/ViewHelpers/Widget/ShowUploadedViewHelper.php +++ b/Classes/ViewHelpers/Widget/ShowUploadedViewHelper.php @@ -19,50 +19,41 @@ */ class ShowUploadedViewHelper extends AbstractViewHelper { + protected $escapeOutput = false; + /** * @return void */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument( 'property', - 'int', + 'string', 'The property name used for identifying and grouping uploaded files. Required if form contains multiple upload fields', false, - '', + '' ); } - #public function render(): string - #{ - # $uploadFileService = GeneralUtility::makeInstance( - # UploadFileService::class, - # ); - # - # return static::renderStatic( - # [ - # 'property' => $this->arguments['property'], - # 'uploadedFileList' => $uploadFileService->getUploadedFileList( - # $this->arguments['property'], - # ), - # 'uploadedFiles' => $uploadFileService->getUploadedFiles( - # $this->arguments['property'], - # ), - # ], - # $this->buildRenderChildrenClosure(), - # $this->renderingContext, - # ); - #} public static function renderStatic( array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext ): string { + $uploadFileService = GeneralUtility::makeInstance(UploadFileService::class); + + $arguments['uploadedFileList'] = $uploadFileService->getUploadedFileList( + $arguments['property'] + ); + $arguments['uploadedFiles'] = $uploadFileService->getUploadedFiles( + $arguments['property'] + ); + /** @var StandaloneView $view */ $view = GeneralUtility::makeInstance(StandaloneView::class); $view->setTemplatePathAndFilename( - 'EXT:media_upload/Resources/Private/Templates/ViewHelpers/Widget/ShowUploaded/Index.html', + 'EXT:media_upload/Resources/Private/Templates/ViewHelpers/Widget/ShowUploaded/Index.html' ); $view->assignMultiple($arguments); return $view->render(); diff --git a/Classes/ViewHelpers/Widget/UploadViewHelper.php b/Classes/ViewHelpers/Widget/UploadViewHelper.php index 204e2a5..2b2f552 100644 --- a/Classes/ViewHelpers/Widget/UploadViewHelper.php +++ b/Classes/ViewHelpers/Widget/UploadViewHelper.php @@ -19,89 +19,76 @@ */ class UploadViewHelper extends AbstractViewHelper { - public function initializeArguments() + protected $escapeOutput = false; + + public function initializeArguments(): void { $this->registerArgument( 'allowedExtensions', 'string', 'Allowed extension to be uploaded.', false, - '', - ) - ->registerArgument( - 'maximumSize', - 'int', - 'Maximum file size in Mo by default.', - false, - 0, - ) - ->registerArgument( - 'sizeUnit', - 'string', - 'Whether it is Ko or Mo.', - false, - 'Mo', - ) - ->registerArgument( - 'storage', - 'int', - 'The final storage identifier to which the file will be added eventually.', - true, - ) - ->registerArgument( - 'maximumItems', - 'int', - 'Maximum items to be uploaded', - false, - 10, - ) - ->registerArgument( - 'property', - 'int', - 'The property name used for identifying and grouping uploaded files. Required if form contains multiple upload fields', - false, - '', - ); + '' + ); + $this->registerArgument( + 'maximumSize', + 'int', + 'Maximum file size in Mo by default.', + false, + 0 + ); + $this->registerArgument( + 'sizeUnit', + 'string', + 'Whether it is Ko or Mo.', + false, + 'Mo' + ); + $this->registerArgument( + 'storage', + 'int', + 'The final storage identifier to which the file will be added eventually.', + true + ); + $this->registerArgument( + 'maximumItems', + 'int', + 'Maximum items to be uploaded', + false, + 10 + ); + $this->registerArgument( + 'property', + 'string', + 'The property name used for identifying and grouping uploaded files. Required if form contains multiple upload fields', + false, + '' + ); } - #public function render(): string - #{ - # $uploadFileService = GeneralUtility::makeInstance( - # UploadFileService::class, - # ); - # return static::renderStatic( - # [ - # 'allowedExtensions' => $this->arguments['allowedExtensions'], - # 'maximumSize' => $this->arguments['maximumSize'], - # 'maximumSizeLabel' => 'qwer' . self::getMaximumSizeLabel( - # (int) $this->arguments['maximumSize'], - # ), - # 'sizeUnit' => $this->arguments['sizeUnit'], - # 'storage' => $this->arguments['storage'], - # 'maximumItems' => $this->arguments['maximumItems'], - # 'property' => $this->arguments['property'], - # 'uploadedFileList' => $uploadFileService->getUploadedFileList( - # $this->arguments['property'], - # ), - # 'widgetIdentifier' => uniqid(), - # ], - # $this->buildRenderChildrenClosure(), - # $this->renderingContext, - # ); - #} - public static function renderStatic( array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext ): string { + // Get request parameters from rendering context if available, otherwise fallback to superglobals + $requestParameters = []; + $request = $renderingContext->getRequest(); + if ($request && method_exists($request, 'getQueryParams') && method_exists($request, 'getParsedBody')) { + // Modern PSR-7 request approach + $queryParams = $request->getQueryParams(); + $postParams = $request->getParsedBody() ?? []; + $requestParameters = array_merge($queryParams, $postParams); // POST takes precedence + } + $uploadFileService = GeneralUtility::makeInstance( UploadFileService::class, + $requestParameters ); $arguments['maximumSizeLabel'] = self::getMaximumSizeLabel( - (int)$arguments['maximumSize'], + (int)$arguments['maximumSize'] ); if ($arguments['maximumSize'] === 0) { @@ -109,15 +96,16 @@ public static function renderStatic( } $arguments['uploadedFileList'] = $uploadFileService->getUploadedFileList( - $arguments['property'], + $arguments['property'] ); $arguments['widgetIdentifier'] = uniqid(); + /** @var StandaloneView $view */ $view = GeneralUtility::makeInstance(StandaloneView::class); $view->setTemplatePathAndFilename( - 'EXT:media_upload/Resources/Private/Templates/ViewHelpers/Widget/Upload/Index.html', + 'EXT:media_upload/Resources/Private/Templates/ViewHelpers/Widget/Upload/Index.html' ); $view->assignMultiple($arguments); return $view->render(); @@ -137,9 +125,13 @@ public static function getMaximumSizeLabel(int $maximumSize = 0): int * @param string $property * @return string */ - public static function getUploadedFileList($property = ''): string + public static function getUploadedFileList(string $property = ''): string { - $parameters = GeneralUtility::_GPmerged('tx_mediaupload_upload'); + // Fallback to direct superglobal access to avoid deprecated method + $getParams = $_GET['tx_mediaupload_upload'] ?? []; + $postParams = $_POST['tx_mediaupload_upload'] ?? []; + $parameters = array_merge($getParams, $postParams); // POST takes precedence + return empty($parameters['uploadedFiles'][$property]) ? '' : $parameters['uploadedFiles'][$property]; diff --git a/Configuration/TCA/Overrides/sys_template.php b/Configuration/TCA/Overrides/sys_template.php new file mode 100644 index 0000000..22b3044 --- /dev/null +++ b/Configuration/TCA/Overrides/sys_template.php @@ -0,0 +1,3 @@ + 'Media Upload', 'description' => 'Fluid widget for mass uploading files on the Frontend using HTML5 techniques powered by Fine Uploader - http://fineuploader.com/', 'category' => 'fe', @@ -14,7 +14,7 @@ [ 'depends' => [ - 'typo3' => '11.5.0-11.5.99', + 'typo3' => '12.4.0-12.4.99', ], 'conflicts' => [ diff --git a/ext_localconf.php b/ext_localconf.php index 8466e10..4acb9af 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -1,15 +1,16 @@ get('media_upload'); + $configuration = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( + \TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class + )->get('media_upload'); - if (false === isset($configuration['autoload_typoscript']) || true === (bool)$configuration['autoload_typoscript']) { + if (!isset($configuration['autoload_typoscript']) || !empty($configuration['autoload_typoscript'])) { \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript( 'media_upload', 'constants', @@ -45,7 +46,7 @@ MediaUploadController::class => 'delete', ] ); - // command line is replaced by symphony command: - // ./vendor/bin/typo3cms mediaupload:removeTempFiles rundry=1 + // command line is replaced by symfony command: + // ./vendor/bin/typo3 mediaupload:removeTempFiles rundry=1 }); diff --git a/ext_tables.php b/ext_tables.php index 906bf5b..b680a07 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -1,11 +1,12 @@ get('media_upload'); +call_user_func(static function () { + $configuration = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( + \TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class + )->get('media_upload'); // Possible Static TS loading - if (true === isset($configuration['autoload_typoscript']) && true === (bool)$configuration['autoload_typoscript']) { - \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile('media_upload', 'Configuration/TypoScript', 'Media upload'); + if (!empty($configuration['autoload_typoscript'])) { } });