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