Main Page | Directories | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages | Examples

class.t3lib_foldertree.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2004 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 ***************************************************************/
00057 require_once (PATH_t3lib.'class.t3lib_treeview.php');
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00081 class t3lib_folderTree extends t3lib_treeView  {
00082 
00088    function t3lib_folderTree()   {
00089       parent::init();
00090 
00091       $this->MOUNTS = $GLOBALS['FILEMOUNTS'];
00092 
00093       $this->treeName='folder';
00094       $this->titleAttrib=''; //don't apply any title
00095       $this->domIdPrefix = 'folder';
00096    }
00097 
00106    function wrapIcon($icon,$row) {
00107          // Add title attribute to input icon tag
00108       $theFolderIcon = $this->addTagAttributes($icon,($this->titleAttrib ? $this->titleAttrib.'="'.$this->getTitleAttrib($row).'"' : ''));
00109 
00110          // Wrap icon in click-menu link.
00111       if (!$this->ext_IconMode)  {
00112          $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon,$row['path'],'',0);
00113       } elseif (!strcmp($this->ext_IconMode,'titlelink'))   {
00114          $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'_'.$this->bank.'\');';
00115          $theFolderIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$theFolderIcon.'</a>';
00116       }
00117       return $theFolderIcon;
00118    }
00119 
00126    function getId($v) {
00127       return t3lib_div::md5Int($v['path']);
00128    }
00129 
00136    function getJumpToParam($v) {
00137       return rawurlencode($v['path']);
00138    }
00139 
00148    function getTitleStr($row,$titleLen=30)   {
00149       return $row['_title'] ? $row['_title'] : parent::getTitleStr($row,$titleLen);
00150    }
00151 
00158    function getBrowsableTree()   {
00159 
00160          // Get stored tree structure AND updating it if needed according to incoming PM GET var.
00161       $this->initializePositionSaving();
00162 
00163          // Init done:
00164       $titleLen=intval($this->BE_USER->uc['titleLen']);
00165       $treeArr=array();
00166 
00167          // Traverse mounts:
00168       foreach($this->MOUNTS as $key => $val) {
00169          $md5_uid = md5($val['path']);
00170          $specUID=hexdec(substr($md5_uid,0,6));
00171          $this->specUIDmap[$specUID]=$val['path'];
00172 
00173             // Set first:
00174          $this->bank=$val['nkey'];
00175          $isOpen = $this->stored[$val['nkey']][$specUID] || $this->expandFirst;
00176          $this->reset();
00177 
00178             // Set PM icon:
00179          $cmd=$this->bank.'_'.($isOpen?'0_':'1_').$specUID.'_'.$this->treeName;
00180          $icon='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.($isOpen?'minus':'plus').'only.gif','width="18" height="16"').' alt="" />';
00181          $firstHtml= $this->PM_ATagWrap($icon,$cmd);
00182 
00183          switch($val['type']) {
00184             case 'user':   $icon = 'gfx/i/_icon_ftp_user.gif'; break;
00185             case 'group':  $icon = 'gfx/i/_icon_ftp_group.gif'; break;
00186             default:    $icon = 'gfx/i/_icon_ftp.gif'; break;
00187          }
00188 
00189             // Preparing rootRec for the mount
00190          $firstHtml.=$this->wrapIcon('<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' alt="" />',$val);
00191             $row=array();
00192             $row['path']=$val['path'];
00193             $row['uid']=$specUID;
00194             $row['title']=$val['name'];
00195 
00196             // Add the root of the mount to ->tree
00197          $this->tree[]=array('HTML'=>$firstHtml,'row'=>$row,'bank'=>$this->bank);
00198 
00199             // If the mount is expanded, go down:
00200          if ($isOpen)   {
00201                // Set depth:
00202             $depthD='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/blank.gif','width="18" height="16"').' alt="" />';
00203             $this->getFolderTree($val['path'],999,$depthD);
00204          }
00205 
00206             // Add tree:
00207          $treeArr=array_merge($treeArr,$this->tree);
00208       }
00209       return $this->printTree($treeArr);
00210    }
00211 
00221    function getFolderTree($files_path, $depth=999, $depthData='') {
00222 
00223          // This generates the directory tree
00224       $dirs = t3lib_div::get_dirs($files_path);
00225 
00226       $c=0;
00227       if (is_array($dirs)) {
00228          $depth=intval($depth);
00229          $HTML='';
00230          $a=0;
00231          $c=count($dirs);
00232          sort($dirs);
00233 
00234          foreach($dirs as $key => $val)   {
00235             $a++;
00236             $this->tree[]=array();     // Reserve space.
00237             end($this->tree);
00238             $treeKey = key($this->tree);  // Get the key for this space
00239             $LN = ($a==$c)?'blank':'line';
00240 
00241             $val = ereg_replace('^\./','',$val);
00242             $title = $val;
00243             $path = $files_path.$val.'/';
00244             $webpath=t3lib_BEfunc::getPathType_web_nonweb($path);
00245 
00246             $md5_uid = md5($path);
00247             $specUID=hexdec(substr($md5_uid,0,6));
00248             $this->specUIDmap[$specUID]=$path;
00249             $row=array();
00250             $row['path']=$path;
00251             $row['uid']=$specUID;
00252             $row['title']=$title;
00253 
00254             if ($depth>1 && $this->expandNext($specUID)) {
00255                $nextCount=$this->getFolderTree(
00256                   $path,
00257                   $depth-1,
00258                   $this->makeHTML ? $depthData.'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$LN.'.gif','width="18" height="16"').' alt="" />' : ''
00259                );
00260                $exp=1;     // Set "did expand" flag
00261             } else {
00262                $nextCount=$this->getCount($path);
00263                $exp=0;     // Clear "did expand" flag
00264             }
00265 
00266                // Set HTML-icons, if any:
00267             if ($this->makeHTML) {
00268                $HTML=$depthData.$this->PMicon($row,$a,$c,$nextCount,$exp);
00269 
00270                $icon = 'gfx/i/_icon_'.$webpath.'folders.gif';
00271                if ($val=='_temp_')  {
00272                   $icon = 'gfx/i/sysf.gif';
00273                   $row['title']='TEMP';
00274                   $row['_title']='<b>TEMP</b>';
00275                }
00276                if ($val=='_recycler_') {
00277                   $icon = 'gfx/i/recycler.gif';
00278                   $row['title']='RECYCLER';
00279                   $row['_title']='<b>RECYCLER</b>';
00280                }
00281                $HTML.=$this->wrapIcon('<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' alt="" />',$row);
00282             }
00283 
00284                // Finally, add the row/HTML content to the ->tree array in the reserved key.
00285             $this->tree[$treeKey] = Array(
00286                'row'=>$row,
00287                'HTML'=>$HTML,
00288                'bank'=>$this->bank
00289             );
00290          }
00291       }
00292       return $c;
00293    }
00294 
00301    function getCount($files_path)   {
00302          // This generates the directory tree
00303       $dirs = t3lib_div::get_dirs($files_path);
00304       $c=0;
00305       if (is_array($dirs)) {
00306          $c=count($dirs);
00307       }
00308       return $c;
00309    }
00310 
00317    function initializePositionSaving() {
00318          // Get stored tree structure:
00319       $this->stored=unserialize($this->BE_USER->uc['browseTrees'][$this->treeName]);
00320 
00321          // Mapping md5-hash to shorter number:
00322       $hashMap=array();
00323       foreach($this->MOUNTS as $key => $val) {
00324          $nkey = hexdec(substr($key,0,4));
00325          $hashMap[$nkey]=$key;
00326          $this->MOUNTS[$key]['nkey']=$nkey;
00327       }
00328 
00329          // PM action:
00330          // (If an plus/minus icon has been clicked, the PM GET var is sent and we must update the stored positions in the tree):
00331       $PM = explode('_',t3lib_div::_GP('PM'));  // 0: mount key, 1: set/clear boolean, 2: item ID (cannot contain "_"), 3: treeName
00332       if (count($PM)==4 && $PM[3]==$this->treeName)   {
00333          if (isset($this->MOUNTS[$hashMap[$PM[0]]]))  {
00334             if ($PM[1]) {  // set
00335                $this->stored[$PM[0]][$PM[2]]=1;
00336                $this->savePosition($this->treeName);
00337             } else { // clear
00338                unset($this->stored[$PM[0]][$PM[2]]);
00339                $this->savePosition($this->treeName);
00340             }
00341          }
00342       }
00343    }
00344 }
00345 
00346 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_foldertree.php']) {
00347    include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_foldertree.php']);
00348 }
00349 ?>

Generated on Sun Oct 3 01:05:48 2004 for TYPO3core 3.7.0 dev by  doxygen 1.3.8-20040913