TYPO3 CMS  TYPO3_6-2
CreateFolderController.php
Go to the documentation of this file.
1 <?php
3 
19 
26 
27  // External, static:
31  public $folderNumber = 10;
32 
33  // Internal, static:
40  public $doc;
41 
42  // Name of the filemount
46  public $title;
47 
48  // Internal, static (GPVar):
52  public $number;
53 
54  // Set with the target path inputted in &target
58  public $target;
59 
65  protected $folderObject;
66 
67  // Return URL of list module.
71  public $returnUrl;
72 
73  // Internal, dynamic:
74  // Accumulating content
78  public $content;
79 
83  public function __construct() {
84  $GLOBALS['SOBE'] = $this;
85  $GLOBALS['BACK_PATH'] = '';
86 
87  $this->init();
88  }
89 
95  protected function init() {
96  // Initialize GPvars:
97  $this->number = GeneralUtility::_GP('number');
98  $this->target = ($combinedIdentifier = GeneralUtility::_GP('target'));
99  $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
100  // create the folder object
101  if ($combinedIdentifier) {
102  $this->folderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($combinedIdentifier);
103  }
104  // Cleaning and checking target directory
105  if (!$this->folderObject) {
106  $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', TRUE);
107  $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', TRUE);
108  throw new \RuntimeException($title . ': ' . $message, 1294586845);
109  }
110  if ($this->folderObject->getStorage()->getUid() === 0) {
111  throw new \TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException('You are not allowed to access folders outside your storages', 1375889838);
112  }
113 
114  // Setting the title and the icon
115  $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-filetree-root');
116  $this->title = $icon . htmlspecialchars($this->folderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->folderObject->getIdentifier());
117  // Setting template object
118  $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
119  $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/file_newfolder.html');
120  $this->doc->backPath = $GLOBALS['BACK_PATH'];
121  $this->doc->JScode = $this->doc->wrapScriptTags('
122  var path = "' . $this->target . '";
123 
124  function reload(a) { //
125  if (!changed || (changed && confirm(' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.redraw')) . '))) {
126  var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl=' . rawurlencode($this->returnUrl) . '";
127  window.location.href = "file_newfolder.php?"+params;
128  }
129  }
130  function backToList() { //
131  top.goToModule("file_list");
132  }
133 
134  var changed = 0;
135  ');
136  }
137 
143  public function main() {
144  // Start content compilation
145  $this->content .= $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle'));
146  // Make page header:
147  $pageContent = $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle'));
148  $pageContent .= $this->doc->spacer(5);
149  $pageContent .= $this->doc->divider(5);
150  if ($this->folderObject->checkActionPermission('add')) {
151  $code = '<form action="tce_file.php" method="post" name="editform">';
152  // Making the selector box for the number of concurrent folder-creations
153  $this->number = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->number, 1, 10);
154  $code .= '
155  <div id="c-select">
156  <label for="number-of-new-folders">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.number_of_folders') . '</label>
157  <select name="number" id="number-of-new-folders" onchange="reload(this.options[this.selectedIndex].value);">';
158  for ($a = 1; $a <= $this->folderNumber; $a++) {
159  $code .= '<option value="' . $a . '"' . ($this->number == $a ? ' selected="selected"' : '') . '>' . $a . '</option>';
160  }
161  $code .= '
162  </select>
163  </div>
164  ';
165  // Making the number of new-folder boxes needed:
166  $code .= '
167  <div id="c-createFolders">
168  ';
169  for ($a = 0; $a < $this->number; $a++) {
170  $code .= '
171  <input' . $this->doc->formWidth(20) . ' type="text" name="file[newfolder][' . $a . '][data]" onchange="changed=true;" />
172  <input type="hidden" name="file[newfolder][' . $a . '][target]" value="' . htmlspecialchars($this->target) . '" /><br />
173  ';
174  }
175  $code .= '
176  </div>
177  ';
178  // Making submit button for folder creation:
179  $code .= '
180  <div id="c-submitFolders">
181  <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.submit', TRUE) . '" />
182  <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', TRUE) . '" onclick="backToList(); return false;" />
183  <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
185  </div>
186  ';
187  // CSH:
188  $code .= BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfolder', $GLOBALS['BACK_PATH'], '<br />');
189  $pageContent .= $code;
190  // Add spacer:
191  $pageContent .= $this->doc->spacer(10);
192  // Switching form tags:
193  $pageContent .= $this->doc->sectionEnd() . '</form>';
194  }
195 
196  if ($this->folderObject->getStorage()->checkUserActionPermission('add', 'File')) {
197  $pageContent .= '<form action="tce_file.php" method="post" name="editform2">';
198  // Create a list of allowed file extensions with the nice format "*.jpg, *.gif" etc.
199  $fileExtList = array();
200  $textfileExt = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], TRUE);
201  foreach ($textfileExt as $fileExt) {
202  if (!preg_match(('/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'] . '/i'), ('.' . $fileExt))) {
203  $fileExtList[] = '*.' . $fileExt;
204  }
205  }
206  // Add form fields for creation of a new, blank text file:
207  $code = '
208  <div id="c-newFile">
209  <p>[' . htmlspecialchars(implode(', ', $fileExtList)) . ']</p>
210  <input' . $this->doc->formWidth(20) . ' type="text" name="file[newfile][0][data]" onchange="changed=true;" />
211  <input type="hidden" name="file[newfile][0][target]" value="' . htmlspecialchars($this->target) . '" />
212  </div>
213  ';
214  // Submit button for creation of a new file:
215  $code .= '
216  <div id="c-submitFiles">
217  <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.newfile_submit', TRUE) . '" />
218  <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', TRUE) . '" onclick="backToList(); return false;" />
219  <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
221  </div>
222  ';
223  // CSH:
224  $code .= BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfile', $GLOBALS['BACK_PATH'], '<br />');
225  $pageContent .= $this->doc->section($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.newfile'), $code);
226  $pageContent .= $this->doc->sectionEnd();
227  $pageContent .= '</form>';
228  }
229 
230  $docHeaderButtons = array(
231  'back' => ''
232  );
233  // Back
234  if ($this->returnUrl) {
235  $docHeaderButtons['back'] = '<a href="' . htmlspecialchars(GeneralUtility::linkThisUrl($this->returnUrl)) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-view-go-back') . '</a>';
236  }
237  // Add the HTML as a section:
238  $markerArray = array(
239  'CSH' => $docHeaderButtons['csh'],
240  'FUNC_MENU' => BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
241  'CONTENT' => $pageContent,
242  'PATH' => $this->title
243  );
244  $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
245  $this->content .= $this->doc->endPage();
246  $this->content = $this->doc->insertStylesAndJS($this->content);
247  }
248 
254  public function printContent() {
255  echo $this->content;
256  }
257 
258 }
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
static cshItem($table, $field, $BACK_PATH, $wrap='', $onlyIconMode=FALSE, $styleAttrib='')
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
static getHiddenTokenField($formName='securityToken', $tokenName='formToken')
static getSpriteIcon($iconName, array $options=array(), array $overlays=array())
static getFuncMenu($mainParams, $elementName, $currentValue, $menuItems, $script='', $addparams='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static linkThisUrl($url, array $getParams=array())