[!!!][TASK] Removed deprecated image/filehandling functions
[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 $fileProcessor->pushErrorMessagesToFlashMessageQueue();
382 }
383 }
384 // Start up filelisting object, include settings.
385 $this->pointer = MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
386 $this->filelist->start($this->folderObject, $this->pointer, $this->MOD_SETTINGS['sort'],
387 $this->MOD_SETTINGS['reverse'], $this->MOD_SETTINGS['clipBoard'],
388 $this->MOD_SETTINGS['bigControlPanel']);
389 // Generate the list
390 $this->filelist->generateList();
391 // Set top JavaScript:
392 $this->view->getModuleTemplate()->addJavaScriptCode(
393 'FileListIndex',
394 'if (top.fsMod) top.fsMod.recentIds["file"] = "' . rawurlencode($this->id) . '";' . $this->filelist->CBfunctions() . '
395 function jumpToUrl(URL) {
396 window.location.href = URL;
397 return false;
398 }
399 ');
400
401 // Include DragUploader only if we have write access
402 if ($this->folderObject->getStorage()->checkUserActionPermission('add', 'File')
403 && $this->folderObject->checkActionPermission('write')
404 ) {
405 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DragUploader');
406 $pageRenderer->addInlineLanguageLabelFile(
407 ExtensionManagementUtility::extPath('lang') . 'locallang_core.xlf',
408 'file_upload'
409 );
410 }
411
412 // Setting up the buttons
413 $this->registerButtons();
414
415 $pageRecord = [
416 '_additional_info' => $this->filelist->getFolderInfo(),
417 'combined_identifier' => $this->folderObject->getCombinedIdentifier(),
418 ];
419 $this->view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation($pageRecord);
420
421 $this->view->assign('headline', $this->getModuleHeadline());
422 $this->view->assign('listHtml', $this->filelist->HTMLcode);
423
424 $this->view->assign('checkboxes', [
425 'bigControlPanel' => [
426 'enabled' => $this->getBackendUser()->getTSConfigVal('options.file_list.enableDisplayBigControlPanel') === 'selectable',
427 'label' => $this->getLanguageService()->getLL('bigControlPanel', true),
428 'html' => BackendUtility::getFuncCheck($this->id, 'SET[bigControlPanel]',
429 $this->MOD_SETTINGS['bigControlPanel'], '', '', 'id="bigControlPanel"'),
430 ],
431 'displayThumbs' => [
432 'enabled' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'] && $this->getBackendUser()->getTSConfigVal('options.file_list.enableDisplayThumbnails') === 'selectable',
433 'label' => $this->getLanguageService()->getLL('displayThumbs', true),
434 'html' => BackendUtility::getFuncCheck($this->id, 'SET[displayThumbs]',
435 $this->MOD_SETTINGS['displayThumbs'], '', '', 'id="checkDisplayThumbs"'),
436 ],
437 'enableClipBoard' => [
438 'enabled' => $this->getBackendUser()->getTSConfigVal('options.file_list.enableClipBoard') === 'selectable',
439 'label' => $this->getLanguageService()->getLL('clipBoard', true),
440 'html' => BackendUtility::getFuncCheck($this->id, 'SET[clipBoard]',
441 $this->MOD_SETTINGS['clipBoard'], '', '', 'id="checkClipBoard"'),
442 ]
443 ]);
444 $this->view->assign('showClipBoard', (bool)$this->MOD_SETTINGS['clipBoard']);
445 $this->view->assign('clipBoardHtml', $this->filelist->clipObj->printClipboard());
446 $this->view->assign('folderIdentifier', $this->folderObject->getCombinedIdentifier());
447 $this->view->assign('fileDenyPattern', $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern']);
448 $this->view->assign('maxFileSize', GeneralUtility::getMaxUploadFileSize() * 1024);
449 } else {
450 $this->forward('missingFolder');
451 }
452 }
453
454 /**
455 * @return void
456 */
457 public function missingFolderAction()
458 {
459 if ($this->errorMessage) {
460 $this->errorMessage->setSeverity(FlashMessage::ERROR);
461 $this->controllerContext->getFlashMessageQueue('core.template.flashMessages')->addMessage($this->errorMessage);
462 }
463 }
464
465 /**
466 * Search for files by name and pass them with a facade to fluid
467 *
468 * @param string $searchWord
469 */
470 public function searchAction($searchWord = '')
471 {
472 if (empty($searchWord)) {
473 $this->forward('index');
474 }
475
476 $fileFacades = [];
477 $files = $this->fileRepository->searchByName($this->folderObject, $searchWord);
478
479 if (empty($files)) {
480 $this->controllerContext->getFlashMessageQueue('core.template.flashMessages')->addMessage(
481 new FlashMessage(LocalizationUtility::translate('flashmessage.no_results', 'filelist'), '',
482 FlashMessage::INFO)
483 );
484 } else {
485 foreach ($files as $file) {
486 $fileFacades[] = new \TYPO3\CMS\Filelist\FileFacade($file);
487 }
488 }
489
490 $pageRenderer = $this->view->getModuleTemplate()->getPageRenderer();
491 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Filelist/FileList');
492
493 $this->view->assign('searchWord', $searchWord);
494 $this->view->assign('files', $fileFacades);
495 $this->view->assign('settings', [
496 'jsConfirmationDelete' => $this->getBackendUser()->jsConfirmation(JsConfirmation::DELETE)
497 ]);
498 }
499
500 /**
501 * Get main headline based on active folder or storage for backend module
502 * Folder names are resolved to their special names like done in the tree view.
503 *
504 * @return string
505 */
506 protected function getModuleHeadline()
507 {
508 $name = $this->folderObject->getName();
509 if ($name === '') {
510 // Show storage name on storage root
511 if ($this->folderObject->getIdentifier() === '/') {
512 $name = $this->folderObject->getStorage()->getName();
513 }
514 } else {
515 $name = key(ListUtility::resolveSpecialFolderNames(
516 array($name => $this->folderObject)
517 ));
518 }
519 return $name;
520 }
521
522 /**
523 * Registers the Icons into the docheader
524 *
525 * @return void
526 * @throws \InvalidArgumentException
527 */
528 protected function registerDocHeaderButtons()
529 {
530 /** @var ButtonBar $buttonBar */
531 $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
532
533 // CSH
534 $cshButton = $buttonBar->makeHelpButton()
535 ->setModuleName('xMOD_csh_corebe')
536 ->setFieldName('filelist_module');
537 $buttonBar->addButton($cshButton);
538 }
539
540 /**
541 * Create the panel of buttons for submitting the form or otherwise perform operations.
542 *
543 * @return array All available buttons as an assoc. array
544 */
545 protected function registerButtons()
546 {
547 /** @var ButtonBar $buttonBar */
548 $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
549
550 /** @var IconFactory $iconFactory */
551 $iconFactory = $this->view->getModuleTemplate()->getIconFactory();
552
553 /** @var $resourceFactory ResourceFactory */
554 $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
555
556 $lang = $this->getLanguageService();
557
558 // Refresh page
559 $refreshLink = GeneralUtility::linkThisScript(
560 array(
561 'target' => rawurlencode($this->folderObject->getCombinedIdentifier()),
562 'imagemode' => $this->filelist->thumbs
563 )
564 );
565 $refreshButton = $buttonBar->makeLinkButton()
566 ->setHref($refreshLink)
567 ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.reload'))
568 ->setIcon($iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL));
569 $buttonBar->addButton($refreshButton, ButtonBar::BUTTON_POSITION_RIGHT);
570
571 // Level up
572 try {
573 $currentStorage = $this->folderObject->getStorage();
574 $parentFolder = $this->folderObject->getParentFolder();
575 if ($parentFolder->getIdentifier() !== $this->folderObject->getIdentifier()
576 && $currentStorage->isWithinFileMountBoundaries($parentFolder)
577 ) {
578 $levelUpClick = 'top.document.getElementsByName("navigation")[0].contentWindow.Tree.highlightActiveItem("file","folder'
579 . GeneralUtility::md5int($parentFolder->getCombinedIdentifier()) . '_"+top.fsMod.currentBank)';
580 $levelUpButton = $buttonBar->makeLinkButton()
581 ->setHref(BackendUtility::getModuleUrl('file_FilelistList', ['id' => $parentFolder->getCombinedIdentifier()]))
582 ->setOnClick($levelUpClick)
583 ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.upOneLevel'))
584 ->setIcon($iconFactory->getIcon('actions-view-go-up', Icon::SIZE_SMALL));
585 $buttonBar->addButton($levelUpButton, ButtonBar::BUTTON_POSITION_LEFT, 1);
586 }
587 } catch (\Exception $e) {
588 }
589
590 // Shortcut
591 if ($this->getBackendUser()->mayMakeShortcut()) {
592 $shortCutButton = $buttonBar->makeShortcutButton()->setModuleName('file_FilelistList');
593 $buttonBar->addButton($shortCutButton, ButtonBar::BUTTON_POSITION_RIGHT);
594 }
595
596 // Upload button (only if upload to this directory is allowed)
597 if ($this->folderObject && $this->folderObject->getStorage()->checkUserActionPermission('add',
598 'File') && $this->folderObject->checkActionPermission('write')
599 ) {
600 $uploadButton = $buttonBar->makeLinkButton()
601 ->setHref(BackendUtility::getModuleUrl(
602 'file_upload',
603 array(
604 'target' => $this->folderObject->getCombinedIdentifier(),
605 'returnUrl' => $this->filelist->listURL(),
606 )
607 ))
608 ->setClasses('t3js-drag-uploader-trigger')
609 ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:cm.upload'))
610 ->setIcon($iconFactory->getIcon('actions-edit-upload', Icon::SIZE_SMALL));
611 $buttonBar->addButton($uploadButton, ButtonBar::BUTTON_POSITION_LEFT, 1);
612 }
613
614 // New folder button
615 if ($this->folderObject && $this->folderObject->checkActionPermission('write')
616 && ($this->folderObject->getStorage()->checkUserActionPermission('add',
617 'File') || $this->folderObject->checkActionPermission('add'))
618 ) {
619 $newButton = $buttonBar->makeLinkButton()
620 ->setHref(BackendUtility::getModuleUrl(
621 'file_newfolder',
622 array(
623 'target' => $this->folderObject->getCombinedIdentifier(),
624 'returnUrl' => $this->filelist->listURL(),
625 )
626 ))
627 ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:cm.new'))
628 ->setIcon($iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL));
629 $buttonBar->addButton($newButton, ButtonBar::BUTTON_POSITION_LEFT, 1);
630 }
631
632 // Add paste button if clipboard is initialized
633 if ($this->filelist->clipObj instanceof Clipboard && $this->folderObject->checkActionPermission('write')) {
634 $elFromTable = $this->filelist->clipObj->elFromTable('_FILE');
635 if (!empty($elFromTable)) {
636 $addPasteButton = true;
637 $elToConfirm = array();
638 foreach ($elFromTable as $key => $element) {
639 $clipBoardElement = $resourceFactory->retrieveFileOrFolderObject($element);
640 if ($clipBoardElement instanceof Folder && $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement,
641 $this->folderObject)
642 ) {
643 $addPasteButton = false;
644 }
645 $elToConfirm[$key] = $clipBoardElement->getName();
646 }
647 if ($addPasteButton) {
648 $pasteButton = $buttonBar->makeLinkButton()
649 ->setHref($this->filelist->clipObj->pasteUrl('_FILE',
650 $this->folderObject->getCombinedIdentifier()))
651 ->setOnClick('return ' . $this->filelist->clipObj->confirmMsg('_FILE',
652 $this->folderObject->getReadablePath(), 'into', $elToConfirm))
653 ->setTitle($lang->getLL('clip_paste'))
654 ->setIcon($iconFactory->getIcon('actions-document-paste-after', Icon::SIZE_SMALL));
655 $buttonBar->addButton($pasteButton, ButtonBar::BUTTON_POSITION_LEFT, 2);
656 }
657 }
658 }
659 }
660
661 /**
662 * Returns an instance of LanguageService
663 *
664 * @return \TYPO3\CMS\Lang\LanguageService
665 */
666 protected function getLanguageService()
667 {
668 return $GLOBALS['LANG'];
669 }
670
671 /**
672 * Returns the current BE user.
673 *
674 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
675 */
676 protected function getBackendUser()
677 {
678 return $GLOBALS['BE_USER'];
679 }
680 }