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