[TASK] Add IconUtility::getSpriteIconForResource()
[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 folder icon in the top
224 if ($folderObject) {
225 $title = htmlspecialchars($folderObject->getIdentifier());
226 // Start compiling the HTML
227 // @todo: how to fix this? $title = $GLOBALS['SOBE']->basicFF->blindPath($title);
228 // If this is some subFolder under the mount root....
229 if ($folderObject->getStorage()->isWithinFileMountBoundaries($folderObject)) {
230 // The icon with link
231 $otherMarkers['PAGE_ICON'] = IconUtility::getSpriteIconForResource($folderObject, array('title' => $title));
232 // No HTML specialchars here - HTML like <strong> </strong> is allowed
233 $otherMarkers['TITLE'] .= GeneralUtility::removeXSS(GeneralUtility::fixed_lgd_cs($title, -($this->fixedL + 20)));
234 } else {
235 // This is the root folder
236 $otherMarkers['PAGE_ICON'] = IconUtility::getSpriteIconForResource($folderObject, array('title' => $title, 'mount-root' => TRUE));
237 $otherMarkers['TITLE'] .= htmlspecialchars(GeneralUtility::fixed_lgd_cs($title, -($this->fixedL + 20)));
238 }
239 if ($this->clickMenus) {
240 $otherMarkers['PAGE_ICON'] = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($otherMarkers['PAGE_ICON'], $folderObject->getCombinedIdentifier());
241 }
242 // Add paste button if clipboard is initialized
243 if ($this->clipObj instanceof \TYPO3\CMS\Backend\Clipboard\Clipboard) {
244 $elFromTable = $this->clipObj->elFromTable('_FILE');
245 if (count($elFromTable)) {
246 $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>';
247 }
248 }
249
250 }
251 $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>';
252 return array($buttons, $otherMarkers);
253 }
254
255 /**
256 * Wrapping input string in a link with clipboard command.
257 *
258 * @param string $string String to be linked - must be htmlspecialchar'ed / prepared before.
259 * @param string $table table - NOT USED
260 * @param string $cmd "cmd" value
261 * @param string $warning Warning for JS confirm message
262 * @return string Linked string
263 * @todo Define visibility
264 */
265 public function linkClipboardHeaderIcon($string, $table, $cmd, $warning = '') {
266 $onClickEvent = 'document.dblistForm.cmd.value=\'' . $cmd . '\';document.dblistForm.submit();';
267 if ($warning) {
268 $onClickEvent = 'if (confirm(' . GeneralUtility::quoteJSvalue($warning) . ')){' . $onClickEvent . '}';
269 }
270 return '<a href="#" onclick="' . htmlspecialchars($onClickEvent) . 'return false;">' . $string . '</a>';
271 }
272
273 /**
274 * Returns a table with directories and files listed.
275 *
276 * @param array $rowlist Array of files from path
277 * @return string HTML-table
278 * @todo Define visibility
279 */
280 public function getTable($rowlist) {
281 // TODO use folder methods directly when they support filters
282 $storage = $this->folderObject->getStorage();
283 $storage->resetFileAndFolderNameFiltersToDefault();
284
285 // Only render the contents of a browsable storage
286
287 if ($this->folderObject->getStorage()->isBrowsable()) {
288 $folders = $storage->getFolderIdentifiersInFolder($this->folderObject->getIdentifier());
289 $files = $this->folderObject->getFiles();
290 $this->sort = trim($this->sort);
291 if ($this->sort !== '') {
292 $filesToSort = array();
293 /** @var $fileObject \TYPO3\CMS\Core\Resource\File */
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 case 'file':
309 $sortingKey = $fileObject->getName();
310 break;
311 default:
312 if ($fileObject->hasProperty($this->sort)) {
313 $sortingKey = $fileObject->getProperty($this->sort);
314 } else {
315 $sortingKey = $fileObject->getName();
316 }
317 }
318 $i = 0;
319 while (isset($filesToSort[$sortingKey . $i])) {
320 $i++;
321 }
322 $filesToSort[$sortingKey . $i] = $fileObject;
323 }
324 uksort($filesToSort, 'strnatcasecmp');
325 if ((int)$this->sortRev === 1) {
326 $filesToSort = array_reverse($filesToSort);
327 }
328 $files = $filesToSort;
329 }
330 $this->totalItems = count($folders) + count($files);
331 // Adds the code of files/dirs
332 $out = '';
333 $titleCol = 'file';
334 // Cleaning rowlist for duplicates and place the $titleCol as the first column always!
335 $rowlist = GeneralUtility::rmFromList($titleCol, $rowlist);
336 $rowlist = GeneralUtility::uniqueList($rowlist);
337 $rowlist = $rowlist ? $titleCol . ',' . $rowlist : $titleCol;
338 if ($this->bigControlPanel || $this->clipBoard) {
339 $rowlist = str_replace('file,', 'file,_CLIPBOARD_,', $rowlist);
340 }
341 $this->fieldArray = explode(',', $rowlist);
342 $folderObjects = array();
343 foreach ($folders as $folder) {
344 $folderObjects[] = $storage->getFolder($folder, TRUE);
345 }
346
347 $folderObjects = \TYPO3\CMS\Core\Resource\Utility\ListUtility::resolveSpecialFolderNames($folderObjects);
348 uksort($folderObjects, 'strnatcasecmp');
349
350 // Directories are added
351 $iOut = $this->formatDirList($folderObjects);
352 // Files are added
353 $iOut .= $this->formatFileList($files, $titleCol);
354 // Header line is drawn
355 $theData = array();
356 foreach ($this->fieldArray as $v) {
357 if ($v == '_CLIPBOARD_' && $this->clipBoard) {
358 $cells = array();
359 $table = '_FILE';
360 $elFromTable = $this->clipObj->elFromTable($table);
361 if (count($elFromTable)) {
362 $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>';
363 }
364 if ($this->clipObj->current != 'normal' && $iOut) {
365 $cells[] = $this->linkClipboardHeaderIcon(IconUtility::getSpriteIcon('actions-edit-copy', array('title' => $GLOBALS['LANG']->getLL('clip_selectMarked', TRUE))), $table, 'setCB');
366 $cells[] = $this->linkClipboardHeaderIcon(IconUtility::getSpriteIcon('actions-edit-delete', array('title' => $GLOBALS['LANG']->getLL('clip_deleteMarked'))), $table, 'delete', $GLOBALS['LANG']->getLL('clip_deleteMarkedWarning'));
367 $onClick = 'checkOffCB(\'' . implode(',', $this->CBnames) . '\', this); return false;';
368 $cells[] = '<a class="cbcCheckAll" rel="" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $GLOBALS['LANG']->getLL('clip_markRecords', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-select') . '</a>';
369 }
370 $theData[$v] = implode('', $cells);
371 } else {
372 // Normal row:
373 $theT = $this->linkWrapSort($GLOBALS['LANG']->getLL('c_' . $v, TRUE), $this->folderObject->getCombinedIdentifier(), $v);
374 $theData[$v] = $theT;
375 }
376 }
377
378 $out .= '<thead>' . $this->addelement(1, '&nbsp;', $theData) . '</thead>';
379 $out .= '<tbody>' . $iOut . '</tbody>';
380 // half line is drawn
381 // finish
382 $out = '
383 <!--
384 File list table:
385 -->
386 <table class="t3-table" id="typo3-filelist">
387 ' . $out . '
388 </table>';
389
390 } else {
391 /** @var $flashMessage \TYPO3\CMS\Core\Messaging\FlashMessage */
392 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('storageNotBrowsableMessage'), $GLOBALS['LANG']->getLL('storageNotBrowsableTitle'), \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
393 $out = $flashMessage->render();
394 }
395 return $out;
396 }
397
398
399 /**
400 * If there is a parent folder and user has access to it, return an icon
401 * which is linked to the filelist of the parent folder.
402 *
403 * @param \TYPO3\CMS\Core\Resource\Folder $currentFolder
404 * @return string
405 */
406 protected function getLinkToParentFolder(\TYPO3\CMS\Core\Resource\Folder $currentFolder) {
407 $levelUp = '';
408 try {
409 $currentStorage = $currentFolder->getStorage();
410 $parentFolder = $currentFolder->getParentFolder();
411 if ($parentFolder->getIdentifier() !== $currentFolder->getIdentifier() && $currentStorage->isWithinFileMountBoundaries($parentFolder)) {
412 $levelUp = $this->linkWrapDir(
413 IconUtility::getSpriteIcon(
414 'actions-view-go-up',
415 array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.upOneLevel', TRUE))
416 ),
417 $parentFolder
418 );
419 }
420 } catch (\Exception $e) {}
421 return $levelUp;
422 }
423 /**
424 * Gets the number of files and total size of a folder
425 *
426 * @return string
427 * @todo Define visibility
428 */
429 public function getFolderInfo() {
430 if ($this->counter == 1) {
431 $fileLabel = $GLOBALS['LANG']->getLL('file', TRUE);
432 } else {
433 $fileLabel = $GLOBALS['LANG']->getLL('files', TRUE);
434 }
435 return $this->counter . ' ' . $fileLabel . ', ' . GeneralUtility::formatSize($this->totalbytes, $GLOBALS['LANG']->getLL('byteSizeUnits', TRUE));
436 }
437
438 /**
439 * This returns tablerows for the directories in the array $items['sorting'].
440 *
441 * @param \TYPO3\CMS\Core\Resource\Folder[] $folders Folders of \TYPO3\CMS\Core\Resource\Folder
442 * @return string HTML table rows.
443 * @todo Define visibility
444 */
445 public function formatDirList(array $folders) {
446 $out = '';
447 foreach ($folders as $folderName => $folderObject) {
448 $role = $folderObject->getRole();
449 if ($role === FolderInterface::ROLE_PROCESSING) {
450 // don't show processing-folder
451 continue;
452 }
453 if ($role !== FolderInterface::ROLE_DEFAULT) {
454 $displayName = '<strong>' . htmlspecialchars($folderName) . '</strong>';
455 } else {
456 $displayName = htmlspecialchars($folderName);
457 }
458
459 list($flag, $code) = $this->fwd_rwd_nav();
460 $out .= $code;
461 if ($flag) {
462 $isLocked = $folderObject instanceof \TYPO3\CMS\Core\Resource\InaccessibleFolder;
463 $isWritable = $folderObject->checkActionPermission('write');
464
465 // Initialization
466 $this->counter++;
467
468 // The icon with link
469 $theIcon = IconUtility::getSpriteIconForResource($folderObject, array('title' => $folderName));
470 if (!$isLocked && !$this->clickMenus) {
471 $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon, $folderObject->getCombinedIdentifier());
472 }
473
474 // Preparing and getting the data-array
475 $theData = array();
476 if ($isLocked) {
477 foreach ($this->fieldArray as $field) {
478 $theData[$field] = '';
479 }
480 $theData['file'] = $displayName;
481 } else {
482 foreach ($this->fieldArray as $field) {
483 switch ($field) {
484 case 'size':
485 $numFiles = $folderObject->getFileCount();
486 $theData[$field] = $numFiles . ' ' . $GLOBALS['LANG']->getLL(($numFiles === 1 ? 'file' : 'files'), TRUE);
487 break;
488 case 'rw':
489 $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>');
490 break;
491 case 'fileext':
492 $theData[$field] = $GLOBALS['LANG']->getLL('folder', TRUE);
493 break;
494 case 'tstamp':
495 // @todo: FAL: how to get the mtime info -- $theData[$field] = \TYPO3\CMS\Backend\Utility\BackendUtility::date($theFile['tstamp']);
496 $theData[$field] = '-';
497 break;
498 case 'file':
499 $theData[$field] = $this->linkWrapDir($displayName, $folderObject);
500 break;
501 case '_CLIPBOARD_':
502 $temp = '';
503 if ($this->bigControlPanel) {
504 $temp .= $this->makeEdit($folderObject);
505 }
506 $temp .= $this->makeClip($folderObject);
507 $theData[$field] = $temp;
508 break;
509 case '_REF_':
510 $theData[$field] = $this->makeRef($folderObject);
511 break;
512 default:
513 $theData[$field] = GeneralUtility::fixed_lgd_cs($theFile[$field], $this->fixedL);
514 }
515 }
516 }
517 $out .= $this->addelement(1, $theIcon, $theData);
518 }
519 $this->eCounter++;
520 $this->dirCounter = $this->eCounter;
521 }
522 return $out;
523 }
524
525 /**
526 * Wraps the directory-titles
527 *
528 * @param string $title String to be wrapped in links
529 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject Folder to work on
530 * @return string HTML
531 * @todo Define visibility
532 */
533 public function linkWrapDir($title, \TYPO3\CMS\Core\Resource\Folder $folderObject) {
534 $href = $this->backPath . $this->script . '&id=' . rawurlencode($folderObject->getCombinedIdentifier());
535 $onclick = ' onclick="' . htmlspecialchars(('top.content.nav_frame.hilight_row("file","folder' . GeneralUtility::md5int($folderObject->getCombinedIdentifier()) . '_"+top.fsMod.currentBank)')) . '"';
536 // Sometimes $code contains plain HTML tags. In such a case the string should not be modified!
537 if ((string)$title === strip_tags($title)) {
538 return '<a href="' . htmlspecialchars($href) . '"' . $onclick . ' title="' . htmlspecialchars($title) . '">' . GeneralUtility::fixed_lgd_cs($title, $this->fixedL) . '</a>';
539 } else {
540 return '<a href="' . htmlspecialchars($href) . '"' . $onclick . '>' . $title . '</a>';
541 }
542 }
543
544 /**
545 * Wraps filenames in links which opens them in a window IF they are in web-path.
546 *
547 * @param string $code String to be wrapped in links
548 * @param \TYPO3\CMS\Core\Resource\File $fileObject File to be linked
549 * @return string HTML
550 * @todo Define visibility
551 */
552 public function linkWrapFile($code, \TYPO3\CMS\Core\Resource\File $fileObject) {
553 $fileUrl = $fileObject->getPublicUrl(TRUE);
554 if ($fileUrl) {
555 $aOnClick = 'return top.openUrlInWindow(\'' . $fileUrl . '\', \'WebFile\');';
556 $code = '<a href="#" title="' . htmlspecialchars($code) . '" onclick="' . htmlspecialchars($aOnClick) . '">' . GeneralUtility::fixed_lgd_cs($code, $this->fixedL) . '</a>';
557 }
558 return $code;
559 }
560
561 /**
562 * Returns list URL; This is the URL of the current script with id and imagemode parameters, that's all.
563 * The URL however is not relative (with the backpath), otherwise GeneralUtility::sanitizeLocalUrl() would say that
564 * the URL would be invalid
565 *
566 * @return string URL
567 * @todo Define visibility
568 */
569 public function listURL() {
570 return GeneralUtility::linkThisScript(array(
571 'target' => rawurlencode($this->folderObject->getCombinedIdentifier()),
572 'imagemode' => $this->thumbs
573 ));
574 }
575
576 /**
577 * Returns some data specific for the directories...
578 *
579 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject File information array
580 * @return array (title, icon, path)
581 * @deprecated since 6.2 - will be removed two versions later without replacement
582 */
583 public function dirData(\TYPO3\CMS\Core\Resource\Folder $folderObject) {
584 GeneralUtility::logDeprecatedFunction();
585
586 $title = htmlspecialchars($folderObject->getName());
587 $icon = 'apps-filetree-folder-default';
588 $role = $folderObject->getRole();
589 if ($role === FolderInterface::ROLE_TEMPORARY) {
590 $title = '<strong>' . $GLOBALS['LANG']->getLL('temp', TRUE) . '</strong>';
591 $icon = 'apps-filetree-folder-temp';
592 } elseif ($role === FolderInterface::ROLE_RECYCLER) {
593 $icon = 'apps-filetree-folder-recycler';
594 $title = '<strong>' . $GLOBALS['LANG']->getLL('recycler', TRUE) . '</strong>';
595 }
596 return array($title, $icon, $folderObject->getIdentifier());
597 }
598
599 /**
600 * This returns tablerows for the files in the array $items['sorting'].
601 *
602 * @param \TYPO3\CMS\Core\Resource\File[] $files File items
603 * @return string HTML table rows.
604 * @todo Define visibility
605 */
606 public function formatFileList(array $files) {
607 $out = '';
608 // first two keys are "0" (default) and "-1" (multiple), after that comes the "other languages"
609 $allSystemLanguages = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Configuration\\TranslationConfigurationProvider')->getSystemLanguages();
610 $systemLanguages = array_filter($allSystemLanguages, function($languageRecord) {
611 if ($languageRecord['uid'] === -1 || $languageRecord['uid'] === 0 || !$GLOBALS['BE_USER']->checkLanguageAccess($languageRecord['uid'])) {
612 return FALSE;
613 } else {
614 return TRUE;
615 }
616 });
617
618 foreach ($files as $fileObject) {
619 list($flag, $code) = $this->fwd_rwd_nav();
620 $out .= $code;
621 if ($flag) {
622 // Initialization
623 $this->counter++;
624 $this->totalbytes += $fileObject->getSize();
625 $ext = $fileObject->getExtension();
626 $fileName = trim($fileObject->getName());
627 // The icon with link
628 $theIcon = IconUtility::getSpriteIconForResource($fileObject, array('title' => $fileName));
629 if ($this->clickMenus) {
630 $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon, $fileObject->getCombinedIdentifier());
631 }
632 // Preparing and getting the data-array
633 $theData = array();
634 foreach ($this->fieldArray as $field) {
635 switch ($field) {
636 case 'size':
637 $theData[$field] = GeneralUtility::formatSize($fileObject->getSize(), $GLOBALS['LANG']->getLL('byteSizeUnits', TRUE));
638 break;
639 case 'rw':
640 $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>');
641 break;
642 case 'fileext':
643 $theData[$field] = strtoupper($ext);
644 break;
645 case 'tstamp':
646 $theData[$field] = BackendUtility::date($fileObject->getProperty('modification_date'));
647 break;
648 case '_CLIPBOARD_':
649 $temp = '';
650 if ($this->bigControlPanel) {
651 $temp .= $this->makeEdit($fileObject);
652 }
653 $temp .= $this->makeClip($fileObject);
654 if (!empty($systemLanguages)) {
655 $temp .= '<a class="filelist-translationToggler" data-fileid="' . $fileObject->getUid() . '">' .
656 IconUtility::getSpriteIcon('mimetypes-x-content-page-language-overlay') . '</a>';
657 }
658 $theData[$field] = $temp;
659 break;
660 case '_REF_':
661 $theData[$field] = $this->makeRef($fileObject);
662 break;
663 case 'file':
664 $theData[$field] = $this->linkWrapFile(htmlspecialchars($fileName), $fileObject);
665
666 if ($fileObject->isMissing()) {
667 $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($fileObject);
668 $theData[$field] .= $flashMessage->render();
669 // Thumbnails?
670 } elseif ($this->thumbs && $this->isImage($ext)) {
671 $processedFile = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array());
672 if ($processedFile) {
673 $thumbUrl = $processedFile->getPublicUrl(TRUE);
674 $theData[$field] .= '<br /><img src="' . $thumbUrl . '" title="' . htmlspecialchars($fileName) . '" alt="" />';
675 }
676 }
677
678 if (!empty($systemLanguages)) {
679 $metaDataRecord = $fileObject->_getMetaData();
680 $translations = $this->getTranslationsForMetaData($metaDataRecord);
681 $languageCode = '';
682
683 foreach ($systemLanguages as $language) {
684 $languageId = $language['uid'];
685 $flagIcon = $language['flagIcon'];
686
687 if (array_key_exists($languageId, $translations)) {
688 $flagButtonIcon = IconUtility::getSpriteIcon(
689 'actions-document-open',
690 array('title' => $fileName),
691 array($flagIcon . '-overlay' => array()));
692 $data = array(
693 'sys_file_metadata' => array($translations[$languageId]['uid'] => 'edit')
694 );
695 $editOnClick = BackendUtility::editOnClick(GeneralUtility::implodeArrayForUrl('edit', $data), $GLOBALS['BACK_PATH'], $this->listUrl());
696 $languageCode .= sprintf('<a href="#" onclick="%s">%s</a>', htmlspecialchars($editOnClick), $flagButtonIcon);
697
698 } else {
699 $href = $GLOBALS['SOBE']->doc->issueCommand(
700 '&cmd[sys_file_metadata][' . $metaDataRecord['uid'] . '][localize]=' . $languageId,
701 $this->backPath . 'alt_doc.php?justLocalized=' . rawurlencode(('sys_file_metadata:' . $metaDataRecord['uid'] . ':' . $languageId)) .
702 '&returnUrl=' . rawurlencode($this->listURL()) . BackendUtility::getUrlToken('editRecord')
703 );
704 $flagButtonIcon = IconUtility::getSpriteIcon($flagIcon);
705 $languageCode .= sprintf('<a href="%s">%s</a> ', htmlspecialchars($href), $flagButtonIcon);
706 }
707 }
708
709 // Hide flag button bar when not translated yet
710 $theData[$field] .= '<div class="localisationData" data-fileid="' . $fileObject->getUid() . '"' .
711 (empty($translations) ? ' style="display: none;"' : '') . '>' . $languageCode . '</div>';
712 }
713
714 break;
715 default:
716 $theData[$field] = '';
717 if ($fileObject->hasProperty($field)) {
718 $theData[$field] = htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileObject->getProperty($field), $this->fixedL));
719 }
720 }
721 }
722 $out .= $this->addelement(1, $theIcon, $theData);
723
724 }
725 $this->eCounter++;
726 }
727 return $out;
728 }
729
730 /**
731 * Fetch the translations for a sys_file_metadata record
732 *
733 * @param $metaDataRecord
734 * @return array keys are the sys_language uids, values are the $rows
735 */
736 protected function getTranslationsForMetaData($metaDataRecord) {
737 $where = $GLOBALS['TCA']['sys_file_metadata']['ctrl']['transOrigPointerField'] . '=' . (int)$metaDataRecord['uid'] .
738 ' AND ' . $GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField'] . '>0';
739 $translationRecords = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_file_metadata', $where);
740 $translations = array();
741 foreach ($translationRecords as $record) {
742 $translations[$record[$GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField']]] = $record;
743 }
744 return $translations;
745 }
746
747 /**
748 * Returns TRUE if $ext is an image-extension according to $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
749 *
750 * @param string $ext File extension
751 * @return boolean
752 * @todo Define visibility
753 */
754 public function isImage($ext) {
755 return GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($ext));
756 }
757
758 /**
759 * Wraps the directory-titles ($code) in a link to filelist/mod1/index.php (id=$path) and sorting commands...
760 *
761 * @param string $code String to be wrapped
762 * @param string $folderIdentifier ID (path)
763 * @param string $col Sorting column
764 * @return string HTML
765 * @todo Define visibility
766 */
767 public function linkWrapSort($code, $folderIdentifier, $col) {
768 if ($this->sort === $col) {
769 // Check reverse sorting
770 $params = '&SET[sort]=' . $col . '&SET[reverse]=' . ($this->sortRev ? '0' : '1');
771 $sortArrow = IconUtility::getSpriteIcon('status-status-sorting-light-' . ($this->sortRev ? 'desc' : 'asc'));
772 } else {
773 $params = '&SET[sort]=' . $col . '&SET[reverse]=0';
774 $sortArrow = '';
775 }
776 $href = GeneralUtility::resolveBackPath(($GLOBALS['BACK_PATH'] . $this->script)) . '&id=' . rawurlencode($folderIdentifier) . $params;
777 return '<a href="' . htmlspecialchars($href) . '">' . $code . $sortArrow . '</a>';
778 }
779
780 /**
781 * Creates the clipboard control pad
782 *
783 * @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.
784 * @return string HTML-table
785 * @todo Define visibility
786 */
787 public function makeClip($fileOrFolderObject) {
788 $cells = array();
789 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
790 $md5 = GeneralUtility::shortmd5($fullIdentifier);
791 // For normal clipboard, add copy/cut buttons:
792 if ($this->clipObj->current == 'normal') {
793 $isSel = $this->clipObj->isSelected('_FILE', $md5);
794 $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>';
795 $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>';
796 } else {
797 // For numeric pads, add select checkboxes:
798 $n = '_FILE|' . $md5;
799 $this->CBnames[] = $n;
800 $checked = $this->clipObj->isSelected('_FILE', $md5) ? ' checked="checked"' : '';
801 $cells[] = '<input type="hidden" name="CBH[' . $n . ']" value="0" />' . '<input type="checkbox" name="CBC[' . $n . ']" value="' . htmlspecialchars($fullIdentifier) . '" class="smallCheckboxes"' . $checked . ' />';
802 }
803 // Display PASTE button, if directory:
804 $elFromTable = $this->clipObj->elFromTable('_FILE');
805 if (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\Folder') && count($elFromTable)) {
806 $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>';
807 }
808 // Compile items into a DIV-element:
809 return ' <!-- CLIPBOARD PANEL: -->
810 <div class="typo3-clipCtrl">
811 ' . implode('
812 ', $cells) . '
813 </div>';
814 }
815
816 /**
817 * Creates the edit control section
818 *
819 * @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.
820 * @return string HTML-table
821 * @todo Define visibility
822 */
823 public function makeEdit($fileOrFolderObject) {
824 $cells = array();
825 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
826 // Edit metadata of file
827 try {
828 if (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\File') && $fileOrFolderObject->isIndexed() && $fileOrFolderObject->checkActionPermission('write')) {
829 $metaData = $fileOrFolderObject->_getMetaData();
830 $data = array(
831 'sys_file_metadata' => array($metaData['uid'] => 'edit')
832 );
833 $editOnClick = BackendUtility::editOnClick(GeneralUtility::implodeArrayForUrl('edit', $data), $GLOBALS['BACK_PATH'], $this->listUrl());
834 $cells['editmetadata'] = '<a href="#" onclick="' . $editOnClick . '" title="Edit Metadata of this file">' . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
835 } else {
836 $cells['editmetadata'] = IconUtility::getSpriteIcon('empty-empty');
837 }
838 } catch (\Exception $e) {
839 $cells['editmetadata'] = IconUtility::getSpriteIcon('empty-empty');
840 }
841 // Edit file content (if editable)
842 if (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\File') && $fileOrFolderObject->checkActionPermission('write') && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileOrFolderObject->getExtension())) {
843 $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;';
844 $cells['edit'] = '<a href="#" onclick="' . $editOnClick . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.editcontent') . '">' . IconUtility::getSpriteIcon('actions-page-open') . '</a>';
845 } else {
846 $cells['edit'] = IconUtility::getSpriteIcon('empty-empty');
847 }
848 // rename the file
849 if ($fileOrFolderObject->checkActionPermission('rename')) {
850 $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;';
851 $cells['rename'] = '<a href="#" onclick="' . $renameOnClick . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.rename') . '">' . IconUtility::getSpriteIcon('actions-edit-rename') . '</a>';
852 } else {
853 $cells['rename'] = IconUtility::getSpriteIcon('empty-empty');
854 }
855 if ($fileOrFolderObject->checkActionPermission('read')) {
856 if (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\Folder')) {
857 $infoOnClick = 'top.launchView( \'_FOLDER\', \'' . $fullIdentifier . '\');return false;';
858 } elseif (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\File')) {
859 $infoOnClick = 'top.launchView( \'_FILE\', \'' . $fullIdentifier . '\');return false;';
860 }
861 $cells['info'] = '<a href="#" onclick="' . $infoOnClick . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.info') . '">' . IconUtility::getSpriteIcon('status-dialog-information') . '</a>';
862 } else {
863 $cells['info'] = IconUtility::getSpriteIcon('empty-empty');
864 }
865
866 // delete the file
867 if ($fileOrFolderObject->checkActionPermission('delete')) {
868 $identifier = $fileOrFolderObject->getIdentifier();
869 if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
870 $referenceCountText = BackendUtility::referenceCount('_FILE', $identifier, ' (There are %s reference(s) to this folder!)');
871 } else {
872 $referenceCountText = BackendUtility::referenceCount('sys_file', $identifier, ' (There are %s reference(s) to this file!)');
873 }
874
875 if ($GLOBALS['BE_USER']->jsConfirmation(4)) {
876 $confirmationCheck = 'confirm(' . GeneralUtility::quoteJSvalue(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.delete'), basename($identifier)) . $referenceCountText) . ')';
877 } else {
878 $confirmationCheck = '1 == 1';
879 }
880
881 $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);};';
882
883 $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>';
884 } else {
885 $cells['delete'] = IconUtility::getSpriteIcon('empty-empty');
886 }
887
888 // Hook for manipulating edit icons.
889 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'])) {
890 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'] as $classData) {
891 $hookObject = GeneralUtility::getUserObj($classData);
892 if (!$hookObject instanceof \TYPO3\CMS\Filelist\FileListEditIconHookInterface) {
893 throw new \UnexpectedValueException(
894 '$hookObject must implement interface \\TYPO3\\CMS\\Filelist\\FileListEditIconHookInterface',
895 1235225797
896 );
897 }
898 $hookObject->manipulateEditIcons($cells, $this);
899 }
900 }
901 // Compile items into a DIV-element:
902 return ' <!-- EDIT CONTROLS: -->
903 <div class="typo3-editCtrl">
904 ' . implode('
905 ', $cells) . '
906 </div>';
907 }
908
909 /**
910 * Make reference count
911 *
912 * @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.
913 * @return string HTML
914 * @todo Define visibility
915 */
916 public function makeRef($fileOrFolderObject) {
917 if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FolderInterface) {
918 return '-';
919 }
920 // Look up the file in the sys_refindex.
921 // Exclude sys_file_metadata records as these are no use references
922 $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"');
923 return $this->generateReferenceToolTip($rows, '\'_FILE\', ' . GeneralUtility::quoteJSvalue($fileOrFolderObject->getCombinedIdentifier()));
924 }
925
926 }