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