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