00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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;
00071
00077 function filelistFolderTree() {
00078 parent::t3lib_folderTree();
00079 }
00080
00088 function wrapIcon($icon,&$row) {
00089
00090
00091 $theFolderIcon = $this->addTagAttributes($icon,($this->titleAttrib ? $this->titleAttrib.'="'.$this->getTitleAttrib($row).'"' : ''));
00092
00093
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
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
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
00147
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;
00156 $doExpand = true;
00157 } else {
00158 $expandedFolderUid = $PM[2];
00159 $doCollapse = true;
00160 }
00161 }
00162
00163
00164
00165
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
00175
00176 if($v['isFirst'] && !($doCollapse) && !($doExpand && $expandedFolderUid == $uid)) {
00177 $itemHTML = "<ul>\n";
00178 }
00179
00180
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
00193
00194 if($v['isLast'] && !($doExpand && $expandedFolderUid == $uid)) { $closeDepth[$v['invertedDepth']] = 1; }
00195
00196
00197
00198
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
00207 if($doCollapse && $expandedFolderUid == $uid) {
00208 $this->ajaxStatus = true;
00209 return $itemHTML;
00210 }
00211
00212
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
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
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
00293 $this->initializePositionSaving();
00294
00295
00296 $titleLen = intval($this->BE_USER->uc['titleLen']);
00297 $treeArr = array();
00298
00299
00300 foreach($this->MOUNTS as $key => $val) {
00301 $specUID = t3lib_div::md5int($val['path']);
00302 $this->specUIDmap[$specUID] = $val['path'];
00303
00304
00305 $this->bank = $val['nkey'];
00306 $isOpen = $this->stored[$val['nkey']][$specUID] || $this->expandFirst;
00307 $this->reset();
00308
00309
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
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
00328 $this->tree[] = array('HTML' => $firstHtml, 'row' => $row, 'bank' => $this->bank);
00329
00330
00331 if ($isOpen)
00332 $this->getFolderTree($val['path'], 999);
00333
00334
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
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();
00366 end($this->tree);
00367 $treeKey = key($this->tree);
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
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;
00389 } else {
00390 $nextCount = $this->getCount($path);
00391 $exp = 0;
00392 }
00393
00394
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
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 ?>