a48a1f93116cb249a30255b5cd5f91e225706c02
2 /***************************************************************
5 * (c) 1999-2009 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 * Extension class for the t3lib_filetree class, needed for drag and drop and ajax functionality
56 * @author Sebastian Kurfuerst <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($icon,&$row) {
85 // Add title attribute to input icon tag
86 $theFolderIcon = $this->addTagAttributes($icon,($this->titleAttrib ?
$this->titleAttrib
.'="'.$this->getTitleAttrib($row).'"' : ''));
88 // Wrap icon in click-menu link.
89 if (!$this->ext_IconMode
) {
90 $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon,$row['path'],'',0);
91 } elseif (!strcmp($this->ext_IconMode
,'titlelink')) {
92 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix
.$this->getId($row).'\','.$this->bank
.');';
93 $theFolderIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$theFolderIcon.'</a>';
95 // Wrap icon in a drag/drop span.
96 return '<span class="dragIcon" id="dragIconID_'.$this->getJumpToParam($row).'">'.$theFolderIcon.'</span>';
101 * Wrapping $title in a-tags.
103 * @param string Title string
104 * @param string Item record
105 * @param integer Bank pointer (which mount point number)
109 function wrapTitle($title,$row,$bank=0) {
110 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix
.$this->getId($row).'\','.$bank.');';
112 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler']) {
113 $CSM = ' oncontextmenu="'.htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('',$row['path'],'',0,'&bank='.$this->bank
,'',TRUE)).'"';
115 $theFolderTitle='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"'.$CSM.'>'.$title.'</a>';
117 // Wrap title in a drag/drop span.
118 return '<span class="dragTitle" id="dragTitleID_'.$this->getJumpToParam($row).'">'.$theFolderTitle.'</span>';
125 * Compiles the HTML code for displaying the structure found inside the ->tree array
127 * @param array "tree-array" - if blank string, the internal ->tree array is used.
128 * @return string The HTML code for the tree
130 function printTree($treeArr='') {
131 $titleLen = intval($this->BE_USER
->uc
['titleLen']);
132 if (!is_array($treeArr)) $treeArr = $this->tree
;
135 <!-- TYPO3 folder tree structure. -->
136 <ul class="tree" id="treeRoot">
138 $titleLen=intval($this->BE_USER
->uc
['titleLen']);
139 if (!is_array($treeArr)) $treeArr=$this->tree
;
141 // -- evaluate AJAX request
142 // IE takes anchor as parameter
143 $PM = t3lib_div
::_GP('PM');
144 if(($PMpos = strpos($PM, '#')) !== false) { $PM = substr($PM, 0, $PMpos); }
145 $PM = explode('_', $PM);
146 if((TYPO3_REQUESTTYPE
& TYPO3_REQUESTTYPE_AJAX
) && is_array($PM) && count($PM)==4) {
148 $expandedFolderUid = $PM[2];
150 $invertedDepthOfAjaxRequestedItem = 0; // We don't know yet. Will be set later.
153 $expandedFolderUid = $PM[2];
159 // we need to count the opened <ul>'s every time we dig into another level,
160 // so we know how many we have to close when all children are done rendering
161 $closeDepth = array();
163 foreach($treeArr as $k => $v) {
164 $classAttr = $v['row']['_CSSCLASS'];
165 $uid = $v['row']['uid'];
166 $idAttr = htmlspecialchars($this->domIdPrefix
.$this->getId($v['row']).'_'.$v['bank']);
169 // if this item is the start of a new level,
170 // then a new level <ul> is needed, but not in ajax mode
171 if($v['isFirst'] && !($doCollapse) && !($doExpand && $expandedFolderUid == $uid)) {
172 $itemHTML = "<ul>\n";
175 // add CSS classes to the list item
176 if($v['hasSub']) { $classAttr = ($classAttr) ?
' expanded': 'expanded'; }
177 if($v['isLast']) { $classAttr = ($classAttr) ?
' last' : 'last'; }
180 <li id="'.$idAttr.'"'.($classAttr ?
' class="'.$classAttr.'"' : '').'><div class="treeLinkItem">'.
182 $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$v['bank']) . '</div>';
185 if(!$v['hasSub']) { $itemHTML .= "</li>\n"; }
187 // we have to remember if this is the last one
188 // on level X so the last child on level X+1 closes the <ul>-tag
189 if($v['isLast'] && !($doExpand && $expandedFolderUid == $uid)) { $closeDepth[$v['invertedDepth']] = 1; }
192 // if this is the last one and does not have subitems, we need to close
193 // the tree as long as the upper levels have last items too
194 if($v['isLast'] && !$v['hasSub'] && !$doCollapse && !($doExpand && $expandedFolderUid == $uid)) {
195 for ($i = $v['invertedDepth']; $closeDepth[$i] == 1; $i++
) {
197 $itemHTML .= "</ul></li>\n";
201 // ajax request: collapse
202 if($doCollapse && $expandedFolderUid == $uid) {
203 $this->ajaxStatus
= true;
207 // ajax request: expand
208 if($doExpand && $expandedFolderUid == $uid) {
209 $ajaxOutput .= $itemHTML;
210 $invertedDepthOfAjaxRequestedItem = $v['invertedDepth'];
211 } elseif($invertedDepthOfAjaxRequestedItem) {
212 if($v['invertedDepth'] < $invertedDepthOfAjaxRequestedItem) {
213 $ajaxOutput .= $itemHTML;
215 $this->ajaxStatus
= true;
224 $this->ajaxStatus
= true;
228 // finally close the first ul
235 * Generate the plus/minus icon for the browsable tree.
237 * @param array record for the entry
238 * @param integer The current entry number
239 * @param integer The total number of entries. If equal to $a, a "bottom" element is returned.
240 * @param integer The number of sub-elements to the current element.
241 * @param boolean The element was expanded to render subelements if this flag is set.
242 * @return string Image tag with the plus/minus icon.
244 * @see t3lib_pageTree::PMicon()
246 function PMicon($row,$a,$c,$nextCount,$exp) {
247 $PM = $nextCount ?
($exp ?
'minus' : 'plus') : 'join';
248 $BTM = ($a == $c) ?
'bottom' : '';
249 $icon = '<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' alt="" />';
252 $cmd = $this->bank
.'_'.($exp?
'0_':'1_').$row['uid'].'_'.$this->treeName
;
253 $icon = $this->PMiconATagWrap($icon,$cmd,!$exp);
260 * Wrap the plus/minus icon in a link
262 * @param string HTML string to wrap, probably an image tag.
263 * @param string Command for 'PM' get var
264 * @return string Link-wrapped input string
267 function PMiconATagWrap($icon, $cmd, $isExpand = true) {
268 if ($this->thisScript
) {
269 // activate dynamic ajax-based tree
270 $js = htmlspecialchars('Tree.load(\''.$cmd.'\', '.intval($isExpand).', this);');
271 return '<a class="pm" onclick="'.$js.'">'.$icon.'</a>';
280 * Will create and return the HTML code for a browsable tree of folders.
281 * Is based on the mounts found in the internal array ->MOUNTS (set in the constructor)
283 * @return string HTML code for the browsable tree
285 function getBrowsableTree() {
287 // Get stored tree structure AND updating it if needed according to incoming PM GET var.
288 $this->initializePositionSaving();
291 $titleLen = intval($this->BE_USER
->uc
['titleLen']);
295 foreach($this->MOUNTS
as $key => $val) {
297 $specUID = t3lib_div
::md5int($val['path']);
298 $this->specUIDmap
[$specUID] = $val['path'];
301 $this->bank
= $val['nkey'];
302 $isOpen = $this->stored
[$val['nkey']][$specUID] ||
$this->expandFirst
;
306 $cmd = $this->bank
.'_'.($isOpen ?
'0_' : '1_').$specUID.'_'.$this->treeName
;
307 $icon='<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.($isOpen?
'minus':'plus').'only.gif').' alt="" />';
308 $firstHtml= $this->PM_ATagWrap($icon,$cmd);
310 switch ($val['type']) {
312 $icon = 'apps-filetree-folder-user';
315 $icon = 'apps-filetree-folder-user';
318 $icon = 'apps-filetree-folder-locked';
321 $icon = 'apps-filetree-mount';
325 // Preparing rootRec for the mount
326 $firstHtml.=$this->wrapIcon(t3lib_iconWorks
::getSpriteIcon($icon),$val);
328 $row['uid'] = $specUID;
329 $row['path'] = $val['path'];
330 $row['title'] = $val['name'];
332 // hasSub is true when the root of the mount is expanded
336 // Add the root of the mount to ->tree
337 $this->tree
[] = array('HTML' => $firstHtml, 'row' => $row, 'bank' => $this->bank
, 'hasSub' => $hasSub);
339 // If the mount is expanded, go down:
341 $this->getFolderTree($val['path'], 999, $val['type']);
344 $treeArr = array_merge($treeArr, $this->tree
);
346 // if this is an AJAX call, don't run through all mounts, only
347 // show the expansion of the current one, not the rest of the mounts
348 if (TYPO3_REQUESTTYPE
& TYPO3_REQUESTTYPE_AJAX
) {
352 return $this->printTree($treeArr);
358 * Fetches the data for the tree
360 * @param string Abs file path
361 * @param integer Max depth (recursivity limit)
362 * @return integer The count of items on the level
363 * @see getBrowsableTree()
365 function getFolderTree($files_path, $depth=999, $type='') {
367 // This generates the directory tree
368 $dirs = t3lib_div
::get_dirs($files_path);
369 if (!is_array($dirs)) return 0;
374 $depth = intval($depth);
378 foreach($dirs as $key => $val) {
380 $this->tree
[] = array(); // Reserve space.
382 $treeKey = key($this->tree
); // Get the key for this space
384 $val = preg_replace('/^\.\//','',$val);
386 $path = $files_path.$val.'/';
388 $specUID = t3lib_div
::md5int($path);
389 $this->specUIDmap
[$specUID] = $path;
392 $row['path'] = $path;
393 $row['uid'] = $specUID;
394 $row['title'] = $title;
396 // Make a recursive call to the next level
397 if ($depth > 1 && $this->expandNext($specUID)) {
398 $nextCount = $this->getFolderTree(
401 $this->makeHTML ?
'<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.($a == $c ?
'blank' : 'line').'.gif','width="18" height="16"').' alt="" />' : '',
404 $exp = 1; // Set "did expand" flag
406 $nextCount = $this->getCount($path);
407 $exp = 0; // Clear "did expand" flag
410 // Set HTML-icons, if any:
411 if ($this->makeHTML
) {
412 $HTML = $this->PMicon($row,$a,$c,$nextCount,$exp);
414 $webpath = t3lib_BEfunc
::getPathType_web_nonweb($path);
416 if (is_writable($path)) {
421 $overlays= array('status-overlay-locked'=>array());
425 if($webpath == 'web') {
426 $icon = 'apps-filetree-folder-default';;
428 $icon = 'apps-filetree-folder-default';
430 if ($val == '_temp_') {
431 $icon = 'apps-filetree-folder-temp';
432 $row['title'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:temp', true);
433 $row['_title'] = '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:temp', true) . '</strong>';
435 if ($val == '_recycler_') {
436 $icon = 'apps-filetree-recycler';
437 $row['title'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:recycler', true);
438 $row['_title'] = '<strong>' .$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:recycler', true) . '</strong>';
440 $HTML .= $this->wrapIcon(t3lib_iconWorks
::getSpriteIcon($icon,array('title'=>$row['title']),$overlays),$row);
443 // Finally, add the row/HTML content to the ->tree array in the reserved key.
444 $this->tree
[$treeKey] = Array(
447 'hasSub' => $nextCount && $this->expandNext($specUID),
448 'isFirst'=> ($a == 1),
450 'invertedDepth'=> $depth,
451 'bank' => $this->bank
455 if($a) { $this->tree
[$treeKey]['isLast'] = true; }
460 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/class.filelistfoldertree.php']) {
461 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/class.filelistfoldertree.php']);