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