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