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