TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
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 
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
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/ClickMenu');
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 
170  public function main()
171  {
172  $lang = $this->getLanguageService();
173  $assigns = [];
174  $assigns['target'] = $this->target;
175  if ($this->folderObject->checkActionPermission('add')) {
176  $assigns['moduleUrlTceFile'] = BackendUtility::getModuleUrl('tce_file');
177  $assigns['cshFileNewFolder'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfolder');
178  // Making the selector box for the number of concurrent folder-creations
179  $this->number = MathUtility::forceIntegerInRange($this->number, 1, 10);
180  for ($a = 1; $a <= $this->folderNumber; $a++) {
181  $options = [];
182  $options['value'] = $a;
183  $options['selected'] = ($this->number == $a ? ' selected="selected"' : '');
184  $assigns['options'][] = $options;
185  }
186  // Making the number of new-folder boxes needed:
187  for ($a = 0; $a < $this->number; $a++) {
188  $folder = [];
189  $folder['this'] = $a;
190  $folder['next'] = $a + 1;
191  $assigns['folders'][] = $folder;
192  }
193  // Making submit button for folder creation:
194  $assigns['returnUrl'] = $this->returnUrl;
195  }
196 
197  if ($this->folderObject->getStorage()->checkUserActionPermission('add', 'File')) {
198  $assigns['moduleUrlOnlineMedia'] = BackendUtility::getModuleUrl('online_media');
199  $assigns['cshFileNewMedia'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newMedia');
200  // Create a list of allowed file extensions with the readable format "youtube, vimeo" etc.
201  $fileExtList = [];
202  $onlineMediaFileExt = OnlineMediaHelperRegistry::getInstance()->getSupportedFileExtensions();
203  foreach ($onlineMediaFileExt as $fileExt) {
205  $fileExtList[] = strtoupper(htmlspecialchars($fileExt));
206  }
207  }
208  $assigns['fileExtList'] = $fileExtList;
209 
210  $assigns['moduleUrlTceFile'] = BackendUtility::getModuleUrl('tce_file');
211  $assigns['cshFileNewFile'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfile');
212  // Create a list of allowed file extensions with a text format "*.txt, *.css" etc.
213  $fileExtList = [];
214  $textFileExt = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], true);
215  foreach ($textFileExt as $fileExt) {
217  $fileExtList[] = strtoupper(htmlspecialchars($fileExt));
218  }
219  }
220  $assigns['txtFileExtList'] = $fileExtList;
221  }
222 
223  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
224  // Back
225  if ($this->returnUrl) {
226  $backButton = $buttonBar->makeLinkButton()
227  ->setHref($this->returnUrl)
228  ->setTitle($lang->sL('LLL:EXT:lang/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:backend/Resources/Private/Templates/File/CreateFolder.html'
239  ));
240  $view->assignMultiple($assigns);
241  $this->content = $view->render();
242  $this->moduleTemplate->setContent($this->content);
243  }
244 
252  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
253  {
254  $this->main();
255  $response->getBody()->write($this->moduleTemplate->renderContent());
256  return $response;
257  }
258 
264  protected function getLanguageService()
265  {
266  return $GLOBALS['LANG'];
267  }
268 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static verifyFilenameAgainstDenyPattern($filename)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31
static getFileAbsFileName($filename, $_=null, $_2=null)
mainAction(ServerRequestInterface $request, ResponseInterface $response)