121325c0223f858a7681d052cc59806f16ff2396
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
{
72 * Calls init functions
76 function filelistFolderTree() {
77 parent
::t3lib_folderTree();
81 * Wrapping icon in browse tree
83 * @param string Icon IMG code
84 * @param array Data row for element.
85 * @return string Page icon
87 function wrapIcon($icon,&$row) {
89 // Add title attribute to input icon tag
90 $theFolderIcon = $this->addTagAttributes($icon,($this->titleAttrib ?
$this->titleAttrib
.'="'.$this->getTitleAttrib($row).'"' : ''));
92 // Wrap icon in click-menu link.
93 if (!$this->ext_IconMode
) {
94 $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon,$row['path'],'',0);
95 } elseif (!strcmp($this->ext_IconMode
,'titlelink')) {
96 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix
.$this->getId($row).'\','.$this->bank
.');';
97 $theFolderIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$theFolderIcon.'</a>';
99 // Wrap icon in a drag/drop span.
100 return '<span class="dragIcon" id="dragIconID_'.$this->getJumpToParam($row).'">'.$theFolderIcon.'</span>';
105 * Wrapping $title in a-tags.
107 * @param string Title string
108 * @param string Item record
109 * @param integer Bank pointer (which mount point number)
113 function wrapTitle($title,$row,$bank=0) {
114 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix
.$this->getId($row).'\','.$bank.');';
116 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler']) {
117 $CSM = ' oncontextmenu="'.htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('',$row['path'],'',0,'&bank='.$this->bank
,'',TRUE)).'"';
119 $theFolderTitle='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"'.$CSM.'>'.$title.'</a>';
121 // Wrap title in a drag/drop span.
122 return '<span class="dragTitle" id="dragTitleID_'.$this->getJumpToParam($row).'">'.$theFolderTitle.'</span>';
129 * Compiles the HTML code for displaying the structure found inside the ->tree array
131 * @param array "tree-array" - if blank string, the internal ->tree array is used.
132 * @return string The HTML code for the tree
134 function printTree($treeArr='') {
135 $titleLen = intval($this->BE_USER
->uc
['titleLen']);
136 if (!is_array($treeArr)) $treeArr = $this->tree
;
139 <!-- TYPO3 folder tree structure. -->
142 $titleLen=intval($this->BE_USER
->uc
['titleLen']);
143 if (!is_array($treeArr)) $treeArr=$this->tree
;
145 // -- evaluate AJAX request
146 // IE takes anchor as parameter
147 $PM = t3lib_div
::_GP('PM');
148 if(($PMpos = strpos($PM, '#')) !== false) { $PM = substr($PM, 0, $PMpos); }
149 $PM = explode('_', $PM);
150 if(($isAjaxCall = t3lib_div
::_GP('ajax')) && is_array($PM) && count($PM)==4) {
152 $expandedFolderUid = $PM[2];
154 $invertedDepthOfAjaxRequestedItem = 0; // We don't know yet. Will be set later.
157 $expandedFolderUid = $PM[2];
163 // we need to count the opened <ul>'s every time we dig into another level,
164 // so we know how many we have to close when all children are done rendering
165 $closeDepth = array();
167 foreach($treeArr as $k => $v) {
168 $classAttr = $v['row']['_CSSCLASS'];
169 $uid = $v['row']['uid'];
170 $idAttr = htmlspecialchars($this->domIdPrefix
.$this->getId($v['row']).'_'.$v['bank']);
173 // if this item is the start of a new level,
174 // then a new level <ul> is needed, but not in ajax mode
175 if($v['isFirst'] && !($doCollapse) && !($doExpand && $expandedFolderUid == $uid)) {
176 $itemHTML = "<ul>\n";
179 // add CSS classes to the list item
180 if($v['hasSub']) { $classAttr = ($classAttr) ?
' expanded': 'expanded'; }
181 if($v['isLast']) { $classAttr = ($classAttr) ?
' last' : 'last'; }
184 <li id="'.$idAttr.'"'.($classAttr ?
' class="'.$classAttr.'"' : '').'>'.
186 $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$v['bank']);
189 if(!$v['hasSub']) { $itemHTML .= "</li>\n"; }
191 // we have to remember if this is the last one
192 // on level X so the last child on level X+1 closes the <ul>-tag
193 if($v['isLast'] && !($doExpand && $expandedFolderUid == $uid)) { $closeDepth[$v['invertedDepth']] = 1; }
196 // if this is the last one and does not have subitems, we need to close
197 // the tree as long as the upper levels have last items too
198 if($v['isLast'] && !$v['hasSub'] && !$doCollapse && !($doExpand && $expandedFolderUid == $uid)) {
199 for ($i = $v['invertedDepth']; $closeDepth[$i] == 1; $i++
) {
201 $itemHTML .= "</ul></li>\n";
205 // ajax request: collapse
206 if($doCollapse && $expandedFolderUid == $uid) { return $itemHTML; }
208 // ajax request: expand
209 if($doExpand && $expandedFolderUid == $uid) {
210 $ajaxOutput .= $itemHTML;
211 $invertedDepthOfAjaxRequestedItem = $v['invertedDepth'];
212 } elseif($invertedDepthOfAjaxRequestedItem) {
213 if($v['invertedDepth'] < $invertedDepthOfAjaxRequestedItem) {
214 $ajaxOutput .= $itemHTML;
223 if($ajaxOutput) { return $ajaxOutput; }
225 // finally close the first ul
232 * Generate the plus/minus icon for the browsable tree.
234 * @param array record for the entry
235 * @param integer The current entry number
236 * @param integer The total number of entries. If equal to $a, a "bottom" element is returned.
237 * @param integer The number of sub-elements to the current element.
238 * @param boolean The element was expanded to render subelements if this flag is set.
239 * @return string Image tag with the plus/minus icon.
241 * @see t3lib_pageTree::PMicon()
243 function PMicon($row,$a,$c,$nextCount,$exp) {
244 $PM = $nextCount ?
($exp ?
'minus' : 'plus') : 'join';
245 $BTM = ($a == $c) ?
'bottom' : '';
246 $icon = '<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' alt="" />';
249 $cmd = $this->bank
.'_'.($exp?
'0_':'1_').$row['uid'].'_'.$this->treeName
;
250 $icon = $this->PMiconATagWrap($icon,$cmd,!$exp);
257 * Wrap the plus/minus icon in a link
259 * @param string HTML string to wrap, probably an image tag.
260 * @param string Command for 'PM' get var
261 * @return string Link-wrapped input string
264 function PMiconATagWrap($icon, $cmd, $isExpand = true) {
265 if ($this->thisScript
) {
266 // activate dynamic ajax-based tree
267 $js = htmlspecialchars('Tree.load(\''.$cmd.'\', '.intval($isExpand).', this);');
268 return '<a class="pm" onclick="'.$js.'">'.$icon.'</a>';
277 * Will create and return the HTML code for a browsable tree of folders.
278 * Is based on the mounts found in the internal array ->MOUNTS (set in the constructor)
280 * @return string HTML code for the browsable tree
282 function getBrowsableTree() {
284 // Get stored tree structure AND updating it if needed according to incoming PM GET var.
285 $this->initializePositionSaving();
288 $titleLen = intval($this->BE_USER
->uc
['titleLen']);
292 foreach($this->MOUNTS
as $key => $val) {
293 $specUID = t3lib_div
::md5int($val['path']);
294 $this->specUIDmap
[$specUID] = $val['path'];
297 $this->bank
= $val['nkey'];
298 $isOpen = $this->stored
[$val['nkey']][$specUID] ||
$this->expandFirst
;
302 $cmd = $this->bank
.'_'.($isOpen ?
'0_' : '1_').$specUID.'_'.$this->treeName
;
303 $icon='<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.($isOpen?
'minus':'plus').'only.gif').' alt="" />';
304 $firstHtml= $this->PM_ATagWrap($icon,$cmd);
306 switch($val['type']) {
307 case 'user': $icon = 'gfx/i/_icon_ftp_user.gif'; break;
308 case 'group': $icon = 'gfx/i/_icon_ftp_group.gif'; break;
309 default: $icon = 'gfx/i/_icon_ftp.gif'; break;
312 // Preparing rootRec for the mount
313 $firstHtml.=$this->wrapIcon('<img'.t3lib_iconWorks
::skinImg($this->backPath
,$icon,'width="18" height="16"').' alt="" />',$val);
315 $row['uid'] = $specUID;
316 $row['path'] = $val['path'];
317 $row['title'] = $val['name'];
319 // Add the root of the mount to ->tree
320 $this->tree
[] = array('HTML' => $firstHtml, 'row' => $row, 'bank' => $this->bank
);
322 // If the mount is expanded, go down:
324 $this->getFolderTree($val['path'], 999);
327 $treeArr = array_merge($treeArr, $this->tree
);
329 return $this->printTree($treeArr);
335 * Fetches the data for the tree
337 * @param string Abs file path
338 * @param integer Max depth (recursivity limit)
339 * @return integer The count of items on the level
340 * @see getBrowsableTree()
342 function getFolderTree($files_path, $depth=999) {
344 // This generates the directory tree
345 $dirs = t3lib_div
::get_dirs($files_path);
346 if (!is_array($dirs)) return 0;
351 $depth = intval($depth);
355 foreach($dirs as $key => $val) {
357 $this->tree
[] = array(); // Reserve space.
359 $treeKey = key($this->tree
); // Get the key for this space
361 $val = ereg_replace('^\./','',$val);
363 $path = $files_path.$val.'/';
365 $specUID = t3lib_div
::md5int($path);
366 $this->specUIDmap
[$specUID] = $path;
369 $row['path'] = $path;
370 $row['uid'] = $specUID;
371 $row['title'] = $title;
373 // Make a recursive call to the next level
374 if ($depth > 1 && $this->expandNext($specUID)) {
375 $nextCount = $this->getFolderTree(
378 $this->makeHTML ?
'<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.($a == $c ?
'blank' : 'line').'.gif','width="18" height="16"').' alt="" />' : ''
380 $exp = 1; // Set "did expand" flag
382 $nextCount = $this->getCount($path);
383 $exp = 0; // Clear "did expand" flag
386 // Set HTML-icons, if any:
387 if ($this->makeHTML
) {
388 $HTML = $this->PMicon($row,$a,$c,$nextCount,$exp);
390 $icon = 'gfx/i/_icon_'.t3lib_BEfunc
::getPathType_web_nonweb($path).'folders.gif';
391 if ($val == '_temp_') {
392 $icon = 'gfx/i/sysf.gif';
393 $row['title']='TEMP';
394 $row['_title']='<b>TEMP</b>';
396 if ($val == '_recycler_') {
397 $icon = 'gfx/i/recycler.gif';
398 $row['title']='RECYCLER';
399 $row['_title']='<b>RECYCLER</b>';
401 $HTML .= $this->wrapIcon('<img'.t3lib_iconWorks
::skinImg($this->backPath
, $icon, 'width="18" height="16"').' alt="" />',$row);
404 // Finally, add the row/HTML content to the ->tree array in the reserved key.
405 $this->tree
[$treeKey] = Array(
408 'hasSub' => $nextCount && $this->expandNext($specUID),
409 'isFirst'=> ($a == 1),
411 'invertedDepth'=> $depth,
412 'bank' => $this->bank
416 if($a) { $this->tree
[$treeKey]['isLast'] = true; }
421 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/class.filelistfoldertree.php']) {
422 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/class.filelistfoldertree.php']);