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