2 namespace TYPO3\CMS\Filelist
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Backend\Clipboard\Clipboard
;
18 use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
;
19 use TYPO3\CMS\Backend\RecordList\AbstractRecordList
;
20 use TYPO3\CMS\Backend\Utility\BackendUtility
;
21 use TYPO3\CMS\Core\Database\DatabaseConnection
;
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\Messaging\FlashMessageService
;
26 use TYPO3\CMS\Core\
Resource\Exception\InsufficientFolderAccessPermissionsException
;
27 use TYPO3\CMS\Core\
Resource\File
;
28 use TYPO3\CMS\Core\
Resource\Folder
;
29 use TYPO3\CMS\Core\
Resource\FolderInterface
;
30 use TYPO3\CMS\Core\
Resource\InaccessibleFolder
;
31 use TYPO3\CMS\Core\
Resource\ProcessedFile
;
32 use TYPO3\CMS\Core\
Resource\ResourceFactory
;
33 use TYPO3\CMS\Core\
Resource\Utility\ListUtility
;
34 use TYPO3\CMS\Core\Type\Bitmask\JsConfirmation
;
35 use TYPO3\CMS\Core\Utility\GeneralUtility
;
36 use TYPO3\CMS\Filelist\Controller\FileListController
;
39 * Class for rendering of File>Filelist
41 class FileList
extends AbstractRecordList
44 * Default Max items shown
51 * Thumbnails on records containing files (pictures)
55 public $thumbs = false;
58 * Space icon used for alignment when no button is available
65 * Max length of strings
72 * If TRUE click menus are generated on files and folders
76 public $clickMenus = 1;
79 * The field to sort by
86 * Reverse sorting flag
95 public $firstElementNumber = 0;
100 public $clipBoard = 0;
105 public $bigControlPanel = 0;
115 public $HTMLcode = '';
120 public $totalbytes = 0;
125 public $dirs = array();
130 public $files = array();
140 protected $folderObject;
143 * Counting the elements no matter what
147 public $eCounter = 0;
152 public $totalItems = '';
157 public $CBnames = array();
160 * @var Clipboard $clipObj
165 * @var ResourceFactory
167 protected $resourceFactory;
170 * @param ResourceFactory $resourceFactory
172 public function injectResourceFactory(ResourceFactory
$resourceFactory)
174 $this->resourceFactory
= $resourceFactory;
180 protected $iconFactory;
183 * @var FileListController
185 protected $fileListController;
190 * @param FileListController $fileListController
192 public function __construct(FileListController
$fileListController)
194 parent
::__construct();
195 $this->fileListController
= $fileListController;
196 $this->iconFactory
= GeneralUtility
::makeInstance(IconFactory
::class);
200 * Initialization of class
202 * @param Folder $folderObject The folder to work on
203 * @param int $pointer Pointer
204 * @param bool $sort Sorting column
205 * @param bool $sortRev Sorting direction
206 * @param bool $clipBoard
207 * @param bool $bigControlPanel Show clipboard flag
210 public function start(Folder
$folderObject, $pointer, $sort, $sortRev, $clipBoard = false, $bigControlPanel = false)
212 $this->folderObject
= $folderObject;
214 $this->totalbytes
= 0;
216 $this->HTMLcode
= '';
217 $this->path
= $folderObject->getReadablePath();
219 $this->sortRev
= $sortRev;
220 $this->firstElementNumber
= $pointer;
221 $this->clipBoard
= $clipBoard;
222 $this->bigControlPanel
= $bigControlPanel;
223 // Setting the maximum length of the filenames to the user's settings or minimum 30 (= $this->fixedL)
224 $this->fixedL
= max($this->fixedL
, $this->getBackendUser()->uc
['titleLen']);
225 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_common.xlf');
226 $this->resourceFactory
= ResourceFactory
::getInstance();
230 * Reading files and directories, counting elements and generating the list in ->HTMLcode
234 public function generateList()
236 $this->HTMLcode
.= $this->getTable('fileext,tstamp,size,rw,_REF_');
240 * Wrapping input string in a link with clipboard command.
242 * @param string $string String to be linked - must be htmlspecialchar'ed / prepared before.
243 * @param string $_ unused
244 * @param string $cmd "cmd" value
245 * @param string $warning Warning for JS confirm message
246 * @return string Linked string
248 public function linkClipboardHeaderIcon($string, $_, $cmd, $warning = '')
250 $onClickEvent = 'document.dblistForm.cmd.value=' . GeneralUtility
::quoteJSvalue($cmd) . ';document.dblistForm.submit();';
252 $onClickEvent = 'if (confirm(' . GeneralUtility
::quoteJSvalue($warning) . ')){' . $onClickEvent . '}';
254 return '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($onClickEvent) . 'return false;">' . $string . '</a>';
258 * Returns a table with directories and files listed.
260 * @param array $rowlist Array of files from path
261 * @return string HTML-table
263 public function getTable($rowlist)
265 // prepare space icon
266 $this->spaceIcon
= '<span class="btn btn-default disabled">' . $this->iconFactory
->getIcon('empty-empty', Icon
::SIZE_SMALL
)->render() . '</span>';
268 // @todo use folder methods directly when they support filters
269 $storage = $this->folderObject
->getStorage();
270 $storage->resetFileAndFolderNameFiltersToDefault();
272 // Only render the contents of a browsable storage
273 if ($this->folderObject
->getStorage()->isBrowsable()) {
275 $foldersCount = $storage->countFoldersInFolder($this->folderObject
);
276 $filesCount = $storage->countFilesInFolder($this->folderObject
);
277 } catch (InsufficientFolderAccessPermissionsException
$e) {
282 if ($foldersCount <= $this->firstElementNumber
) {
283 $foldersFrom = false;
286 $foldersFrom = $this->firstElementNumber
;
287 if ($this->firstElementNumber +
$this->iLimit
> $foldersCount) {
288 $foldersNum = $foldersCount - $this->firstElementNumber
;
290 $foldersNum = $this->iLimit
;
293 if ($foldersCount >= $this->firstElementNumber +
$this->iLimit
) {
297 if ($this->firstElementNumber
<= $foldersCount) {
299 $filesNum = $this->iLimit
- $foldersNum;
301 $filesFrom = $this->firstElementNumber
- $foldersCount;
302 if ($filesFrom +
$this->iLimit
> $filesCount) {
303 $filesNum = $filesCount - $filesFrom;
305 $filesNum = $this->iLimit
;
309 $folders = $storage->getFoldersInFolder($this->folderObject
, $foldersFrom, $foldersNum, true, false, trim($this->sort
), (bool)$this->sortRev
);
310 $files = $this->folderObject
->getFiles($filesFrom, $filesNum, Folder
::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS
, false, trim($this->sort
), (bool)$this->sortRev
);
311 $this->totalItems
= $foldersCount +
$filesCount;
312 // Adds the code of files/dirs
315 // Cleaning rowlist for duplicates and place the $titleCol as the first column always!
316 $rowlist = '_LOCALIZATION_,' . $rowlist;
317 $rowlist = GeneralUtility
::rmFromList($titleCol, $rowlist);
318 $rowlist = GeneralUtility
::uniqueList($rowlist);
319 $rowlist = $rowlist ?
$titleCol . ',' . $rowlist : $titleCol;
320 if ($this->clipBoard
) {
321 $rowlist = str_replace('_LOCALIZATION_,', '_LOCALIZATION_,_CLIPBOARD_,', $rowlist);
322 $this->addElement_tdCssClass
['_CLIPBOARD_'] = 'col-clipboard';
324 if ($this->bigControlPanel
) {
325 $rowlist = str_replace('_LOCALIZATION_,', '_LOCALIZATION_,_CONTROL_,', $rowlist);
326 $this->addElement_tdCssClass
['_CONTROL_'] = 'col-control';
328 $this->fieldArray
= explode(',', $rowlist);
330 // Add classes to table cells
331 $this->addElement_tdCssClass
[$titleCol] = 'col-title';
332 $this->addElement_tdCssClass
['_LOCALIZATION_'] = 'col-localizationa';
334 $folders = ListUtility
::resolveSpecialFolderNames($folders);
337 // Directories are added
338 $this->eCounter
= $this->firstElementNumber
;
339 list(, $code) = $this->fwd_rwd_nav();
342 $iOut .= $this->formatDirList($folders);
344 $iOut .= $this->formatFileList($files);
346 $this->eCounter
= $this->firstElementNumber +
$this->iLimit
<= $this->totalItems
347 ?
$this->firstElementNumber +
$this->iLimit
349 list(, $code) = $this->fwd_rwd_nav();
352 // Header line is drawn
354 foreach ($this->fieldArray
as $v) {
355 if ($v == '_CLIPBOARD_' && $this->clipBoard
) {
358 $elFromTable = $this->clipObj
->elFromTable($table);
359 if (!empty($elFromTable) && $this->folderObject
->checkActionPermission('write')) {
360 $addPasteButton = true;
361 $elToConfirm = array();
362 foreach ($elFromTable as $key => $element) {
363 $clipBoardElement = $this->resourceFactory
->retrieveFileOrFolderObject($element);
364 if ($clipBoardElement instanceof Folder
&& $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement, $this->folderObject
)) {
365 $addPasteButton = false;
367 $elToConfirm[$key] = $clipBoardElement->getName();
369 if ($addPasteButton) {
370 $cells[] = '<a class="btn btn-default" href="' . htmlspecialchars($this->clipObj
->pasteUrl('_FILE', $this->folderObject
->getCombinedIdentifier())) . '" onclick="return ' . htmlspecialchars($this->clipObj
->confirmMsg('_FILE', $this->path
, 'into', $elToConfirm)) . '" title="' . $this->getLanguageService()->getLL('clip_paste', 1) . '">' . $this->iconFactory
->getIcon('actions-document-paste-after', Icon
::SIZE_SMALL
)->render() . '</a>';
373 if ($this->clipObj
->current
!== 'normal' && $iOut) {
374 $cells[] = $this->linkClipboardHeaderIcon('<span title="' . $this->getLanguageService()->getLL('clip_selectMarked', true) . '">' . $this->iconFactory
->getIcon('actions-edit-copy', Icon
::SIZE_SMALL
)->render() . '</span>', $table, 'setCB');
375 $cells[] = $this->linkClipboardHeaderIcon('<span title="' . $this->getLanguageService()->getLL('clip_deleteMarked', true) . '">' . $this->iconFactory
->getIcon('actions-edit-delete', Icon
::SIZE_SMALL
)->render(), $table, 'delete', $this->getLanguageService()->getLL('clip_deleteMarkedWarning'));
376 $onClick = 'checkOffCB(' . GeneralUtility
::quoteJSvalue(implode(',', $this->CBnames
)) . ', this); return false;';
377 $cells[] = '<a class="btn btn-default" rel="" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $this->getLanguageService()->getLL('clip_markRecords', true) . '">' . $this->iconFactory
->getIcon('actions-document-select', Icon
::SIZE_SMALL
)->render() . '</a>';
379 $theData[$v] = implode('', $cells);
382 $theT = $this->linkWrapSort($this->getLanguageService()->getLL('c_' . $v, true), $this->folderObject
->getCombinedIdentifier(), $v);
383 $theData[$v] = $theT;
387 $out .= '<thead>' . $this->addelement(1, '', $theData, '', '', '', 'th') . '</thead>';
388 $out .= '<tbody>' . $iOut . '</tbody>';
389 // half line is drawn
395 <div class="table-fit">
396 <table class="table table-striped table-hover" id="typo3-filelist">
401 /** @var $flashMessage FlashMessage */
402 $flashMessage = GeneralUtility
::makeInstance(FlashMessage
::class, $this->getLanguageService()->getLL('storageNotBrowsableMessage'), $this->getLanguageService()->getLL('storageNotBrowsableTitle'), FlashMessage
::INFO
);
403 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
404 $flashMessageService = GeneralUtility
::makeInstance(FlashMessageService
::class);
405 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
406 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
407 $defaultFlashMessageQueue->enqueue($flashMessage);
414 * If there is a parent folder and user has access to it, return an icon
415 * which is linked to the filelist of the parent folder.
417 * @param Folder $currentFolder
420 protected function getLinkToParentFolder(Folder
$currentFolder)
424 $currentStorage = $currentFolder->getStorage();
425 $parentFolder = $currentFolder->getParentFolder();
426 if ($parentFolder->getIdentifier() !== $currentFolder->getIdentifier() && $currentStorage->isWithinFileMountBoundaries($parentFolder)) {
427 $levelUp = $this->linkWrapDir(
428 '<span title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.upOneLevel', true) . '">'
429 . $this->iconFactory
->getIcon('actions-view-go-up', Icon
::SIZE_SMALL
)->render()
434 } catch (\Exception
$e) {
440 * Gets the number of files and total size of a folder
444 public function getFolderInfo()
446 if ($this->counter
== 1) {
447 $fileLabel = $this->getLanguageService()->getLL('file', true);
449 $fileLabel = $this->getLanguageService()->getLL('files', true);
451 return $this->counter
. ' ' . $fileLabel . ', ' . GeneralUtility
::formatSize($this->totalbytes
, $this->getLanguageService()->getLL('byteSizeUnits', true));
455 * This returns tablerows for the directories in the array $items['sorting'].
457 * @param Folder[] $folders Folders of \TYPO3\CMS\Core\Resource\Folder
458 * @return string HTML table rows.
460 public function formatDirList(array $folders)
463 foreach ($folders as $folderName => $folderObject) {
464 $role = $folderObject->getRole();
465 if ($role === FolderInterface
::ROLE_PROCESSING
) {
466 // don't show processing-folder
469 if ($role !== FolderInterface
::ROLE_DEFAULT
) {
470 $displayName = '<strong>' . htmlspecialchars($folderName) . '</strong>';
472 $displayName = htmlspecialchars($folderName);
475 $isLocked = $folderObject instanceof InaccessibleFolder
;
476 $isWritable = $folderObject->checkActionPermission('write');
481 // The icon with link
482 $theIcon = '<span title="' . htmlspecialchars($folderName) . '">' . $this->iconFactory
->getIconForResource($folderObject, Icon
::SIZE_SMALL
)->render() . '</span>';
483 if (!$isLocked && $this->clickMenus
) {
484 $theIcon = BackendUtility
::wrapClickMenuOnIcon($theIcon, $folderObject->getCombinedIdentifier());
487 // Preparing and getting the data-array
490 foreach ($this->fieldArray
as $field) {
491 $theData[$field] = '';
493 $theData['file'] = $displayName;
495 foreach ($this->fieldArray
as $field) {
499 $numFiles = $folderObject->getFileCount();
500 } catch (InsufficientFolderAccessPermissionsException
$e) {
503 $theData[$field] = $numFiles . ' ' . $this->getLanguageService()->getLL(($numFiles === 1 ?
'file' : 'files'), true);
506 $theData[$field] = '<strong class="text-danger">' . $this->getLanguageService()->getLL('read', true) . '</strong>' . (!$isWritable ?
'' : '<strong class="text-danger">' . $this->getLanguageService()->getLL('write', true) . '</strong>');
509 $theData[$field] = $this->getLanguageService()->getLL('folder', true);
512 $tstamp = $folderObject->getModificationTime();
513 $theData[$field] = $tstamp ? BackendUtility
::date($tstamp) : '-';
516 $theData[$field] = $this->linkWrapDir($displayName, $folderObject);
519 $theData[$field] = $this->makeEdit($folderObject);
522 $theData[$field] = $this->makeClip($folderObject);
525 $theData[$field] = $this->makeRef($folderObject);
528 $theData[$field] = GeneralUtility
::fixed_lgd_cs($theData[$field], $this->fixedL
);
532 $out .= $this->addelement(1, $theIcon, $theData);
538 * Wraps the directory-titles
540 * @param string $title String to be wrapped in links
541 * @param Folder $folderObject Folder to work on
542 * @return string HTML
544 public function linkWrapDir($title, Folder
$folderObject)
546 $href = BackendUtility
::getModuleUrl('file_FilelistList', ['id' => $folderObject->getCombinedIdentifier()]);
547 $onclick = ' onclick="' . htmlspecialchars(('top.document.getElementsByName("navigation")[0].contentWindow.Tree.highlightActiveItem("file","folder' . GeneralUtility
::md5int($folderObject->getCombinedIdentifier()) . '_"+top.fsMod.currentBank)')) . '"';
548 // Sometimes $code contains plain HTML tags. In such a case the string should not be modified!
549 if ((string)$title === strip_tags($title)) {
550 return '<a href="' . htmlspecialchars($href) . '"' . $onclick . ' title="' . htmlspecialchars($title) . '">' . GeneralUtility
::fixed_lgd_cs($title, $this->fixedL
) . '</a>';
552 return '<a href="' . htmlspecialchars($href) . '"' . $onclick . '>' . $title . '</a>';
557 * Wraps filenames in links which opens the metadata editor.
559 * @param string $code String to be wrapped in links
560 * @param File $fileObject File to be linked
561 * @return string HTML
563 public function linkWrapFile($code, File
$fileObject)
566 if ($fileObject instanceof File
&& $fileObject->isIndexed() && $fileObject->checkActionPermission('write') && $this->getBackendUser()->check('tables_modify', 'sys_file_metadata')) {
567 $metaData = $fileObject->_getMetaData();
570 'sys_file_metadata' => [
571 $metaData['uid'] => 'edit'
574 'returnUrl' => $this->listURL()
576 $url = BackendUtility
::getModuleUrl('record_edit', $urlParameters);
577 $title = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.editMetadata'));
578 $code = '<a href="' . htmlspecialchars($url) . '" title="' . $title . '">' . GeneralUtility
::fixed_lgd_cs($code, $this->fixedL
) . '</a>';
580 } catch (\Exception
$e) {
581 // intentional fall-through
587 * Returns list URL; This is the URL of the current script with id and imagemode parameters, that's all.
588 * The URL however is not relative, otherwise GeneralUtility::sanitizeLocalUrl() would say that
589 * the URL would be invalid
591 * @param string $altId
592 * @param string $table Table name to display. Enter "-1" for the current table.
593 * @param string $exclList Comma separated list of fields NOT to include ("sortField", "sortRev" or "firstElementNumber")
597 public function listURL($altId = '', $table = '-1', $exclList = '')
599 return GeneralUtility
::linkThisScript(array(
600 'target' => rawurlencode($this->folderObject
->getCombinedIdentifier()),
601 'imagemode' => $this->thumbs
606 * This returns tablerows for the files in the array $items['sorting'].
608 * @param File[] $files File items
609 * @return string HTML table rows.
611 public function formatFileList(array $files)
614 // first two keys are "0" (default) and "-1" (multiple), after that comes the "other languages"
615 $allSystemLanguages = GeneralUtility
::makeInstance(TranslationConfigurationProvider
::class)->getSystemLanguages();
616 $systemLanguages = array_filter($allSystemLanguages, function ($languageRecord) {
617 if ($languageRecord['uid'] === -1 ||
$languageRecord['uid'] === 0 ||
!$this->getBackendUser()->checkLanguageAccess($languageRecord['uid'])) {
624 foreach ($files as $fileObject) {
627 $this->totalbytes +
= $fileObject->getSize();
628 $ext = $fileObject->getExtension();
629 $fileName = trim($fileObject->getName());
630 // The icon with link
631 $theIcon = '<span title="' . htmlspecialchars($fileName . ' [' . (int)$fileObject->getUid() . ']') . '">'
632 . $this->iconFactory
->getIconForResource($fileObject, Icon
::SIZE_SMALL
)->render() . '</span>';
633 if ($this->clickMenus
) {
634 $theIcon = BackendUtility
::wrapClickMenuOnIcon($theIcon, $fileObject->getCombinedIdentifier());
636 // Preparing and getting the data-array
638 foreach ($this->fieldArray
as $field) {
641 $theData[$field] = GeneralUtility
::formatSize($fileObject->getSize(), $this->getLanguageService()->getLL('byteSizeUnits', true));
644 $theData[$field] = '' . (!$fileObject->checkActionPermission('read') ?
' ' : '<strong class="text-danger">' . $this->getLanguageService()->getLL('read', true) . '</strong>') . (!$fileObject->checkActionPermission('write') ?
'' : '<strong class="text-danger">' . $this->getLanguageService()->getLL('write', true) . '</strong>');
647 $theData[$field] = strtoupper($ext);
650 $theData[$field] = BackendUtility
::date($fileObject->getModificationTime());
653 $theData[$field] = $this->makeEdit($fileObject);
656 $theData[$field] = $this->makeClip($fileObject);
658 case '_LOCALIZATION_':
659 if (!empty($systemLanguages) && $fileObject->isIndexed() && $fileObject->checkActionPermission('write') && $this->getBackendUser()->check('tables_modify', 'sys_file_metadata')) {
660 $metaDataRecord = $fileObject->_getMetaData();
661 $translations = $this->getTranslationsForMetaData($metaDataRecord);
664 foreach ($systemLanguages as $language) {
665 $languageId = $language['uid'];
666 $flagIcon = $language['flagIcon'];
667 if (array_key_exists($languageId, $translations)) {
668 $title = htmlspecialchars(sprintf($this->getLanguageService()->getLL('editMetadataForLanguage'), $language['title']));
669 // @todo the overlay for the flag needs to be added ($flagIcon . '-overlay')
672 'sys_file_metadata' => [
673 $translations[$languageId]['uid'] => 'edit'
676 'returnUrl' => $this->listURL()
678 $flagButtonIcon = $this->iconFactory
->getIcon($flagIcon, Icon
::SIZE_SMALL
, 'overlay-edit')->render();
679 $url = BackendUtility
::getModuleUrl('record_edit', $urlParameters);
680 $languageCode .= '<a href="' . htmlspecialchars($url) . '" class="btn btn-default" title="' . $title . '">'
681 . $flagButtonIcon . '</a>';
684 'justLocalized' => 'sys_file_metadata:' . $metaDataRecord['uid'] . ':' . $languageId,
685 'returnUrl' => $this->listURL()
687 $returnUrl = BackendUtility
::getModuleUrl('record_edit', $parameters);
688 $href = BackendUtility
::getLinkToDataHandlerAction(
689 '&cmd[sys_file_metadata][' . $metaDataRecord['uid'] . '][localize]=' . $languageId,
692 $flagButtonIcon = '<span title="' . htmlspecialchars(sprintf($this->getLanguageService()->getLL('createMetadataForLanguage'), $language['title'])) . '">' . $this->iconFactory
->getIcon($flagIcon, Icon
::SIZE_SMALL
, 'overlay-new')->render() . '</span>';
693 $languageCode .= '<a href="' . htmlspecialchars($href) . '" class="btn btn-default">' . $flagButtonIcon . '</a> ';
697 // Hide flag button bar when not translated yet
698 $theData[$field] = ' <div class="localisationData btn-group" data-fileid="' . $fileObject->getUid() . '"' .
699 (empty($translations) ?
' style="display: none;"' : '') . '>' . $languageCode . '</div>';
700 $theData[$field] .= '<a class="btn btn-default filelist-translationToggler" data-fileid="' . $fileObject->getUid() . '">' .
701 '<span title="' . $this->getLanguageService()->getLL('translateMetadata', true) . '">'
702 . $this->iconFactory
->getIcon('mimetypes-x-content-page-language-overlay', Icon
::SIZE_SMALL
)->render() . '</span>'
707 $theData[$field] = $this->makeRef($fileObject);
710 // Edit metadata of file
711 $theData[$field] = $this->linkWrapFile(htmlspecialchars($fileName), $fileObject);
713 if ($fileObject->isMissing()) {
714 $flashMessage = \TYPO3\CMS\Core\
Resource\Utility\BackendUtility
::getFlashMessageForMissingFile($fileObject);
715 $theData[$field] .= $flashMessage->render();
717 } elseif ($this->thumbs
&& ($this->isImage($ext) ||
$this->isMediaFile($ext))) {
718 $processedFile = $fileObject->process(ProcessedFile
::CONTEXT_IMAGEPREVIEW
, array());
719 if ($processedFile) {
720 $thumbUrl = $processedFile->getPublicUrl(true);
721 $theData[$field] .= '<br /><img src="' . $thumbUrl . '" ' .
722 'width="' . $processedFile->getProperty('width') . '" ' .
723 'height="' . $processedFile->getProperty('height') . '" ' .
724 'title="' . htmlspecialchars($fileName) . '" alt="" />';
729 $theData[$field] = '';
730 if ($fileObject->hasProperty($field)) {
731 $theData[$field] = htmlspecialchars(GeneralUtility
::fixed_lgd_cs($fileObject->getProperty($field), $this->fixedL
));
735 $out .= $this->addelement(1, $theIcon, $theData);
741 * Fetch the translations for a sys_file_metadata record
743 * @param $metaDataRecord
744 * @return array keys are the sys_language uids, values are the $rows
746 protected function getTranslationsForMetaData($metaDataRecord)
748 $where = $GLOBALS['TCA']['sys_file_metadata']['ctrl']['transOrigPointerField'] . '=' . (int)$metaDataRecord['uid'] .
749 ' AND ' . $GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField'] . '>0';
750 $translationRecords = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_file_metadata', $where);
751 $translations = array();
752 foreach ($translationRecords as $record) {
753 $translations[$record[$GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField']]] = $record;
755 return $translations;
759 * Returns TRUE if $ext is an image-extension according to $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
761 * @param string $ext File extension
764 public function isImage($ext)
766 return GeneralUtility
::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($ext));
770 * Returns TRUE if $ext is an media-extension according to $GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext']
772 * @param string $ext File extension
775 public function isMediaFile($ext)
777 return GeneralUtility
::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext'], strtolower($ext));
781 * Wraps the directory-titles ($code) in a link to filelist/Modules/Filelist/index.php (id=$path) and sorting commands...
783 * @param string $code String to be wrapped
784 * @param string $folderIdentifier ID (path)
785 * @param string $col Sorting column
786 * @return string HTML
788 public function linkWrapSort($code, $folderIdentifier, $col)
790 $params = ['id' => $folderIdentifier, 'SET' => [ 'sort' => $col ]];
792 if ($this->sort
=== $col) {
793 // Check reverse sorting
794 $params['SET']['reverse'] = ($this->sortRev ?
'0' : '1');
795 $sortArrow = $this->iconFactory
->getIcon('status-status-sorting-light-' . ($this->sortRev ?
'desc' : 'asc'), Icon
::SIZE_SMALL
)->render();
797 $params['SET']['reverse'] = 0;
800 $href = BackendUtility
::getModuleUrl('file_FilelistList', $params);
801 return '<a href="' . htmlspecialchars($href) . '">' . $code . ' ' . $sortArrow . '</a>';
805 * Creates the clipboard control pad
807 * @param File|Folder $fileOrFolderObject Array with information about the file/directory for which to make the clipboard panel for the listing.
808 * @return string HTML-table
810 public function makeClip($fileOrFolderObject)
812 if (!$fileOrFolderObject->checkActionPermission('read')) {
816 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
817 $fullName = $fileOrFolderObject->getName();
818 $md5 = GeneralUtility
::shortmd5($fullIdentifier);
819 // For normal clipboard, add copy/cut buttons:
820 if ($this->clipObj
->current
=== 'normal') {
821 $isSel = $this->clipObj
->isSelected('_FILE', $md5);
822 $copyTitle = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.copy', true);
823 $cutTitle = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.cut', true);
824 $copyIcon = $this->iconFactory
->getIcon('actions-edit-copy', Icon
::SIZE_SMALL
)->render();
825 $cutIcon = $this->iconFactory
->getIcon('actions-edit-cut', Icon
::SIZE_SMALL
)->render();
827 if ($isSel === 'copy') {
828 $copyIcon = $this->iconFactory
->getIcon('actions-edit-copy-release', Icon
::SIZE_SMALL
)->render();
829 } elseif ($isSel === 'cut') {
830 $cutIcon = $this->iconFactory
->getIcon('actions-edit-cut-release', Icon
::SIZE_SMALL
)->render();
833 $cells[] = '<a class="btn btn-default"" href="' . htmlspecialchars($this->clipObj
->selUrlFile($fullIdentifier, 1, ($isSel === 'copy'))) . '" title="' . $copyTitle . '">' . $copyIcon . '</a>';
834 // we can only cut if file can be moved
835 if ($fileOrFolderObject->checkActionPermission('move')) {
836 $cells[] = '<a class="btn btn-default" href="' . htmlspecialchars($this->clipObj
->selUrlFile($fullIdentifier, 0, ($isSel === 'cut'))) . '" title="' . $cutTitle . '">' . $cutIcon . '</a>';
838 $cells[] = $this->spaceIcon
;
841 // For numeric pads, add select checkboxes:
842 $n = '_FILE|' . $md5;
843 $this->CBnames
[] = $n;
844 $checked = $this->clipObj
->isSelected('_FILE', $md5) ?
' checked="checked"' : '';
845 $cells[] = '<input type="hidden" name="CBH[' . $n . ']" value="0" /><label class="btn btn-default btn-checkbox"><input type="checkbox" name="CBC[' . $n . ']" value="' . htmlspecialchars($fullIdentifier) . '" ' . $checked . ' /><span class="t3-icon fa"></span></label>';
847 // Display PASTE button, if directory:
848 $elFromTable = $this->clipObj
->elFromTable('_FILE');
849 if ($fileOrFolderObject instanceof Folder
&& !empty($elFromTable) && $fileOrFolderObject->checkActionPermission('write')) {
850 $addPasteButton = true;
851 $elToConfirm = array();
852 foreach ($elFromTable as $key => $element) {
853 $clipBoardElement = $this->resourceFactory
->retrieveFileOrFolderObject($element);
854 if ($clipBoardElement instanceof Folder
&& $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement, $fileOrFolderObject)) {
855 $addPasteButton = false;
857 $elToConfirm[$key] = $clipBoardElement->getName();
859 if ($addPasteButton) {
860 $cells[] = '<a class="btn btn-default" href="' . htmlspecialchars($this->clipObj
->pasteUrl('_FILE', $fullIdentifier)) . '" onclick="return ' . htmlspecialchars($this->clipObj
->confirmMsg('_FILE', $fullName, 'into', $elToConfirm)) . '" title="' . $this->getLanguageService()->getLL('clip_pasteInto', true) . '">' . $this->iconFactory
->getIcon('actions-document-paste-into', Icon
::SIZE_SMALL
)->render() . '</a>';
863 // Compile items into a DIV-element:
864 return ' <div class="btn-group" role="group">' . implode('', $cells) . '</div>';
868 * Creates the edit control section
870 * @param File|Folder $fileOrFolderObject Array with information about the file/directory for which to make the edit control section for the listing.
871 * @return string HTML-table
873 public function makeEdit($fileOrFolderObject)
876 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
878 // Edit file content (if editable)
879 if ($fileOrFolderObject instanceof File
&& $fileOrFolderObject->checkActionPermission('write') && GeneralUtility
::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileOrFolderObject->getExtension())) {
880 $url = BackendUtility
::getModuleUrl('file_edit', array('target' => $fullIdentifier));
881 $editOnClick = 'top.content.list_frame.location.href=' . GeneralUtility
::quoteJSvalue($url) . '+\'&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
882 $cells['edit'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($editOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.editcontent') . '">'
883 . $this->iconFactory
->getIcon('actions-page-open', Icon
::SIZE_SMALL
)->render()
886 $cells['edit'] = $this->spaceIcon
;
888 if ($fileOrFolderObject instanceof File
) {
889 $fileUrl = $fileOrFolderObject->getPublicUrl(true);
891 $aOnClick = 'return top.openUrlInWindow(' . GeneralUtility
::quoteJSvalue($fileUrl) . ', \'WebFile\');';
892 $cells['view'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($aOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.view') . '">' . $this->iconFactory
->getIcon('actions-document-view', Icon
::SIZE_SMALL
)->render() . '</a>';
894 $cells['view'] = $this->spaceIcon
;
897 $cells['view'] = $this->spaceIcon
;
901 if ($fileOrFolderObject instanceof File
&& $fileOrFolderObject->checkActionPermission('replace')) {
902 $url = BackendUtility
::getModuleUrl('file_replace', array('target' => $fullIdentifier, 'uid' => $fileOrFolderObject->getUid()));
903 $replaceOnClick = 'top.content.list_frame.location.href = ' . GeneralUtility
::quoteJSvalue($url) . '+\'&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
904 $cells['replace'] = '<a href="#" class="btn btn-default" onclick="' . $replaceOnClick . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.replace') . '">' . $this->iconFactory
->getIcon('actions-edit-replace', Icon
::SIZE_SMALL
)->render() . '</a>';
908 if ($fileOrFolderObject->checkActionPermission('rename')) {
909 $url = BackendUtility
::getModuleUrl('file_rename', array('target' => $fullIdentifier));
910 $renameOnClick = 'top.content.list_frame.location.href = ' . GeneralUtility
::quoteJSvalue($url) . '+\'&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
911 $cells['rename'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($renameOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.rename') . '">' . $this->iconFactory
->getIcon('actions-edit-rename', Icon
::SIZE_SMALL
)->render() . '</a>';
913 $cells['rename'] = $this->spaceIcon
;
915 if ($fileOrFolderObject->checkActionPermission('read')) {
917 if ($fileOrFolderObject instanceof Folder
) {
918 $infoOnClick = 'top.launchView( \'_FOLDER\', ' . GeneralUtility
::quoteJSvalue($fullIdentifier) . ');return false;';
919 } elseif ($fileOrFolderObject instanceof File
) {
920 $infoOnClick = 'top.launchView( \'_FILE\', ' . GeneralUtility
::quoteJSvalue($fullIdentifier) . ');return false;';
922 $cells['info'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($infoOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.info') . '">' . $this->iconFactory
->getIcon('actions-document-info', Icon
::SIZE_SMALL
)->render() . '</a>';
924 $cells['info'] = $this->spaceIcon
;
928 if ($fileOrFolderObject->checkActionPermission('delete')) {
929 $identifier = $fileOrFolderObject->getIdentifier();
930 if ($fileOrFolderObject instanceof Folder
) {
931 $referenceCountText = BackendUtility
::referenceCount('_FILE', $identifier, ' ' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.referencesToFolder'));
933 $referenceCountText = BackendUtility
::referenceCount('sys_file', $fileOrFolderObject->getUid(), ' ' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.referencesToFile'));
936 if ($this->getBackendUser()->jsConfirmation(JsConfirmation
::DELETE
)) {
937 $confirmationCheck = '1';
939 $confirmationCheck = '0';
942 $deleteUrl = BackendUtility
::getModuleUrl('tce_file');
943 $confirmationMessage = sprintf($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:mess.delete'), $fileOrFolderObject->getName()) . $referenceCountText;
944 $title = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.delete');
945 $cells['delete'] = '<a href="#" class="btn btn-default t3js-filelist-delete" data-content="' . htmlspecialchars($confirmationMessage)
946 . '" data-check="' . $confirmationCheck
947 . '" data-delete-url="' . htmlspecialchars($deleteUrl)
948 . '" data-title="' . htmlspecialchars($title)
949 . '" data-identifier="' . htmlspecialchars($fileOrFolderObject->getCombinedIdentifier())
950 . '" data-veri-code="' . $this->getBackendUser()->veriCode()
951 . '" title="' . htmlspecialchars($title) . '">'
952 . $this->iconFactory
->getIcon('actions-edit-delete', Icon
::SIZE_SMALL
)->render() . '</a>';
954 $cells['delete'] = $this->spaceIcon
;
957 // Hook for manipulating edit icons.
958 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'])) {
959 $cells['__fileOrFolderObject'] = $fileOrFolderObject;
960 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'] as $classData) {
961 $hookObject = GeneralUtility
::getUserObj($classData);
962 if (!$hookObject instanceof FileListEditIconHookInterface
) {
963 throw new \
UnexpectedValueException(
964 '$hookObject must implement interface \\TYPO3\\CMS\\Filelist\\FileListEditIconHookInterface',
968 $hookObject->manipulateEditIcons($cells, $this);
970 unset($cells['__fileOrFolderObject']);
972 // Compile items into a DIV-element:
973 return '<div class="btn-group">' . implode('', $cells) . '</div>';
977 * Make reference count
979 * @param File|Folder $fileOrFolderObject Array with information about the file/directory for which to make the clipboard panel for the listing.
980 * @return string HTML
982 public function makeRef($fileOrFolderObject)
984 if ($fileOrFolderObject instanceof FolderInterface
) {
987 // Look up the file in the sys_refindex.
988 // Exclude sys_file_metadata records as these are no use references
989 $databaseConnection = $this->getDatabaseConnection();
990 $table = 'sys_refindex';
991 $referenceCount = $databaseConnection->exec_SELECTcountRows(
994 'ref_table=' . $databaseConnection->fullQuoteStr('sys_file', $table)
995 . ' AND ref_uid=' . (int)$fileOrFolderObject->getUid()
997 . ' AND tablename != ' . $databaseConnection->fullQuoteStr('sys_file_metadata', $table)
999 return $this->generateReferenceToolTip($referenceCount, '\'_FILE\', ' . GeneralUtility
::quoteJSvalue($fileOrFolderObject->getCombinedIdentifier()));
1003 * Returns the database connection
1005 * @return DatabaseConnection
1007 protected function getDatabaseConnection()
1009 return $GLOBALS['TYPO3_DB'];
1013 * Returns an instance of LanguageService
1015 * @return \TYPO3\CMS\Lang\LanguageService
1017 protected function getLanguageService()
1019 return $GLOBALS['LANG'];
1023 * Returns the current BE user.
1025 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1027 protected function getBackendUser()
1029 return $GLOBALS['BE_USER'];