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\Backend\Utility\IconUtility
;
22 use TYPO3\CMS\Core\Database\DatabaseConnection
;
23 use TYPO3\CMS\Core\Messaging\FlashMessage
;
24 use TYPO3\CMS\Core\
Resource\File
;
25 use TYPO3\CMS\Core\
Resource\Folder
;
26 use TYPO3\CMS\Core\
Resource\InaccessibleFolder
;
27 use TYPO3\CMS\Core\
Resource\ProcessedFile
;
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\GeneralUtility
;
32 use TYPO3\CMS\Core\
Resource\FolderInterface
;
35 * Class for rendering of File>Filelist
37 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
39 class FileList
extends AbstractRecordList
{
42 * Default Max items shown
49 * Thumbnails on records containing files (pictures)
53 public $thumbs = FALSE;
56 * Space icon used for alignment when no button is available
63 * Max length of strings
75 * If TRUE click menus are generated on files and folders
79 public $clickMenus = 1;
82 * The field to sort by
89 * Reverse sorting flag
98 public $firstElementNumber = 0;
103 public $clipBoard = 0;
108 public $bigControlPanel = 0;
118 public $HTMLcode = '';
123 public $totalbytes = 0;
128 public $dirs = array();
133 public $files = array();
143 protected $folderObject;
146 * Counting the elements no matter what
150 public $eCounter = 0;
155 public $dirCounter = 0;
160 public $totalItems = '';
165 public $CBnames = array();
168 * @var Clipboard $clipObj
173 * @var ResourceFactory
175 protected $resourceFactory;
178 * @param ResourceFactory $resourceFactory
180 public function injectResourceFactory(ResourceFactory
$resourceFactory) {
181 $this->resourceFactory
= $resourceFactory;
185 * Initialization of class
187 * @param Folder $folderObject The folder to work on
188 * @param int $pointer Pointer
189 * @param bool $sort Sorting column
190 * @param bool $sortRev Sorting direction
191 * @param bool $clipBoard
192 * @param bool $bigControlPanel Show clipboard flag
195 public function start(Folder
$folderObject, $pointer, $sort, $sortRev, $clipBoard = FALSE, $bigControlPanel = FALSE) {
196 $this->script
= BackendUtility
::getModuleUrl('file_list');
197 $this->folderObject
= $folderObject;
199 $this->totalbytes
= 0;
201 $this->HTMLcode
= '';
202 $this->path
= $folderObject->getIdentifier();
204 $this->sortRev
= $sortRev;
205 $this->firstElementNumber
= $pointer;
206 $this->clipBoard
= $clipBoard;
207 $this->bigControlPanel
= $bigControlPanel;
208 // Setting the maximum length of the filenames to the user's settings or minimum 30 (= $this->fixedL)
209 $this->fixedL
= max($this->fixedL
, $this->getBackendUser()->uc
['titleLen']);
210 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_common.xlf');
211 $this->resourceFactory
= ResourceFactory
::getInstance();
215 * Reading files and directories, counting elements and generating the list in ->HTMLcode
219 public function generateList() {
220 $this->HTMLcode
.= $this->getTable('fileext,tstamp,size,rw,_REF_');
224 * Return the buttons used by the file list to include in the top header
226 * @param Folder $folderObject
229 public function getButtonsAndOtherMarkers(Folder
$folderObject) {
230 $otherMarkers = array(
235 'level_up' => $this->getLinkToParentFolder($folderObject),
241 // Makes the code for the folder icon in the top
243 $title = htmlspecialchars($folderObject->getIdentifier());
244 // Start compiling the HTML
245 // If this is some subFolder under the mount root....
246 if ($folderObject->getStorage()->isWithinFileMountBoundaries($folderObject)) {
247 // The icon with link
248 $otherMarkers['PAGE_ICON'] = IconUtility
::getSpriteIconForResource($folderObject, array('title' => $title));
249 // No HTML specialchars here - HTML like <strong> </strong> is allowed
250 $otherMarkers['TITLE'] .= GeneralUtility
::removeXSS(GeneralUtility
::fixed_lgd_cs($title, -($this->fixedL +
20)));
252 // This is the root folder
253 $otherMarkers['PAGE_ICON'] = IconUtility
::getSpriteIconForResource($folderObject, array('title' => $title, 'mount-root' => TRUE));
254 $otherMarkers['TITLE'] .= htmlspecialchars(GeneralUtility
::fixed_lgd_cs($title, -($this->fixedL +
20)));
256 if ($this->clickMenus
) {
257 $otherMarkers['PAGE_ICON'] = $GLOBALS['SOBE']->doc
->wrapClickMenuOnIcon($otherMarkers['PAGE_ICON'], $folderObject->getCombinedIdentifier());
259 // Add paste button if clipboard is initialized
260 if ($this->clipObj
instanceof Clipboard
&& $folderObject->checkActionPermission('write')) {
261 $elFromTable = $this->clipObj
->elFromTable('_FILE');
262 if (count($elFromTable)) {
263 $addPasteButton = TRUE;
264 foreach ($elFromTable as $element) {
265 $clipBoardElement = $this->resourceFactory
->retrieveFileOrFolderObject($element);
266 if ($clipBoardElement instanceof Folder
&& $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement, $folderObject)) {
267 $addPasteButton = FALSE;
270 if ($addPasteButton) {
271 $buttons['PASTE'] = '<a href="' . htmlspecialchars($this->clipObj
->pasteUrl('_FILE', $folderObject->getCombinedIdentifier())) . '" onclick="return ' . htmlspecialchars($this->clipObj
->confirmMsg('_FILE', $this->path
, 'into', $elFromTable)) . '" title="' . $this->getLanguageService()->getLL('clip_paste', TRUE) . '">' . IconUtility
::getSpriteIcon('actions-document-paste-after') . '</a>';
277 $buttons['refresh'] = '<a href="' . htmlspecialchars($this->listURL()) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.reload', TRUE) . '">' . IconUtility
::getSpriteIcon('actions-system-refresh') . '</a>';
278 return array($buttons, $otherMarkers);
282 * Wrapping input string in a link with clipboard command.
284 * @param string $string String to be linked - must be htmlspecialchar'ed / prepared before.
285 * @param string $table table - NOT USED
286 * @param string $cmd "cmd" value
287 * @param string $warning Warning for JS confirm message
288 * @return string Linked string
290 public function linkClipboardHeaderIcon($string, $table, $cmd, $warning = '') {
291 $onClickEvent = 'document.dblistForm.cmd.value=\'' . $cmd . '\';document.dblistForm.submit();';
293 $onClickEvent = 'if (confirm(' . GeneralUtility
::quoteJSvalue($warning) . ')){' . $onClickEvent . '}';
295 return '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($onClickEvent) . 'return false;">' . $string . '</a>';
299 * Returns a table with directories and files listed.
301 * @param array $rowlist Array of files from path
302 * @return string HTML-table
304 public function getTable($rowlist) {
305 // prepare space icon
306 $this->spaceIcon
= '<span class="btn btn-default disabled">' . IconUtility
::getSpriteIcon('empty-empty') . '</span>';
308 // @todo use folder methods directly when they support filters
309 $storage = $this->folderObject
->getStorage();
310 $storage->resetFileAndFolderNameFiltersToDefault();
312 // Only render the contents of a browsable storage
313 if ($this->folderObject
->getStorage()->isBrowsable()) {
314 $folders = $storage->getFolderIdentifiersInFolder($this->folderObject
->getIdentifier());
315 $files = $this->folderObject
->getFiles();
316 $this->sort
= trim($this->sort
);
317 if ($this->sort
!== '') {
318 $filesToSort = array();
319 /** @var $fileObject File */
320 foreach ($files as $fileObject) {
321 switch ($this->sort
) {
323 $sortingKey = $fileObject->getSize();
326 $sortingKey = ($fileObject->checkActionPermission('read') ?
'R' : '' . $fileObject->checkActionPermission('write')) ?
'W' : '';
329 $sortingKey = $fileObject->getExtension();
332 $sortingKey = $fileObject->getModificationTime();
335 $sortingKey = $fileObject->getName();
338 if ($fileObject->hasProperty($this->sort
)) {
339 $sortingKey = $fileObject->getProperty($this->sort
);
341 $sortingKey = $fileObject->getName();
345 while (isset($filesToSort[$sortingKey . $i])) {
348 $filesToSort[$sortingKey . $i] = $fileObject;
350 uksort($filesToSort, 'strnatcasecmp');
351 if ((int)$this->sortRev
=== 1) {
352 $filesToSort = array_reverse($filesToSort);
354 $files = $filesToSort;
356 $this->totalItems
= count($folders) +
count($files);
357 // Adds the code of files/dirs
360 // Cleaning rowlist for duplicates and place the $titleCol as the first column always!
361 $rowlist = '_LOCALIZATION_,' . $rowlist;
362 $rowlist = GeneralUtility
::rmFromList($titleCol, $rowlist);
363 $rowlist = GeneralUtility
::uniqueList($rowlist);
364 $rowlist = $rowlist ?
$titleCol . ',' . $rowlist : $titleCol;
365 if ($this->clipBoard
) {
366 $rowlist = str_replace('_LOCALIZATION_,', '_LOCALIZATION_,_CLIPBOARD_,', $rowlist);
367 $this->addElement_tdCssClass
['_CLIPBOARD_'] = 'col-clipboard';
369 if ($this->bigControlPanel
) {
370 $rowlist = str_replace('_LOCALIZATION_,', '_LOCALIZATION_,_CONTROL_,', $rowlist);
371 $this->addElement_tdCssClass
['_CONTROL_'] = 'col-control';
373 $this->fieldArray
= explode(',', $rowlist);
374 $folderObjects = array();
375 foreach ($folders as $folder) {
376 $folderObjects[] = $storage->getFolder($folder, TRUE);
378 // Add classes to table cells
379 $this->addElement_tdCssClass
[$titleCol] = 'col-title';
380 $this->addElement_tdCssClass
['_LOCALIZATION_'] = 'col-localizationa';
382 $folderObjects = ListUtility
::resolveSpecialFolderNames($folderObjects);
383 uksort($folderObjects, 'strnatcasecmp');
385 // Directories are added
386 $iOut = $this->formatDirList($folderObjects);
388 $iOut .= $this->formatFileList($files, $titleCol);
389 // Header line is drawn
391 foreach ($this->fieldArray
as $v) {
392 if ($v == '_CLIPBOARD_' && $this->clipBoard
) {
395 $elFromTable = $this->clipObj
->elFromTable($table);
396 if (count($elFromTable) && $this->folderObject
->checkActionPermission('write')) {
397 $addPasteButton = TRUE;
398 foreach ($elFromTable as $element) {
399 $clipBoardElement = $this->resourceFactory
->retrieveFileOrFolderObject($element);
400 if ($clipBoardElement instanceof Folder
&& $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement, $this->folderObject
)) {
401 $addPasteButton = FALSE;
404 if ($addPasteButton) {
405 $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', $elFromTable)) . '" title="' . $this->getLanguageService()->getLL('clip_paste', 1) . '">' . IconUtility
::getSpriteIcon('actions-document-paste-after') . '</a>';
408 if ($this->clipObj
->current
!== 'normal' && $iOut) {
409 $cells[] = $this->linkClipboardHeaderIcon(IconUtility
::getSpriteIcon('actions-edit-copy', array('title' => $this->getLanguageService()->getLL('clip_selectMarked', TRUE))), $table, 'setCB');
410 $cells[] = $this->linkClipboardHeaderIcon(IconUtility
::getSpriteIcon('actions-edit-delete', array('title' => $this->getLanguageService()->getLL('clip_deleteMarked'))), $table, 'delete', $this->getLanguageService()->getLL('clip_deleteMarkedWarning'));
411 $onClick = 'checkOffCB(\'' . implode(',', $this->CBnames
) . '\', this); return false;';
412 $cells[] = '<a class="btn btn-default" rel="" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $this->getLanguageService()->getLL('clip_markRecords', TRUE) . '">' . IconUtility
::getSpriteIcon('actions-document-select') . '</a>';
414 $theData[$v] = implode('', $cells);
417 $theT = $this->linkWrapSort($this->getLanguageService()->getLL('c_' . $v, TRUE), $this->folderObject
->getCombinedIdentifier(), $v);
418 $theData[$v] = $theT;
422 $out .= '<thead>' . $this->addelement(1, '', $theData, '', '', '', 'th') . '</thead>';
423 $out .= '<tbody>' . $iOut . '</tbody>';
424 // half line is drawn
430 <div class="table-fit">
431 <table class="table table-striped table-hover" id="typo3-filelist">
437 /** @var $flashMessage FlashMessage */
438 $flashMessage = GeneralUtility
::makeInstance(FlashMessage
::class, $this->getLanguageService()->getLL('storageNotBrowsableMessage'), $this->getLanguageService()->getLL('storageNotBrowsableTitle'), FlashMessage
::INFO
);
439 $out = $flashMessage->render();
445 * If there is a parent folder and user has access to it, return an icon
446 * which is linked to the filelist of the parent folder.
448 * @param Folder $currentFolder
451 protected function getLinkToParentFolder(Folder
$currentFolder) {
454 $currentStorage = $currentFolder->getStorage();
455 $parentFolder = $currentFolder->getParentFolder();
456 if ($parentFolder->getIdentifier() !== $currentFolder->getIdentifier() && $currentStorage->isWithinFileMountBoundaries($parentFolder)) {
457 $levelUp = $this->linkWrapDir(
458 IconUtility
::getSpriteIcon(
459 'actions-view-go-up',
460 array('title' => $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.php:labels.upOneLevel', TRUE))
465 } catch (\Exception
$e) {}
470 * Gets the number of files and total size of a folder
474 public function getFolderInfo() {
475 if ($this->counter
== 1) {
476 $fileLabel = $this->getLanguageService()->getLL('file', TRUE);
478 $fileLabel = $this->getLanguageService()->getLL('files', TRUE);
480 return $this->counter
. ' ' . $fileLabel . ', ' . GeneralUtility
::formatSize($this->totalbytes
, $this->getLanguageService()->getLL('byteSizeUnits', TRUE));
484 * This returns tablerows for the directories in the array $items['sorting'].
486 * @param Folder[] $folders Folders of \TYPO3\CMS\Core\Resource\Folder
487 * @return string HTML table rows.
489 public function formatDirList(array $folders) {
491 foreach ($folders as $folderName => $folderObject) {
492 $role = $folderObject->getRole();
493 if ($role === FolderInterface
::ROLE_PROCESSING
) {
494 // don't show processing-folder
497 if ($role !== FolderInterface
::ROLE_DEFAULT
) {
498 $displayName = '<strong>' . htmlspecialchars($folderName) . '</strong>';
500 $displayName = htmlspecialchars($folderName);
503 list($flag, $code) = $this->fwd_rwd_nav();
506 $isLocked = $folderObject instanceof InaccessibleFolder
;
507 $isWritable = $folderObject->checkActionPermission('write');
512 // The icon with link
513 $theIcon = IconUtility
::getSpriteIconForResource($folderObject, array('title' => $folderName));
514 if (!$isLocked && $this->clickMenus
) {
515 $theIcon = $GLOBALS['SOBE']->doc
->wrapClickMenuOnIcon($theIcon, $folderObject->getCombinedIdentifier());
518 // Preparing and getting the data-array
521 foreach ($this->fieldArray
as $field) {
522 $theData[$field] = '';
524 $theData['file'] = $displayName;
526 foreach ($this->fieldArray
as $field) {
529 $numFiles = $folderObject->getFileCount();
530 $theData[$field] = $numFiles . ' ' . $this->getLanguageService()->getLL(($numFiles === 1 ?
'file' : 'files'), TRUE);
533 $theData[$field] = '<strong class="text-danger">' . $this->getLanguageService()->getLL('read', TRUE) . '</strong>' . (!$isWritable ?
'' : '<strong class="text-danger">' . $this->getLanguageService()->getLL('write', TRUE) . '</strong>');
536 $theData[$field] = $this->getLanguageService()->getLL('folder', TRUE);
539 // @todo: FAL: how to get the mtime info -- $theData[$field] = \TYPO3\CMS\Backend\Utility\BackendUtility::date($theFile['tstamp']);
540 $theData[$field] = '-';
543 $theData[$field] = $this->linkWrapDir($displayName, $folderObject);
546 $theData[$field] = $this->makeEdit($folderObject);
549 $theData[$field] = $this->makeClip($folderObject);
552 $theData[$field] = $this->makeRef($folderObject);
555 $theData[$field] = GeneralUtility
::fixed_lgd_cs($theData[$field], $this->fixedL
);
559 $out .= $this->addelement(1, $theIcon, $theData);
562 $this->dirCounter
= $this->eCounter
;
568 * Wraps the directory-titles
570 * @param string $title String to be wrapped in links
571 * @param Folder $folderObject Folder to work on
572 * @return string HTML
574 public function linkWrapDir($title, Folder
$folderObject) {
575 $href = $this->backPath
. $this->script
. '&id=' . rawurlencode($folderObject->getCombinedIdentifier());
576 $onclick = ' onclick="' . htmlspecialchars(('top.document.getElementsByName("navigation")[0].contentWindow.Tree.highlightActiveItem("file","folder' . GeneralUtility
::md5int($folderObject->getCombinedIdentifier()) . '_"+top.fsMod.currentBank)')) . '"';
577 // Sometimes $code contains plain HTML tags. In such a case the string should not be modified!
578 if ((string)$title === strip_tags($title)) {
579 return '<a href="' . htmlspecialchars($href) . '"' . $onclick . ' title="' . htmlspecialchars($title) . '">' . GeneralUtility
::fixed_lgd_cs($title, $this->fixedL
) . '</a>';
581 return '<a href="' . htmlspecialchars($href) . '"' . $onclick . '>' . $title . '</a>';
586 * Wraps filenames in links which opens the metadata editor.
588 * @param string $code String to be wrapped in links
589 * @param File $fileObject File to be linked
590 * @return string HTML
592 public function linkWrapFile($code, File
$fileObject) {
594 if ($fileObject instanceof File
&& $fileObject->isIndexed() && $fileObject->checkActionPermission('write') && $this->getBackendUser()->check('tables_modify', 'sys_file_metadata')) {
595 $metaData = $fileObject->_getMetaData();
597 'sys_file_metadata' => array($metaData['uid'] => 'edit')
599 $editOnClick = BackendUtility
::editOnClick(GeneralUtility
::implodeArrayForUrl('edit', $data), $GLOBALS['BACK_PATH'], $this->listUrl());
600 $title = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.editMetadata'));
601 $code = '<a href="#" title="' . $title . '" onclick="' . htmlspecialchars($editOnClick) . '">' . GeneralUtility
::fixed_lgd_cs($code, $this->fixedL
) . '</a>';
603 } catch (\Exception
$e) {
604 // intentional fall-through
610 * Returns list URL; This is the URL of the current script with id and imagemode parameters, that's all.
611 * The URL however is not relative (with the backpath), otherwise GeneralUtility::sanitizeLocalUrl() would say that
612 * the URL would be invalid
616 public function listURL() {
617 return GeneralUtility
::linkThisScript(array(
618 'target' => rawurlencode($this->folderObject
->getCombinedIdentifier()),
619 'imagemode' => $this->thumbs
624 * This returns tablerows for the files in the array $items['sorting'].
626 * @param File[] $files File items
627 * @return string HTML table rows.
629 public function formatFileList(array $files) {
631 // first two keys are "0" (default) and "-1" (multiple), after that comes the "other languages"
632 $allSystemLanguages = GeneralUtility
::makeInstance(TranslationConfigurationProvider
::class)->getSystemLanguages();
633 $systemLanguages = array_filter($allSystemLanguages, function($languageRecord) {
634 if ($languageRecord['uid'] === -1 ||
$languageRecord['uid'] === 0 ||
!$this->getBackendUser()->checkLanguageAccess($languageRecord['uid'])) {
641 foreach ($files as $fileObject) {
642 list($flag, $code) = $this->fwd_rwd_nav();
647 $this->totalbytes +
= $fileObject->getSize();
648 $ext = $fileObject->getExtension();
649 $fileName = trim($fileObject->getName());
650 // The icon with link
651 $theIcon = IconUtility
::getSpriteIconForResource($fileObject, array('title' => $fileName . ' [' . (int)$fileObject->getUid() . ']'));
652 if ($this->clickMenus
) {
653 $theIcon = $GLOBALS['SOBE']->doc
->wrapClickMenuOnIcon($theIcon, $fileObject->getCombinedIdentifier());
655 // Preparing and getting the data-array
657 foreach ($this->fieldArray
as $field) {
660 $theData[$field] = GeneralUtility
::formatSize($fileObject->getSize(), $this->getLanguageService()->getLL('byteSizeUnits', TRUE));
663 $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>');
666 $theData[$field] = strtoupper($ext);
669 $theData[$field] = BackendUtility
::date($fileObject->getModificationTime());
672 $theData[$field] = $this->makeEdit($fileObject);
675 $theData[$field] = $this->makeClip($fileObject);
677 case '_LOCALIZATION_':
678 if (!empty($systemLanguages) && $fileObject->isIndexed() && $fileObject->checkActionPermission('write') && $this->getBackendUser()->check('tables_modify', 'sys_file_metadata')) {
679 $metaDataRecord = $fileObject->_getMetaData();
680 $translations = $this->getTranslationsForMetaData($metaDataRecord);
683 foreach ($systemLanguages as $language) {
684 $languageId = $language['uid'];
685 $flagIcon = $language['flagIcon'];
686 if (array_key_exists($languageId, $translations)) {
687 $flagButtonIcon = IconUtility
::getSpriteIcon(
688 'actions-document-open',
689 array('title' => sprintf($GLOBALS['LANG']->getLL('editMetadataForLanguage'), $language['title'])),
690 array($flagIcon . '-overlay' => array()));
692 'sys_file_metadata' => array($translations[$languageId]['uid'] => 'edit')
694 $editOnClick = BackendUtility
::editOnClick(GeneralUtility
::implodeArrayForUrl('edit', $data), $GLOBALS['BACK_PATH'], $this->listUrl());
695 $languageCode .= '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($editOnClick) . '">' . $flagButtonIcon . '</a>';
697 $href = $GLOBALS['SOBE']->doc
->issueCommand(
698 '&cmd[sys_file_metadata][' . $metaDataRecord['uid'] . '][localize]=' . $languageId,
699 $this->backPath
. 'alt_doc.php?justLocalized=' . rawurlencode(('sys_file_metadata:' . $metaDataRecord['uid'] . ':' . $languageId)) .
700 '&returnUrl=' . rawurlencode($this->listURL()) . BackendUtility
::getUrlToken('editRecord')
702 $flagButtonIcon = IconUtility
::getSpriteIcon(
704 array('title' => sprintf($GLOBALS['LANG']->getLL('createMetadataForLanguage'), $language['title'])),
705 array($flagIcon . '-overlay' => array())
707 $languageCode .= '<a href="' . htmlspecialchars($href) . '" class="btn btn-default">' . $flagButtonIcon . '</a> ';
711 // Hide flag button bar when not translated yet
712 $theData[$field] = ' <div class="localisationData btn-group" data-fileid="' . $fileObject->getUid() . '"' .
713 (empty($translations) ?
' style="display: none;"' : '') . '>' . $languageCode . '</div>';
714 $theData[$field] .= '<a class="btn btn-default filelist-translationToggler" data-fileid="' . $fileObject->getUid() . '">' .
715 IconUtility
::getSpriteIcon(
716 'mimetypes-x-content-page-language-overlay',
718 'title' => $GLOBALS['LANG']->getLL('translateMetadata')
724 $theData[$field] = $this->makeRef($fileObject);
727 // Edit metadata of file
728 $theData[$field] = $this->linkWrapFile(htmlspecialchars($fileName), $fileObject);
730 if ($fileObject->isMissing()) {
731 $flashMessage = \TYPO3\CMS\Core\
Resource\Utility\BackendUtility
::getFlashMessageForMissingFile($fileObject);
732 $theData[$field] .= $flashMessage->render();
734 } elseif ($this->thumbs
&& $this->isImage($ext)) {
735 $processedFile = $fileObject->process(ProcessedFile
::CONTEXT_IMAGEPREVIEW
, array());
736 if ($processedFile) {
737 $thumbUrl = $processedFile->getPublicUrl(TRUE);
738 $theData[$field] .= '<br /><img src="' . $thumbUrl . '" title="' . htmlspecialchars($fileName) . '" alt="" />';
743 $theData[$field] = '';
744 if ($fileObject->hasProperty($field)) {
745 $theData[$field] = htmlspecialchars(GeneralUtility
::fixed_lgd_cs($fileObject->getProperty($field), $this->fixedL
));
749 $out .= $this->addelement(1, $theIcon, $theData);
758 * Fetch the translations for a sys_file_metadata record
760 * @param $metaDataRecord
761 * @return array keys are the sys_language uids, values are the $rows
763 protected function getTranslationsForMetaData($metaDataRecord) {
764 $where = $GLOBALS['TCA']['sys_file_metadata']['ctrl']['transOrigPointerField'] . '=' . (int)$metaDataRecord['uid'] .
765 ' AND ' . $GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField'] . '>0';
766 $translationRecords = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_file_metadata', $where);
767 $translations = array();
768 foreach ($translationRecords as $record) {
769 $translations[$record[$GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField']]] = $record;
771 return $translations;
775 * Returns TRUE if $ext is an image-extension according to $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
777 * @param string $ext File extension
780 public function isImage($ext) {
781 return GeneralUtility
::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($ext));
785 * Wraps the directory-titles ($code) in a link to filelist/mod1/index.php (id=$path) and sorting commands...
787 * @param string $code String to be wrapped
788 * @param string $folderIdentifier ID (path)
789 * @param string $col Sorting column
790 * @return string HTML
792 public function linkWrapSort($code, $folderIdentifier, $col) {
793 if ($this->sort
=== $col) {
794 // Check reverse sorting
795 $params = '&SET[sort]=' . $col . '&SET[reverse]=' . ($this->sortRev ?
'0' : '1');
796 $sortArrow = IconUtility
::getSpriteIcon('status-status-sorting-light-' . ($this->sortRev ?
'desc' : 'asc'));
798 $params = '&SET[sort]=' . $col . '&SET[reverse]=0';
801 $href = GeneralUtility
::resolveBackPath(($GLOBALS['BACK_PATH'] . $this->script
)) . '&id=' . rawurlencode($folderIdentifier) . $params;
802 return '<a href="' . htmlspecialchars($href) . '">' . $code . ' ' . $sortArrow . '</a>';
806 * Creates the clipboard control pad
808 * @param File|Folder $fileOrFolderObject Array with information about the file/directory for which to make the clipboard panel for the listing.
809 * @return string HTML-table
811 public function makeClip($fileOrFolderObject) {
812 if (!$fileOrFolderObject->checkActionPermission('read')) {
816 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
817 $md5 = GeneralUtility
::shortmd5($fullIdentifier);
818 // For normal clipboard, add copy/cut buttons:
819 if ($this->clipObj
->current
== 'normal') {
820 $isSel = $this->clipObj
->isSelected('_FILE', $md5);
821 $cells[] = '<a class="btn btn-default"" href="' . htmlspecialchars($this->clipObj
->selUrlFile($fullIdentifier, 1, ($isSel == 'copy'))) . '">' . IconUtility
::getSpriteIcon(('actions-edit-copy' . ($isSel == 'copy' ?
'-release' : '')), array('title' => $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.copy', TRUE))) . '</a>';
822 // we can only cut if file can be moved
823 if ($fileOrFolderObject->checkActionPermission('move')) {
824 $cells[] = '<a class="btn btn-default" href="' . htmlspecialchars($this->clipObj
->selUrlFile($fullIdentifier, 0, ($isSel == 'cut'))) . '">' . IconUtility
::getSpriteIcon(('actions-edit-cut' . ($isSel == 'cut' ?
'-release' : '')), array('title' => $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.cut', TRUE))) . '</a>';
826 $cells[] = $this->spaceIcon
;
829 // For numeric pads, add select checkboxes:
830 $n = '_FILE|' . $md5;
831 $this->CBnames
[] = $n;
832 $checked = $this->clipObj
->isSelected('_FILE', $md5) ?
' checked="checked"' : '';
833 $cells[] = '<label class="btn btn-default btn-checkbox"><input type="hidden" name="CBH[' . $n . ']" value="0" /><input type="checkbox" name="CBC[' . $n . ']" value="' . htmlspecialchars($fullIdentifier) . '" ' . $checked . ' /><span class="t3-icon fa"></span></label>';
835 // Display PASTE button, if directory:
836 $elFromTable = $this->clipObj
->elFromTable('_FILE');
837 if ($fileOrFolderObject instanceof Folder
&& count($elFromTable) && $fileOrFolderObject->checkActionPermission('write')) {
838 $addPasteButton = TRUE;
839 foreach ($elFromTable as $element) {
840 $clipBoardElement = $this->resourceFactory
->retrieveFileOrFolderObject($element);
841 if ($clipBoardElement instanceof Folder
&& $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement, $fileOrFolderObject)) {
842 $addPasteButton = FALSE;
845 if ($addPasteButton) {
846 $cells[] = '<a class="btn btn-default" href="' . htmlspecialchars($this->clipObj
->pasteUrl('_FILE', $fullIdentifier)) . '" onclick="return ' . htmlspecialchars($this->clipObj
->confirmMsg('_FILE', $fullIdentifier, 'into', $elFromTable)) . '" title="' . $this->getLanguageService()->getLL('clip_pasteInto', TRUE) . '">' . IconUtility
::getSpriteIcon('actions-document-paste-into') . '</a>';
849 // Compile items into a DIV-element:
850 return ' <div class="btn-group" role="group">' . implode('', $cells) . '</div>';
854 * Creates the edit control section
856 * @param File|Folder $fileOrFolderObject Array with information about the file/directory for which to make the edit control section for the listing.
857 * @return string HTML-table
859 public function makeEdit($fileOrFolderObject) {
861 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
862 // Edit file content (if editable)
863 if ($fileOrFolderObject instanceof File
&& $fileOrFolderObject->checkActionPermission('write') && GeneralUtility
::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileOrFolderObject->getExtension())) {
864 $url = BackendUtility
::getModuleUrl('file_edit', array('target' => $fullIdentifier));
865 $editOnClick = 'top.content.list_frame.location.href=top.TS.PATH_typo3+' . GeneralUtility
::quoteJSvalue($url) . '+\'&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
866 $cells['edit'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($editOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.editcontent') . '">' . IconUtility
::getSpriteIcon('actions-page-open') . '</a>';
868 $cells['edit'] = $this->spaceIcon
;
870 if ($fileOrFolderObject instanceof File
) {
871 $fileUrl = $fileOrFolderObject->getPublicUrl(TRUE);
873 $aOnClick = 'return top.openUrlInWindow(' . GeneralUtility
::quoteJSvalue($fileUrl) . ', \'WebFile\');';
874 $cells['view'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($aOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.view') . '">' . IconUtility
::getSpriteIcon('actions-document-view') . '</a>';
876 $cells['view'] = $this->spaceIcon
;
879 $cells['view'] = $this->spaceIcon
;
882 if ($fileOrFolderObject->checkActionPermission('rename')) {
883 $url = BackendUtility
::getModuleUrl('file_rename', array('target' => $fullIdentifier));
884 $renameOnClick = 'top.content.list_frame.location.href = top.TS.PATH_typo3+' . GeneralUtility
::quoteJSvalue($url) . '+\'&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
885 $cells['rename'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($renameOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.rename') . '">' . IconUtility
::getSpriteIcon('actions-edit-rename') . '</a>';
887 $cells['rename'] = $this->spaceIcon
;
889 if ($fileOrFolderObject->checkActionPermission('read')) {
891 if ($fileOrFolderObject instanceof Folder
) {
892 $infoOnClick = 'top.launchView( \'_FOLDER\', ' . GeneralUtility
::quoteJSvalue($fullIdentifier) . ');return false;';
893 } elseif ($fileOrFolderObject instanceof File
) {
894 $infoOnClick = 'top.launchView( \'_FILE\', ' . GeneralUtility
::quoteJSvalue($fullIdentifier) . ');return false;';
896 $cells['info'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($infoOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.info') . '">' . IconUtility
::getSpriteIcon('status-dialog-information') . '</a>';
898 $cells['info'] = $this->spaceIcon
;
902 if ($fileOrFolderObject->checkActionPermission('delete')) {
903 $identifier = $fileOrFolderObject->getIdentifier();
904 if ($fileOrFolderObject instanceof Folder
) {
905 $referenceCountText = BackendUtility
::referenceCount('_FILE', $identifier, ' (There are %s reference(s) to this folder!)');
907 $referenceCountText = BackendUtility
::referenceCount('sys_file', $fileOrFolderObject->getUid(), ' (There are %s reference(s) to this file!)');
910 if ($this->getBackendUser()->jsConfirmation(JsConfirmation
::DELETE
)) {
911 $confirmationCheck = 'confirm(' . GeneralUtility
::quoteJSvalue(sprintf($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:mess.delete'), $fileOrFolderObject->getName()) . $referenceCountText) . ')';
913 $confirmationCheck = '1 == 1';
916 $removeOnClick = 'if (' . $confirmationCheck . ') { top.content.list_frame.location.href=top.TS.PATH_typo3+' . GeneralUtility
::quoteJSvalue(BackendUtility
::getModuleUrl('tce_file') .'&file[delete][0][data]=' . rawurlencode($fileOrFolderObject->getCombinedIdentifier()) . '&vC=' . $this->getBackendUser()->veriCode() . BackendUtility
::getUrlToken('tceAction') . '&redirect=') . '+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);};';
918 $cells['delete'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($removeOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.delete') . '">' . IconUtility
::getSpriteIcon('actions-edit-delete') . '</a>';
920 $cells['delete'] = $this->spaceIcon
;
923 // Hook for manipulating edit icons.
924 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'])) {
925 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'] as $classData) {
926 $hookObject = GeneralUtility
::getUserObj($classData);
927 if (!$hookObject instanceof FileListEditIconHookInterface
) {
928 throw new \
UnexpectedValueException(
929 '$hookObject must implement interface \\TYPO3\\CMS\\Filelist\\FileListEditIconHookInterface',
933 $hookObject->manipulateEditIcons($cells, $this);
936 // Compile items into a DIV-element:
937 return '<div class="btn-group">' . implode('', $cells) . '</div>';
941 * Make reference count
943 * @param File|Folder $fileOrFolderObject Array with information about the file/directory for which to make the clipboard panel for the listing.
944 * @return string HTML
946 public function makeRef($fileOrFolderObject) {
947 if ($fileOrFolderObject instanceof FolderInterface
) {
950 // Look up the file in the sys_refindex.
951 // Exclude sys_file_metadata records as these are no use references
952 $referenceCount = $this->getDatabaseConnection()->exec_SELECTcountRows(
955 'ref_table=\'sys_file\' AND ref_uid = ' . (int)$fileOrFolderObject->getUid() . ' AND deleted=0 AND tablename != "sys_file_metadata"'
957 return $this->generateReferenceToolTip($referenceCount, '\'_FILE\', ' . GeneralUtility
::quoteJSvalue($fileOrFolderObject->getCombinedIdentifier()));
961 * Returns the database connection
962 * @return DatabaseConnection
964 protected function getDatabaseConnection() {
965 return $GLOBALS['TYPO3_DB'];
969 * Returns an instance of LanguageService
971 * @return \TYPO3\CMS\Lang\LanguageService
973 protected function getLanguageService() {
974 return $GLOBALS['LANG'];
978 * Returns the current BE user.
980 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
982 protected function getBackendUser() {
983 return $GLOBALS['BE_USER'];