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