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