Documentation TYPO3 par Ameos |
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2006 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 ***************************************************************/ 00054 require_once (PATH_t3lib.'class.t3lib_foldertree.php'); 00055 00056 00057 00067 class filelistFolderTree extends t3lib_folderTree { 00068 00069 var $ext_IconMode; 00070 var $ajaxStatus = false; // Indicates, whether the ajax call was successful, i.e. the requested page has been found 00071 00077 function filelistFolderTree() { 00078 parent::t3lib_folderTree(); 00079 } 00080 00088 function wrapIcon($icon,&$row) { 00089 00090 // Add title attribute to input icon tag 00091 $theFolderIcon = $this->addTagAttributes($icon,($this->titleAttrib ? $this->titleAttrib.'="'.$this->getTitleAttrib($row).'"' : '')); 00092 00093 // Wrap icon in click-menu link. 00094 if (!$this->ext_IconMode) { 00095 $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon,$row['path'],'',0); 00096 } elseif (!strcmp($this->ext_IconMode,'titlelink')) { 00097 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'\','.$this->bank.');'; 00098 $theFolderIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$theFolderIcon.'</a>'; 00099 } 00100 // Wrap icon in a drag/drop span. 00101 return '<span class="dragIcon" id="dragIconID_'.$this->getJumpToParam($row).'">'.$theFolderIcon.'</span>'; 00102 } 00103 00104 00114 function wrapTitle($title,$row,$bank=0) { 00115 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'\','.$bank.');'; 00116 $CSM = ''; 00117 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler']) { 00118 $CSM = ' oncontextmenu="'.htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('',$row['path'],'',0,'&bank='.$this->bank,'',TRUE)).'"'; 00119 } 00120 $theFolderTitle='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"'.$CSM.'>'.$title.'</a>'; 00121 00122 // Wrap title in a drag/drop span. 00123 return '<span class="dragTitle" id="dragTitleID_'.$this->getJumpToParam($row).'">'.$theFolderTitle.'</span>'; 00124 } 00125 00126 00127 00128 00135 function printTree($treeArr='') { 00136 $titleLen = intval($this->BE_USER->uc['titleLen']); 00137 if (!is_array($treeArr)) $treeArr = $this->tree; 00138 00139 $out = ' 00140 <!-- TYPO3 folder tree structure. --> 00141 <ul class="tree"> 00142 '; 00143 $titleLen=intval($this->BE_USER->uc['titleLen']); 00144 if (!is_array($treeArr)) $treeArr=$this->tree; 00145 00146 // -- evaluate AJAX request 00147 // IE takes anchor as parameter 00148 $PM = t3lib_div::_GP('PM'); 00149 if(($PMpos = strpos($PM, '#')) !== false) { $PM = substr($PM, 0, $PMpos); } 00150 $PM = explode('_', $PM); 00151 if(($isAjaxCall = t3lib_div::_GP('ajax')) && is_array($PM) && count($PM)==4) { 00152 if($PM[1]) { 00153 $expandedFolderUid = $PM[2]; 00154 $ajaxOutput = ''; 00155 $invertedDepthOfAjaxRequestedItem = 0; // We don't know yet. Will be set later. 00156 $doExpand = true; 00157 } else { 00158 $expandedFolderUid = $PM[2]; 00159 $doCollapse = true; 00160 } 00161 } 00162 00163 00164 // we need to count the opened <ul>'s every time we dig into another level, 00165 // so we know how many we have to close when all children are done rendering 00166 $closeDepth = array(); 00167 00168 foreach($treeArr as $k => $v) { 00169 $classAttr = $v['row']['_CSSCLASS']; 00170 $uid = $v['row']['uid']; 00171 $idAttr = htmlspecialchars($this->domIdPrefix.$this->getId($v['row']).'_'.$v['bank']); 00172 $itemHTML = ''; 00173 00174 // if this item is the start of a new level, 00175 // then a new level <ul> is needed, but not in ajax mode 00176 if($v['isFirst'] && !($doCollapse) && !($doExpand && $expandedFolderUid == $uid)) { 00177 $itemHTML = "<ul>\n"; 00178 } 00179 00180 // add CSS classes to the list item 00181 if($v['hasSub']) { $classAttr = ($classAttr) ? ' expanded': 'expanded'; } 00182 if($v['isLast']) { $classAttr = ($classAttr) ? ' last' : 'last'; } 00183 00184 $itemHTML .=' 00185 <li id="'.$idAttr.'"'.($classAttr ? ' class="'.$classAttr.'"' : '').'>'. 00186 $v['HTML']. 00187 $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$v['bank']); 00188 00189 00190 if(!$v['hasSub']) { $itemHTML .= "</li>\n"; } 00191 00192 // we have to remember if this is the last one 00193 // on level X so the last child on level X+1 closes the <ul>-tag 00194 if($v['isLast'] && !($doExpand && $expandedFolderUid == $uid)) { $closeDepth[$v['invertedDepth']] = 1; } 00195 00196 00197 // if this is the last one and does not have subitems, we need to close 00198 // the tree as long as the upper levels have last items too 00199 if($v['isLast'] && !$v['hasSub'] && !$doCollapse && !($doExpand && $expandedFolderUid == $uid)) { 00200 for ($i = $v['invertedDepth']; $closeDepth[$i] == 1; $i++) { 00201 $closeDepth[$i] = 0; 00202 $itemHTML .= "</ul></li>\n"; 00203 } 00204 } 00205 00206 // ajax request: collapse 00207 if($doCollapse && $expandedFolderUid == $uid) { 00208 $this->ajaxStatus = true; 00209 return $itemHTML; 00210 } 00211 00212 // ajax request: expand 00213 if($doExpand && $expandedFolderUid == $uid) { 00214 $ajaxOutput .= $itemHTML; 00215 $invertedDepthOfAjaxRequestedItem = $v['invertedDepth']; 00216 } elseif($invertedDepthOfAjaxRequestedItem) { 00217 if($v['invertedDepth'] < $invertedDepthOfAjaxRequestedItem) { 00218 $ajaxOutput .= $itemHTML; 00219 } else { 00220 $this->ajaxStatus = true; 00221 return $ajaxOutput; 00222 } 00223 } 00224 00225 $out .= $itemHTML; 00226 } 00227 00228 if($ajaxOutput) { 00229 $this->ajaxStatus = true; 00230 return $ajaxOutput; 00231 } 00232 00233 // finally close the first ul 00234 $out .= "</ul>\n"; 00235 return $out; 00236 } 00237 00238 00251 function PMicon($row,$a,$c,$nextCount,$exp) { 00252 $PM = $nextCount ? ($exp ? 'minus' : 'plus') : 'join'; 00253 $BTM = ($a == $c) ? 'bottom' : ''; 00254 $icon = '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' alt="" />'; 00255 00256 if ($nextCount) { 00257 $cmd = $this->bank.'_'.($exp?'0_':'1_').$row['uid'].'_'.$this->treeName; 00258 $icon = $this->PMiconATagWrap($icon,$cmd,!$exp); 00259 } 00260 return $icon; 00261 } 00262 00263 00272 function PMiconATagWrap($icon, $cmd, $isExpand = true) { 00273 if ($this->thisScript) { 00274 // activate dynamic ajax-based tree 00275 $js = htmlspecialchars('Tree.load(\''.$cmd.'\', '.intval($isExpand).', this);'); 00276 return '<a class="pm" onclick="'.$js.'">'.$icon.'</a>'; 00277 } else { 00278 return $icon; 00279 } 00280 } 00281 00282 00283 00290 function getBrowsableTree() { 00291 00292 // Get stored tree structure AND updating it if needed according to incoming PM GET var. 00293 $this->initializePositionSaving(); 00294 00295 // Init done: 00296 $titleLen = intval($this->BE_USER->uc['titleLen']); 00297 $treeArr = array(); 00298 00299 // Traverse mounts: 00300 foreach($this->MOUNTS as $key => $val) { 00301 $specUID = t3lib_div::md5int($val['path']); 00302 $this->specUIDmap[$specUID] = $val['path']; 00303 00304 // Set first: 00305 $this->bank = $val['nkey']; 00306 $isOpen = $this->stored[$val['nkey']][$specUID] || $this->expandFirst; 00307 $this->reset(); 00308 00309 // Set PM icon: 00310 $cmd = $this->bank.'_'.($isOpen ? '0_' : '1_').$specUID.'_'.$this->treeName; 00311 $icon='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.($isOpen?'minus':'plus').'only.gif').' alt="" />'; 00312 $firstHtml= $this->PM_ATagWrap($icon,$cmd); 00313 00314 switch($val['type']) { 00315 case 'user': $icon = 'gfx/i/_icon_ftp_user.gif'; break; 00316 case 'group': $icon = 'gfx/i/_icon_ftp_group.gif'; break; 00317 default: $icon = 'gfx/i/_icon_ftp.gif'; break; 00318 } 00319 00320 // Preparing rootRec for the mount 00321 $firstHtml.=$this->wrapIcon('<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' alt="" />',$val); 00322 $row=array(); 00323 $row['uid'] = $specUID; 00324 $row['path'] = $val['path']; 00325 $row['title'] = $val['name']; 00326 00327 // Add the root of the mount to ->tree 00328 $this->tree[] = array('HTML' => $firstHtml, 'row' => $row, 'bank' => $this->bank); 00329 00330 // If the mount is expanded, go down: 00331 if ($isOpen) 00332 $this->getFolderTree($val['path'], 999); 00333 00334 // Add tree: 00335 $treeArr = array_merge($treeArr, $this->tree); 00336 } 00337 return $this->printTree($treeArr); 00338 } 00339 00340 00341 00350 function getFolderTree($files_path, $depth=999) { 00351 00352 // This generates the directory tree 00353 $dirs = t3lib_div::get_dirs($files_path); 00354 if (!is_array($dirs)) return 0; 00355 00356 sort($dirs); 00357 $c = count($dirs); 00358 00359 $depth = intval($depth); 00360 $HTML = ''; 00361 $a = 0; 00362 00363 foreach($dirs as $key => $val) { 00364 $a++; 00365 $this->tree[] = array(); // Reserve space. 00366 end($this->tree); 00367 $treeKey = key($this->tree); // Get the key for this space 00368 00369 $val = ereg_replace('^\./','',$val); 00370 $title = $val; 00371 $path = $files_path.$val.'/'; 00372 00373 $specUID = t3lib_div::md5int($path); 00374 $this->specUIDmap[$specUID] = $path; 00375 00376 $row = array(); 00377 $row['path'] = $path; 00378 $row['uid'] = $specUID; 00379 $row['title'] = $title; 00380 00381 // Make a recursive call to the next level 00382 if ($depth > 1 && $this->expandNext($specUID)) { 00383 $nextCount = $this->getFolderTree( 00384 $path, 00385 $depth-1, 00386 $this->makeHTML ? '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.($a == $c ? 'blank' : 'line').'.gif','width="18" height="16"').' alt="" />' : '' 00387 ); 00388 $exp = 1; // Set "did expand" flag 00389 } else { 00390 $nextCount = $this->getCount($path); 00391 $exp = 0; // Clear "did expand" flag 00392 } 00393 00394 // Set HTML-icons, if any: 00395 if ($this->makeHTML) { 00396 $HTML = $this->PMicon($row,$a,$c,$nextCount,$exp); 00397 00398 $icon = 'gfx/i/_icon_'.t3lib_BEfunc::getPathType_web_nonweb($path).'folders.gif'; 00399 if ($val == '_temp_') { 00400 $icon = 'gfx/i/sysf.gif'; 00401 $row['title']='TEMP'; 00402 $row['_title']='<b>TEMP</b>'; 00403 } 00404 if ($val == '_recycler_') { 00405 $icon = 'gfx/i/recycler.gif'; 00406 $row['title']='RECYCLER'; 00407 $row['_title']='<b>RECYCLER</b>'; 00408 } 00409 $HTML .= $this->wrapIcon('<img'.t3lib_iconWorks::skinImg($this->backPath, $icon, 'width="18" height="16"').' alt="" />',$row); 00410 } 00411 00412 // Finally, add the row/HTML content to the ->tree array in the reserved key. 00413 $this->tree[$treeKey] = Array( 00414 'row' => $row, 00415 'HTML' => $HTML, 00416 'hasSub' => $nextCount && $this->expandNext($specUID), 00417 'isFirst'=> ($a == 1), 00418 'isLast' => false, 00419 'invertedDepth'=> $depth, 00420 'bank' => $this->bank 00421 ); 00422 } 00423 00424 if($a) { $this->tree[$treeKey]['isLast'] = true; } 00425 return $c; 00426 } 00427 } 00428 00429 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.filelistfoldertree.php']) { 00430 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.filelistfoldertree.php']); 00431 } 00432 ?>