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