TYPO3 CMS  TYPO3_8-7
CreateFolderController.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
28 
35 {
39  public $folderNumber = 10;
40 
46  public $title;
47 
51  public $number;
52 
58  public $target;
59 
65  protected $folderObject;
66 
72  public $returnUrl;
73 
77  protected $pathInfo;
78 
84  public $content;
85 
89  public function __construct()
90  {
91  parent::__construct();
92  $GLOBALS['SOBE'] = $this;
93  $this->init();
94  }
95 
100  protected function init()
101  {
102  // Initialize GPvars:
103  $this->number = GeneralUtility::_GP('number');
104  $this->target = ($combinedIdentifier = GeneralUtility::_GP('target'));
105  $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
106  // create the folder object
107  if ($combinedIdentifier) {
108  $this->folderObject = ResourceFactory::getInstance()
109  ->getFolderObjectFromCombinedIdentifier($combinedIdentifier);
110  }
111  // Cleaning and checking target directory
112  if (!$this->folderObject) {
113  $title = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_file_list.xlf:paramError');
114  $message = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_file_list.xlf:targetNoDir');
115  throw new \RuntimeException($title . ': ' . $message, 1294586845);
116  }
117  if ($this->folderObject->getStorage()->getUid() === 0) {
119  'You are not allowed to access folders outside your storages',
120  1375889838
121  );
122  }
123 
124  $pathInfo = [
125  'combined_identifier' => $this->folderObject->getCombinedIdentifier(),
126  ];
127  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pathInfo);
128  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
129  $this->moduleTemplate->addJavaScriptCode(
130  'CreateFolderInlineJavaScript',
131  'var path = "' . $this->target . '";
132  var confirmTitle = '
134  $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:pleaseConfirm')
135  )
136  . ';
137  var confirmText = '
139  $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:mess.redraw')
140  )
141  . ';
142  function reload(a) {
143  var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl=' . rawurlencode($this->returnUrl) . '";
144  var url = \'' . BackendUtility::getModuleUrl('file_newfolder') . '\';
145  if (!changed) {
146  window.location.href = url + params;
147  } else {
148  var modal = top.TYPO3.Modal.confirm(confirmTitle, confirmText);
149  modal.on(\'confirm.button.cancel\', function(e) {
150  top.TYPO3.Modal.currentModal.trigger(\'modal-dismiss\');
151  });
152  modal.on(\'confirm.button.ok\', function(e) {
153  top.TYPO3.Modal.currentModal.trigger(\'modal-dismiss\');
154  window.location.href = url + params;
155  });
156  }
157  }
158  function backToList() {
159  top.goToModule("file_FilelistList");
160  }
161  var changed = 0;'
162  );
163  }
164 
168  public function main()
169  {
170  $lang = $this->getLanguageService();
171  $assigns = [];
172  $assigns['target'] = $this->target;
173  if ($this->folderObject->checkActionPermission('add')) {
174  $assigns['moduleUrlTceFile'] = BackendUtility::getModuleUrl('tce_file');
175  $assigns['cshFileNewFolder'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfolder');
176  // Making the selector box for the number of concurrent folder-creations
177  $this->number = MathUtility::forceIntegerInRange($this->number, 1, 10);
178  for ($a = 1; $a <= $this->folderNumber; $a++) {
179  $options = [];
180  $options['value'] = $a;
181  $options['selected'] = ($this->number == $a ? ' selected="selected"' : '');
182  $assigns['options'][] = $options;
183  }
184  // Making the number of new-folder boxes needed:
185  for ($a = 0; $a < $this->number; $a++) {
186  $folder = [];
187  $folder['this'] = $a;
188  $folder['next'] = $a + 1;
189  $assigns['folders'][] = $folder;
190  }
191  // Making submit button for folder creation:
192  $assigns['returnUrl'] = $this->returnUrl;
193  }
194 
195  if ($this->folderObject->getStorage()->checkUserActionPermission('add', 'File')) {
196  $assigns['moduleUrlOnlineMedia'] = BackendUtility::getModuleUrl('online_media');
197  $assigns['cshFileNewMedia'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newMedia');
198  // Create a list of allowed file extensions with the readable format "youtube, vimeo" etc.
199  $fileExtList = [];
200  $onlineMediaFileExt = OnlineMediaHelperRegistry::getInstance()->getSupportedFileExtensions();
201  foreach ($onlineMediaFileExt as $fileExt) {
203  $fileExtList[] = strtoupper(htmlspecialchars($fileExt));
204  }
205  }
206  $assigns['fileExtList'] = $fileExtList;
207 
208  $assigns['moduleUrlTceFile'] = BackendUtility::getModuleUrl('tce_file');
209  $assigns['cshFileNewFile'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfile');
210  // Create a list of allowed file extensions with a text format "*.txt, *.css" etc.
211  $fileExtList = [];
212  $textFileExt = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], true);
213  foreach ($textFileExt as $fileExt) {
215  $fileExtList[] = strtoupper(htmlspecialchars($fileExt));
216  }
217  }
218  $assigns['txtFileExtList'] = $fileExtList;
219  }
220 
221  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
222  // CSH button
223  $helpButton = $buttonBar->makeHelpButton()
224  ->setFieldName('file_new')
225  ->setModuleName('xMOD_csh_corebe');
226  $buttonBar->addButton($helpButton);
227 
228  // Back
229  if ($this->returnUrl) {
230  $backButton = $buttonBar->makeLinkButton()
231  ->setHref($this->returnUrl)
232  ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
233  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL));
234  $buttonBar->addButton($backButton);
235  }
236 
237  // Rendering of the output via fluid
238  $view = GeneralUtility::makeInstance(StandaloneView::class);
239  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
240  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
241  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
242  'EXT:backend/Resources/Private/Templates/File/CreateFolder.html'
243  ));
244  $view->assignMultiple($assigns);
245  $this->content = $view->render();
246  $this->moduleTemplate->setContent($this->content);
247  }
248 
256  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
257  {
258  $this->main();
259  $response->getBody()->write($this->moduleTemplate->renderContent());
260  return $response;
261  }
262 
268  protected function getLanguageService()
269  {
270  return $GLOBALS['LANG'];
271  }
272 }
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31
static getFileAbsFileName($filename, $_=null, $_2=null)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static verifyFilenameAgainstDenyPattern($filename)
static makeInstance($className,... $constructorArguments)
mainAction(ServerRequestInterface $request, ResponseInterface $response)
static cshItem($table, $field, $_='', $wrap='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']