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