[TASK] Remove @package and @subpackage annotations
[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 $out .= '<thead>' . $this->addelement(1, $levelUp, $theData, ' class="t3-row-header"', '') . '</thead>';
360 $out .= '<tbody>' . $iOut . '</tbody>';
361 // half line is drawn
362 // finish
363 $out = '
364
365
366 <!--
367 File list table:
368 -->
369 <table cellpadding="0" cellspacing="0" id="typo3-filelist">
370 ' . $out . '
371 </table>';
372 } else {
373 /** @var $flashMessage \TYPO3\CMS\Core\Messaging\FlashMessage */
374 $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);
375 $out = $flashMessage->render();
376 }
377 return $out;
378 }
379
380 /**
381 * Gets the number of files and total size of a folder
382 *
383 * @return string
384 * @todo Define visibility
385 */
386 public function getFolderInfo() {
387 if ($this->counter == 1) {
388 $fileLabel = $GLOBALS['LANG']->getLL('file', TRUE);
389 } else {
390 $fileLabel = $GLOBALS['LANG']->getLL('files', TRUE);
391 }
392 return $this->counter . ' ' . $fileLabel . ', ' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($this->totalbytes, $GLOBALS['LANG']->getLL('byteSizeUnits', TRUE));
393 }
394
395 /**
396 * This returns tablerows for the directories in the array $items['sorting'].
397 *
398 * @param \TYPO3\CMS\Core\Resource\Folder[] $folders Folders of \TYPO3\CMS\Core\Resource\Folder
399 * @return string HTML table rows.
400 * @todo Define visibility
401 */
402 public function formatDirList(array $folders) {
403 $out = '';
404 foreach ($folders as $folderObject) {
405 list($flag, $code) = $this->fwd_rwd_nav();
406 $out .= $code;
407 if ($flag) {
408 // Initialization
409 $this->counter++;
410 list($title, $icon, $path) = $this->dirData($folderObject);
411 // The icon with link
412 $theIcon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile('folder', array('title' => $title));
413 if ($this->clickMenus) {
414 $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon, $folderObject->getCombinedIdentifier());
415 }
416 // Preparing and getting the data-array
417 $theData = array();
418 foreach ($this->fieldArray as $field) {
419 switch ($field) {
420 case 'size':
421 $numFiles = $folderObject->getFileCount();
422 $theData[$field] = $numFiles . ' ' . $GLOBALS['LANG']->getLL(($numFiles === 1 ? 'file' : 'files'), TRUE);
423 break;
424 case 'rw':
425 $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>');
426 break;
427 case 'fileext':
428 $theData[$field] = $GLOBALS['LANG']->getLL('folder', TRUE);
429 break;
430 case 'tstamp':
431 // @todo: FAL: how to get the mtime info -- $theData[$field] = t3lib_BEfunc::date($theFile['tstamp']);
432 $theData[$field] = '-';
433 break;
434 case 'file':
435 $theData[$field] = $this->linkWrapDir($title, $folderObject);
436 break;
437 case '_CLIPBOARD_':
438 $temp = '';
439 if ($this->bigControlPanel) {
440 $temp .= $this->makeEdit($folderObject);
441 }
442 $temp .= $this->makeClip($folderObject);
443 $theData[$field] = $temp;
444 break;
445 case '_REF_':
446 $theData[$field] = $this->makeRef($folderObject);
447 break;
448 default:
449 $theData[$field] = \TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($theFile[$field], $this->fixedL);
450 break;
451 }
452 }
453 $out .= $this->addelement(1, $theIcon, $theData, ' class="file_list_normal"');
454 }
455 $this->eCounter++;
456 $this->dirCounter = $this->eCounter;
457 }
458 return $out;
459 }
460
461 /**
462 * Wraps the directory-titles
463 *
464 * @param string $title String to be wrapped in links
465 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject Folder to work on
466 * @return string HTML
467 * @todo Define visibility
468 */
469 public function linkWrapDir($title, \TYPO3\CMS\Core\Resource\Folder $folderObject) {
470 $href = $this->backPath . $this->script . '&id=' . rawurlencode($folderObject->getCombinedIdentifier());
471 $onclick = ' onclick="' . htmlspecialchars(('top.content.nav_frame.hilight_row("file","folder' . \TYPO3\CMS\Core\Utility\GeneralUtility::md5int($folderObject->getCombinedIdentifier()) . '_"+top.fsMod.currentBank)')) . '"';
472 // Sometimes $code contains plain HTML tags. In such a case the string should not be modified!
473 if (!strcmp($title, strip_tags($title))) {
474 return '<a href="' . htmlspecialchars($href) . '"' . $onclick . ' title="' . htmlspecialchars($title) . '">' . \TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($title, $this->fixedL) . '</a>';
475 } else {
476 return '<a href="' . htmlspecialchars($href) . '"' . $onclick . '>' . $title . '</a>';
477 }
478 }
479
480 /**
481 * Wraps filenames in links which opens them in a window IF they are in web-path.
482 *
483 * @param string $code String to be wrapped in links
484 * @param \TYPO3\CMS\Core\Resource\File $fileObject File to be linked
485 * @return string HTML
486 * @todo Define visibility
487 */
488 public function linkWrapFile($code, \TYPO3\CMS\Core\Resource\File $fileObject) {
489 $fileUrl = $fileObject->getPublicUrl(TRUE);
490 if ($fileUrl) {
491 $aOnClick = 'return top.openUrlInWindow(\'' . $fileUrl . '\', \'WebFile\');';
492 $code = '<a href="#" title="' . htmlspecialchars($code) . '" onclick="' . htmlspecialchars($aOnClick) . '">' . \TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($code, $this->fixedL) . '</a>';
493 }
494 return $code;
495 }
496
497 /**
498 * Returns list URL; This is the URL of the current script with id and imagemode parameters, thats all.
499 * The URL however is not relative (with the backpath), otherwise t3lib_div::sanitizeLocalUrl() would say that
500 * the URL would be invalid
501 *
502 * @return string URL
503 * @todo Define visibility
504 */
505 public function listURL() {
506 return \TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array(
507 'target' => rawurlencode($this->folderObject->getCombinedIdentifier()),
508 'imagemode' => $this->thumbs
509 ));
510 }
511
512 /**
513 * Returns some data specific for the directories...
514 *
515 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject File information array
516 * @return array (title, icon, path)
517 * @todo Define visibility
518 */
519 public function dirData(\TYPO3\CMS\Core\Resource\Folder $folderObject) {
520 $title = htmlspecialchars($folderObject->getName());
521 $icon = 'apps-filetree-folder-default';
522 if ($title == '_temp_') {
523 $icon = 'apps-filetree-folder-temp';
524 $title = '<strong>' . $GLOBALS['LANG']->getLL('temp', TRUE) . '</strong>';
525 }
526 if ($title == '_recycler_') {
527 $icon = 'apps-filetree-folder-recycler';
528 $title = '<strong>' . $GLOBALS['LANG']->getLL('recycler', TRUE) . '</strong>';
529 }
530 // Mark the icon as read-only icon if the folder is not writable
531 if ($folderObject->checkActionPermission('write') === FALSE) {
532 $icon = 'apps-filetree-folder-locked';
533 }
534 return array($title, $icon, $folderObject->getIdentifier());
535 }
536
537 /**
538 * This returns tablerows for the files in the array $items['sorting'].
539 *
540 * @param \TYPO3\CMS\Core\Resource\File[] $files File items
541 * @return string HTML table rows.
542 * @todo Define visibility
543 */
544 public function formatFileList(array $files) {
545 $out = '';
546 foreach ($files as $fileObject) {
547 list($flag, $code) = $this->fwd_rwd_nav();
548 $out .= $code;
549 if ($flag) {
550 // Initialization
551 $this->counter++;
552 $fileInfo = $fileObject->getStorage()->getFileInfo($fileObject);
553 $this->totalbytes += $fileObject->getSize();
554 $ext = $fileObject->getExtension();
555 $fileName = trim($fileObject->getName());
556 // The icon with link
557 $theIcon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($ext, array('title' => $fileName));
558 if ($this->clickMenus) {
559 $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon, $fileObject->getCombinedIdentifier());
560 }
561 // Preparing and getting the data-array
562 $theData = array();
563 foreach ($this->fieldArray as $field) {
564 switch ($field) {
565 case 'size':
566 $theData[$field] = \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($fileObject->getSize(), $GLOBALS['LANG']->getLL('byteSizeUnits', TRUE));
567 break;
568 case 'rw':
569 $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>');
570 break;
571 case 'fileext':
572 $theData[$field] = strtoupper($ext);
573 break;
574 case 'tstamp':
575 $theData[$field] = \TYPO3\CMS\Backend\Utility\BackendUtility::date($fileInfo['mtime']);
576 break;
577 case '_CLIPBOARD_':
578 $temp = '';
579 if ($this->bigControlPanel) {
580 $temp .= $this->makeEdit($fileObject);
581 }
582 $temp .= $this->makeClip($fileObject);
583 $theData[$field] = $temp;
584 break;
585 case '_REF_':
586 $theData[$field] = $this->makeRef($fileObject);
587 break;
588 case 'file':
589 $theData[$field] = $this->linkWrapFile(htmlspecialchars($fileName), $fileObject);
590 // Thumbnails?
591 if ($this->thumbs && $this->isImage($ext)) {
592 $processedFile = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array());
593 if ($processedFile) {
594 $thumbUrl = $processedFile->getPublicUrl(TRUE);
595 $theData[$field] .= '<br /><img src="' . $thumbUrl . '" hspace="2" title="' . htmlspecialchars($fileName) . '" alt="" />';
596 }
597 }
598 break;
599 default:
600 // @todo: fix the access on the array
601 $theData[$field] = htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($theFile[$field], $this->fixedL));
602 break;
603 }
604 }
605 $out .= $this->addelement(1, $theIcon, $theData, ' class="file_list_normal"');
606 }
607 $this->eCounter++;
608 }
609 return $out;
610 }
611
612 /**
613 * Returns TRUE if $ext is an image-extension according to $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
614 *
615 * @param string $ext File extension
616 * @return boolean
617 * @todo Define visibility
618 */
619 public function isImage($ext) {
620 return \TYPO3\CMS\Core\Utility\GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($ext));
621 }
622
623 /**
624 * Wraps the directory-titles ($code) in a link to filelist/mod1/index.php (id=$path) and sorting commands...
625 *
626 * @param string $code String to be wrapped
627 * @param string $folderIdentifier ID (path)
628 * @param string $col Sorting column
629 * @return string HTML
630 * @todo Define visibility
631 */
632 public function linkWrapSort($code, $folderIdentifier, $col) {
633 if ($this->sort === $col) {
634 // Check reverse sorting
635 $params = '&SET[sort]=' . $col . '&SET[reverse]=' . ($this->sortRev ? '0' : '1');
636 $sortArrow = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('status-status-sorting-light-' . ($this->sortRev ? 'desc' : 'asc'));
637 } else {
638 $params = '&SET[sort]=' . $col . '&SET[reverse]=0';
639 $sortArrow = '';
640 }
641 $href = \TYPO3\CMS\Core\Utility\GeneralUtility::resolveBackPath(($GLOBALS['BACK_PATH'] . $this->script)) . '&id=' . rawurlencode($folderIdentifier) . $params;
642 return '<a href="' . htmlspecialchars($href) . '">' . $code . $sortArrow . '</a>';
643 }
644
645 /**
646 * Creates the clipboard control pad
647 *
648 * @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.
649 * @return string HTML-table
650 * @todo Define visibility
651 */
652 public function makeClip($fileOrFolderObject) {
653 $cells = array();
654 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
655 $md5 = \TYPO3\CMS\Core\Utility\GeneralUtility::shortmd5($fullIdentifier);
656 // For normal clipboard, add copy/cut buttons:
657 if ($this->clipObj->current == 'normal') {
658 $isSel = $this->clipObj->isSelected('_FILE', $md5);
659 $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>';
660 $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>';
661 } else {
662 // For numeric pads, add select checkboxes:
663 $n = '_FILE|' . $md5;
664 $this->CBnames[] = $n;
665 $checked = $this->clipObj->isSelected('_FILE', $md5) ? ' checked="checked"' : '';
666 $cells[] = '<input type="hidden" name="CBH[' . $n . ']" value="0" />' . '<input type="checkbox" name="CBC[' . $n . ']" value="' . htmlspecialchars($fullIdentifier) . '" class="smallCheckboxes"' . $checked . ' />';
667 }
668 // Display PASTE button, if directory:
669 $elFromTable = $this->clipObj->elFromTable('_FILE');
670 if (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\Folder') && count($elFromTable)) {
671 $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>';
672 }
673 // Compile items into a DIV-element:
674 return ' <!-- CLIPBOARD PANEL: -->
675 <div class="typo3-clipCtrl">
676 ' . implode('
677 ', $cells) . '
678 </div>';
679 }
680
681 /**
682 * Creates the edit control section
683 *
684 * @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.
685 * @return string HTML-table
686 * @todo Define visibility
687 */
688 public function makeEdit($fileOrFolderObject) {
689 $cells = array();
690 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
691 // Edit metadata of file
692 try {
693 if (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\File') && $fileOrFolderObject->isIndexed() && $fileOrFolderObject->checkActionPermission('edit')) {
694 $data = array(
695 'sys_file' => array($fileOrFolderObject->getUid() => 'edit')
696 );
697 $editOnClick = \TYPO3\CMS\Backend\Utility\BackendUtility::editOnClick(\TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('edit', $data), $GLOBALS['BACK_PATH'], $this->listUrl());
698 $cells['editmetadata'] = '<a href="#" onclick="' . $editOnClick . '" title="Edit Metadata of this file">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-open') . '</a>';
699 } else {
700 $cells['editmetadata'] = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('empty-empty');
701 }
702 } catch (\Exception $e) {
703 $cells['editmetadata'] = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('empty-empty');
704 }
705 // Edit file content (if editable)
706 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())) {
707 $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;';
708 $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>';
709 } else {
710 $cells['edit'] = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('empty-empty');
711 }
712 // rename the file
713 if ($fileOrFolderObject->checkActionPermission('rename')) {
714 $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;';
715 $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>';
716 } else {
717 $cells['rename'] = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('empty-empty');
718 }
719 if (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\Folder')) {
720 $infoOnClick = 'top.launchView( \'_FOLDER\', \'' . $fullIdentifier . '\');return false;';
721 } elseif (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\File')) {
722 $infoOnClick = 'top.launchView( \'_FILE\', \'' . $fullIdentifier . '\');return false;';
723 }
724 $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>';
725 // Hook for manipulating edit icons.
726 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'])) {
727 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'] as $classData) {
728 $hookObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classData);
729 if (!$hookObject instanceof \TYPO3\CMS\Filelist\FileListEditIconHookInterface) {
730 throw new \UnexpectedValueException('$hookObject must implement interface fileList_editIconHook', 1235225797);
731 }
732 $hookObject->manipulateEditIcons($cells, $this);
733 }
734 }
735 // Compile items into a DIV-element:
736 return ' <!-- EDIT CONTROLS: -->
737 <div class="typo3-editCtrl">
738 ' . implode('
739 ', $cells) . '
740 </div>';
741 }
742
743 /**
744 * Make reference count
745 *
746 * @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.
747 * @return string HTML
748 * @todo Define visibility
749 */
750 public function makeRef($fileOrFolderObject) {
751 if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FolderInterface) {
752 return '-';
753 }
754 // Look up the path:
755 $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');
756 return $this->generateReferenceToolTip($rows, '\'_FILE\', \'' . $fileOrFolderObject->getCombinedIdentifier() . '\'');
757 }
758
759 }
760
761
762 ?>