‪TYPO3CMS  9.5
FileUploadController.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
28 
34 {
36 
40  protected ‪$deprecatedPublicProperties = [
41  'title' => 'Using $title of class FileUploadController from outside is discouraged as this variable is only used for internal storage.',
42  'target' => 'Using $target of class FileUploadController from outside is discouraged as this variable is only used for internal storage.',
43  'returnUrl' => 'Using $returnUrl of class FileUploadController from outside is discouraged as this variable is only used for internal storage.',
44  'content' => 'Using $content of class FileUploadController from outside is discouraged as this variable is only used for internal storage.',
45  ];
46 
52  protected ‪$title;
53 
59  protected ‪$target;
60 
66  protected ‪$returnUrl;
67 
73  protected ‪$content;
74 
80  protected ‪$folderObject;
81 
87  protected ‪$moduleTemplate;
88 
92  public function ‪__construct()
93  {
94  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
95  $this->‪getLanguageService()->‪includeLLFile('EXT:core/Resources/Private/Language/locallang_misc.xlf');
96 
97  // @deprecated since TYPO3 v9, will be moved out of __construct() in TYPO3 v10.0
98  $this->‪init(‪$GLOBALS['TYPO3_REQUEST']);
99  }
100 
107  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
108  {
109  $this->‪renderContent();
110  return new ‪HtmlResponse($this->moduleTemplate->renderContent());
111  }
112 
118  public function ‪main()
119  {
120  trigger_error('FileUploadController->main() will be replaced by protected method renderContent() in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
121  $this->‪renderContent();
122  }
123 
130  public function ‪renderUploadForm()
131  {
132  trigger_error('FileUploadController->renderUploadForm() will be replaced by protected method renderUploadFormInternal() in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
133  return $this->‪renderUploadFormInternal();
134  }
135 
142  protected function ‪init(ServerRequestInterface $request): void
143  {
144  $parsedBody = $request->getParsedBody();
145  $queryParams = $request->getQueryParams();
146 
148  $uriBuilder = GeneralUtility::makeInstance(\‪TYPO3\CMS\Backend\Routing\UriBuilder::class);
149  // Initialize GPvars:
150  $this->target = $parsedBody['target'] ?? $queryParams['target'] ?? null;
151  $this->returnUrl = GeneralUtility::sanitizeLocalUrl($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? '');
152  if (!$this->returnUrl) {
153  $this->returnUrl = (string)$uriBuilder->buildUriFromRoute('file_list', [
154  'id' => rawurlencode($this->target)
155  ]);
156  }
157  // Create the folder object
158  if ($this->target) {
159  $this->folderObject = ‪ResourceFactory::getInstance()
160  ->‪retrieveFileOrFolderObject($this->target);
161  }
162  if ($this->folderObject->getStorage()->getUid() === 0) {
163  throw new InsufficientFolderAccessPermissionsException(
164  'You are not allowed to access folders outside your storages',
165  1375889834
166  );
167  }
168 
169  // Cleaning and checking target directory
170  if (!$this->folderObject) {
171  ‪$title = $this->‪getLanguageService()->‪sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:paramError');
172  $message = $this->‪getLanguageService()->‪sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:targetNoDir');
173  throw new \RuntimeException(‪$title . ': ' . $message, 1294586843);
174  }
175 
176  // Setting up the context sensitive menu
177  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
178 
179  // building pathInfo for metaInformation
180  $pathInfo = [
181  'combined_identifier' => $this->folderObject->getCombinedIdentifier(),
182  ];
183  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pathInfo);
184  }
185 
189  protected function ‪renderContent(): void
190  {
191  $lang = $this->‪getLanguageService();
193  $uriBuilder = GeneralUtility::makeInstance(\‪TYPO3\CMS\Backend\Routing\UriBuilder::class);
194 
195  // set page title
196  $this->moduleTemplate->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_upload.php.pagetitle'));
197 
198  $pageContent = '<form action="'
199  . htmlspecialchars((string)$uriBuilder->buildUriFromRoute('tce_file'))
200  . '" method="post" id="FileUploadController" name="editform" enctype="multipart/form-data">';
201  // Make page header:
202  $pageContent .= '<h1>' . $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_upload.php.pagetitle') . '</h1>';
203  $pageContent .= $this->‪renderUploadFormInternal();
204 
205  // Header Buttons
206  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
207 
208  // csh button
209  $cshButton = $buttonBar->makeHelpButton()
210  ->setModuleName('xMOD_csh_corebe')
211  ->setFieldName('file_upload');
212  $buttonBar->addButton($cshButton);
213 
214  // back button
215  if ($this->returnUrl) {
216  $backButton = $buttonBar->makeLinkButton()
217  ->setHref($this->returnUrl)
218  ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
219  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', ‪Icon::SIZE_SMALL));
220  $buttonBar->addButton($backButton);
221  }
222 
223  $pageContent .= '</form>';
224  $this->content .= '<div>' . $pageContent . '</div>';
225  $this->moduleTemplate->setContent($this->content);
226  }
227 
233  protected function ‪renderUploadFormInternal(): string
234  {
235  ‪$content = '
236  <div class="form-group">
237  <input type="file" multiple="multiple" class="form-control" name="upload_1[]" />
238  <input type="hidden" name="data[upload][1][target]" value="' . htmlspecialchars($this->folderObject->getCombinedIdentifier()) . '" />
239  <input type="hidden" name="data[upload][1][data]" value="1" />
240  </div>
241  <div class="checkbox">
242  <label for="overwriteExistingFiles">
243  <input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="replace" /> ' . htmlspecialchars($this->‪getLanguageService()->getLL('overwriteExistingFiles')) . '</label>
244  </div>
245  <div>
246  <input type="hidden" name="data[upload][1][redirect]" value="' . $this->returnUrl . '" />
247  <input class="btn btn-primary" type="submit" value="' . htmlspecialchars($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_upload.php.submit')) . '" />
248  </div>
249  <div class="callout callout-warning">
250  ' . htmlspecialchars($this->‪getLanguageService()->getLL('uploadMultipleFilesInfo')) . '
251  </div>
252  ';
253 
254  return ‪$content;
255  }
256 
260  protected function ‪getLanguageService(): ‪LanguageService
261  {
262  return ‪$GLOBALS['LANG'];
263  }
264 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪mixed includeLLFile($fileRef, $setGlobal=true, $mergeLocalOntoDefault=false)
Definition: LanguageService.php:260
‪TYPO3\CMS\Backend\Controller\File\FileUploadController\__construct
‪__construct()
Definition: FileUploadController.php:84
‪TYPO3\CMS\Backend\Controller\File\FileUploadController\getLanguageService
‪LanguageService getLanguageService()
Definition: FileUploadController.php:252
‪TYPO3\CMS\Backend\Controller\File\FileUploadController\$target
‪string $target
Definition: FileUploadController.php:55
‪TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException
Definition: InsufficientFolderAccessPermissionsException.php:21
‪TYPO3\CMS\Backend\Controller\File\FileUploadController\$deprecatedPublicProperties
‪array $deprecatedPublicProperties
Definition: FileUploadController.php:38
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Backend\Controller\File\FileUploadController
Definition: FileUploadController.php:34
‪TYPO3\CMS\Backend\Controller\File\FileUploadController\renderContent
‪renderContent()
Definition: FileUploadController.php:181
‪TYPO3
‪TYPO3\CMS\Core\Resource\ResourceFactory\getInstance
‪static ResourceFactory getInstance()
Definition: ResourceFactory.php:39
‪TYPO3\CMS\Backend\Controller\File\FileUploadController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: FileUploadController.php:79
‪TYPO3\CMS\Backend\Controller\File\FileUploadController\$folderObject
‪TYPO3 CMS Core Resource Folder $folderObject
Definition: FileUploadController.php:73
‪TYPO3\CMS\Backend\Controller\File\FileUploadController\main
‪main()
Definition: FileUploadController.php:110
‪TYPO3\CMS\Backend\Controller\File\FileUploadController\$content
‪string $content
Definition: FileUploadController.php:67
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:158
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:40
‪TYPO3\CMS\Backend\Controller\File\FileUploadController\renderUploadFormInternal
‪string renderUploadFormInternal()
Definition: FileUploadController.php:225
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Backend\Controller\File\FileUploadController\$title
‪string $title
Definition: FileUploadController.php:49
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Controller\File\FileUploadController\init
‪init(ServerRequestInterface $request)
Definition: FileUploadController.php:134
‪TYPO3\CMS\Backend\Controller\File
Definition: CreateFolderController.php:3
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait
Definition: PublicPropertyDeprecationTrait.php:66
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Resource\ResourceFactory\retrieveFileOrFolderObject
‪File Folder null retrieveFileOrFolderObject($input)
Definition: ResourceFactory.php:491
‪TYPO3\CMS\Backend\Controller\File\FileUploadController\renderUploadForm
‪string renderUploadForm()
Definition: FileUploadController.php:122
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:25
‪TYPO3\CMS\Backend\Controller\File\FileUploadController\$returnUrl
‪string $returnUrl
Definition: FileUploadController.php:61
‪TYPO3\CMS\Backend\Controller\File\FileUploadController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: FileUploadController.php:99