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