[BUGFIX] Filelist: Only show paste buttons if clipObj is set
[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 break;
481 }
482 }
483 $out .= $this->addelement(1, $theIcon, $theData, ' class="file_list_normal"');
484 }
485 $this->eCounter++;
486 $this->dirCounter = $this->eCounter;
487 }
488 return $out;
489 }
490
491 /**
492 * Wraps the directory-titles
493 *
494 * @param string $title String to be wrapped in links
495 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject Folder to work on
496 * @return string HTML
497 * @todo Define visibility
498 */
499 public function linkWrapDir($title, \TYPO3\CMS\Core\Resource\Folder $folderObject) {
500 $href = $this->backPath . $this->script . '&id=' . rawurlencode($folderObject->getCombinedIdentifier());
501 $onclick = ' onclick="' . htmlspecialchars(('top.content.nav_frame.hilight_row("file","folder' . \TYPO3\CMS\Core\Utility\GeneralUtility::md5int($folderObject->getCombinedIdentifier()) . '_"+top.fsMod.currentBank)')) . '"';
502 // Sometimes $code contains plain HTML tags. In such a case the string should not be modified!
503 if (!strcmp($title, strip_tags($title))) {
504 return '<a href="' . htmlspecialchars($href) . '"' . $onclick . ' title="' . htmlspecialchars($title) . '">' . \TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($title, $this->fixedL) . '</a>';
505 } else {
506 return '<a href="' . htmlspecialchars($href) . '"' . $onclick . '>' . $title . '</a>';
507 }
508 }
509
510 /**
511 * Wraps filenames in links which opens them in a window IF they are in web-path.
512 *
513 * @param string $code String to be wrapped in links
514 * @param \TYPO3\CMS\Core\Resource\File $fileObject File to be linked
515 * @return string HTML
516 * @todo Define visibility
517 */
518 public function linkWrapFile($code, \TYPO3\CMS\Core\Resource\File $fileObject) {
519 $fileUrl = $fileObject->getPublicUrl(TRUE);
520 if ($fileUrl) {
521 $aOnClick = 'return top.openUrlInWindow(\'' . $fileUrl . '\', \'WebFile\');';
522 $code = '<a href="#" title="' . htmlspecialchars($code) . '" onclick="' . htmlspecialchars($aOnClick) . '">' . \TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($code, $this->fixedL) . '</a>';
523 }
524 return $code;
525 }
526
527 /**
528 * Returns list URL; This is the URL of the current script with id and imagemode parameters, thats all.
529 * The URL however is not relative (with the backpath), otherwise \TYPO3\CMS\Core\Utility\GeneralUtility::sanitizeLocalUrl() would say that
530 * the URL would be invalid
531 *
532 * @return string URL
533 * @todo Define visibility
534 */
535 public function listURL() {
536 return \TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array(
537 'target' => rawurlencode($this->folderObject->getCombinedIdentifier()),
538 'imagemode' => $this->thumbs
539 ));
540 }
541
542 /**
543 * Returns some data specific for the directories...
544 *
545 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject File information array
546 * @return array (title, icon, path)
547 * @todo Define visibility
548 */
549 public function dirData(\TYPO3\CMS\Core\Resource\Folder $folderObject) {
550 $title = htmlspecialchars($folderObject->getName());
551 $icon = 'apps-filetree-folder-default';
552 $role = $folderObject->getRole();
553 if ($role === FolderInterface::ROLE_TEMPORARY) {
554 $title = '<strong>' . $GLOBALS['LANG']->getLL('temp', TRUE) . '</strong>';
555 $icon = 'apps-filetree-folder-temp';
556 } elseif ($role === FolderInterface::ROLE_RECYCLER) {
557 $icon = 'apps-filetree-folder-recycler';
558 $title = '<strong>' . $GLOBALS['LANG']->getLL('recycler', TRUE) . '</strong>';
559 }
560 // Mark the icon as read-only icon if the folder is not writable
561 if ($folderObject->checkActionPermission('write') === FALSE) {
562 $icon = 'apps-filetree-folder-locked';
563 }
564 return array($title, $icon, $folderObject->getIdentifier());
565 }
566
567 /**
568 * This returns tablerows for the files in the array $items['sorting'].
569 *
570 * @param \TYPO3\CMS\Core\Resource\File[] $files File items
571 * @return string HTML table rows.
572 * @todo Define visibility
573 */
574 public function formatFileList(array $files) {
575 $out = '';
576 foreach ($files as $fileObject) {
577 list($flag, $code) = $this->fwd_rwd_nav();
578 $out .= $code;
579 if ($flag) {
580 // Initialization
581 $this->counter++;
582 $fileInfo = $fileObject->getStorage()->getFileInfo($fileObject);
583 $this->totalbytes += $fileObject->getSize();
584 $ext = $fileObject->getExtension();
585 $fileName = trim($fileObject->getName());
586 // The icon with link
587 $theIcon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($ext, array('title' => $fileName));
588 if ($this->clickMenus) {
589 $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon, $fileObject->getCombinedIdentifier());
590 }
591 // Preparing and getting the data-array
592 $theData = array();
593 foreach ($this->fieldArray as $field) {
594 switch ($field) {
595 case 'size':
596 $theData[$field] = \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($fileObject->getSize(), $GLOBALS['LANG']->getLL('byteSizeUnits', TRUE));
597 break;
598 case 'rw':
599 $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>');
600 break;
601 case 'fileext':
602 $theData[$field] = strtoupper($ext);
603 break;
604 case 'tstamp':
605 $theData[$field] = \TYPO3\CMS\Backend\Utility\BackendUtility::date($fileInfo['mtime']);
606 break;
607 case '_CLIPBOARD_':
608 $temp = '';
609 if ($this->bigControlPanel) {
610 $temp .= $this->makeEdit($fileObject);
611 }
612 $temp .= $this->makeClip($fileObject);
613 $theData[$field] = $temp;
614 break;
615 case '_REF_':
616 $theData[$field] = $this->makeRef($fileObject);
617 break;
618 case 'file':
619 $theData[$field] = $this->linkWrapFile(htmlspecialchars($fileName), $fileObject);
620 // Thumbnails?
621 if ($this->thumbs && $this->isImage($ext)) {
622 $processedFile = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array());
623 if ($processedFile) {
624 $thumbUrl = $processedFile->getPublicUrl(TRUE);
625 $theData[$field] .= '<br /><img src="' . $thumbUrl . '" hspace="2" title="' . htmlspecialchars($fileName) . '" alt="" />';
626 }
627 }
628 break;
629 default:
630 // @todo: fix the access on the array
631 $theData[$field] = htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($theFile[$field], $this->fixedL));
632 break;
633 }
634 }
635 $out .= $this->addelement(1, $theIcon, $theData, ' class="file_list_normal"');
636 }
637 $this->eCounter++;
638 }
639 return $out;
640 }
641
642 /**
643 * Returns TRUE if $ext is an image-extension according to $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
644 *
645 * @param string $ext File extension
646 * @return boolean
647 * @todo Define visibility
648 */
649 public function isImage($ext) {
650 return \TYPO3\CMS\Core\Utility\GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($ext));
651 }
652
653 /**
654 * Wraps the directory-titles ($code) in a link to filelist/mod1/index.php (id=$path) and sorting commands...
655 *
656 * @param string $code String to be wrapped
657 * @param string $folderIdentifier ID (path)
658 * @param string $col Sorting column
659 * @return string HTML
660 * @todo Define visibility
661 */
662 public function linkWrapSort($code, $folderIdentifier, $col) {
663 if ($this->sort === $col) {
664 // Check reverse sorting
665 $params = '&SET[sort]=' . $col . '&SET[reverse]=' . ($this->sortRev ? '0' : '1');
666 $sortArrow = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('status-status-sorting-light-' . ($this->sortRev ? 'desc' : 'asc'));
667 } else {
668 $params = '&SET[sort]=' . $col . '&SET[reverse]=0';
669 $sortArrow = '';
670 }
671 $href = \TYPO3\CMS\Core\Utility\GeneralUtility::resolveBackPath(($GLOBALS['BACK_PATH'] . $this->script)) . '&id=' . rawurlencode($folderIdentifier) . $params;
672 return '<a href="' . htmlspecialchars($href) . '">' . $code . $sortArrow . '</a>';
673 }
674
675 /**
676 * Creates the clipboard control pad
677 *
678 * @param \TYPO3\CMS\Core\Resource\File|\TYPO3\CMS\Core\Resource\Folder $fileOrFolderObject Array with information about the file/directory for which to make the clipboard panel for the listing.
679 * @return string HTML-table
680 * @todo Define visibility
681 */
682 public function makeClip($fileOrFolderObject) {
683 $cells = array();
684 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
685 $md5 = \TYPO3\CMS\Core\Utility\GeneralUtility::shortmd5($fullIdentifier);
686 // For normal clipboard, add copy/cut buttons:
687 if ($this->clipObj->current == 'normal') {
688 $isSel = $this->clipObj->isSelected('_FILE', $md5);
689 $cells[] = '<a href="' . htmlspecialchars($this->clipObj->selUrlFile($fullIdentifier, 1, ($isSel == 'copy'))) . '">' . \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>';
690 $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>';
691 } else {
692 // For numeric pads, add select checkboxes:
693 $n = '_FILE|' . $md5;
694 $this->CBnames[] = $n;
695 $checked = $this->clipObj->isSelected('_FILE', $md5) ? ' checked="checked"' : '';
696 $cells[] = '<input type="hidden" name="CBH[' . $n . ']" value="0" />' . '<input type="checkbox" name="CBC[' . $n . ']" value="' . htmlspecialchars($fullIdentifier) . '" class="smallCheckboxes"' . $checked . ' />';
697 }
698 // Display PASTE button, if directory:
699 $elFromTable = $this->clipObj->elFromTable('_FILE');
700 if (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\Folder') && count($elFromTable)) {
701 $cells[] = '<a href="' . htmlspecialchars($this->clipObj->pasteUrl('_FILE', $fullIdentifier)) . '" onclick="return ' . htmlspecialchars($this->clipObj->confirmMsg('_FILE', $fullIdentifier, 'into', $elFromTable)) . '" title="' . $GLOBALS['LANG']->getLL('clip_pasteInto', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-paste-into') . '</a>';
702 }
703 // Compile items into a DIV-element:
704 return ' <!-- CLIPBOARD PANEL: -->
705 <div class="typo3-clipCtrl">
706 ' . implode('
707 ', $cells) . '
708 </div>';
709 }
710
711 /**
712 * Creates the edit control section
713 *
714 * @param \TYPO3\CMS\Core\Resource\File|\TYPO3\CMS\Core\Resource\Folder $fileOrFolderObject Array with information about the file/directory for which to make the edit control section for the listing.
715 * @return string HTML-table
716 * @todo Define visibility
717 */
718 public function makeEdit($fileOrFolderObject) {
719 $cells = array();
720 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
721 // Edit metadata of file
722 try {
723 if (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\File') && $fileOrFolderObject->isIndexed() && $fileOrFolderObject->checkActionPermission('edit')) {
724 $data = array(
725 'sys_file' => array($fileOrFolderObject->getUid() => 'edit')
726 );
727 $editOnClick = \TYPO3\CMS\Backend\Utility\BackendUtility::editOnClick(\TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('edit', $data), $GLOBALS['BACK_PATH'], $this->listUrl());
728 $cells['editmetadata'] = '<a href="#" onclick="' . $editOnClick . '" title="Edit Metadata of this file">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-open') . '</a>';
729 } else {
730 $cells['editmetadata'] = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('empty-empty');
731 }
732 } catch (\Exception $e) {
733 $cells['editmetadata'] = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('empty-empty');
734 }
735 // Edit file content (if editable)
736 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())) {
737 $editOnClick = 'top.content.list_frame.location.href=top.TS.PATH_typo3+\'file_edit.php?target=' . rawurlencode($fullIdentifier) . '&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
738 $cells['edit'] = '<a href="#" onclick="' . $editOnClick . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.edit') . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-page-open') . '</a>';
739 } else {
740 $cells['edit'] = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('empty-empty');
741 }
742 // rename the file
743 if ($fileOrFolderObject->checkActionPermission('rename')) {
744 $renameOnClick = 'top.content.list_frame.location.href = top.TS.PATH_typo3+\'file_rename.php?target=' . rawurlencode($fullIdentifier) . '&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
745 $cells['rename'] = '<a href="#" onclick="' . $renameOnClick . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.rename') . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-edit-rename') . '</a>';
746 } else {
747 $cells['rename'] = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('empty-empty');
748 }
749 if (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\Folder')) {
750 $infoOnClick = 'top.launchView( \'_FOLDER\', \'' . $fullIdentifier . '\');return false;';
751 } elseif (is_a($fileOrFolderObject, 'TYPO3\\CMS\\Core\\Resource\\File')) {
752 $infoOnClick = 'top.launchView( \'_FILE\', \'' . $fullIdentifier . '\');return false;';
753 }
754 $cells['info'] = '<a href="#" onclick="' . $infoOnClick . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.info') . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('status-dialog-information') . '</a>';
755
756 // delete the file
757 if ($fileOrFolderObject->checkActionPermission('remove')) {
758 $identifier = $fileOrFolderObject->getIdentifier();
759 if ($fileOrFolderObject instanceof TYPO3\CMS\Core\Resource\Folder) {
760 $referenceCountText = \TYPO3\CMS\Backend\Utility\BackendUtility::referenceCount('_FILE', $identifier, ' (There are %s reference(s) to this folder!)');
761 } else {
762 $referenceCountText = \TYPO3\CMS\Backend\Utility\BackendUtility::referenceCount('sys_file', $identifier, ' (There are %s reference(s) to this file!)');
763 }
764
765 if ($GLOBALS['BE_USER']->jsConfirmation(4)) {
766 $confirmationCheck = 'confirm(' . $GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.delete'), basename($identifier)) . $referenceCountText) . ')';
767 } else {
768 $confirmationCheck = '1 == 1';
769 }
770
771 $removeOnClick = 'if (' . $confirmationCheck . ') { top.content.list_frame.location.href=top.TS.PATH_typo3+\'tce_file.php?file[delete][0][data]=' . rawurlencode($fileOrFolderObject->getCombinedIdentifier()) . '&vC=' . $GLOBALS['BE_USER']->veriCode() . '&redirect=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);};';
772
773 $cells['delete'] = '<a href="#" onclick="' . htmlspecialchars($removeOnClick) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.delete') . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-edit-delete') . '</a>';
774 } else {
775 $cells['delete'] = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('empty-empty');
776 }
777
778 // Hook for manipulating edit icons.
779 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'])) {
780 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'] as $classData) {
781 $hookObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classData);
782 if (!$hookObject instanceof \TYPO3\CMS\Filelist\FileListEditIconHookInterface) {
783 throw new \UnexpectedValueException(
784 '$hookObject must implement interface \\TYPO3\\CMS\\Filelist\\FileListEditIconHookInterface',
785 1235225797
786 );
787 }
788 $hookObject->manipulateEditIcons($cells, $this);
789 }
790 }
791 // Compile items into a DIV-element:
792 return ' <!-- EDIT CONTROLS: -->
793 <div class="typo3-editCtrl">
794 ' . implode('
795 ', $cells) . '
796 </div>';
797 }
798
799 /**
800 * Make reference count
801 *
802 * @param \TYPO3\CMS\Core\Resource\File|\TYPO3\CMS\Core\Resource\Folder $fileOrFolderObject Array with information about the file/directory for which to make the clipboard panel for the listing.
803 * @return string HTML
804 * @todo Define visibility
805 */
806 public function makeRef($fileOrFolderObject) {
807 if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FolderInterface) {
808 return '-';
809 }
810 // Look up the path:
811 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_refindex', 'ref_table=\'sys_file\' AND ref_uid = ' . (integer)$fileOrFolderObject->getUid() . ' AND deleted=0');
812 return $this->generateReferenceToolTip($rows, '\'_FILE\', ' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($fileOrFolderObject->getCombinedIdentifier()));
813 }
814
815 }
816
817 ?>