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