2 /***************************************************************
5 * (c) 1999-2011 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
70 public function __construct() {
71 parent
::__construct();
75 * Compatibility constructor.
77 * @deprecated since TYPO3 4.6 and will be removed in TYPO3 4.8. Use __construct() instead.
79 public function filelistFolderTree() {
80 t3lib_div
::logDeprecatedFunction();
81 // Note: we cannot call $this->__construct() here because it would call the derived class constructor and cause recursion
82 // This code uses official PHP behavior (http://www.php.net/manual/en/language.oop5.basic.php) when $this in the
83 // statically called non-static method inherits $this from the caller's scope.
84 filelistFolderTree
::__construct();
88 * Wrapping icon in browse tree
90 * @param string Icon IMG code
91 * @param array Data row for element.
92 * @return string Page icon
94 function wrapIcon($theFolderIcon, &$row) {
96 // Wrap icon in click-menu link.
97 if (!$this->ext_IconMode
) {
98 $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon,$row['path'],'',0);
99 } elseif (!strcmp($this->ext_IconMode
,'titlelink')) {
100 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix
.$this->getId($row).'\','.$this->bank
.');';
101 $theFolderIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$theFolderIcon.'</a>';
103 // Wrap icon in a drag/drop span.
104 return '<span class="dragIcon" id="dragIconID_'.$this->getJumpToParam($row).'">'.$theFolderIcon.'</span>';
109 * Wrapping $title in a-tags.
111 * @param string Title string
112 * @param string Item record
113 * @param integer Bank pointer (which mount point number)
117 function wrapTitle($title,$row,$bank=0) {
118 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix
.$this->getId($row).'\','.$bank.');';
120 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler']) {
121 $CSM = ' oncontextmenu="'.htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('',$row['path'],'',0,'&bank='.$this->bank
,'',TRUE)).'"';
123 $theFolderTitle='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"'.$CSM.'>'.$title.'</a>';
125 // Wrap title in a drag/drop span.
126 return '<span class="dragTitle" id="dragTitleID_'.$this->getJumpToParam($row).'">'.$theFolderTitle.'</span>';
133 * Compiles the HTML code for displaying the structure found inside the ->tree array
135 * @param array "tree-array" - if blank string, the internal ->tree array is used.
136 * @return string The HTML code for the tree
138 function printTree($treeArr='') {
139 $titleLen = intval($this->BE_USER
->uc
['titleLen']);
140 if (!is_array($treeArr)) $treeArr = $this->tree
;
143 <!-- TYPO3 folder tree structure. -->
144 <ul class="tree" id="treeRoot">
146 $titleLen=intval($this->BE_USER
->uc
['titleLen']);
147 if (!is_array($treeArr)) $treeArr=$this->tree
;
149 // -- evaluate AJAX request
150 // IE takes anchor as parameter
151 $PM = t3lib_div
::_GP('PM');
152 if(($PMpos = strpos($PM, '#')) !== FALSE) { $PM = substr($PM, 0, $PMpos); }
153 $PM = explode('_', $PM);
154 if((TYPO3_REQUESTTYPE
& TYPO3_REQUESTTYPE_AJAX
) && is_array($PM) && count($PM)==4) {
156 $expandedFolderUid = $PM[2];
158 $invertedDepthOfAjaxRequestedItem = 0; // We don't know yet. Will be set later.
161 $expandedFolderUid = $PM[2];
167 // we need to count the opened <ul>'s every time we dig into another level,
168 // so we know how many we have to close when all children are done rendering
169 $closeDepth = array();
171 foreach($treeArr as $k => $v) {
172 $classAttr = $v['row']['_CSSCLASS'];
173 $uid = $v['row']['uid'];
174 $idAttr = htmlspecialchars($this->domIdPrefix
.$this->getId($v['row']).'_'.$v['bank']);
177 // if this item is the start of a new level,
178 // then a new level <ul> is needed, but not in ajax mode
179 if($v['isFirst'] && !($doCollapse) && !($doExpand && $expandedFolderUid == $uid)) {
180 $itemHTML = "<ul>\n";
183 // add CSS classes to the list item
184 if($v['hasSub']) { $classAttr = ($classAttr) ?
' expanded': 'expanded'; }
185 if($v['isLast']) { $classAttr = ($classAttr) ?
' last' : 'last'; }
188 <li id="'.$idAttr.'"'.($classAttr ?
' class="'.$classAttr.'"' : '').'><div class="treeLinkItem">'.
190 $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$v['bank']) . '</div>';
193 if(!$v['hasSub']) { $itemHTML .= "</li>\n"; }
195 // we have to remember if this is the last one
196 // on level X so the last child on level X+1 closes the <ul>-tag
197 if($v['isLast'] && !($doExpand && $expandedFolderUid == $uid)) { $closeDepth[$v['invertedDepth']] = 1; }
200 // if this is the last one and does not have subitems, we need to close
201 // the tree as long as the upper levels have last items too
202 if($v['isLast'] && !$v['hasSub'] && !$doCollapse && !($doExpand && $expandedFolderUid == $uid)) {
203 for ($i = $v['invertedDepth']; $closeDepth[$i] == 1; $i++
) {
205 $itemHTML .= "</ul></li>\n";
209 // ajax request: collapse
210 if($doCollapse && $expandedFolderUid == $uid) {
211 $this->ajaxStatus
= TRUE;
215 // ajax request: expand
216 if($doExpand && $expandedFolderUid == $uid) {
217 $ajaxOutput .= $itemHTML;
218 $invertedDepthOfAjaxRequestedItem = $v['invertedDepth'];
219 } elseif($invertedDepthOfAjaxRequestedItem) {
220 if($v['invertedDepth'] < $invertedDepthOfAjaxRequestedItem) {
221 $ajaxOutput .= $itemHTML;
223 $this->ajaxStatus
= TRUE;
232 $this->ajaxStatus
= TRUE;
236 // finally close the first ul
243 * Generate the plus/minus icon for the browsable tree.
245 * @param array record for the entry
246 * @param integer The current entry number
247 * @param integer The total number of entries. If equal to $a, a "bottom" element is returned.
248 * @param integer The number of sub-elements to the current element.
249 * @param boolean The element was expanded to render subelements if this flag is set.
250 * @return string Image tag with the plus/minus icon.
252 * @see t3lib_pageTree::PMicon()
254 function PMicon($row,$a,$c,$nextCount,$exp) {
255 $PM = $nextCount ?
($exp ?
'minus' : 'plus') : 'join';
256 $BTM = ($a == $c) ?
'bottom' : '';
257 $icon = '<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' alt="" />';
260 $cmd = $this->bank
.'_'.($exp?
'0_':'1_').$row['uid'].'_'.$this->treeName
;
261 $icon = $this->PMiconATagWrap($icon,$cmd,!$exp);
268 * Wrap the plus/minus icon in a link
270 * @param string HTML string to wrap, probably an image tag.
271 * @param string Command for 'PM' get var
272 * @return string Link-wrapped input string
275 function PMiconATagWrap($icon, $cmd, $isExpand = TRUE) {
276 if ($this->thisScript
) {
277 // activate dynamic ajax-based tree
278 $js = htmlspecialchars('Tree.load(\''.$cmd.'\', '.intval($isExpand).', this);');
279 return '<a class="pm" onclick="'.$js.'">'.$icon.'</a>';
288 * Will create and return the HTML code for a browsable tree of folders.
289 * Is based on the mounts found in the internal array ->MOUNTS (set in the constructor)
291 * @return string HTML code for the browsable tree
293 function getBrowsableTree() {
295 // Get stored tree structure AND updating it if needed according to incoming PM GET var.
296 $this->initializePositionSaving();
299 $titleLen = intval($this->BE_USER
->uc
['titleLen']);
303 foreach($this->MOUNTS
as $key => $val) {
305 $specUID = t3lib_div
::md5int($val['path']);
306 $this->specUIDmap
[$specUID] = $val['path'];
309 $this->bank
= $val['nkey'];
310 $isOpen = $this->stored
[$val['nkey']][$specUID] ||
$this->expandFirst
;
314 $cmd = $this->bank
.'_'.($isOpen ?
'0_' : '1_').$specUID.'_'.$this->treeName
;
315 $icon='<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.($isOpen?
'minus':'plus').'only.gif').' alt="" />';
316 $firstHtml= $this->PM_ATagWrap($icon,$cmd);
318 switch ($val['type']) {
320 $icon = 'apps-filetree-folder-user';
323 $icon = 'apps-filetree-folder-user';
326 $icon = 'apps-filetree-folder-locked';
329 $icon = 'apps-filetree-mount';
333 // Preparing rootRec for the mount
334 $firstHtml.=$this->wrapIcon(t3lib_iconWorks
::getSpriteIcon($icon),$val);
336 $row['uid'] = $specUID;
337 $row['path'] = $val['path'];
338 $row['title'] = $val['name'];
340 // hasSub is TRUE when the root of the mount is expanded
344 // Add the root of the mount to ->tree
345 $this->tree
[] = array('HTML' => $firstHtml, 'row' => $row, 'bank' => $this->bank
, 'hasSub' => $hasSub);
347 // If the mount is expanded, go down:
349 $this->getFolderTree($val['path'], 999, $val['type']);
352 $treeArr = array_merge($treeArr, $this->tree
);
354 // if this is an AJAX call, don't run through all mounts, only
355 // show the expansion of the current one, not the rest of the mounts
356 if (TYPO3_REQUESTTYPE
& TYPO3_REQUESTTYPE_AJAX
) {
360 return $this->printTree($treeArr);
366 * Fetches the data for the tree
368 * @param string Abs file path
369 * @param integer Max depth (recursivity limit)
370 * @return integer The count of items on the level
371 * @see getBrowsableTree()
373 function getFolderTree($files_path, $depth=999, $type='') {
375 // This generates the directory tree
376 $dirs = t3lib_div
::get_dirs($files_path);
377 if (!is_array($dirs)) return 0;
382 $depth = intval($depth);
386 foreach($dirs as $key => $val) {
388 $this->tree
[] = array(); // Reserve space.
390 $treeKey = key($this->tree
); // Get the key for this space
392 $val = preg_replace('/^\.\//','',$val);
394 $path = $files_path.$val.'/';
396 $specUID = t3lib_div
::md5int($path);
397 $this->specUIDmap
[$specUID] = $path;
400 $row['path'] = $path;
401 $row['uid'] = $specUID;
402 $row['title'] = $title;
404 // Make a recursive call to the next level
405 if ($depth > 1 && $this->expandNext($specUID)) {
406 $nextCount = $this->getFolderTree(
409 $this->makeHTML ?
'<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.($a == $c ?
'blank' : 'line').'.gif','width="18" height="16"').' alt="" />' : '',
412 $exp = 1; // Set "did expand" flag
414 $nextCount = $this->getCount($path);
415 $exp = 0; // Clear "did expand" flag
418 // Set HTML-icons, if any:
419 if ($this->makeHTML
) {
420 $HTML = $this->PMicon($row,$a,$c,$nextCount,$exp);
422 $webpath = t3lib_BEfunc
::getPathType_web_nonweb($path);
424 if (is_writable($path)) {
429 $overlays= array('status-overlay-locked'=>array());
434 $icon = 'apps-filetree-folder-opened';
436 $icon = 'apps-filetree-folder-default';
438 if ($val == '_temp_') {
439 $icon = 'apps-filetree-folder-temp';
440 $row['title'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:temp', TRUE);
441 $row['_title'] = '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:temp', TRUE) . '</strong>';
443 if ($val == '_recycler_') {
444 $icon = 'apps-filetree-folder-recycler';
445 $row['title'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:recycler', TRUE);
446 $row['_title'] = '<strong>' .$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:recycler', TRUE) . '</strong>';
448 $HTML .= $this->wrapIcon(t3lib_iconWorks
::getSpriteIcon($icon,array('title'=>$row['title']),$overlays),$row);
451 // Finally, add the row/HTML content to the ->tree array in the reserved key.
452 $this->tree
[$treeKey] = Array(
455 'hasSub' => $nextCount && $this->expandNext($specUID),
456 'isFirst'=> ($a == 1),
458 'invertedDepth'=> $depth,
459 'bank' => $this->bank
463 if($a) { $this->tree
[$treeKey]['isLast'] = TRUE; }
468 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['typo3/class.filelistfoldertree.php'])) {
469 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['typo3/class.filelistfoldertree.php']);