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
00058 require_once (PATH_t3lib.'class.t3lib_treeview.php');
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00082 class t3lib_folderTree extends t3lib_treeView {
00083
00089 function t3lib_folderTree() {
00090 parent::init();
00091
00092 $this->MOUNTS = $GLOBALS['FILEMOUNTS'];
00093
00094 $this->treeName='folder';
00095 $this->titleAttrib='';
00096 $this->domIdPrefix = 'folder';
00097 }
00098
00107 function wrapIcon($icon,$row) {
00108
00109 $theFolderIcon = $this->addTagAttributes($icon,($this->titleAttrib ? $this->titleAttrib.'="'.$this->getTitleAttrib($row).'"' : ''));
00110
00111
00112 if (!$this->ext_IconMode) {
00113 $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon,$row['path'],'',0);
00114 } elseif (!strcmp($this->ext_IconMode,'titlelink')) {
00115 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'\','.$this->bank.');';
00116 $theFolderIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$theFolderIcon.'</a>';
00117 }
00118 return $theFolderIcon;
00119 }
00120
00130 function wrapTitle($title,$row,$bank=0) {
00131 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'\','.$bank.');';
00132 $CSM = '';
00133 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler']) {
00134 $CSM = ' oncontextmenu="'.htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('',$row['path'],'',0,'','',TRUE)).'"';
00135 }
00136 return '<a href="#" title="'.htmlspecialchars($row['title']).'" onclick="'.htmlspecialchars($aOnClick).'"'.$CSM.'>'.$title.'</a>';
00137 }
00138
00145 function getId($v) {
00146 return t3lib_div::md5Int($v['path']);
00147 }
00148
00155 function getJumpToParam($v) {
00156 return rawurlencode($v['path']);
00157 }
00158
00167 function getTitleStr($row,$titleLen=30) {
00168 return $row['_title'] ? $row['_title'] : parent::getTitleStr($row,$titleLen);
00169 }
00170
00177 function getBrowsableTree() {
00178
00179
00180 $this->initializePositionSaving();
00181
00182
00183 $titleLen=intval($this->BE_USER->uc['titleLen']);
00184 $treeArr=array();
00185
00186
00187 foreach($this->MOUNTS as $key => $val) {
00188 $md5_uid = md5($val['path']);
00189 $specUID=hexdec(substr($md5_uid,0,6));
00190 $this->specUIDmap[$specUID]=$val['path'];
00191
00192
00193 $this->bank=$val['nkey'];
00194 $isOpen = $this->stored[$val['nkey']][$specUID] || $this->expandFirst;
00195 $this->reset();
00196
00197
00198 $cmd=$this->bank.'_'.($isOpen?'0_':'1_').$specUID.'_'.$this->treeName;
00199 $icon='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.($isOpen?'minus':'plus').'only.gif','width="18" height="16"').' alt="" />';
00200 $firstHtml= $this->PM_ATagWrap($icon,$cmd);
00201
00202 switch($val['type']) {
00203 case 'user': $icon = 'gfx/i/_icon_ftp_user.gif'; break;
00204 case 'group': $icon = 'gfx/i/_icon_ftp_group.gif'; break;
00205 default: $icon = 'gfx/i/_icon_ftp.gif'; break;
00206 }
00207
00208
00209 $firstHtml.=$this->wrapIcon('<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' alt="" />',$val);
00210 $row=array();
00211 $row['path']=$val['path'];
00212 $row['uid']=$specUID;
00213 $row['title']=$val['name'];
00214
00215
00216 $this->tree[]=array('HTML'=>$firstHtml,'row'=>$row,'bank'=>$this->bank);
00217
00218
00219 if ($isOpen) {
00220
00221 $depthD='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/blank.gif','width="18" height="16"').' alt="" />';
00222 $this->getFolderTree($val['path'],999,$depthD);
00223 }
00224
00225
00226 $treeArr=array_merge($treeArr,$this->tree);
00227 }
00228 return $this->printTree($treeArr);
00229 }
00230
00240 function getFolderTree($files_path, $depth=999, $depthData='') {
00241
00242
00243 $dirs = t3lib_div::get_dirs($files_path);
00244
00245 $c=0;
00246 if (is_array($dirs)) {
00247 $depth=intval($depth);
00248 $HTML='';
00249 $a=0;
00250 $c=count($dirs);
00251 sort($dirs);
00252
00253 foreach($dirs as $key => $val) {
00254 $a++;
00255 $this->tree[]=array();
00256 end($this->tree);
00257 $treeKey = key($this->tree);
00258 $LN = ($a==$c)?'blank':'line';
00259
00260 $val = ereg_replace('^\./','',$val);
00261 $title = $val;
00262 $path = $files_path.$val.'/';
00263 $webpath=t3lib_BEfunc::getPathType_web_nonweb($path);
00264
00265 $md5_uid = md5($path);
00266 $specUID=hexdec(substr($md5_uid,0,6));
00267 $this->specUIDmap[$specUID]=$path;
00268 $row=array();
00269 $row['path']=$path;
00270 $row['uid']=$specUID;
00271 $row['title']=$title;
00272
00273 if ($depth>1 && $this->expandNext($specUID)) {
00274 $nextCount=$this->getFolderTree(
00275 $path,
00276 $depth-1,
00277 $this->makeHTML ? $depthData.'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$LN.'.gif','width="18" height="16"').' alt="" />' : ''
00278 );
00279 $exp=1;
00280 } else {
00281 $nextCount=$this->getCount($path);
00282 $exp=0;
00283 }
00284
00285
00286 if ($this->makeHTML) {
00287 $HTML=$depthData.$this->PMicon($row,$a,$c,$nextCount,$exp);
00288
00289 $icon = 'gfx/i/_icon_'.$webpath.'folders.gif';
00290 if ($val=='_temp_') {
00291 $icon = 'gfx/i/sysf.gif';
00292 $row['title']='TEMP';
00293 $row['_title']='<b>TEMP</b>';
00294 }
00295 if ($val=='_recycler_') {
00296 $icon = 'gfx/i/recycler.gif';
00297 $row['title']='RECYCLER';
00298 $row['_title']='<b>RECYCLER</b>';
00299 }
00300 $HTML.=$this->wrapIcon('<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' alt="" />',$row);
00301 }
00302
00303
00304 $this->tree[$treeKey] = Array(
00305 'row'=>$row,
00306 'HTML'=>$HTML,
00307 'bank'=>$this->bank
00308 );
00309 }
00310 }
00311 return $c;
00312 }
00313
00320 function getCount($files_path) {
00321
00322 $dirs = t3lib_div::get_dirs($files_path);
00323 $c=0;
00324 if (is_array($dirs)) {
00325 $c=count($dirs);
00326 }
00327 return $c;
00328 }
00329
00336 function initializePositionSaving() {
00337
00338 $this->stored=unserialize($this->BE_USER->uc['browseTrees'][$this->treeName]);
00339
00340
00341 $hashMap=array();
00342 foreach($this->MOUNTS as $key => $val) {
00343 $nkey = hexdec(substr($key,0,4));
00344 $hashMap[$nkey]=$key;
00345 $this->MOUNTS[$key]['nkey']=$nkey;
00346 }
00347
00348
00349
00350 $PM = explode('_',t3lib_div::_GP('PM'));
00351 if (count($PM)==4 && $PM[3]==$this->treeName) {
00352 if (isset($this->MOUNTS[$hashMap[$PM[0]]])) {
00353 if ($PM[1]) {
00354 $this->stored[$PM[0]][$PM[2]]=1;
00355 $this->savePosition($this->treeName);
00356 } else {
00357 unset($this->stored[$PM[0]][$PM[2]]);
00358 $this->savePosition($this->treeName);
00359 }
00360 }
00361 }
00362 }
00363 }
00364
00365 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_foldertree.php']) {
00366 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_foldertree.php']);
00367 }
00368 ?>