c6d0269dd8606be3ade935ce2236e6c0dd8f0a19
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
68 * Compatibility constructor.
70 * @deprecated since TYPO3 4.6 and will be removed in TYPO3 4.8. Use __construct() instead.
72 public function filelistFolderTree() {
73 t3lib_div
::logDeprecatedFunction();
74 // Note: we cannot call $this->__construct() here because it would call the derived class constructor and cause recursion
75 // This code uses official PHP behavior (http://www.php.net/manual/en/language.oop5.basic.php) when $this in the
76 // statically called non-static method inherits $this from the caller's scope.
77 filelistFolderTree
::__construct();
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($theFolderIcon, &$row) {
89 // Wrap icon in click-menu link.
90 if (!$this->ext_IconMode
) {
91 $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon,$row['path'],'',0);
92 } elseif (!strcmp($this->ext_IconMode
,'titlelink')) {
93 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix
.$this->getId($row).'\','.$this->bank
.');';
94 $theFolderIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$theFolderIcon.'</a>';
96 // Wrap icon in a drag/drop span.
97 return '<span class="dragIcon" id="dragIconID_'.$this->getJumpToParam($row).'">'.$theFolderIcon.'</span>';
102 * Wrapping $title in a-tags.
104 * @param string Title string
105 * @param string Item record
106 * @param integer Bank pointer (which mount point number)
110 function wrapTitle($title,$row,$bank=0) {
111 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix
.$this->getId($row).'\','.$bank.');';
113 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler']) {
114 $CSM = ' oncontextmenu="'.htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('',$row['path'],'',0,'&bank='.$this->bank
,'',TRUE)).'"';
116 $theFolderTitle='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"'.$CSM.'>'.$title.'</a>';
118 // Wrap title in a drag/drop span.
119 return '<span class="dragTitle" id="dragTitleID_'.$this->getJumpToParam($row).'">'.$theFolderTitle.'</span>';
126 * Compiles the HTML code for displaying the structure found inside the ->tree array
128 * @param array "tree-array" - if blank string, the internal ->tree array is used.
129 * @return string The HTML code for the tree
131 function printTree($treeArr='') {
132 $titleLen = intval($this->BE_USER
->uc
['titleLen']);
133 if (!is_array($treeArr)) $treeArr = $this->tree
;
136 <!-- TYPO3 folder tree structure. -->
137 <ul class="tree" id="treeRoot">
139 $titleLen=intval($this->BE_USER
->uc
['titleLen']);
140 if (!is_array($treeArr)) $treeArr=$this->tree
;
142 // -- evaluate AJAX request
143 // IE takes anchor as parameter
144 $PM = t3lib_div
::_GP('PM');
145 if(($PMpos = strpos($PM, '#')) !== FALSE) { $PM = substr($PM, 0, $PMpos); }
146 $PM = explode('_', $PM);
147 if((TYPO3_REQUESTTYPE
& TYPO3_REQUESTTYPE_AJAX
) && is_array($PM) && count($PM)==4) {
149 $expandedFolderUid = $PM[2];
151 $invertedDepthOfAjaxRequestedItem = 0; // We don't know yet. Will be set later.
154 $expandedFolderUid = $PM[2];
160 // we need to count the opened <ul>'s every time we dig into another level,
161 // so we know how many we have to close when all children are done rendering
162 $closeDepth = array();
164 foreach($treeArr as $k => $v) {
165 $classAttr = $v['row']['_CSSCLASS'];
166 $uid = $v['row']['uid'];
167 $idAttr = htmlspecialchars($this->domIdPrefix
.$this->getId($v['row']).'_'.$v['bank']);
170 // if this item is the start of a new level,
171 // then a new level <ul> is needed, but not in ajax mode
172 if($v['isFirst'] && !($doCollapse) && !($doExpand && $expandedFolderUid == $uid)) {
173 $itemHTML = "<ul>\n";
176 // add CSS classes to the list item
177 if($v['hasSub']) { $classAttr = ($classAttr) ?
' expanded': 'expanded'; }
178 if($v['isLast']) { $classAttr = ($classAttr) ?
' last' : 'last'; }
181 <li id="'.$idAttr.'"'.($classAttr ?
' class="'.$classAttr.'"' : '').'><div class="treeLinkItem">'.
183 $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$v['bank']) . '</div>';
186 if(!$v['hasSub']) { $itemHTML .= "</li>\n"; }
188 // we have to remember if this is the last one
189 // on level X so the last child on level X+1 closes the <ul>-tag
190 if($v['isLast'] && !($doExpand && $expandedFolderUid == $uid)) { $closeDepth[$v['invertedDepth']] = 1; }
193 // if this is the last one and does not have subitems, we need to close
194 // the tree as long as the upper levels have last items too
195 if($v['isLast'] && !$v['hasSub'] && !$doCollapse && !($doExpand && $expandedFolderUid == $uid)) {
196 for ($i = $v['invertedDepth']; $closeDepth[$i] == 1; $i++
) {
198 $itemHTML .= "</ul></li>\n";
202 // ajax request: collapse
203 if($doCollapse && $expandedFolderUid == $uid) {
204 $this->ajaxStatus
= TRUE;
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;
216 $this->ajaxStatus
= TRUE;
225 $this->ajaxStatus
= TRUE;
229 // finally close the first ul
236 * Generate the plus/minus icon for the browsable tree.
238 * @param array record for the entry
239 * @param integer The current entry number
240 * @param integer The total number of entries. If equal to $a, a "bottom" element is returned.
241 * @param integer The number of sub-elements to the current element.
242 * @param boolean The element was expanded to render subelements if this flag is set.
243 * @return string Image tag with the plus/minus icon.
245 * @see t3lib_pageTree::PMicon()
247 function PMicon($row,$a,$c,$nextCount,$exp) {
248 $PM = $nextCount ?
($exp ?
'minus' : 'plus') : 'join';
249 $BTM = ($a == $c) ?
'bottom' : '';
250 $icon = '<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' alt="" />';
253 $cmd = $this->bank
.'_'.($exp?
'0_':'1_').$row['uid'].'_'.$this->treeName
;
254 $icon = $this->PMiconATagWrap($icon,$cmd,!$exp);
261 * Wrap the plus/minus icon in a link
263 * @param string HTML string to wrap, probably an image tag.
264 * @param string Command for 'PM' get var
265 * @return string Link-wrapped input string
268 function PMiconATagWrap($icon, $cmd, $isExpand = TRUE) {
269 if ($this->thisScript
) {
270 // activate dynamic ajax-based tree
271 $js = htmlspecialchars('Tree.load(\''.$cmd.'\', '.intval($isExpand).', this);');
272 return '<a class="pm" onclick="'.$js.'">'.$icon.'</a>';
281 * Will create and return the HTML code for a browsable tree of folders.
282 * Is based on the mounts found in the internal array ->MOUNTS (set in the constructor)
284 * @return string HTML code for the browsable tree
286 function getBrowsableTree() {
288 // Get stored tree structure AND updating it if needed according to incoming PM GET var.
289 $this->initializePositionSaving();
292 $titleLen = intval($this->BE_USER
->uc
['titleLen']);
296 foreach($this->MOUNTS
as $key => $val) {
298 $specUID = t3lib_div
::md5int($val['path']);
299 $this->specUIDmap
[$specUID] = $val['path'];
302 $this->bank
= $val['nkey'];
303 $isOpen = $this->stored
[$val['nkey']][$specUID] ||
$this->expandFirst
;
307 $cmd = $this->bank
.'_'.($isOpen ?
'0_' : '1_').$specUID.'_'.$this->treeName
;
308 $icon='<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.($isOpen?
'minus':'plus').'only.gif').' alt="" />';
309 $firstHtml= $this->PM_ATagWrap($icon,$cmd);
311 switch ($val['type']) {
313 $icon = 'apps-filetree-folder-user';
316 $icon = 'apps-filetree-folder-user';
319 $icon = 'apps-filetree-folder-locked';
322 $icon = 'apps-filetree-mount';
326 // Preparing rootRec for the mount
327 $firstHtml.=$this->wrapIcon(t3lib_iconWorks
::getSpriteIcon($icon),$val);
329 $row['uid'] = $specUID;
330 $row['path'] = $val['path'];
331 $row['title'] = $val['name'];
333 // hasSub is TRUE when the root of the mount is expanded
337 // Add the root of the mount to ->tree
338 $this->tree
[] = array('HTML' => $firstHtml, 'row' => $row, 'bank' => $this->bank
, 'hasSub' => $hasSub);
340 // If the mount is expanded, go down:
342 $this->getFolderTree($val['path'], 999, $val['type']);
345 $treeArr = array_merge($treeArr, $this->tree
);
347 // if this is an AJAX call, don't run through all mounts, only
348 // show the expansion of the current one, not the rest of the mounts
349 if (TYPO3_REQUESTTYPE
& TYPO3_REQUESTTYPE_AJAX
) {
353 return $this->printTree($treeArr);
359 * Fetches the data for the tree
361 * @param string Abs file path
362 * @param integer Max depth (recursivity limit)
363 * @return integer The count of items on the level
364 * @see getBrowsableTree()
366 function getFolderTree($files_path, $depth=999, $type='') {
368 // This generates the directory tree
369 $dirs = t3lib_div
::get_dirs($files_path);
370 if (!is_array($dirs)) return 0;
375 $depth = intval($depth);
379 foreach($dirs as $key => $val) {
381 $this->tree
[] = array(); // Reserve space.
383 $treeKey = key($this->tree
); // Get the key for this space
385 $val = preg_replace('/^\.\//','',$val);
387 $path = $files_path.$val.'/';
389 $specUID = t3lib_div
::md5int($path);
390 $this->specUIDmap
[$specUID] = $path;
393 $row['path'] = $path;
394 $row['uid'] = $specUID;
395 $row['title'] = $title;
397 // Make a recursive call to the next level
398 if ($depth > 1 && $this->expandNext($specUID)) {
399 $nextCount = $this->getFolderTree(
402 $this->makeHTML ?
'<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.($a == $c ?
'blank' : 'line').'.gif','width="18" height="16"').' alt="" />' : '',
405 $exp = 1; // Set "did expand" flag
407 $nextCount = $this->getCount($path);
408 $exp = 0; // Clear "did expand" flag
411 // Set HTML-icons, if any:
412 if ($this->makeHTML
) {
413 $HTML = $this->PMicon($row,$a,$c,$nextCount,$exp);
415 $webpath = t3lib_BEfunc
::getPathType_web_nonweb($path);
417 if (is_writable($path)) {
422 $overlays= array('status-overlay-locked'=>array());
427 $icon = 'apps-filetree-folder-opened';
429 $icon = 'apps-filetree-folder-default';
431 if ($val == '_temp_') {
432 $icon = 'apps-filetree-folder-temp';
433 $row['title'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:temp', TRUE);
434 $row['_title'] = '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:temp', TRUE) . '</strong>';
436 if ($val == '_recycler_') {
437 $icon = 'apps-filetree-folder-recycler';
438 $row['title'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:recycler', TRUE);
439 $row['_title'] = '<strong>' .$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:recycler', TRUE) . '</strong>';
441 $HTML .= $this->wrapIcon(t3lib_iconWorks
::getSpriteIcon($icon,array('title'=>$row['title']),$overlays),$row);
444 // Finally, add the row/HTML content to the ->tree array in the reserved key.
445 $this->tree
[$treeKey] = Array(
448 'hasSub' => $nextCount && $this->expandNext($specUID),
449 'isFirst'=> ($a == 1),
451 'invertedDepth'=> $depth,
452 'bank' => $this->bank
456 if($a) { $this->tree
[$treeKey]['isLast'] = TRUE; }
461 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['typo3/class.filelistfoldertree.php'])) {
462 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['typo3/class.filelistfoldertree.php']);