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