[BUGFIX] Filelist: Removed call to deprecated method render()
[Packages/TYPO3.CMS.git] / typo3 / sysext / filelist / Classes / FileList.php
1 <?php
2 namespace TYPO3\CMS\Filelist;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Clipboard\Clipboard;
18 use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider;
19 use TYPO3\CMS\Backend\RecordList\AbstractRecordList;
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
21 use TYPO3\CMS\Core\Database\DatabaseConnection;
22 use TYPO3\CMS\Core\Imaging\Icon;
23 use TYPO3\CMS\Core\Imaging\IconFactory;
24 use TYPO3\CMS\Core\Messaging\FlashMessage;
25 use TYPO3\CMS\Core\Messaging\FlashMessageService;
26 use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException;
27 use TYPO3\CMS\Core\Resource\File;
28 use TYPO3\CMS\Core\Resource\Folder;
29 use TYPO3\CMS\Core\Resource\FolderInterface;
30 use TYPO3\CMS\Core\Resource\InaccessibleFolder;
31 use TYPO3\CMS\Core\Resource\ProcessedFile;
32 use TYPO3\CMS\Core\Resource\ResourceFactory;
33 use TYPO3\CMS\Core\Resource\Utility\ListUtility;
34 use TYPO3\CMS\Core\Type\Bitmask\JsConfirmation;
35 use TYPO3\CMS\Core\Utility\GeneralUtility;
36 use TYPO3\CMS\Filelist\Controller\FileListController;
37
38 /**
39 * Class for rendering of File>Filelist
40 */
41 class FileList extends AbstractRecordList
42 {
43 /**
44 * Default Max items shown
45 *
46 * @var int
47 */
48 public $iLimit = 40;
49
50 /**
51 * Thumbnails on records containing files (pictures)
52 *
53 * @var bool
54 */
55 public $thumbs = false;
56
57 /**
58 * Space icon used for alignment when no button is available
59 *
60 * @var string
61 */
62 public $spaceIcon;
63
64 /**
65 * Max length of strings
66 *
67 * @var int
68 */
69 public $fixedL = 30;
70
71 /**
72 * If TRUE click menus are generated on files and folders
73 *
74 * @var bool
75 */
76 public $clickMenus = 1;
77
78 /**
79 * The field to sort by
80 *
81 * @var string
82 */
83 public $sort = '';
84
85 /**
86 * Reverse sorting flag
87 *
88 * @var bool
89 */
90 public $sortRev = 1;
91
92 /**
93 * @var int
94 */
95 public $firstElementNumber = 0;
96
97 /**
98 * @var bool
99 */
100 public $clipBoard = 0;
101
102 /**
103 * @var bool
104 */
105 public $bigControlPanel = 0;
106
107 /**
108 * @var string
109 */
110 public $JScode = '';
111
112 /**
113 * @var string
114 */
115 public $HTMLcode = '';
116
117 /**
118 * @var int
119 */
120 public $totalbytes = 0;
121
122 /**
123 * @var array
124 */
125 public $dirs = array();
126
127 /**
128 * @var array
129 */
130 public $files = array();
131
132 /**
133 * @var string
134 */
135 public $path = '';
136
137 /**
138 * @var Folder
139 */
140 protected $folderObject;
141
142 /**
143 * Counting the elements no matter what
144 *
145 * @var int
146 */
147 public $eCounter = 0;
148
149 /**
150 * @var string
151 */
152 public $totalItems = '';
153
154 /**
155 * @var array
156 */
157 public $CBnames = array();
158
159 /**
160 * @var Clipboard $clipObj
161 */
162 public $clipObj;
163
164 /**
165 * @var ResourceFactory
166 */
167 protected $resourceFactory;
168
169 /**
170 * @param ResourceFactory $resourceFactory
171 */
172 public function injectResourceFactory(ResourceFactory $resourceFactory)
173 {
174 $this->resourceFactory = $resourceFactory;
175 }
176
177 /**
178 * @var IconFactory
179 */
180 protected $iconFactory;
181
182 /**
183 * @var FileListController
184 */
185 protected $fileListController;
186
187 /**
188 * Construct
189 *
190 * @param FileListController $fileListController
191 */
192 public function __construct(FileListController $fileListController)
193 {
194 parent::__construct();
195 $this->fileListController = $fileListController;
196 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
197 }
198
199 /**
200 * Initialization of class
201 *
202 * @param Folder $folderObject The folder to work on
203 * @param int $pointer Pointer
204 * @param bool $sort Sorting column
205 * @param bool $sortRev Sorting direction
206 * @param bool $clipBoard
207 * @param bool $bigControlPanel Show clipboard flag
208 * @return void
209 */
210 public function start(Folder $folderObject, $pointer, $sort, $sortRev, $clipBoard = false, $bigControlPanel = false)
211 {
212 $this->folderObject = $folderObject;
213 $this->counter = 0;
214 $this->totalbytes = 0;
215 $this->JScode = '';
216 $this->HTMLcode = '';
217 $this->path = $folderObject->getReadablePath();
218 $this->sort = $sort;
219 $this->sortRev = $sortRev;
220 $this->firstElementNumber = $pointer;
221 $this->clipBoard = $clipBoard;
222 $this->bigControlPanel = $bigControlPanel;
223 // Setting the maximum length of the filenames to the user's settings or minimum 30 (= $this->fixedL)
224 $this->fixedL = max($this->fixedL, $this->getBackendUser()->uc['titleLen']);
225 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_common.xlf');
226 $this->resourceFactory = ResourceFactory::getInstance();
227 }
228
229 /**
230 * Reading files and directories, counting elements and generating the list in ->HTMLcode
231 *
232 * @return void
233 */
234 public function generateList()
235 {
236 $this->HTMLcode .= $this->getTable('fileext,tstamp,size,rw,_REF_');
237 }
238
239 /**
240 * Return the buttons used by the filelist to include in the top header
241 *
242 * @param Folder $folderObject
243 * @return array
244 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, buttons are now defined in FileListController
245 */
246 public function getButtonsAndOtherMarkers(Folder $folderObject)
247 {
248 GeneralUtility::logDeprecatedFunction();
249 $otherMarkers = array(
250 'PAGE_ICON' => '',
251 'TITLE' => ''
252 );
253 $buttons = array(
254 'level_up' => $this->getLinkToParentFolder($folderObject),
255 'refresh' => '',
256 'title' => '',
257 'page_icon' => '',
258 'PASTE' => ''
259 );
260 // Makes the code for the folder icon in the top
261 if ($folderObject) {
262 $title = $folderObject->getReadablePath();
263 // Start compiling the HTML
264 // If this is some subFolder under the mount root....
265 if ($folderObject->getStorage()->isWithinFileMountBoundaries($folderObject)) {
266 // The icon with link
267 $otherMarkers['PAGE_ICON'] = '<span title="' . htmlspecialchars($title) . '">' . $this->iconFactory->getIconForResource($folderObject, Icon::SIZE_SMALL)->render() . '</span>';
268 } else {
269 // This is the root folder
270 $otherMarkers['PAGE_ICON'] = '<span title="' . htmlspecialchars($title) . '">' . $this->iconFactory->getIconForResource($folderObject, Icon::SIZE_SMALL, null, array('mount-root' => true))->render() . '</span>';
271 }
272 $otherMarkers['TITLE'] .= htmlspecialchars(GeneralUtility::fixed_lgd_cs($title, -($this->fixedL + 20)));
273
274 if ($this->clickMenus) {
275 $otherMarkers['PAGE_ICON'] = BackendUtility::wrapClickMenuOnIcon($otherMarkers['PAGE_ICON'], $folderObject->getCombinedIdentifier());
276 }
277 // Add paste button if clipboard is initialized
278 if ($this->clipObj instanceof Clipboard && $folderObject->checkActionPermission('write')) {
279 $elFromTable = $this->clipObj->elFromTable('_FILE');
280 if (!empty($elFromTable)) {
281 $addPasteButton = true;
282 $elToConfirm = array();
283 foreach ($elFromTable as $key => $element) {
284 $clipBoardElement = $this->resourceFactory->retrieveFileOrFolderObject($element);
285 if ($clipBoardElement instanceof Folder && $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement, $folderObject)) {
286 $addPasteButton = false;
287 }
288 $elToConfirm[$key] = $clipBoardElement->getName();
289 }
290 if ($addPasteButton) {
291 $buttons['PASTE'] = '<a href="' . htmlspecialchars($this->clipObj->pasteUrl('_FILE', $folderObject->getCombinedIdentifier())) . '" onclick="return ' . htmlspecialchars($this->clipObj->confirmMsg('_FILE', $this->path, 'into', $elToConfirm)) . '" title="' . $this->getLanguageService()->getLL('clip_paste', true) . '">' . $this->iconFactory->getIcon('actions-document-paste-after', Icon::SIZE_SMALL)->render() . '</a>';
292 }
293 }
294 }
295 }
296 $buttons['refresh'] = '<a href="' . htmlspecialchars($this->listURL()) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.reload', true) . '">' . $this->iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL)->render() . '</a>';
297 return array($buttons, $otherMarkers);
298 }
299
300 /**
301 * Wrapping input string in a link with clipboard command.
302 *
303 * @param string $string String to be linked - must be htmlspecialchar'ed / prepared before.
304 * @param string $_ unused
305 * @param string $cmd "cmd" value
306 * @param string $warning Warning for JS confirm message
307 * @return string Linked string
308 */
309 public function linkClipboardHeaderIcon($string, $_, $cmd, $warning = '')
310 {
311 $onClickEvent = 'document.dblistForm.cmd.value=' . GeneralUtility::quoteJSvalue($cmd) . ';document.dblistForm.submit();';
312 if ($warning) {
313 $onClickEvent = 'if (confirm(' . GeneralUtility::quoteJSvalue($warning) . ')){' . $onClickEvent . '}';
314 }
315 return '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($onClickEvent) . 'return false;">' . $string . '</a>';
316 }
317
318 /**
319 * Returns a table with directories and files listed.
320 *
321 * @param array $rowlist Array of files from path
322 * @return string HTML-table
323 */
324 public function getTable($rowlist)
325 {
326 // prepare space icon
327 $this->spaceIcon = '<span class="btn btn-default disabled">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
328
329 // @todo use folder methods directly when they support filters
330 $storage = $this->folderObject->getStorage();
331 $storage->resetFileAndFolderNameFiltersToDefault();
332
333 // Only render the contents of a browsable storage
334 if ($this->folderObject->getStorage()->isBrowsable()) {
335 try {
336 $foldersCount = $storage->countFoldersInFolder($this->folderObject);
337 $filesCount = $storage->countFilesInFolder($this->folderObject);
338 } catch (InsufficientFolderAccessPermissionsException $e) {
339 $foldersCount = 0;
340 $filesCount = 0;
341 }
342
343 if ($foldersCount <= $this->firstElementNumber) {
344 $foldersFrom = false;
345 $foldersNum = false;
346 } else {
347 $foldersFrom = $this->firstElementNumber;
348 if ($this->firstElementNumber + $this->iLimit > $foldersCount) {
349 $foldersNum = $foldersCount - $this->firstElementNumber;
350 } else {
351 $foldersNum = $this->iLimit;
352 }
353 }
354 if ($foldersCount >= $this->firstElementNumber + $this->iLimit) {
355 $filesFrom = false;
356 $filesNum = false;
357 } else {
358 if ($this->firstElementNumber <= $foldersCount) {
359 $filesFrom = 0;
360 $filesNum = $this->iLimit - $foldersNum;
361 } else {
362 $filesFrom = $this->firstElementNumber - $foldersCount;
363 if ($filesFrom + $this->iLimit > $filesCount) {
364 $filesNum = $filesCount - $filesFrom;
365 } else {
366 $filesNum = $this->iLimit;
367 }
368 }
369 }
370 $folders = $storage->getFoldersInFolder($this->folderObject, $foldersFrom, $foldersNum, true, false, trim($this->sort), (bool)$this->sortRev);
371 $files = $this->folderObject->getFiles($filesFrom, $filesNum, Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, false, trim($this->sort), (bool)$this->sortRev);
372 $this->totalItems = $foldersCount + $filesCount;
373 // Adds the code of files/dirs
374 $out = '';
375 $titleCol = 'file';
376 // Cleaning rowlist for duplicates and place the $titleCol as the first column always!
377 $rowlist = '_LOCALIZATION_,' . $rowlist;
378 $rowlist = GeneralUtility::rmFromList($titleCol, $rowlist);
379 $rowlist = GeneralUtility::uniqueList($rowlist);
380 $rowlist = $rowlist ? $titleCol . ',' . $rowlist : $titleCol;
381 if ($this->clipBoard) {
382 $rowlist = str_replace('_LOCALIZATION_,', '_LOCALIZATION_,_CLIPBOARD_,', $rowlist);
383 $this->addElement_tdCssClass['_CLIPBOARD_'] = 'col-clipboard';
384 }
385 if ($this->bigControlPanel) {
386 $rowlist = str_replace('_LOCALIZATION_,', '_LOCALIZATION_,_CONTROL_,', $rowlist);
387 $this->addElement_tdCssClass['_CONTROL_'] = 'col-control';
388 }
389 $this->fieldArray = explode(',', $rowlist);
390
391 // Add classes to table cells
392 $this->addElement_tdCssClass[$titleCol] = 'col-title';
393 $this->addElement_tdCssClass['_LOCALIZATION_'] = 'col-localizationa';
394
395 $folders = ListUtility::resolveSpecialFolderNames($folders);
396
397 $iOut = '';
398 // Directories are added
399 $this->eCounter = $this->firstElementNumber;
400 list(, $code) = $this->fwd_rwd_nav();
401 $iOut .= $code;
402
403 $iOut .= $this->formatDirList($folders);
404 // Files are added
405 $iOut .= $this->formatFileList($files);
406
407 $this->eCounter = $this->firstElementNumber + $this->iLimit <= $this->totalItems
408 ? $this->firstElementNumber + $this->iLimit
409 : $this->totalItems;
410 list(, $code) = $this->fwd_rwd_nav();
411 $iOut .= $code;
412
413 // Header line is drawn
414 $theData = array();
415 foreach ($this->fieldArray as $v) {
416 if ($v == '_CLIPBOARD_' && $this->clipBoard) {
417 $cells = array();
418 $table = '_FILE';
419 $elFromTable = $this->clipObj->elFromTable($table);
420 if (!empty($elFromTable) && $this->folderObject->checkActionPermission('write')) {
421 $addPasteButton = true;
422 $elToConfirm = array();
423 foreach ($elFromTable as $key => $element) {
424 $clipBoardElement = $this->resourceFactory->retrieveFileOrFolderObject($element);
425 if ($clipBoardElement instanceof Folder && $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement, $this->folderObject)) {
426 $addPasteButton = false;
427 }
428 $elToConfirm[$key] = $clipBoardElement->getName();
429 }
430 if ($addPasteButton) {
431 $cells[] = '<a class="btn btn-default" href="' . htmlspecialchars($this->clipObj->pasteUrl('_FILE', $this->folderObject->getCombinedIdentifier())) . '" onclick="return ' . htmlspecialchars($this->clipObj->confirmMsg('_FILE', $this->path, 'into', $elToConfirm)) . '" title="' . $this->getLanguageService()->getLL('clip_paste', 1) . '">' . $this->iconFactory->getIcon('actions-document-paste-after', Icon::SIZE_SMALL)->render() . '</a>';
432 }
433 }
434 if ($this->clipObj->current !== 'normal' && $iOut) {
435 $cells[] = $this->linkClipboardHeaderIcon('<span title="' . $this->getLanguageService()->getLL('clip_selectMarked', true) . '">' . $this->iconFactory->getIcon('actions-edit-copy', Icon::SIZE_SMALL)->render() . '</span>', $table, 'setCB');
436 $cells[] = $this->linkClipboardHeaderIcon('<span title="' . $this->getLanguageService()->getLL('clip_deleteMarked', true) . '">' . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render(), $table, 'delete', $this->getLanguageService()->getLL('clip_deleteMarkedWarning'));
437 $onClick = 'checkOffCB(' . GeneralUtility::quoteJSvalue(implode(',', $this->CBnames)) . ', this); return false;';
438 $cells[] = '<a class="btn btn-default" rel="" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $this->getLanguageService()->getLL('clip_markRecords', true) . '">' . $this->iconFactory->getIcon('actions-document-select', Icon::SIZE_SMALL)->render() . '</a>';
439 }
440 $theData[$v] = implode('', $cells);
441 } else {
442 // Normal row:
443 $theT = $this->linkWrapSort($this->getLanguageService()->getLL('c_' . $v, true), $this->folderObject->getCombinedIdentifier(), $v);
444 $theData[$v] = $theT;
445 }
446 }
447
448 $out .= '<thead>' . $this->addelement(1, '', $theData, '', '', '', 'th') . '</thead>';
449 $out .= '<tbody>' . $iOut . '</tbody>';
450 // half line is drawn
451 // finish
452 $out = '
453 <!--
454 Filelist table:
455 -->
456 <div class="table-fit">
457 <table class="table table-striped table-hover" id="typo3-filelist">
458 ' . $out . '
459 </table>
460 </div>';
461 } else {
462 /** @var $flashMessage FlashMessage */
463 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $this->getLanguageService()->getLL('storageNotBrowsableMessage'), $this->getLanguageService()->getLL('storageNotBrowsableTitle'), FlashMessage::INFO);
464 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
465 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
466 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
467 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
468 $defaultFlashMessageQueue->enqueue($flashMessage);
469 $out = '';
470 }
471 return $out;
472 }
473
474 /**
475 * If there is a parent folder and user has access to it, return an icon
476 * which is linked to the filelist of the parent folder.
477 *
478 * @param Folder $currentFolder
479 * @return string
480 */
481 protected function getLinkToParentFolder(Folder $currentFolder)
482 {
483 $levelUp = '';
484 try {
485 $currentStorage = $currentFolder->getStorage();
486 $parentFolder = $currentFolder->getParentFolder();
487 if ($parentFolder->getIdentifier() !== $currentFolder->getIdentifier() && $currentStorage->isWithinFileMountBoundaries($parentFolder)) {
488 $levelUp = $this->linkWrapDir(
489 '<span title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.upOneLevel', true) . '">'
490 . $this->iconFactory->getIcon('actions-view-go-up', Icon::SIZE_SMALL)->render()
491 . '</span>',
492 $parentFolder
493 );
494 }
495 } catch (\Exception $e) {
496 }
497 return $levelUp;
498 }
499
500 /**
501 * Gets the number of files and total size of a folder
502 *
503 * @return string
504 */
505 public function getFolderInfo()
506 {
507 if ($this->counter == 1) {
508 $fileLabel = $this->getLanguageService()->getLL('file', true);
509 } else {
510 $fileLabel = $this->getLanguageService()->getLL('files', true);
511 }
512 return $this->counter . ' ' . $fileLabel . ', ' . GeneralUtility::formatSize($this->totalbytes, $this->getLanguageService()->getLL('byteSizeUnits', true));
513 }
514
515 /**
516 * This returns tablerows for the directories in the array $items['sorting'].
517 *
518 * @param Folder[] $folders Folders of \TYPO3\CMS\Core\Resource\Folder
519 * @return string HTML table rows.
520 */
521 public function formatDirList(array $folders)
522 {
523 $out = '';
524 foreach ($folders as $folderName => $folderObject) {
525 $role = $folderObject->getRole();
526 if ($role === FolderInterface::ROLE_PROCESSING) {
527 // don't show processing-folder
528 continue;
529 }
530 if ($role !== FolderInterface::ROLE_DEFAULT) {
531 $displayName = '<strong>' . htmlspecialchars($folderName) . '</strong>';
532 } else {
533 $displayName = htmlspecialchars($folderName);
534 }
535
536 $isLocked = $folderObject instanceof InaccessibleFolder;
537 $isWritable = $folderObject->checkActionPermission('write');
538
539 // Initialization
540 $this->counter++;
541
542 // The icon with link
543 $theIcon = '<span title="' . htmlspecialchars($folderName) . '">' . $this->iconFactory->getIconForResource($folderObject, Icon::SIZE_SMALL)->render() . '</span>';
544 if (!$isLocked && $this->clickMenus) {
545 $theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, $folderObject->getCombinedIdentifier());
546 }
547
548 // Preparing and getting the data-array
549 $theData = array();
550 if ($isLocked) {
551 foreach ($this->fieldArray as $field) {
552 $theData[$field] = '';
553 }
554 $theData['file'] = $displayName;
555 } else {
556 foreach ($this->fieldArray as $field) {
557 switch ($field) {
558 case 'size':
559 try {
560 $numFiles = $folderObject->getFileCount();
561 } catch (InsufficientFolderAccessPermissionsException $e) {
562 $numFiles = 0;
563 }
564 $theData[$field] = $numFiles . ' ' . $this->getLanguageService()->getLL(($numFiles === 1 ? 'file' : 'files'), true);
565 break;
566 case 'rw':
567 $theData[$field] = '<strong class="text-danger">' . $this->getLanguageService()->getLL('read', true) . '</strong>' . (!$isWritable ? '' : '<strong class="text-danger">' . $this->getLanguageService()->getLL('write', true) . '</strong>');
568 break;
569 case 'fileext':
570 $theData[$field] = $this->getLanguageService()->getLL('folder', true);
571 break;
572 case 'tstamp':
573 // @todo: FAL: how to get the mtime info -- $theData[$field] = \TYPO3\CMS\Backend\Utility\BackendUtility::date($theFile['tstamp']);
574 $theData[$field] = '-';
575 break;
576 case 'file':
577 $theData[$field] = $this->linkWrapDir($displayName, $folderObject);
578 break;
579 case '_CONTROL_':
580 $theData[$field] = $this->makeEdit($folderObject);
581 break;
582 case '_CLIPBOARD_':
583 $theData[$field] = $this->makeClip($folderObject);
584 break;
585 case '_REF_':
586 $theData[$field] = $this->makeRef($folderObject);
587 break;
588 default:
589 $theData[$field] = GeneralUtility::fixed_lgd_cs($theData[$field], $this->fixedL);
590 }
591 }
592 }
593 $out .= $this->addelement(1, $theIcon, $theData);
594 }
595 return $out;
596 }
597
598 /**
599 * Wraps the directory-titles
600 *
601 * @param string $title String to be wrapped in links
602 * @param Folder $folderObject Folder to work on
603 * @return string HTML
604 */
605 public function linkWrapDir($title, Folder $folderObject)
606 {
607 $href = BackendUtility::getModuleUrl('file_FilelistList', ['id' => $folderObject->getCombinedIdentifier()]);
608 $onclick = ' onclick="' . htmlspecialchars(('top.document.getElementsByName("navigation")[0].contentWindow.Tree.highlightActiveItem("file","folder' . GeneralUtility::md5int($folderObject->getCombinedIdentifier()) . '_"+top.fsMod.currentBank)')) . '"';
609 // Sometimes $code contains plain HTML tags. In such a case the string should not be modified!
610 if ((string)$title === strip_tags($title)) {
611 return '<a href="' . htmlspecialchars($href) . '"' . $onclick . ' title="' . htmlspecialchars($title) . '">' . GeneralUtility::fixed_lgd_cs($title, $this->fixedL) . '</a>';
612 } else {
613 return '<a href="' . htmlspecialchars($href) . '"' . $onclick . '>' . $title . '</a>';
614 }
615 }
616
617 /**
618 * Wraps filenames in links which opens the metadata editor.
619 *
620 * @param string $code String to be wrapped in links
621 * @param File $fileObject File to be linked
622 * @return string HTML
623 */
624 public function linkWrapFile($code, File $fileObject)
625 {
626 try {
627 if ($fileObject instanceof File && $fileObject->isIndexed() && $fileObject->checkActionPermission('write') && $this->getBackendUser()->check('tables_modify', 'sys_file_metadata')) {
628 $metaData = $fileObject->_getMetaData();
629 $urlParameters = [
630 'edit' => [
631 'sys_file_metadata' => [
632 $metaData['uid'] => 'edit'
633 ]
634 ],
635 'returnUrl' => $this->listURL()
636 ];
637 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
638 $title = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.editMetadata'));
639 $code = '<a href="' . htmlspecialchars($url) . '" title="' . $title . '">' . GeneralUtility::fixed_lgd_cs($code, $this->fixedL) . '</a>';
640 }
641 } catch (\Exception $e) {
642 // intentional fall-through
643 }
644 return $code;
645 }
646
647 /**
648 * Returns list URL; This is the URL of the current script with id and imagemode parameters, that's all.
649 * The URL however is not relative, otherwise GeneralUtility::sanitizeLocalUrl() would say that
650 * the URL would be invalid
651 *
652 * @param string $altId
653 * @param string $table Table name to display. Enter "-1" for the current table.
654 * @param string $exclList Comma separated list of fields NOT to include ("sortField", "sortRev" or "firstElementNumber")
655 *
656 * @return string URL
657 */
658 public function listURL($altId = '', $table = '-1', $exclList = '')
659 {
660 return GeneralUtility::linkThisScript(array(
661 'target' => rawurlencode($this->folderObject->getCombinedIdentifier()),
662 'imagemode' => $this->thumbs
663 ));
664 }
665
666 /**
667 * This returns tablerows for the files in the array $items['sorting'].
668 *
669 * @param File[] $files File items
670 * @return string HTML table rows.
671 */
672 public function formatFileList(array $files)
673 {
674 $out = '';
675 // first two keys are "0" (default) and "-1" (multiple), after that comes the "other languages"
676 $allSystemLanguages = GeneralUtility::makeInstance(TranslationConfigurationProvider::class)->getSystemLanguages();
677 $systemLanguages = array_filter($allSystemLanguages, function ($languageRecord) {
678 if ($languageRecord['uid'] === -1 || $languageRecord['uid'] === 0 || !$this->getBackendUser()->checkLanguageAccess($languageRecord['uid'])) {
679 return false;
680 } else {
681 return true;
682 }
683 });
684
685 foreach ($files as $fileObject) {
686 // Initialization
687 $this->counter++;
688 $this->totalbytes += $fileObject->getSize();
689 $ext = $fileObject->getExtension();
690 $fileName = trim($fileObject->getName());
691 // The icon with link
692 $theIcon = '<span title="' . htmlspecialchars($fileName . ' [' . (int)$fileObject->getUid() . ']') . '">'
693 . $this->iconFactory->getIconForResource($fileObject, Icon::SIZE_SMALL)->render() . '</span>';
694 if ($this->clickMenus) {
695 $theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, $fileObject->getCombinedIdentifier());
696 }
697 // Preparing and getting the data-array
698 $theData = array();
699 foreach ($this->fieldArray as $field) {
700 switch ($field) {
701 case 'size':
702 $theData[$field] = GeneralUtility::formatSize($fileObject->getSize(), $this->getLanguageService()->getLL('byteSizeUnits', true));
703 break;
704 case 'rw':
705 $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>');
706 break;
707 case 'fileext':
708 $theData[$field] = strtoupper($ext);
709 break;
710 case 'tstamp':
711 $theData[$field] = BackendUtility::date($fileObject->getModificationTime());
712 break;
713 case '_CONTROL_':
714 $theData[$field] = $this->makeEdit($fileObject);
715 break;
716 case '_CLIPBOARD_':
717 $theData[$field] = $this->makeClip($fileObject);
718 break;
719 case '_LOCALIZATION_':
720 if (!empty($systemLanguages) && $fileObject->isIndexed() && $fileObject->checkActionPermission('write') && $this->getBackendUser()->check('tables_modify', 'sys_file_metadata')) {
721 $metaDataRecord = $fileObject->_getMetaData();
722 $translations = $this->getTranslationsForMetaData($metaDataRecord);
723 $languageCode = '';
724
725 foreach ($systemLanguages as $language) {
726 $languageId = $language['uid'];
727 $flagIcon = $language['flagIcon'];
728 if (array_key_exists($languageId, $translations)) {
729 $title = htmlspecialchars(sprintf($this->getLanguageService()->getLL('editMetadataForLanguage'), $language['title']));
730 // @todo the overlay for the flag needs to be added ($flagIcon . '-overlay')
731 $urlParameters = [
732 'edit' => [
733 'sys_file_metadata' => [
734 $translations[$languageId]['uid'] => 'edit'
735 ]
736 ],
737 'returnUrl' => $this->listURL()
738 ];
739 $flagButtonIcon = $this->iconFactory->getIcon($flagIcon, Icon::SIZE_SMALL, 'overlay-edit')->render();
740 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
741 $languageCode .= '<a href="' . htmlspecialchars($url) . '" class="btn btn-default" title="' . $title . '">'
742 . $flagButtonIcon . '</a>';
743 } else {
744 $parameters = [
745 'justLocalized' => 'sys_file_metadata:' . $metaDataRecord['uid'] . ':' . $languageId,
746 'returnUrl' => $this->listURL()
747 ];
748 $returnUrl = BackendUtility::getModuleUrl('record_edit', $parameters);
749 $href = BackendUtility::getLinkToDataHandlerAction(
750 '&cmd[sys_file_metadata][' . $metaDataRecord['uid'] . '][localize]=' . $languageId,
751 $returnUrl
752 );
753 $flagButtonIcon = '<span title="' . htmlspecialchars(sprintf($this->getLanguageService()->getLL('createMetadataForLanguage'), $language['title'])) . '">' . $this->iconFactory->getIcon($flagIcon, Icon::SIZE_SMALL, 'overlay-new')->render() . '</span>';
754 $languageCode .= '<a href="' . htmlspecialchars($href) . '" class="btn btn-default">' . $flagButtonIcon . '</a> ';
755 }
756 }
757
758 // Hide flag button bar when not translated yet
759 $theData[$field] = ' <div class="localisationData btn-group" data-fileid="' . $fileObject->getUid() . '"' .
760 (empty($translations) ? ' style="display: none;"' : '') . '>' . $languageCode . '</div>';
761 $theData[$field] .= '<a class="btn btn-default filelist-translationToggler" data-fileid="' . $fileObject->getUid() . '">' .
762 '<span title="' . $this->getLanguageService()->getLL('translateMetadata', true) . '">'
763 . $this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL)->render() . '</span>'
764 . '</a>';
765 }
766 break;
767 case '_REF_':
768 $theData[$field] = $this->makeRef($fileObject);
769 break;
770 case 'file':
771 // Edit metadata of file
772 $theData[$field] = $this->linkWrapFile(htmlspecialchars($fileName), $fileObject);
773
774 if ($fileObject->isMissing()) {
775 $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($fileObject);
776 $theData[$field] .= $flashMessage->render();
777 // Thumbnails?
778 } elseif ($this->thumbs && ($this->isImage($ext) || $this->isMediaFile($ext))) {
779 $processedFile = $fileObject->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, array());
780 if ($processedFile) {
781 $thumbUrl = $processedFile->getPublicUrl(true);
782 $theData[$field] .= '<br /><img src="' . $thumbUrl . '" ' .
783 'width="' . $processedFile->getProperty('width') . '" ' .
784 'height="' . $processedFile->getProperty('height') . '" ' .
785 'title="' . htmlspecialchars($fileName) . '" alt="" />';
786 }
787 }
788 break;
789 default:
790 $theData[$field] = '';
791 if ($fileObject->hasProperty($field)) {
792 $theData[$field] = htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileObject->getProperty($field), $this->fixedL));
793 }
794 }
795 }
796 $out .= $this->addelement(1, $theIcon, $theData);
797 }
798 return $out;
799 }
800
801 /**
802 * Fetch the translations for a sys_file_metadata record
803 *
804 * @param $metaDataRecord
805 * @return array keys are the sys_language uids, values are the $rows
806 */
807 protected function getTranslationsForMetaData($metaDataRecord)
808 {
809 $where = $GLOBALS['TCA']['sys_file_metadata']['ctrl']['transOrigPointerField'] . '=' . (int)$metaDataRecord['uid'] .
810 ' AND ' . $GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField'] . '>0';
811 $translationRecords = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_file_metadata', $where);
812 $translations = array();
813 foreach ($translationRecords as $record) {
814 $translations[$record[$GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField']]] = $record;
815 }
816 return $translations;
817 }
818
819 /**
820 * Returns TRUE if $ext is an image-extension according to $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
821 *
822 * @param string $ext File extension
823 * @return bool
824 */
825 public function isImage($ext)
826 {
827 return GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($ext));
828 }
829
830 /**
831 * Returns TRUE if $ext is an media-extension according to $GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext']
832 *
833 * @param string $ext File extension
834 * @return bool
835 */
836 public function isMediaFile($ext)
837 {
838 return GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext'], strtolower($ext));
839 }
840
841 /**
842 * Wraps the directory-titles ($code) in a link to filelist/Modules/Filelist/index.php (id=$path) and sorting commands...
843 *
844 * @param string $code String to be wrapped
845 * @param string $folderIdentifier ID (path)
846 * @param string $col Sorting column
847 * @return string HTML
848 */
849 public function linkWrapSort($code, $folderIdentifier, $col)
850 {
851 $params = ['id' => $folderIdentifier, 'SET' => [ 'sort' => $col ]];
852
853 if ($this->sort === $col) {
854 // Check reverse sorting
855 $params['SET']['reverse'] = ($this->sortRev ? '0' : '1');
856 $sortArrow = $this->iconFactory->getIcon('status-status-sorting-light-' . ($this->sortRev ? 'desc' : 'asc'), Icon::SIZE_SMALL)->render();
857 } else {
858 $params['SET']['reverse'] = 0;
859 $sortArrow = '';
860 }
861 $href = BackendUtility::getModuleUrl('file_FilelistList', $params);
862 return '<a href="' . htmlspecialchars($href) . '">' . $code . ' ' . $sortArrow . '</a>';
863 }
864
865 /**
866 * Creates the clipboard control pad
867 *
868 * @param File|Folder $fileOrFolderObject Array with information about the file/directory for which to make the clipboard panel for the listing.
869 * @return string HTML-table
870 */
871 public function makeClip($fileOrFolderObject)
872 {
873 if (!$fileOrFolderObject->checkActionPermission('read')) {
874 return '';
875 }
876 $cells = array();
877 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
878 $fullName = $fileOrFolderObject->getName();
879 $md5 = GeneralUtility::shortmd5($fullIdentifier);
880 // For normal clipboard, add copy/cut buttons:
881 if ($this->clipObj->current === 'normal') {
882 $isSel = $this->clipObj->isSelected('_FILE', $md5);
883 $copyTitle = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.copy', true);
884 $cutTitle = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.cut', true);
885 $copyIcon = $this->iconFactory->getIcon('actions-edit-copy', Icon::SIZE_SMALL)->render();
886 $cutIcon = $this->iconFactory->getIcon('actions-edit-cut', Icon::SIZE_SMALL)->render();
887
888 if ($isSel === 'copy') {
889 $copyIcon = $this->iconFactory->getIcon('actions-edit-copy-release', Icon::SIZE_SMALL)->render();
890 } elseif ($isSel === 'cut') {
891 $cutIcon = $this->iconFactory->getIcon('actions-edit-cut-release', Icon::SIZE_SMALL)->render();
892 }
893
894 $cells[] = '<a class="btn btn-default"" href="' . htmlspecialchars($this->clipObj->selUrlFile($fullIdentifier, 1, ($isSel === 'copy'))) . '" title="' . $copyTitle . '">' . $copyIcon . '</a>';
895 // we can only cut if file can be moved
896 if ($fileOrFolderObject->checkActionPermission('move')) {
897 $cells[] = '<a class="btn btn-default" href="' . htmlspecialchars($this->clipObj->selUrlFile($fullIdentifier, 0, ($isSel === 'cut'))) . '" title="' . $cutTitle . '">' . $cutIcon . '</a>';
898 } else {
899 $cells[] = $this->spaceIcon;
900 }
901 } else {
902 // For numeric pads, add select checkboxes:
903 $n = '_FILE|' . $md5;
904 $this->CBnames[] = $n;
905 $checked = $this->clipObj->isSelected('_FILE', $md5) ? ' checked="checked"' : '';
906 $cells[] = '<input type="hidden" name="CBH[' . $n . ']" value="0" /><label class="btn btn-default btn-checkbox"><input type="checkbox" name="CBC[' . $n . ']" value="' . htmlspecialchars($fullIdentifier) . '" ' . $checked . ' /><span class="t3-icon fa"></span></label>';
907 }
908 // Display PASTE button, if directory:
909 $elFromTable = $this->clipObj->elFromTable('_FILE');
910 if ($fileOrFolderObject instanceof Folder && !empty($elFromTable) && $fileOrFolderObject->checkActionPermission('write')) {
911 $addPasteButton = true;
912 $elToConfirm = array();
913 foreach ($elFromTable as $key => $element) {
914 $clipBoardElement = $this->resourceFactory->retrieveFileOrFolderObject($element);
915 if ($clipBoardElement instanceof Folder && $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement, $fileOrFolderObject)) {
916 $addPasteButton = false;
917 }
918 $elToConfirm[$key] = $clipBoardElement->getName();
919 }
920 if ($addPasteButton) {
921 $cells[] = '<a class="btn btn-default" href="' . htmlspecialchars($this->clipObj->pasteUrl('_FILE', $fullIdentifier)) . '" onclick="return ' . htmlspecialchars($this->clipObj->confirmMsg('_FILE', $fullName, 'into', $elToConfirm)) . '" title="' . $this->getLanguageService()->getLL('clip_pasteInto', true) . '">' . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render() . '</a>';
922 }
923 }
924 // Compile items into a DIV-element:
925 return ' <div class="btn-group" role="group">' . implode('', $cells) . '</div>';
926 }
927
928 /**
929 * Creates the edit control section
930 *
931 * @param File|Folder $fileOrFolderObject Array with information about the file/directory for which to make the edit control section for the listing.
932 * @return string HTML-table
933 */
934 public function makeEdit($fileOrFolderObject)
935 {
936 $cells = array();
937 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
938
939 // Edit file content (if editable)
940 if ($fileOrFolderObject instanceof File && $fileOrFolderObject->checkActionPermission('write') && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileOrFolderObject->getExtension())) {
941 $url = BackendUtility::getModuleUrl('file_edit', array('target' => $fullIdentifier));
942 $editOnClick = 'top.content.list_frame.location.href=' . GeneralUtility::quoteJSvalue($url) . '+\'&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
943 $cells['edit'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($editOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.editcontent') . '">'
944 . $this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)->render()
945 . '</a>';
946 } else {
947 $cells['edit'] = $this->spaceIcon;
948 }
949 if ($fileOrFolderObject instanceof File) {
950 $fileUrl = $fileOrFolderObject->getPublicUrl(true);
951 if ($fileUrl) {
952 $aOnClick = 'return top.openUrlInWindow(' . GeneralUtility::quoteJSvalue($fileUrl) . ', \'WebFile\');';
953 $cells['view'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($aOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.view') . '">' . $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL)->render() . '</a>';
954 } else {
955 $cells['view'] = $this->spaceIcon;
956 }
957 } else {
958 $cells['view'] = $this->spaceIcon;
959 }
960
961 // replace file
962 if ($fileOrFolderObject instanceof File && $fileOrFolderObject->checkActionPermission('replace')) {
963 $url = BackendUtility::getModuleUrl('file_replace', array('target' => $fullIdentifier, 'uid' => $fileOrFolderObject->getUid()));
964 $replaceOnClick = 'top.content.list_frame.location.href = ' . GeneralUtility::quoteJSvalue($url) . '+\'&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
965 $cells['replace'] = '<a href="#" class="btn btn-default" onclick="' . $replaceOnClick . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.replace') . '">' . $this->iconFactory->getIcon('actions-edit-replace', Icon::SIZE_SMALL)->render() . '</a>';
966 }
967
968 // rename the file
969 if ($fileOrFolderObject->checkActionPermission('rename')) {
970 $url = BackendUtility::getModuleUrl('file_rename', array('target' => $fullIdentifier));
971 $renameOnClick = 'top.content.list_frame.location.href = ' . GeneralUtility::quoteJSvalue($url) . '+\'&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
972 $cells['rename'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($renameOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.rename') . '">' . $this->iconFactory->getIcon('actions-edit-rename', Icon::SIZE_SMALL)->render() . '</a>';
973 } else {
974 $cells['rename'] = $this->spaceIcon;
975 }
976 if ($fileOrFolderObject->checkActionPermission('read')) {
977 $infoOnClick = '';
978 if ($fileOrFolderObject instanceof Folder) {
979 $infoOnClick = 'top.launchView( \'_FOLDER\', ' . GeneralUtility::quoteJSvalue($fullIdentifier) . ');return false;';
980 } elseif ($fileOrFolderObject instanceof File) {
981 $infoOnClick = 'top.launchView( \'_FILE\', ' . GeneralUtility::quoteJSvalue($fullIdentifier) . ');return false;';
982 }
983 $cells['info'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($infoOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.info') . '">' . $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL)->render() . '</a>';
984 } else {
985 $cells['info'] = $this->spaceIcon;
986 }
987
988 // delete the file
989 if ($fileOrFolderObject->checkActionPermission('delete')) {
990 $identifier = $fileOrFolderObject->getIdentifier();
991 if ($fileOrFolderObject instanceof Folder) {
992 $referenceCountText = BackendUtility::referenceCount('_FILE', $identifier, ' ' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.referencesToFolder'));
993 } else {
994 $referenceCountText = BackendUtility::referenceCount('sys_file', $fileOrFolderObject->getUid(), ' ' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.referencesToFile'));
995 }
996
997 if ($this->getBackendUser()->jsConfirmation(JsConfirmation::DELETE)) {
998 $confirmationCheck = '1';
999 } else {
1000 $confirmationCheck = '0';
1001 }
1002
1003 $deleteUrl = BackendUtility::getModuleUrl('tce_file');
1004 $confirmationMessage = sprintf($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:mess.delete'), $fileOrFolderObject->getName()) . $referenceCountText;
1005 $title = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.delete');
1006 $cells['delete'] = '<a href="#" class="btn btn-default t3js-filelist-delete" data-content="' . htmlspecialchars($confirmationMessage)
1007 . '" data-check="' . $confirmationCheck
1008 . '" data-delete-url="' . htmlspecialchars($deleteUrl)
1009 . '" data-title="' . htmlspecialchars($title)
1010 . '" data-identifier="' . htmlspecialchars($fileOrFolderObject->getCombinedIdentifier())
1011 . '" data-veri-code="' . $this->getBackendUser()->veriCode()
1012 . '" title="' . htmlspecialchars($title) . '">'
1013 . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render() . '</a>';
1014 } else {
1015 $cells['delete'] = $this->spaceIcon;
1016 }
1017
1018 // Hook for manipulating edit icons.
1019 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'])) {
1020 $cells['__fileOrFolderObject'] = $fileOrFolderObject;
1021 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'] as $classData) {
1022 $hookObject = GeneralUtility::getUserObj($classData);
1023 if (!$hookObject instanceof FileListEditIconHookInterface) {
1024 throw new \UnexpectedValueException(
1025 '$hookObject must implement interface \\TYPO3\\CMS\\Filelist\\FileListEditIconHookInterface',
1026 1235225797
1027 );
1028 }
1029 $hookObject->manipulateEditIcons($cells, $this);
1030 }
1031 unset($cells['__fileOrFolderObject']);
1032 }
1033 // Compile items into a DIV-element:
1034 return '<div class="btn-group">' . implode('', $cells) . '</div>';
1035 }
1036
1037 /**
1038 * Make reference count
1039 *
1040 * @param File|Folder $fileOrFolderObject Array with information about the file/directory for which to make the clipboard panel for the listing.
1041 * @return string HTML
1042 */
1043 public function makeRef($fileOrFolderObject)
1044 {
1045 if ($fileOrFolderObject instanceof FolderInterface) {
1046 return '-';
1047 }
1048 // Look up the file in the sys_refindex.
1049 // Exclude sys_file_metadata records as these are no use references
1050 $databaseConnection = $this->getDatabaseConnection();
1051 $table = 'sys_refindex';
1052 $referenceCount = $databaseConnection->exec_SELECTcountRows(
1053 '*',
1054 $table,
1055 'ref_table=' . $databaseConnection->fullQuoteStr('sys_file', $table)
1056 . ' AND ref_uid=' . (int)$fileOrFolderObject->getUid()
1057 . ' AND deleted=0'
1058 . ' AND tablename != ' . $databaseConnection->fullQuoteStr('sys_file_metadata', $table)
1059 );
1060 return $this->generateReferenceToolTip($referenceCount, '\'_FILE\', ' . GeneralUtility::quoteJSvalue($fileOrFolderObject->getCombinedIdentifier()));
1061 }
1062
1063 /**
1064 * Returns the database connection
1065 *
1066 * @return DatabaseConnection
1067 */
1068 protected function getDatabaseConnection()
1069 {
1070 return $GLOBALS['TYPO3_DB'];
1071 }
1072
1073 /**
1074 * Returns an instance of LanguageService
1075 *
1076 * @return \TYPO3\CMS\Lang\LanguageService
1077 */
1078 protected function getLanguageService()
1079 {
1080 return $GLOBALS['LANG'];
1081 }
1082
1083 /**
1084 * Returns the current BE user.
1085 *
1086 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1087 */
1088 protected function getBackendUser()
1089 {
1090 return $GLOBALS['BE_USER'];
1091 }
1092 }