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