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