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