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