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