Fixed bug #10783: Make workspaces icons skinnable
[Packages/TYPO3.CMS.git] / typo3 / class.file_list.inc
1 <?php
2 /***************************************************************
3 *  Copyright notice
4 *
5 *  (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 *  All rights reserved
7 *
8 *  This script is part of the TYPO3 project. The TYPO3 project is
9 *  free software; you can redistribute it and/or modify
10 *  it under the terms of the GNU General Public License as published by
11 *  the Free Software Foundation; either version 2 of the License, or
12 *  (at your option) any later version.
13 *
14 *  The GNU General Public License can be found at
15 *  http://www.gnu.org/copyleft/gpl.html.
16 *  A copy is found in the textfile GPL.txt and important notices to the license
17 *  from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 *  This script is distributed in the hope that it will be useful,
21 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 *  GNU General Public License for more details.
24 *
25 *  This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28  * Include file extending t3lib_recordList
29  *
30  * $Id$
31  * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
32  *
33  * @author      Kasper Skaarhoj <kasperYYYY@typo3.com>
34  */
35 /**
36  * [CLASS/FUNCTION INDEX of SCRIPT]
37  *
38  *
39  *
40  *   75: class fileList extends t3lib_recordList
41  *  112:     function start($path,$pointer,$sort,$sortRev,$clipBoard=0)
42  *  133:     function generateList()
43  *  146:     function writeTop($path)
44  *  204:     function linkClipboardHeaderIcon($string,$table,$cmd,$warning='')
45  *  218:     function getTable($files,$dirs,$rowlist)
46  *  306:     function formatDirList($items)
47  *  372:     function linkWrapDir($code,$path)
48  *  391:     function linkWrapFile($code,$path)
49  *  406:     function listURL()
50  *  416:     function dirData($theFile)
51  *  441:     function formatFileList($items)
52  *  518:     function isImage($ext)
53  *  530:     function linkWrapSort($code,$path,$col)
54  *  548:     function readDirectory($path,$type,$extList='')
55  *  602:     function makeClip($theData)
56  *  647:     function makeRef($theData)
57  *
58  * TOTAL FUNCTIONS: 16
59  * (This index is automatically created/updated by the extension "extdeveval")
60  *
61  */
62
63
64
65
66
67
68 /**
69  * Class for rendering of File>Filelist
70  *
71  * @author      Kasper Skaarhoj <kasperYYYY@typo3.com>
72  * @package TYPO3
73  * @subpackage core
74  */
75 class fileList extends t3lib_recordList {
76         var $iLimit = 40;                                       // default Max items shown
77         var $thumbs = 0;                                        // Boolean. Thumbnails on records containing files (pictures)
78         var $widthGif = '<img src="clear.gif" width="1" height="1" hspace="165" alt="" />';
79         var $fixedL = 30;                                       // Max length of strings
80         var $script = 'file_list.php';
81         var $clickMenus=1;                                      // If true click menus are generated on files and folders
82
83         var $sort = '';                                         // The field to sort by...
84         var $sortRev = 1;                                       // Reverse sorting flag
85         var $firstElementNumber=0;
86         var $clipBoard = 0;
87
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 $dirCounter = 0;
97         var $totalItems='';
98
99         var $CBnames=array();
100
101
102
103         /**
104          * Initialization of class
105          *
106          * @param       string          The path to list
107          * @param       integer         Pointer
108          * @param       boolean         Sorting column
109          * @param       boolean         Sorting direction
110          * @param       boolean         Show clipboard flag
111          * @return      void
112          */
113         function start($path,$pointer,$sort,$sortRev,$clipBoard=0)      {
114                 $this->counter=0;
115                 $this->totalbytes=0;
116                 $this->JScode='';
117                 $this->HTMLcode='';
118                 $this->path = $path;
119                 $this->sort=$sort;
120                 $this->sortRev=$sortRev;
121                 $this->firstElementNumber=$pointer;
122                 $this->clipBoard = $clipBoard;
123                         // setting the maximum length of the filenames to the user's settings or minimum 30 (= $this->fixedL)
124                 $this->fixedL = max($this->fixedL, $GLOBALS['BE_USER']->uc['titleLen']);
125
126                 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'])  {
127                         $this->thumbScript='gfx/notfound_thumb.gif';
128                 }
129                 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_common.xml');
130         }
131
132         /**
133          * Reading files and directories, counting elements and generating the list in ->HTMLcode
134          *
135          * @return      void
136          */
137         function generateList() {
138                 $this->dirs = $this->readDirectory($this->path,'dir,link');
139                 $this->files = $this->readDirectory($this->path,'file');
140                 $this->totalItems=count($this->dirs['sorting'])+count($this->files['sorting']);
141                 $this->HTMLcode.=$this->getTable($this->files, $this->dirs, 'fileext,tstamp,size,rw,_REF_');
142         }
143
144         /**
145          * Return the buttons used by the file list to include in the top header
146          *
147          * @return      array
148          */
149         function getButtonsAndOtherMarkers($path) {
150
151                         // Makes the code for the foldericon in the top
152                 $path = $GLOBALS['SOBE']->basicFF->is_directory($path); // Cleaning name...
153
154                 if ($path)      {
155                         $otherMarkers = array(
156                                 'PAGE_ICON' => '',
157                                 'TITLE' => '',
158                         );
159
160                         $buttons = array(
161                                 'level_up' => '',
162                                 'refresh' => '',
163                                 'title' => '',
164                                 'page_icon' => '',
165                         );
166
167                         $theFile = $GLOBALS['SOBE']->basicFF->getTotalFileInfo($path);
168
169                         list($title,$icon,$path) =  $this->dirData($theFile);
170
171                                 // Start compiling the HTML
172                         $title = $GLOBALS['SOBE']->basicFF->blindPath($path);
173
174                                 // if this is some subpage under the mount root....
175                         if ($GLOBALS['SOBE']->basicFF->checkPathAgainstMounts($theFile['path'])) {
176                                         // The icon with link
177                                 $otherMarkers['PAGE_ICON'] = '<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' title="'.htmlspecialchars($theFile['file']).'" alt="" />';
178                                 if ($this->clickMenus) $otherMarkers['PAGE_ICON'] = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($otherMarkers['PAGE_ICON'],$path);
179
180                                 $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']);
181                                 $otherMarkers['TITLE'] .= t3lib_div::fixed_lgd_cs($title,-($this->fixedL+20));  // No HTML specialchars here - HTML like <b> </b> is allowed
182
183                                 // this is the root page
184                         } else {
185                                 $otherMarkers['PAGE_ICON'] = '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/i/_icon_ftp.gif','width="18" height="16"').' alt="" />';
186                                 if ($this->clickMenus) $otherMarkers['PAGE_ICON'] = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($otherMarkers['PAGE_ICON'],$path);
187                                 $otherMarkers['TITLE'] .= htmlspecialchars(t3lib_div::fixed_lgd_cs($title,-($this->fixedL+20)));
188                         }
189                 }
190
191                 $buttons['refresh'] = '<a href="'.htmlspecialchars($this->listURL()).'">'.
192                                 '<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="" />'.
193                                 '</a>';
194
195                 return array($buttons, $otherMarkers);
196         }
197
198         /**
199          * Wrapping input string in a link with clipboard command.
200          *
201          * @param       string          String to be linked - must be htmlspecialchar'ed / prepared before.
202          * @param       string          table - NOT USED
203          * @param       string          "cmd" value
204          * @param       string          Warning for JS confirm message
205          * @return      string          Linked string
206          */
207         function linkClipboardHeaderIcon($string,$table,$cmd,$warning='')       {
208                 $onClickEvent = 'document.dblistForm.cmd.value=\''.$cmd.'\';document.dblistForm.submit();';
209                 if ($warning)   $onClickEvent = 'if (confirm('.$GLOBALS['LANG']->JScharCode($warning).')){'.$onClickEvent.'}';
210                 return '<a href="#" onclick="'.htmlspecialchars($onClickEvent).'return false;">'.$string.'</a>';
211         }
212
213         /**
214          * Returns a table with directories and files listed.
215          *
216          * @param       array           Array of files from path
217          * @param       array           Array of directories from path
218          * @param       string          List of rows to display horizontallyh
219          * @return      string          HTML-table
220          */
221         function getTable($files,$dirs,$rowlist)        {
222                         // Adds the code of files/dirs
223                 $out='';
224                 $titleCol = 'file';
225
226                         // Cleaning rowlist for duplicates and place the $titleCol as the first column always!
227                 $rowlist = t3lib_div::rmFromList($titleCol,$rowlist);
228                 $rowlist = t3lib_div::uniqueList($rowlist);
229                 $rowlist = $rowlist ? $titleCol.','.$rowlist : $titleCol;
230                 if ($this->clipBoard)   $rowlist.=',_CLIPBOARD_';
231                 $this->fieldArray = explode(',',$rowlist);
232
233                         // Directories are added
234                 $iOut = '';
235                 $iOut.= $this->formatDirList($dirs);
236
237                 if (count($dirs['sorting']))    {
238                                 // half line is drawn
239                         $theData = Array();
240                         $theData[$titleCol] = '';
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="1" 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                 // Folders:
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], $GLOBALS['LANG']->getLL('byteSizeUnits', true));
339                                                         break;
340                                                         case 'rw':
341                                                                 $theData[$field] = (($theFile['readable']) ? '' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('read', true) . '</strong></span>') . (($theFile['writable']) ? '' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('write', true) . '</strong></span>');
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_cs($theFile[$field],$this->fixedL);
360                                                         break;
361                                                 }
362                                         }
363                                         $altRows = 'class="' . ($i++ % 2 == 0 ? 'bgColor6' : 'bgColor4') . '"';
364
365                                         $out .= $this->addelement(1, $theIcon, $theData, $altRows);
366                                 }
367                                 $this->eCounter++;
368                                 $this->dirCounter = $this->eCounter;
369                         }
370                 }
371                 return $out;
372         }
373
374         /**
375          * Wraps the directory-titles
376          *
377          * @param       string          String to be wrapped in links
378          * @param       string          ID (path)
379          * @return      string          HTML
380          */
381         function linkWrapDir($code,$path)       {
382                 $href = $this->script.'?id='.rawurlencode($path);
383                 $onclick = ' onclick="'.htmlspecialchars('top.content.nav_frame.hilight_row("file","folder'.t3lib_div::md5int($path).'_"+top.fsMod.currentBank)').'"';
384
385                         // Sometimes $code contains plain HTML tags. In such a case the string should not be modified!
386                 if(!strcmp($code,strip_tags($code)))    {
387                         return '<a href="'.htmlspecialchars($href).'"'.$onclick.' title="'.htmlspecialchars($code).'">'.t3lib_div::fixed_lgd_cs($code,$this->fixedL).'</a>';
388                 } else  {
389                         return '<a href="'.htmlspecialchars($href).'"'.$onclick.'>'.$code.'</a>';
390                 }
391         }
392
393         /**
394          * Wraps filenames in links which opens them in a window IF they are in web-path.
395          *
396          * @param       string          String to be wrapped in links
397          * @param       string          ID (path)
398          * @return      string          HTML
399          */
400         function linkWrapFile($code,$path)      {
401
402                 if (t3lib_div::isFirstPartOfStr($path,t3lib_div::getIndpEnv('TYPO3_DOCUMENT_ROOT')))    {
403                         $href = substr($path,strlen(t3lib_div::getIndpEnv('TYPO3_DOCUMENT_ROOT')));
404                         $aOnClick = "return top.openUrlInWindow('".$href."','WebFile');";
405                         $code = '<a href="#" title="'.htmlspecialchars($code).'" onclick="'.htmlspecialchars($aOnClick).'">'.t3lib_div::fixed_lgd_cs($code,$this->fixedL).'</a>';
406                 }
407                 return $code;
408         }
409
410         /**
411          * Returns list URL; This is the URL of the current script with id and imagemode parameters, thats all.
412          *
413          * @return      string          URL
414          */
415         function listURL()      {
416                 return $this->script.'?id='.rawurlencode($this->path).'&imagemode='.$this->thumbs;
417         }
418
419         /**
420          * Returns some data specific for the directories...
421          *
422          * @param       array           File information array
423          * @return      array           (title, icon, path)
424          */
425         function dirData($theFile)      {
426                 $path = $theFile['path'] . $theFile['file'] . '/';
427                 $webpath = t3lib_BEfunc::getPathType_web_nonweb($path);
428
429                 $title = htmlspecialchars($theFile['file']);
430                 $icon = 'gfx/i/_icon_' . $webpath . 'folders.gif';
431                 if ($title == '_temp_') {
432                         $icon = 'gfx/i/sysf.gif';
433                         $title = '<strong>' . $GLOBALS['LANG']->getLL('temp', true) . '</strong>';
434                 }
435                 if ($title == '_recycler_')     {
436                         $icon = 'gfx/i/recycler.gif';
437                         $title = '<strong>' . $GLOBALS['LANG']->getLL('recycler', true) . '</strong>';
438                 }
439                 $icon = $theFile['writable'] ? 'gfx/i/_icon_' . $webpath . 'folders_ro.gif' : $icon;
440
441                 return array($title, $icon, $path);
442         }
443
444         /**
445          * This returns tablerows for the files in the array $items['sorting'].
446          *
447          * @param       array           File items
448          * @return      string          HTML table rows.
449          */
450         function formatFileList($items) {
451                 $out='';
452
453                         // Files:
454                 if (count($items['sorting']))   {
455                         reset($items['sorting']);
456                         while (list($key,) = each($items['sorting']))   {
457                                 list($flag,$code) = $this->fwd_rwd_nav();
458                                 $out.=$code;
459                                 if ($flag)      {
460                                                 // Initialization
461                                         $theFile = $items['files'][$key];
462                                         $this->counter++;
463
464                                         $this->totalbytes+=$theFile['size'];
465                                         $ext = $items['files'][$key][fileext];
466                                         $icon = t3lib_BEfunc::getFileIcon($ext);
467
468                                                 // The icon with link
469                                         $theIcon = '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/fileicons/'.$icon,'width="18" height="16"').' title="'.htmlspecialchars($theFile['file']).'" alt="" />';
470                                         if ($this->clickMenus) $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon,$theFile['path'].$theFile['file']);
471
472                                                 //      Preparing and getting the data-array
473                                         $theData = Array();
474                                         reset($this->fieldArray);
475                                         while(list(,$field)=each($this->fieldArray))    {
476                                                 switch($field)  {
477                                                         case 'size':
478                                                                 $theData[$field] = t3lib_div::formatSize($theFile[$field], $GLOBALS['LANG']->getLL('byteSizeUnits', true));
479                                                         break;
480                                                         case 'rw':
481                                                                 $theData[$field] = (($theFile['readable']) ? '' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('read', true) . '</strong></span>') . (($theFile['writable']) ? '' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('write', true) . '</strong></span>');
482                                                         break;
483                                                         case 'fileext':
484                                                                 $theData[$field]=strtoupper($theFile[$field]);
485                                                         break;
486                                                         case 'tstamp':
487                                                                 $theData[$field]=Date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $theFile[$field]);
488                                                         break;
489                                                         case '_CLIPBOARD_':
490                                                                 $theData[$field]=$this->makeClip($theFile);
491                                                         break;
492                                                         case '_REF_':
493                                                                 $theData[$field]=$this->makeRef($theFile);
494                                                         break;
495                                                         case 'file':
496                                                                 $theData[$field] = $this->linkWrapFile($theFile[$field],$theFile['path'].$theFile['file']);
497                                                         break;
498                                                         default:
499                                                                 $theData[$field]=t3lib_div::fixed_lgd_cs($theFile[$field],$this->fixedL);
500                                                         break;
501                                                 }
502                                         }
503                                         if ($this->dirCounter % 2 == 0) {
504                                                 $altRows = 'class="' . ($i++ % 2 == 0 ? 'bgColor6' : 'bgColor4') . '"';
505                                         } else {
506                                                 $altRows = 'class="' . ($i++ % 2 == 0 ? 'bgColor4' : 'bgColor6') . '"';
507                                         }
508
509                                         $out .= $this->addelement(1, $theIcon, $theData, $altRows);
510
511                                                 // Thumbsnails?
512                                         if ($this->thumbs && $this->isImage($theFile['fileext']))       {
513                                                 $thumbData = array();
514                                                 $theFile_R = rawurlencode($theFile['path'].$theFile['file']);
515                                                 $titleCol = $this->fieldArray[0];
516
517                                                 $theFile_abs = $theFile['path'].$theFile['file'];
518                                                 $check = basename($theFile_abs).':'.filemtime($theFile_abs).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
519                                                 $params = '&file='.$theFile_R;
520                                                 $params.= '&md5sum='.t3lib_div::shortMD5($check);
521                                                 $href = $this->backPath.$this->thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
522
523                                                 $thumbData[$titleCol]='<img src="'.htmlspecialchars($href).'" hspace="2" title="'.htmlspecialchars(trim($theFile['file'])).'" alt="" />';
524                                                 $out.= $this->addelement(4,'',$thumbData);
525                                         }
526                                 }
527                                 $this->eCounter++;
528                         }
529                 }
530                 return $out;
531         }
532
533         /**
534          * Returns true if $ext is an image-extension according to $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
535          *
536          * @param       string          file extension
537          * @return      boolean
538          */
539         function isImage($ext)  {
540                 return t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],strtolower($ext));
541         }
542
543         /**
544          * Wraps the directory-titles ($code) in a link to file_list.php (id=$path) and sorting commands...
545          *
546          * @param       string          String to be wrapped
547          * @param       string          ID (path)
548          * @param       string          Sorting column
549          * @return      string          HTML
550          */
551         function linkWrapSort($code,$path,$col) {
552                 if ($this->sort==$col && !$this->sortRev)       {               // reverse sorting
553                         $params='&SET[sort]='.$col.'&SET[reverse]=1';
554                 } else {
555                         $params='&SET[sort]='.$col.'&SET[reverse]=0';
556                 }
557                 $href = $this->script.'?id='.rawurlencode($path).$params;
558                 return '<a href="'.htmlspecialchars($href).'">'.$code.'</a>';
559         }
560
561         /**
562          * Returns an array with file/dir items + an array with the sorted items
563          *
564          * @param       string          Path (absolute) to read
565          * @param       string          $type is the technical type; file,dir,link. empty is all kinds of stuff.
566          * @param       string          $extList: List of fileextensions to select. If empty, all are selected.
567          * @return      array           Array('files'=>array(), 'sorting'=>array());
568          */
569         function readDirectory($path,$type,$extList='') {
570                 $items = Array('files'=>array(), 'sorting'=>array());
571                 $path = $GLOBALS['SOBE']->basicFF->is_directory($path); // Cleaning name...
572
573                 if($path && $GLOBALS['SOBE']->basicFF->checkPathAgainstMounts($path.'/'))       {
574                         $d = @dir($path);
575                         $tempArray=Array();
576                         if (is_object($d))      {
577                                 while(false !== ($entry=$d->read())) {
578                                         if ($entry!='.' && $entry!='..')        {
579                                                 $wholePath = $path.'/'.$entry;          // Because of odd PHP-error where  <br />-tag is sometimes placed after a filename!!
580                                                 if (@file_exists($wholePath) && (!$type || t3lib_div::inList($type,filetype($wholePath))))      {
581                                                         if ($extList)   {
582                                                                 $fI = t3lib_div::split_fileref($entry);
583                                                                 if (t3lib_div::inList($extList,$fI['fileext'])) {
584                                                                         $tempArray[] = $wholePath;
585                                                                 }
586                                                         } else {
587                                                                 $tempArray[] = $wholePath;
588                                                         }
589                                                 }
590                                         }
591                                 }
592                                 $d->close();
593                         }
594                                 // Get fileinfo
595                         reset($tempArray);
596                         while (list(,$val)=each($tempArray))    {
597                                 $temp = $GLOBALS['SOBE']->basicFF->getTotalFileInfo($val);
598                                 $items['files'][] = $temp;
599                                 if ($this->sort)        {
600                                         $items['sorting'][] = strtoupper($temp[$this->sort]);
601                                 } else {
602                                         $items['sorting'][] = '';
603                                 }
604                         }
605                                 // Sort if required
606                         if ($this->sort)        {
607                                 if (!$this->sortRev)    {
608                                         asort($items['sorting']);
609                                 } else {
610                                         arsort($items['sorting']);
611                                 }
612                         }
613                 }
614                 return $items;
615         }
616
617         /**
618          * Creates the clipboard control pad
619          *
620          * @param       array           Array with information about the file/directory for which to make the clipboard panel for the listing.
621          * @return      string          HTML-table
622          */
623         function makeClip($theData)     {
624                 $cells=array();
625                 $fullIdent = $theData['path'].$theData['file'];
626                 $md5=t3lib_div::shortmd5($fullIdent);
627
628                         // For normal clipboard, add copy/cut buttons:
629                 if ($this->clipObj->current=='normal')  {
630                         $isSel = $this->clipObj->isSelected('_FILE',$md5);
631                         $cells[]='<a href="'.htmlspecialchars($this->clipObj->selUrlFile($fullIdent,1,($isSel=='copy'))).'">'.
632                                                 '<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="" />'.
633                                                 '</a>';
634                         $cells[]='<a href="'.htmlspecialchars($this->clipObj->selUrlFile($fullIdent,0,($isSel=='cut'))).'">'.
635                                                 '<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="" />'.
636                                                 '</a>';
637                 } else {        // For numeric pads, add select checkboxes:
638                         $n='_FILE|'.$md5;
639                         $this->CBnames[]=$n;
640
641                         $checked = ($this->clipObj->isSelected('_FILE',$md5)?' checked="checked"':'');
642                         $cells[]='<input type="hidden" name="CBH['.$n.']" value="0" />'.
643                                         '<input type="checkbox" name="CBC['.$n.']" value="'.htmlspecialchars($fullIdent).'" class="smallCheckboxes"'.$checked.' />';
644                 }
645
646                         // Display PASTE button, if directory:
647                 $elFromTable = $this->clipObj->elFromTable('_FILE');
648                 if (@is_dir($fullIdent) && count($elFromTable)) {
649                         $cells[]='<a href="'.htmlspecialchars($this->clipObj->pasteUrl('_FILE',$fullIdent)).'" onclick="return '.htmlspecialchars($this->clipObj->confirmMsg('_FILE',$fullIdent,'into',$elFromTable)).'">'.
650                                                 '<img'.t3lib_iconWorks::skinImg('','gfx/clip_pasteinto.gif','width="12" height="12"').' title="'.$GLOBALS['LANG']->getLL('clip_pasteInto',1).'" alt="" />'.
651                                                 '</a>';
652                 }
653
654                         // Compile items into a DIV-element:
655                 return '                                                        <!-- CLIPBOARD PANEL: -->
656                                                                                         <div class="typo3-clipCtrl">
657                                                                                                 '.implode('
658                                                                                                 ',$cells).'
659                                                                                         </div>';
660         }
661
662         /**
663          * Make reference count
664          *
665          * @param       array           Array with information about the file/directory for which to make the clipboard panel for the listing.
666          * @return      string          HTML
667          */
668         function makeRef($theData)      {
669
670                         // First, fit path to match what is stored in the refindex:
671                 $fullIdent = $theData['path'].$theData['file'];
672
673                 if (t3lib_div::isFirstPartOfStr($fullIdent,PATH_site))  {
674                         $fullIdent = substr($fullIdent,strlen(PATH_site));
675                 }
676
677                         // Look up the path:
678                 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
679                         '*',
680                         'sys_refindex',
681                         'ref_table='.$GLOBALS['TYPO3_DB']->fullQuoteStr('_FILE','sys_refindex').
682                                 ' AND ref_string='.$GLOBALS['TYPO3_DB']->fullQuoteStr($fullIdent,'sys_refindex').
683                                 ' AND deleted=0'
684                 );
685
686                         // Compile information for title tag:
687                 $infoData=array();
688                 if (is_array($rows)) {
689                         foreach($rows as $row)  {
690                                 $infoData[]=$row['tablename'].':'.$row['recuid'].':'.$row['field'];
691                         }
692                 }
693
694                 return count($infoData) ? '<a href="#" onclick="'.htmlspecialchars('top.launchView(\''.$theData['path'].$theData['file'].'\', \'\'); return false;').'" title="'.htmlspecialchars(t3lib_div::fixed_lgd_cs(implode(' / ',$infoData),100)).'">'.count($infoData).'</a>' : '';
695         }
696 }
697
698
699
700 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.file_list.inc'])       {
701         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.file_list.inc']);
702 }
703 ?>