[BUGFIX] Regression: filelistFolderTree constructor is recursive
[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         var $eCounter=0;                                        // Counting the elements no matter what...
69         var $dirCounter = 0;
70         var $totalItems='';
71
72         var $CBnames=array();
73
74
75
76         /**
77          * Initialization of class
78          *
79          * @param       string          The path to list
80          * @param       integer         Pointer
81          * @param       boolean         Sorting column
82          * @param       boolean         Sorting direction
83          * @param       boolean         Show clipboard flag
84          * @return      void
85          */
86         function start($path, $pointer, $sort, $sortRev, $clipBoard=0, $bigControlPanel=0) {
87                 $this->counter=0;
88                 $this->totalbytes=0;
89                 $this->JScode='';
90                 $this->HTMLcode='';
91                 $this->path = $path;
92                 $this->sort=$sort;
93                 $this->sortRev=$sortRev;
94                 $this->firstElementNumber=$pointer;
95                 $this->clipBoard = $clipBoard;
96                 $this->bigControlPanel = $bigControlPanel;
97                         // setting the maximum length of the filenames to the user's settings or minimum 30 (= $this->fixedL)
98                 $this->fixedL = max($this->fixedL, $GLOBALS['BE_USER']->uc['titleLen']);
99
100                 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'])  {
101                         $this->thumbScript='gfx/notfound_thumb.gif';
102                 }
103                 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_common.xml');
104         }
105
106         /**
107          * Reading files and directories, counting elements and generating the list in ->HTMLcode
108          *
109          * @return      void
110          */
111         function generateList() {
112                 $this->dirs = $this->readDirectory($this->path,'dir,link');
113                 $this->files = $this->readDirectory($this->path,'file');
114                 $this->totalItems=count($this->dirs['sorting'])+count($this->files['sorting']);
115                 $this->HTMLcode.=$this->getTable($this->files, $this->dirs, 'fileext,tstamp,size,rw,_REF_');
116         }
117
118         /**
119          * Return the buttons used by the file list to include in the top header
120          *
121          * @return      array
122          */
123         function getButtonsAndOtherMarkers($path) {
124
125                         // Makes the code for the foldericon in the top
126                 $path = $GLOBALS['SOBE']->basicFF->is_directory($path); // Cleaning name...
127
128                 if ($path)      {
129                         $otherMarkers = array(
130                                 'PAGE_ICON' => '',
131                                 'TITLE' => '',
132                         );
133
134                         $buttons = array(
135                                 'level_up' => '',
136                                 'refresh' => '',
137                                 'title' => '',
138                                 'page_icon' => '',
139                         );
140
141                         $theFile = $GLOBALS['SOBE']->basicFF->getTotalFileInfo($path);
142
143                         list($title,$icon,$path) =  $this->dirData($theFile);
144
145                                 // Start compiling the HTML
146                         $title = $GLOBALS['SOBE']->basicFF->blindPath($path);
147
148                                 // if this is some subpage under the mount root....
149                         if ($GLOBALS['SOBE']->basicFF->checkPathAgainstMounts($theFile['path'])) {
150                                         // The icon with link
151                                 $otherMarkers['PAGE_ICON'] = '<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' title="'.htmlspecialchars($theFile['file']).'" alt="'.htmlspecialchars($theFile['file']).'" />';
152                                 if ($this->clickMenus) $otherMarkers['PAGE_ICON'] = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($otherMarkers['PAGE_ICON'],$path);
153
154                                 $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))), $theFile['path']);
155                                 $otherMarkers['TITLE'] .= t3lib_div::removeXSS(t3lib_div::fixed_lgd_cs($title,-($this->fixedL+20)));    // No HTML specialchars here - HTML like <strong> </strong> is allowed
156
157                                 // this is the root page
158                         } else {
159                                 $otherMarkers['PAGE_ICON'] = t3lib_iconWorks::getSpriteIcon('apps-filetree-root');
160                                 if ($this->clickMenus) $otherMarkers['PAGE_ICON'] = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($otherMarkers['PAGE_ICON'],$path);
161                                 $otherMarkers['TITLE'] .= htmlspecialchars(t3lib_div::fixed_lgd_cs($title,-($this->fixedL+20)));
162                         }
163                 }
164
165                 $buttons['refresh'] = '<a href="'.htmlspecialchars($this->listURL()).'" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.reload', 1) . '">'.
166                                 t3lib_iconWorks::getSpriteIcon('actions-system-refresh')  .
167                         '</a>';
168
169                 return array($buttons, $otherMarkers);
170         }
171
172         /**
173          * Wrapping input string in a link with clipboard command.
174          *
175          * @param       string          String to be linked - must be htmlspecialchar'ed / prepared before.
176          * @param       string          table - NOT USED
177          * @param       string          "cmd" value
178          * @param       string          Warning for JS confirm message
179          * @return      string          Linked string
180          */
181         function linkClipboardHeaderIcon($string,$table,$cmd,$warning='')       {
182                 $onClickEvent = 'document.dblistForm.cmd.value=\''.$cmd.'\';document.dblistForm.submit();';
183                 if ($warning)   $onClickEvent = 'if (confirm('.$GLOBALS['LANG']->JScharCode($warning).')){'.$onClickEvent.'}';
184                 return '<a href="#" onclick="'.htmlspecialchars($onClickEvent).'return false;">'.$string.'</a>';
185         }
186
187         /**
188          * Returns a table with directories and files listed.
189          *
190          * @param       array           Array of files from path
191          * @param       array           Array of directories from path
192          * @param       string          List of rows to display horizontallyh
193          * @return      string          HTML-table
194          */
195         function getTable($files,$dirs,$rowlist)        {
196                         // Adds the code of files/dirs
197                 $out='';
198                 $titleCol = 'file';
199                 $upLevelDir = dirname(substr($files['files'][0]['path'], 0, -1)) . '/';
200                 $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) : '';
201
202                         // Cleaning rowlist for duplicates and place the $titleCol as the first column always!
203                 $rowlist = t3lib_div::rmFromList($titleCol,$rowlist);
204                 $rowlist = t3lib_div::uniqueList($rowlist);
205                 $rowlist = $rowlist ? $titleCol.','.$rowlist : $titleCol;
206                 if ($this->bigControlPanel || $this->clipBoard) {
207                         $rowlist = str_replace('file,', 'file,_CLIPBOARD_,', $rowlist);
208                 }
209                 $this->fieldArray = explode(',',$rowlist);
210
211                         // Directories are added
212                 $iOut = '';
213                 $iOut.= $this->formatDirList($dirs);
214
215                 if (count($dirs['sorting']))    {
216                                 // half line is drawn
217                         $theData = Array();
218                         $theData[$titleCol] = '';
219                 }
220
221
222
223                         // Files are added
224                 $iOut.= $this->formatFileList($files,$titleCol);
225
226                         // Header line is drawn
227                 $theData = Array();
228
229                 foreach ($this->fieldArray as $v)       {
230                         if ($v == '_CLIPBOARD_' && $this->clipBoard) {
231                                 $cells=array();
232                                 $table='_FILE';
233                                 $elFromTable = $this->clipObj->elFromTable($table);
234                                 if (count($elFromTable))        {
235                                         $cells[]='<a href="'.htmlspecialchars($this->clipObj->pasteUrl('_FILE',$this->path)).'" onclick="return '.htmlspecialchars($this->clipObj->confirmMsg('_FILE',$this->path,'into',$elFromTable)).'" title="' . $GLOBALS['LANG']->getLL('clip_paste', 1) . '">' .
236                                                 t3lib_iconWorks::getSpriteIcon('actions-document-paste-after') .
237                                         '</a>';
238                                 }
239                                 if ($this->clipObj->current!='normal' && $iOut) {
240                                         $cells[]=$this->linkClipboardHeaderIcon(t3lib_iconWorks::getSpriteIcon('actions-edit-copy', array('title' => $GLOBALS['LANG']->getLL('clip_selectMarked', 1))), $table,'setCB');
241                                         $cells[]=$this->linkClipboardHeaderIcon(t3lib_iconWorks::getSpriteIcon('actions-edit-delete', array('title' => $GLOBALS['LANG']->getLL('clip_deleteMarked'))), $table,'delete',$GLOBALS['LANG']->getLL('clip_deleteMarkedWarning'));
242                                         $onClick = 'checkOffCB(\'' . implode(',', $this->CBnames) . '\', this); return false;';
243                                         $cells[] = '<a class="cbcCheckAll" rel="" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $GLOBALS['LANG']->getLL('clip_markRecords', TRUE) . '">' .
244                                                         t3lib_iconWorks::getSpriteIcon('actions-document-select').
245                                                 '</a>';
246                                 }
247                                 $theData[$v] = implode('',$cells);
248                         } else {        // Normal row:
249                                 $theT = $this->linkWrapSort($GLOBALS['LANG']->getLL('c_'.$v,1), $this->path,$v);
250                                 $theData[$v] = $theT;
251                         }
252                 }
253                 $out .= '<thead>' . $this->addelement(1, $levelUp, $theData, ' class="t3-row-header"', '') . '</thead>';
254                 $out .= '<tbody>' . $iOut . '</tbody>';
255
256                         // half line is drawn
257
258                         // finish
259                 return '
260
261
262                 <!--
263                         File list table:
264                 -->
265                         <table cellpadding="0" cellspacing="0" id="typo3-filelist">
266                                 '.$out.'
267                         </table>';
268         }
269
270         /**
271          * Gets the number of files and total size of a folder
272          *
273          * @return string
274          **/
275         function getFolderInfo() {
276                 if($this->counter == 1) {
277                         $fileLabel = $GLOBALS['LANG']->getLL('file', TRUE);
278                 } else {
279                         $fileLabel = $GLOBALS['LANG']->getLL('files', TRUE);
280                 }
281                 return $this->counter . ' ' . $fileLabel . ', ' . t3lib_div::formatSize($this->totalbytes, $GLOBALS['LANG']->getLL('byteSizeUnits', TRUE));
282         }
283
284         /**
285          * This returns tablerows for the directories in the array $items['sorting'].
286          *
287          * @param       array           Directory items
288          * @return      string          HTML table rows.
289          */
290         function formatDirList($items)  {
291                 $out='';
292
293                 // Folders:
294                 if (count($items['sorting']))   {
295                         foreach ($items['sorting'] as $key => $value) {
296                                 list($flag,$code) = $this->fwd_rwd_nav();
297                                 $out.=$code;
298                                 if ($flag)      {
299                                                 // Initialization
300                                         $theFile = $items['files'][$key];
301                                         $this->counter++;
302
303                                         list($title,$icon,$path) =  $this->dirData($theFile);
304
305                                                 // The icon with link
306                                         $theIcon = t3lib_iconWorks::getSpriteIconForFile( ($theFile['type'] == 'dir' ? 'folder' : $theFile['fileext']), array('title' => htmlspecialchars($theFile['file'])));
307                                         if ($this->clickMenus) $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon,$path);
308
309                                                 //      Preparing and getting the data-array
310                                         $theData = Array();
311                                         foreach ($this->fieldArray as $field) {
312                                                 switch($field)  {
313                                                         case 'size':
314                                                                 $theData[$field] = t3lib_div::formatSize($theFile[$field], $GLOBALS['LANG']->getLL('byteSizeUnits', TRUE));
315                                                         break;
316                                                         case 'rw':
317                                                                 $theData[$field] = (($theFile['readable']) ? '' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('read', TRUE) . '</strong></span>') . (($theFile['writable']) ? '' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('write', TRUE) . '</strong></span>');
318                                                         break;
319                                                         case 'fileext':
320                                                                 $theData[$field]=strtoupper($theFile['fileext']);
321                                                         break;
322                                                         case 'tstamp':
323                                                                 $theData[$field]=Date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $theFile['tstamp']);
324                                                         break;
325                                                         case 'file':
326                                                                 $theData[$field]= $this->linkWrapDir($title,$path);
327                                                         break;
328                                                         case '_CLIPBOARD_':
329                                                                 $temp = '';
330                                                                 if ($this->bigControlPanel) {
331                                                                         $temp .= $this->makeEdit($theFile);
332                                                                 }
333                                                                 $temp .= $this->makeClip($theFile);
334                                                                 $theData[$field] = $temp;
335                                                         break;
336                                                         case '_REF_':
337                                                                 $theData[$field]=$this->makeRef($theFile);
338                                                         break;
339                                                         default:
340                                                                 $theData[$field]=t3lib_div::fixed_lgd_cs($theFile[$field],$this->fixedL);
341                                                         break;
342                                                 }
343                                         }
344                                         $altRows = 'class="' . ($i++ % 2 == 0 ? 'bgColor6' : 'bgColor4') . '"';
345
346                                         $out .= $this->addelement(1, $theIcon, $theData, $altRows);
347                                 }
348                                 $this->eCounter++;
349                                 $this->dirCounter = $this->eCounter;
350                         }
351                 }
352                 return $out;
353         }
354
355         /**
356          * Wraps the directory-titles
357          *
358          * @param       string          String to be wrapped in links
359          * @param       string          ID (path)
360          * @return      string          HTML
361          */
362         function linkWrapDir($code,$path)       {
363                 $href = $this->script.'?id='.rawurlencode($path);
364                 $onclick = ' onclick="'.htmlspecialchars('top.content.nav_frame.hilight_row("file","folder'.t3lib_div::md5int($path).'_"+top.fsMod.currentBank)').'"';
365
366                         // Sometimes $code contains plain HTML tags. In such a case the string should not be modified!
367                 if(!strcmp($code,strip_tags($code)))    {
368                         return '<a href="'.htmlspecialchars($href).'"'.$onclick.' title="'.htmlspecialchars($code).'">'.t3lib_div::fixed_lgd_cs($code,$this->fixedL).'</a>';
369                 } else  {
370                         return '<a href="'.htmlspecialchars($href).'"'.$onclick.'>'.$code.'</a>';
371                 }
372         }
373
374         /**
375          * Wraps filenames in links which opens them in a window IF they are in web-path.
376          *
377          * @param       string          String to be wrapped in links
378          * @param       string          ID (path)
379          * @return      string          HTML
380          */
381         function linkWrapFile($code,$path)      {
382
383                 if (t3lib_div::isFirstPartOfStr($path, PATH_site)) {
384                         $href = t3lib_div::getIndpEnv('TYPO3_SITE_URL') . substr($path, strlen(PATH_site));
385                         $aOnClick = "return top.openUrlInWindow('".$href."','WebFile');";
386                         $code = '<a href="#" title="'.htmlspecialchars($code).'" onclick="'.htmlspecialchars($aOnClick).'">'.t3lib_div::fixed_lgd_cs($code,$this->fixedL).'</a>';
387                 }
388                 return $code;
389         }
390
391         /**
392          * Returns list URL; This is the URL of the current script with id and imagemode parameters, thats all.
393          *
394          * @return      string          URL
395          */
396         function listURL()      {
397                 return $this->script.'?id='.rawurlencode($this->path).'&imagemode='.$this->thumbs;
398         }
399
400         /**
401          * Returns some data specific for the directories...
402          *
403          * @param       array           File information array
404          * @return      array           (title, icon, path)
405          */
406         function dirData($theFile)      {
407                 $path = $theFile['path'] . $theFile['file'] . '/';
408                 $webpath = t3lib_BEfunc::getPathType_web_nonweb($path);
409
410                 $title = htmlspecialchars($theFile['file']);
411                 $icon = 'gfx/i/_icon_' . $webpath . 'folders.gif';
412                 if ($title == '_temp_') {
413                         $icon = 'gfx/i/sysf.gif';
414                         $title = '<strong>' . $GLOBALS['LANG']->getLL('temp', TRUE) . '</strong>';
415                 }
416                 if ($title == '_recycler_')     {
417                         $icon = 'gfx/i/recycler.gif';
418                         $title = '<strong>' . $GLOBALS['LANG']->getLL('recycler', TRUE) . '</strong>';
419                 }
420                 $icon = $theFile['writable'] ? 'gfx/i/_icon_' . $webpath . 'folders_ro.gif' : $icon;
421
422                 return array($title, $icon, $path);
423         }
424
425         /**
426          * This returns tablerows for the files in the array $items['sorting'].
427          *
428          * @param       array           File items
429          * @return      string          HTML table rows.
430          */
431         function formatFileList($items) {
432                 $out='';
433
434                         // Files:
435                 if (count($items['sorting']))   {
436                         foreach ($items['sorting'] as $key => $value) {
437                                 list($flag,$code) = $this->fwd_rwd_nav();
438                                 $out.=$code;
439                                 if ($flag)      {
440                                                 // Initialization
441                                         $theFile = $items['files'][$key];
442                                         $this->counter++;
443
444                                         $this->totalbytes+=$theFile['size'];
445                                         $ext = $items['files'][$key][fileext];
446                                         $icon = t3lib_BEfunc::getFileIcon($ext);
447
448                                                 // The icon with link
449                                         $theIcon = t3lib_iconWorks::getSpriteIconForFile($theFile['fileext'], array('title' => htmlspecialchars($theFile['file'])));
450
451                                         if ($this->clickMenus) $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon,$theFile['path'].$theFile['file']);
452
453                                                 //      Preparing and getting the data-array
454                                         $theData = Array();
455                                         foreach ($this->fieldArray as $field) {
456                                                 switch($field)  {
457                                                         case 'size':
458                                                                 $theData[$field] = t3lib_div::formatSize($theFile[$field], $GLOBALS['LANG']->getLL('byteSizeUnits', TRUE));
459                                                         break;
460                                                         case 'rw':
461                                                                 $theData[$field] = (($theFile['readable']) ? '' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('read', TRUE) . '</strong></span>') . (($theFile['writable']) ? '' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('write', TRUE) . '</strong></span>');
462                                                         break;
463                                                         case 'fileext':
464                                                                 $theData[$field]=strtoupper($theFile[$field]);
465                                                         break;
466                                                         case 'tstamp':
467                                                                 $theData[$field]=Date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $theFile[$field]);
468                                                         break;
469                                                         case '_CLIPBOARD_':
470                                                                 $temp = '';
471                                                                 if ($this->bigControlPanel) {
472                                                                         $temp .= $this->makeEdit($theFile);
473                                                                 }
474                                                                 $temp .= $this->makeClip($theFile);
475                                                                 $theData[$field] = $temp;
476                                                         break;
477                                                         case '_REF_':
478                                                                 $theData[$field]=$this->makeRef($theFile);
479                                                         break;
480                                                         case 'file':
481                                                                 $theData[$field] = $this->linkWrapFile($theFile[$field],$theFile['path'].$theFile['file']);
482                                                                         // Thumbsnails?
483                                                                 if ($this->thumbs && $this->isImage($theFile['fileext']))       {
484                                                                         $thumbData = array();
485                                                                         $theFile_R = rawurlencode($theFile['path'].$theFile['file']);
486                                                                         $titleCol = $this->fieldArray[0];
487
488                                                                         $theFile_abs = $theFile['path'].$theFile['file'];
489                                                                         $check = basename($theFile_abs).':'.filemtime($theFile_abs).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
490                                                                         $params = '&file='.$theFile_R;
491                                                                         $params.= '&md5sum='.t3lib_div::shortMD5($check);
492                                                                         $href = $this->backPath.$this->thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
493
494                                                                         $theData[$field] .= '<br /><img src="'.htmlspecialchars($href).'" hspace="2" title="'.htmlspecialchars(trim($theFile['file'])).'" alt="'.htmlspecialchars(trim($theFile['file'])).'" />';
495                                                                 }
496                                                         break;
497                                                         default:
498                                                                 $theData[$field]=t3lib_div::fixed_lgd_cs($theFile[$field],$this->fixedL);
499                                                         break;
500                                                 }
501                                         }
502                                         if ($this->dirCounter % 2 == 0) {
503                                                 $altRows = 'class="' . ($i++ % 2 == 0 ? 'bgColor6' : 'bgColor4') . '"';
504                                         } else {
505                                                 $altRows = 'class="' . ($i++ % 2 == 0 ? 'bgColor4' : 'bgColor6') . '"';
506                                         }
507
508                                         $out .= $this->addelement(1, $theIcon, $theData, $altRows);
509                                 }
510                                 $this->eCounter++;
511                         }
512                 }
513                 return $out;
514         }
515
516         /**
517          * Returns TRUE if $ext is an image-extension according to $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
518          *
519          * @param       string          file extension
520          * @return      boolean
521          */
522         function isImage($ext)  {
523                 return t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],strtolower($ext));
524         }
525
526         /**
527          * Wraps the directory-titles ($code) in a link to file_list.php (id=$path) and sorting commands...
528          *
529          * @param       string          String to be wrapped
530          * @param       string          ID (path)
531          * @param       string          Sorting column
532          * @return      string          HTML
533          */
534         function linkWrapSort($code,$path,$col) {
535                 if ($this->sort==$col && !$this->sortRev)       {               // reverse sorting
536                         $params='&SET[sort]='.$col.'&SET[reverse]=1';
537                 } else {
538                         $params='&SET[sort]='.$col.'&SET[reverse]=0';
539                 }
540                 $href = $GLOBALS['BACK_PATH'] . t3lib_extMgm::extRelPath('filelist') . 'mod1/' . $this->script . '?id=' . rawurlencode($path) . $params;
541                 return '<a href="'.htmlspecialchars($href).'">'.$code.'</a>';
542         }
543
544         /**
545          * Returns an array with file/dir items + an array with the sorted items
546          *
547          * @param       string          Path (absolute) to read
548          * @param       string          $type is the technical type; file,dir,link. empty is all kinds of stuff.
549          * @param       string          $extList: List of fileextensions to select. If empty, all are selected.
550          * @return      array           Array('files'=>array(), 'sorting'=>array());
551          */
552         function readDirectory($path,$type,$extList='') {
553                 $items = Array('files'=>array(), 'sorting'=>array());
554                 $path = $GLOBALS['SOBE']->basicFF->is_directory($path); // Cleaning name...
555
556                 if($path && $GLOBALS['SOBE']->basicFF->checkPathAgainstMounts($path.'/'))       {
557                         $d = @dir($path);
558                         $tempArray=Array();
559                         if (is_object($d))      {
560                                 while(FALSE !== ($entry=$d->read())) {
561                                         if ($entry!='.' && $entry!='..')        {
562                                                 $wholePath = $path.'/'.$entry;          // Because of odd PHP-error where  <br />-tag is sometimes placed after a filename!!
563                                                 if (@file_exists($wholePath) && (!$type || t3lib_div::inList($type,filetype($wholePath))))      {
564                                                         if ($extList)   {
565                                                                 $fI = t3lib_div::split_fileref($entry);
566                                                                 if (t3lib_div::inList($extList,$fI['fileext'])) {
567                                                                         $tempArray[] = $wholePath;
568                                                                 }
569                                                         } else {
570                                                                 $tempArray[] = $wholePath;
571                                                         }
572                                                 }
573                                         }
574                                 }
575                                 $d->close();
576                         }
577                                 // Get fileinfo
578                         foreach ($tempArray as $val) {
579                                 $temp = $GLOBALS['SOBE']->basicFF->getTotalFileInfo($val);
580                                 $items['files'][] = $temp;
581                                 if ($this->sort)        {
582                                         $items['sorting'][] = strtoupper($temp[$this->sort]);
583                                 } else {
584                                         $items['sorting'][] = '';
585                                 }
586                         }
587                                 // Sort if required
588                         if ($this->sort)        {
589                                 if (!$this->sortRev)    {
590                                         asort($items['sorting']);
591                                 } else {
592                                         arsort($items['sorting']);
593                                 }
594                         }
595                 }
596                 return $items;
597         }
598
599         /**
600          * Creates the clipboard control pad
601          *
602          * @param       array           Array with information about the file/directory for which to make the clipboard panel for the listing.
603          * @return      string          HTML-table
604          */
605         function makeClip($theData)     {
606                 $cells=array();
607                 $fullIdent = $theData['path'].$theData['file'];
608                 $md5=t3lib_div::shortmd5($fullIdent);
609
610                         // For normal clipboard, add copy/cut buttons:
611                 if ($this->clipObj->current=='normal')  {
612                         $isSel = $this->clipObj->isSelected('_FILE',$md5);
613                         $cells[]='<a href="'.htmlspecialchars($this->clipObj->selUrlFile($fullIdent,1,($isSel=='copy'))).'">'.
614                                                 t3lib_iconWorks::getSpriteIcon('actions-edit-copy'.($isSel=='copy'?'-release':''),array('title'=>$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:cm.copy',1))).
615                                                 '</a>';
616                         $cells[]='<a href="'.htmlspecialchars($this->clipObj->selUrlFile($fullIdent,0,($isSel=='cut'))).'">'.
617                                                 t3lib_iconWorks::getSpriteIcon('actions-edit-cut'.($isSel=='cut'?'-release':''),array('title'=>$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:cm.cut',1))).
618                                                 '</a>';
619                 } else {        // For numeric pads, add select checkboxes:
620                         $n='_FILE|'.$md5;
621                         $this->CBnames[]=$n;
622
623                         $checked = ($this->clipObj->isSelected('_FILE',$md5)?' checked="checked"':'');
624                         $cells[]='<input type="hidden" name="CBH['.$n.']" value="0" />'.
625                                         '<input type="checkbox" name="CBC['.$n.']" value="'.htmlspecialchars($fullIdent).'" class="smallCheckboxes"'.$checked.' />';
626                 }
627
628                         // Display PASTE button, if directory:
629                 $elFromTable = $this->clipObj->elFromTable('_FILE');
630                 if (@is_dir($fullIdent) && count($elFromTable)) {
631                         $cells[]='<a href="'.htmlspecialchars($this->clipObj->pasteUrl('_FILE',$fullIdent)).'" onclick="return '.htmlspecialchars($this->clipObj->confirmMsg('_FILE',$fullIdent,'into',$elFromTable)).'" title="' . $GLOBALS['LANG']->getLL('clip_pasteInto', TRUE) . '">'.
632                           t3lib_iconWorks::getSpriteIcon('actions-document-paste-into') .
633                         '</a>';
634                 }
635
636                         // Compile items into a DIV-element:
637                 return '                                                        <!-- CLIPBOARD PANEL: -->
638                                                                                         <div class="typo3-clipCtrl">
639                                                                                                 '.implode('
640                                                                                                 ',$cells).'
641                                                                                         </div>';
642         }
643
644         /**
645         * Creates the edit control section
646         *
647         * @param        array           Array with information about the file/directory for which to make the edit control section for the listing.
648         * @return       string          HTML-table
649         */
650         function makeEdit($theData) {
651                 $cells = array();
652                 $fullIdent = $theData['path'].$theData['file'];
653                 $canEdit = t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $theData['realFileext']);
654
655                         // prepare space icon
656                 $iconWidth  = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['iconSizeWidth']  ? $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['iconSizeWidth']  : 12;
657                 $iconHeight = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['iconSizeHeight'] ? $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['iconSizeHeight'] : 12;
658                 $spaceIcon = '<img src="' . $this->backPath . 'clear.gif" width="' . $iconWidth . '" height="' . $iconHeight . '" title="" alt="" />';
659
660
661                         //edit
662                 if ($theData['type'] == 'dir' || !$canEdit) {
663                         $cells['edit'] = $spaceIcon;
664                 } else {
665                         $editOnClick = 'top.content.list_frame.location.href=top.TS.PATH_typo3+\'file_edit.php?target=' .
666                                 rawurlencode($fullIdent) .
667                                 '&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
668                         $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>';
669                 }
670                         //rename
671                 $renameOnClick = 'top.content.list_frame.location.href=top.TS.PATH_typo3+\'file_rename.php?target=' .
672                         rawurlencode($fullIdent) .
673                         '&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
674
675                 $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>';
676
677                         //info
678                 $infoOnClick = 'top.launchView(\'' . $fullIdent . '\', \'\');return false;';
679                 $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>';
680
681                         // Hook for manipulating edit icons.
682                 if(is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'])) {
683                         foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'] as $classData) {
684                                 $hookObject = t3lib_div::getUserObj($classData);
685
686                                 if(!($hookObject instanceof fileList_editIconHook)) {
687                                         throw new UnexpectedValueException('$hookObject must implement interface fileList_editIconHook', 1235225797);
688                                 }
689
690                                 $hookObject->manipulateEditIcons($cells, $this);
691                         }
692                 }
693
694                         // Compile items into a DIV-element:
695                 return '                                                        <!-- EDIT CONTROLS: -->
696                                                                                         <div class="typo3-editCtrl">
697                                                                                                 ' . implode('
698                                                                                                 ', $cells).'
699                                                                                         </div>';
700         }
701
702         /**
703          * Make reference count
704          *
705          * @param       array           Array with information about the file/directory for which to make the clipboard panel for the listing.
706          * @return      string          HTML
707          */
708         function makeRef($theData)      {
709
710                         // First, fit path to match what is stored in the refindex:
711                 $fullIdent = $theData['path'].$theData['file'];
712
713                 if (t3lib_div::isFirstPartOfStr($fullIdent,PATH_site))  {
714                         $fullIdent = substr($fullIdent,strlen(PATH_site));
715                 }
716
717                         // Look up the path:
718                 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
719                         '*',
720                         'sys_refindex',
721                         'ref_table='.$GLOBALS['TYPO3_DB']->fullQuoteStr('_FILE','sys_refindex').
722                                 ' AND ref_string='.$GLOBALS['TYPO3_DB']->fullQuoteStr($fullIdent,'sys_refindex').
723                                 ' AND deleted=0'
724                 );
725
726                         // Compile information for title tag:
727                 $infoData=array();
728                 if (is_array($rows)) {
729                         foreach($rows as $row)  {
730                                 $infoData[]=$row['tablename'].':'.$row['recuid'].':'.$row['field'];
731                         }
732                 }
733
734                 return count($infoData) ? '<a href="#" onclick="'.htmlspecialchars('top.launchView(\''.$theData['path'].$theData['file'].'\', \'\'); return false;').'" title="'.htmlspecialchars(t3lib_div::fixed_lgd_cs(implode(' / ',$infoData),100)).'">'.count($infoData).'</a>' : '';
735         }
736 }
737
738
739
740 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/class.file_list.inc'])) {
741         include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/class.file_list.inc']);
742 }
743 ?>