2 /***************************************************************
5 * (c) 1999-2010 Kasper Skårhøj (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 * Extension class for the t3lib_filetree class, needed for drag and drop and ajax functionality
56 * @author Sebastian Kurfürst <sebastian@garbage-group.de>
57 * @author Benjamin Mack <bmack@xnos.org>
60 * @see class t3lib_browseTree
62 class filelistFolderTree
extends t3lib_folderTree
{
65 var $ajaxStatus = false; // Indicates, whether the ajax call was successful, i.e. the requested page has been found
68 * Calls init functions
72 function filelistFolderTree() {
73 parent
::t3lib_folderTree();
77 * Wrapping icon in browse tree
79 * @param string Icon IMG code
80 * @param array Data row for element.
81 * @return string Page icon
83 function wrapIcon($theFolderIcon, &$row) {
85 // Wrap icon in click-menu link.
86 if (!$this->ext_IconMode
) {
87 $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon,$row['path'],'',0);
88 } elseif (!strcmp($this->ext_IconMode
,'titlelink')) {
89 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix
.$this->getId($row).'\','.$this->bank
.');';
90 $theFolderIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$theFolderIcon.'</a>';
92 // Wrap icon in a drag/drop span.
93 return '<span class="dragIcon" id="dragIconID_'.$this->getJumpToParam($row).'">'.$theFolderIcon.'</span>';
98 * Wrapping $title in a-tags.
100 * @param string Title string
101 * @param string Item record
102 * @param integer Bank pointer (which mount point number)
106 function wrapTitle($title,$row,$bank=0) {
107 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix
.$this->getId($row).'\','.$bank.');';
109 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler']) {
110 $CSM = ' oncontextmenu="'.htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('',$row['path'],'',0,'&bank='.$this->bank
,'',TRUE)).'"';
112 $theFolderTitle='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"'.$CSM.'>'.$title.'</a>';
114 // Wrap title in a drag/drop span.
115 return '<span class="dragTitle" id="dragTitleID_'.$this->getJumpToParam($row).'">'.$theFolderTitle.'</span>';
122 * Compiles the HTML code for displaying the structure found inside the ->tree array
124 * @param array "tree-array" - if blank string, the internal ->tree array is used.
125 * @return string The HTML code for the tree
127 function printTree($treeArr='') {
128 $titleLen = intval($this->BE_USER
->uc
['titleLen']);
129 if (!is_array($treeArr)) $treeArr = $this->tree
;
132 <!-- TYPO3 folder tree structure. -->
133 <ul class="tree" id="treeRoot">
135 $titleLen=intval($this->BE_USER
->uc
['titleLen']);
136 if (!is_array($treeArr)) $treeArr=$this->tree
;
138 // -- evaluate AJAX request
139 // IE takes anchor as parameter
140 $PM = t3lib_div
::_GP('PM');
141 if(($PMpos = strpos($PM, '#')) !== false) { $PM = substr($PM, 0, $PMpos); }
142 $PM = explode('_', $PM);
143 if((TYPO3_REQUESTTYPE
& TYPO3_REQUESTTYPE_AJAX
) && is_array($PM) && count($PM)==4) {
145 $expandedFolderUid = $PM[2];
147 $invertedDepthOfAjaxRequestedItem = 0; // We don't know yet. Will be set later.
150 $expandedFolderUid = $PM[2];
156 // we need to count the opened <ul>'s every time we dig into another level,
157 // so we know how many we have to close when all children are done rendering
158 $closeDepth = array();
160 foreach($treeArr as $k => $v) {
161 $classAttr = $v['row']['_CSSCLASS'];
162 $uid = $v['row']['uid'];
163 $idAttr = htmlspecialchars($this->domIdPrefix
.$this->getId($v['row']).'_'.$v['bank']);
166 // if this item is the start of a new level,
167 // then a new level <ul> is needed, but not in ajax mode
168 if($v['isFirst'] && !($doCollapse) && !($doExpand && $expandedFolderUid == $uid)) {
169 $itemHTML = "<ul>\n";
172 // add CSS classes to the list item
173 if($v['hasSub']) { $classAttr = ($classAttr) ?
' expanded': 'expanded'; }
174 if($v['isLast']) { $classAttr = ($classAttr) ?
' last' : 'last'; }
177 <li id="'.$idAttr.'"'.($classAttr ?
' class="'.$classAttr.'"' : '').'><div class="treeLinkItem">'.
179 $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$v['bank']) . '</div>';
182 if(!$v['hasSub']) { $itemHTML .= "</li>\n"; }
184 // we have to remember if this is the last one
185 // on level X so the last child on level X+1 closes the <ul>-tag
186 if($v['isLast'] && !($doExpand && $expandedFolderUid == $uid)) { $closeDepth[$v['invertedDepth']] = 1; }
189 // if this is the last one and does not have subitems, we need to close
190 // the tree as long as the upper levels have last items too
191 if($v['isLast'] && !$v['hasSub'] && !$doCollapse && !($doExpand && $expandedFolderUid == $uid)) {
192 for ($i = $v['invertedDepth']; $closeDepth[$i] == 1; $i++
) {
194 $itemHTML .= "</ul></li>\n";
198 // ajax request: collapse
199 if($doCollapse && $expandedFolderUid == $uid) {
200 $this->ajaxStatus
= true;
204 // ajax request: expand
205 if($doExpand && $expandedFolderUid == $uid) {
206 $ajaxOutput .= $itemHTML;
207 $invertedDepthOfAjaxRequestedItem = $v['invertedDepth'];
208 } elseif($invertedDepthOfAjaxRequestedItem) {
209 if($v['invertedDepth'] < $invertedDepthOfAjaxRequestedItem) {
210 $ajaxOutput .= $itemHTML;
212 $this->ajaxStatus
= true;
221 $this->ajaxStatus
= true;
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) {
294 $specUID = t3lib_div
::md5int($val['path']);
295 $this->specUIDmap
[$specUID] = $val['path'];
298 $this->bank
= $val['nkey'];
299 $isOpen = $this->stored
[$val['nkey']][$specUID] ||
$this->expandFirst
;
303 $cmd = $this->bank
.'_'.($isOpen ?
'0_' : '1_').$specUID.'_'.$this->treeName
;
304 $icon='<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.($isOpen?
'minus':'plus').'only.gif').' alt="" />';
305 $firstHtml= $this->PM_ATagWrap($icon,$cmd);
307 switch ($val['type']) {
309 $icon = 'apps-filetree-folder-user';
312 $icon = 'apps-filetree-folder-user';
315 $icon = 'apps-filetree-folder-locked';
318 $icon = 'apps-filetree-mount';
322 // Preparing rootRec for the mount
323 $firstHtml.=$this->wrapIcon(t3lib_iconWorks
::getSpriteIcon($icon),$val);
325 $row['uid'] = $specUID;
326 $row['path'] = $val['path'];
327 $row['title'] = $val['name'];
329 // hasSub is true when the root of the mount is expanded
333 // Add the root of the mount to ->tree
334 $this->tree
[] = array('HTML' => $firstHtml, 'row' => $row, 'bank' => $this->bank
, 'hasSub' => $hasSub);
336 // If the mount is expanded, go down:
338 $this->getFolderTree($val['path'], 999, $val['type']);
341 $treeArr = array_merge($treeArr, $this->tree
);
343 // if this is an AJAX call, don't run through all mounts, only
344 // show the expansion of the current one, not the rest of the mounts
345 if (TYPO3_REQUESTTYPE
& TYPO3_REQUESTTYPE_AJAX
) {
349 return $this->printTree($treeArr);
355 * Fetches the data for the tree
357 * @param string Abs file path
358 * @param integer Max depth (recursivity limit)
359 * @return integer The count of items on the level
360 * @see getBrowsableTree()
362 function getFolderTree($files_path, $depth=999, $type='') {
364 // This generates the directory tree
365 $dirs = t3lib_div
::get_dirs($files_path);
366 if (!is_array($dirs)) return 0;
371 $depth = intval($depth);
375 foreach($dirs as $key => $val) {
377 $this->tree
[] = array(); // Reserve space.
379 $treeKey = key($this->tree
); // Get the key for this space
381 $val = preg_replace('/^\.\//','',$val);
383 $path = $files_path.$val.'/';
385 $specUID = t3lib_div
::md5int($path);
386 $this->specUIDmap
[$specUID] = $path;
389 $row['path'] = $path;
390 $row['uid'] = $specUID;
391 $row['title'] = $title;
393 // Make a recursive call to the next level
394 if ($depth > 1 && $this->expandNext($specUID)) {
395 $nextCount = $this->getFolderTree(
398 $this->makeHTML ?
'<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.($a == $c ?
'blank' : 'line').'.gif','width="18" height="16"').' alt="" />' : '',
401 $exp = 1; // Set "did expand" flag
403 $nextCount = $this->getCount($path);
404 $exp = 0; // Clear "did expand" flag
407 // Set HTML-icons, if any:
408 if ($this->makeHTML
) {
409 $HTML = $this->PMicon($row,$a,$c,$nextCount,$exp);
411 $webpath = t3lib_BEfunc
::getPathType_web_nonweb($path);
413 if (is_writable($path)) {
418 $overlays= array('status-overlay-locked'=>array());
422 if($webpath == 'web') {
423 $icon = 'apps-filetree-folder-default';
425 $icon = 'apps-filetree-folder-default';
427 if ($val == '_temp_') {
428 $icon = 'apps-filetree-folder-temp';
429 $row['title'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:temp', true);
430 $row['_title'] = '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:temp', true) . '</strong>';
432 if ($val == '_recycler_') {
433 $icon = 'apps-filetree-folder-recycler';
434 $row['title'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:recycler', true);
435 $row['_title'] = '<strong>' .$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:recycler', true) . '</strong>';
437 $HTML .= $this->wrapIcon(t3lib_iconWorks
::getSpriteIcon($icon,array('title'=>$row['title']),$overlays),$row);
440 // Finally, add the row/HTML content to the ->tree array in the reserved key.
441 $this->tree
[$treeKey] = Array(
444 'hasSub' => $nextCount && $this->expandNext($specUID),
445 'isFirst'=> ($a == 1),
447 'invertedDepth'=> $depth,
448 'bank' => $this->bank
452 if($a) { $this->tree
[$treeKey]['isLast'] = true; }
457 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['typo3/class.filelistfoldertree.php'])) {
458 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['typo3/class.filelistfoldertree.php']);