Documentation TYPO3 par Ameos

class.t3lib_foldertree.php

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 ***************************************************************/
00058 require_once (PATH_t3lib.'class.t3lib_treeview.php');
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00082 class t3lib_folderTree extends t3lib_treeView  {
00083 
00089         function t3lib_folderTree()     {
00090                 parent::init();
00091 
00092                 $this->MOUNTS = $GLOBALS['FILEMOUNTS'];
00093 
00094                 $this->treeName='folder';
00095                 $this->titleAttrib=''; //don't apply any title
00096                 $this->domIdPrefix = 'folder';
00097         }
00098 
00107         function wrapIcon($icon,$row)   {
00108                         // Add title attribute to input icon tag
00109                 $theFolderIcon = $this->addTagAttributes($icon,($this->titleAttrib ? $this->titleAttrib.'="'.$this->getTitleAttrib($row).'"' : ''));
00110 
00111                         // Wrap icon in click-menu link.
00112                 if (!$this->ext_IconMode)       {
00113                         $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon,$row['path'],'',0);
00114                 } elseif (!strcmp($this->ext_IconMode,'titlelink'))     {
00115                         $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'_'.$this->bank.'\');';
00116                         $theFolderIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$theFolderIcon.'</a>';
00117                 }
00118                 return $theFolderIcon;
00119         }
00120 
00130         function wrapTitle($title,$row,$bank=0) {
00131                 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'_'.$bank.'\');';
00132                 $CSM = '';
00133                 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler'])       {
00134                         $CSM = ' oncontextmenu="'.htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('',$row['path'],'',0,'','',TRUE)).'"';
00135                 }
00136                 return '<a href="#" title="'.htmlspecialchars($row['title']).'" onclick="'.htmlspecialchars($aOnClick).'"'.$CSM.'>'.$title.'</a>';
00137         }
00138 
00145         function getId($v) {
00146                 return t3lib_div::md5Int($v['path']);
00147         }
00148 
00155         function getJumpToParam($v) {
00156                 return rawurlencode($v['path']);
00157         }
00158 
00167         function getTitleStr($row,$titleLen=30) {
00168                 return $row['_title'] ? $row['_title'] : parent::getTitleStr($row,$titleLen);
00169         }
00170 
00177         function getBrowsableTree()     {
00178 
00179                         // Get stored tree structure AND updating it if needed according to incoming PM GET var.
00180                 $this->initializePositionSaving();
00181 
00182                         // Init done:
00183                 $titleLen=intval($this->BE_USER->uc['titleLen']);
00184                 $treeArr=array();
00185 
00186                         // Traverse mounts:
00187                 foreach($this->MOUNTS as $key => $val)  {
00188                         $md5_uid = md5($val['path']);
00189                         $specUID=hexdec(substr($md5_uid,0,6));
00190                         $this->specUIDmap[$specUID]=$val['path'];
00191 
00192                                 // Set first:
00193                         $this->bank=$val['nkey'];
00194                         $isOpen = $this->stored[$val['nkey']][$specUID] || $this->expandFirst;
00195                         $this->reset();
00196 
00197                                 // Set PM icon:
00198                         $cmd=$this->bank.'_'.($isOpen?'0_':'1_').$specUID.'_'.$this->treeName;
00199                         $icon='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.($isOpen?'minus':'plus').'only.gif','width="18" height="16"').' alt="" />';
00200                         $firstHtml= $this->PM_ATagWrap($icon,$cmd);
00201 
00202                         switch($val['type'])    {
00203                                 case 'user':    $icon = 'gfx/i/_icon_ftp_user.gif';     break;
00204                                 case 'group':   $icon = 'gfx/i/_icon_ftp_group.gif'; break;
00205                                 default:                $icon = 'gfx/i/_icon_ftp.gif'; break;
00206                         }
00207 
00208                                 // Preparing rootRec for the mount
00209                         $firstHtml.=$this->wrapIcon('<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' alt="" />',$val);
00210                                 $row=array();
00211                                 $row['path']=$val['path'];
00212                                 $row['uid']=$specUID;
00213                                 $row['title']=$val['name'];
00214 
00215                                 // Add the root of the mount to ->tree
00216                         $this->tree[]=array('HTML'=>$firstHtml,'row'=>$row,'bank'=>$this->bank);
00217 
00218                                 // If the mount is expanded, go down:
00219                         if ($isOpen)    {
00220                                         // Set depth:
00221                                 $depthD='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/blank.gif','width="18" height="16"').' alt="" />';
00222                                 $this->getFolderTree($val['path'],999,$depthD);
00223                         }
00224 
00225                                 // Add tree:
00226                         $treeArr=array_merge($treeArr,$this->tree);
00227                 }
00228                 return $this->printTree($treeArr);
00229         }
00230 
00240         function getFolderTree($files_path, $depth=999, $depthData='')  {
00241 
00242                         // This generates the directory tree
00243                 $dirs = t3lib_div::get_dirs($files_path);
00244 
00245                 $c=0;
00246                 if (is_array($dirs))    {
00247                         $depth=intval($depth);
00248                         $HTML='';
00249                         $a=0;
00250                         $c=count($dirs);
00251                         sort($dirs);
00252 
00253                         foreach($dirs as $key => $val)  {
00254                                 $a++;
00255                                 $this->tree[]=array();          // Reserve space.
00256                                 end($this->tree);
00257                                 $treeKey = key($this->tree);    // Get the key for this space
00258                                 $LN = ($a==$c)?'blank':'line';
00259 
00260                                 $val = ereg_replace('^\./','',$val);
00261                                 $title = $val;
00262                                 $path = $files_path.$val.'/';
00263                                 $webpath=t3lib_BEfunc::getPathType_web_nonweb($path);
00264 
00265                                 $md5_uid = md5($path);
00266                                 $specUID=hexdec(substr($md5_uid,0,6));
00267                                 $this->specUIDmap[$specUID]=$path;
00268                                 $row=array();
00269                                 $row['path']=$path;
00270                                 $row['uid']=$specUID;
00271                                 $row['title']=$title;
00272 
00273                                 if ($depth>1 && $this->expandNext($specUID))    {
00274                                         $nextCount=$this->getFolderTree(
00275                                                 $path,
00276                                                 $depth-1,
00277                                                 $this->makeHTML ? $depthData.'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$LN.'.gif','width="18" height="16"').' alt="" />' : ''
00278                                         );
00279                                         $exp=1;         // Set "did expand" flag
00280                                 } else {
00281                                         $nextCount=$this->getCount($path);
00282                                         $exp=0;         // Clear "did expand" flag
00283                                 }
00284 
00285                                         // Set HTML-icons, if any:
00286                                 if ($this->makeHTML)    {
00287                                         $HTML=$depthData.$this->PMicon($row,$a,$c,$nextCount,$exp);
00288 
00289                                         $icon = 'gfx/i/_icon_'.$webpath.'folders.gif';
00290                                         if ($val=='_temp_')     {
00291                                                 $icon = 'gfx/i/sysf.gif';
00292                                                 $row['title']='TEMP';
00293                                                 $row['_title']='<b>TEMP</b>';
00294                                         }
00295                                         if ($val=='_recycler_') {
00296                                                 $icon = 'gfx/i/recycler.gif';
00297                                                 $row['title']='RECYCLER';
00298                                                 $row['_title']='<b>RECYCLER</b>';
00299                                         }
00300                                         $HTML.=$this->wrapIcon('<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' alt="" />',$row);
00301                                 }
00302 
00303                                         // Finally, add the row/HTML content to the ->tree array in the reserved key.
00304                                 $this->tree[$treeKey] = Array(
00305                                         'row'=>$row,
00306                                         'HTML'=>$HTML,
00307                                         'bank'=>$this->bank
00308                                 );
00309                         }
00310                 }
00311                 return $c;
00312         }
00313 
00320         function getCount($files_path)  {
00321                         // This generates the directory tree
00322                 $dirs = t3lib_div::get_dirs($files_path);
00323                 $c=0;
00324                 if (is_array($dirs))    {
00325                         $c=count($dirs);
00326                 }
00327                 return $c;
00328         }
00329 
00336         function initializePositionSaving()     {
00337                         // Get stored tree structure:
00338                 $this->stored=unserialize($this->BE_USER->uc['browseTrees'][$this->treeName]);
00339 
00340                         // Mapping md5-hash to shorter number:
00341                 $hashMap=array();
00342                 foreach($this->MOUNTS as $key => $val)  {
00343                         $nkey = hexdec(substr($key,0,4));
00344                         $hashMap[$nkey]=$key;
00345                         $this->MOUNTS[$key]['nkey']=$nkey;
00346                 }
00347 
00348                         // PM action:
00349                         // (If an plus/minus icon has been clicked, the PM GET var is sent and we must update the stored positions in the tree):
00350                 $PM = explode('_',t3lib_div::_GP('PM'));        // 0: mount key, 1: set/clear boolean, 2: item ID (cannot contain "_"), 3: treeName
00351                 if (count($PM)==4 && $PM[3]==$this->treeName)   {
00352                         if (isset($this->MOUNTS[$hashMap[$PM[0]]]))     {
00353                                 if ($PM[1])     {       // set
00354                                         $this->stored[$PM[0]][$PM[2]]=1;
00355                                         $this->savePosition($this->treeName);
00356                                 } else {        // clear
00357                                         unset($this->stored[$PM[0]][$PM[2]]);
00358                                         $this->savePosition($this->treeName);
00359                                 }
00360                         }
00361                 }
00362         }
00363 }
00364 
00365 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_foldertree.php'])        {
00366         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_foldertree.php']);
00367 }
00368 ?>


Généré par Le spécialiste TYPO3 avec  doxygen 1.4.6