2 declare(strict_types = 1);
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
53 'initClipboard' =>
'Using FileController::initClipboard() is deprecated and will not be possible anymore in TYPO3 v10.0.',
54 'main' =>
'Using FileController::main() is deprecated and will not be possible anymore in TYPO3 v10.0.',
117 public function mainAction(ServerRequestInterface $request): ResponseInterface
124 if ($request->getParsedBody()[
'edit'] ??
'') {
126 $file = $this->fileData[
'newfile'][0];
131 if ($this->redirect) {
133 GeneralUtility::locationHeaderUrl($this->redirect),
153 $errors = $this->fileProcessor->getErrorMessages();
155 return (
new HtmlResponse(
'<t3err>' . implode(
',',
$errors) .
'</t3err>'))->withStatus(500,
'(AJAX)');
158 foreach ($this->fileData as $action => $results) {
159 foreach ($results as $result) {
160 if (is_array($result)) {
161 foreach ($result as $subResult) {
169 return (
new JsonResponse())->setPayload($flatResult);
180 $fileName = $request->getParsedBody()[
'fileName'] ?? $request->getQueryParams()[
'fileName'] ??
null;
181 $fileTarget = $request->getParsedBody()[
'fileTarget'] ?? $request->getQueryParams()[
'fileTarget'] ??
null;
183 $fileFactory = GeneralUtility::makeInstance(ResourceFactory::class);
184 $fileTargetObject = $fileFactory->retrieveFileOrFolderObject($fileTarget);
185 $processedFileName = $fileTargetObject->getStorage()->sanitizeFileName($fileName, $fileTargetObject);
188 if ($fileTargetObject->hasFile($processedFileName)) {
189 $result = $this->
flattenResultDataValue($fileTargetObject->getStorage()->getFileInFolder($processedFileName, $fileTargetObject));
199 protected function init(ServerRequestInterface $request): void
202 $parsedBody = $request->getParsedBody();
203 $queryParams = $request->getQueryParams();
204 $this->file = $parsedBody[
'data'] ?? $queryParams[
'data'] ??
null;
205 if ($this->file ===
null) {
207 $this->redirect = GeneralUtility::sanitizeLocalUrl($parsedBody[
'redirect'] ?? $queryParams[
'redirect'] ??
'');
209 $mode = key($this->file);
210 $elementKey = key($this->file[$mode]);
211 $this->redirect = GeneralUtility::sanitizeLocalUrl($this->file[$mode][$elementKey][
'redirect']);
213 $this->CB = $parsedBody[
'CB'] ?? $queryParams[
'CB'] ??
null;
215 if (isset($this->file[
'rename'][0][
'conflictMode'])) {
216 $conflictMode = $this->file[
'rename'][0][
'conflictMode'];
217 unset($this->file[
'rename'][0][
'conflictMode']);
220 $this->overwriteExistingFiles =
DuplicationBehavior::cast($parsedBody[
'overwriteExistingFiles'] ?? $queryParams[
'overwriteExistingFiles'] ??
null);
223 $this->fileProcessor = GeneralUtility::makeInstance(ExtendedFileUtility::class);
231 if (is_array($this->CB)) {
232 $clipObj = GeneralUtility::makeInstance(Clipboard::class);
233 $clipObj->initializeClipboard();
234 if ($this->CB[
'paste']) {
235 $clipObj->setCurrentPad($this->CB[
'pad']);
236 $this->file = $clipObj->makePasteCmdArray_file($this->CB[
'paste'], $this->file);
238 if ($this->CB[
'delete']) {
239 $clipObj->setCurrentPad($this->CB[
'pad']);
240 $this->file = $clipObj->makeDeleteCmdArray_file($this->file);
249 protected function main(): void
252 $this->fileProcessor->setActionPermissions();
253 $this->fileProcessor->setExistingFilesConflictMode($this->overwriteExistingFiles);
254 $this->fileProcessor->start($this->file);
255 $this->fileData = $this->fileProcessor->processData();
267 $textFileExtensionList =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'textfile_ext'] ??
'';
268 if (!GeneralUtility::inList($textFileExtensionList,
$file->getExtension())) {
275 if ($this->redirect) {
278 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
279 return (
string)$uriBuilder->buildUriFromRoute(
'file_edit', $urlParameters);
290 trigger_error(
'FileController->finish() will be removed in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
292 if ($this->redirect) {
308 if ($result instanceof File) {
310 if (GeneralUtility::inList(
$GLOBALS[
'TYPO3_CONF_VARS'][
'GFX'][
'imagefile_ext'], $result->getExtension())) {
312 if ($processedFile) {
313 $thumbUrl = $processedFile->getPublicUrl(
true);
316 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
317 $result = array_merge(
321 'icon' => $iconFactory->getIconForFileExtension($result->getExtension(),
Icon::SIZE_SMALL)->render(),
322 'thumbUrl' => $thumbUrl
325 } elseif ($result instanceof Folder) {
326 $result = $result->getIdentifier();