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