2 /***************************************************************
5 * (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Folder navigation tree for the File main module
30 * @author Benjamin Mack <bmack@xnos.org>
33 * [CLASS/FUNCTION INDEX of SCRIPT]
37 * 71: class fileListTree extends t3lib_browseTree
38 * 81: function webPageTree()
39 * 92: function wrapIcon($icon,&$row)
40 * 130: function wrapStop($str,$row)
41 * 146: function wrapTitle($title,$row,$bank=0)
42 * 165: function printTree($treeArr = '')
43 * 271: function PMicon($row,$a,$c,$nextCount,$exp)
44 * 292: function PMiconATagWrap($icon, $cmd, $isExpand = true)
45 * 309: function getBrowsableTree()
46 * 377: function getTree($uid, $depth=999, $depthData='',$blankLineCode='',$subCSSclass='')
50 * (This index is automatically created/updated by the extension "extdeveval")
54 require_once (PATH_t3lib
.'class.t3lib_foldertree.php');
59 * Extension class for the t3lib_filetree class, needed for drag and drop and ajax functionality
61 * @author Sebastian Kurfuerst <sebastian@garbage-group.de>
62 * @author Benjamin Mack <bmack@xnos.org>
65 * @see class t3lib_browseTree
67 class filelistFolderTree
extends t3lib_folderTree
{
70 var $ajaxStatus = false; // Indicates, whether the ajax call was successful, i.e. the requested page has been found
73 * Calls init functions
77 function filelistFolderTree() {
78 parent
::t3lib_folderTree();
82 * Wrapping icon in browse tree
84 * @param string Icon IMG code
85 * @param array Data row for element.
86 * @return string Page icon
88 function wrapIcon($icon,&$row) {
90 // Add title attribute to input icon tag
91 $theFolderIcon = $this->addTagAttributes($icon,($this->titleAttrib ?
$this->titleAttrib
.'="'.$this->getTitleAttrib($row).'"' : ''));
93 // Wrap icon in click-menu link.
94 if (!$this->ext_IconMode
) {
95 $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon,$row['path'],'',0);
96 } elseif (!strcmp($this->ext_IconMode
,'titlelink')) {
97 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix
.$this->getId($row).'\','.$this->bank
.');';
98 $theFolderIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$theFolderIcon.'</a>';
100 // Wrap icon in a drag/drop span.
101 return '<span class="dragIcon" id="dragIconID_'.$this->getJumpToParam($row).'">'.$theFolderIcon.'</span>';
106 * Wrapping $title in a-tags.
108 * @param string Title string
109 * @param string Item record
110 * @param integer Bank pointer (which mount point number)
114 function wrapTitle($title,$row,$bank=0) {
115 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix
.$this->getId($row).'\','.$bank.');';
117 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler']) {
118 $CSM = ' oncontextmenu="'.htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('',$row['path'],'',0,'&bank='.$this->bank
,'',TRUE)).'"';
120 $theFolderTitle='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"'.$CSM.'>'.$title.'</a>';
122 // Wrap title in a drag/drop span.
123 return '<span class="dragTitle" id="dragTitleID_'.$this->getJumpToParam($row).'">'.$theFolderTitle.'</span>';
130 * Compiles the HTML code for displaying the structure found inside the ->tree array
132 * @param array "tree-array" - if blank string, the internal ->tree array is used.
133 * @return string The HTML code for the tree
135 function printTree($treeArr='') {
136 $titleLen = intval($this->BE_USER
->uc
['titleLen']);
137 if (!is_array($treeArr)) $treeArr = $this->tree
;
140 <!-- TYPO3 folder tree structure. -->
143 $titleLen=intval($this->BE_USER
->uc
['titleLen']);
144 if (!is_array($treeArr)) $treeArr=$this->tree
;
146 // -- evaluate AJAX request
147 // IE takes anchor as parameter
148 $PM = t3lib_div
::_GP('PM');
149 if(($PMpos = strpos($PM, '#')) !== false) { $PM = substr($PM, 0, $PMpos); }
150 $PM = explode('_', $PM);
151 if((TYPO3_REQUESTTYPE
& TYPO3_REQUESTTYPE_AJAX
) && is_array($PM) && count($PM)==4) {
153 $expandedFolderUid = $PM[2];
155 $invertedDepthOfAjaxRequestedItem = 0; // We don't know yet. Will be set later.
158 $expandedFolderUid = $PM[2];
164 // we need to count the opened <ul>'s every time we dig into another level,
165 // so we know how many we have to close when all children are done rendering
166 $closeDepth = array();
168 foreach($treeArr as $k => $v) {
169 $classAttr = $v['row']['_CSSCLASS'];
170 $uid = $v['row']['uid'];
171 $idAttr = htmlspecialchars($this->domIdPrefix
.$this->getId($v['row']).'_'.$v['bank']);
174 // if this item is the start of a new level,
175 // then a new level <ul> is needed, but not in ajax mode
176 if($v['isFirst'] && !($doCollapse) && !($doExpand && $expandedFolderUid == $uid)) {
177 $itemHTML = "<ul>\n";
180 // add CSS classes to the list item
181 if($v['hasSub']) { $classAttr = ($classAttr) ?
' expanded': 'expanded'; }
182 if($v['isLast']) { $classAttr = ($classAttr) ?
' last' : 'last'; }
185 <li id="'.$idAttr.'"'.($classAttr ?
' class="'.$classAttr.'"' : '').'>'.
187 $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$v['bank']);
190 if(!$v['hasSub']) { $itemHTML .= "</li>\n"; }
192 // we have to remember if this is the last one
193 // on level X so the last child on level X+1 closes the <ul>-tag
194 if($v['isLast'] && !($doExpand && $expandedFolderUid == $uid)) { $closeDepth[$v['invertedDepth']] = 1; }
197 // if this is the last one and does not have subitems, we need to close
198 // the tree as long as the upper levels have last items too
199 if($v['isLast'] && !$v['hasSub'] && !$doCollapse && !($doExpand && $expandedFolderUid == $uid)) {
200 for ($i = $v['invertedDepth']; $closeDepth[$i] == 1; $i++
) {
202 $itemHTML .= "</ul></li>\n";
206 // ajax request: collapse
207 if($doCollapse && $expandedFolderUid == $uid) {
208 $this->ajaxStatus
= true;
212 // ajax request: expand
213 if($doExpand && $expandedFolderUid == $uid) {
214 $ajaxOutput .= $itemHTML;
215 $invertedDepthOfAjaxRequestedItem = $v['invertedDepth'];
216 } elseif($invertedDepthOfAjaxRequestedItem) {
217 if($v['invertedDepth'] < $invertedDepthOfAjaxRequestedItem) {
218 $ajaxOutput .= $itemHTML;
220 $this->ajaxStatus
= true;
229 $this->ajaxStatus
= true;
233 // finally close the first ul
240 * Generate the plus/minus icon for the browsable tree.
242 * @param array record for the entry
243 * @param integer The current entry number
244 * @param integer The total number of entries. If equal to $a, a "bottom" element is returned.
245 * @param integer The number of sub-elements to the current element.
246 * @param boolean The element was expanded to render subelements if this flag is set.
247 * @return string Image tag with the plus/minus icon.
249 * @see t3lib_pageTree::PMicon()
251 function PMicon($row,$a,$c,$nextCount,$exp) {
252 $PM = $nextCount ?
($exp ?
'minus' : 'plus') : 'join';
253 $BTM = ($a == $c) ?
'bottom' : '';
254 $icon = '<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' alt="" />';
257 $cmd = $this->bank
.'_'.($exp?
'0_':'1_').$row['uid'].'_'.$this->treeName
;
258 $icon = $this->PMiconATagWrap($icon,$cmd,!$exp);
265 * Wrap the plus/minus icon in a link
267 * @param string HTML string to wrap, probably an image tag.
268 * @param string Command for 'PM' get var
269 * @return string Link-wrapped input string
272 function PMiconATagWrap($icon, $cmd, $isExpand = true) {
273 if ($this->thisScript
) {
274 // activate dynamic ajax-based tree
275 $js = htmlspecialchars('Tree.load(\''.$cmd.'\', '.intval($isExpand).', this);');
276 return '<a class="pm" onclick="'.$js.'">'.$icon.'</a>';
285 * Will create and return the HTML code for a browsable tree of folders.
286 * Is based on the mounts found in the internal array ->MOUNTS (set in the constructor)
288 * @return string HTML code for the browsable tree
290 function getBrowsableTree() {
292 // Get stored tree structure AND updating it if needed according to incoming PM GET var.
293 $this->initializePositionSaving();
296 $titleLen = intval($this->BE_USER
->uc
['titleLen']);
300 foreach($this->MOUNTS
as $key => $val) {
301 $specUID = t3lib_div
::md5int($val['path']);
302 $this->specUIDmap
[$specUID] = $val['path'];
305 $this->bank
= $val['nkey'];
306 $isOpen = $this->stored
[$val['nkey']][$specUID] ||
$this->expandFirst
;
310 $cmd = $this->bank
.'_'.($isOpen ?
'0_' : '1_').$specUID.'_'.$this->treeName
;
311 $icon='<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.($isOpen?
'minus':'plus').'only.gif').' alt="" />';
312 $firstHtml= $this->PM_ATagWrap($icon,$cmd);
314 switch($val['type']) {
315 case 'user': $icon = 'gfx/i/_icon_ftp_user.gif'; break;
316 case 'group': $icon = 'gfx/i/_icon_ftp_group.gif'; break;
317 default: $icon = 'gfx/i/_icon_ftp.gif'; break;
320 // Preparing rootRec for the mount
321 $firstHtml.=$this->wrapIcon('<img'.t3lib_iconWorks
::skinImg($this->backPath
,$icon,'width="18" height="16"').' alt="" />',$val);
323 $row['uid'] = $specUID;
324 $row['path'] = $val['path'];
325 $row['title'] = $val['name'];
327 // Add the root of the mount to ->tree
328 $this->tree
[] = array('HTML' => $firstHtml, 'row' => $row, 'bank' => $this->bank
);
330 // If the mount is expanded, go down:
332 $this->getFolderTree($val['path'], 999);
335 $treeArr = array_merge($treeArr, $this->tree
);
337 return $this->printTree($treeArr);
343 * Fetches the data for the tree
345 * @param string Abs file path
346 * @param integer Max depth (recursivity limit)
347 * @return integer The count of items on the level
348 * @see getBrowsableTree()
350 function getFolderTree($files_path, $depth=999) {
352 // This generates the directory tree
353 $dirs = t3lib_div
::get_dirs($files_path);
354 if (!is_array($dirs)) return 0;
359 $depth = intval($depth);
363 foreach($dirs as $key => $val) {
365 $this->tree
[] = array(); // Reserve space.
367 $treeKey = key($this->tree
); // Get the key for this space
369 $val = ereg_replace('^\./','',$val);
371 $path = $files_path.$val.'/';
373 $specUID = t3lib_div
::md5int($path);
374 $this->specUIDmap
[$specUID] = $path;
377 $row['path'] = $path;
378 $row['uid'] = $specUID;
379 $row['title'] = $title;
381 // Make a recursive call to the next level
382 if ($depth > 1 && $this->expandNext($specUID)) {
383 $nextCount = $this->getFolderTree(
386 $this->makeHTML ?
'<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.($a == $c ?
'blank' : 'line').'.gif','width="18" height="16"').' alt="" />' : ''
388 $exp = 1; // Set "did expand" flag
390 $nextCount = $this->getCount($path);
391 $exp = 0; // Clear "did expand" flag
394 // Set HTML-icons, if any:
395 if ($this->makeHTML
) {
396 $HTML = $this->PMicon($row,$a,$c,$nextCount,$exp);
398 $icon = 'gfx/i/_icon_'.t3lib_BEfunc
::getPathType_web_nonweb($path).'folders.gif';
399 if ($val == '_temp_') {
400 $icon = 'gfx/i/sysf.gif';
401 $row['title']='TEMP';
402 $row['_title']='<b>TEMP</b>';
404 if ($val == '_recycler_') {
405 $icon = 'gfx/i/recycler.gif';
406 $row['title']='RECYCLER';
407 $row['_title']='<b>RECYCLER</b>';
409 $HTML .= $this->wrapIcon('<img'.t3lib_iconWorks
::skinImg($this->backPath
, $icon, 'width="18" height="16"').' alt="" />',$row);
412 // Finally, add the row/HTML content to the ->tree array in the reserved key.
413 $this->tree
[$treeKey] = Array(
416 'hasSub' => $nextCount && $this->expandNext($specUID),
417 'isFirst'=> ($a == 1),
419 'invertedDepth'=> $depth,
420 'bank' => $this->bank
424 if($a) { $this->tree
[$treeKey]['isLast'] = true; }
429 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/class.filelistfoldertree.php']) {
430 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/class.filelistfoldertree.php']);