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