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