| [ Index ] |
|
Code source de Typo3 4.1.3 |
1 <?php 2 /*************************************************************** 3 * Copyright notice 4 * 5 * (c) 1999-2005 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 * Generate a folder tree 29 * 30 * $Id: class.t3lib_foldertree.php 955 2005-12-28 00:49:12Z mundaun $ 31 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj 32 * 33 * @author Kasper Skaarhoj <kasperYYYY@typo3.com> 34 * @coauthor René Fritz <r.fritz@colorcube.de> 35 */ 36 /** 37 * [CLASS/FUNCTION INDEX of SCRIPT] 38 * 39 * 40 * 41 * 82: class t3lib_folderTree extends t3lib_treeView 42 * 89: function t3lib_folderTree() 43 * 107: function wrapIcon($icon,$row) 44 * 130: function wrapTitle($title,$row,$bank=0) 45 * 145: function getId($v) 46 * 155: function getJumpToParam($v) 47 * 167: function getTitleStr($row,$titleLen=30) 48 * 177: function getBrowsableTree() 49 * 240: function getFolderTree($files_path, $depth=999, $depthData='') 50 * 320: function getCount($files_path) 51 * 336: function initializePositionSaving() 52 * 53 * TOTAL FUNCTIONS: 10 54 * (This index is automatically created/updated by the extension "extdeveval") 55 * 56 */ 57 58 require_once (PATH_t3lib.'class.t3lib_treeview.php'); 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 /** 74 * Extension class for the t3lib_treeView class, specially made for browsing folders in the File module 75 * 76 * @author Kasper Skaarhoj <kasperYYYY@typo3.com> 77 * @coauthor René Fritz <r.fritz@colorcube.de> 78 * @package TYPO3 79 * @subpackage t3lib 80 * @see class t3lib_treeView 81 */ 82 class t3lib_folderTree extends t3lib_treeView { 83 84 /** 85 * Constructor function of the class 86 * 87 * @return void 88 */ 89 function t3lib_folderTree() { 90 parent::init(); 91 92 $this->MOUNTS = $GLOBALS['FILEMOUNTS']; 93 94 $this->treeName='folder'; 95 $this->titleAttrib=''; //don't apply any title 96 $this->domIdPrefix = 'folder'; 97 } 98 99 /** 100 * Wrapping the folder icon 101 * 102 * @param string The image tag for the icon 103 * @param array The row for the current element 104 * @return string The processed icon input value. 105 * @access private 106 */ 107 function wrapIcon($icon,$row) { 108 // Add title attribute to input icon tag 109 $theFolderIcon = $this->addTagAttributes($icon,($this->titleAttrib ? $this->titleAttrib.'="'.$this->getTitleAttrib($row).'"' : '')); 110 111 // Wrap icon in click-menu link. 112 if (!$this->ext_IconMode) { 113 $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon,$row['path'],'',0); 114 } elseif (!strcmp($this->ext_IconMode,'titlelink')) { 115 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'\','.$this->bank.');'; 116 $theFolderIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$theFolderIcon.'</a>'; 117 } 118 return $theFolderIcon; 119 } 120 121 /** 122 * Wrapping $title in a-tags. 123 * 124 * @param string Title string 125 * @param string Item record 126 * @param integer Bank pointer (which mount point number) 127 * @return string 128 * @access private 129 */ 130 function wrapTitle($title,$row,$bank=0) { 131 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'\','.$bank.');'; 132 $CSM = ''; 133 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler']) { 134 $CSM = ' oncontextmenu="'.htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('',$row['path'],'',0,'','',TRUE)).'"'; 135 } 136 return '<a href="#" title="'.htmlspecialchars($row['title']).'" onclick="'.htmlspecialchars($aOnClick).'"'.$CSM.'>'.$title.'</a>'; 137 } 138 139 /** 140 * Returns the id from the record - for folders, this is an md5 hash. 141 * 142 * @param array Record array 143 * @return integer The "uid" field value. 144 */ 145 function getId($v) { 146 return t3lib_div::md5Int($v['path']); 147 } 148 149 /** 150 * Returns jump-url parameter value. 151 * 152 * @param array The record array. 153 * @return string The jump-url parameter. 154 */ 155 function getJumpToParam($v) { 156 return rawurlencode($v['path']); 157 } 158 159 /** 160 * Returns the title for the input record. If blank, a "no title" labele (localized) will be returned. 161 * '_title' is used for setting an alternative title for folders. 162 * 163 * @param array The input row array (where the key "_title" is used for the title) 164 * @param integer Title length (30) 165 * @return string The title. 166 */ 167 function getTitleStr($row,$titleLen=30) { 168 return $row['_title'] ? $row['_title'] : parent::getTitleStr($row,$titleLen); 169 } 170 171 /** 172 * Will create and return the HTML code for a browsable tree of folders. 173 * Is based on the mounts found in the internal array ->MOUNTS (set in the constructor) 174 * 175 * @return string HTML code for the browsable tree 176 */ 177 function getBrowsableTree() { 178 179 // Get stored tree structure AND updating it if needed according to incoming PM GET var. 180 $this->initializePositionSaving(); 181 182 // Init done: 183 $titleLen=intval($this->BE_USER->uc['titleLen']); 184 $treeArr=array(); 185 186 // Traverse mounts: 187 foreach($this->MOUNTS as $key => $val) { 188 $md5_uid = md5($val['path']); 189 $specUID=hexdec(substr($md5_uid,0,6)); 190 $this->specUIDmap[$specUID]=$val['path']; 191 192 // Set first: 193 $this->bank=$val['nkey']; 194 $isOpen = $this->stored[$val['nkey']][$specUID] || $this->expandFirst; 195 $this->reset(); 196 197 // Set PM icon: 198 $cmd=$this->bank.'_'.($isOpen?'0_':'1_').$specUID.'_'.$this->treeName; 199 $icon='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.($isOpen?'minus':'plus').'only.gif','width="18" height="16"').' alt="" />'; 200 $firstHtml= $this->PM_ATagWrap($icon,$cmd); 201 202 switch($val['type']) { 203 case 'user': $icon = 'gfx/i/_icon_ftp_user.gif'; break; 204 case 'group': $icon = 'gfx/i/_icon_ftp_group.gif'; break; 205 default: $icon = 'gfx/i/_icon_ftp.gif'; break; 206 } 207 208 // Preparing rootRec for the mount 209 $firstHtml.=$this->wrapIcon('<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' alt="" />',$val); 210 $row=array(); 211 $row['path']=$val['path']; 212 $row['uid']=$specUID; 213 $row['title']=$val['name']; 214 215 // Add the root of the mount to ->tree 216 $this->tree[]=array('HTML'=>$firstHtml,'row'=>$row,'bank'=>$this->bank); 217 218 // If the mount is expanded, go down: 219 if ($isOpen) { 220 // Set depth: 221 $depthD='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/blank.gif','width="18" height="16"').' alt="" />'; 222 $this->getFolderTree($val['path'],999,$depthD); 223 } 224 225 // Add tree: 226 $treeArr=array_merge($treeArr,$this->tree); 227 } 228 return $this->printTree($treeArr); 229 } 230 231 /** 232 * Fetches the data for the tree 233 * 234 * @param string Abs file path 235 * @param integer Max depth (recursivity limit) 236 * @param string HTML-code prefix for recursive calls. 237 * @return integer The count of items on the level 238 * @see getBrowsableTree() 239 */ 240 function getFolderTree($files_path, $depth=999, $depthData='') { 241 242 // This generates the directory tree 243 $dirs = t3lib_div::get_dirs($files_path); 244 245 $c=0; 246 if (is_array($dirs)) { 247 $depth=intval($depth); 248 $HTML=''; 249 $a=0; 250 $c=count($dirs); 251 sort($dirs); 252 253 foreach($dirs as $key => $val) { 254 $a++; 255 $this->tree[]=array(); // Reserve space. 256 end($this->tree); 257 $treeKey = key($this->tree); // Get the key for this space 258 $LN = ($a==$c)?'blank':'line'; 259 260 $val = ereg_replace('^\./','',$val); 261 $title = $val; 262 $path = $files_path.$val.'/'; 263 $webpath=t3lib_BEfunc::getPathType_web_nonweb($path); 264 265 $md5_uid = md5($path); 266 $specUID=hexdec(substr($md5_uid,0,6)); 267 $this->specUIDmap[$specUID]=$path; 268 $row=array(); 269 $row['path']=$path; 270 $row['uid']=$specUID; 271 $row['title']=$title; 272 273 if ($depth>1 && $this->expandNext($specUID)) { 274 $nextCount=$this->getFolderTree( 275 $path, 276 $depth-1, 277 $this->makeHTML ? $depthData.'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$LN.'.gif','width="18" height="16"').' alt="" />' : '' 278 ); 279 $exp=1; // Set "did expand" flag 280 } else { 281 $nextCount=$this->getCount($path); 282 $exp=0; // Clear "did expand" flag 283 } 284 285 // Set HTML-icons, if any: 286 if ($this->makeHTML) { 287 $HTML=$depthData.$this->PMicon($row,$a,$c,$nextCount,$exp); 288 289 $icon = 'gfx/i/_icon_'.$webpath.'folders.gif'; 290 if ($val=='_temp_') { 291 $icon = 'gfx/i/sysf.gif'; 292 $row['title']='TEMP'; 293 $row['_title']='<b>TEMP</b>'; 294 } 295 if ($val=='_recycler_') { 296 $icon = 'gfx/i/recycler.gif'; 297 $row['title']='RECYCLER'; 298 $row['_title']='<b>RECYCLER</b>'; 299 } 300 $HTML.=$this->wrapIcon('<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' alt="" />',$row); 301 } 302 303 // Finally, add the row/HTML content to the ->tree array in the reserved key. 304 $this->tree[$treeKey] = Array( 305 'row'=>$row, 306 'HTML'=>$HTML, 307 'bank'=>$this->bank 308 ); 309 } 310 } 311 return $c; 312 } 313 314 /** 315 * Counts the number of directories in a file path. 316 * 317 * @param string File path. 318 * @return integer 319 */ 320 function getCount($files_path) { 321 // This generates the directory tree 322 $dirs = t3lib_div::get_dirs($files_path); 323 $c=0; 324 if (is_array($dirs)) { 325 $c=count($dirs); 326 } 327 return $c; 328 } 329 330 /** 331 * Get stored tree structure AND updating it if needed according to incoming PM GET var. 332 * 333 * @return void 334 * @access private 335 */ 336 function initializePositionSaving() { 337 // Get stored tree structure: 338 $this->stored=unserialize($this->BE_USER->uc['browseTrees'][$this->treeName]); 339 340 // Mapping md5-hash to shorter number: 341 $hashMap=array(); 342 foreach($this->MOUNTS as $key => $val) { 343 $nkey = hexdec(substr($key,0,4)); 344 $hashMap[$nkey]=$key; 345 $this->MOUNTS[$key]['nkey']=$nkey; 346 } 347 348 // PM action: 349 // (If an plus/minus icon has been clicked, the PM GET var is sent and we must update the stored positions in the tree): 350 $PM = explode('_',t3lib_div::_GP('PM')); // 0: mount key, 1: set/clear boolean, 2: item ID (cannot contain "_"), 3: treeName 351 if (count($PM)==4 && $PM[3]==$this->treeName) { 352 if (isset($this->MOUNTS[$hashMap[$PM[0]]])) { 353 if ($PM[1]) { // set 354 $this->stored[$PM[0]][$PM[2]]=1; 355 $this->savePosition($this->treeName); 356 } else { // clear 357 unset($this->stored[$PM[0]][$PM[2]]); 358 $this->savePosition($this->treeName); 359 } 360 } 361 } 362 } 363 } 364 365 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_foldertree.php']) { 366 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_foldertree.php']); 367 } 368 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Nov 25 17:13:16 2007 | par Balluche grâce à PHPXref 0.7 |
|