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\Utility\BackendUtility
;
18 use TYPO3\CMS\Backend\Utility\IconUtility
;
19 use TYPO3\CMS\Core\Database\DatabaseConnection
;
20 use TYPO3\CMS\Core\Utility\GeneralUtility
;
21 use TYPO3\CMS\Core\
Resource\FolderInterface
;
24 * Class for rendering of File>Filelist
26 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
28 class FileList
extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList
{
31 * Default Max items shown
38 * Thumbnails on records containing files (pictures)
42 public $thumbs = FALSE;
45 * Space icon used for alignment when no button is available
52 * Max length of strings
64 * If TRUE click menus are generated on files and folders
68 public $clickMenus = 1;
71 * The field to sort by
78 * Reverse sorting flag
87 public $firstElementNumber = 0;
92 public $clipBoard = 0;
97 public $bigControlPanel = 0;
107 public $HTMLcode = '';
112 public $totalbytes = 0;
117 public $dirs = array();
122 public $files = array();
130 * @var \TYPO3\CMS\Core\Resource\Folder
132 protected $folderObject;
135 * Counting the elements no matter what
139 public $eCounter = 0;
144 public $dirCounter = 0;
149 public $totalItems = '';
154 public $CBnames = array();
157 * Initialization of class
159 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject The folder to work on
160 * @param int $pointer Pointer
161 * @param bool $sort Sorting column
162 * @param bool $sortRev Sorting direction
163 * @param bool $bigControlPanel Show clipboard flag
166 public function start(\TYPO3\CMS\Core\
Resource\Folder
$folderObject, $pointer, $sort, $sortRev, $clipBoard = FALSE, $bigControlPanel = FALSE) {
167 $this->script
= BackendUtility
::getModuleUrl('file_list');
168 $this->folderObject
= $folderObject;
170 $this->totalbytes
= 0;
172 $this->HTMLcode
= '';
173 $this->path
= $folderObject->getIdentifier();
175 $this->sortRev
= $sortRev;
176 $this->firstElementNumber
= $pointer;
177 $this->clipBoard
= $clipBoard;
178 $this->bigControlPanel
= $bigControlPanel;
179 // Setting the maximum length of the filenames to the user's settings or minimum 30 (= $this->fixedL)
180 $this->fixedL
= max($this->fixedL
, $GLOBALS['BE_USER']->uc
['titleLen']);
181 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_common.xlf');
185 * Reading files and directories, counting elements and generating the list in ->HTMLcode
189 public function generateList() {
190 $this->HTMLcode
.= $this->getTable('fileext,tstamp,size,rw,_REF_');
194 * Return the buttons used by the file list to include in the top header
196 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject
199 public function getButtonsAndOtherMarkers(\TYPO3\CMS\Core\
Resource\Folder
$folderObject) {
200 $otherMarkers = array(
205 'level_up' => $this->getLinkToParentFolder($folderObject),
211 // Makes the code for the folder icon in the top
213 $title = htmlspecialchars($folderObject->getIdentifier());
214 // Start compiling the HTML
215 // If this is some subFolder under the mount root....
216 if ($folderObject->getStorage()->isWithinFileMountBoundaries($folderObject)) {
217 // The icon with link
218 $otherMarkers['PAGE_ICON'] = IconUtility
::getSpriteIconForResource($folderObject, array('title' => $title));
219 // No HTML specialchars here - HTML like <strong> </strong> is allowed
220 $otherMarkers['TITLE'] .= GeneralUtility
::removeXSS(GeneralUtility
::fixed_lgd_cs($title, -($this->fixedL +
20)));
222 // This is the root folder
223 $otherMarkers['PAGE_ICON'] = IconUtility
::getSpriteIconForResource($folderObject, array('title' => $title, 'mount-root' => TRUE));
224 $otherMarkers['TITLE'] .= htmlspecialchars(GeneralUtility
::fixed_lgd_cs($title, -($this->fixedL +
20)));
226 if ($this->clickMenus
) {
227 $otherMarkers['PAGE_ICON'] = $GLOBALS['SOBE']->doc
->wrapClickMenuOnIcon($otherMarkers['PAGE_ICON'], $folderObject->getCombinedIdentifier());
229 // Add paste button if clipboard is initialized
230 if ($this->clipObj
instanceof \TYPO3\CMS\Backend\Clipboard\Clipboard
&& $folderObject->checkActionPermission('write')) {
231 $elFromTable = $this->clipObj
->elFromTable('_FILE');
232 if (count($elFromTable)) {
233 $buttons['PASTE'] = '<a href="' . htmlspecialchars($this->clipObj
->pasteUrl('_FILE', $this->folderObject
->getCombinedIdentifier())) . '" onclick="return ' . htmlspecialchars($this->clipObj
->confirmMsg('_FILE', $this->path
, 'into', $elFromTable)) . '" title="' . $GLOBALS['LANG']->getLL('clip_paste', TRUE) . '">' . IconUtility
::getSpriteIcon('actions-document-paste-after') . '</a>';
238 $buttons['refresh'] = '<a href="' . htmlspecialchars($this->listURL()) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.reload', TRUE) . '">' . IconUtility
::getSpriteIcon('actions-system-refresh') . '</a>';
239 return array($buttons, $otherMarkers);
243 * Wrapping input string in a link with clipboard command.
245 * @param string $string String to be linked - must be htmlspecialchar'ed / prepared before.
246 * @param string $table table - NOT USED
247 * @param string $cmd "cmd" value
248 * @param string $warning Warning for JS confirm message
249 * @return string Linked string
251 public function linkClipboardHeaderIcon($string, $table, $cmd, $warning = '') {
252 $onClickEvent = 'document.dblistForm.cmd.value=\'' . $cmd . '\';document.dblistForm.submit();';
254 $onClickEvent = 'if (confirm(' . GeneralUtility
::quoteJSvalue($warning) . ')){' . $onClickEvent . '}';
256 return '<a href="#" class="btn" onclick="' . htmlspecialchars($onClickEvent) . 'return false;">' . $string . '</a>';
260 * Returns a table with directories and files listed.
262 * @param array $rowlist Array of files from path
263 * @return string HTML-table
265 public function getTable($rowlist) {
266 // prepare space icon
267 $this->spaceIcon
= '<span class="btn disabled">' . IconUtility
::getSpriteIcon('empty-empty') . '</span>';
269 // @todo use folder methods directly when they support filters
270 $storage = $this->folderObject
->getStorage();
271 $storage->resetFileAndFolderNameFiltersToDefault();
273 // Only render the contents of a browsable storage
274 if ($this->folderObject
->getStorage()->isBrowsable()) {
275 $folders = $storage->getFolderIdentifiersInFolder($this->folderObject
->getIdentifier());
276 $files = $this->folderObject
->getFiles();
277 $this->sort
= trim($this->sort
);
278 if ($this->sort
!== '') {
279 $filesToSort = array();
280 /** @var $fileObject \TYPO3\CMS\Core\Resource\File */
281 foreach ($files as $fileObject) {
282 switch ($this->sort
) {
284 $sortingKey = $fileObject->getSize();
287 $sortingKey = ($fileObject->checkActionPermission('read') ?
'R' : '' . $fileObject->checkActionPermission('write')) ?
'W' : '';
290 $sortingKey = $fileObject->getExtension();
293 $sortingKey = $fileObject->getModificationTime();
296 $sortingKey = $fileObject->getName();
299 if ($fileObject->hasProperty($this->sort
)) {
300 $sortingKey = $fileObject->getProperty($this->sort
);
302 $sortingKey = $fileObject->getName();
306 while (isset($filesToSort[$sortingKey . $i])) {
309 $filesToSort[$sortingKey . $i] = $fileObject;
311 uksort($filesToSort, 'strnatcasecmp');
312 if ((int)$this->sortRev
=== 1) {
313 $filesToSort = array_reverse($filesToSort);
315 $files = $filesToSort;
317 $this->totalItems
= count($folders) +
count($files);
318 // Adds the code of files/dirs
321 // Cleaning rowlist for duplicates and place the $titleCol as the first column always!
322 $rowlist = '_LOCALIZATION_,' . $rowlist;
323 $rowlist = GeneralUtility
::rmFromList($titleCol, $rowlist);
324 $rowlist = GeneralUtility
::uniqueList($rowlist);
325 $rowlist = $rowlist ?
$titleCol . ',' . $rowlist : $titleCol;
326 if ($this->clipBoard
) {
327 $rowlist = str_replace('_LOCALIZATION_,', '_LOCALIZATION_,_CLIPBOARD_,', $rowlist);
328 $this->addElement_tdCssClass
['_CLIPBOARD_'] = 'col-clipboard';
330 if ($this->bigControlPanel
) {
331 $rowlist = str_replace('_LOCALIZATION_,', '_LOCALIZATION_,_CONTROL_,', $rowlist);
332 $this->addElement_tdCssClass
['_CONTROL_'] = 'col-control';
334 $this->fieldArray
= explode(',', $rowlist);
335 $folderObjects = array();
336 foreach ($folders as $folder) {
337 $folderObjects[] = $storage->getFolder($folder, TRUE);
339 // Add classes to table cells
340 $this->addElement_tdCssClass
[$titleCol] = 'col-title';
341 $this->addElement_tdCssClass
['_LOCALIZATION_'] = 'col-localizationa';
343 $folderObjects = \TYPO3\CMS\Core\
Resource\Utility\ListUtility
::resolveSpecialFolderNames($folderObjects);
344 uksort($folderObjects, 'strnatcasecmp');
346 // Directories are added
347 $iOut = $this->formatDirList($folderObjects);
349 $iOut .= $this->formatFileList($files, $titleCol);
350 // Header line is drawn
352 foreach ($this->fieldArray
as $v) {
353 if ($v == '_CLIPBOARD_' && $this->clipBoard
) {
356 $elFromTable = $this->clipObj
->elFromTable($table);
357 if (count($elFromTable) && $this->folderObject
->checkActionPermission('write')) {
358 $cells[] = '<a class="btn" href="' . htmlspecialchars($this->clipObj
->pasteUrl('_FILE', $this->folderObject
->getCombinedIdentifier())) . '" onclick="return ' . htmlspecialchars($this->clipObj
->confirmMsg('_FILE', $this->path
, 'into', $elFromTable)) . '" title="' . $GLOBALS['LANG']->getLL('clip_paste', 1) . '">' . IconUtility
::getSpriteIcon('actions-document-paste-after') . '</a>';
360 if ($this->clipObj
->current
!= 'normal' && $iOut) {
361 $cells[] = $this->linkClipboardHeaderIcon(IconUtility
::getSpriteIcon('actions-edit-copy', array('title' => $GLOBALS['LANG']->getLL('clip_selectMarked', TRUE))), $table, 'setCB');
362 $cells[] = $this->linkClipboardHeaderIcon(IconUtility
::getSpriteIcon('actions-edit-delete', array('title' => $GLOBALS['LANG']->getLL('clip_deleteMarked'))), $table, 'delete', $GLOBALS['LANG']->getLL('clip_deleteMarkedWarning'));
363 $onClick = 'checkOffCB(\'' . implode(',', $this->CBnames
) . '\', this); return false;';
364 $cells[] = '<a class="btn" rel="" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $GLOBALS['LANG']->getLL('clip_markRecords', TRUE) . '">' . IconUtility
::getSpriteIcon('actions-document-select') . '</a>';
366 $theData[$v] = implode('', $cells);
369 $theT = $this->linkWrapSort($GLOBALS['LANG']->getLL('c_' . $v, TRUE), $this->folderObject
->getCombinedIdentifier(), $v);
370 $theData[$v] = $theT;
374 $out .= '<thead>' . $this->addelement(1, '', $theData, '', '', '', 'th') . '</thead>';
375 $out .= '<tbody>' . $iOut . '</tbody>';
376 // half line is drawn
382 <div class="table-fit">
383 <table class="table table-striped table-hover" id="typo3-filelist">
389 /** @var $flashMessage \TYPO3\CMS\Core\Messaging\FlashMessage */
390 $flashMessage = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage
::class, $GLOBALS['LANG']->getLL('storageNotBrowsableMessage'), $GLOBALS['LANG']->getLL('storageNotBrowsableTitle'), \TYPO3\CMS\Core\Messaging\FlashMessage
::INFO
);
391 $out = $flashMessage->render();
398 * If there is a parent folder and user has access to it, return an icon
399 * which is linked to the filelist of the parent folder.
401 * @param \TYPO3\CMS\Core\Resource\Folder $currentFolder
404 protected function getLinkToParentFolder(\TYPO3\CMS\Core\
Resource\Folder
$currentFolder) {
407 $currentStorage = $currentFolder->getStorage();
408 $parentFolder = $currentFolder->getParentFolder();
409 if ($parentFolder->getIdentifier() !== $currentFolder->getIdentifier() && $currentStorage->isWithinFileMountBoundaries($parentFolder)) {
410 $levelUp = $this->linkWrapDir(
411 IconUtility
::getSpriteIcon(
412 'actions-view-go-up',
413 array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.upOneLevel', TRUE))
418 } catch (\Exception
$e) {}
422 * Gets the number of files and total size of a folder
426 public function getFolderInfo() {
427 if ($this->counter
== 1) {
428 $fileLabel = $GLOBALS['LANG']->getLL('file', TRUE);
430 $fileLabel = $GLOBALS['LANG']->getLL('files', TRUE);
432 return $this->counter
. ' ' . $fileLabel . ', ' . GeneralUtility
::formatSize($this->totalbytes
, $GLOBALS['LANG']->getLL('byteSizeUnits', TRUE));
436 * This returns tablerows for the directories in the array $items['sorting'].
438 * @param \TYPO3\CMS\Core\Resource\Folder[] $folders Folders of \TYPO3\CMS\Core\Resource\Folder
439 * @return string HTML table rows.
441 public function formatDirList(array $folders) {
443 foreach ($folders as $folderName => $folderObject) {
444 $role = $folderObject->getRole();
445 if ($role === FolderInterface
::ROLE_PROCESSING
) {
446 // don't show processing-folder
449 if ($role !== FolderInterface
::ROLE_DEFAULT
) {
450 $displayName = '<strong>' . htmlspecialchars($folderName) . '</strong>';
452 $displayName = htmlspecialchars($folderName);
455 list($flag, $code) = $this->fwd_rwd_nav();
458 $isLocked = $folderObject instanceof \TYPO3\CMS\Core\
Resource\InaccessibleFolder
;
459 $isWritable = $folderObject->checkActionPermission('write');
464 // The icon with link
465 $theIcon = IconUtility
::getSpriteIconForResource($folderObject, array('title' => $folderName));
466 if (!$isLocked && $this->clickMenus
) {
467 $theIcon = $GLOBALS['SOBE']->doc
->wrapClickMenuOnIcon($theIcon, $folderObject->getCombinedIdentifier());
470 // Preparing and getting the data-array
473 foreach ($this->fieldArray
as $field) {
474 $theData[$field] = '';
476 $theData['file'] = $displayName;
478 foreach ($this->fieldArray
as $field) {
481 $numFiles = $folderObject->getFileCount();
482 $theData[$field] = $numFiles . ' ' . $GLOBALS['LANG']->getLL(($numFiles === 1 ?
'file' : 'files'), TRUE);
485 $theData[$field] = '<strong class="text-danger">' . $GLOBALS['LANG']->getLL('read', TRUE) . '</strong>' . (!$isWritable ?
'' : '<strong class="text-danger">' . $GLOBALS['LANG']->getLL('write', TRUE) . '</strong>');
488 $theData[$field] = $GLOBALS['LANG']->getLL('folder', TRUE);
491 // @todo: FAL: how to get the mtime info -- $theData[$field] = \TYPO3\CMS\Backend\Utility\BackendUtility::date($theFile['tstamp']);
492 $theData[$field] = '-';
495 $theData[$field] = $this->linkWrapDir($displayName, $folderObject);
498 $theData[$field] = $this->makeEdit($folderObject);
501 $theData[$field] = $this->makeClip($folderObject);
504 $theData[$field] = $this->makeRef($folderObject);
507 $theData[$field] = GeneralUtility
::fixed_lgd_cs($theFile[$field], $this->fixedL
);
511 $out .= $this->addelement(1, $theIcon, $theData);
514 $this->dirCounter
= $this->eCounter
;
520 * Wraps the directory-titles
522 * @param string $title String to be wrapped in links
523 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject Folder to work on
524 * @return string HTML
526 public function linkWrapDir($title, \TYPO3\CMS\Core\
Resource\Folder
$folderObject) {
527 $href = $this->backPath
. $this->script
. '&id=' . rawurlencode($folderObject->getCombinedIdentifier());
528 $onclick = ' onclick="' . htmlspecialchars(('top.document.getElementsByName("navigation")[0].contentWindow.Tree.highlightActiveItem("file","folder' . GeneralUtility
::md5int($folderObject->getCombinedIdentifier()) . '_"+top.fsMod.currentBank)')) . '"';
529 // Sometimes $code contains plain HTML tags. In such a case the string should not be modified!
530 if ((string)$title === strip_tags($title)) {
531 return '<a href="' . htmlspecialchars($href) . '"' . $onclick . ' title="' . htmlspecialchars($title) . '">' . GeneralUtility
::fixed_lgd_cs($title, $this->fixedL
) . '</a>';
533 return '<a href="' . htmlspecialchars($href) . '"' . $onclick . '>' . $title . '</a>';
538 * Wraps filenames in links which opens them in a window IF they are in web-path.
540 * @param string $code String to be wrapped in links
541 * @param \TYPO3\CMS\Core\Resource\File $fileObject File to be linked
542 * @return string HTML
544 public function linkWrapFile($code, \TYPO3\CMS\Core\
Resource\File
$fileObject) {
545 $fileUrl = $fileObject->getPublicUrl(TRUE);
547 $aOnClick = 'return top.openUrlInWindow(\'' . $fileUrl . '\', \'WebFile\');';
548 $code = '<a href="#" title="' . htmlspecialchars($code) . '" onclick="' . htmlspecialchars($aOnClick) . '">' . GeneralUtility
::fixed_lgd_cs($code, $this->fixedL
) . '</a>';
554 * Returns list URL; This is the URL of the current script with id and imagemode parameters, that's all.
555 * The URL however is not relative (with the backpath), otherwise GeneralUtility::sanitizeLocalUrl() would say that
556 * the URL would be invalid
560 public function listURL() {
561 return GeneralUtility
::linkThisScript(array(
562 'target' => rawurlencode($this->folderObject
->getCombinedIdentifier()),
563 'imagemode' => $this->thumbs
568 * This returns tablerows for the files in the array $items['sorting'].
570 * @param \TYPO3\CMS\Core\Resource\File[] $files File items
571 * @return string HTML table rows.
573 public function formatFileList(array $files) {
575 // first two keys are "0" (default) and "-1" (multiple), after that comes the "other languages"
576 $allSystemLanguages = GeneralUtility
::makeInstance(\TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
::class)->getSystemLanguages();
577 $systemLanguages = array_filter($allSystemLanguages, function($languageRecord) {
578 if ($languageRecord['uid'] === -1 ||
$languageRecord['uid'] === 0 ||
!$GLOBALS['BE_USER']->checkLanguageAccess($languageRecord['uid'])) {
585 foreach ($files as $fileObject) {
586 list($flag, $code) = $this->fwd_rwd_nav();
591 $this->totalbytes +
= $fileObject->getSize();
592 $ext = $fileObject->getExtension();
593 $fileName = trim($fileObject->getName());
594 // The icon with link
595 $theIcon = IconUtility
::getSpriteIconForResource($fileObject, array('title' => $fileName . ' [' . (int)$fileObject->getUid() . ']'));
596 if ($this->clickMenus
) {
597 $theIcon = $GLOBALS['SOBE']->doc
->wrapClickMenuOnIcon($theIcon, $fileObject->getCombinedIdentifier());
599 // Preparing and getting the data-array
601 foreach ($this->fieldArray
as $field) {
604 $theData[$field] = GeneralUtility
::formatSize($fileObject->getSize(), $GLOBALS['LANG']->getLL('byteSizeUnits', TRUE));
607 $theData[$field] = '' . (!$fileObject->checkActionPermission('read') ?
' ' : '<strong class="text-danger">' . $GLOBALS['LANG']->getLL('read', TRUE) . '</strong>') . (!$fileObject->checkActionPermission('write') ?
'' : '<strong class="text-danger">' . $GLOBALS['LANG']->getLL('write', TRUE) . '</strong>');
610 $theData[$field] = strtoupper($ext);
613 $theData[$field] = BackendUtility
::date($fileObject->getModificationTime());
616 $theData[$field] = $this->makeEdit($fileObject);
619 $theData[$field] = $this->makeClip($fileObject);
621 case '_LOCALIZATION_':
622 if (!empty($systemLanguages) && $fileObject->isIndexed() && $fileObject->checkActionPermission('write')) {
623 $metaDataRecord = $fileObject->_getMetaData();
624 $translations = $this->getTranslationsForMetaData($metaDataRecord);
627 foreach ($systemLanguages as $language) {
628 $languageId = $language['uid'];
629 $flagIcon = $language['flagIcon'];
631 if (array_key_exists($languageId, $translations)) {
632 $flagButtonIcon = IconUtility
::getSpriteIcon(
633 'actions-document-open',
634 array('title' => $fileName),
635 array($flagIcon . '-overlay' => array()));
637 'sys_file_metadata' => array($translations[$languageId]['uid'] => 'edit')
639 $editOnClick = BackendUtility
::editOnClick(GeneralUtility
::implodeArrayForUrl('edit', $data), $GLOBALS['BACK_PATH'], $this->listUrl());
640 $languageCode .= '<a href="#" class="btn" onclick="' . $editOnClick . '">' . $flagButtonIcon . '</a>';
642 $href = $GLOBALS['SOBE']->doc
->issueCommand(
643 '&cmd[sys_file_metadata][' . $metaDataRecord['uid'] . '][localize]=' . $languageId,
644 $this->backPath
. 'alt_doc.php?justLocalized=' . rawurlencode(('sys_file_metadata:' . $metaDataRecord['uid'] . ':' . $languageId)) .
645 '&returnUrl=' . rawurlencode($this->listURL()) . BackendUtility
::getUrlToken('editRecord')
647 $flagButtonIcon = IconUtility
::getSpriteIcon($flagIcon);
648 $languageCode .= '<a href="' . htmlspecialchars($href) . '" class="btn">' . $flagButtonIcon . '</a> ';
652 // Hide flag button bar when not translated yet
653 $theData[$field] = ' <div class="localisationData btn-group" data-fileid="' . $fileObject->getUid() . '"' .
654 (empty($translations) ?
' style="display: none;"' : '') . '>' . $languageCode . '</div>';
655 $theData[$field] .= '<a class="btn filelist-translationToggler" data-fileid="' . $fileObject->getUid() . '">' .
656 IconUtility
::getSpriteIcon(
657 'mimetypes-x-content-page-language-overlay',
659 'title' => $GLOBALS['LANG']->getLL('translateMetadata')
665 $theData[$field] = $this->makeRef($fileObject);
668 $theData[$field] = $this->linkWrapFile(htmlspecialchars($fileName), $fileObject);
670 if ($fileObject->isMissing()) {
671 $flashMessage = \TYPO3\CMS\Core\
Resource\Utility\BackendUtility
::getFlashMessageForMissingFile($fileObject);
672 $theData[$field] .= $flashMessage->render();
674 } elseif ($this->thumbs
&& $this->isImage($ext)) {
675 $processedFile = $fileObject->process(\TYPO3\CMS\Core\
Resource\ProcessedFile
::CONTEXT_IMAGEPREVIEW
, array());
676 if ($processedFile) {
677 $thumbUrl = $processedFile->getPublicUrl(TRUE);
678 $theData[$field] .= '<br /><img src="' . $thumbUrl . '" title="' . htmlspecialchars($fileName) . '" alt="" />';
683 $theData[$field] = '';
684 if ($fileObject->hasProperty($field)) {
685 $theData[$field] = htmlspecialchars(GeneralUtility
::fixed_lgd_cs($fileObject->getProperty($field), $this->fixedL
));
689 $out .= $this->addelement(1, $theIcon, $theData);
698 * Fetch the translations for a sys_file_metadata record
700 * @param $metaDataRecord
701 * @return array keys are the sys_language uids, values are the $rows
703 protected function getTranslationsForMetaData($metaDataRecord) {
704 $where = $GLOBALS['TCA']['sys_file_metadata']['ctrl']['transOrigPointerField'] . '=' . (int)$metaDataRecord['uid'] .
705 ' AND ' . $GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField'] . '>0';
706 $translationRecords = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_file_metadata', $where);
707 $translations = array();
708 foreach ($translationRecords as $record) {
709 $translations[$record[$GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField']]] = $record;
711 return $translations;
715 * Returns TRUE if $ext is an image-extension according to $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
717 * @param string $ext File extension
720 public function isImage($ext) {
721 return GeneralUtility
::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($ext));
725 * Wraps the directory-titles ($code) in a link to filelist/mod1/index.php (id=$path) and sorting commands...
727 * @param string $code String to be wrapped
728 * @param string $folderIdentifier ID (path)
729 * @param string $col Sorting column
730 * @return string HTML
732 public function linkWrapSort($code, $folderIdentifier, $col) {
733 if ($this->sort
=== $col) {
734 // Check reverse sorting
735 $params = '&SET[sort]=' . $col . '&SET[reverse]=' . ($this->sortRev ?
'0' : '1');
736 $sortArrow = IconUtility
::getSpriteIcon('status-status-sorting-light-' . ($this->sortRev ?
'desc' : 'asc'));
738 $params = '&SET[sort]=' . $col . '&SET[reverse]=0';
741 $href = GeneralUtility
::resolveBackPath(($GLOBALS['BACK_PATH'] . $this->script
)) . '&id=' . rawurlencode($folderIdentifier) . $params;
742 return '<a href="' . htmlspecialchars($href) . '">' . $code . $sortArrow . '</a>';
746 * Creates the clipboard control pad
748 * @param \TYPO3\CMS\Core\Resource\File|\TYPO3\CMS\Core\Resource\Folder $fileOrFolderObject Array with information about the file/directory for which to make the clipboard panel for the listing.
749 * @return string HTML-table
751 public function makeClip($fileOrFolderObject) {
752 if (!$fileOrFolderObject->checkActionPermission('read')) {
756 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
757 $md5 = GeneralUtility
::shortmd5($fullIdentifier);
758 // For normal clipboard, add copy/cut buttons:
759 if ($this->clipObj
->current
== 'normal') {
760 $isSel = $this->clipObj
->isSelected('_FILE', $md5);
761 $cells[] = '<a class="btn" href="' . htmlspecialchars($this->clipObj
->selUrlFile($fullIdentifier, 1, ($isSel == 'copy'))) . '">' . IconUtility
::getSpriteIcon(('actions-edit-copy' . ($isSel == 'copy' ?
'-release' : '')), array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.copy', TRUE))) . '</a>';
762 // we can only cut if file can be moved
763 if ($fileOrFolderObject->checkActionPermission('move')) {
764 $cells[] = '<a class="btn" href="' . htmlspecialchars($this->clipObj
->selUrlFile($fullIdentifier, 0, ($isSel == 'cut'))) . '">' . IconUtility
::getSpriteIcon(('actions-edit-cut' . ($isSel == 'cut' ?
'-release' : '')), array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.cut', TRUE))) . '</a>';
766 $cells[] = $this->spaceIcon
;
769 // For numeric pads, add select checkboxes:
770 $n = '_FILE|' . $md5;
771 $this->CBnames
[] = $n;
772 $checked = $this->clipObj
->isSelected('_FILE', $md5) ?
' checked="checked"' : '';
773 $cells[] = '<div class="btn-checkbox-holder"><input type="hidden" name="CBH[' . $n . ']" value="0" /><input type="checkbox" name="CBC[' . $n . ']" value="' . htmlspecialchars($fullIdentifier) . '" class="smallCheckboxes btn-checkbox"' . $checked . ' /><span class="btn"><span class="t3-icon fa"></span></span></div>';
775 // Display PASTE button, if directory:
776 $elFromTable = $this->clipObj
->elFromTable('_FILE');
777 if (is_a($fileOrFolderObject, \TYPO3\CMS\Core\
Resource\Folder
::class) && count($elFromTable) && $fileOrFolderObject->checkActionPermission('write')) {
778 $cells[] = '<a class="btn" href="' . htmlspecialchars($this->clipObj
->pasteUrl('_FILE', $fullIdentifier)) . '" onclick="return ' . htmlspecialchars($this->clipObj
->confirmMsg('_FILE', $fullIdentifier, 'into', $elFromTable)) . '" title="' . $GLOBALS['LANG']->getLL('clip_pasteInto', TRUE) . '">' . IconUtility
::getSpriteIcon('actions-document-paste-into') . '</a>';
780 // Compile items into a DIV-element:
781 return ' <div class="btn-group">' . implode('', $cells) . '</div>';
785 * Creates the edit control section
787 * @param \TYPO3\CMS\Core\Resource\File|\TYPO3\CMS\Core\Resource\Folder $fileOrFolderObject Array with information about the file/directory for which to make the edit control section for the listing.
788 * @return string HTML-table
790 public function makeEdit($fileOrFolderObject) {
792 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
793 // Edit metadata of file
795 if (is_a($fileOrFolderObject, \TYPO3\CMS\Core\
Resource\File
::class) && $fileOrFolderObject->isIndexed() && $fileOrFolderObject->checkActionPermission('write')) {
796 $metaData = $fileOrFolderObject->_getMetaData();
798 'sys_file_metadata' => array($metaData['uid'] => 'edit')
800 $editOnClick = BackendUtility
::editOnClick(GeneralUtility
::implodeArrayForUrl('edit', $data), $GLOBALS['BACK_PATH'], $this->listUrl());
801 $title = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.editMetadata'));
802 $cells['editmetadata'] = '<a href="#" class="btn" onclick="' . $editOnClick . '" title="' . $title . '">'
803 . IconUtility
::getSpriteIcon('actions-document-open') . '</a>';
805 $cells['editmetadata'] = $this->spaceIcon
;
807 } catch (\Exception
$e) {
808 $cells['editmetadata'] = $this->spaceIcon
;
810 // Edit file content (if editable)
811 if (is_a($fileOrFolderObject, \TYPO3\CMS\Core\
Resource\File
::class) && $fileOrFolderObject->checkActionPermission('write') && GeneralUtility
::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileOrFolderObject->getExtension())) {
812 $url = BackendUtility
::getModuleUrl('file_edit', array('target' => $fullIdentifier));
813 $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;';
814 $cells['edit'] = '<a href="#" class="btn" onclick="' . htmlspecialchars($editOnClick) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.editcontent') . '">' . IconUtility
::getSpriteIcon('actions-page-open') . '</a>';
816 $cells['edit'] = $this->spaceIcon
;
819 if ($fileOrFolderObject->checkActionPermission('rename')) {
820 $url = BackendUtility
::getModuleUrl('file_rename', array('target' => $fullIdentifier));
821 $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;';
822 $cells['rename'] = '<a href="#" class="btn" onclick="' . htmlspecialchars($renameOnClick) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.rename') . '">' . IconUtility
::getSpriteIcon('actions-edit-rename') . '</a>';
824 $cells['rename'] = $this->spaceIcon
;
826 if ($fileOrFolderObject->checkActionPermission('read')) {
827 if (is_a($fileOrFolderObject, \TYPO3\CMS\Core\
Resource\Folder
::class)) {
828 $infoOnClick = 'top.launchView( \'_FOLDER\', \'' . $fullIdentifier . '\');return false;';
829 } elseif (is_a($fileOrFolderObject, \TYPO3\CMS\Core\
Resource\File
::class)) {
830 $infoOnClick = 'top.launchView( \'_FILE\', \'' . $fullIdentifier . '\');return false;';
832 $cells['info'] = '<a href="#" class="btn" onclick="' . $infoOnClick . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.info') . '">' . IconUtility
::getSpriteIcon('status-dialog-information') . '</a>';
834 $cells['info'] = $this->spaceIcon
;
838 if ($fileOrFolderObject->checkActionPermission('delete')) {
839 $identifier = $fileOrFolderObject->getIdentifier();
840 if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\
Resource\Folder
) {
841 $referenceCountText = BackendUtility
::referenceCount('_FILE', $identifier, ' (There are %s reference(s) to this folder!)');
843 $referenceCountText = BackendUtility
::referenceCount('sys_file', $fileOrFolderObject->getUid(), ' (There are %s reference(s) to this file!)');
846 if ($GLOBALS['BE_USER']->jsConfirmation(4)) {
847 $confirmationCheck = 'confirm(' . GeneralUtility
::quoteJSvalue(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.delete'), $fileOrFolderObject->getName()) . $referenceCountText) . ')';
849 $confirmationCheck = '1 == 1';
852 $removeOnClick = 'if (' . $confirmationCheck . ') { top.content.list_frame.location.href=top.TS.PATH_typo3+\'tce_file.php?file[delete][0][data]=' . rawurlencode($fileOrFolderObject->getCombinedIdentifier()) . '&vC=' . $GLOBALS['BE_USER']->veriCode() . BackendUtility
::getUrlToken('tceAction') . '&redirect=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);};';
854 $cells['delete'] = '<a href="#" class="btn" onclick="' . htmlspecialchars($removeOnClick) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.delete') . '">' . IconUtility
::getSpriteIcon('actions-edit-delete') . '</a>';
856 $cells['delete'] = $this->spaceIcon
;
859 // Hook for manipulating edit icons.
860 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'])) {
861 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'] as $classData) {
862 $hookObject = GeneralUtility
::getUserObj($classData);
863 if (!$hookObject instanceof \TYPO3\CMS\Filelist\FileListEditIconHookInterface
) {
864 throw new \
UnexpectedValueException(
865 '$hookObject must implement interface \\TYPO3\\CMS\\Filelist\\FileListEditIconHookInterface',
869 $hookObject->manipulateEditIcons($cells, $this);
872 // Compile items into a DIV-element:
873 return '<div class="btn-group">' . implode('', $cells) . '</div>';
877 * Make reference count
879 * @param \TYPO3\CMS\Core\Resource\File|\TYPO3\CMS\Core\Resource\Folder $fileOrFolderObject Array with information about the file/directory for which to make the clipboard panel for the listing.
880 * @return string HTML
882 public function makeRef($fileOrFolderObject) {
883 if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\
Resource\FolderInterface
) {
886 // Look up the file in the sys_refindex.
887 // Exclude sys_file_metadata records as these are no use references
888 $referenceCount = $this->getDatabaseConnection()->exec_SELECTcountRows(
891 'ref_table=\'sys_file\' AND ref_uid = ' . (int)$fileOrFolderObject->getUid() . ' AND deleted=0 AND tablename != "sys_file_metadata"'
893 return $this->generateReferenceToolTip($referenceCount, '\'_FILE\', ' . GeneralUtility
::quoteJSvalue($fileOrFolderObject->getCombinedIdentifier()));
897 * Returns the database connection
898 * @return DatabaseConnection
900 protected function getDatabaseConnection() {
901 return $GLOBALS['TYPO3_DB'];