[TASK] Deprecate ExtendedFileUtility::pushErrorMessagesToFlashMessageQueue
[Packages/TYPO3.CMS.git] / typo3 / sysext / filelist / Classes / Controller / FileListController.php
1 <?php
2 namespace TYPO3\CMS\Filelist\Controller;
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 TYPO3\CMS\Backend\Clipboard\Clipboard;
18 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
19 use TYPO3\CMS\Backend\Template\DocumentTemplate;
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
21 use TYPO3\CMS\Backend\View\BackendTemplateView;
22 use TYPO3\CMS\Core\Imaging\Icon;
23 use TYPO3\CMS\Core\Imaging\IconFactory;
24 use TYPO3\CMS\Core\Messaging\FlashMessage;
25 use TYPO3\CMS\Core\Resource\DuplicationBehavior;
26 use TYPO3\CMS\Core\Resource\Exception;
27 use TYPO3\CMS\Core\Resource\Folder;
28 use TYPO3\CMS\Core\Resource\ResourceFactory;
29 use TYPO3\CMS\Core\Resource\Utility\ListUtility;
30 use TYPO3\CMS\Core\Type\Bitmask\JsConfirmation;
31 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
32 use TYPO3\CMS\Core\Utility\File\ExtendedFileUtility;
33 use TYPO3\CMS\Core\Utility\GeneralUtility;
34 use TYPO3\CMS\Core\Utility\MathUtility;
35 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
36 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
37 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
38 use TYPO3\CMS\Filelist\FileList;
39
40 /**
41 * Script Class for creating the list of files in the File > Filelist module
42 */
43 class FileListController extends ActionController
44 {
45 /**
46 * @var array
47 */
48 public $MOD_MENU = array();
49
50 /**
51 * @var array
52 */
53 public $MOD_SETTINGS = array();
54
55 /**
56 * Document template object
57 *
58 * @var DocumentTemplate
59 */
60 public $doc;
61
62 /**
63 * "id" -> the path to list.
64 *
65 * @var string
66 */
67 public $id;
68
69 /**
70 * @var Folder
71 */
72 protected $folderObject;
73
74 /**
75 * @var FlashMessage
76 */
77 protected $errorMessage;
78
79 /**
80 * Pointer to listing
81 *
82 * @var int
83 */
84 public $pointer;
85
86 /**
87 * "Table"
88 * @var string
89 */
90 public $table;
91
92 /**
93 * Thumbnail mode.
94 *
95 * @var string
96 */
97 public $imagemode;
98
99 /**
100 * @var string
101 */
102 public $cmd;
103
104 /**
105 * Defines behaviour when uploading files with names that already exist; possible values are
106 * the values of the \TYPO3\CMS\Core\Resource\DuplicationBehavior enumeration
107 *
108 * @var \TYPO3\CMS\Core\Resource\DuplicationBehavior
109 */
110 protected $overwriteExistingFiles;
111
112 /**
113 * The filelist object
114 *
115 * @var FileList
116 */
117 public $filelist = null;
118
119 /**
120 * The name of the module
121 *
122 * @var string
123 */
124 protected $moduleName = 'file_list';
125
126 /**
127 * @var \TYPO3\CMS\Core\Resource\FileRepository
128 */
129 protected $fileRepository;
130
131 /**
132 * @var BackendTemplateView
133 */
134 protected $view;
135
136 /**
137 * BackendTemplateView Container
138 *
139 * @var BackendTemplateView
140 */
141 protected $defaultViewObjectName = BackendTemplateView::class;
142
143 /**
144 * @param \TYPO3\CMS\Core\Resource\FileRepository $fileRepository
145 */
146 public function injectFileRepository(\TYPO3\CMS\Core\Resource\FileRepository $fileRepository)
147 {
148 $this->fileRepository = $fileRepository;
149 }
150
151 /**
152 * Initialize variables, file object
153 * Incoming GET vars include id, pointer, table, imagemode
154 *
155 * @return void
156 * @throws \RuntimeException
157 * @throws Exception\InsufficientFolderAccessPermissionsException
158 */
159 public function initializeObject()
160 {
161 $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
162 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_mod_file_list.xlf');
163 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_misc.xlf');
164
165 // Setting GPvars:
166 $this->id = ($combinedIdentifier = GeneralUtility::_GP('id'));
167 $this->pointer = GeneralUtility::_GP('pointer');
168 $this->table = GeneralUtility::_GP('table');
169 $this->imagemode = GeneralUtility::_GP('imagemode');
170 $this->cmd = GeneralUtility::_GP('cmd');
171 $this->overwriteExistingFiles = DuplicationBehavior::cast(GeneralUtility::_GP('overwriteExistingFiles'));
172
173 try {
174 if ($combinedIdentifier) {
175 /** @var $resourceFactory ResourceFactory */
176 $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
177 $storage = $resourceFactory->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
178 $identifier = substr($combinedIdentifier, strpos($combinedIdentifier, ':') + 1);
179 if (!$storage->hasFolder($identifier)) {
180 $identifier = $storage->getFolderIdentifierFromFileIdentifier($identifier);
181 }
182
183 $this->folderObject = $resourceFactory->getFolderObjectFromCombinedIdentifier($storage->getUid() . ':' . $identifier);
184 // Disallow access to fallback storage 0
185 if ($storage->getUid() === 0) {
186 throw new Exception\InsufficientFolderAccessPermissionsException('You are not allowed to access files outside your storages',
187 1434539815);
188 }
189 // Disallow the rendering of the processing folder (e.g. could be called manually)
190 if ($this->folderObject && $storage->isProcessingFolder($this->folderObject)) {
191 $this->folderObject = $storage->getRootLevelFolder();
192 }
193 } else {
194 // Take the first object of the first storage
195 $fileStorages = $this->getBackendUser()->getFileStorages();
196 $fileStorage = reset($fileStorages);
197 if ($fileStorage) {
198 $this->folderObject = $fileStorage->getRootLevelFolder();
199 } else {
200 throw new \RuntimeException('Could not find any folder to be displayed.', 1349276894);
201 }
202 }
203
204 if ($this->folderObject && !$this->folderObject->getStorage()->isWithinFileMountBoundaries($this->folderObject)) {
205 throw new \RuntimeException('Folder not accessible.', 1430409089);
206 }
207 } catch (Exception\InsufficientFolderAccessPermissionsException $permissionException) {
208 $this->folderObject = null;
209 $this->errorMessage = GeneralUtility::makeInstance(FlashMessage::class,
210 sprintf(
211 $this->getLanguageService()->getLL('missingFolderPermissionsMessage', true),
212 htmlspecialchars($this->id)
213 ),
214 $this->getLanguageService()->getLL('missingFolderPermissionsTitle', true),
215 FlashMessage::NOTICE
216 );
217 } catch (Exception $fileException) {
218 // Set folder object to null and throw a message later on
219 $this->folderObject = null;
220 // Take the first object of the first storage
221 $fileStorages = $this->getBackendUser()->getFileStorages();
222 $fileStorage = reset($fileStorages);
223 if ($fileStorage instanceof \TYPO3\CMS\Core\Resource\ResourceStorage) {
224 $this->folderObject = $fileStorage->getRootLevelFolder();
225 if (!$fileStorage->isWithinFileMountBoundaries($this->folderObject)) {
226 $this->folderObject = null;
227 }
228 }
229 $this->errorMessage = GeneralUtility::makeInstance(FlashMessage::class,
230 sprintf(
231 $this->getLanguageService()->getLL('folderNotFoundMessage', true),
232 htmlspecialchars($this->id)
233 ),
234 $this->getLanguageService()->getLL('folderNotFoundTitle', true),
235 FlashMessage::NOTICE
236 );
237 } catch (\RuntimeException $e) {
238 $this->folderObject = null;
239 $this->errorMessage = GeneralUtility::makeInstance(FlashMessage::class,
240 $e->getMessage() . ' (' . $e->getCode() . ')',
241 $this->getLanguageService()->getLL('folderNotFoundTitle', true),
242 FlashMessage::NOTICE
243 );
244 }
245
246 if ($this->folderObject && !$this->folderObject->getStorage()->checkFolderActionPermission('read',
247 $this->folderObject)
248 ) {
249 $this->folderObject = null;
250 }
251
252 // Configure the "menu" - which is used internally to save the values of sorting, displayThumbs etc.
253 $this->menuConfig();
254 }
255
256 /**
257 * Setting the menu/session variables
258 *
259 * @return void
260 */
261 public function menuConfig()
262 {
263 // MENU-ITEMS:
264 // If array, then it's a selector box menu
265 // If empty string it's just a variable, that will be saved.
266 // Values NOT in this array will not be saved in the settings-array for the module.
267 $this->MOD_MENU = array(
268 'sort' => '',
269 'reverse' => '',
270 'displayThumbs' => '',
271 'clipBoard' => '',
272 'bigControlPanel' => ''
273 );
274 // CLEANSE SETTINGS
275 $this->MOD_SETTINGS = BackendUtility::getModuleData(
276 $this->MOD_MENU,
277 GeneralUtility::_GP('SET'),
278 $this->moduleName
279 );
280 }
281
282 /**
283 * Initialize the view
284 *
285 * @param ViewInterface $view The view
286 * @return void
287 */
288 public function initializeView(ViewInterface $view)
289 {
290 /** @var BackendTemplateView $view */
291 parent::initializeView($view);
292 $pageRenderer = $this->view->getModuleTemplate()->getPageRenderer();
293 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Filelist/FileListLocalisation');
294 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Filelist/FileSearch');
295 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
296 $this->registerDocHeaderButtons();
297 }
298
299 /**
300 * @return void
301 */
302 public function initializeIndexAction()
303 {
304 // Apply predefined values for hidden checkboxes
305 // Set predefined value for DisplayBigControlPanel:
306 $backendUser = $this->getBackendUser();
307 if ($backendUser->getTSConfigVal('options.file_list.enableDisplayBigControlPanel') === 'activated') {
308 $this->MOD_SETTINGS['bigControlPanel'] = true;
309 } elseif ($backendUser->getTSConfigVal('options.file_list.enableDisplayBigControlPanel') === 'deactivated') {
310 $this->MOD_SETTINGS['bigControlPanel'] = false;
311 }
312 // Set predefined value for DisplayThumbnails:
313 if ($backendUser->getTSConfigVal('options.file_list.enableDisplayThumbnails') === 'activated') {
314 $this->MOD_SETTINGS['displayThumbs'] = true;
315 } elseif ($backendUser->getTSConfigVal('options.file_list.enableDisplayThumbnails') === 'deactivated') {
316 $this->MOD_SETTINGS['displayThumbs'] = false;
317 }
318 // Set predefined value for Clipboard:
319 if ($backendUser->getTSConfigVal('options.file_list.enableClipBoard') === 'activated') {
320 $this->MOD_SETTINGS['clipBoard'] = true;
321 } elseif ($backendUser->getTSConfigVal('options.file_list.enableClipBoard') === 'deactivated') {
322 $this->MOD_SETTINGS['clipBoard'] = false;
323 }
324 // If user never opened the list module, set the value for displayThumbs
325 if (!isset($this->MOD_SETTINGS['displayThumbs'])) {
326 $this->MOD_SETTINGS['displayThumbs'] = $backendUser->uc['thumbnailsByDefault'];
327 }
328 if (!isset($this->MOD_SETTINGS['sort'])) {
329 // Set default sorting
330 $this->MOD_SETTINGS['sort'] = 'file';
331 $this->MOD_SETTINGS['reverse'] = 0;
332 }
333 }
334
335 /**
336 * @return void
337 */
338 public function indexAction()
339 {
340 $pageRenderer = $this->view->getModuleTemplate()->getPageRenderer();
341 $pageRenderer->setTitle($this->getLanguageService()->getLL('files'));
342
343 // There there was access to this file path, continue, make the list
344 if ($this->folderObject) {
345 // Create fileListing object
346 $this->filelist = GeneralUtility::makeInstance(FileList::class, $this);
347 $this->filelist->thumbs = $GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'] && $this->MOD_SETTINGS['displayThumbs'];
348 // Create clipboard object and initialize that
349 $this->filelist->clipObj = GeneralUtility::makeInstance(Clipboard::class);
350 $this->filelist->clipObj->fileMode = 1;
351 $this->filelist->clipObj->initializeClipboard();
352 $CB = GeneralUtility::_GET('CB');
353 if ($this->cmd == 'setCB') {
354 $CB['el'] = $this->filelist->clipObj->cleanUpCBC(array_merge(GeneralUtility::_POST('CBH'),
355 (array)GeneralUtility::_POST('CBC')), '_FILE');
356 }
357 if (!$this->MOD_SETTINGS['clipBoard']) {
358 $CB['setP'] = 'normal';
359 }
360 $this->filelist->clipObj->setCmd($CB);
361 $this->filelist->clipObj->cleanCurrent();
362 // Saves
363 $this->filelist->clipObj->endClipboard();
364 // If the "cmd" was to delete files from the list (clipboard thing), do that:
365 if ($this->cmd == 'delete') {
366 $items = $this->filelist->clipObj->cleanUpCBC(GeneralUtility::_POST('CBC'), '_FILE', 1);
367 if (!empty($items)) {
368 // Make command array:
369 $FILE = array();
370 foreach ($items as $v) {
371 $FILE['delete'][] = array('data' => $v);
372 }
373 // Init file processing object for deleting and pass the cmd array.
374 /** @var ExtendedFileUtility $fileProcessor */
375 $fileProcessor = GeneralUtility::makeInstance(ExtendedFileUtility::class);
376 $fileProcessor->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
377 $fileProcessor->setActionPermissions();
378 $fileProcessor->setExistingFilesConflictMode($this->overwriteExistingFiles);
379 $fileProcessor->start($FILE);
380 $fileProcessor->processData();
381 }
382 }
383 // Start up filelisting object, include settings.
384 $this->pointer = MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
385 $this->filelist->start($this->folderObject, $this->pointer, $this->MOD_SETTINGS['sort'],
386 $this->MOD_SETTINGS['reverse'], $this->MOD_SETTINGS['clipBoard'],
387 $this->MOD_SETTINGS['bigControlPanel']);
388 // Generate the list
389 $this->filelist->generateList();
390 // Set top JavaScript:
391 $this->view->getModuleTemplate()->addJavaScriptCode(
392 'FileListIndex',
393 'if (top.fsMod) top.fsMod.recentIds["file"] = "' . rawurlencode($this->id) . '";' . $this->filelist->CBfunctions() . '
394 function jumpToUrl(URL) {
395 window.location.href = URL;
396 return false;
397 }
398 ');
399
400 // Include DragUploader only if we have write access
401 if ($this->folderObject->getStorage()->checkUserActionPermission('add', 'File')
402 && $this->folderObject->checkActionPermission('write')
403 ) {
404 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DragUploader');
405 $pageRenderer->addInlineLanguageLabelFile(
406 ExtensionManagementUtility::extPath('lang') . 'locallang_core.xlf',
407 'file_upload'
408 );
409 }
410
411 // Setting up the buttons
412 $this->registerButtons();
413
414 $pageRecord = [
415 '_additional_info' => $this->filelist->getFolderInfo(),
416 'combined_identifier' => $this->folderObject->getCombinedIdentifier(),
417 ];
418 $this->view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation($pageRecord);
419
420 $this->view->assign('headline', $this->getModuleHeadline());
421 $this->view->assign('listHtml', $this->filelist->HTMLcode);
422
423 $this->view->assign('checkboxes', [
424 'bigControlPanel' => [
425 'enabled' => $this->getBackendUser()->getTSConfigVal('options.file_list.enableDisplayBigControlPanel') === 'selectable',
426 'label' => $this->getLanguageService()->getLL('bigControlPanel', true),
427 'html' => BackendUtility::getFuncCheck($this->id, 'SET[bigControlPanel]',
428 $this->MOD_SETTINGS['bigControlPanel'], '', '', 'id="bigControlPanel"'),
429 ],
430 'displayThumbs' => [
431 'enabled' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'] && $this->getBackendUser()->getTSConfigVal('options.file_list.enableDisplayThumbnails') === 'selectable',
432 'label' => $this->getLanguageService()->getLL('displayThumbs', true),
433 'html' => BackendUtility::getFuncCheck($this->id, 'SET[displayThumbs]',
434 $this->MOD_SETTINGS['displayThumbs'], '', '', 'id="checkDisplayThumbs"'),
435 ],
436 'enableClipBoard' => [
437 'enabled' => $this->getBackendUser()->getTSConfigVal('options.file_list.enableClipBoard') === 'selectable',
438 'label' => $this->getLanguageService()->getLL('clipBoard', true),
439 'html' => BackendUtility::getFuncCheck($this->id, 'SET[clipBoard]',
440 $this->MOD_SETTINGS['clipBoard'], '', '', 'id="checkClipBoard"'),
441 ]
442 ]);
443 $this->view->assign('showClipBoard', (bool)$this->MOD_SETTINGS['clipBoard']);
444 $this->view->assign('clipBoardHtml', $this->filelist->clipObj->printClipboard());
445 $this->view->assign('folderIdentifier', $this->folderObject->getCombinedIdentifier());
446 $this->view->assign('fileDenyPattern', $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern']);
447 $this->view->assign('maxFileSize', GeneralUtility::getMaxUploadFileSize() * 1024);
448 } else {
449 $this->forward('missingFolder');
450 }
451 }
452
453 /**
454 * @return void
455 */
456 public function missingFolderAction()
457 {
458 if ($this->errorMessage) {
459 $this->errorMessage->setSeverity(FlashMessage::ERROR);
460 $this->controllerContext->getFlashMessageQueue('core.template.flashMessages')->addMessage($this->errorMessage);
461 }
462 }
463
464 /**
465 * Search for files by name and pass them with a facade to fluid
466 *
467 * @param string $searchWord
468 */
469 public function searchAction($searchWord = '')
470 {
471 if (empty($searchWord)) {
472 $this->forward('index');
473 }
474
475 $fileFacades = [];
476 $files = $this->fileRepository->searchByName($this->folderObject, $searchWord);
477
478 if (empty($files)) {
479 $this->controllerContext->getFlashMessageQueue('core.template.flashMessages')->addMessage(
480 new FlashMessage(LocalizationUtility::translate('flashmessage.no_results', 'filelist'), '',
481 FlashMessage::INFO)
482 );
483 } else {
484 foreach ($files as $file) {
485 $fileFacades[] = new \TYPO3\CMS\Filelist\FileFacade($file);
486 }
487 }
488
489 $pageRenderer = $this->view->getModuleTemplate()->getPageRenderer();
490 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Filelist/FileList');
491
492 $this->view->assign('searchWord', $searchWord);
493 $this->view->assign('files', $fileFacades);
494 $this->view->assign('settings', [
495 'jsConfirmationDelete' => $this->getBackendUser()->jsConfirmation(JsConfirmation::DELETE)
496 ]);
497 }
498
499 /**
500 * Get main headline based on active folder or storage for backend module
501 * Folder names are resolved to their special names like done in the tree view.
502 *
503 * @return string
504 */
505 protected function getModuleHeadline()
506 {
507 $name = $this->folderObject->getName();
508 if ($name === '') {
509 // Show storage name on storage root
510 if ($this->folderObject->getIdentifier() === '/') {
511 $name = $this->folderObject->getStorage()->getName();
512 }
513 } else {
514 $name = key(ListUtility::resolveSpecialFolderNames(
515 array($name => $this->folderObject)
516 ));
517 }
518 return $name;
519 }
520
521 /**
522 * Registers the Icons into the docheader
523 *
524 * @return void
525 * @throws \InvalidArgumentException
526 */
527 protected function registerDocHeaderButtons()
528 {
529 /** @var ButtonBar $buttonBar */
530 $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
531
532 // CSH
533 $cshButton = $buttonBar->makeHelpButton()
534 ->setModuleName('xMOD_csh_corebe')
535 ->setFieldName('filelist_module');
536 $buttonBar->addButton($cshButton);
537 }
538
539 /**
540 * Create the panel of buttons for submitting the form or otherwise perform operations.
541 *
542 * @return array All available buttons as an assoc. array
543 */
544 protected function registerButtons()
545 {
546 /** @var ButtonBar $buttonBar */
547 $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
548
549 /** @var IconFactory $iconFactory */
550 $iconFactory = $this->view->getModuleTemplate()->getIconFactory();
551
552 /** @var $resourceFactory ResourceFactory */
553 $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
554
555 $lang = $this->getLanguageService();
556
557 // Refresh page
558 $refreshLink = GeneralUtility::linkThisScript(
559 array(
560 'target' => rawurlencode($this->folderObject->getCombinedIdentifier()),
561 'imagemode' => $this->filelist->thumbs
562 )
563 );
564 $refreshButton = $buttonBar->makeLinkButton()
565 ->setHref($refreshLink)
566 ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.reload'))
567 ->setIcon($iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL));
568 $buttonBar->addButton($refreshButton, ButtonBar::BUTTON_POSITION_RIGHT);
569
570 // Level up
571 try {
572 $currentStorage = $this->folderObject->getStorage();
573 $parentFolder = $this->folderObject->getParentFolder();
574 if ($parentFolder->getIdentifier() !== $this->folderObject->getIdentifier()
575 && $currentStorage->isWithinFileMountBoundaries($parentFolder)
576 ) {
577 $levelUpClick = 'top.document.getElementsByName("navigation")[0].contentWindow.Tree.highlightActiveItem("file","folder'
578 . GeneralUtility::md5int($parentFolder->getCombinedIdentifier()) . '_"+top.fsMod.currentBank)';
579 $levelUpButton = $buttonBar->makeLinkButton()
580 ->setHref(BackendUtility::getModuleUrl('file_FilelistList', ['id' => $parentFolder->getCombinedIdentifier()]))
581 ->setOnClick($levelUpClick)
582 ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.upOneLevel'))
583 ->setIcon($iconFactory->getIcon('actions-view-go-up', Icon::SIZE_SMALL));
584 $buttonBar->addButton($levelUpButton, ButtonBar::BUTTON_POSITION_LEFT, 1);
585 }
586 } catch (\Exception $e) {
587 }
588
589 // Shortcut
590 if ($this->getBackendUser()->mayMakeShortcut()) {
591 $shortCutButton = $buttonBar->makeShortcutButton()->setModuleName('file_FilelistList');
592 $buttonBar->addButton($shortCutButton, ButtonBar::BUTTON_POSITION_RIGHT);
593 }
594
595 // Upload button (only if upload to this directory is allowed)
596 if ($this->folderObject && $this->folderObject->getStorage()->checkUserActionPermission('add',
597 'File') && $this->folderObject->checkActionPermission('write')
598 ) {
599 $uploadButton = $buttonBar->makeLinkButton()
600 ->setHref(BackendUtility::getModuleUrl(
601 'file_upload',
602 array(
603 'target' => $this->folderObject->getCombinedIdentifier(),
604 'returnUrl' => $this->filelist->listURL(),
605 )
606 ))
607 ->setClasses('t3js-drag-uploader-trigger')
608 ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:cm.upload'))
609 ->setIcon($iconFactory->getIcon('actions-edit-upload', Icon::SIZE_SMALL));
610 $buttonBar->addButton($uploadButton, ButtonBar::BUTTON_POSITION_LEFT, 1);
611 }
612
613 // New folder button
614 if ($this->folderObject && $this->folderObject->checkActionPermission('write')
615 && ($this->folderObject->getStorage()->checkUserActionPermission('add',
616 'File') || $this->folderObject->checkActionPermission('add'))
617 ) {
618 $newButton = $buttonBar->makeLinkButton()
619 ->setHref(BackendUtility::getModuleUrl(
620 'file_newfolder',
621 array(
622 'target' => $this->folderObject->getCombinedIdentifier(),
623 'returnUrl' => $this->filelist->listURL(),
624 )
625 ))
626 ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:cm.new'))
627 ->setIcon($iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL));
628 $buttonBar->addButton($newButton, ButtonBar::BUTTON_POSITION_LEFT, 1);
629 }
630
631 // Add paste button if clipboard is initialized
632 if ($this->filelist->clipObj instanceof Clipboard && $this->folderObject->checkActionPermission('write')) {
633 $elFromTable = $this->filelist->clipObj->elFromTable('_FILE');
634 if (!empty($elFromTable)) {
635 $addPasteButton = true;
636 $elToConfirm = array();
637 foreach ($elFromTable as $key => $element) {
638 $clipBoardElement = $resourceFactory->retrieveFileOrFolderObject($element);
639 if ($clipBoardElement instanceof Folder && $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement,
640 $this->folderObject)
641 ) {
642 $addPasteButton = false;
643 }
644 $elToConfirm[$key] = $clipBoardElement->getName();
645 }
646 if ($addPasteButton) {
647 $pasteButton = $buttonBar->makeLinkButton()
648 ->setHref($this->filelist->clipObj->pasteUrl('_FILE',
649 $this->folderObject->getCombinedIdentifier()))
650 ->setOnClick('return ' . $this->filelist->clipObj->confirmMsg('_FILE',
651 $this->folderObject->getReadablePath(), 'into', $elToConfirm))
652 ->setTitle($lang->getLL('clip_paste'))
653 ->setIcon($iconFactory->getIcon('actions-document-paste-after', Icon::SIZE_SMALL));
654 $buttonBar->addButton($pasteButton, ButtonBar::BUTTON_POSITION_LEFT, 2);
655 }
656 }
657 }
658 }
659
660 /**
661 * Returns an instance of LanguageService
662 *
663 * @return \TYPO3\CMS\Lang\LanguageService
664 */
665 protected function getLanguageService()
666 {
667 return $GLOBALS['LANG'];
668 }
669
670 /**
671 * Returns the current BE user.
672 *
673 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
674 */
675 protected function getBackendUser()
676 {
677 return $GLOBALS['BE_USER'];
678 }
679 }