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\Utility\GeneralUtility
;
20 use TYPO3\CMS\Core\
Resource\FolderInterface
;
23 * Class for rendering of File>Filelist
25 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
27 class FileList
extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList
{
30 * Default Max items shown
37 * Thumbnails on records containing files (pictures)
41 public $thumbs = FALSE;
44 * Space icon used for alignment when no button is available
51 * Max length of strings
63 * If TRUE click menus are generated on files and folders
67 public $clickMenus = 1;
70 * The field to sort by
77 * Reverse sorting flag
86 public $firstElementNumber = 0;
91 public $clipBoard = 0;
96 public $bigControlPanel = 0;
106 public $HTMLcode = '';
111 public $totalbytes = 0;
116 public $dirs = array();
121 public $files = array();
129 * @var \TYPO3\CMS\Core\Resource\Folder
131 protected $folderObject;
134 * Counting the elements no matter what
138 public $eCounter = 0;
143 public $dirCounter = 0;
148 public $totalItems = '';
153 public $CBnames = array();
156 * Initialization of class
158 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject The folder to work on
159 * @param int $pointer Pointer
160 * @param bool $sort Sorting column
161 * @param bool $sortRev Sorting direction
162 * @param bool $bigControlPanel Show clipboard flag
165 public function start(\TYPO3\CMS\Core\
Resource\Folder
$folderObject, $pointer, $sort, $sortRev, $clipBoard = FALSE, $bigControlPanel = FALSE) {
166 $this->script
= BackendUtility
::getModuleUrl('file_list');
167 $this->folderObject
= $folderObject;
169 $this->totalbytes
= 0;
171 $this->HTMLcode
= '';
172 $this->path
= $folderObject->getIdentifier();
174 $this->sortRev
= $sortRev;
175 $this->firstElementNumber
= $pointer;
176 $this->clipBoard
= $clipBoard;
177 $this->bigControlPanel
= $bigControlPanel;
178 // Setting the maximum length of the filenames to the user's settings or minimum 30 (= $this->fixedL)
179 $this->fixedL
= max($this->fixedL
, $GLOBALS['BE_USER']->uc
['titleLen']);
180 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_common.xlf');
184 * Reading files and directories, counting elements and generating the list in ->HTMLcode
188 public function generateList() {
189 $this->HTMLcode
.= $this->getTable('fileext,tstamp,size,rw,_REF_');
193 * Return the buttons used by the file list to include in the top header
195 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject
198 public function getButtonsAndOtherMarkers(\TYPO3\CMS\Core\
Resource\Folder
$folderObject) {
199 $otherMarkers = array(
204 'level_up' => $this->getLinkToParentFolder($folderObject),
210 // Makes the code for the folder icon in the top
212 $title = htmlspecialchars($folderObject->getIdentifier());
213 // Start compiling the HTML
214 // If this is some subFolder under the mount root....
215 if ($folderObject->getStorage()->isWithinFileMountBoundaries($folderObject)) {
216 // The icon with link
217 $otherMarkers['PAGE_ICON'] = IconUtility
::getSpriteIconForResource($folderObject, array('title' => $title));
218 // No HTML specialchars here - HTML like <strong> </strong> is allowed
219 $otherMarkers['TITLE'] .= GeneralUtility
::removeXSS(GeneralUtility
::fixed_lgd_cs($title, -($this->fixedL +
20)));
221 // This is the root folder
222 $otherMarkers['PAGE_ICON'] = IconUtility
::getSpriteIconForResource($folderObject, array('title' => $title, 'mount-root' => TRUE));
223 $otherMarkers['TITLE'] .= htmlspecialchars(GeneralUtility
::fixed_lgd_cs($title, -($this->fixedL +
20)));
225 if ($this->clickMenus
) {
226 $otherMarkers['PAGE_ICON'] = $GLOBALS['SOBE']->doc
->wrapClickMenuOnIcon($otherMarkers['PAGE_ICON'], $folderObject->getCombinedIdentifier());
228 // Add paste button if clipboard is initialized
229 if ($this->clipObj
instanceof \TYPO3\CMS\Backend\Clipboard\Clipboard
&& $folderObject->checkActionPermission('write')) {
230 $elFromTable = $this->clipObj
->elFromTable('_FILE');
231 if (count($elFromTable)) {
232 $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>';
237 $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>';
238 return array($buttons, $otherMarkers);
242 * Wrapping input string in a link with clipboard command.
244 * @param string $string String to be linked - must be htmlspecialchar'ed / prepared before.
245 * @param string $table table - NOT USED
246 * @param string $cmd "cmd" value
247 * @param string $warning Warning for JS confirm message
248 * @return string Linked string
250 public function linkClipboardHeaderIcon($string, $table, $cmd, $warning = '') {
251 $onClickEvent = 'document.dblistForm.cmd.value=\'' . $cmd . '\';document.dblistForm.submit();';
253 $onClickEvent = 'if (confirm(' . GeneralUtility
::quoteJSvalue($warning) . ')){' . $onClickEvent . '}';
255 return '<a href="#" class="btn" onclick="' . htmlspecialchars($onClickEvent) . 'return false;">' . $string . '</a>';
259 * Returns a table with directories and files listed.
261 * @param array $rowlist Array of files from path
262 * @return string HTML-table
264 public function getTable($rowlist) {
265 // prepare space icon
266 $this->spaceIcon
= '<span class="btn disabled">' . IconUtility
::getSpriteIcon('empty-empty') . '</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()) {
274 $folders = $storage->getFolderIdentifiersInFolder($this->folderObject
->getIdentifier());
275 $files = $this->folderObject
->getFiles();
276 $this->sort
= trim($this->sort
);
277 if ($this->sort
!== '') {
278 $filesToSort = array();
279 /** @var $fileObject \TYPO3\CMS\Core\Resource\File */
280 foreach ($files as $fileObject) {
281 switch ($this->sort
) {
283 $sortingKey = $fileObject->getSize();
286 $sortingKey = ($fileObject->checkActionPermission('read') ?
'R' : '' . $fileObject->checkActionPermission('write')) ?
'W' : '';
289 $sortingKey = $fileObject->getExtension();
292 $sortingKey = $fileObject->getModificationTime();
295 $sortingKey = $fileObject->getName();
298 if ($fileObject->hasProperty($this->sort
)) {
299 $sortingKey = $fileObject->getProperty($this->sort
);
301 $sortingKey = $fileObject->getName();
305 while (isset($filesToSort[$sortingKey . $i])) {
308 $filesToSort[$sortingKey . $i] = $fileObject;
310 uksort($filesToSort, 'strnatcasecmp');
311 if ((int)$this->sortRev
=== 1) {
312 $filesToSort = array_reverse($filesToSort);
314 $files = $filesToSort;
316 $this->totalItems
= count($folders) +
count($files);
317 // Adds the code of files/dirs
320 // Cleaning rowlist for duplicates and place the $titleCol as the first column always!
321 $rowlist = '_LOCALIZATION_,' . $rowlist;
322 $rowlist = GeneralUtility
::rmFromList($titleCol, $rowlist);
323 $rowlist = GeneralUtility
::uniqueList($rowlist);
324 $rowlist = $rowlist ?
$titleCol . ',' . $rowlist : $titleCol;
325 if ($this->clipBoard
) {
326 $rowlist = str_replace('_LOCALIZATION_,', '_LOCALIZATION_,_CLIPBOARD_,', $rowlist);
327 $this->addElement_tdCssClass
['_CLIPBOARD_'] = 'col-clipboard';
329 if ($this->bigControlPanel
) {
330 $rowlist = str_replace('_LOCALIZATION_,', '_LOCALIZATION_,_CONTROL_,', $rowlist);
331 $this->addElement_tdCssClass
['_CONTROL_'] = 'col-control';
333 $this->fieldArray
= explode(',', $rowlist);
334 $folderObjects = array();
335 foreach ($folders as $folder) {
336 $folderObjects[] = $storage->getFolder($folder, TRUE);
338 // Add classes to table cells
339 $this->addElement_tdCssClass
[$titleCol] = 'col-title';
340 $this->addElement_tdCssClass
['_LOCALIZATION_'] = 'col-localizationa';
342 $folderObjects = \TYPO3\CMS\Core\
Resource\Utility\ListUtility
::resolveSpecialFolderNames($folderObjects);
343 uksort($folderObjects, 'strnatcasecmp');
345 // Directories are added
346 $iOut = $this->formatDirList($folderObjects);
348 $iOut .= $this->formatFileList($files, $titleCol);
349 // Header line is drawn
351 foreach ($this->fieldArray
as $v) {
352 if ($v == '_CLIPBOARD_' && $this->clipBoard
) {
355 $elFromTable = $this->clipObj
->elFromTable($table);
356 if (count($elFromTable) && $this->folderObject
->checkActionPermission('write')) {
357 $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>';
359 if ($this->clipObj
->current
!= 'normal' && $iOut) {
360 $cells[] = $this->linkClipboardHeaderIcon(IconUtility
::getSpriteIcon('actions-edit-copy', array('title' => $GLOBALS['LANG']->getLL('clip_selectMarked', TRUE))), $table, 'setCB');
361 $cells[] = $this->linkClipboardHeaderIcon(IconUtility
::getSpriteIcon('actions-edit-delete', array('title' => $GLOBALS['LANG']->getLL('clip_deleteMarked'))), $table, 'delete', $GLOBALS['LANG']->getLL('clip_deleteMarkedWarning'));
362 $onClick = 'checkOffCB(\'' . implode(',', $this->CBnames
) . '\', this); return false;';
363 $cells[] = '<a class="btn" rel="" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $GLOBALS['LANG']->getLL('clip_markRecords', TRUE) . '">' . IconUtility
::getSpriteIcon('actions-document-select') . '</a>';
365 $theData[$v] = implode('', $cells);
368 $theT = $this->linkWrapSort($GLOBALS['LANG']->getLL('c_' . $v, TRUE), $this->folderObject
->getCombinedIdentifier(), $v);
369 $theData[$v] = $theT;
373 $out .= '<thead>' . $this->addelement(1, '', $theData, '', '', '', 'th') . '</thead>';
374 $out .= '<tbody>' . $iOut . '</tbody>';
375 // half line is drawn
381 <div class="table-fit">
382 <table class="table table-hover" id="typo3-filelist">
388 /** @var $flashMessage \TYPO3\CMS\Core\Messaging\FlashMessage */
389 $flashMessage = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage
::class, $GLOBALS['LANG']->getLL('storageNotBrowsableMessage'), $GLOBALS['LANG']->getLL('storageNotBrowsableTitle'), \TYPO3\CMS\Core\Messaging\FlashMessage
::INFO
);
390 $out = $flashMessage->render();
397 * If there is a parent folder and user has access to it, return an icon
398 * which is linked to the filelist of the parent folder.
400 * @param \TYPO3\CMS\Core\Resource\Folder $currentFolder
403 protected function getLinkToParentFolder(\TYPO3\CMS\Core\
Resource\Folder
$currentFolder) {
406 $currentStorage = $currentFolder->getStorage();
407 $parentFolder = $currentFolder->getParentFolder();
408 if ($parentFolder->getIdentifier() !== $currentFolder->getIdentifier() && $currentStorage->isWithinFileMountBoundaries($parentFolder)) {
409 $levelUp = $this->linkWrapDir(
410 IconUtility
::getSpriteIcon(
411 'actions-view-go-up',
412 array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.upOneLevel', TRUE))
417 } catch (\Exception
$e) {}
421 * Gets the number of files and total size of a folder
425 public function getFolderInfo() {
426 if ($this->counter
== 1) {
427 $fileLabel = $GLOBALS['LANG']->getLL('file', TRUE);
429 $fileLabel = $GLOBALS['LANG']->getLL('files', TRUE);
431 return $this->counter
. ' ' . $fileLabel . ', ' . GeneralUtility
::formatSize($this->totalbytes
, $GLOBALS['LANG']->getLL('byteSizeUnits', TRUE));
435 * This returns tablerows for the directories in the array $items['sorting'].
437 * @param \TYPO3\CMS\Core\Resource\Folder[] $folders Folders of \TYPO3\CMS\Core\Resource\Folder
438 * @return string HTML table rows.
440 public function formatDirList(array $folders) {
442 foreach ($folders as $folderName => $folderObject) {
443 $role = $folderObject->getRole();
444 if ($role === FolderInterface
::ROLE_PROCESSING
) {
445 // don't show processing-folder
448 if ($role !== FolderInterface
::ROLE_DEFAULT
) {
449 $displayName = '<strong>' . htmlspecialchars($folderName) . '</strong>';
451 $displayName = htmlspecialchars($folderName);
454 list($flag, $code) = $this->fwd_rwd_nav();
457 $isLocked = $folderObject instanceof \TYPO3\CMS\Core\
Resource\InaccessibleFolder
;
458 $isWritable = $folderObject->checkActionPermission('write');
463 // The icon with link
464 $theIcon = IconUtility
::getSpriteIconForResource($folderObject, array('title' => $folderName));
465 if (!$isLocked && $this->clickMenus
) {
466 $theIcon = $GLOBALS['SOBE']->doc
->wrapClickMenuOnIcon($theIcon, $folderObject->getCombinedIdentifier());
469 // Preparing and getting the data-array
472 foreach ($this->fieldArray
as $field) {
473 $theData[$field] = '';
475 $theData['file'] = $displayName;
477 foreach ($this->fieldArray
as $field) {
480 $numFiles = $folderObject->getFileCount();
481 $theData[$field] = $numFiles . ' ' . $GLOBALS['LANG']->getLL(($numFiles === 1 ?
'file' : 'files'), TRUE);
484 $theData[$field] = '<strong class="text-danger">' . $GLOBALS['LANG']->getLL('read', TRUE) . '</strong>' . (!$isWritable ?
'' : '<strong class="text-danger">' . $GLOBALS['LANG']->getLL('write', TRUE) . '</strong>');
487 $theData[$field] = $GLOBALS['LANG']->getLL('folder', TRUE);
490 // @todo: FAL: how to get the mtime info -- $theData[$field] = \TYPO3\CMS\Backend\Utility\BackendUtility::date($theFile['tstamp']);
491 $theData[$field] = '-';
494 $theData[$field] = $this->linkWrapDir($displayName, $folderObject);
497 $theData[$field] = $this->makeEdit($folderObject);
500 $theData[$field] = $this->makeClip($folderObject);
503 $theData[$field] = $this->makeRef($folderObject);
506 $theData[$field] = GeneralUtility
::fixed_lgd_cs($theFile[$field], $this->fixedL
);
510 $out .= $this->addelement(1, $theIcon, $theData);
513 $this->dirCounter
= $this->eCounter
;
519 * Wraps the directory-titles
521 * @param string $title String to be wrapped in links
522 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject Folder to work on
523 * @return string HTML
525 public function linkWrapDir($title, \TYPO3\CMS\Core\
Resource\Folder
$folderObject) {
526 $href = $this->backPath
. $this->script
. '&id=' . rawurlencode($folderObject->getCombinedIdentifier());
527 $onclick = ' onclick="' . htmlspecialchars(('top.content.nav_frame.hilight_row("file","folder' . GeneralUtility
::md5int($folderObject->getCombinedIdentifier()) . '_"+top.fsMod.currentBank)')) . '"';
528 // Sometimes $code contains plain HTML tags. In such a case the string should not be modified!
529 if ((string)$title === strip_tags($title)) {
530 return '<a href="' . htmlspecialchars($href) . '"' . $onclick . ' title="' . htmlspecialchars($title) . '">' . GeneralUtility
::fixed_lgd_cs($title, $this->fixedL
) . '</a>';
532 return '<a href="' . htmlspecialchars($href) . '"' . $onclick . '>' . $title . '</a>';
537 * Wraps filenames in links which opens them in a window IF they are in web-path.
539 * @param string $code String to be wrapped in links
540 * @param \TYPO3\CMS\Core\Resource\File $fileObject File to be linked
541 * @return string HTML
543 public function linkWrapFile($code, \TYPO3\CMS\Core\
Resource\File
$fileObject) {
544 $fileUrl = $fileObject->getPublicUrl(TRUE);
546 $aOnClick = 'return top.openUrlInWindow(\'' . $fileUrl . '\', \'WebFile\');';
547 $code = '<a href="#" title="' . htmlspecialchars($code) . '" onclick="' . htmlspecialchars($aOnClick) . '">' . GeneralUtility
::fixed_lgd_cs($code, $this->fixedL
) . '</a>';
553 * Returns list URL; This is the URL of the current script with id and imagemode parameters, that's all.
554 * The URL however is not relative (with the backpath), otherwise GeneralUtility::sanitizeLocalUrl() would say that
555 * the URL would be invalid
559 public function listURL() {
560 return GeneralUtility
::linkThisScript(array(
561 'target' => rawurlencode($this->folderObject
->getCombinedIdentifier()),
562 'imagemode' => $this->thumbs
567 * This returns tablerows for the files in the array $items['sorting'].
569 * @param \TYPO3\CMS\Core\Resource\File[] $files File items
570 * @return string HTML table rows.
572 public function formatFileList(array $files) {
574 // first two keys are "0" (default) and "-1" (multiple), after that comes the "other languages"
575 $allSystemLanguages = GeneralUtility
::makeInstance(\TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
::class)->getSystemLanguages();
576 $systemLanguages = array_filter($allSystemLanguages, function($languageRecord) {
577 if ($languageRecord['uid'] === -1 ||
$languageRecord['uid'] === 0 ||
!$GLOBALS['BE_USER']->checkLanguageAccess($languageRecord['uid'])) {
584 foreach ($files as $fileObject) {
585 list($flag, $code) = $this->fwd_rwd_nav();
590 $this->totalbytes +
= $fileObject->getSize();
591 $ext = $fileObject->getExtension();
592 $fileName = trim($fileObject->getName());
593 // The icon with link
594 $theIcon = IconUtility
::getSpriteIconForResource($fileObject, array('title' => $fileName));
595 if ($this->clickMenus
) {
596 $theIcon = $GLOBALS['SOBE']->doc
->wrapClickMenuOnIcon($theIcon, $fileObject->getCombinedIdentifier());
598 // Preparing and getting the data-array
600 foreach ($this->fieldArray
as $field) {
603 $theData[$field] = GeneralUtility
::formatSize($fileObject->getSize(), $GLOBALS['LANG']->getLL('byteSizeUnits', TRUE));
606 $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>');
609 $theData[$field] = strtoupper($ext);
612 $theData[$field] = BackendUtility
::date($fileObject->getModificationTime());
615 $theData[$field] = $this->makeEdit($fileObject);
618 $theData[$field] = $this->makeClip($fileObject);
620 case '_LOCALIZATION_':
621 if (!empty($systemLanguages) && $fileObject->isIndexed() && $fileObject->checkActionPermission('write')) {
622 $metaDataRecord = $fileObject->_getMetaData();
623 $translations = $this->getTranslationsForMetaData($metaDataRecord);
626 foreach ($systemLanguages as $language) {
627 $languageId = $language['uid'];
628 $flagIcon = $language['flagIcon'];
630 if (array_key_exists($languageId, $translations)) {
631 $flagButtonIcon = IconUtility
::getSpriteIcon(
632 'actions-document-open',
633 array('title' => $fileName),
634 array($flagIcon . '-overlay' => array()));
636 'sys_file_metadata' => array($translations[$languageId]['uid'] => 'edit')
638 $editOnClick = BackendUtility
::editOnClick(GeneralUtility
::implodeArrayForUrl('edit', $data), $GLOBALS['BACK_PATH'], $this->listUrl());
639 $languageCode .= '<a href="#" class="btn" onclick="' . $editOnClick . '">' . $flagButtonIcon . '</a>';
641 $href = $GLOBALS['SOBE']->doc
->issueCommand(
642 '&cmd[sys_file_metadata][' . $metaDataRecord['uid'] . '][localize]=' . $languageId,
643 $this->backPath
. 'alt_doc.php?justLocalized=' . rawurlencode(('sys_file_metadata:' . $metaDataRecord['uid'] . ':' . $languageId)) .
644 '&returnUrl=' . rawurlencode($this->listURL()) . BackendUtility
::getUrlToken('editRecord')
646 $flagButtonIcon = IconUtility
::getSpriteIcon($flagIcon);
647 $languageCode .= '<a href="' . htmlspecialchars($href) . '" class="btn">' . $flagButtonIcon . '</a> ';
651 // Hide flag button bar when not translated yet
652 $theData[$field] = ' <div class="localisationData btn-group" data-fileid="' . $fileObject->getUid() . '"' .
653 (empty($translations) ?
' style="display: none;"' : '') . '>' . $languageCode . '</div>';
654 $theData[$field] .= '<a class="btn filelist-translationToggler" data-fileid="' . $fileObject->getUid() . '">' .
655 IconUtility
::getSpriteIcon('mimetypes-x-content-page-language-overlay') . '</a>';
659 $theData[$field] = $this->makeRef($fileObject);
662 $theData[$field] = $this->linkWrapFile(htmlspecialchars($fileName), $fileObject);
664 if ($fileObject->isMissing()) {
665 $flashMessage = \TYPO3\CMS\Core\
Resource\Utility\BackendUtility
::getFlashMessageForMissingFile($fileObject);
666 $theData[$field] .= $flashMessage->render();
668 } elseif ($this->thumbs
&& $this->isImage($ext)) {
669 $processedFile = $fileObject->process(\TYPO3\CMS\Core\
Resource\ProcessedFile
::CONTEXT_IMAGEPREVIEW
, array());
670 if ($processedFile) {
671 $thumbUrl = $processedFile->getPublicUrl(TRUE);
672 $theData[$field] .= '<br /><img src="' . $thumbUrl . '" title="' . htmlspecialchars($fileName) . '" alt="" />';
677 $theData[$field] = '';
678 if ($fileObject->hasProperty($field)) {
679 $theData[$field] = htmlspecialchars(GeneralUtility
::fixed_lgd_cs($fileObject->getProperty($field), $this->fixedL
));
683 $out .= $this->addelement(1, $theIcon, $theData);
692 * Fetch the translations for a sys_file_metadata record
694 * @param $metaDataRecord
695 * @return array keys are the sys_language uids, values are the $rows
697 protected function getTranslationsForMetaData($metaDataRecord) {
698 $where = $GLOBALS['TCA']['sys_file_metadata']['ctrl']['transOrigPointerField'] . '=' . (int)$metaDataRecord['uid'] .
699 ' AND ' . $GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField'] . '>0';
700 $translationRecords = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_file_metadata', $where);
701 $translations = array();
702 foreach ($translationRecords as $record) {
703 $translations[$record[$GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField']]] = $record;
705 return $translations;
709 * Returns TRUE if $ext is an image-extension according to $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
711 * @param string $ext File extension
714 public function isImage($ext) {
715 return GeneralUtility
::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($ext));
719 * Wraps the directory-titles ($code) in a link to filelist/mod1/index.php (id=$path) and sorting commands...
721 * @param string $code String to be wrapped
722 * @param string $folderIdentifier ID (path)
723 * @param string $col Sorting column
724 * @return string HTML
726 public function linkWrapSort($code, $folderIdentifier, $col) {
727 if ($this->sort
=== $col) {
728 // Check reverse sorting
729 $params = '&SET[sort]=' . $col . '&SET[reverse]=' . ($this->sortRev ?
'0' : '1');
730 $sortArrow = IconUtility
::getSpriteIcon('status-status-sorting-light-' . ($this->sortRev ?
'desc' : 'asc'));
732 $params = '&SET[sort]=' . $col . '&SET[reverse]=0';
735 $href = GeneralUtility
::resolveBackPath(($GLOBALS['BACK_PATH'] . $this->script
)) . '&id=' . rawurlencode($folderIdentifier) . $params;
736 return '<a href="' . htmlspecialchars($href) . '">' . $code . $sortArrow . '</a>';
740 * Creates the clipboard control pad
742 * @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.
743 * @return string HTML-table
745 public function makeClip($fileOrFolderObject) {
746 if (!$fileOrFolderObject->checkActionPermission('read')) {
750 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
751 $md5 = GeneralUtility
::shortmd5($fullIdentifier);
752 // For normal clipboard, add copy/cut buttons:
753 if ($this->clipObj
->current
== 'normal') {
754 $isSel = $this->clipObj
->isSelected('_FILE', $md5);
755 $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>';
756 // we can only cut if file can be moved
757 if ($fileOrFolderObject->checkActionPermission('move')) {
758 $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>';
760 $cells[] = $this->spaceIcon
;
763 // For numeric pads, add select checkboxes:
764 $n = '_FILE|' . $md5;
765 $this->CBnames
[] = $n;
766 $checked = $this->clipObj
->isSelected('_FILE', $md5) ?
' checked="checked"' : '';
767 $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>';
769 // Display PASTE button, if directory:
770 $elFromTable = $this->clipObj
->elFromTable('_FILE');
771 if (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\Folder') && count($elFromTable) && $fileOrFolderObject->checkActionPermission('write')) {
772 $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>';
774 // Compile items into a DIV-element:
775 return ' <div class="btn-group">' . implode('', $cells) . '</div>';
779 * Creates the edit control section
781 * @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.
782 * @return string HTML-table
784 public function makeEdit($fileOrFolderObject) {
786 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
787 // Edit metadata of file
789 if (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\File') && $fileOrFolderObject->isIndexed() && $fileOrFolderObject->checkActionPermission('write')) {
790 $metaData = $fileOrFolderObject->_getMetaData();
792 'sys_file_metadata' => array($metaData['uid'] => 'edit')
794 $editOnClick = BackendUtility
::editOnClick(GeneralUtility
::implodeArrayForUrl('edit', $data), $GLOBALS['BACK_PATH'], $this->listUrl());
795 $title = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.editMetadata'));
796 $cells['editmetadata'] = '<a href="#" class="btn" onclick="' . $editOnClick . '" title="' . $title . '">'
797 . IconUtility
::getSpriteIcon('actions-document-open') . '</a>';
799 $cells['editmetadata'] = $this->spaceIcon
;
801 } catch (\Exception
$e) {
802 $cells['editmetadata'] = $this->spaceIcon
;
804 // Edit file content (if editable)
805 if (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\File') && $fileOrFolderObject->checkActionPermission('write') && GeneralUtility
::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileOrFolderObject->getExtension())) {
806 $url = BackendUtility
::getModuleUrl('file_edit', array('target' => $fullIdentifier));
807 $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;';
808 $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>';
810 $cells['edit'] = $this->spaceIcon
;
813 if ($fileOrFolderObject->checkActionPermission('rename')) {
814 $url = BackendUtility
::getModuleUrl('file_rename', array('target' => $fullIdentifier));
815 $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;';
816 $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>';
818 $cells['rename'] = $this->spaceIcon
;
820 if ($fileOrFolderObject->checkActionPermission('read')) {
821 if (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\Folder')) {
822 $infoOnClick = 'top.launchView( \'_FOLDER\', \'' . $fullIdentifier . '\');return false;';
823 } elseif (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\File')) {
824 $infoOnClick = 'top.launchView( \'_FILE\', \'' . $fullIdentifier . '\');return false;';
826 $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>';
828 $cells['info'] = $this->spaceIcon
;
832 if ($fileOrFolderObject->checkActionPermission('delete')) {
833 $identifier = $fileOrFolderObject->getIdentifier();
834 if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\
Resource\Folder
) {
835 $referenceCountText = BackendUtility
::referenceCount('_FILE', $identifier, ' (There are %s reference(s) to this folder!)');
837 $referenceCountText = BackendUtility
::referenceCount('sys_file', $fileOrFolderObject->getUid(), ' (There are %s reference(s) to this file!)');
840 if ($GLOBALS['BE_USER']->jsConfirmation(4)) {
841 $confirmationCheck = 'confirm(' . GeneralUtility
::quoteJSvalue(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.delete'), $fileOrFolderObject->getName()) . $referenceCountText) . ')';
843 $confirmationCheck = '1 == 1';
846 $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);};';
848 $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>';
850 $cells['delete'] = $this->spaceIcon
;
853 // Hook for manipulating edit icons.
854 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'])) {
855 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'] as $classData) {
856 $hookObject = GeneralUtility
::getUserObj($classData);
857 if (!$hookObject instanceof \TYPO3\CMS\Filelist\FileListEditIconHookInterface
) {
858 throw new \
UnexpectedValueException(
859 '$hookObject must implement interface \\TYPO3\\CMS\\Filelist\\FileListEditIconHookInterface',
863 $hookObject->manipulateEditIcons($cells, $this);
866 // Compile items into a DIV-element:
867 return '<div class="btn-group">' . implode('', $cells) . '</div>';
871 * Make reference count
873 * @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.
874 * @return string HTML
876 public function makeRef($fileOrFolderObject) {
877 if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\
Resource\FolderInterface
) {
880 // Look up the file in the sys_refindex.
881 // Exclude sys_file_metadata records as these are no use references
882 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_refindex', 'ref_table=\'sys_file\' AND ref_uid = ' . (int)$fileOrFolderObject->getUid() . ' AND deleted=0 AND tablename != "sys_file_metadata"');
883 return $this->generateReferenceToolTip($rows, '\'_FILE\', ' . GeneralUtility
::quoteJSvalue($fileOrFolderObject->getCombinedIdentifier()));