Documentation TYPO3 par Ameos |
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00074 class fileList extends t3lib_recordList { 00075 var $iLimit = 40; // default Max items shown 00076 var $thumbs = 0; // Boolean. Thumbnails on records containing files (pictures) 00077 var $widthGif = '<img src="clear.gif" width="1" height="1" hspace="165" alt="" />'; 00078 var $fixedL = 30; // Max length of strings 00079 var $script = 'file_list.php'; 00080 var $clickMenus=1; // If true click menus are generated on files and folders 00081 00082 var $sort = ''; // The field to sort by... 00083 var $sortRev = 1; // Reverse sorting flag 00084 var $firstElementNumber=0; 00085 var $clipBoard = 0; 00086 00087 // internal 00088 var $JScode = ''; 00089 var $HTMLcode = ''; 00090 var $totalbytes=0; 00091 var $dirs = Array(); 00092 var $files = Array(); 00093 var $path = ''; 00094 var $eCounter=0; // Counting the elements no matter what... 00095 var $totalItems=''; 00096 00097 var $CBnames=array(); 00098 00099 00100 00111 function start($path,$pointer,$sort,$sortRev,$clipBoard=0) { 00112 $this->counter=0; 00113 $this->totalbytes=0; 00114 $this->JScode=''; 00115 $this->HTMLcode=''; 00116 $this->path = $path; 00117 $this->sort=$sort; 00118 $this->sortRev=$sortRev; 00119 $this->firstElementNumber=$pointer; 00120 $this->clipBoard = $clipBoard; 00121 00122 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails']) { 00123 $this->thumbScript='gfx/notfound_thumb.gif'; 00124 } 00125 } 00126 00132 function generateList() { 00133 $this->dirs = $this->readDirectory($this->path,'dir,link'); 00134 $this->files = $this->readDirectory($this->path,'file'); 00135 $this->totalItems=count($this->dirs['sorting'])+count($this->files['sorting']); 00136 $this->HTMLcode.=$this->getTable($this->files, $this->dirs, 'fileext,tstamp,size,rw'); 00137 } 00138 00145 function writeTop($path) { 00146 // Makes the code for the foldericon in the top 00147 $path = $GLOBALS['SOBE']->basicFF->is_directory($path); // Cleaning name... 00148 00149 if ($path) { 00150 $out=''; 00151 $theFile = $GLOBALS['SOBE']->basicFF->getTotalFileInfo($path); 00152 $root = $GLOBALS['SOBE']->basicFF->checkPathAgainstMounts($theFile['path']); 00153 $titleCol='path'; 00154 $this->fieldArray = Array($titleCol,'up'); 00155 00156 list($title,$icon,$path) = $this->dirData($theFile); 00157 00158 // Start compiling the HTML 00159 $theData = Array(); 00160 $theData[$titleCol] = $this->widthGif; 00161 00162 $title = $GLOBALS['SOBE']->basicFF->blindPath($path); 00163 $theData['up']='<a href="'.htmlspecialchars($this->listURL()).'">'. 00164 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/refresh_n.gif','width="14" height="14"').' title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.reload',1).'" alt="" />'. 00165 '</a>'; 00166 00167 if ($root) { 00168 // The icon with link 00169 $theIcon = '<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' title="'.htmlspecialchars($theFile['file']).'" alt="" />'; 00170 if ($this->clickMenus) $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon,$path); 00171 00172 $theData[$titleCol].='<br />'.t3lib_div::fixed_lgd_cs($title,-($this->fixedL+20)); // No HTML specialchars here - HTML like <b> </b> is allowed 00173 $theData['up'].=$this->linkWrapDir('<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/i/folder_up.gif','width="18" height="16"').' title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.upOneLevel',1).'" alt="" />',$theFile['path']); 00174 } else { 00175 // root:0 00176 $theIcon='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/i/_icon_ftp.gif','width="18" height="16"').' alt="" />'; 00177 $theData[$titleCol].='<br />'.htmlspecialchars(t3lib_div::fixed_lgd_cs($title,-($this->fixedL+20))); 00178 } 00179 00180 // Adding top element 00181 $out.=$this->addelement(1,'',$theData,'','',$theIcon); 00182 00183 $this->HTMLcode.=' 00184 00185 <!-- 00186 Page header for file list 00187 --> 00188 <table border="0" cellpadding="0" cellspacing="0" id="typo3-filelist-top"> 00189 '.$out.' 00190 </table>'; 00191 } 00192 } 00193 00203 function linkClipboardHeaderIcon($string,$table,$cmd,$warning='') { 00204 $onClickEvent = 'document.dblistForm.cmd.value=\''.$cmd.'\';document.dblistForm.submit();'; 00205 if ($warning) $onClickEvent = 'if (confirm('.$GLOBALS['LANG']->JScharCode($warning).')){'.$onClickEvent.'}'; 00206 return '<a href="#" onclick="'.htmlspecialchars($onClickEvent).'return false;">'.$string.'</a>'; 00207 } 00208 00217 function getTable($files,$dirs,$rowlist) { 00218 // Adds the code of files/dirs 00219 $out=''; 00220 $titleCol = 'file'; 00221 00222 // Cleaning rowlist for duplicates and place the $titleCol as the first column always! 00223 $rowlist = t3lib_div::rmFromList($titleCol,$rowlist); 00224 $rowlist = t3lib_div::uniqueList($rowlist); 00225 $rowlist = $rowlist ? $titleCol.','.$rowlist : $titleCol; 00226 if ($this->clipBoard) $rowlist.=',_CLIPBOARD_'; 00227 $this->fieldArray = explode(',',$rowlist); 00228 00229 // half line is drawn 00230 $theData = Array(); 00231 $theData[$titleCol] = $this->widthGif; 00232 $out.=$this->addelement(0,'',$theData,''); 00233 00234 00235 00236 // Directories are added 00237 $iOut = ''; 00238 $iOut.= $this->formatDirList($dirs,$titleCol); 00239 00240 if (count($dirs['sorting'])) { 00241 // half line is drawn 00242 $theData = Array(); 00243 $theData[$titleCol] = ''; 00244 $iOut.=$this->addelement(0,'',$theData); 00245 } 00246 00247 00248 00249 // Files are added 00250 $iOut.= $this->formatFileList($files,$titleCol); 00251 00252 // Header line is drawn 00253 $theData = Array(); 00254 reset($this->fieldArray); 00255 while(list(,$v)=each($this->fieldArray)) { 00256 if ($v=='_CLIPBOARD_') { 00257 $cells=array(); 00258 $table='_FILE'; 00259 $elFromTable = $this->clipObj->elFromTable($table); 00260 if (count($elFromTable)) { 00261 $cells[]='<a href="'.htmlspecialchars($this->clipObj->pasteUrl('_FILE',$this->path)).'" onclick="return '.htmlspecialchars($this->clipObj->confirmMsg('_FILE',$this->path,'into',$elFromTable)).'">'. 00262 '<img'.t3lib_iconWorks::skinImg('','gfx/clip_pasteafter.gif','width="12" height="12"').' title="'.$GLOBALS['LANG']->getLL('clip_paste',1).'" alt="" /></a>'; 00263 } 00264 if ($this->clipObj->current!='normal' && $iOut) { 00265 $cells[]=$this->linkClipboardHeaderIcon('<img'.t3lib_iconWorks::skinImg('','gfx/clip_copy.gif','width="12" height="12"').' title="'.$GLOBALS['LANG']->getLL('clip_selectMarked',1).'" alt="" />',$table,'setCB'); 00266 $cells[]=$this->linkClipboardHeaderIcon('<img'.t3lib_iconWorks::skinImg('','gfx/garbage.gif','width="11" height="12"').' title="'.$GLOBALS['LANG']->getLL('clip_deleteMarked',1).'" alt="" />',$table,'delete',$GLOBALS['LANG']->getLL('clip_deleteMarkedWarning')); 00267 $onClick = 'checkOffCB(\''.implode(',',$this->CBnames).'\'); return false;'; 00268 $cells[]='<a href="#" onclick="'.htmlspecialchars($onClick).'">'. 00269 '<img'.t3lib_iconWorks::skinImg('','gfx/clip_select.gif','width="12" height="12"').' title="'.$GLOBALS['LANG']->getLL('clip_markRecords',1).'" alt="" />'. 00270 '</a>'; 00271 } 00272 00273 $theData[$v] = implode('',$cells); 00274 } else { // Normal row: 00275 $theT = $this->linkWrapSort($GLOBALS['LANG']->getLL('c_'.$v,1), $this->path,$v); 00276 $theData[$v] = $theT; 00277 } 00278 } 00279 $out.=$this->addelement(1,'',$theData,' class="c-headLine"',''); 00280 $out.=$iOut; 00281 00282 // half line is drawn 00283 $theData = Array(); 00284 $theData[$titleCol] = $this->counter.' File(s), '.t3lib_div::formatSize($this->totalbytes).'bytes'; 00285 $out.=$this->addelement(1,'',$theData); 00286 00287 // finish 00288 return ' 00289 00290 00291 <!-- 00292 File list table: 00293 --> 00294 <table border="0" cellpadding="0" cellspacing="0" id="typo3-filelist"> 00295 '.$out.' 00296 </table>'; 00297 } 00298 00305 function formatDirList($items) { 00306 $out=''; 00307 00308 // Files: 00309 if (count($items['sorting'])) { 00310 reset($items['sorting']); 00311 while (list($key,) = each($items['sorting'])) { 00312 list($flag,$code) = $this->fwd_rwd_nav(); 00313 $out.=$code; 00314 if ($flag) { 00315 // Initialization 00316 $theFile = $items['files'][$key]; 00317 $this->counter++; 00318 00319 list($title,$icon,$path) = $this->dirData($theFile); 00320 00321 // The icon with link 00322 $theIcon = '<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' title="'.htmlspecialchars($theFile['file']).'" alt="" />'; 00323 if ($this->clickMenus) $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon,$path); 00324 00325 // Preparing and getting the data-array 00326 $theData = Array(); 00327 reset($this->fieldArray); 00328 while(list(,$field)=each($this->fieldArray)) { 00329 switch($field) { 00330 case 'size': 00331 // $theData[$field]=t3lib_div::formatSize($theFile[$field]); 00332 break; 00333 case 'rw': 00334 $theData[$field]= (($theFile['readable'])?'':'<span class="typo3-red"><b>R</b></span>').(($theFile['writable'])?'':'<span class="typo3-red"><b>W</b></span>'); 00335 break; 00336 case 'fileext': 00337 // $theData[$field]=strtoupper($theFile['fileext']); 00338 break; 00339 case 'tstamp': 00340 $theData[$field]=Date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $theFile['tstamp']); 00341 break; 00342 case 'file': 00343 $theData[$field]= $this->linkWrapDir($title,$path); 00344 break; 00345 case '_CLIPBOARD_': 00346 $theData[$field]=$this->makeClip($theFile); 00347 break; 00348 default: 00349 $theData[$field]=t3lib_div::fixed_lgd($theFile[$field],$this->fixedL); 00350 break; 00351 } 00352 } 00353 $out.=$this->addelement(1,$theIcon,$theData); 00354 } 00355 $this->eCounter++; 00356 } 00357 } 00358 return $out; 00359 } 00360 00368 function linkWrapDir($code,$path) { 00369 $href = $this->script.'?id='.rawurlencode($path); 00370 00371 // Sometimes $code contains plain HTML tags. In such a case the string should not be modified! 00372 if(!strcmp($code,strip_tags($code))) { 00373 return '<a href="'.htmlspecialchars($href).'" title="'.htmlspecialchars($code).'">'.t3lib_div::fixed_lgd($code,$this->fixedL).'</a>'; 00374 } else { 00375 return '<a href="'.htmlspecialchars($href).'">'.$code.'</a>'; 00376 } 00377 } 00378 00386 function linkWrapFile($code,$path) { 00387 00388 if (t3lib_div::isFirstPartOfStr($path,t3lib_div::getIndpEnv('TYPO3_DOCUMENT_ROOT'))) { 00389 $href = substr($path,strlen(t3lib_div::getIndpEnv('TYPO3_DOCUMENT_ROOT'))); 00390 $aOnClick = "return top.openUrlInWindow('".$href."','WebFile');"; 00391 $code = '<a href="#" title="'.htmlspecialchars($code).'" onclick="'.htmlspecialchars($aOnClick).'">'.t3lib_div::fixed_lgd($code,$this->fixedL).'</a>'; 00392 } 00393 return $code; 00394 } 00395 00401 function listURL() { 00402 return $this->script.'?id='.rawurlencode($this->path).'&imagemode='.$this->thumbs; 00403 } 00404 00411 function dirData($theFile) { 00412 $path = $theFile['path'].$theFile['file'].'/'; 00413 $webpath=t3lib_BEfunc::getPathType_web_nonweb($path); 00414 00415 $title=htmlspecialchars($theFile['file']); 00416 $icon = 'gfx/i/_icon_'.$webpath.'folders.gif'; 00417 if ($title=='_temp_') { 00418 $icon = 'gfx/i/sysf.gif'; 00419 $title='<b>TEMP</b>'; 00420 } 00421 if ($title=='_recycler_') { 00422 $icon = 'gfx/i/recycler.gif'; 00423 $title='<b>RECYCLER</b>'; 00424 } 00425 $icon = $theFile['writable'] ? 'gfx/i/_icon_'.$webpath.'folders_ro.gif' : $icon; 00426 00427 return Array($title,$icon,$path); 00428 } 00429 00436 function formatFileList($items) { 00437 $out=''; 00438 00439 // Files: 00440 if (count($items['sorting'])) { 00441 reset($items['sorting']); 00442 while (list($key,) = each($items['sorting'])) { 00443 list($flag,$code) = $this->fwd_rwd_nav(); 00444 $out.=$code; 00445 if ($flag) { 00446 // Initialization 00447 $theFile = $items['files'][$key]; 00448 $this->counter++; 00449 00450 $this->totalbytes+=$theFile['size']; 00451 $ext = $items['files'][$key][fileext]; 00452 $icon = t3lib_BEfunc::getFileIcon($ext); 00453 00454 // The icon with link 00455 $theIcon = '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/fileicons/'.$icon,'width="18" height="16"').' title="'.htmlspecialchars($theFile['file']).'" alt="" />'; 00456 if ($this->clickMenus) $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon,$theFile['path'].$theFile['file']); 00457 00458 // Preparing and getting the data-array 00459 $theData = Array(); 00460 reset($this->fieldArray); 00461 while(list(,$field)=each($this->fieldArray)) { 00462 switch($field) { 00463 case 'size': 00464 $theData[$field]=t3lib_div::formatSize($theFile[$field]); 00465 break; 00466 case 'rw': 00467 $theData[$field]= (($theFile['readable'])?'':'<span class="typo3-red"><b>R</b></span>').(($theFile['writable'])?'':'<span class="typo3-red"><b>W</b></span>'); 00468 break; 00469 case 'fileext': 00470 $theData[$field]=strtoupper($theFile[$field]); 00471 break; 00472 case 'tstamp': 00473 $theData[$field]=Date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $theFile[$field]); 00474 break; 00475 case '_CLIPBOARD_': 00476 $theData[$field]=$this->makeClip($theFile); 00477 break; 00478 case 'file': 00479 $theData[$field] = $this->linkWrapFile($theFile[$field],$theFile['path'].$theFile['file']); 00480 break; 00481 default: 00482 $theData[$field]=t3lib_div::fixed_lgd($theFile[$field],$this->fixedL); 00483 break; 00484 } 00485 } 00486 $out.=$this->addelement(1,$theIcon,$theData); 00487 00488 // Thumbsnails? 00489 if ($this->thumbs && $this->isImage($theFile['fileext'])) { 00490 $thumbData=Array(); 00491 $theFile_R = rawurlencode($theFile['path'].$theFile['file']); 00492 $titleCol=$this->fieldArray[0]; 00493 $href = $this->backPath.$this->thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].'&file='.$theFile_R; 00494 $thumbData[$titleCol]='<img src="'.htmlspecialchars($href).'" hspace="2" title="'.htmlspecialchars(trim($theFile['file'])).'" alt="" />'; 00495 $out.=$this->addelement(4,'',$thumbData); 00496 } 00497 } 00498 $this->eCounter++; 00499 } 00500 } 00501 return $out; 00502 } 00503 00510 function isImage($ext) { 00511 return t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],strtolower($ext)); 00512 } 00513 00522 function linkWrapSort($code,$path,$col) { 00523 if ($this->sort==$col && !$this->sortRev) { // reverse sorting 00524 $params='&SET[sort]='.$col.'&SET[reverse]=1'; 00525 } else { 00526 $params='&SET[sort]='.$col.'&SET[reverse]=0'; 00527 } 00528 $href = $this->script.'?id='.rawurlencode($path).$params; 00529 return '<a href="'.htmlspecialchars($href).'">'.$code.'</a>'; 00530 } 00531 00540 function readDirectory($path,$type,$extList='') { 00541 $items = Array('files'=>array(), 'sorting'=>array()); 00542 $path = $GLOBALS['SOBE']->basicFF->is_directory($path); // Cleaning name... 00543 00544 if($path && $GLOBALS['SOBE']->basicFF->checkPathAgainstMounts($path.'/')) { 00545 $d = @dir($path); 00546 $tempArray=Array(); 00547 if (is_object($d)) { 00548 while($entry=$d->read()) { 00549 if ($entry!='.' && $entry!='..') { 00550 $wholePath = $path.'/'.$entry; // Because of odd PHP-error where <br />-tag is sometimes placed after a filename!! 00551 if (@file_exists($wholePath) && (!$type || t3lib_div::inList($type,filetype($wholePath)))) { 00552 if ($extList) { 00553 $fI = t3lib_div::split_fileref($entry); 00554 if (t3lib_div::inList($extList,$fI['fileext'])) { 00555 $tempArray[] = $wholePath; 00556 } 00557 } else { 00558 $tempArray[] = $wholePath; 00559 } 00560 } 00561 } 00562 } 00563 $d->close(); 00564 } 00565 // Get fileinfo 00566 reset($tempArray); 00567 while (list(,$val)=each($tempArray)) { 00568 $temp = $GLOBALS['SOBE']->basicFF->getTotalFileInfo($val); 00569 $items['files'][] = $temp; 00570 if ($this->sort) { 00571 $items['sorting'][] = strtoupper($temp[$this->sort]); 00572 } else { 00573 $items['sorting'][] = ''; 00574 } 00575 } 00576 // Sort if required 00577 if ($this->sort) { 00578 if (!$this->sortRev) { 00579 asort($items['sorting']); 00580 } else { 00581 arsort($items['sorting']); 00582 } 00583 } 00584 } 00585 return $items; 00586 } 00587 00594 function makeClip($theData) { 00595 $cells=array(); 00596 $fullIdent = $theData['path'].$theData['file']; 00597 $md5=t3lib_div::shortmd5($fullIdent); 00598 00599 // For normal clipboard, add copy/cut buttons: 00600 if ($this->clipObj->current=='normal') { 00601 $isSel = $this->clipObj->isSelected('_FILE',$md5); 00602 $cells[]='<a href="'.htmlspecialchars($this->clipObj->selUrlFile($fullIdent,1,($isSel=='copy'))).'">'. 00603 '<img'.t3lib_iconWorks::skinImg('','gfx/clip_copy'.($isSel=='copy'?'_h':'').'.gif','width="12" height="12"').' title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:cm.copy',1).'" alt="" />'. 00604 '</a>'; 00605 $cells[]='<a href="'.htmlspecialchars($this->clipObj->selUrlFile($fullIdent,0,($isSel=='cut'))).'">'. 00606 '<img'.t3lib_iconWorks::skinImg('','gfx/clip_cut'.($isSel=='cut'?'_h':'').'.gif','width="12" height="12"').' title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:cm.cut',1).'" alt="" />'. 00607 '</a>'; 00608 } else { // For numeric pads, add select checkboxes: 00609 $n='_FILE|'.$md5; 00610 $this->CBnames[]=$n; 00611 00612 $checked = ($this->clipObj->isSelected('_FILE',$md5)?' checked="checked"':''); 00613 $cells[]='<input type="hidden" name="CBH['.$n.']" value="0" />'. 00614 '<input type="checkbox" name="CBC['.$n.']" value="'.htmlspecialchars($fullIdent).'" class="smallCheckboxes"'.$checked.' />'; 00615 } 00616 00617 // Display PASTE button, if directory: 00618 $elFromTable = $this->clipObj->elFromTable('_FILE'); 00619 if (@is_dir($fullIdent) && count($elFromTable)) { 00620 $cells[]='<a href="'.htmlspecialchars($this->clipObj->pasteUrl('_FILE',$fullIdent)).'" onclick="return '.htmlspecialchars($this->clipObj->confirmMsg('_FILE',$fullIdent,'into',$elFromTable)).'">'. 00621 '<img'.t3lib_iconWorks::skinImg('','gfx/clip_pasteinto.gif','width="12" height="12"').' title="'.$GLOBALS['LANG']->getLL('clip_pasteInto',1).'" alt="" />'. 00622 '</a>'; 00623 } 00624 00625 // Compile items into a DIV-element: 00626 return ' <!-- CLIPBOARD PANEL: --> 00627 <div class="typo3-clipCtrl"> 00628 '.implode(' 00629 ',$cells).' 00630 </div>'; 00631 } 00632 } 00633 00634 00635 00636 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.file_list.inc']) { 00637 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.file_list.inc']); 00638 } 00639 ?>