[FEATURE] Make thumbnail size in file list configurable
[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\Routing\UriBuilder;
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
21 use TYPO3\CMS\Core\Database\ConnectionPool;
22 use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
23 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
24 use TYPO3\CMS\Core\Imaging\Icon;
25 use TYPO3\CMS\Core\Imaging\IconFactory;
26 use TYPO3\CMS\Core\Messaging\FlashMessage;
27 use TYPO3\CMS\Core\Messaging\FlashMessageService;
28 use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException;
29 use TYPO3\CMS\Core\Resource\File;
30 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\Filelist\Configuration\ThumbnailConfiguration;
40 use TYPO3\CMS\Filelist\Controller\FileListController;
41
42 /**
43 * Class for rendering of File>Filelist
44 */
45 class FileList
46 {
47 /**
48 * Default Max items shown
49 *
50 * @var int
51 */
52 public $iLimit = 40;
53
54 /**
55 * Thumbnails on records containing files (pictures)
56 *
57 * @var bool
58 */
59 public $thumbs = false;
60
61 /**
62 * Space icon used for alignment when no button is available
63 *
64 * @var string
65 */
66 public $spaceIcon;
67
68 /**
69 * Max length of strings
70 *
71 * @var int
72 */
73 public $fixedL = 30;
74
75 /**
76 * The field to sort by
77 *
78 * @var string
79 */
80 public $sort = '';
81
82 /**
83 * Reverse sorting flag
84 *
85 * @var bool
86 */
87 public $sortRev = 1;
88
89 /**
90 * @var int
91 */
92 public $firstElementNumber = 0;
93
94 /**
95 * @var bool
96 */
97 public $clipBoard = 0;
98
99 /**
100 * @var bool
101 */
102 public $bigControlPanel = 0;
103
104 /**
105 * @var string
106 */
107 public $JScode = '';
108
109 /**
110 * String with accumulated HTML content
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 = [];
125
126 /**
127 * @var array
128 */
129 public $files = [];
130
131 /**
132 * @var string
133 */
134 public $path = '';
135
136 /**
137 * OBSOLETE - NOT USED ANYMORE. leftMargin
138 *
139 * @var int
140 */
141 public $leftMargin = 0;
142
143 /**
144 * This could be set to the total number of items. Used by the fwd_rew_navigation...
145 *
146 * @var string
147 */
148 public $totalItems = '';
149
150 /**
151 * Decides the columns shown. Filled with values that refers to the keys of the data-array. $this->fieldArray[0] is the title column.
152 *
153 * @var array
154 */
155 public $fieldArray = [];
156
157 /**
158 * Set to zero, if you don't want a left-margin with addElement function
159 *
160 * @var int
161 */
162 public $setLMargin = 1;
163
164 /**
165 * Contains page translation languages
166 *
167 * @var array
168 */
169 public $pageOverlays = [];
170
171 /**
172 * Counter increased for each element. Used to index elements for the JavaScript-code that transfers to the clipboard
173 *
174 * @var int
175 */
176 public $counter = 0;
177
178 /**
179 * Contains sys language icons and titles
180 *
181 * @var array
182 */
183 public $languageIconTitles = [];
184
185 /**
186 * Script URL
187 *
188 * @var string
189 */
190 public $thisScript = '';
191
192 /**
193 * If set this is <td> CSS-classname for odd columns in addElement. Used with db_layout / pages section
194 *
195 * @var string
196 */
197 public $oddColumnsCssClass = '';
198
199 /**
200 * Counting the elements no matter what
201 *
202 * @var int
203 */
204 public $eCounter = 0;
205
206 /**
207 * @var TranslationConfigurationProvider
208 */
209 public $translateTools;
210
211 /**
212 * Keys are fieldnames and values are td-parameters to add in addElement(), please use $addElement_tdCSSClass for CSS-classes;
213 *
214 * @var array
215 */
216 public $addElement_tdParams = [];
217
218 /**
219 * @var int
220 */
221 public $no_noWrap = 0;
222
223 /**
224 * @var int
225 */
226 public $showIcon = 1;
227
228 /**
229 * Keys are fieldnames and values are td-css-classes to add in addElement();
230 *
231 * @var array
232 */
233 public $addElement_tdCssClass = [];
234
235 /**
236 * @var Folder
237 */
238 protected $folderObject;
239
240 /**
241 * @var array
242 */
243 public $CBnames = [];
244
245 /**
246 * @var Clipboard $clipObj
247 */
248 public $clipObj;
249
250 /**
251 * @var ResourceFactory
252 */
253 protected $resourceFactory;
254
255 /**
256 * @var IconFactory
257 */
258 protected $iconFactory;
259
260 /**
261 * @var int
262 */
263 protected $id = 0;
264
265 /**
266 * @var FileListController
267 */
268 protected $fileListController;
269
270 /**
271 * @var ThumbnailConfiguration
272 */
273 protected $thumbnailConfiguration;
274
275 /**
276 * Construct
277 *
278 * @param FileListController $fileListController
279 */
280 public function __construct(FileListController $fileListController)
281 {
282 if (isset($GLOBALS['BE_USER']->uc['titleLen']) && $GLOBALS['BE_USER']->uc['titleLen'] > 0) {
283 $this->fixedL = $GLOBALS['BE_USER']->uc['titleLen'];
284 }
285 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
286 $this->getTranslateTools();
287 $this->determineScriptUrl();
288 $this->fileListController = $fileListController;
289 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
290 $this->thumbnailConfiguration = GeneralUtility::makeInstance(ThumbnailConfiguration::class);
291
292 $modTSconfig = BackendUtility::getModTSconfig(0, 'options.file_list');
293 if (!empty($modTSconfig['properties']['filesPerPage'])) {
294 $this->iLimit = MathUtility::forceIntegerInRange($modTSconfig['properties']['filesPerPage'], 1);
295 }
296 }
297
298 /**
299 * @param ResourceFactory $resourceFactory
300 */
301 public function injectResourceFactory(ResourceFactory $resourceFactory)
302 {
303 $this->resourceFactory = $resourceFactory;
304 }
305
306 /**
307 * Initialization of class
308 *
309 * @param Folder $folderObject The folder to work on
310 * @param int $pointer Pointer
311 * @param bool $sort Sorting column
312 * @param bool $sortRev Sorting direction
313 * @param bool $clipBoard
314 * @param bool $bigControlPanel Show clipboard flag
315 */
316 public function start(Folder $folderObject, $pointer, $sort, $sortRev, $clipBoard = false, $bigControlPanel = false)
317 {
318 $this->folderObject = $folderObject;
319 $this->counter = 0;
320 $this->totalbytes = 0;
321 $this->JScode = '';
322 $this->HTMLcode = '';
323 $this->path = $folderObject->getReadablePath();
324 $this->sort = $sort;
325 $this->sortRev = $sortRev;
326 $this->firstElementNumber = $pointer;
327 $this->clipBoard = $clipBoard;
328 $this->bigControlPanel = $bigControlPanel;
329 // Setting the maximum length of the filenames to the user's settings or minimum 30 (= $this->fixedL)
330 $this->fixedL = max($this->fixedL, $this->getBackendUser()->uc['titleLen']);
331 $this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_common.xlf');
332 $this->resourceFactory = ResourceFactory::getInstance();
333 }
334
335 /**
336 * Reading files and directories, counting elements and generating the list in ->HTMLcode
337 */
338 public function generateList()
339 {
340 $this->HTMLcode .= $this->getTable('fileext,tstamp,size,rw,_REF_');
341 }
342
343 /**
344 * Wrapping input string in a link with clipboard command.
345 *
346 * @param string $string String to be linked - must be htmlspecialchar'ed / prepared before.
347 * @param string $_ unused
348 * @param string $cmd "cmd" value
349 * @param string $warning Warning for JS confirm message
350 * @return string Linked string
351 */
352 public function linkClipboardHeaderIcon($string, $_, $cmd, $warning = '')
353 {
354 $jsCode = 'document.dblistForm.cmd.value=' . GeneralUtility::quoteJSvalue($cmd)
355 . ';document.dblistForm.submit();';
356
357 $attributes = [];
358 if ($warning) {
359 $attributes['class'] = 'btn btn-default t3js-modal-trigger';
360 $attributes['data-href'] = 'javascript:' . $jsCode;
361 $attributes['data-severity'] = 'warning';
362 $attributes['data-content'] = $warning;
363 } else {
364 $attributes['class'] = 'btn btn-default';
365 $attributes['onclick'] = $jsCode . 'return false;';
366 }
367
368 $attributesString = '';
369 foreach ($attributes as $key => $value) {
370 $attributesString .= ' ' . $key . '="' . htmlspecialchars($value) . '"';
371 }
372 return '<a href="#" ' . $attributesString . '>' . $string . '</a>';
373 }
374
375 /**
376 * Returns a table with directories and files listed.
377 *
378 * @param array $rowlist Array of files from path
379 * @return string HTML-table
380 */
381 public function getTable($rowlist)
382 {
383 // prepare space icon
384 $this->spaceIcon = '<span class="btn btn-default disabled">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
385
386 // @todo use folder methods directly when they support filters
387 $storage = $this->folderObject->getStorage();
388 $storage->resetFileAndFolderNameFiltersToDefault();
389
390 // Only render the contents of a browsable storage
391 if ($this->folderObject->getStorage()->isBrowsable()) {
392 try {
393 $foldersCount = $storage->countFoldersInFolder($this->folderObject);
394 $filesCount = $storage->countFilesInFolder($this->folderObject);
395 } catch (InsufficientFolderAccessPermissionsException $e) {
396 $foldersCount = 0;
397 $filesCount = 0;
398 }
399
400 if ($foldersCount <= $this->firstElementNumber) {
401 $foldersFrom = false;
402 $foldersNum = false;
403 } else {
404 $foldersFrom = $this->firstElementNumber;
405 if ($this->firstElementNumber + $this->iLimit > $foldersCount) {
406 $foldersNum = $foldersCount - $this->firstElementNumber;
407 } else {
408 $foldersNum = $this->iLimit;
409 }
410 }
411 if ($foldersCount >= $this->firstElementNumber + $this->iLimit) {
412 $filesFrom = false;
413 $filesNum = false;
414 } else {
415 if ($this->firstElementNumber <= $foldersCount) {
416 $filesFrom = 0;
417 $filesNum = $this->iLimit - $foldersNum;
418 } else {
419 $filesFrom = $this->firstElementNumber - $foldersCount;
420 if ($filesFrom + $this->iLimit > $filesCount) {
421 $filesNum = $filesCount - $filesFrom;
422 } else {
423 $filesNum = $this->iLimit;
424 }
425 }
426 }
427
428 $folders = $storage->getFoldersInFolder($this->folderObject, $foldersFrom, $foldersNum, true, false, trim($this->sort), (bool)$this->sortRev);
429 $files = $this->folderObject->getFiles($filesFrom, $filesNum, Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, false, trim($this->sort), (bool)$this->sortRev);
430 $this->totalItems = $foldersCount + $filesCount;
431 // Adds the code of files/dirs
432 $out = '';
433 $titleCol = 'file';
434 // Cleaning rowlist for duplicates and place the $titleCol as the first column always!
435 $rowlist = '_LOCALIZATION_,' . $rowlist;
436 $rowlist = GeneralUtility::rmFromList($titleCol, $rowlist);
437 $rowlist = GeneralUtility::uniqueList($rowlist);
438 $rowlist = $rowlist ? $titleCol . ',' . $rowlist : $titleCol;
439 if ($this->clipBoard) {
440 $rowlist = str_replace('_LOCALIZATION_,', '_LOCALIZATION_,_CLIPBOARD_,', $rowlist);
441 $this->addElement_tdCssClass['_CLIPBOARD_'] = 'col-clipboard';
442 }
443 if ($this->bigControlPanel) {
444 $rowlist = str_replace('_LOCALIZATION_,', '_LOCALIZATION_,_CONTROL_,', $rowlist);
445 $this->addElement_tdCssClass['_CONTROL_'] = 'col-control';
446 }
447 $this->fieldArray = explode(',', $rowlist);
448
449 // Add classes to table cells
450 $this->addElement_tdCssClass[$titleCol] = 'col-title col-responsive';
451 $this->addElement_tdCssClass['_LOCALIZATION_'] = 'col-localizationa';
452
453 $folders = ListUtility::resolveSpecialFolderNames($folders);
454
455 $iOut = '';
456 // Directories are added
457 $this->eCounter = $this->firstElementNumber;
458 list(, $code) = $this->fwd_rwd_nav();
459 $iOut .= $code;
460
461 $iOut .= $this->formatDirList($folders);
462 // Files are added
463 $iOut .= $this->formatFileList($files);
464
465 $this->eCounter = $this->firstElementNumber + $this->iLimit < $this->totalItems
466 ? $this->firstElementNumber + $this->iLimit
467 : -1;
468 list(, $code) = $this->fwd_rwd_nav();
469 $iOut .= $code;
470
471 // Header line is drawn
472 $theData = [];
473 foreach ($this->fieldArray as $v) {
474 if ($v === '_CLIPBOARD_' && $this->clipBoard) {
475 $cells = [];
476 $table = '_FILE';
477 $elFromTable = $this->clipObj->elFromTable($table);
478 if (!empty($elFromTable) && $this->folderObject->checkActionPermission('write')) {
479 $addPasteButton = true;
480 $elToConfirm = [];
481 foreach ($elFromTable as $key => $element) {
482 $clipBoardElement = $this->resourceFactory->retrieveFileOrFolderObject($element);
483 if ($clipBoardElement instanceof Folder && $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement, $this->folderObject)) {
484 $addPasteButton = false;
485 }
486 $elToConfirm[$key] = $clipBoardElement->getName();
487 }
488 if ($addPasteButton) {
489 $cells[] = '<a class="btn btn-default t3js-modal-trigger"' .
490 ' href="' . htmlspecialchars($this->clipObj->pasteUrl(
491 '_FILE',
492 $this->folderObject->getCombinedIdentifier()
493 )) . '"'
494 . ' data-content="' . htmlspecialchars($this->clipObj->confirmMsgText(
495 '_FILE',
496 $this->path,
497 'into',
498 $elToConfirm
499 )) . '"'
500 . ' data-severity="warning"'
501 . ' data-title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_paste')) . '"'
502 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_paste')) . '">'
503 . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)
504 ->render()
505 . '</a>';
506 }
507 }
508 if ($this->clipObj->current !== 'normal' && $iOut) {
509 $cells[] = $this->linkClipboardHeaderIcon('<span title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_selectMarked')) . '">' . $this->iconFactory->getIcon('actions-edit-copy', Icon::SIZE_SMALL)->render() . '</span>', $table, 'setCB');
510 $cells[] = $this->linkClipboardHeaderIcon('<span title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_deleteMarked')) . '">' . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render(), $table, 'delete', $this->getLanguageService()->getLL('clip_deleteMarkedWarning'));
511 $onClick = 'checkOffCB(' . GeneralUtility::quoteJSvalue(implode(',', $this->CBnames)) . ', this); return false;';
512 $cells[] = '<a class="btn btn-default" rel="" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_markRecords')) . '">' . $this->iconFactory->getIcon('actions-document-select', Icon::SIZE_SMALL)->render() . '</a>';
513 }
514 $theData[$v] = implode('', $cells);
515 } else {
516 // Normal row:
517 $theT = $this->linkWrapSort(htmlspecialchars($this->getLanguageService()->getLL('c_' . $v)), $this->folderObject->getCombinedIdentifier(), $v);
518 $theData[$v] = $theT;
519 }
520 }
521
522 $out .= '<thead>' . $this->addElement(1, '', $theData, '', '', '', 'th') . '</thead>';
523 $out .= '<tbody>' . $iOut . '</tbody>';
524 // half line is drawn
525 // finish
526 $out = '
527 <!--
528 Filelist table:
529 -->
530 <div class="table-fit">
531 <table class="table table-striped table-hover" id="typo3-filelist">
532 ' . $out . '
533 </table>
534 </div>';
535 } else {
536 /** @var $flashMessage FlashMessage */
537 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $this->getLanguageService()->getLL('storageNotBrowsableMessage'), $this->getLanguageService()->getLL('storageNotBrowsableTitle'), FlashMessage::INFO);
538 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
539 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
540 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
541 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
542 $defaultFlashMessageQueue->enqueue($flashMessage);
543 $out = '';
544 }
545 return $out;
546 }
547
548 /**
549 * Returns a table-row with the content from the fields in the input data array.
550 * OBS: $this->fieldArray MUST be set! (represents the list of fields to display)
551 *
552 * @param int $h Is an integer >=0 and denotes how tall an element is. Set to '0' makes a halv line, -1 = full line, set to 1 makes a 'join' and above makes 'line'
553 * @param string $icon Is the <img>+<a> of the record. If not supplied the first 'join'-icon will be a 'line' instead
554 * @param array $data Is the dataarray, record with the fields. Notice: These fields are (currently) NOT htmlspecialchar'ed before being wrapped in <td>-tags
555 * @param string $rowParams Is insert in the <tr>-tags. Must carry a ' ' as first character
556 * @param string $_ OBSOLETE - NOT USED ANYMORE. $lMargin is the leftMargin (int)
557 * @param string $_2 OBSOLETE - NOT USED ANYMORE. Is the HTML <img>-tag for an alternative 'gfx/ol/line.gif'-icon (used in the top)
558 * @param string $colType Defines the tag being used for the columns. Default is td.
559 *
560 * @return string HTML content for the table row
561 */
562 public function addElement($h, $icon, $data, $rowParams = '', $_ = '', $_2 = '', $colType = 'td')
563 {
564 $colType = ($colType === 'th') ? 'th' : 'td';
565 $noWrap = $this->no_noWrap ? '' : ' nowrap';
566 // Start up:
567 $l10nParent = isset($data['_l10nparent_']) ? (int)$data['_l10nparent_'] : 0;
568 $out = '
569 <!-- Element, begin: -->
570 <tr ' . $rowParams . ' data-uid="' . (int)$data['uid'] . '" data-l10nparent="' . $l10nParent . '">';
571 // Show icon and lines
572 if ($this->showIcon) {
573 $out .= '
574 <' . $colType . ' class="col-icon nowrap">';
575 if (!$h) {
576 $out .= '&nbsp;';
577 } else {
578 for ($a = 0; $a < $h; $a++) {
579 if (!$a) {
580 if ($icon) {
581 $out .= $icon;
582 }
583 }
584 }
585 }
586 $out .= '</' . $colType . '>
587 ';
588 }
589 // Init rendering.
590 $colsp = '';
591 $lastKey = '';
592 $c = 0;
593 $ccount = 0;
594 // __label is used as the label key to circumvent problems with uid used as label (see #67756)
595 // as it was introduced later on, check if it really exists before using it
596 $fields = $this->fieldArray;
597 if ($colType === 'td' && array_key_exists('__label', $data)) {
598 $fields[0] = '__label';
599 }
600 // Traverse field array which contains the data to present:
601 foreach ($fields as $vKey) {
602 if (isset($data[$vKey])) {
603 if ($lastKey) {
604 $cssClass = $this->addElement_tdCssClass[$lastKey];
605 if ($this->oddColumnsCssClass && $ccount % 2 == 0) {
606 $cssClass = implode(' ', [$this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass]);
607 }
608 $out .= '
609 <' . $colType . ' class="' . $cssClass . $noWrap . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</' . $colType . '>';
610 }
611 $lastKey = $vKey;
612 $c = 1;
613 $ccount++;
614 } else {
615 if (!$lastKey) {
616 $lastKey = $vKey;
617 }
618 $c++;
619 }
620 if ($c > 1) {
621 $colsp = ' colspan="' . $c . '"';
622 } else {
623 $colsp = '';
624 }
625 }
626 if ($lastKey) {
627 $cssClass = $this->addElement_tdCssClass[$lastKey];
628 if ($this->oddColumnsCssClass) {
629 $cssClass = implode(' ', [$this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass]);
630 }
631 $out .= '
632 <' . $colType . ' class="' . $cssClass . $noWrap . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</' . $colType . '>';
633 }
634 // End row
635 $out .= '
636 </tr>';
637 // Return row.
638 return $out;
639 }
640
641 /**
642 * Dummy function, used to write the top of a table listing.
643 */
644 public function writeTop()
645 {
646 }
647
648 /**
649 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
650 *
651 * @param string $table Table name
652 * @return array array([boolean], [HTML]) where [boolean] is 1 for reverse element, [HTML] is the table-row code for the element
653 */
654 public function fwd_rwd_nav($table = '')
655 {
656 $code = '';
657 if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber + $this->iLimit) {
658 if ($this->firstElementNumber && $this->eCounter == $this->firstElementNumber) {
659 // Reverse
660 $theData = [];
661 $titleCol = $this->fieldArray[0];
662 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd', $this->eCounter, $table);
663 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
664 }
665 return [1, $code];
666 }
667 if ($this->eCounter == $this->firstElementNumber + $this->iLimit) {
668 // Forward
669 $theData = [];
670 $titleCol = $this->fieldArray[0];
671 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd', $this->eCounter, $table);
672 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
673 }
674 return [0, $code];
675 }
676
677 /**
678 * Creates the button with link to either forward or reverse
679 *
680 * @param string $type Type: "fwd" or "rwd
681 * @param int $pointer Pointer
682 * @param string $table Table name
683 * @return string
684 * @access private
685 */
686 public function fwd_rwd_HTML($type, $pointer, $table = '')
687 {
688 $content = '';
689 $tParam = $table ? '&table=' . rawurlencode($table) : '';
690 switch ($type) {
691 case 'fwd':
692 $href = $this->listURL() . '&pointer=' . ($pointer - $this->iLimit) . $tParam;
693 $content = '<a href="' . htmlspecialchars($href) . '">' . $this->iconFactory->getIcon(
694 'actions-move-up',
695 Icon::SIZE_SMALL
696 )->render() . '</a> <i>[1 - ' . $pointer . ']</i>';
697 break;
698 case 'rwd':
699 $href = $this->listURL() . '&pointer=' . $pointer . $tParam;
700 $content = '<a href="' . htmlspecialchars($href) . '">' . $this->iconFactory->getIcon(
701 'actions-move-down',
702 Icon::SIZE_SMALL
703 )->render() . '</a> <i>[' . ($pointer + 1) . ' - ' . $this->totalItems . ']</i>';
704 break;
705 }
706 return $content;
707 }
708
709 /**
710 * Returning JavaScript for ClipBoard functionality.
711 *
712 * @return string
713 */
714 public function CBfunctions()
715 {
716 return '
717 // checkOffCB()
718 function checkOffCB(listOfCBnames, link) { //
719 var checkBoxes, flag, i;
720 var checkBoxes = listOfCBnames.split(",");
721 if (link.rel === "") {
722 link.rel = "allChecked";
723 flag = true;
724 } else {
725 link.rel = "";
726 flag = false;
727 }
728 for (i = 0; i < checkBoxes.length; i++) {
729 setcbValue(checkBoxes[i], flag);
730 }
731 }
732 // cbValue()
733 function cbValue(CBname) { //
734 var CBfullName = "CBC["+CBname+"]";
735 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
736 }
737 // setcbValue()
738 function setcbValue(CBname,flag) { //
739 CBfullName = "CBC["+CBname+"]";
740 if(document.dblistForm[CBfullName]) {
741 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
742 }
743 }
744
745 ';
746 }
747
748 /**
749 * Initializes page languages and icons
750 */
751 public function initializeLanguages()
752 {
753 // Look up page overlays:
754 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
755 ->getQueryBuilderForTable('pages_language_overlay');
756 $queryBuilder->getRestrictions()
757 ->removeAll()
758 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
759 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
760 $result = $queryBuilder
761 ->select('*')
762 ->from('pages_language_overlay')
763 ->where(
764 $queryBuilder->expr()->andX(
765 $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)),
766 $queryBuilder->expr()->gt(
767 'sys_language_uid',
768 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
769 )
770 )
771 )
772 ->execute();
773
774 $this->pageOverlays = [];
775 while ($row = $result->fetch()) {
776 $this->pageOverlays[$row['sys_language_uid']] = $row;
777 }
778
779 $this->languageIconTitles = $this->getTranslateTools()->getSystemLanguages($this->id);
780 }
781
782 /**
783 * Return the icon for the language
784 *
785 * @param int $sys_language_uid Sys language uid
786 * @param bool $addAsAdditionalText If set to true, only the flag is returned
787 * @return string Language icon
788 */
789 public function languageFlag($sys_language_uid, $addAsAdditionalText = true)
790 {
791 $out = '';
792 $title = htmlspecialchars($this->languageIconTitles[$sys_language_uid]['title']);
793 if ($this->languageIconTitles[$sys_language_uid]['flagIcon']) {
794 $out .= '<span title="' . $title . '">' . $this->iconFactory->getIcon(
795 $this->languageIconTitles[$sys_language_uid]['flagIcon'],
796 Icon::SIZE_SMALL
797 )->render() . '</span>';
798 if (!$addAsAdditionalText) {
799 return $out;
800 }
801 $out .= '&nbsp;';
802 }
803 $out .= $title;
804 return $out;
805 }
806
807 /**
808 * If there is a parent folder and user has access to it, return an icon
809 * which is linked to the filelist of the parent folder.
810 *
811 * @param Folder $currentFolder
812 * @return string
813 */
814 protected function getLinkToParentFolder(Folder $currentFolder)
815 {
816 $levelUp = '';
817 try {
818 $currentStorage = $currentFolder->getStorage();
819 $parentFolder = $currentFolder->getParentFolder();
820 if ($parentFolder->getIdentifier() !== $currentFolder->getIdentifier() && $currentStorage->isWithinFileMountBoundaries($parentFolder)) {
821 $levelUp = $this->linkWrapDir(
822 '<span title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.upOneLevel')) . '">'
823 . $this->iconFactory->getIcon('actions-view-go-up', Icon::SIZE_SMALL)->render()
824 . '</span>',
825 $parentFolder
826 );
827 }
828 } catch (\Exception $e) {
829 }
830 return $levelUp;
831 }
832
833 /**
834 * Gets the number of files and total size of a folder
835 *
836 * @return string
837 */
838 public function getFolderInfo()
839 {
840 if ($this->counter == 1) {
841 $fileLabel = htmlspecialchars($this->getLanguageService()->getLL('file'));
842 } else {
843 $fileLabel = htmlspecialchars($this->getLanguageService()->getLL('files'));
844 }
845 return $this->counter . ' ' . $fileLabel . ', ' . GeneralUtility::formatSize($this->totalbytes, htmlspecialchars($this->getLanguageService()->getLL('byteSizeUnits')));
846 }
847
848 /**
849 * This returns tablerows for the directories in the array $items['sorting'].
850 *
851 * @param Folder[] $folders Folders of \TYPO3\CMS\Core\Resource\Folder
852 * @return string HTML table rows.
853 */
854 public function formatDirList(array $folders)
855 {
856 $out = '';
857 foreach ($folders as $folderName => $folderObject) {
858 $role = $folderObject->getRole();
859 if ($role === FolderInterface::ROLE_PROCESSING) {
860 // don't show processing-folder
861 continue;
862 }
863 if ($role !== FolderInterface::ROLE_DEFAULT) {
864 $displayName = '<strong>' . htmlspecialchars($folderName) . '</strong>';
865 } else {
866 $displayName = htmlspecialchars($folderName);
867 }
868
869 $isLocked = $folderObject instanceof InaccessibleFolder;
870 $isWritable = $folderObject->checkActionPermission('write');
871
872 // Initialization
873 $this->counter++;
874
875 // The icon with link
876 $theIcon = '<span title="' . htmlspecialchars($folderName) . '">' . $this->iconFactory->getIconForResource($folderObject, Icon::SIZE_SMALL)->render() . '</span>';
877 if (!$isLocked) {
878 $theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, 'sys_file', $folderObject->getCombinedIdentifier());
879 }
880
881 // Preparing and getting the data-array
882 $theData = [];
883 if ($isLocked) {
884 foreach ($this->fieldArray as $field) {
885 $theData[$field] = '';
886 }
887 $theData['file'] = $displayName;
888 } else {
889 foreach ($this->fieldArray as $field) {
890 switch ($field) {
891 case 'size':
892 try {
893 $numFiles = $folderObject->getFileCount();
894 } catch (InsufficientFolderAccessPermissionsException $e) {
895 $numFiles = 0;
896 }
897 $theData[$field] = $numFiles . ' ' . htmlspecialchars($this->getLanguageService()->getLL(($numFiles === 1 ? 'file' : 'files')));
898 break;
899 case 'rw':
900 $theData[$field] = '<strong class="text-danger">' . htmlspecialchars($this->getLanguageService()->getLL('read')) . '</strong>' . (!$isWritable ? '' : '<strong class="text-danger">' . htmlspecialchars($this->getLanguageService()->getLL('write')) . '</strong>');
901 break;
902 case 'fileext':
903 $theData[$field] = htmlspecialchars($this->getLanguageService()->getLL('folder'));
904 break;
905 case 'tstamp':
906 $tstamp = $folderObject->getModificationTime();
907 $theData[$field] = $tstamp ? BackendUtility::date($tstamp) : '-';
908 break;
909 case 'file':
910 $theData[$field] = $this->linkWrapDir($displayName, $folderObject);
911 break;
912 case '_CONTROL_':
913 $theData[$field] = $this->makeEdit($folderObject);
914 break;
915 case '_CLIPBOARD_':
916 $theData[$field] = $this->makeClip($folderObject);
917 break;
918 case '_REF_':
919 $theData[$field] = $this->makeRef($folderObject);
920 break;
921 default:
922 $theData[$field] = GeneralUtility::fixed_lgd_cs($theData[$field], $this->fixedL);
923 }
924 }
925 }
926 $out .= $this->addElement(1, $theIcon, $theData);
927 }
928 return $out;
929 }
930
931 /**
932 * Wraps the directory-titles
933 *
934 * @param string $title String to be wrapped in links
935 * @param Folder $folderObject Folder to work on
936 * @return string HTML
937 */
938 public function linkWrapDir($title, Folder $folderObject)
939 {
940 $href = BackendUtility::getModuleUrl('file_FilelistList', ['id' => $folderObject->getCombinedIdentifier()]);
941 $onclick = ' onclick="' . htmlspecialchars(('top.document.getElementsByName("navigation")[0].contentWindow.Tree.highlightActiveItem("file","folder' . GeneralUtility::md5int($folderObject->getCombinedIdentifier()) . '_"+top.fsMod.currentBank)')) . '"';
942 // Sometimes $code contains plain HTML tags. In such a case the string should not be modified!
943 if ((string)$title === strip_tags($title)) {
944 return '<a href="' . htmlspecialchars($href) . '"' . $onclick . ' title="' . htmlspecialchars($title) . '">' . $title . '</a>';
945 }
946 return '<a href="' . htmlspecialchars($href) . '"' . $onclick . '>' . $title . '</a>';
947 }
948
949 /**
950 * Wraps filenames in links which opens the metadata editor.
951 *
952 * @param string $code String to be wrapped in links
953 * @param File $fileObject File to be linked
954 * @return string HTML
955 */
956 public function linkWrapFile($code, File $fileObject)
957 {
958 try {
959 if ($fileObject instanceof File && $fileObject->isIndexed() && $fileObject->checkActionPermission('write') && $this->getBackendUser()->check('tables_modify', 'sys_file_metadata')) {
960 $metaData = $fileObject->_getMetaData();
961 $urlParameters = [
962 'edit' => [
963 'sys_file_metadata' => [
964 $metaData['uid'] => 'edit'
965 ]
966 ],
967 'returnUrl' => $this->listURL()
968 ];
969 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
970 $title = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.editMetadata'));
971 $code = '<a class="responsive-title" href="' . htmlspecialchars($url) . '" title="' . $title . '">' . $code . '</a>';
972 }
973 } catch (\Exception $e) {
974 // intentional fall-through
975 }
976 return $code;
977 }
978
979 /**
980 * Returns list URL; This is the URL of the current script with id and imagemode parameters, that's all.
981 * The URL however is not relative, otherwise GeneralUtility::sanitizeLocalUrl() would say that
982 * the URL would be invalid
983 *
984 * @param string $altId
985 * @param string $table Table name to display. Enter "-1" for the current table.
986 * @param string $exclList Comma separated list of fields NOT to include ("sortField", "sortRev" or "firstElementNumber")
987 *
988 * @return string URL
989 */
990 public function listURL($altId = '', $table = '-1', $exclList = '')
991 {
992 return GeneralUtility::linkThisScript([
993 'target' => rawurlencode($this->folderObject->getCombinedIdentifier()),
994 'imagemode' => $this->thumbs
995 ]);
996 }
997
998 /**
999 * This returns tablerows for the files in the array $items['sorting'].
1000 *
1001 * @param File[] $files File items
1002 * @return string HTML table rows.
1003 */
1004 public function formatFileList(array $files)
1005 {
1006 $out = '';
1007 // first two keys are "0" (default) and "-1" (multiple), after that comes the "other languages"
1008 $allSystemLanguages = GeneralUtility::makeInstance(TranslationConfigurationProvider::class)->getSystemLanguages();
1009 $systemLanguages = array_filter($allSystemLanguages, function ($languageRecord) {
1010 if ($languageRecord['uid'] === -1 || $languageRecord['uid'] === 0 || !$this->getBackendUser()->checkLanguageAccess($languageRecord['uid'])) {
1011 return false;
1012 }
1013 return true;
1014 });
1015
1016 foreach ($files as $fileObject) {
1017 // Initialization
1018 $this->counter++;
1019 $this->totalbytes += $fileObject->getSize();
1020 $ext = $fileObject->getExtension();
1021 $fileName = trim($fileObject->getName());
1022 // The icon with link
1023 $theIcon = '<span title="' . htmlspecialchars($fileName . ' [' . (int)$fileObject->getUid() . ']') . '">'
1024 . $this->iconFactory->getIconForResource($fileObject, Icon::SIZE_SMALL)->render() . '</span>';
1025 $theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, 'sys_file', $fileObject->getCombinedIdentifier());
1026 // Preparing and getting the data-array
1027 $theData = [];
1028 foreach ($this->fieldArray as $field) {
1029 switch ($field) {
1030 case 'size':
1031 $theData[$field] = GeneralUtility::formatSize($fileObject->getSize(), htmlspecialchars($this->getLanguageService()->getLL('byteSizeUnits')));
1032 break;
1033 case 'rw':
1034 $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>');
1035 break;
1036 case 'fileext':
1037 $theData[$field] = strtoupper($ext);
1038 break;
1039 case 'tstamp':
1040 $theData[$field] = BackendUtility::date($fileObject->getModificationTime());
1041 break;
1042 case '_CONTROL_':
1043 $theData[$field] = $this->makeEdit($fileObject);
1044 break;
1045 case '_CLIPBOARD_':
1046 $theData[$field] = $this->makeClip($fileObject);
1047 break;
1048 case '_LOCALIZATION_':
1049 if (!empty($systemLanguages) && $fileObject->isIndexed() && $fileObject->checkActionPermission('write') && $this->getBackendUser()->check('tables_modify', 'sys_file_metadata')) {
1050 $metaDataRecord = $fileObject->_getMetaData();
1051 $translations = $this->getTranslationsForMetaData($metaDataRecord);
1052 $languageCode = '';
1053
1054 foreach ($systemLanguages as $language) {
1055 $languageId = $language['uid'];
1056 $flagIcon = $language['flagIcon'];
1057 if (array_key_exists($languageId, $translations)) {
1058 $title = htmlspecialchars(sprintf($this->getLanguageService()->getLL('editMetadataForLanguage'), $language['title']));
1059 // @todo the overlay for the flag needs to be added ($flagIcon . '-overlay')
1060 $urlParameters = [
1061 'edit' => [
1062 'sys_file_metadata' => [
1063 $translations[$languageId]['uid'] => 'edit'
1064 ]
1065 ],
1066 'returnUrl' => $this->listURL()
1067 ];
1068 $flagButtonIcon = $this->iconFactory->getIcon($flagIcon, Icon::SIZE_SMALL, 'overlay-edit')->render();
1069 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1070 $languageCode .= '<a href="' . htmlspecialchars($url) . '" class="btn btn-default" title="' . $title . '">'
1071 . $flagButtonIcon . '</a>';
1072 } else {
1073 $parameters = [
1074 'justLocalized' => 'sys_file_metadata:' . $metaDataRecord['uid'] . ':' . $languageId,
1075 'returnUrl' => $this->listURL()
1076 ];
1077 $returnUrl = BackendUtility::getModuleUrl('record_edit', $parameters);
1078 $href = BackendUtility::getLinkToDataHandlerAction(
1079 '&cmd[sys_file_metadata][' . $metaDataRecord['uid'] . '][localize]=' . $languageId,
1080 $returnUrl
1081 );
1082 $flagButtonIcon = '<span title="' . htmlspecialchars(sprintf($this->getLanguageService()->getLL('createMetadataForLanguage'), $language['title'])) . '">' . $this->iconFactory->getIcon($flagIcon, Icon::SIZE_SMALL, 'overlay-new')->render() . '</span>';
1083 $languageCode .= '<a href="' . htmlspecialchars($href) . '" class="btn btn-default">' . $flagButtonIcon . '</a> ';
1084 }
1085 }
1086
1087 // Hide flag button bar when not translated yet
1088 $theData[$field] = ' <div class="localisationData btn-group" data-fileid="' . $fileObject->getUid() . '"' .
1089 (empty($translations) ? ' style="display: none;"' : '') . '>' . $languageCode . '</div>';
1090 $theData[$field] .= '<a class="btn btn-default filelist-translationToggler" data-fileid="' . $fileObject->getUid() . '">' .
1091 '<span title="' . htmlspecialchars($this->getLanguageService()->getLL('translateMetadata')) . '">'
1092 . $this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL)->render() . '</span>'
1093 . '</a>';
1094 }
1095 break;
1096 case '_REF_':
1097 $theData[$field] = $this->makeRef($fileObject);
1098 break;
1099 case 'file':
1100 // Edit metadata of file
1101 $theData[$field] = $this->linkWrapFile(htmlspecialchars($fileName), $fileObject);
1102
1103 if ($fileObject->isMissing()) {
1104 $theData[$field] .= '<span class="label label-danger label-space-left">'
1105 . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.file_missing'))
1106 . '</span>';
1107 // Thumbnails?
1108 } elseif ($this->thumbs && ($this->isImage($ext) || $this->isMediaFile($ext))) {
1109 $processedFile = $fileObject->process(
1110 ProcessedFile::CONTEXT_IMAGEPREVIEW,
1111 [
1112 'width' => $this->thumbnailConfiguration->getWidth(),
1113 'height' => $this->thumbnailConfiguration->getHeight()
1114 ]
1115 );
1116 if ($processedFile) {
1117 $thumbUrl = $processedFile->getPublicUrl(true);
1118 $theData[$field] .= '<br /><img src="' . $thumbUrl . '" ' .
1119 'width="' . $processedFile->getProperty('width') . '" ' .
1120 'height="' . $processedFile->getProperty('height') . '" ' .
1121 'title="' . htmlspecialchars($fileName) . '" alt="" />';
1122 }
1123 }
1124 break;
1125 default:
1126 $theData[$field] = '';
1127 if ($fileObject->hasProperty($field)) {
1128 $theData[$field] = htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileObject->getProperty($field), $this->fixedL));
1129 }
1130 }
1131 }
1132 $out .= $this->addElement(1, $theIcon, $theData);
1133 }
1134 return $out;
1135 }
1136
1137 /**
1138 * Fetch the translations for a sys_file_metadata record
1139 *
1140 * @param $metaDataRecord
1141 * @return array keys are the sys_language uids, values are the $rows
1142 */
1143 protected function getTranslationsForMetaData($metaDataRecord)
1144 {
1145 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_metadata');
1146 $queryBuilder->getRestrictions()->removeAll();
1147 $translationRecords = $queryBuilder->select('*')
1148 ->from('sys_file_metadata')
1149 ->where(
1150 $queryBuilder->expr()->eq(
1151 $GLOBALS['TCA']['sys_file_metadata']['ctrl']['transOrigPointerField'],
1152 $queryBuilder->createNamedParameter($metaDataRecord['uid'], \PDO::PARAM_INT)
1153 ),
1154 $queryBuilder->expr()->gt(
1155 $GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField'],
1156 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
1157 )
1158 )
1159 ->execute()
1160 ->fetchAll();
1161
1162 $translations = [];
1163 foreach ($translationRecords as $record) {
1164 $translations[$record[$GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField']]] = $record;
1165 }
1166 return $translations;
1167 }
1168
1169 /**
1170 * Returns TRUE if $ext is an image-extension according to $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
1171 *
1172 * @param string $ext File extension
1173 * @return bool
1174 */
1175 public function isImage($ext)
1176 {
1177 return GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($ext));
1178 }
1179
1180 /**
1181 * Returns TRUE if $ext is an media-extension according to $GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext']
1182 *
1183 * @param string $ext File extension
1184 * @return bool
1185 */
1186 public function isMediaFile($ext)
1187 {
1188 return GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext'], strtolower($ext));
1189 }
1190
1191 /**
1192 * Wraps the directory-titles ($code) in a link to filelist/Modules/Filelist/index.php (id=$path) and sorting commands...
1193 *
1194 * @param string $code String to be wrapped
1195 * @param string $folderIdentifier ID (path)
1196 * @param string $col Sorting column
1197 * @return string HTML
1198 */
1199 public function linkWrapSort($code, $folderIdentifier, $col)
1200 {
1201 $params = ['id' => $folderIdentifier, 'SET' => [ 'sort' => $col ]];
1202
1203 if ($this->sort === $col) {
1204 // Check reverse sorting
1205 $params['SET']['reverse'] = ($this->sortRev ? '0' : '1');
1206 $sortArrow = $this->iconFactory->getIcon('status-status-sorting-light-' . ($this->sortRev ? 'desc' : 'asc'), Icon::SIZE_SMALL)->render();
1207 } else {
1208 $params['SET']['reverse'] = 0;
1209 $sortArrow = '';
1210 }
1211 $href = BackendUtility::getModuleUrl('file_FilelistList', $params);
1212 return '<a href="' . htmlspecialchars($href) . '">' . $code . ' ' . $sortArrow . '</a>';
1213 }
1214
1215 /**
1216 * Creates the clipboard control pad
1217 *
1218 * @param File|Folder $fileOrFolderObject Array with information about the file/directory for which to make the clipboard panel for the listing.
1219 * @return string HTML-table
1220 */
1221 public function makeClip($fileOrFolderObject)
1222 {
1223 if (!$fileOrFolderObject->checkActionPermission('read')) {
1224 return '';
1225 }
1226 $cells = [];
1227 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
1228 $fullName = $fileOrFolderObject->getName();
1229 $md5 = GeneralUtility::shortMD5($fullIdentifier);
1230 // For normal clipboard, add copy/cut buttons:
1231 if ($this->clipObj->current === 'normal') {
1232 $isSel = $this->clipObj->isSelected('_FILE', $md5);
1233 $copyTitle = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.copy'));
1234 $cutTitle = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.cut'));
1235 $copyIcon = $this->iconFactory->getIcon('actions-edit-copy', Icon::SIZE_SMALL)->render();
1236 $cutIcon = $this->iconFactory->getIcon('actions-edit-cut', Icon::SIZE_SMALL)->render();
1237
1238 if ($isSel === 'copy') {
1239 $copyIcon = $this->iconFactory->getIcon('actions-edit-copy-release', Icon::SIZE_SMALL)->render();
1240 } elseif ($isSel === 'cut') {
1241 $cutIcon = $this->iconFactory->getIcon('actions-edit-cut-release', Icon::SIZE_SMALL)->render();
1242 }
1243
1244 $cells[] = '<a class="btn btn-default"" href="' . htmlspecialchars($this->clipObj->selUrlFile($fullIdentifier, 1, ($isSel === 'copy'))) . '" title="' . $copyTitle . '">' . $copyIcon . '</a>';
1245 // we can only cut if file can be moved
1246 if ($fileOrFolderObject->checkActionPermission('move')) {
1247 $cells[] = '<a class="btn btn-default" href="' . htmlspecialchars($this->clipObj->selUrlFile($fullIdentifier, 0, ($isSel === 'cut'))) . '" title="' . $cutTitle . '">' . $cutIcon . '</a>';
1248 } else {
1249 $cells[] = $this->spaceIcon;
1250 }
1251 } else {
1252 // For numeric pads, add select checkboxes:
1253 $n = '_FILE|' . $md5;
1254 $this->CBnames[] = $n;
1255 $checked = $this->clipObj->isSelected('_FILE', $md5) ? ' checked="checked"' : '';
1256 $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>';
1257 }
1258 // Display PASTE button, if directory:
1259 $elFromTable = $this->clipObj->elFromTable('_FILE');
1260 if ($fileOrFolderObject instanceof Folder && !empty($elFromTable) && $fileOrFolderObject->checkActionPermission('write')) {
1261 $addPasteButton = true;
1262 $elToConfirm = [];
1263 foreach ($elFromTable as $key => $element) {
1264 $clipBoardElement = $this->resourceFactory->retrieveFileOrFolderObject($element);
1265 if ($clipBoardElement instanceof Folder && $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement, $fileOrFolderObject)) {
1266 $addPasteButton = false;
1267 }
1268 $elToConfirm[$key] = $clipBoardElement->getName();
1269 }
1270 if ($addPasteButton) {
1271 $cells[] = '<a class="btn btn-default t3js-modal-trigger" '
1272 . ' href="' . htmlspecialchars($this->clipObj->pasteUrl('_FILE', $fullIdentifier)) . '"'
1273 . ' data-content="' . htmlspecialchars($this->clipObj->confirmMsgText('_FILE', $fullName, 'into', $elToConfirm)) . '"'
1274 . ' data-severity="warning"'
1275 . ' data-title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_pasteInto')) . '"'
1276 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_pasteInto')) . '"'
1277 . '>'
1278 . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render()
1279 . '</a>';
1280 }
1281 }
1282 // Compile items into a DIV-element:
1283 return ' <div class="btn-group" role="group">' . implode('', $cells) . '</div>';
1284 }
1285
1286 /**
1287 * Creates the edit control section
1288 *
1289 * @param File|Folder $fileOrFolderObject Array with information about the file/directory for which to make the edit control section for the listing.
1290 * @return string HTML-table
1291 */
1292 public function makeEdit($fileOrFolderObject)
1293 {
1294 $cells = [];
1295 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
1296 $md5 = GeneralUtility::shortMD5($fullIdentifier);
1297 $isSel = $this->clipObj->isSelected('_FILE', $md5);
1298
1299 // Edit file content (if editable)
1300 if ($fileOrFolderObject instanceof File && $fileOrFolderObject->checkActionPermission('write') && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileOrFolderObject->getExtension())) {
1301 $url = BackendUtility::getModuleUrl('file_edit', ['target' => $fullIdentifier]);
1302 $editOnClick = 'top.list_frame.location.href=' . GeneralUtility::quoteJSvalue($url) . '+\'&returnUrl=\'+top.rawurlencode(top.list_frame.document.location.pathname+top.list_frame.document.location.search);return false;';
1303 $cells['edit'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($editOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.editcontent') . '">'
1304 . $this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)->render()
1305 . '</a>';
1306 } else {
1307 $cells['edit'] = $this->spaceIcon;
1308 }
1309
1310 // Edit metadata of file
1311 if ($fileOrFolderObject instanceof File && $fileOrFolderObject->checkActionPermission('write') && $this->getBackendUser()->check('tables_modify', 'sys_file_metadata')) {
1312 $metaData = $fileOrFolderObject->_getMetaData();
1313 $urlParameters = [
1314 'edit' => [
1315 'sys_file_metadata' => [
1316 $metaData['uid'] => 'edit'
1317 ]
1318 ],
1319 'returnUrl' => $this->listURL()
1320 ];
1321 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1322 $title = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.editMetadata'));
1323 $cells['metadata'] = '<a class="btn btn-default" href="' . htmlspecialchars($url) . '" title="' . $title . '">' . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>';
1324 }
1325
1326 // document view
1327 if ($fileOrFolderObject instanceof File) {
1328 $fileUrl = $fileOrFolderObject->getPublicUrl(true);
1329 if ($fileUrl) {
1330 $aOnClick = 'return top.openUrlInWindow(' . GeneralUtility::quoteJSvalue($fileUrl) . ', \'WebFile\');';
1331 $cells['view'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($aOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.view') . '">' . $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL)->render() . '</a>';
1332 } else {
1333 $cells['view'] = $this->spaceIcon;
1334 }
1335 } else {
1336 $cells['view'] = $this->spaceIcon;
1337 }
1338
1339 // replace file
1340 if ($fileOrFolderObject instanceof File && $fileOrFolderObject->checkActionPermission('replace')) {
1341 $url = BackendUtility::getModuleUrl('file_replace', ['target' => $fullIdentifier, 'uid' => $fileOrFolderObject->getUid()]);
1342 $replaceOnClick = 'top.list_frame.location.href = ' . GeneralUtility::quoteJSvalue($url) . '+\'&returnUrl=\'+top.rawurlencode(top.list_frame.document.location.pathname+top.list_frame.document.location.search);return false;';
1343 $cells['replace'] = '<a href="#" class="btn btn-default" onclick="' . $replaceOnClick . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.replace') . '">' . $this->iconFactory->getIcon('actions-edit-replace', Icon::SIZE_SMALL)->render() . '</a>';
1344 }
1345
1346 // rename the file
1347 if ($fileOrFolderObject->checkActionPermission('rename')) {
1348 $url = BackendUtility::getModuleUrl('file_rename', ['target' => $fullIdentifier]);
1349 $renameOnClick = 'top.list_frame.location.href = ' . GeneralUtility::quoteJSvalue($url) . '+\'&returnUrl=\'+top.rawurlencode(top.list_frame.document.location.pathname+top.list_frame.document.location.search);return false;';
1350 $cells['rename'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($renameOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.rename') . '">' . $this->iconFactory->getIcon('actions-edit-rename', Icon::SIZE_SMALL)->render() . '</a>';
1351 } else {
1352 $cells['rename'] = $this->spaceIcon;
1353 }
1354 if ($fileOrFolderObject->checkActionPermission('read')) {
1355 $infoOnClick = '';
1356 if ($fileOrFolderObject instanceof Folder) {
1357 $infoOnClick = 'top.launchView( \'_FOLDER\', ' . GeneralUtility::quoteJSvalue($fullIdentifier) . ');return false;';
1358 } elseif ($fileOrFolderObject instanceof File) {
1359 $infoOnClick = 'top.launchView( \'_FILE\', ' . GeneralUtility::quoteJSvalue($fullIdentifier) . ');return false;';
1360 }
1361 $cells['info'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($infoOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.info') . '">' . $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL)->render() . '</a>';
1362 } else {
1363 $cells['info'] = $this->spaceIcon;
1364 }
1365
1366 // copy the file
1367 if ($fileOrFolderObject->checkActionPermission('copy') && $this->clipObj->current === 'normal') {
1368 $copyTitle = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.copy'));
1369 $copyIcon = $this->iconFactory->getIcon('actions-edit-copy', Icon::SIZE_SMALL)->render();
1370
1371 if ($isSel === 'copy') {
1372 $copyIcon = $this->iconFactory->getIcon('actions-edit-copy-release', Icon::SIZE_SMALL)->render();
1373 }
1374
1375 $cells['copy'] = '<a class="btn btn-default"" href="' . htmlspecialchars($this->clipObj->selUrlFile($fullIdentifier, 1, ($isSel === 'copy'))) . '" title="' . $copyTitle . '">' . $copyIcon . '</a>';
1376 }
1377
1378 // cut the file
1379 if ($fileOrFolderObject->checkActionPermission('move') && $this->clipObj->current === 'normal') {
1380 $cutTitle = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.cut'));
1381 $cutIcon = $this->iconFactory->getIcon('actions-edit-cut', Icon::SIZE_SMALL)->render();
1382
1383 if ($isSel === 'cut') {
1384 $cutIcon = $this->iconFactory->getIcon('actions-edit-cut-release', Icon::SIZE_SMALL)->render();
1385 }
1386
1387 $cells['cut'] = '<a class="btn btn-default" href="' . htmlspecialchars($this->clipObj->selUrlFile($fullIdentifier, 0, ($isSel === 'cut'))) . '" title="' . $cutTitle . '">' . $cutIcon . '</a>';
1388 }
1389
1390 // delete the file
1391 if ($fileOrFolderObject->checkActionPermission('delete')) {
1392 $identifier = $fileOrFolderObject->getIdentifier();
1393 if ($fileOrFolderObject instanceof Folder) {
1394 $referenceCountText = BackendUtility::referenceCount('_FILE', $identifier, ' ' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.referencesToFolder'));
1395 $deleteType = 'delete_folder';
1396 } else {
1397 $referenceCountText = BackendUtility::referenceCount('sys_file', $fileOrFolderObject->getUid(), ' ' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.referencesToFile'));
1398 $deleteType = 'delete_file';
1399 }
1400
1401 if ($this->getBackendUser()->jsConfirmation(JsConfirmation::DELETE)) {
1402 $confirmationCheck = '1';
1403 } else {
1404 $confirmationCheck = '0';
1405 }
1406
1407 $deleteUrl = BackendUtility::getModuleUrl('tce_file');
1408 $confirmationMessage = sprintf($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:mess.delete'), $fileOrFolderObject->getName()) . $referenceCountText;
1409 $title = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.delete');
1410 $cells['delete'] = '<a href="#" class="btn btn-default t3js-filelist-delete" data-content="' . htmlspecialchars($confirmationMessage)
1411 . '" data-check="' . $confirmationCheck
1412 . '" data-delete-url="' . htmlspecialchars($deleteUrl)
1413 . '" data-title="' . htmlspecialchars($title)
1414 . '" data-identifier="' . htmlspecialchars($fileOrFolderObject->getCombinedIdentifier())
1415 . '" data-delete-type="' . $deleteType
1416 . '" title="' . htmlspecialchars($title) . '">'
1417 . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render() . '</a>';
1418 } else {
1419 $cells['delete'] = $this->spaceIcon;
1420 }
1421
1422 // Hook for manipulating edit icons.
1423 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'])) {
1424 $cells['__fileOrFolderObject'] = $fileOrFolderObject;
1425 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'] as $className) {
1426 $hookObject = GeneralUtility::makeInstance($className);
1427 if (!$hookObject instanceof FileListEditIconHookInterface) {
1428 throw new \UnexpectedValueException(
1429 $className . ' must implement interface ' . FileListEditIconHookInterface::class,
1430 1235225797
1431 );
1432 }
1433 $hookObject->manipulateEditIcons($cells, $this);
1434 }
1435 unset($cells['__fileOrFolderObject']);
1436 }
1437 // Compile items into a DIV-element:
1438 return '<div class="btn-group">' . implode('', $cells) . '</div>';
1439 }
1440
1441 /**
1442 * Make reference count
1443 *
1444 * @param File|Folder $fileOrFolderObject Array with information about the file/directory for which to make the clipboard panel for the listing.
1445 * @return string HTML
1446 */
1447 public function makeRef($fileOrFolderObject)
1448 {
1449 if ($fileOrFolderObject instanceof FolderInterface) {
1450 return '-';
1451 }
1452 // Look up the file in the sys_refindex.
1453 // Exclude sys_file_metadata records as these are no use references
1454 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_refindex');
1455 $referenceCount = $queryBuilder->count('*')
1456 ->from('sys_refindex')
1457 ->where(
1458 $queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
1459 $queryBuilder->expr()->eq(
1460 'ref_table',
1461 $queryBuilder->createNamedParameter('sys_file', \PDO::PARAM_STR)
1462 ),
1463 $queryBuilder->expr()->eq(
1464 'ref_uid',
1465 $queryBuilder->createNamedParameter($fileOrFolderObject->getUid(), \PDO::PARAM_INT)
1466 ),
1467 $queryBuilder->expr()->neq(
1468 'tablename',
1469 $queryBuilder->createNamedParameter('sys_file_metadata', \PDO::PARAM_STR)
1470 )
1471 )
1472 ->execute()
1473 ->fetchColumn();
1474
1475 return $this->generateReferenceToolTip($referenceCount, '\'_FILE\', ' . GeneralUtility::quoteJSvalue($fileOrFolderObject->getCombinedIdentifier()));
1476 }
1477
1478 /**
1479 * Returns an instance of LanguageService
1480 *
1481 * @return \TYPO3\CMS\Core\Localization\LanguageService
1482 */
1483 protected function getLanguageService()
1484 {
1485 return $GLOBALS['LANG'];
1486 }
1487
1488 /**
1489 * Returns the current BE user.
1490 *
1491 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1492 */
1493 protected function getBackendUser()
1494 {
1495 return $GLOBALS['BE_USER'];
1496 }
1497
1498 /**
1499 * Sets the script url depending on being a module or script request
1500 */
1501 protected function determineScriptUrl()
1502 {
1503 if ($routePath = GeneralUtility::_GP('route')) {
1504 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
1505 $this->thisScript = (string)$uriBuilder->buildUriFromRoutePath($routePath);
1506 } else {
1507 $this->thisScript = GeneralUtility::getIndpEnv('SCRIPT_NAME');
1508 }
1509 }
1510
1511 /**
1512 * @return string
1513 */
1514 protected function getThisScript()
1515 {
1516 return strpos($this->thisScript, '?') === false ? $this->thisScript . '?' : $this->thisScript . '&';
1517 }
1518
1519 /**
1520 * Gets an instance of TranslationConfigurationProvider
1521 *
1522 * @return TranslationConfigurationProvider
1523 */
1524 protected function getTranslateTools()
1525 {
1526 if (!isset($this->translateTools)) {
1527 $this->translateTools = GeneralUtility::makeInstance(TranslationConfigurationProvider::class);
1528 }
1529 return $this->translateTools;
1530 }
1531
1532 /**
1533 * Generates HTML code for a Reference tooltip out of
1534 * sys_refindex records you hand over
1535 *
1536 * @param int $references number of records from sys_refindex table
1537 * @param string $launchViewParameter JavaScript String, which will be passed as parameters to top.launchView
1538 * @return string
1539 */
1540 protected function generateReferenceToolTip($references, $launchViewParameter = '')
1541 {
1542 if (!$references) {
1543 $htmlCode = '-';
1544 } else {
1545 $htmlCode = '<a href="#"';
1546 if ($launchViewParameter !== '') {
1547 $htmlCode .= ' onclick="' . htmlspecialchars(
1548 ('top.launchView(' . $launchViewParameter . '); return false;')
1549 ) . '"';
1550 }
1551 $htmlCode .= ' title="' . htmlspecialchars(
1552 $this->getLanguageService()->sL(
1553 'LLL:EXT:backend/Resources/Private/Language/locallang.xlf:show_references'
1554 ) . ' (' . $references . ')'
1555 ) . '">';
1556 $htmlCode .= $references;
1557 $htmlCode .= '</a>';
1558 }
1559 return $htmlCode;
1560 }
1561 }