TYPO3 CMS  TYPO3_6-2
FileListController.php
Go to the documentation of this file.
1 <?php
3 
21 
28 
34  public $MCONF = array();
35 
39  public $MOD_MENU = array();
40 
44  public $MOD_SETTINGS = array();
45 
51  public $content;
52 
59  public $doc;
60 
66  public $id;
67 
71  protected $folderObject;
72 
76  protected $errorMessage;
77 
83  public $pointer;
84 
90  public $table;
91 
97  public $imagemode;
98 
102  public $cmd;
103 
108 
114  public $filelist = NULL;
115 
119  public function __construct() {
120  $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_mod_file_list.xlf');
121  $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_misc.xlf');
122  $GLOBALS['BE_USER']->modAccess($GLOBALS['MCONF'], TRUE);
123  }
124 
134  public function init() {
135  // Setting GPvars:
136  $this->id = ($combinedIdentifier = GeneralUtility::_GP('id'));
137  $this->pointer = GeneralUtility::_GP('pointer');
138  $this->table = GeneralUtility::_GP('table');
139  $this->imagemode = GeneralUtility::_GP('imagemode');
140  $this->cmd = GeneralUtility::_GP('cmd');
141  $this->overwriteExistingFiles = GeneralUtility::_GP('overwriteExistingFiles');
142  // Setting module name:
143  $this->MCONF = $GLOBALS['MCONF'];
144  try {
145  if ($combinedIdentifier) {
147  $fileFactory = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
148  $storage = $fileFactory->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
149  $identifier = substr($combinedIdentifier, strpos($combinedIdentifier, ':') + 1);
150  if (!$storage->hasFolder($identifier)) {
151  $identifier = $storage->getFolderIdentifierFromFileIdentifier($identifier);
152  }
153 
154  $this->folderObject = $fileFactory->getFolderObjectFromCombinedIdentifier($storage->getUid() . ':' . $identifier);
155  // Disallow access to fallback storage 0
156  if ($storage->getUid() === 0) {
157  throw new Exception\InsufficientFolderAccessPermissionsException('You are not allowed to access files outside your storages', 1434539815);
158  }
159  // Disallow the rendering of the processing folder (e.g. could be called manually)
160  if ($this->folderObject && $storage->isProcessingFolder($this->folderObject)) {
161  $this->folderObject = $storage->getRootLevelFolder();
162  }
163  } else {
164  // Take the first object of the first storage
165  $fileStorages = $GLOBALS['BE_USER']->getFileStorages();
166  $fileStorage = reset($fileStorages);
167  if ($fileStorage) {
168  $this->folderObject = $fileStorage->getRootLevelFolder();
169  } else {
170  throw new \RuntimeException('Could not find any folder to be displayed.', 1349276894);
171  }
172  }
173 
174  if ($this->folderObject && !$this->folderObject->getStorage()->isWithinFileMountBoundaries($this->folderObject)) {
175  throw new \RuntimeException('Folder not accessible.', 1430409089);
176  }
177  } catch (Exception\InsufficientFolderAccessPermissionsException $permissionException) {
178  $this->folderObject = NULL;
179  $this->errorMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
180  sprintf(
181  $GLOBALS['LANG']->getLL('missingFolderPermissionsMessage', TRUE),
182  htmlspecialchars($this->id)
183  ),
184  $GLOBALS['LANG']->getLL('missingFolderPermissionsTitle', TRUE),
186  );
187  } catch (Exception $fileException) {
188  // Set folder object to null and throw a message later on
189  $this->folderObject = NULL;
190  // Take the first object of the first storage
191  $fileStorages = $GLOBALS['BE_USER']->getFileStorages();
192  $fileStorage = reset($fileStorages);
193  if ($fileStorage instanceof \TYPO3\CMS\Core\Resource\ResourceStorage) {
194  $this->folderObject = $fileStorage->getRootLevelFolder();
195  if (!$fileStorage->isWithinFileMountBoundaries($this->folderObject)) {
196  $this->folderObject = NULL;
197  }
198  }
199  $this->errorMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
200  sprintf(
201  $GLOBALS['LANG']->getLL('folderNotFoundMessage', TRUE),
202  htmlspecialchars($this->id)
203  ),
204  $GLOBALS['LANG']->getLL('folderNotFoundTitle', TRUE),
206  );
207  } catch (\RuntimeException $e) {
208  $this->folderObject = NULL;
209  $this->errorMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
210  $e->getMessage() . ' (' . $e->getCode() . ')',
211  $GLOBALS['LANG']->getLL('folderNotFoundTitle', TRUE),
213  );
214  }
215 
216  if ($this->folderObject && !$this->folderObject->getStorage()->checkFolderActionPermission('read', $this->folderObject)) {
217  $this->folderObject = NULL;
218  }
219 
220  // Configure the "menu" - which is used internally to save the values of sorting, displayThumbs etc.
221  $this->menuConfig();
222  }
223 
230  public function menuConfig() {
231  // MENU-ITEMS:
232  // If array, then it's a selector box menu
233  // If empty string it's just a variable, that will be saved.
234  // Values NOT in this array will not be saved in the settings-array for the module.
235  $this->MOD_MENU = array(
236  'sort' => '',
237  'reverse' => '',
238  'displayThumbs' => '',
239  'clipBoard' => '',
240  'bigControlPanel' => ''
241  );
242  // CLEANSE SETTINGS
243  $this->MOD_SETTINGS = BackendUtility::getModuleData(
244  $this->MOD_MENU,
245  GeneralUtility::_GP('SET'),
246  $this->MCONF['name']
247  );
248  }
249 
256  public function main() {
257  // Initialize the template object
258  $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
259  $this->doc->backPath = $GLOBALS['BACK_PATH'];
260  $this->doc->setModuleTemplate('EXT:filelist/Resources/Private/Templates/file_list.html');
261 
263  $pageRenderer = $this->doc->getPageRenderer();
264  $pageRenderer->loadPrototype();
265  $pageRenderer->loadJQuery();
266  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Filelist/FileListLocalisation');
267 
268  // There there was access to this file path, continue, make the list
269  if ($this->folderObject) {
270 
271  // Create filelisting object
272  $this->filelist = GeneralUtility::makeInstance('TYPO3\\CMS\\Filelist\\FileList');
273  $this->filelist->backPath = $GLOBALS['BACK_PATH'];
274  // Apply predefined values for hidden checkboxes
275  // Set predefined value for DisplayBigControlPanel:
276  if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayBigControlPanel') === 'activated') {
277  $this->MOD_SETTINGS['bigControlPanel'] = TRUE;
278  } elseif ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayBigControlPanel') === 'deactivated') {
279  $this->MOD_SETTINGS['bigControlPanel'] = FALSE;
280  }
281  // Set predefined value for DisplayThumbnails:
282  if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayThumbnails') === 'activated') {
283  $this->MOD_SETTINGS['displayThumbs'] = TRUE;
284  } elseif ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayThumbnails') === 'deactivated') {
285  $this->MOD_SETTINGS['displayThumbs'] = FALSE;
286  }
287  // Set predefined value for Clipboard:
288  if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableClipBoard') === 'activated') {
289  $this->MOD_SETTINGS['clipBoard'] = TRUE;
290  } elseif ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableClipBoard') === 'deactivated') {
291  $this->MOD_SETTINGS['clipBoard'] = FALSE;
292  }
293  // If user never opened the list module, set the value for displayThumbs
294  if (!isset($this->MOD_SETTINGS['displayThumbs'])) {
295  $this->MOD_SETTINGS['displayThumbs'] = $GLOBALS['BE_USER']->uc['thumbnailsByDefault'];
296  }
297  $this->filelist->thumbs = $this->MOD_SETTINGS['displayThumbs'];
298  // Create clipboard object and initialize that
299  $this->filelist->clipObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Clipboard\\Clipboard');
300  $this->filelist->clipObj->fileMode = 1;
301  $this->filelist->clipObj->initializeClipboard();
302  $CB = GeneralUtility::_GET('CB');
303  if ($this->cmd == 'setCB') {
304  $CB['el'] = $this->filelist->clipObj->cleanUpCBC(array_merge(GeneralUtility::_POST('CBH'), (array)GeneralUtility::_POST('CBC')), '_FILE');
305  }
306  if (!$this->MOD_SETTINGS['clipBoard']) {
307  $CB['setP'] = 'normal';
308  }
309  $this->filelist->clipObj->setCmd($CB);
310  $this->filelist->clipObj->cleanCurrent();
311  // Saves
312  $this->filelist->clipObj->endClipboard();
313  // If the "cmd" was to delete files from the list (clipboard thing), do that:
314  if ($this->cmd == 'delete') {
315  $items = $this->filelist->clipObj->cleanUpCBC(GeneralUtility::_POST('CBC'), '_FILE', 1);
316  if (count($items)) {
317  // Make command array:
318  $FILE = array();
319  foreach ($items as $v) {
320  $FILE['delete'][] = array('data' => $v);
321  }
322  // Init file processing object for deleting and pass the cmd array.
323  $fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility');
324  $fileProcessor->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
325  $fileProcessor->setActionPermissions();
326  $fileProcessor->dontCheckForUnique = $this->overwriteExistingFiles ? 1 : 0;
327  $fileProcessor->start($FILE);
328  $fileProcessor->processData();
329  $fileProcessor->pushErrorMessagesToFlashMessageQueue();
330  }
331  }
332  if (!isset($this->MOD_SETTINGS['sort'])) {
333  // Set default sorting
334  $this->MOD_SETTINGS['sort'] = 'file';
335  $this->MOD_SETTINGS['reverse'] = 0;
336  }
337  // Start up filelisting object, include settings.
338  $this->pointer = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
339  $this->filelist->start($this->folderObject, $this->pointer, $this->MOD_SETTINGS['sort'], $this->MOD_SETTINGS['reverse'], $this->MOD_SETTINGS['clipBoard'], $this->MOD_SETTINGS['bigControlPanel']);
340  // Generate the list
341  $this->filelist->generateList();
342  // Set top JavaScript:
343  $this->doc->JScode = $this->doc->wrapScriptTags('if (top.fsMod) top.fsMod.recentIds["file"] = "' . rawurlencode($this->id) . '";' . $this->filelist->CBfunctions());
344  // This will return content necessary for the context sensitive clickmenus to work: bodytag events, JavaScript functions and DIV-layers.
345  $this->doc->getContextMenuCode();
346  // Setting up the buttons and markers for docheader
347  list($buttons, $otherMarkers) = $this->filelist->getButtonsAndOtherMarkers($this->folderObject);
348  // add the folder info to the marker array
349  $otherMarkers['FOLDER_INFO'] = $this->filelist->getFolderInfo();
350  $docHeaderButtons = array_merge($this->getButtons(), $buttons);
351 
352  // Include DragUploader only if we have write access
353  if ($this->folderObject->getStorage()->checkUserActionPermission('add', 'File')
354  && $this->folderObject->checkActionPermission('write')
355  ) {
356  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DragUploader');
357  $pageRenderer->addInlineLanguagelabelFile(
358  \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('lang') . 'locallang_core.xlf',
359  'file_upload'
360  );
361  }
362 
363  // Build the <body> for the module
364  $moduleHeadline = $this->getModuleHeadline();
365  // Create output
366  $pageContent = $moduleHeadline !== '' ? '<h1>' . $moduleHeadline . '</h1>' : '';
367 
368  $pageContent .= '<form action="' . htmlspecialchars($this->filelist->listURL()) . '" method="post" name="dblistForm">';
369  $pageContent .= $this->filelist->HTMLcode;
370  $pageContent .= '<input type="hidden" name="cmd" /></form>';
371 
372  // Making listing options:
373  if ($this->filelist->HTMLcode) {
374  $pageContent .= '
375 
376  <!--
377  Listing options for extended view, clipboard and thumbnails
378  -->
379  <div id="typo3-listOptions">
380  ';
381  // Add "display bigControlPanel" checkbox:
382  if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayBigControlPanel') === 'selectable') {
383  $pageContent .= BackendUtility::getFuncCheck($this->id, 'SET[bigControlPanel]', $this->MOD_SETTINGS['bigControlPanel'], '', '', 'id="bigControlPanel"') . '<label for="bigControlPanel"> ' . $GLOBALS['LANG']->getLL('bigControlPanel', TRUE) . '</label><br />';
384  }
385  // Add "display thumbnails" checkbox:
386  if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableDisplayThumbnails') === 'selectable') {
387  $pageContent .= BackendUtility::getFuncCheck($this->id, 'SET[displayThumbs]', $this->MOD_SETTINGS['displayThumbs'], '', '', 'id="checkDisplayThumbs"') . ' <label for="checkDisplayThumbs">' . $GLOBALS['LANG']->getLL('displayThumbs', TRUE) . '</label><br />';
388  }
389  // Add "clipboard" checkbox:
390  if ($GLOBALS['BE_USER']->getTSConfigVal('options.file_list.enableClipBoard') === 'selectable') {
391  $pageContent .= BackendUtility::getFuncCheck($this->id, 'SET[clipBoard]', $this->MOD_SETTINGS['clipBoard'], '', '', 'id="checkClipBoard"') . ' <label for="checkClipBoard">' . $GLOBALS['LANG']->getLL('clipBoard', TRUE) . '</label>';
392  }
393  $pageContent .= '
394  </div>
395  ';
396  // Set clipboard:
397  if ($this->MOD_SETTINGS['clipBoard']) {
398  $pageContent .= $this->filelist->clipObj->printClipboard();
399  $pageContent .= BackendUtility::cshItem('xMOD_csh_corebe', 'filelist_clipboard', $GLOBALS['BACK_PATH']);
400  }
401  }
402  $markerArray = array(
403  'CSH' => $docHeaderButtons['csh'],
404  'FUNC_MENU' => BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
405  'CONTENT' => ($this->errorMessage ? $this->errorMessage->render() : '') . $pageContent,
406  'FOLDER_IDENTIFIER' => $this->folderObject->getCombinedIdentifier(),
407  'FILEDENYPATERN' => $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'],
408  'MAXFILESIZE' => GeneralUtility::getMaxUploadFileSize() * 1024,
409  );
410  $this->content = $this->doc->moduleBody(array(), $docHeaderButtons, array_merge($markerArray, $otherMarkers));
411  // Renders the module page
412  $this->content = $this->doc->render($GLOBALS['LANG']->getLL('files'), $this->content);
413  } else {
414  $content = '';
415  if ($this->errorMessage) {
416  $this->errorMessage->setSeverity(\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
417  $content = $this->doc->moduleBody(array(), array_merge(array('REFRESH' => '', 'PASTE' => '', 'LEVEL_UP' => ''), $this->getButtons()), array('CSH' => '', 'TITLE' => '', 'FOLDER_INFO' => '', 'PAGE_ICON' => '', 'FUNC_MENU' => '', 'CONTENT' => $this->errorMessage->render()));
418  }
419  // Create output - no access (no warning though)
420  $this->content = $this->doc->render($GLOBALS['LANG']->getLL('files'), $content);
421  }
422  }
423 
431  protected function getModuleHeadline() {
432  $name = $this->folderObject->getName();
433  if ($name === '') {
434  // Show storage name on storage root
435  if ($this->folderObject->getIdentifier() === '/') {
436  $name = $this->folderObject->getStorage()->getName();
437  }
438  } else {
439  $name = key(\TYPO3\CMS\Core\Resource\Utility\ListUtility::resolveSpecialFolderNames(
440  array($name => $this->folderObject)
441  ));
442  }
443  return $name;
444  }
445 
452  public function printContent() {
453  echo $this->content;
454  }
455 
462  public function getButtons() {
463  $buttons = array(
464  'csh' => '',
465  'shortcut' => '',
466  'upload' => '',
467  'new' => ''
468  );
469  // Add shortcut
470  if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
471  $buttons['shortcut'] = $this->doc->makeShortcutIcon('pointer,id,target,table', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name']);
472  }
473  // FileList Module CSH:
474  $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'filelist_module', $GLOBALS['BACK_PATH'], '', TRUE);
475  // Upload button (only if upload to this directory is allowed)
476  if ($this->folderObject && $this->folderObject->getStorage()->checkUserActionPermission('add', 'File') && $this->folderObject->checkActionPermission('write')) {
477  $buttons['upload'] = '<a href="' . $GLOBALS['BACK_PATH'] . 'file_upload.php?target=' . rawurlencode($this->folderObject->getCombinedIdentifier()) . '&amp;returnUrl=' . rawurlencode($this->filelist->listURL()) . '" id="button-upload" title="' . $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.upload', TRUE)) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-edit-upload') . '</a>';
478  }
479  // New folder button
480  if ($this->folderObject && $this->folderObject->checkActionPermission('write')
481  && ($this->folderObject->getStorage()->checkUserActionPermission('add', 'File') || $this->folderObject->checkActionPermission('add'))
482  ) {
483  $buttons['new'] = '<a href="' . $GLOBALS['BACK_PATH'] . 'file_newfolder.php?target=' . rawurlencode($this->folderObject->getCombinedIdentifier()) . '&amp;returnUrl=' . rawurlencode($this->filelist->listURL()) . '" title="' . $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.new', TRUE)) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-new') . '</a>';
484  }
485  return $buttons;
486  }
487 
488 }
static getFuncCheck($mainParams, $elementName, $currentValue, $script='', $addParams='', $tagParams='')
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
static cshItem($table, $field, $BACK_PATH, $wrap='', $onlyIconMode=FALSE, $styleAttrib='')
static getMaxUploadFileSize($localLimit=0)
static getModuleData($MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='')
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'][]