FileList.php 55.2 KB
Newer Older
1
<?php
2

3
/*
4
 * This file is part of the TYPO3 CMS project.
5
 *
6
7
8
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
9
 *
10
11
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
12
 *
13
14
 * The TYPO3 project - inspiring people to share!
 */
Wouter Wolters's avatar
Wouter Wolters committed
15

16
17
namespace TYPO3\CMS\Filelist;

18
19
use TYPO3\CMS\Backend\Clipboard\Clipboard;
use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider;
20
use TYPO3\CMS\Backend\Routing\UriBuilder;
21
use TYPO3\CMS\Backend\Utility\BackendUtility;
22
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
23
use TYPO3\CMS\Core\Database\ConnectionPool;
24
25
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
26
27
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Resource\AbstractFile;
28
use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException;
29
30
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\Folder;
31
use TYPO3\CMS\Core\Resource\FolderInterface;
32
use TYPO3\CMS\Core\Resource\InaccessibleFolder;
33
use TYPO3\CMS\Core\Resource\ProcessedFile;
34
use TYPO3\CMS\Core\Resource\ResourceFactory;
35
use TYPO3\CMS\Core\Resource\Utility\ListUtility;
36
use TYPO3\CMS\Core\Type\Bitmask\JsConfirmation;
37
use TYPO3\CMS\Core\Utility\GeneralUtility;
38
use TYPO3\CMS\Core\Utility\MathUtility;
39
use TYPO3\CMS\Core\Utility\PathUtility;
40
use TYPO3\CMS\Filelist\Configuration\ThumbnailConfiguration;
41

42
/**
43
44
 * Class for rendering of File>Filelist (basically used in FileListController)
 * @see \TYPO3\CMS\Filelist\Controller\FileListController
45
 * @internal this is a concrete TYPO3 controller implementation and solely used for EXT:filelist and not part of TYPO3's Core API.
46
 */
47
class FileList
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
{
    /**
     * Default Max items shown
     *
     * @var int
     */
    public $iLimit = 40;

    /**
     * Thumbnails on records containing files (pictures)
     *
     * @var bool
     */
    public $thumbs = false;

    /**
     * Space icon used for alignment when no button is available
     *
     * @var string
     */
    public $spaceIcon;

    /**
     * Max length of strings
     *
     * @var int
     */
    public $fixedL = 30;

    /**
     * The field to sort by
     *
     * @var string
     */
    public $sort = '';

    /**
     * Reverse sorting flag
     *
     * @var bool
     */
89
    public $sortRev = true;
90
91
92
93
94
95
96
97
98
99
100

    /**
     * @var int
     */
    public $firstElementNumber = 0;

    /**
     * @var int
     */
    public $totalbytes = 0;

101
102
103
    /**
     * This could be set to the total number of items. Used by the fwd_rew_navigation...
     *
104
     * @var int
105
     */
106
    public $totalItems = 0;
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

    /**
     * Decides the columns shown. Filled with values that refers to the keys of the data-array. $this->fieldArray[0] is the title column.
     *
     * @var array
     */
    public $fieldArray = [];

    /**
     * Counter increased for each element. Used to index elements for the JavaScript-code that transfers to the clipboard
     *
     * @var int
     */
    public $counter = 0;

122
123
124
125
126
127
128
129
    /**
     * Counting the elements no matter what
     *
     * @var int
     */
    public $eCounter = 0;

    /**
130
     * @var TranslationConfigurationProvider
131
     */
132
133
134
135
136
137
138
    public $translateTools;

    /**
     * Keys are fieldnames and values are td-css-classes to add in addElement();
     *
     * @var array
     */
139
140
141
142
143
144
    public $addElement_tdCssClass = [
        '_CONTROL_' => 'col-control',
        '_CLIPBOARD_' => 'col-clipboard',
        'file' => 'col-title col-responsive',
        '_LOCALIZATION_' => 'col-localizationa',
    ];
145
146
147
148
149

    /**
     * @var Folder
     */
    protected $folderObject;
150
151
152
153

    /**
     * @var array
     */
154
    public $CBnames = [];
155
156
157
158
159
160
161
162
163
164
165
166

    /**
     * @var Clipboard $clipObj
     */
    public $clipObj;

    /**
     * @var ResourceFactory
     */
    protected $resourceFactory;

    /**
167
     * @var IconFactory
168
     */
169
    protected $iconFactory;
170
171

    /**
172
     * @var int
173
     */
174
    protected $id = 0;
175

176
177
178
179
180
    /**
     * @var ThumbnailConfiguration
     */
    protected $thumbnailConfiguration;

181
    /**
182
     * @var UriBuilder
183
     */
184
185
    protected $uriBuilder;

186
    public function __construct()
187
    {
188
189
        // Setting the maximum length of the filenames to the user's settings or minimum 30 (= $this->fixedL)
        $this->fixedL = max($this->fixedL, $this->getBackendUser()->uc['titleLen'] ?? 1);
190
        $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
191
        $this->translateTools = GeneralUtility::makeInstance(TranslationConfigurationProvider::class);
192
        $this->thumbnailConfiguration = GeneralUtility::makeInstance(ThumbnailConfiguration::class);
193
        $this->iLimit = MathUtility::forceIntegerInRange(
194
            $this->getBackendUser()->getTSConfig()['options.']['file_list.']['filesPerPage'] ?? $this->iLimit,
195
196
            1
        );
197
198
199
200
201
202
203
204
        // Create clipboard object and initialize that
        $this->clipObj = GeneralUtility::makeInstance(Clipboard::class);
        $this->clipObj->fileMode = true;
        $this->clipObj->initializeClipboard();
        $this->resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
        $this->getLanguageService()->includeLLFile('EXT:core/Resources/Private/Language/locallang_common.xlf');
        $this->uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
        $this->spaceIcon = '<span class="btn btn-default disabled">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
205
206
    }

207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
    /**
     * Initialization of class
     *
     * @param Folder $folderObject The folder to work on
     * @param int $pointer Pointer
     * @param bool $sort Sorting column
     * @param bool $sortRev Sorting direction
     * @param bool $clipBoard
     * @param bool $bigControlPanel Show clipboard flag
     */
    public function start(Folder $folderObject, $pointer, $sort, $sortRev, $clipBoard = false, $bigControlPanel = false)
    {
        $this->folderObject = $folderObject;
        $this->counter = 0;
        $this->totalbytes = 0;
        $this->sort = $sort;
        $this->sortRev = $sortRev;
        $this->firstElementNumber = $pointer;
225
226
227
228
229
230
231
232
233
        // Cleaning rowlist for duplicates and place the $titleCol as the first column always!
        $rowlist = 'file,_LOCALIZATION_,fileext,tstamp,size,rw,_REF_';
        if ($clipBoard) {
            $rowlist = str_replace('_LOCALIZATION_,', '_LOCALIZATION_,_CLIPBOARD_,', $rowlist);
        }
        if ($bigControlPanel) {
            $rowlist = str_replace('_LOCALIZATION_,', '_LOCALIZATION_,_CONTROL_,', $rowlist);
        }
        $this->fieldArray = explode(',', $rowlist);
234
235
236
237
238
239
240
241
242
243
    }

    /**
     * Wrapping input string in a link with clipboard command.
     *
     * @param string $string String to be linked - must be htmlspecialchar'ed / prepared before.
     * @param string $cmd "cmd" value
     * @param string $warning Warning for JS confirm message
     * @return string Linked string
     */
244
    public function linkClipboardHeaderIcon($string, $cmd, $warning = '')
245
246
    {
        if ($warning) {
247
248
            $attributes['class'] = 'btn btn-default t3js-modal-trigger';
            $attributes['data-severity'] = 'warning';
249
            $attributes['data-bs-content'] = $warning;
250
251
            $attributes['data-event-name'] = 'filelist:clipboard:cmd';
            $attributes['data-event-payload'] = $cmd;
252
253
        } else {
            $attributes['class'] = 'btn btn-default';
254
            $attributes['data-filelist-clipboard-cmd'] = $cmd;
255
256
        }

257
        return '<a href="#" ' . GeneralUtility::implodeAttributes($attributes, true) . '>' . $string . '</a>';
258
259
260
261
262
263
264
    }

    /**
     * Returns a table with directories and files listed.
     *
     * @return string HTML-table
     */
265
    public function getTable()
266
267
268
269
270
271
    {
        // @todo use folder methods directly when they support filters
        $storage = $this->folderObject->getStorage();
        $storage->resetFileAndFolderNameFiltersToDefault();

        // Only render the contents of a browsable storage
272
273
274
275
276
277
278
279
280
281
        if (!$this->folderObject->getStorage()->isBrowsable()) {
            return '';
        }
        try {
            $foldersCount = $storage->countFoldersInFolder($this->folderObject);
            $filesCount = $storage->countFilesInFolder($this->folderObject);
        } catch (InsufficientFolderAccessPermissionsException $e) {
            $foldersCount = 0;
            $filesCount = 0;
        }
282

283
284
285
286
287
288
289
        if ($foldersCount <= $this->firstElementNumber) {
            $foldersFrom = false;
            $foldersNum = false;
        } else {
            $foldersFrom = $this->firstElementNumber;
            if ($this->firstElementNumber + $this->iLimit > $foldersCount) {
                $foldersNum = $foldersCount - $this->firstElementNumber;
290
            } else {
291
                $foldersNum = $this->iLimit;
292
            }
293
294
295
296
297
298
299
300
        }
        if ($foldersCount >= $this->firstElementNumber + $this->iLimit) {
            $filesFrom = false;
            $filesNum  = false;
        } else {
            if ($this->firstElementNumber <= $foldersCount) {
                $filesFrom = 0;
                $filesNum  = $this->iLimit - $foldersNum;
301
            } else {
302
303
304
                $filesFrom = $this->firstElementNumber - $foldersCount;
                if ($filesFrom + $this->iLimit > $filesCount) {
                    $filesNum = $filesCount - $filesFrom;
305
                } else {
306
                    $filesNum = $this->iLimit;
307
308
                }
            }
309
        }
310

311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
        $folders = $storage->getFoldersInFolder($this->folderObject, $foldersFrom, $foldersNum, true, false, trim($this->sort), (bool)$this->sortRev);
        $files = $this->folderObject->getFiles($filesFrom, $filesNum, Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, false, trim($this->sort), (bool)$this->sortRev);
        $this->totalItems = $foldersCount + $filesCount;
        // Adds the code of files/dirs

        $folders = ListUtility::resolveSpecialFolderNames($folders);

        $iOut = '';
        // Directories are added
        $this->eCounter = $this->firstElementNumber;
        $iOut .= $this->fwd_rwd_nav();

        $iOut .= $this->formatDirList($folders);
        // Files are added
        $iOut .= $this->formatFileList($files);

        $this->eCounter = $this->firstElementNumber + $this->iLimit < $this->totalItems
            ? $this->firstElementNumber + $this->iLimit
            : -1;
        $iOut .= $this->fwd_rwd_nav();

        // Header line is drawn
        $theData = [];
        foreach ($this->fieldArray as $v) {
            if ($v === '_CLIPBOARD_') {
                $theData[$v] = $this->renderClipboardHeaderRow(!empty($iOut));
            } elseif ($v === '_REF_') {
338
                $theData[$v] = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels._REF_'));
339
340
341
            } else {
                // Normal row
                $theData[$v]  = $this->linkWrapSort($this->folderObject->getCombinedIdentifier(), $v);
342
            }
343
        }
344

345
346
347
348
349
350
351
352
353
354
        return '
            <div class="panel panel-default">
                <div class="table-fit">
                    <table class="table table-striped table-hover" id="typo3-filelist">
                        <thead>' . $this->addElement('', $theData, 'th') . '</thead>
                        <tbody>' . $iOut . '</tbody>
                    </table>
                </div>
            </div>';
    }
355

356
357
358
359
360
361
362
363
364
365
366
367
368
    protected function renderClipboardHeaderRow(bool $hasContent): string
    {
        $cells = [];
        $elFromTable = $this->clipObj->elFromTable('_FILE');
        if (!empty($elFromTable) && $this->folderObject->checkActionPermission('write')) {
            $clipboardMode = $this->clipObj->clipData[$this->clipObj->current]['mode'] ?? '';
            $permission = $clipboardMode === 'copy' ? 'copy' : 'move';
            $addPasteButton = $this->folderObject->checkActionPermission($permission);
            $elToConfirm = [];
            foreach ($elFromTable as $key => $element) {
                $clipBoardElement = $this->resourceFactory->retrieveFileOrFolderObject($element);
                if ($clipBoardElement instanceof Folder && $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement, $this->folderObject)) {
                    $addPasteButton = false;
369
                }
370
371
372
373
374
375
376
377
                $elToConfirm[$key] = $clipBoardElement->getName();
            }
            if ($addPasteButton) {
                $cells[] = '<a class="btn btn-default t3js-modal-trigger"' .
                    ' href="' . htmlspecialchars($this->clipObj->pasteUrl(
                        '_FILE',
                        $this->folderObject->getCombinedIdentifier()
                    )) . '"'
378
                    . ' data-bs-content="' . htmlspecialchars($this->clipObj->confirmMsgText(
379
380
381
382
383
384
385
386
387
388
389
390
391
                        '_FILE',
                        $this->folderObject->getReadablePath(),
                        'into',
                        $elToConfirm
                    )) . '"'
                    . ' data-severity="warning"'
                    . ' data-title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_paste')) . '"'
                    . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_paste')) . '">'
                    . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)
                        ->render()
                    . '</a>';
            } else {
                $cells[] = $this->spaceIcon;
392
393
            }
        }
394
395
396
397
398
399
        if ($this->clipObj->current !== 'normal' && $hasContent) {
            $cells[] = $this->linkClipboardHeaderIcon('<span title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_selectMarked')) . '">' . $this->iconFactory->getIcon('actions-edit-copy', Icon::SIZE_SMALL)->render() . '</span>', 'setCB');
            $cells[] = $this->linkClipboardHeaderIcon('<span title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_deleteMarked')) . '">' . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render() . '</span>', 'delete', $this->getLanguageService()->getLL('clip_deleteMarkedWarning'));
            $cells[] = '<a class="btn btn-default t3js-toggle-all-checkboxes" data-checkboxes-names="' . htmlspecialchars(implode(',', $this->CBnames)) . '" rel="" href="#" title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_markRecords')) . '">' . $this->iconFactory->getIcon('actions-document-select', Icon::SIZE_SMALL)->render() . '</a>';
        }
        return implode('', $cells);
400
401
    }

402
403
404
405
406
    /**
     * Returns a table-row with the content from the fields in the input data array.
     * OBS: $this->fieldArray MUST be set! (represents the list of fields to display)
     *
     * @param string $icon Is the <img>+<a> of the record. If not supplied the first 'join'-icon will be a 'line' instead
407
     * @param array $data Is the data array, record with the fields. Notice: These fields are (currently) NOT htmlspecialchar'ed before being wrapped in <td>-tags
408
409
410
411
     * @param string $colType Defines the tag being used for the columns. Default is td.
     *
     * @return string HTML content for the table row
     */
412
    public function addElement($icon, $data, $colType = 'td')
413
414
415
    {
        $colType = ($colType === 'th') ? 'th' : 'td';
        // Start up:
416
        $l10nParent = (int)($data['_l10nparent_'] ?? 0);
417
        $out = '
418
419
420
421
422
		<tr data-uid="' . (int)($data['uid'] ?? 0) . '" data-l10nparent="' . $l10nParent . '">';
        $out .= '
        <' . $colType . ' class="col-icon nowrap">';
        if ($icon) {
            $out .= $icon;
423
        }
424
        $out .= '</' . $colType . '>';
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
        // Init rendering.
        $colsp = '';
        $lastKey = '';
        $c = 0;
        $ccount = 0;
        // __label is used as the label key to circumvent problems with uid used as label (see #67756)
        // as it was introduced later on, check if it really exists before using it
        $fields = $this->fieldArray;
        if ($colType === 'td' && array_key_exists('__label', $data)) {
            $fields[0] = '__label';
        }
        // Traverse field array which contains the data to present:
        foreach ($fields as $vKey) {
            if (isset($data[$vKey])) {
                if ($lastKey) {
440
                    $cssClass = $this->addElement_tdCssClass[$lastKey] ?? '';
441
                    $out .= '
442
						<' . $colType . ' class="' . $cssClass . '"' . $colsp . '>' . $data[$lastKey] . '</' . $colType . '>';
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
                }
                $lastKey = $vKey;
                $c = 1;
                $ccount++;
            } else {
                if (!$lastKey) {
                    $lastKey = $vKey;
                }
                $c++;
            }
            if ($c > 1) {
                $colsp = ' colspan="' . $c . '"';
            } else {
                $colsp = '';
            }
        }
        if ($lastKey) {
460
            $cssClass = $this->addElement_tdCssClass[$lastKey] ?? '';
461
            $out .= '
462
				<' . $colType . ' class="' . $cssClass . '"' . $colsp . '>' . $data[$lastKey] . '</' . $colType . '>';
463
464
465
466
467
468
469
470
471
        }
        $out .= '
		</tr>';
        return $out;
    }

    /**
     * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
     *
472
     * @return string the table-row code for the element
473
     */
474
    public function fwd_rwd_nav()
475
476
477
478
479
480
    {
        $code = '';
        if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber + $this->iLimit) {
            if ($this->firstElementNumber && $this->eCounter == $this->firstElementNumber) {
                // 	Reverse
                $theData = [];
481
482
                $theData['file'] = $this->fwd_rwd_HTML('fwd', $this->eCounter);
                $code = $this->addElement('', $theData);
483
            }
484
            return $code;
485
486
487
488
        }
        if ($this->eCounter == $this->firstElementNumber + $this->iLimit) {
            // 	Forward
            $theData = [];
489
490
            $theData['file'] = $this->fwd_rwd_HTML('rwd', $this->eCounter);
            $code = $this->addElement('', $theData);
491
        }
492
        return $code;
493
494
495
496
497
498
499
500
    }

    /**
     * Creates the button with link to either forward or reverse
     *
     * @param string $type Type: "fwd" or "rwd
     * @param int $pointer Pointer
     * @return string
501
     * @internal
502
     */
503
    public function fwd_rwd_HTML($type, $pointer)
504
505
506
507
    {
        $content = '';
        switch ($type) {
            case 'fwd':
508
                $href = $this->listURL() . '&pointer=' . ($pointer - $this->iLimit);
509
                $content = '<a href="' . htmlspecialchars($href) . '">' . $this->iconFactory->getIcon(
Benni Mack's avatar
Benni Mack committed
510
511
                    'actions-move-up',
                    Icon::SIZE_SMALL
512
                )->render() . ' <i>[' . (max(0, $pointer - $this->iLimit) + 1) . ' - ' . $pointer . ']</i></a>';
513
514
                break;
            case 'rwd':
515
                $href = $this->listURL() . '&pointer=' . $pointer;
516
                $content = '<a href="' . htmlspecialchars($href) . '">' . $this->iconFactory->getIcon(
Benni Mack's avatar
Benni Mack committed
517
518
                    'actions-move-down',
                    Icon::SIZE_SMALL
519
                )->render() . ' <i>[' . ($pointer + 1) . ' - ' . $this->totalItems . ']</i></a>';
520
521
522
523
524
                break;
        }
        return $content;
    }

525
526
527
528
529
530
531
532
    /**
     * Gets the number of files and total size of a folder
     *
     * @return string
     */
    public function getFolderInfo()
    {
        if ($this->counter == 1) {
533
            $fileLabel = htmlspecialchars($this->getLanguageService()->getLL('file'));
534
        } else {
535
            $fileLabel = htmlspecialchars($this->getLanguageService()->getLL('files'));
536
        }
537
        return $this->counter . ' ' . $fileLabel . ', ' . GeneralUtility::formatSize($this->totalbytes, htmlspecialchars($this->getLanguageService()->getLL('byteSizeUnits')));
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
    }

    /**
     * This returns tablerows for the directories in the array $items['sorting'].
     *
     * @param Folder[] $folders Folders of \TYPO3\CMS\Core\Resource\Folder
     * @return string HTML table rows.
     */
    public function formatDirList(array $folders)
    {
        $out = '';
        foreach ($folders as $folderName => $folderObject) {
            $role = $folderObject->getRole();
            if ($role === FolderInterface::ROLE_PROCESSING) {
                // don't show processing-folder
                continue;
            }
            if ($role !== FolderInterface::ROLE_DEFAULT) {
                $displayName = '<strong>' . htmlspecialchars($folderName) . '</strong>';
            } else {
                $displayName = htmlspecialchars($folderName);
            }

            $isLocked = $folderObject instanceof InaccessibleFolder;
            $isWritable = $folderObject->checkActionPermission('write');

            // Initialization
            $this->counter++;

            // The icon with link
            $theIcon = '<span title="' . htmlspecialchars($folderName) . '">' . $this->iconFactory->getIconForResource($folderObject, Icon::SIZE_SMALL)->render() . '</span>';
Benni Mack's avatar
Benni Mack committed
569
            if (!$isLocked) {
570
                $theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, 'sys_file', $folderObject->getCombinedIdentifier());
571
572
573
            }

            // Preparing and getting the data-array
574
            $theData = [];
575
576
577
578
579
580
581
582
583
584
585
586
587
588
            if ($isLocked) {
                foreach ($this->fieldArray as $field) {
                    $theData[$field] = '';
                }
                $theData['file'] = $displayName;
            } else {
                foreach ($this->fieldArray as $field) {
                    switch ($field) {
                        case 'size':
                            try {
                                $numFiles = $folderObject->getFileCount();
                            } catch (InsufficientFolderAccessPermissionsException $e) {
                                $numFiles = 0;
                            }
589
                            $theData[$field] = $numFiles . ' ' . htmlspecialchars($this->getLanguageService()->getLL(($numFiles === 1 ? 'file' : 'files')));
590
591
                            break;
                        case 'rw':
592
                            $theData[$field] = '<strong class="text-danger">' . htmlspecialchars($this->getLanguageService()->getLL('read')) . '</strong>' . (!$isWritable ? '' : '<strong class="text-danger">' . htmlspecialchars($this->getLanguageService()->getLL('write')) . '</strong>');
593
594
                            break;
                        case 'fileext':
595
                            $theData[$field] = htmlspecialchars($this->getLanguageService()->getLL('folder'));
596
597
                            break;
                        case 'tstamp':
598
599
                            $tstamp = $folderObject->getModificationTime();
                            $theData[$field] = $tstamp ? BackendUtility::date($tstamp) : '-';
600
601
602
603
604
605
606
607
608
609
610
611
612
613
                            break;
                        case 'file':
                            $theData[$field] = $this->linkWrapDir($displayName, $folderObject);
                            break;
                        case '_CONTROL_':
                            $theData[$field] = $this->makeEdit($folderObject);
                            break;
                        case '_CLIPBOARD_':
                            $theData[$field] = $this->makeClip($folderObject);
                            break;
                        case '_REF_':
                            $theData[$field] = $this->makeRef($folderObject);
                            break;
                        default:
614
                            $theData[$field] = GeneralUtility::fixed_lgd_cs($theData[$field] ?? '', $this->fixedL);
615
616
617
                    }
                }
            }
618
            $out .= $this->addElement($theIcon, $theData);
619
620
621
622
623
624
625
626
627
628
629
630
631
        }
        return $out;
    }

    /**
     * Wraps the directory-titles
     *
     * @param string $title String to be wrapped in links
     * @param Folder $folderObject Folder to work on
     * @return string HTML
     */
    public function linkWrapDir($title, Folder $folderObject)
    {
632
        $href = (string)$this->uriBuilder->buildUriFromRoute('file_FilelistList', ['id' => $folderObject->getCombinedIdentifier()]);
633
634
635
636
        $triggerTreeUpdateAttribute = sprintf(
            ' data-tree-update-request="%s"',
            htmlspecialchars('folder' . GeneralUtility::md5int($folderObject->getCombinedIdentifier()))
        );
637
638
        // Sometimes $code contains plain HTML tags. In such a case the string should not be modified!
        if ((string)$title === strip_tags($title)) {
639
            return '<a href="' . htmlspecialchars($href) . '"' . $triggerTreeUpdateAttribute . ' title="' . htmlspecialchars($title) . '">' . $title . '</a>';
640
        }
641
        return '<a href="' . htmlspecialchars($href) . '"' . $triggerTreeUpdateAttribute . '>' . $title . '</a>';
642
643
644
645
646
647
648
649
650
651
652
653
    }

    /**
     * Wraps filenames in links which opens the metadata editor.
     *
     * @param string $code String to be wrapped in links
     * @param File $fileObject File to be linked
     * @return string HTML
     */
    public function linkWrapFile($code, File $fileObject)
    {
        try {
654
            if ($fileObject instanceof File && $fileObject->isIndexed() && $fileObject->checkActionPermission('editMeta') && $this->getBackendUser()->check('tables_modify', 'sys_file_metadata')) {
655
                $metaData = $fileObject->getMetaData()->get();
656
657
658
659
660
661
662
663
                $urlParameters = [
                    'edit' => [
                        'sys_file_metadata' => [
                            $metaData['uid'] => 'edit'
                        ]
                    ],
                    'returnUrl' => $this->listURL()
                ];
664
                $url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
665
                $title = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.editMetadata'));
666
                $code = '<a class="responsive-title" href="' . htmlspecialchars($url) . '" title="' . $title . '">' . $code . '</a>';
667
668
669
670
671
672
673
674
675
676
            }
        } catch (\Exception $e) {
            // intentional fall-through
        }
        return $code;
    }

    /**
     * Returns list URL; This is the URL of the current script with id and imagemode parameters, that's all.
     * The URL however is not relative, otherwise GeneralUtility::sanitizeLocalUrl() would say that
677
     * the URL would be invalid.
678
679
680
     *
     * @return string URL
     */
681
    public function listURL()
682
    {
683
        return GeneralUtility::linkThisScript([
684
685
            'target' => rawurlencode($this->folderObject->getCombinedIdentifier()),
            'imagemode' => $this->thumbs
686
        ]);
687
688
    }

689
690
691
692
693
694
695
696
697
698
699
    protected function getAvailableSystemLanguages(): array
    {
        // first two keys are "0" (default) and "-1" (multiple), after that comes the "other languages"
        $allSystemLanguages = $this->translateTools->getSystemLanguages();
        return array_filter($allSystemLanguages, function ($languageRecord) {
            if ($languageRecord['uid'] === -1 || $languageRecord['uid'] === 0 || !$this->getBackendUser()->checkLanguageAccess($languageRecord['uid'])) {
                return false;
            }
            return true;
        });
    }
700
701
702
703
704
705
706
707
708
    /**
     * This returns tablerows for the files in the array $items['sorting'].
     *
     * @param File[] $files File items
     * @return string HTML table rows.
     */
    public function formatFileList(array $files)
    {
        $out = '';
709
        $systemLanguages = $this->getAvailableSystemLanguages();
710
711
712
713
714
715
716
717
718
        foreach ($files as $fileObject) {
            // Initialization
            $this->counter++;
            $this->totalbytes += $fileObject->getSize();
            $ext = $fileObject->getExtension();
            $fileName = trim($fileObject->getName());
            // The icon with link
            $theIcon = '<span title="' . htmlspecialchars($fileName . ' [' . (int)$fileObject->getUid() . ']') . '">'
                . $this->iconFactory->getIconForResource($fileObject, Icon::SIZE_SMALL)->render() . '</span>';
Benni Mack's avatar
Benni Mack committed
719
            $theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, 'sys_file', $fileObject->getCombinedIdentifier());
720
            // Preparing and getting the data-array
721
            $theData = [];
722
723
724
            foreach ($this->fieldArray as $field) {
                switch ($field) {
                    case 'size':
725
                        $theData[$field] = GeneralUtility::formatSize((int)$fileObject->getSize(), htmlspecialchars($this->getLanguageService()->getLL('byteSizeUnits')));
726
727
                        break;
                    case 'rw':
728
                        $theData[$field] = '' . (!$fileObject->checkActionPermission('read') ? ' ' : '<strong class="text-danger">' . htmlspecialchars($this->getLanguageService()->getLL('read')) . '</strong>') . (!$fileObject->checkActionPermission('write') ? '' : '<strong class="text-danger">' . htmlspecialchars($this->getLanguageService()->getLL('write')) . '</strong>');
729
730
                        break;
                    case 'fileext':
731
                        $theData[$field] = htmlspecialchars(strtoupper($ext));
732
733
734
735
736
737
738
739
740
741
742
                        break;
                    case 'tstamp':
                        $theData[$field] = BackendUtility::date($fileObject->getModificationTime());
                        break;
                    case '_CONTROL_':
                        $theData[$field] = $this->makeEdit($fileObject);
                        break;
                    case '_CLIPBOARD_':
                        $theData[$field] = $this->makeClip($fileObject);
                        break;
                    case '_LOCALIZATION_':
743
                        if (!empty($systemLanguages) && $fileObject->isIndexed() && $fileObject->checkActionPermission('editMeta') && $this->getBackendUser()->check('tables_modify', 'sys_file_metadata') && !empty($GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField'] ?? null)) {
744
                            $metaDataRecord = $fileObject->getMetaData()->get();
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
                            $translations = $this->getTranslationsForMetaData($metaDataRecord);
                            $languageCode = '';

                            foreach ($systemLanguages as $language) {
                                $languageId = $language['uid'];
                                $flagIcon = $language['flagIcon'];
                                if (array_key_exists($languageId, $translations)) {
                                    $title = htmlspecialchars(sprintf($this->getLanguageService()->getLL('editMetadataForLanguage'), $language['title']));
                                    $urlParameters = [
                                        'edit' => [
                                            'sys_file_metadata' => [
                                                $translations[$languageId]['uid'] => 'edit'
                                            ]
                                        ],
                                        'returnUrl' => $this->listURL()
                                    ];
                                    $flagButtonIcon = $this->iconFactory->getIcon($flagIcon, Icon::SIZE_SMALL, 'overlay-edit')->render();
762
                                    $url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
763
764
765
766
767
768
769
                                    $languageCode .= '<a href="' . htmlspecialchars($url) . '" class="btn btn-default" title="' . $title . '">'
                                        . $flagButtonIcon . '</a>';
                                } else {
                                    $parameters = [
                                        'justLocalized' => 'sys_file_metadata:' . $metaDataRecord['uid'] . ':' . $languageId,
                                        'returnUrl' => $this->listURL()
                                    ];
770
                                    $returnUrl = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $parameters);
771
                                    $href = BackendUtility::getLinkToDataHandlerAction(
772
773
774
775
776
777
778
779
780
781
782
783
                                        '&cmd[sys_file_metadata][' . $metaDataRecord['uid'] . '][localize]=' . $languageId,
                                        $returnUrl
                                    );
                                    $flagButtonIcon = '<span title="' . htmlspecialchars(sprintf($this->getLanguageService()->getLL('createMetadataForLanguage'), $language['title'])) . '">' . $this->iconFactory->getIcon($flagIcon, Icon::SIZE_SMALL, 'overlay-new')->render() . '</span>';
                                    $languageCode .= '<a href="' . htmlspecialchars($href) . '" class="btn btn-default">' . $flagButtonIcon . '</a> ';
                                }
                            }

                            // Hide flag button bar when not translated yet
                            $theData[$field] = ' <div class="localisationData btn-group" data-fileid="' . $fileObject->getUid() . '"' .
                                (empty($translations) ? ' style="display: none;"' : '') . '>' . $languageCode . '</div>';
                            $theData[$field] .= '<a class="btn btn-default filelist-translationToggler" data-fileid="' . $fileObject->getUid() . '">' .
784
                                '<span title="' . htmlspecialchars($this->getLanguageService()->getLL('translateMetadata')) . '">'
785
786
787
788
789
790
791
792
793
794
795
796
                                . $this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL)->render() . '</span>'
                                . '</a>';
                        }
                        break;
                    case '_REF_':
                        $theData[$field] = $this->makeRef($fileObject);
                        break;
                    case 'file':
                        // Edit metadata of file
                        $theData[$field] = $this->linkWrapFile(htmlspecialchars($fileName), $fileObject);

                        if ($fileObject->isMissing()) {
797
                            $theData[$field] .= '<span class="label label-danger label-space-left">'
798
                                . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:warning.file_missing'))
799
                                . '</span>';
800
                        // Thumbnails?
801
                        } elseif ($this->thumbs && ($fileObject->isImage() || $fileObject->isMediaFile())) {
802
803
804
805
806
807
808
                            $processedFile = $fileObject->process(
                                ProcessedFile::CONTEXT_IMAGEPREVIEW,
                                [
                                    'width' => $this->thumbnailConfiguration->getWidth(),
                                    'height' => $this->thumbnailConfiguration->getHeight(),
                                ]
                            );
809
                            $theData[$field] .= '<br /><img src="' . htmlspecialchars(PathUtility::getAbsoluteWebPath($processedFile->getPublicUrl())) . '" ' .
810
811
                                'width="' . htmlspecialchars($processedFile->getProperty('width')) . '" ' .
                                'height="' . htmlspecialchars($processedFile->getProperty('height')) . '" ' .
812
                                'title="' . htmlspecialchars($fileName) . '" alt="" />';
813
814
815
816
817
818
819
820
821
                        }
                        break;
                    default:
                        $theData[$field] = '';
                        if ($fileObject->hasProperty($field)) {
                            $theData[$field] = htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileObject->getProperty($field), $this->fixedL));
                        }
                }
            }
822
            $out .= $this->addElement($theIcon, $theData);
823
824
825
826
827
828
829
        }
        return $out;
    }

    /**
     * Fetch the translations for a sys_file_metadata record
     *
830
     * @param array $metaDataRecord
831
832
833
834
     * @return array keys are the sys_language uids, values are the $rows
     */
    protected function getTranslationsForMetaData($metaDataRecord)
    {
835
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_metadata');
836
        $queryBuilder->getRestrictions()->removeAll();
837
838
        $translationRecords = $queryBuilder->select('*')
            ->from('sys_file_metadata')
839
            ->where(
840
841
842
843
844
845
846
847
                $queryBuilder->expr()->eq(
                    $GLOBALS['TCA']['sys_file_metadata']['ctrl']['transOrigPointerField'],
                    $queryBuilder->createNamedParameter($metaDataRecord['uid'], \PDO::PARAM_INT)
                ),
                $queryBuilder->expr()->gt(
                    $GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField'],
                    $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
                )
848
            )
849
850
851
            ->execute()
            ->fetchAll();

852
        $translations = [];
853
854
855
856
857
858
859
860
        foreach ($translationRecords as $record) {
            $translations[$record[$GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField']]] = $record;
        }
        return $translations;
    }

    /**
     * Returns TRUE if $ext is an image-extension according to $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
861
     * Use the AbstractFile->isImage() method if you're using File objects directly
862
863
864
865
866
867
     *
     * @param string $ext File extension
     * @return bool
     */
    public function isImage($ext)
    {
868
        return GeneralUtility::inList(strtolower($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']), strtolower($ext));
869
870
871
    }

    /**
872
     * Returns TRUE if $ext is a media-extension according to $GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext']
873
     * Use the AbstractFile->isMediaFile() method if you're using File objects directly
874
875
876
877
878
879
     *
     * @param string $ext File extension
     * @return bool
     */
    public function isMediaFile($ext)
    {
880
        return GeneralUtility::inList(strtolower($GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext']), strtolower($ext));
881
882
883
884
885
886
887
888
889
    }

    /**
     * Wraps the directory-titles ($code) in a link to filelist/Modules/Filelist/index.php (id=$path) and sorting commands...
     *
     * @param string $folderIdentifier ID (path)
     * @param string $col Sorting column
     * @return string HTML
     */
890
    public function linkWrapSort($folderIdentifier, $col)
891
    {
892
        $code = htmlspecialchars($this->getLanguageService()->getLL('c_' . $col));
Christian Kuhn's avatar
Christian Kuhn committed
893
        $params = ['id' => $folderIdentifier, 'SET' => ['sort' => $col]];
894
895
896
897

        if ($this->sort === $col) {
            // Check reverse sorting
            $params['SET']['reverse'] = ($this->sortRev ? '0' : '1');
898
            $sortArrow = $this->iconFactory->getIcon('status-status-sorting-' . ($this->sortRev ? 'desc' : 'asc'), Icon::SIZE_SMALL)->render();
899
900
901
902
        } else {
            $params['SET']['reverse'] = 0;
            $sortArrow = '';
        }
903
        $href = (string)$this->uriBuilder->buildUriFromRoute('file_FilelistList', $params);
904
905
906
907
908
909
910
911
912
913
914
915
916
917
        return '<a href="' . htmlspecialchars($href) . '">' . $code . ' ' . $sortArrow . '</a>';
    }

    /**
     * Creates the clipboard control pad
     *
     * @param File|Folder $fileOrFolderObject Array with information about the file/directory for which to make the clipboard panel for the listing.
     * @return string HTML-table
     */
    public function makeClip($fileOrFolderObject)
    {
        if (!$fileOrFolderObject->checkActionPermission('read')) {
            return '';
        }
918
        $cells = [];
919
920
        $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
        $fullName = $fileOrFolderObject->getName();
921
        $md5 = GeneralUtility::shortMD5($fullIdentifier);
922
923
924
        // For normal clipboard, add copy/cut buttons:
        if ($this->clipObj->current === 'normal') {
            $isSel = $this->clipObj->isSelected('_FILE', $md5);
925
926
            $copyTitle = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.copy'));
            $cutTitle = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.cut'));
927
928
929
930
931
932
933
934
935
            $copyIcon = $this->iconFactory->getIcon('actions-edit-copy', Icon::SIZE_SMALL)->render();
            $cutIcon = $this->iconFactory->getIcon('actions-edit-cut', Icon::SIZE_SMALL)->render();

            if ($isSel === 'copy') {
                $copyIcon = $this->iconFactory->getIcon('actions-edit-copy-release', Icon::SIZE_SMALL)->render();
            } elseif ($isSel === 'cut') {
                $cutIcon = $this->iconFactory->getIcon('actions-edit-cut-release', Icon::SIZE_SMALL)->render();
            }

936
937
938
939
940
            if ($fileOrFolderObject->checkActionPermission('copy')) {
                $cells[] = '<a class="btn btn-default" href="' . htmlspecialchars($this->clipObj->selUrlFile(
                    $fullIdentifier,
                    1,
                    $isSel === 'copy'
941
                )) . '" title="' . $copyTitle . '">' . $copyIcon . '</a>';
942
943
944
            } else {
                $cells[] = $this->spaceIcon;
            }
945
946
            // we can only cut if file can be moved
            if ($fileOrFolderObject->checkActionPermission('move')) {
947
948
949
                $cells[] = '<a class="btn btn-default" href="' . htmlspecialchars($this->clipObj->selUrlFile(
                    $fullIdentifier,
                    0,
Benni Mack's avatar
Benni Mack committed
950
                    $isSel === 'cut'
951
                )) . '" title="' . $cutTitle . '">' . $cutIcon . '</a>';
952
953
954
955
956
957
958
959
960
961
962
963
964
            } else {
                $cells[] = $this->spaceIcon;
            }
        } else {
            // For numeric pads, add select checkboxes:
            $n = '_FILE|' . $md5;
            $this->CBnames[] = $n;
            $checked = $this->clipObj->isSelected('_FILE', $md5) ? ' checked="checked"' : '';
            $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>';
        }
        // Display PASTE button, if directory:
        $elFromTable = $this->clipObj->elFromTable('_FILE');
        if ($fileOrFolderObject instanceof Folder && !empty($elFromTable) && $fileOrFolderObject->checkActionPermission('write')) {
965
966
967
            $clipboardMode = $this->clipObj->clipData[$this->clipObj->current]['mode'] ?? '';
            $permission = $clipboardMode === 'copy' ? 'copy' : 'move';
            $addPasteButton = $this->folderObject->checkActionPermission($permission);
968
            $elToConfirm = [];
969
970
971
972
973
974
975
976
            foreach ($elFromTable as $key => $element) {
                $clipBoardElement = $this->resourceFactory->retrieveFileOrFolderObject($element);
                if ($clipBoardElement instanceof Folder && $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement, $fileOrFolderObject)) {
                    $addPasteButton = false;
                }
                $elToConfirm[$key] = $clipBoardElement->getName();
            }
            if ($addPasteButton) {
977
978
                $cells[] = '<a class="btn btn-default t3js-modal-trigger" '
                    . ' href="' . htmlspecialchars($this->clipObj->pasteUrl('_FILE', $fullIdentifier)) . '"'
979
                    . ' data-bs-content="' . htmlspecialchars($this->clipObj->confirmMsgText('_FILE', $fullName, 'into', $elToConfirm)) . '"'
980
                    . ' data-severity="warning"'
981
982
                    . ' data-title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_pasteInto')) . '"'
                    . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_pasteInto')) . '"'
983
                    . '>'
984
985
                    . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render()
                    . '</a>';
986
987
            } else {
                $cells[] = $this->spaceIcon;
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
            }
        }
        // Compile items into a DIV-element:
        return ' <div class="btn-group" role="group">' . implode('', $cells) . '</div>';
    }

    /**
     * Creates the edit control section
     *
     * @param File|Folder $fileOrFolderObject Array with information about the file/directory for which to make the edit control section for the listing.
     * @return string HTML-table
     */
    public function makeEdit($fileOrFolderObject)
    {
1002
        $cells = [];
1003
1004
1005
        $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();

        // Edit file content (if editable)
1006
        if ($fileOrFolderObject instanceof File && $fileOrFolderObject->checkActionPermission('write') && $fileOrFolderObject->isTextFile()) {
1007
1008
1009
1010
1011
            $attributes = [
                'href' => (string)$this->uriBuilder->buildUriFromRoute('file_edit', ['target' => $fullIdentifier, 'returnUrl' => $this->listURL()]),
                'title' => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.editcontent'),
            ];
            $cells['edit'] = '<a class="btn btn-default" ' . GeneralUtility::implodeAttributes($attributes, true) . '>'
1012
1013
1014
1015
1016
                . $this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)->render()
                . '</a>';
        } else {
            $cells['edit'] = $this->spaceIcon;
        }
1017
1018

        // Edit metadata of file
1019
        if ($fileOrFolderObject instanceof File && $fileOrFolderObject->checkActionPermission('editMeta') && $this->getBackendUser()->check('tables_modify', 'sys_file_metadata')) {
1020
            $metaData = $fileOrFolderObject->getMetaData()->get();
1021
1022
1023
1024
1025
1026
1027
1028
            $urlParameters = [
                'edit' => [
                    'sys_file_metadata' => [
                        $metaData['uid'] => 'edit'
                    ]
                ],
                'returnUrl' => $this->listURL()
            ];
1029
            $url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
1030
            $title = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.editMetadata'));
1031
1032
1033
1034
            $cells['metadata'] = '<a class="btn btn-default" href="' . htmlspecialchars($url) . '" title="' . $title . '">' . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>';
        }

        // document view
1035
        if ($fileOrFolderObject instanceof File) {
1036
            $fileUrl = $fileOrFolderObject->getPublicUrl();
1037
            if ($fileUrl) {
1038
                $cells['view'] = '<a href="' . htmlspecialchars(PathUtility::getAbsoluteWebPath($fileUrl)) . '" target="_blank" class="btn btn-default" title="' . $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.view') . '">' . $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL)->render() . '</a>';
1039
1040
1041
1042
1043
1044
1045
1046
1047
            } else {
                $cells['view'] = $this->spaceIcon;
            }
        } else {
            $cells['view'] = $this->spaceIcon;
        }

        // replace file
        if ($fileOrFolderObject instanceof File && $fileOrFolderObject->checkActionPermission('replace')) {
1048
            $attributes = [
1049
                'href' => (string)$this->uriBuilder->buildUriFromRoute('file_replace', ['target' => $fullIdentifier, 'uid' => $fileOrFolderObject->getUid(), 'returnUrl' => $this->listURL()]),
1050
1051
1052
                'title' => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.replace'),
            ];
            $cells['replace'] = '<a class="btn btn-default" ' . GeneralUtility::implodeAttributes($attributes, true) . '>' . $this->iconFactory->getIcon('actions-edit-replace', Icon::SIZE_SMALL)->render() . '</a>';
1053
1054
1055
1056
        }

        // rename the file
        if ($fileOrFolderObject->checkActionPermission('rename')) {
1057
            $attributes = [
1058
                'href' => (string)$this->uriBuilder->buildUriFromRoute('file_rename', ['target' => $fullIdentifier, 'returnUrl' => $this->listURL()]),
1059
1060
1061
                'title' => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.rename'),
            ];
            $cells['rename'] = '<a class="btn btn-default" ' . GeneralUtility::implodeAttributes($attributes, true) . '>' . $this->iconFactory->getIcon('actions-edit-rename', Icon::SIZE_SMALL)->render() . '</a>';
1062
1063
1064
        } else {
            $cells['rename'] = $this->spaceIcon;
        }
1065
1066
1067
1068

        // upload files
        if ($fileOrFolderObject->getStorage()->checkUserActionPermission('add', 'File') && $fileOrFolderObject->checkActionPermission('write')) {
            if ($fileOrFolderObject instanceof Folder) {
1069
                $attributes = [
1070
                    'href' => (string)$this->uriBuilder->buildUriFromRoute('file_upload', ['target' => $fullIdentifier, 'returnUrl' => $this->listURL()]),
1071
1072
1073
                    'title' => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.upload'),
                ];
                $cells['upload'] = '<a class="btn btn-default" ' . GeneralUtility::implodeAttributes($attributes, true) . '>' . $this->iconFactory->getIcon('actions-edit-upload', Icon::SIZE_SMALL)->render() . '</a>';
1074
1075
1076
            }
        }

1077
        if ($fileOrFolderObject->checkActionPermission('read')) {
1078
1079
1080
1081
1082
1083
            $attributes = [
                'title' => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.info'),
            ];
            if ($fileOrFolderObject instanceof Folder || $fileOrFolderObject instanceof File) {
                $attributes['data-filelist-show-item-type'] = $fileOrFolderObject instanceof File ? '_FILE' : '_FOLDER';
                $attributes['data-filelist-show-item-identifier'] = $fullIdentifier;
1084
            }
1085
1086
            $cells['info'] = '<a href="#" class="btn btn-default" ' . GeneralUtility::implodeAttributes($attributes, true) . '>'
                . $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL)->render() . '</a>';
1087
1088
1089
1090
1091
1092
1093
1094
        } else {
            $cells['info'] = $this->spaceIcon;
        }

        // delete the file
        if ($fileOrFolderObject->checkActionPermission('delete')) {
            $identifier = $fileOrFolderObject->getIdentifier();
            if ($fileOrFolderObject instanceof Folder) {
1095
                $referenceCountText = BackendUtility::referenceCount('_FILE', $identifier, ' ' . $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.referencesToFolder'));
1096
                $deleteType = 'delete_folder';
1097
            } else {
1098
                $referenceCountText = BackendUtility::referenceCount('sys_file', (string)$fileOrFolderObject->getUid(), ' ' . $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.referencesToFile'));
1099
                $deleteType = 'delete_file';
1100
1101
1102
            }

            if ($this->getBackendUser()->jsConfirmation(JsConfirmation::DELETE)) {
1103
                $confirmationCheck = '1';
1104
            } else {
1105
                $confirmationCheck = '0';
1106
1107
            }

1108
            $deleteUrl = (string)$this->uriBuilder->buildUriFromRoute('tce_file');
1109
1110
            $confirmationMessage = sprintf($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:mess.delete'), $fileOrFolderObject->getName()) . $referenceCountText;
            $title = $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.delete');
1111
            $cells['delete'] = '<a href="#" class="btn btn-default t3js-filelist-delete" data-bs-content="' . htmlspecialchars($confirmationMessage)
1112
1113
1114
1115
                . '" data-check="' . $confirmationCheck
                . '" data-delete-url="' . htmlspecialchars($deleteUrl)
                . '" data-title="' . htmlspecialchars($title)
                . '" data-identifier="' . htmlspecialchars($fileOrFolderObject->getCombinedIdentifier())
1116
                . '" data-delete-type="' . $deleteType
1117
1118
                . '" title="' . htmlspecialchars($title) . '">'
                . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render() . '</a>';
1119
1120
1121
1122
1123
        } else {
            $cells['delete'] = $this->spaceIcon;
        }