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