|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2011 Kasper Skårhøj (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 ***************************************************************/ 00027 /** 00028 * Folder navigation tree for the File main module 00029 * 00030 * @author Benjamin Mack <bmack@xnos.org> 00031 * 00032 * 00033 * [CLASS/FUNCTION INDEX of SCRIPT] 00034 * 00035 * 00036 * 00037 * 71: class fileListTree extends t3lib_browseTree 00038 * 81: function webPageTree() 00039 * 92: function wrapIcon($icon,&$row) 00040 * 130: function wrapStop($str,$row) 00041 * 146: function wrapTitle($title,$row,$bank=0) 00042 * 165: function printTree($treeArr = '') 00043 * 271: function PMicon($row,$a,$c,$nextCount,$exp) 00044 * 292: function PMiconATagWrap($icon, $cmd, $isExpand = true) 00045 * 309: function getBrowsableTree() 00046 * 377: function getTree($uid, $depth=999, $depthData='',$blankLineCode='',$subCSSclass='') 00047 * 00048 * 00049 * TOTAL FUNCTIONS: 9 00050 * (This index is automatically created/updated by the extension "extdeveval") 00051 * 00052 */ 00053 /** 00054 * Extension class for the t3lib_filetree class, needed for drag and drop and ajax functionality 00055 * 00056 * @author Sebastian Kurfürst <sebastian@garbage-group.de> 00057 * @author Benjamin Mack <bmack@xnos.org> 00058 * @package TYPO3 00059 * @subpackage core 00060 * @see class t3lib_browseTree 00061 */ 00062 class filelistFolderTree extends t3lib_folderTree { 00063 00064 var $ext_IconMode; 00065 var $ajaxStatus = false; // Indicates, whether the ajax call was successful, i.e. the requested page has been found 00066 00067 /** 00068 * Calls init functions 00069 * 00070 * @return void 00071 */ 00072 function filelistFolderTree() { 00073 parent::t3lib_folderTree(); 00074 } 00075 00076 /** 00077 * Wrapping icon in browse tree 00078 * 00079 * @param string Icon IMG code 00080 * @param array Data row for element. 00081 * @return string Page icon 00082 */ 00083 function wrapIcon($theFolderIcon, &$row) { 00084 00085 // Wrap icon in click-menu link. 00086 if (!$this->ext_IconMode) { 00087 $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon,$row['path'],'',0); 00088 } elseif (!strcmp($this->ext_IconMode,'titlelink')) { 00089 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'\','.$this->bank.');'; 00090 $theFolderIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$theFolderIcon.'</a>'; 00091 } 00092 // Wrap icon in a drag/drop span. 00093 return '<span class="dragIcon" id="dragIconID_'.$this->getJumpToParam($row).'">'.$theFolderIcon.'</span>'; 00094 } 00095 00096 00097 /** 00098 * Wrapping $title in a-tags. 00099 * 00100 * @param string Title string 00101 * @param string Item record 00102 * @param integer Bank pointer (which mount point number) 00103 * @return string 00104 * @access private 00105 */ 00106 function wrapTitle($title,$row,$bank=0) { 00107 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'\','.$bank.');'; 00108 $CSM = ''; 00109 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler']) { 00110 $CSM = ' oncontextmenu="'.htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('',$row['path'],'',0,'&bank='.$this->bank,'',TRUE)).'"'; 00111 } 00112 $theFolderTitle='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"'.$CSM.'>'.$title.'</a>'; 00113 00114 // Wrap title in a drag/drop span. 00115 return '<span class="dragTitle" id="dragTitleID_'.$this->getJumpToParam($row).'">'.$theFolderTitle.'</span>'; 00116 } 00117 00118 00119 00120 00121 /** 00122 * Compiles the HTML code for displaying the structure found inside the ->tree array 00123 * 00124 * @param array "tree-array" - if blank string, the internal ->tree array is used. 00125 * @return string The HTML code for the tree 00126 */ 00127 function printTree($treeArr='') { 00128 $titleLen = intval($this->BE_USER->uc['titleLen']); 00129 if (!is_array($treeArr)) $treeArr = $this->tree; 00130 00131 $out = ' 00132 <!-- TYPO3 folder tree structure. --> 00133 <ul class="tree" id="treeRoot"> 00134 '; 00135 $titleLen=intval($this->BE_USER->uc['titleLen']); 00136 if (!is_array($treeArr)) $treeArr=$this->tree; 00137 00138 // -- evaluate AJAX request 00139 // IE takes anchor as parameter 00140 $PM = t3lib_div::_GP('PM'); 00141 if(($PMpos = strpos($PM, '#')) !== false) { $PM = substr($PM, 0, $PMpos); } 00142 $PM = explode('_', $PM); 00143 if((TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) && is_array($PM) && count($PM)==4) { 00144 if($PM[1]) { 00145 $expandedFolderUid = $PM[2]; 00146 $ajaxOutput = ''; 00147 $invertedDepthOfAjaxRequestedItem = 0; // We don't know yet. Will be set later. 00148 $doExpand = true; 00149 } else { 00150 $expandedFolderUid = $PM[2]; 00151 $doCollapse = true; 00152 } 00153 } 00154 00155 00156 // we need to count the opened <ul>'s every time we dig into another level, 00157 // so we know how many we have to close when all children are done rendering 00158 $closeDepth = array(); 00159 00160 foreach($treeArr as $k => $v) { 00161 $classAttr = $v['row']['_CSSCLASS']; 00162 $uid = $v['row']['uid']; 00163 $idAttr = htmlspecialchars($this->domIdPrefix.$this->getId($v['row']).'_'.$v['bank']); 00164 $itemHTML = ''; 00165 00166 // if this item is the start of a new level, 00167 // then a new level <ul> is needed, but not in ajax mode 00168 if($v['isFirst'] && !($doCollapse) && !($doExpand && $expandedFolderUid == $uid)) { 00169 $itemHTML = "<ul>\n"; 00170 } 00171 00172 // add CSS classes to the list item 00173 if($v['hasSub']) { $classAttr = ($classAttr) ? ' expanded': 'expanded'; } 00174 if($v['isLast']) { $classAttr = ($classAttr) ? ' last' : 'last'; } 00175 00176 $itemHTML .=' 00177 <li id="'.$idAttr.'"'.($classAttr ? ' class="'.$classAttr.'"' : '').'><div class="treeLinkItem">'. 00178 $v['HTML']. 00179 $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$v['bank']) . '</div>'; 00180 00181 00182 if(!$v['hasSub']) { $itemHTML .= "</li>\n"; } 00183 00184 // we have to remember if this is the last one 00185 // on level X so the last child on level X+1 closes the <ul>-tag 00186 if($v['isLast'] && !($doExpand && $expandedFolderUid == $uid)) { $closeDepth[$v['invertedDepth']] = 1; } 00187 00188 00189 // if this is the last one and does not have subitems, we need to close 00190 // the tree as long as the upper levels have last items too 00191 if($v['isLast'] && !$v['hasSub'] && !$doCollapse && !($doExpand && $expandedFolderUid == $uid)) { 00192 for ($i = $v['invertedDepth']; $closeDepth[$i] == 1; $i++) { 00193 $closeDepth[$i] = 0; 00194 $itemHTML .= "</ul></li>\n"; 00195 } 00196 } 00197 00198 // ajax request: collapse 00199 if($doCollapse && $expandedFolderUid == $uid) { 00200 $this->ajaxStatus = true; 00201 return $itemHTML; 00202 } 00203 00204 // ajax request: expand 00205 if($doExpand && $expandedFolderUid == $uid) { 00206 $ajaxOutput .= $itemHTML; 00207 $invertedDepthOfAjaxRequestedItem = $v['invertedDepth']; 00208 } elseif($invertedDepthOfAjaxRequestedItem) { 00209 if($v['invertedDepth'] < $invertedDepthOfAjaxRequestedItem) { 00210 $ajaxOutput .= $itemHTML; 00211 } else { 00212 $this->ajaxStatus = true; 00213 return $ajaxOutput; 00214 } 00215 } 00216 00217 $out .= $itemHTML; 00218 } 00219 00220 if($ajaxOutput) { 00221 $this->ajaxStatus = true; 00222 return $ajaxOutput; 00223 } 00224 00225 // finally close the first ul 00226 $out .= "</ul>\n"; 00227 return $out; 00228 } 00229 00230 00231 /** 00232 * Generate the plus/minus icon for the browsable tree. 00233 * 00234 * @param array record for the entry 00235 * @param integer The current entry number 00236 * @param integer The total number of entries. If equal to $a, a "bottom" element is returned. 00237 * @param integer The number of sub-elements to the current element. 00238 * @param boolean The element was expanded to render subelements if this flag is set. 00239 * @return string Image tag with the plus/minus icon. 00240 * @access private 00241 * @see t3lib_pageTree::PMicon() 00242 */ 00243 function PMicon($row,$a,$c,$nextCount,$exp) { 00244 $PM = $nextCount ? ($exp ? 'minus' : 'plus') : 'join'; 00245 $BTM = ($a == $c) ? 'bottom' : ''; 00246 $icon = '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' alt="" />'; 00247 00248 if ($nextCount) { 00249 $cmd = $this->bank.'_'.($exp?'0_':'1_').$row['uid'].'_'.$this->treeName; 00250 $icon = $this->PMiconATagWrap($icon,$cmd,!$exp); 00251 } 00252 return $icon; 00253 } 00254 00255 00256 /** 00257 * Wrap the plus/minus icon in a link 00258 * 00259 * @param string HTML string to wrap, probably an image tag. 00260 * @param string Command for 'PM' get var 00261 * @return string Link-wrapped input string 00262 * @access private 00263 */ 00264 function PMiconATagWrap($icon, $cmd, $isExpand = true) { 00265 if ($this->thisScript) { 00266 // activate dynamic ajax-based tree 00267 $js = htmlspecialchars('Tree.load(\''.$cmd.'\', '.intval($isExpand).', this);'); 00268 return '<a class="pm" onclick="'.$js.'">'.$icon.'</a>'; 00269 } else { 00270 return $icon; 00271 } 00272 } 00273 00274 00275 00276 /** 00277 * Will create and return the HTML code for a browsable tree of folders. 00278 * Is based on the mounts found in the internal array ->MOUNTS (set in the constructor) 00279 * 00280 * @return string HTML code for the browsable tree 00281 */ 00282 function getBrowsableTree() { 00283 00284 // Get stored tree structure AND updating it if needed according to incoming PM GET var. 00285 $this->initializePositionSaving(); 00286 00287 // Init done: 00288 $titleLen = intval($this->BE_USER->uc['titleLen']); 00289 $treeArr = array(); 00290 00291 // Traverse mounts: 00292 foreach($this->MOUNTS as $key => $val) { 00293 $hasSub = false; 00294 $specUID = t3lib_div::md5int($val['path']); 00295 $this->specUIDmap[$specUID] = $val['path']; 00296 00297 // Set first: 00298 $this->bank = $val['nkey']; 00299 $isOpen = $this->stored[$val['nkey']][$specUID] || $this->expandFirst; 00300 $this->reset(); 00301 00302 // Set PM icon: 00303 $cmd = $this->bank.'_'.($isOpen ? '0_' : '1_').$specUID.'_'.$this->treeName; 00304 $icon='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.($isOpen? 'minus':'plus').'only.gif').' alt="" />'; 00305 $firstHtml= $this->PM_ATagWrap($icon,$cmd); 00306 00307 switch ($val['type']) { 00308 case 'user': 00309 $icon = 'apps-filetree-folder-user'; 00310 break; 00311 case 'group': 00312 $icon = 'apps-filetree-folder-user'; 00313 break; 00314 case 'readonly': 00315 $icon = 'apps-filetree-folder-locked'; 00316 break; 00317 default: 00318 $icon = 'apps-filetree-mount'; 00319 break; 00320 } 00321 00322 // Preparing rootRec for the mount 00323 $firstHtml.=$this->wrapIcon(t3lib_iconWorks::getSpriteIcon($icon),$val); 00324 $row=array(); 00325 $row['uid'] = $specUID; 00326 $row['path'] = $val['path']; 00327 $row['title'] = $val['name']; 00328 00329 // hasSub is true when the root of the mount is expanded 00330 if ($isOpen) { 00331 $hasSub = true; 00332 } 00333 // Add the root of the mount to ->tree 00334 $this->tree[] = array('HTML' => $firstHtml, 'row' => $row, 'bank' => $this->bank, 'hasSub' => $hasSub); 00335 00336 // If the mount is expanded, go down: 00337 if ($isOpen) 00338 $this->getFolderTree($val['path'], 999, $val['type']); 00339 00340 // Add tree: 00341 $treeArr = array_merge($treeArr, $this->tree); 00342 00343 // if this is an AJAX call, don't run through all mounts, only 00344 // show the expansion of the current one, not the rest of the mounts 00345 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) { 00346 break; 00347 } 00348 } 00349 return $this->printTree($treeArr); 00350 } 00351 00352 00353 00354 /** 00355 * Fetches the data for the tree 00356 * 00357 * @param string Abs file path 00358 * @param integer Max depth (recursivity limit) 00359 * @return integer The count of items on the level 00360 * @see getBrowsableTree() 00361 */ 00362 function getFolderTree($files_path, $depth=999, $type='') { 00363 00364 // This generates the directory tree 00365 $dirs = t3lib_div::get_dirs($files_path); 00366 if (!is_array($dirs)) return 0; 00367 00368 sort($dirs); 00369 $c = count($dirs); 00370 00371 $depth = intval($depth); 00372 $HTML = ''; 00373 $a = 0; 00374 00375 foreach($dirs as $key => $val) { 00376 $a++; 00377 $this->tree[] = array(); // Reserve space. 00378 end($this->tree); 00379 $treeKey = key($this->tree); // Get the key for this space 00380 00381 $val = preg_replace('/^\.\//','',$val); 00382 $title = $val; 00383 $path = $files_path.$val.'/'; 00384 00385 $specUID = t3lib_div::md5int($path); 00386 $this->specUIDmap[$specUID] = $path; 00387 00388 $row = array(); 00389 $row['path'] = $path; 00390 $row['uid'] = $specUID; 00391 $row['title'] = $title; 00392 00393 // Make a recursive call to the next level 00394 if ($depth > 1 && $this->expandNext($specUID)) { 00395 $nextCount = $this->getFolderTree( 00396 $path, 00397 $depth-1, 00398 $this->makeHTML ? '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.($a == $c ? 'blank' : 'line').'.gif','width="18" height="16"').' alt="" />' : '', 00399 $type 00400 ); 00401 $exp = 1; // Set "did expand" flag 00402 } else { 00403 $nextCount = $this->getCount($path); 00404 $exp = 0; // Clear "did expand" flag 00405 } 00406 00407 // Set HTML-icons, if any: 00408 if ($this->makeHTML) { 00409 $HTML = $this->PMicon($row,$a,$c,$nextCount,$exp); 00410 00411 $webpath = t3lib_BEfunc::getPathType_web_nonweb($path); 00412 00413 if (is_writable($path)) { 00414 $type = ''; 00415 $overlays = array(); 00416 } else { 00417 $type = 'readonly'; 00418 $overlays= array('status-overlay-locked'=>array()); 00419 00420 } 00421 00422 if ($exp) { 00423 $icon = 'apps-filetree-folder-opened'; 00424 } else { 00425 $icon = 'apps-filetree-folder-default'; 00426 } 00427 if ($val == '_temp_') { 00428 $icon = 'apps-filetree-folder-temp'; 00429 $row['title'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:temp', true); 00430 $row['_title'] = '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:temp', true) . '</strong>'; 00431 } 00432 if ($val == '_recycler_') { 00433 $icon = 'apps-filetree-folder-recycler'; 00434 $row['title'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:recycler', true); 00435 $row['_title'] = '<strong>' .$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:recycler', true) . '</strong>'; 00436 } 00437 $HTML .= $this->wrapIcon(t3lib_iconWorks::getSpriteIcon($icon,array('title'=>$row['title']),$overlays),$row); 00438 } 00439 00440 // Finally, add the row/HTML content to the ->tree array in the reserved key. 00441 $this->tree[$treeKey] = Array( 00442 'row' => $row, 00443 'HTML' => $HTML, 00444 'hasSub' => $nextCount && $this->expandNext($specUID), 00445 'isFirst'=> ($a == 1), 00446 'isLast' => false, 00447 'invertedDepth'=> $depth, 00448 'bank' => $this->bank 00449 ); 00450 } 00451 00452 if($a) { $this->tree[$treeKey]['isLast'] = true; } 00453 return $c; 00454 } 00455 } 00456 00457 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/class.filelistfoldertree.php'])) { 00458 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/class.filelistfoldertree.php']); 00459 } 00460 00461 ?>
1.8.0