Main Page | Directories | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages | Examples

t3lib_folderTree Class Reference

Inherited by localFolderTree.

List of all members.

Public Member Functions

 t3lib_folderTree ()
 Constructor function of the class.
 wrapIcon ($icon, $row)
 Wrapping the folder icon.
 getId ($v)
 Returns the id from the record - for folders, this is an md5 hash.
 getJumpToParam ($v)
 Returns jump-url parameter value.
 getTitleStr ($row, $titleLen=30)
 Returns the title for the input record.
 getBrowsableTree ()
 Will create and return the HTML code for a browsable tree of folders.
 getFolderTree ($files_path, $depth=999, $depthData='')
 Fetches the data for the tree.
 getCount ($files_path)
 Counts the number of directories in a file path.
 initializePositionSaving ()
 Get stored tree structure AND updating it if needed according to incoming PM GET var.


Constructor & Destructor Documentation

t3lib_folderTree::t3lib_folderTree  ) 
 

Constructor function of the class.

Returns:
void

Definition at line 88 of file class.t3lib_foldertree.php.

00088                                  {
00089       parent::init();
00090 
00091       $this->MOUNTS = $GLOBALS['FILEMOUNTS'];
00092 
00093       $this->treeName='folder';
00094       $this->titleAttrib=''; //don't apply any title
00095       $this->domIdPrefix = 'folder';
00096    }


Member Function Documentation

t3lib_folderTree::getBrowsableTree  ) 
 

Will create and return the HTML code for a browsable tree of folders.

Is based on the mounts found in the internal array ->MOUNTS (set in the constructor)

Returns:
string HTML code for the browsable tree

Definition at line 158 of file class.t3lib_foldertree.php.

References $val, getFolderTree(), initializePositionSaving(), and wrapIcon().

00158                                  {
00159 
00160          // Get stored tree structure AND updating it if needed according to incoming PM GET var.
00161       $this->initializePositionSaving();
00162 
00163          // Init done:
00164       $titleLen=intval($this->BE_USER->uc['titleLen']);
00165       $treeArr=array();
00166 
00167          // Traverse mounts:
00168       foreach($this->MOUNTS as $key => $val) {
00169          $md5_uid = md5($val['path']);
00170          $specUID=hexdec(substr($md5_uid,0,6));
00171          $this->specUIDmap[$specUID]=$val['path'];
00172 
00173             // Set first:
00174          $this->bank=$val['nkey'];
00175          $isOpen = $this->stored[$val['nkey']][$specUID] || $this->expandFirst;
00176          $this->reset();
00177 
00178             // Set PM icon:
00179          $cmd=$this->bank.'_'.($isOpen?'0_':'1_').$specUID.'_'.$this->treeName;
00180          $icon='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.($isOpen?'minus':'plus').'only.gif','width="18" height="16"').' alt="" />';
00181          $firstHtml= $this->PM_ATagWrap($icon,$cmd);
00182 
00183          switch($val['type']) {
00184             case 'user':   $icon = 'gfx/i/_icon_ftp_user.gif'; break;
00185             case 'group':  $icon = 'gfx/i/_icon_ftp_group.gif'; break;
00186             default:    $icon = 'gfx/i/_icon_ftp.gif'; break;
00187          }
00188 
00189             // Preparing rootRec for the mount
00190          $firstHtml.=$this->wrapIcon('<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' alt="" />',$val);
00191             $row=array();
00192             $row['path']=$val['path'];
00193             $row['uid']=$specUID;
00194             $row['title']=$val['name'];
00195 
00196             // Add the root of the mount to ->tree
00197          $this->tree[]=array('HTML'=>$firstHtml,'row'=>$row,'bank'=>$this->bank);
00198 
00199             // If the mount is expanded, go down:
00200          if ($isOpen)   {
00201                // Set depth:
00202             $depthD='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/blank.gif','width="18" height="16"').' alt="" />';
00203             $this->getFolderTree($val['path'],999,$depthD);
00204          }
00205 
00206             // Add tree:
00207          $treeArr=array_merge($treeArr,$this->tree);
00208       }
00209       return $this->printTree($treeArr);
00210    }

t3lib_folderTree::getCount files_path  ) 
 

Counts the number of directories in a file path.

Parameters:
string File path.
Returns:
integer

Definition at line 301 of file class.t3lib_foldertree.php.

Referenced by getFolderTree().

00301                                     {
00302          // This generates the directory tree
00303       $dirs = t3lib_div::get_dirs($files_path);
00304       $c=0;
00305       if (is_array($dirs)) {
00306          $c=count($dirs);
00307       }
00308       return $c;
00309    }

t3lib_folderTree::getFolderTree files_path,
depth = 999,
depthData = ''
 

Fetches the data for the tree.

Parameters:
string Abs file path
integer Max depth (recursivity limit)
string HTML-code prefix for recursive calls.
Returns:
integer The count of items on the level
See also:
getBrowsableTree()

Definition at line 221 of file class.t3lib_foldertree.php.

References $a, $val, getCount(), getPathType_web_nonweb(), and wrapIcon().

Referenced by getBrowsableTree().

00221                                                                   {
00222 
00223          // This generates the directory tree
00224       $dirs = t3lib_div::get_dirs($files_path);
00225 
00226       $c=0;
00227       if (is_array($dirs)) {
00228          $depth=intval($depth);
00229          $HTML='';
00230          $a=0;
00231          $c=count($dirs);
00232          sort($dirs);
00233 
00234          foreach($dirs as $key => $val)   {
00235             $a++;
00236             $this->tree[]=array();     // Reserve space.
00237             end($this->tree);
00238             $treeKey = key($this->tree);  // Get the key for this space
00239             $LN = ($a==$c)?'blank':'line';
00240 
00241             $val = ereg_replace('^\./','',$val);
00242             $title = $val;
00243             $path = $files_path.$val.'/';
00244             $webpath=t3lib_BEfunc::getPathType_web_nonweb($path);
00245 
00246             $md5_uid = md5($path);
00247             $specUID=hexdec(substr($md5_uid,0,6));
00248             $this->specUIDmap[$specUID]=$path;
00249             $row=array();
00250             $row['path']=$path;
00251             $row['uid']=$specUID;
00252             $row['title']=$title;
00253 
00254             if ($depth>1 && $this->expandNext($specUID)) {
00255                $nextCount=$this->getFolderTree(
00256                   $path,
00257                   $depth-1,
00258                   $this->makeHTML ? $depthData.'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$LN.'.gif','width="18" height="16"').' alt="" />' : ''
00259                );
00260                $exp=1;     // Set "did expand" flag
00261             } else {
00262                $nextCount=$this->getCount($path);
00263                $exp=0;     // Clear "did expand" flag
00264             }
00265 
00266                // Set HTML-icons, if any:
00267             if ($this->makeHTML) {
00268                $HTML=$depthData.$this->PMicon($row,$a,$c,$nextCount,$exp);
00269 
00270                $icon = 'gfx/i/_icon_'.$webpath.'folders.gif';
00271                if ($val=='_temp_')  {
00272                   $icon = 'gfx/i/sysf.gif';
00273                   $row['title']='TEMP';
00274                   $row['_title']='<b>TEMP</b>';
00275                }
00276                if ($val=='_recycler_') {
00277                   $icon = 'gfx/i/recycler.gif';
00278                   $row['title']='RECYCLER';
00279                   $row['_title']='<b>RECYCLER</b>';
00280                }
00281                $HTML.=$this->wrapIcon('<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' alt="" />',$row);
00282             }
00283 
00284                // Finally, add the row/HTML content to the ->tree array in the reserved key.
00285             $this->tree[$treeKey] = Array(
00286                'row'=>$row,
00287                'HTML'=>$HTML,
00288                'bank'=>$this->bank
00289             );
00290          }
00291       }
00292       return $c;
00293    }

t3lib_folderTree::getId v  ) 
 

Returns the id from the record - for folders, this is an md5 hash.

Parameters:
array Record array
Returns:
integer The "uid" field value.

Definition at line 126 of file class.t3lib_foldertree.php.

00126                       {
00127       return t3lib_div::md5Int($v['path']);
00128    }

t3lib_folderTree::getJumpToParam v  ) 
 

Returns jump-url parameter value.

Parameters:
array The record array.
Returns:
string The jump-url parameter.

Definition at line 136 of file class.t3lib_foldertree.php.

00136                                {
00137       return rawurlencode($v['path']);
00138    }

t3lib_folderTree::getTitleStr row,
titleLen = 30
 

Returns the title for the input record.

If blank, a "no title" labele (localized) will be returned. '_title' is used for setting an alternative title for folders.

Parameters:
array The input row array (where the key "_title" is used for the title)
integer Title length (30)
Returns:
string The title.

Definition at line 148 of file class.t3lib_foldertree.php.

00148                                              {
00149       return $row['_title'] ? $row['_title'] : parent::getTitleStr($row,$titleLen);
00150    }

t3lib_folderTree::initializePositionSaving  ) 
 

Get stored tree structure AND updating it if needed according to incoming PM GET var.

Returns:
void private

Definition at line 317 of file class.t3lib_foldertree.php.

Referenced by getBrowsableTree().

00317                                        {
00318          // Get stored tree structure:
00319       $this->stored=unserialize($this->BE_USER->uc['browseTrees'][$this->treeName]);
00320 
00321          // Mapping md5-hash to shorter number:
00322       $hashMap=array();
00323       foreach($this->MOUNTS as $key => $val) {
00324          $nkey = hexdec(substr($key,0,4));
00325          $hashMap[$nkey]=$key;
00326          $this->MOUNTS[$key]['nkey']=$nkey;
00327       }
00328 
00329          // PM action:
00330          // (If an plus/minus icon has been clicked, the PM GET var is sent and we must update the stored positions in the tree):
00331       $PM = explode('_',t3lib_div::_GP('PM'));  // 0: mount key, 1: set/clear boolean, 2: item ID (cannot contain "_"), 3: treeName
00332       if (count($PM)==4 && $PM[3]==$this->treeName)   {
00333          if (isset($this->MOUNTS[$hashMap[$PM[0]]]))  {
00334             if ($PM[1]) {  // set
00335                $this->stored[$PM[0]][$PM[2]]=1;
00336                $this->savePosition($this->treeName);
00337             } else { // clear
00338                unset($this->stored[$PM[0]][$PM[2]]);
00339                $this->savePosition($this->treeName);
00340             }
00341          }
00342       }
00343    }

t3lib_folderTree::wrapIcon icon,
row
 

Wrapping the folder icon.

Parameters:
string The image tag for the icon
array The row for the current element
Returns:
string The processed icon input value. private

Definition at line 106 of file class.t3lib_foldertree.php.

Referenced by getBrowsableTree(), and getFolderTree().

00106                                  {
00107          // Add title attribute to input icon tag
00108       $theFolderIcon = $this->addTagAttributes($icon,($this->titleAttrib ? $this->titleAttrib.'="'.$this->getTitleAttrib($row).'"' : ''));
00109 
00110          // Wrap icon in click-menu link.
00111       if (!$this->ext_IconMode)  {
00112          $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon,$row['path'],'',0);
00113       } elseif (!strcmp($this->ext_IconMode,'titlelink'))   {
00114          $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'_'.$this->bank.'\');';
00115          $theFolderIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$theFolderIcon.'</a>';
00116       }
00117       return $theFolderIcon;
00118    }


The documentation for this class was generated from the following file:
Generated on Sun Oct 3 01:06:56 2004 for TYPO3core 3.7.0 dev by  doxygen 1.3.8-20040913