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