[BUGFIX] Pootle: Multi-line labels are not rendered properly
[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]=Date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $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]=Date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $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).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
489                                                                         $params = '&file='.$theFile_R;
490                                                                         $params.= '&md5sum='.t3lib_div::shortMD5($check);
491                                                                         $href = $this->backPath.$this->thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
492
493                                                                         $theData[$field] .= '<br /><img src="'.htmlspecialchars($href).'" hspace="2" title="'.htmlspecialchars(trim($theFile['file'])).'" alt="'.htmlspecialchars(trim($theFile['file'])).'" />';
494                                                                 }
495                                                         break;
496                                                         default:
497                                                                 $theData[$field]=t3lib_div::fixed_lgd_cs($theFile[$field],$this->fixedL);
498                                                         break;
499                                                 }
500                                         }
501
502                                         $out .= $this->addelement(1, $theIcon, $theData, ' class="file_list_normal"');
503                                 }
504                                 $this->eCounter++;
505                         }
506                 }
507                 return $out;
508         }
509
510         /**
511          * Returns TRUE if $ext is an image-extension according to $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
512          *
513          * @param       string          file extension
514          * @return      boolean
515          */
516         function isImage($ext)  {
517                 return t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],strtolower($ext));
518         }
519
520         /**
521          * Wraps the directory-titles ($code) in a link to file_list.php (id=$path) and sorting commands...
522          *
523          * @param       string          String to be wrapped
524          * @param       string          ID (path)
525          * @param       string          Sorting column
526          * @return      string          HTML
527          */
528         function linkWrapSort($code,$path,$col) {
529                 if ($this->sort==$col && !$this->sortRev)       {               // reverse sorting
530                         $params='&SET[sort]='.$col.'&SET[reverse]=1';
531                 } else {
532                         $params='&SET[sort]='.$col.'&SET[reverse]=0';
533                 }
534                 $href = $GLOBALS['BACK_PATH'] . t3lib_extMgm::extRelPath('filelist') . 'mod1/' . $this->script . '?id=' . rawurlencode($path) . $params;
535                 return '<a href="'.htmlspecialchars($href).'">'.$code.'</a>';
536         }
537
538         /**
539          * Returns an array with file/dir items + an array with the sorted items
540          *
541          * @param       string          Path (absolute) to read
542          * @param       string          $type is the technical type; file,dir,link. empty is all kinds of stuff.
543          * @param       string          $extList: List of fileextensions to select. If empty, all are selected.
544          * @return      array           Array('files'=>array(), 'sorting'=>array());
545          */
546         function readDirectory($path,$type,$extList='') {
547                 $items = Array('files'=>array(), 'sorting'=>array());
548                 $path = $GLOBALS['SOBE']->basicFF->is_directory($path); // Cleaning name...
549
550                 if($path && $GLOBALS['SOBE']->basicFF->checkPathAgainstMounts($path.'/'))       {
551                         $d = @dir($path);
552                         $tempArray=Array();
553                         if (is_object($d))      {
554                                 while(FALSE !== ($entry=$d->read())) {
555                                         if ($entry!='.' && $entry!='..')        {
556                                                 $wholePath = $path.'/'.$entry;          // Because of odd PHP-error where  <br />-tag is sometimes placed after a filename!!
557                                                 if (@file_exists($wholePath) && (!$type || t3lib_div::inList($type,filetype($wholePath))))      {
558                                                         if ($extList)   {
559                                                                 $fI = t3lib_div::split_fileref($entry);
560                                                                 if (t3lib_div::inList($extList,$fI['fileext'])) {
561                                                                         $tempArray[] = $wholePath;
562                                                                 }
563                                                         } else {
564                                                                 $tempArray[] = $wholePath;
565                                                         }
566                                                 }
567                                         }
568                                 }
569                                 $d->close();
570                         }
571                                 // Get fileinfo
572                         foreach ($tempArray as $val) {
573                                 $temp = $GLOBALS['SOBE']->basicFF->getTotalFileInfo($val);
574                                 $items['files'][] = $temp;
575                                 if ($this->sort)        {
576                                         $items['sorting'][] = strtoupper($temp[$this->sort]);
577                                 } else {
578                                         $items['sorting'][] = '';
579                                 }
580                         }
581                                 // Sort if required
582                         if ($this->sort)        {
583                                 if (!$this->sortRev)    {
584                                         asort($items['sorting']);
585                                 } else {
586                                         arsort($items['sorting']);
587                                 }
588                         }
589                 }
590                 return $items;
591         }
592
593         /**
594          * Creates the clipboard control pad
595          *
596          * @param       array           Array with information about the file/directory for which to make the clipboard panel for the listing.
597          * @return      string          HTML-table
598          */
599         function makeClip($theData)     {
600                 $cells=array();
601                 $fullIdent = $theData['path'].$theData['file'];
602                 $md5=t3lib_div::shortmd5($fullIdent);
603
604                         // For normal clipboard, add copy/cut buttons:
605                 if ($this->clipObj->current=='normal')  {
606                         $isSel = $this->clipObj->isSelected('_FILE',$md5);
607                         $cells[]='<a href="'.htmlspecialchars($this->clipObj->selUrlFile($fullIdent,1,($isSel=='copy'))).'">'.
608                                                 t3lib_iconWorks::getSpriteIcon('actions-edit-copy'.($isSel=='copy'?'-release':''),array('title'=>$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:cm.copy',1))).
609                                                 '</a>';
610                         $cells[]='<a href="'.htmlspecialchars($this->clipObj->selUrlFile($fullIdent,0,($isSel=='cut'))).'">'.
611                                                 t3lib_iconWorks::getSpriteIcon('actions-edit-cut'.($isSel=='cut'?'-release':''),array('title'=>$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:cm.cut',1))).
612                                                 '</a>';
613                 } else {        // For numeric pads, add select checkboxes:
614                         $n='_FILE|'.$md5;
615                         $this->CBnames[]=$n;
616
617                         $checked = ($this->clipObj->isSelected('_FILE',$md5)?' checked="checked"':'');
618                         $cells[]='<input type="hidden" name="CBH['.$n.']" value="0" />'.
619                                         '<input type="checkbox" name="CBC['.$n.']" value="'.htmlspecialchars($fullIdent).'" class="smallCheckboxes"'.$checked.' />';
620                 }
621
622                         // Display PASTE button, if directory:
623                 $elFromTable = $this->clipObj->elFromTable('_FILE');
624                 if (@is_dir($fullIdent) && count($elFromTable)) {
625                         $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) . '">'.
626                           t3lib_iconWorks::getSpriteIcon('actions-document-paste-into') .
627                         '</a>';
628                 }
629
630                         // Compile items into a DIV-element:
631                 return '                                                        <!-- CLIPBOARD PANEL: -->
632                                                                                         <div class="typo3-clipCtrl">
633                                                                                                 '.implode('
634                                                                                                 ',$cells).'
635                                                                                         </div>';
636         }
637
638         /**
639         * Creates the edit control section
640         *
641         * @param        array           Array with information about the file/directory for which to make the edit control section for the listing.
642         * @return       string          HTML-table
643         */
644         function makeEdit($theData) {
645                 $cells = array();
646                 $fullIdent = $theData['path'].$theData['file'];
647                 $canEdit = t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $theData['realFileext']);
648
649                         // prepare space icon
650                 $iconWidth  = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['iconSizeWidth']  ? $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['iconSizeWidth']  : 12;
651                 $iconHeight = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['iconSizeHeight'] ? $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['iconSizeHeight'] : 12;
652                 $spaceIcon = '<img src="' . $this->backPath . 'clear.gif" width="' . $iconWidth . '" height="' . $iconHeight . '" title="" alt="" />';
653
654
655                         //edit
656                 if ($theData['type'] == 'dir' || !$canEdit) {
657                         $cells['edit'] = $spaceIcon;
658                 } else {
659                         $editOnClick = 'top.content.list_frame.location.href=top.TS.PATH_typo3+\'file_edit.php?target=' .
660                                 rawurlencode($fullIdent) .
661                                 '&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
662                         $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>';
663                 }
664                         //rename
665                 $renameOnClick = 'top.content.list_frame.location.href=top.TS.PATH_typo3+\'file_rename.php?target=' .
666                         rawurlencode($fullIdent) .
667                         '&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
668
669                 $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>';
670
671                         //info
672                 $infoOnClick = 'top.launchView(\'' . $fullIdent . '\', \'\');return false;';
673                 $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>';
674
675                         // Hook for manipulating edit icons.
676                 if(is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'])) {
677                         foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'] as $classData) {
678                                 $hookObject = t3lib_div::getUserObj($classData);
679
680                                 if(!($hookObject instanceof fileList_editIconHook)) {
681                                         throw new UnexpectedValueException('$hookObject must implement interface fileList_editIconHook', 1235225797);
682                                 }
683
684                                 $hookObject->manipulateEditIcons($cells, $this);
685                         }
686                 }
687
688                         // Compile items into a DIV-element:
689                 return '                                                        <!-- EDIT CONTROLS: -->
690                                                                                         <div class="typo3-editCtrl">
691                                                                                                 ' . implode('
692                                                                                                 ', $cells).'
693                                                                                         </div>';
694         }
695
696         /**
697          * Make reference count
698          *
699          * @param       array           Array with information about the file/directory for which to make the clipboard panel for the listing.
700          * @return      string          HTML
701          */
702         function makeRef($theData)      {
703
704                         // First, fit path to match what is stored in the refindex:
705                 $fullIdent = $theData['path'].$theData['file'];
706
707                 if (t3lib_div::isFirstPartOfStr($fullIdent,PATH_site))  {
708                         $fullIdent = substr($fullIdent,strlen(PATH_site));
709                 }
710
711                         // Look up the path:
712                 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
713                         '*',
714                         'sys_refindex',
715                         'ref_table='.$GLOBALS['TYPO3_DB']->fullQuoteStr('_FILE','sys_refindex').
716                                 ' AND ref_string='.$GLOBALS['TYPO3_DB']->fullQuoteStr($fullIdent,'sys_refindex').
717                                 ' AND deleted=0'
718                 );
719
720                         // Compile information for title tag:
721                 $infoData=array();
722                 if (is_array($rows)) {
723                         foreach($rows as $row)  {
724                                 $infoData[]=$row['tablename'].':'.$row['recuid'].':'.$row['field'];
725                         }
726                 }
727
728                 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>' : '';
729         }
730 }
731
732
733
734 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/class.file_list.inc'])) {
735         include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/class.file_list.inc']);
736 }
737 ?>