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