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