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