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