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