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