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