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