‪TYPO3CMS  10.4
FileUploadController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
30 
36 {
42  protected ‪$target;
43 
49  protected ‪$returnUrl;
50 
56  protected ‪$content;
57 
63  protected ‪$folderObject;
64 
70  protected ‪$moduleTemplate;
71 
78  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
79  {
80  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
81  $this->‪getLanguageService()->‪includeLLFile('EXT:core/Resources/Private/Language/locallang_misc.xlf');
82  $this->‪init($request);
83  $this->‪renderContent();
84  return new ‪HtmlResponse($this->moduleTemplate->renderContent());
85  }
86 
93  protected function ‪init(ServerRequestInterface $request): void
94  {
95  $parsedBody = $request->getParsedBody();
96  $queryParams = $request->getQueryParams();
97 
99  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
100  // Initialize GPvars:
101  $this->target = $parsedBody['target'] ?? $queryParams['target'] ?? null;
102  $this->returnUrl = GeneralUtility::sanitizeLocalUrl($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? '');
103  if (!$this->returnUrl) {
104  $this->returnUrl = (string)$uriBuilder->buildUriFromRoute('file_list', [
105  'id' => rawurlencode($this->target)
106  ]);
107  }
108  // Create the folder object
109  if ($this->target) {
110  $this->folderObject = GeneralUtility::makeInstance(ResourceFactory::class)
111  ->retrieveFileOrFolderObject($this->target);
112  }
113  if ($this->folderObject->getStorage()->getUid() === 0) {
115  'You are not allowed to access folders outside your storages',
116  1375889834
117  );
118  }
119 
120  // Cleaning and checking target directory
121  if (!$this->folderObject) {
122  $title = $this->‪getLanguageService()->‪sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:paramError');
123  $message = $this->‪getLanguageService()->‪sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:targetNoDir');
124  throw new \RuntimeException($title . ': ' . $message, 1294586843);
125  }
126 
127  // Setting up the context sensitive menu
128  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
129 
130  // building pathInfo for metaInformation
131  $pathInfo = [
132  'combined_identifier' => $this->folderObject->getCombinedIdentifier(),
133  ];
134  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pathInfo);
135  }
136 
140  protected function ‪renderContent(): void
141  {
142  $lang = $this->‪getLanguageService();
144  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
145 
146  // set page title
147  $this->moduleTemplate->setTitle($lang->sL('LLL:EXT:filelist/Resources/Private/Language/locallang.xlf:file_upload.php.pagetitle'));
148 
149  $pageContent = '<form action="'
150  . htmlspecialchars((string)$uriBuilder->buildUriFromRoute('tce_file'))
151  . '" method="post" id="FileUploadController" name="editform" enctype="multipart/form-data">';
152  // Make page header:
153  $pageContent .= '<h1>' . $lang->sL('LLL:EXT:filelist/Resources/Private/Language/locallang.xlf:file_upload.php.pagetitle') . '</h1>';
154  $pageContent .= $this->‪renderUploadFormInternal();
155 
156  // Header Buttons
157  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
158 
159  // csh button
160  $cshButton = $buttonBar->makeHelpButton()
161  ->setModuleName('xMOD_csh_corebe')
162  ->setFieldName('file_upload');
163  $buttonBar->addButton($cshButton);
164 
165  // back button
166  if ($this->returnUrl) {
167  $backButton = $buttonBar->makeLinkButton()
168  ->setHref($this->returnUrl)
169  ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
170  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', ‪Icon::SIZE_SMALL));
171  $buttonBar->addButton($backButton);
172  }
173 
174  $pageContent .= '</form>';
175  $this->content .= '<div>' . $pageContent . '</div>';
176  $this->moduleTemplate->setContent($this->content);
177  }
178 
184  protected function ‪renderUploadFormInternal(): string
185  {
186  ‪$content = '
187  <div class="form-group">
188  <input type="file" multiple="multiple" class="form-control" name="upload_1[]" />
189  <input type="hidden" name="data[upload][1][target]" value="' . htmlspecialchars($this->folderObject->getCombinedIdentifier()) . '" />
190  <input type="hidden" name="data[upload][1][data]" value="1" />
191  </div>
192  <div class="checkbox">
193  <label for="overwriteExistingFiles">
194  <input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="replace" /> ' . htmlspecialchars($this->‪getLanguageService()->getLL('overwriteExistingFiles')) . '</label>
195  </div>
196  <div>
197  <input type="hidden" name="data[upload][1][redirect]" value="' . $this->returnUrl . '" />
198  <input class="btn btn-primary" type="submit" value="' . htmlspecialchars($this->‪getLanguageService()->sL('LLL:EXT:filelist/Resources/Private/Language/locallang.xlf:file_upload.php.submit')) . '" />
199  </div>
200  <div class="callout callout-warning">
201  ' . htmlspecialchars($this->‪getLanguageService()->getLL('uploadMultipleFilesInfo')) . '
202  </div>
203  ';
204 
205  return ‪$content;
206  }
207 
211  protected function ‪getLanguageService(): ‪LanguageService
212  {
213  return ‪$GLOBALS['LANG'];
214  }
215 }
‪TYPO3\CMS\Filelist\Controller\File\FileUploadController\$returnUrl
‪string $returnUrl
Definition: FileUploadController.php:47
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Filelist\Controller\File\FileUploadController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: FileUploadController.php:73
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪array includeLLFile($fileRef, $setGlobal=null, $mergeLocalOntoDefault=null)
Definition: LanguageService.php:297
‪TYPO3\CMS\Filelist\Controller\File\FileUploadController\init
‪init(ServerRequestInterface $request)
Definition: FileUploadController.php:88
‪TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException
Definition: InsufficientFolderAccessPermissionsException.php:24
‪TYPO3\CMS\Filelist\Controller\File\FileUploadController\renderUploadFormInternal
‪string renderUploadFormInternal()
Definition: FileUploadController.php:179
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Filelist\Controller\File\FileUploadController\$folderObject
‪TYPO3 CMS Core Resource Folder $folderObject
Definition: FileUploadController.php:59
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:194
‪TYPO3\CMS\Filelist\Controller\File
Definition: CreateFolderController.php:18
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:43
‪TYPO3\CMS\Filelist\Controller\File\FileUploadController\$content
‪string $content
Definition: FileUploadController.php:53
‪TYPO3\CMS\Filelist\Controller\File\FileUploadController\renderContent
‪renderContent()
Definition: FileUploadController.php:135
‪TYPO3\CMS\Filelist\Controller\File\FileUploadController\getLanguageService
‪LanguageService getLanguageService()
Definition: FileUploadController.php:206
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Filelist\Controller\File\FileUploadController
Definition: FileUploadController.php:36
‪TYPO3\CMS\Filelist\Controller\File\FileUploadController\$target
‪string $target
Definition: FileUploadController.php:41
‪TYPO3\CMS\Filelist\Controller\File\FileUploadController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: FileUploadController.php:65
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26