‪TYPO3CMS  11.5
CreateFolderController.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;
25 use TYPO3\CMS\Backend\Utility\BackendUtility;
30 use TYPO3\CMS\Core\Page\PageRenderer;
38 
46 {
50  protected ‪$folderNumber = 10;
51 
55  protected ‪$number;
56 
62  protected ‪$target;
63 
69  protected ‪$folderObject;
70 
76  protected ‪$returnUrl;
77 
81  protected ‪$pathInfo;
82 
88  protected ‪$moduleTemplate;
89 
91  protected PageRenderer ‪$pageRenderer;
92  protected ‪UriBuilder ‪$uriBuilder;
95 
96  public function ‪__construct(
98  PageRenderer ‪$pageRenderer,
102  ) {
103  $this->iconFactory = ‪$iconFactory;
104  $this->pageRenderer = ‪$pageRenderer;
105  $this->uriBuilder = ‪$uriBuilder;
106  $this->resourceFactory = ‪$resourceFactory;
107  $this->moduleTemplateFactory = ‪$moduleTemplateFactory;
108  }
109 
116  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
117  {
118  $this->moduleTemplate = $this->moduleTemplateFactory->create($request);
119  $this->‪init($request);
120  $this->‪main();
121  return new ‪HtmlResponse($this->moduleTemplate->renderContent());
122  }
123 
130  protected function ‪init(ServerRequestInterface $request): void
131  {
132  $parsedBody = $request->getParsedBody();
133  $queryParams = $request->getQueryParams();
134 
135  $this->number = $parsedBody['number'] ?? $queryParams['number'] ?? 0;
136  $this->target = ($combinedIdentifier = $parsedBody['target'] ?? $queryParams['target'] ?? '');
137  $this->returnUrl = GeneralUtility::sanitizeLocalUrl($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? '');
138  // create the folder object
139  if ($combinedIdentifier) {
140  $this->folderObject = $this->resourceFactory->getFolderObjectFromCombinedIdentifier($combinedIdentifier);
141  }
142  // Cleaning and checking target directory
143  if (!$this->folderObject) {
144  $title = $this->‪getLanguageService()->‪sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:paramError');
145  $message = $this->‪getLanguageService()->‪sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:targetNoDir');
146  throw new \RuntimeException($title . ': ' . $message, 1294586845);
147  }
148  if ($this->folderObject->getStorage()->isFallbackStorage()) {
150  'You are not allowed to access folders outside your storages',
151  1375889838
152  );
153  }
154 
155  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformationForResource($this->folderObject);
156  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
157  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Filelist/CreateFolder');
158  }
159 
163  protected function ‪main()
164  {
165  $lang = $this->‪getLanguageService();
166  $assigns = [
167  'target' => ‪$this->target,
168  'confirmTitle' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:pleaseConfirm'),
169  'confirmText' => $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:mess.redraw'),
170  'selfUrl' => (string)$this->uriBuilder->buildUriFromRoute('file_newfolder', [
171  'target' => $this->target,
172  'returnUrl' => $this->returnUrl,
173  'number' => 'AMOUNT',
174  ]),
175  ];
176  if ($this->folderObject->checkActionPermission('add')) {
177  $assigns['moduleUrlTceFile'] = (string)$this->uriBuilder->buildUriFromRoute('tce_file');
178  $assigns['cshFileNewFolder'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfolder');
179  // Making the selector box for the number of concurrent folder-creations
180  $this->number = ‪MathUtility::forceIntegerInRange($this->number, 1, 10);
181  for ($a = 1; $a <= ‪$this->folderNumber; $a++) {
182  $options = [];
183  $options['value'] = $a;
184  $options['selected'] = ($this->number == $a ? ' selected="selected"' : '');
185  $assigns['options'][] = $options;
186  }
187  // Making the number of new-folder boxes needed:
188  for ($a = 0; $a < ‪$this->number; $a++) {
189  $folder = [];
190  $folder['this'] = $a;
191  $folder['next'] = $a + 1;
192  $assigns['folders'][] = $folder;
193  }
194  // Making submit button for folder creation:
195  $assigns['returnUrl'] = ‪$this->returnUrl;
196  }
197 
198  if ($this->folderObject->getStorage()->checkUserActionPermission('add', 'File')) {
199  $assigns['moduleUrlOnlineMedia'] = (string)$this->uriBuilder->buildUriFromRoute('online_media');
200  $assigns['cshFileNewMedia'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newMedia');
201  // Create a list of allowed file extensions with the readable format "youtube, vimeo" etc.
202  $fileExtList = [];
203  $onlineMediaFileExt = GeneralUtility::makeInstance(OnlineMediaHelperRegistry::class)->getSupportedFileExtensions();
204  $fileNameVerifier = GeneralUtility::makeInstance(FileNameValidator::class);
205  foreach ($onlineMediaFileExt as $fileExt) {
206  if ($fileNameVerifier->isValid('.' . $fileExt)) {
207  $fileExtList[] = strtoupper(htmlspecialchars($fileExt));
208  }
209  }
210  $assigns['fileExtList'] = $fileExtList;
211 
212  $assigns['moduleUrlTceFile'] = (string)$this->uriBuilder->buildUriFromRoute('tce_file');
213  $assigns['cshFileNewFile'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfile');
214  // Create a list of allowed file extensions with a text format "*.txt, *.css" etc.
215  $fileExtList = [];
216  $textFileExt = ‪GeneralUtility::trimExplode(',', ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], true);
217  foreach ($textFileExt as $fileExt) {
218  if ($fileNameVerifier->isValid('.' . $fileExt)) {
219  $fileExtList[] = strtoupper(htmlspecialchars($fileExt));
220  }
221  }
222  $assigns['txtFileExtList'] = $fileExtList;
223  }
224 
225  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
226  // CSH button
227  $helpButton = $buttonBar->makeHelpButton()
228  ->setFieldName('file_new')
229  ->setModuleName('xMOD_csh_corebe');
230  $buttonBar->addButton($helpButton);
231 
232  // Back
233  if ($this->returnUrl) {
234  $backButton = $buttonBar->makeLinkButton()
235  ->setHref($this->returnUrl)
236  ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
237  ->setIcon($this->iconFactory->getIcon('actions-view-go-back', ‪Icon::SIZE_SMALL));
238  $buttonBar->addButton($backButton);
239  }
240 
241  // Rendering of the output via fluid
242  $view = GeneralUtility::makeInstance(StandaloneView::class);
243  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
244  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
245  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
246  'EXT:filelist/Resources/Private/Templates/File/CreateFolder.html'
247  ));
248  $view->assignMultiple($assigns);
249  $this->moduleTemplate->setContent($view->render());
250  }
251 
257  protected function ‪getLanguageService(): ‪LanguageService
258  {
259  return ‪$GLOBALS['LANG'];
260  }
261 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:999
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry
Definition: OnlineMediaHelperRegistry.php:27
‪TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException
Definition: InsufficientFolderAccessPermissionsException.php:23
‪TYPO3\CMS\Filelist\Controller\File\CreateFolderController\$moduleTemplateFactory
‪ModuleTemplateFactory $moduleTemplateFactory
Definition: CreateFolderController.php:87
‪TYPO3\CMS\Core\Resource\Security\FileNameValidator
Definition: FileNameValidator.php:25
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Backend\Template\ModuleTemplateFactory
Definition: ModuleTemplateFactory.php:29
‪TYPO3\CMS\Filelist\Controller\File\CreateFolderController\$iconFactory
‪IconFactory $iconFactory
Definition: CreateFolderController.php:83
‪TYPO3\CMS\Filelist\Controller\File\CreateFolderController\__construct
‪__construct(IconFactory $iconFactory, PageRenderer $pageRenderer, UriBuilder $uriBuilder, ResourceFactory $resourceFactory, ModuleTemplateFactory $moduleTemplateFactory)
Definition: CreateFolderController.php:89
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
‪TYPO3\CMS\Filelist\Controller\File\CreateFolderController\$number
‪int $number
Definition: CreateFolderController.php:53
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Filelist\Controller\File\CreateFolderController
Definition: CreateFolderController.php:46
‪TYPO3\CMS\Filelist\Controller\File\CreateFolderController\$target
‪string $target
Definition: CreateFolderController.php:59
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:161
‪TYPO3\CMS\Filelist\Controller\File\CreateFolderController\$pageRenderer
‪PageRenderer $pageRenderer
Definition: CreateFolderController.php:84
‪TYPO3\CMS\Filelist\Controller\File\CreateFolderController\$folderObject
‪TYPO3 CMS Core Resource Folder $folderObject
Definition: CreateFolderController.php:65
‪TYPO3\CMS\Filelist\Controller\File\CreateFolderController\getLanguageService
‪LanguageService getLanguageService()
Definition: CreateFolderController.php:250
‪TYPO3\CMS\Filelist\Controller\File
Definition: CreateFolderController.php:18
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:46
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:40
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Filelist\Controller\File\CreateFolderController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: CreateFolderController.php:81
‪TYPO3\CMS\Filelist\Controller\File\CreateFolderController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: CreateFolderController.php:109
‪TYPO3\CMS\Filelist\Controller\File\CreateFolderController\$returnUrl
‪string $returnUrl
Definition: CreateFolderController.php:71
‪TYPO3\CMS\Filelist\Controller\File\CreateFolderController\$resourceFactory
‪ResourceFactory $resourceFactory
Definition: CreateFolderController.php:86
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:31
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Filelist\Controller\File\CreateFolderController\main
‪main()
Definition: CreateFolderController.php:156
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Filelist\Controller\File\CreateFolderController\$uriBuilder
‪UriBuilder $uriBuilder
Definition: CreateFolderController.php:85
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Filelist\Controller\File\CreateFolderController\$folderNumber
‪int $folderNumber
Definition: CreateFolderController.php:49
‪TYPO3\CMS\Filelist\Controller\File\CreateFolderController\$pathInfo
‪array $pathInfo
Definition: CreateFolderController.php:75
‪TYPO3\CMS\Filelist\Controller\File\CreateFolderController\init
‪init(ServerRequestInterface $request)
Definition: CreateFolderController.php:123
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26