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