Fixed bug #13294: IRRE deleted combo records are still validated by TBE_EDITOR (Thank...
[Packages/TYPO3.CMS.git] / typo3 / class.filelistfoldertree.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
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.
13 *
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.
18 *
19 *
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.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Folder navigation tree for the File main module
29 *
30 * @author Benjamin Mack <bmack@xnos.org>
31 *
32 *
33 * [CLASS/FUNCTION INDEX of SCRIPT]
34 *
35 *
36 *
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='')
47 *
48 *
49 * TOTAL FUNCTIONS: 9
50 * (This index is automatically created/updated by the extension "extdeveval")
51 *
52 */
53 /**
54 * Extension class for the t3lib_filetree class, needed for drag and drop and ajax functionality
55 *
56 * @author Sebastian Kurfürst <sebastian@garbage-group.de>
57 * @author Benjamin Mack <bmack@xnos.org>
58 * @package TYPO3
59 * @subpackage core
60 * @see class t3lib_browseTree
61 */
62 class filelistFolderTree extends t3lib_folderTree {
63
64 var $ext_IconMode;
65 var $ajaxStatus = false; // Indicates, whether the ajax call was successful, i.e. the requested page has been found
66
67 /**
68 * Calls init functions
69 *
70 * @return void
71 */
72 function filelistFolderTree() {
73 parent::t3lib_folderTree();
74 }
75
76 /**
77 * Wrapping icon in browse tree
78 *
79 * @param string Icon IMG code
80 * @param array Data row for element.
81 * @return string Page icon
82 */
83 function wrapIcon($theFolderIcon, &$row) {
84
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>';
91 }
92 // Wrap icon in a drag/drop span.
93 return '<span class="dragIcon" id="dragIconID_'.$this->getJumpToParam($row).'">'.$theFolderIcon.'</span>';
94 }
95
96
97 /**
98 * Wrapping $title in a-tags.
99 *
100 * @param string Title string
101 * @param string Item record
102 * @param integer Bank pointer (which mount point number)
103 * @return string
104 * @access private
105 */
106 function wrapTitle($title,$row,$bank=0) {
107 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'\','.$bank.');';
108 $CSM = '';
109 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler']) {
110 $CSM = ' oncontextmenu="'.htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('',$row['path'],'',0,'&bank='.$this->bank,'',TRUE)).'"';
111 }
112 $theFolderTitle='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"'.$CSM.'>'.$title.'</a>';
113
114 // Wrap title in a drag/drop span.
115 return '<span class="dragTitle" id="dragTitleID_'.$this->getJumpToParam($row).'">'.$theFolderTitle.'</span>';
116 }
117
118
119
120
121 /**
122 * Compiles the HTML code for displaying the structure found inside the ->tree array
123 *
124 * @param array "tree-array" - if blank string, the internal ->tree array is used.
125 * @return string The HTML code for the tree
126 */
127 function printTree($treeArr='') {
128 $titleLen = intval($this->BE_USER->uc['titleLen']);
129 if (!is_array($treeArr)) $treeArr = $this->tree;
130
131 $out = '
132 <!-- TYPO3 folder tree structure. -->
133 <ul class="tree" id="treeRoot">
134 ';
135 $titleLen=intval($this->BE_USER->uc['titleLen']);
136 if (!is_array($treeArr)) $treeArr=$this->tree;
137
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) {
144 if($PM[1]) {
145 $expandedFolderUid = $PM[2];
146 $ajaxOutput = '';
147 $invertedDepthOfAjaxRequestedItem = 0; // We don't know yet. Will be set later.
148 $doExpand = true;
149 } else {
150 $expandedFolderUid = $PM[2];
151 $doCollapse = true;
152 }
153 }
154
155
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();
159
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']);
164 $itemHTML = '';
165
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";
170 }
171
172 // add CSS classes to the list item
173 if($v['hasSub']) { $classAttr = ($classAttr) ? ' expanded': 'expanded'; }
174 if($v['isLast']) { $classAttr = ($classAttr) ? ' last' : 'last'; }
175
176 $itemHTML .='
177 <li id="'.$idAttr.'"'.($classAttr ? ' class="'.$classAttr.'"' : '').'><div class="treeLinkItem">'.
178 $v['HTML'].
179 $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$v['bank']) . '</div>';
180
181
182 if(!$v['hasSub']) { $itemHTML .= "</li>\n"; }
183
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; }
187
188
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++) {
193 $closeDepth[$i] = 0;
194 $itemHTML .= "</ul></li>\n";
195 }
196 }
197
198 // ajax request: collapse
199 if($doCollapse && $expandedFolderUid == $uid) {
200 $this->ajaxStatus = true;
201 return $itemHTML;
202 }
203
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;
211 } else {
212 $this->ajaxStatus = true;
213 return $ajaxOutput;
214 }
215 }
216
217 $out .= $itemHTML;
218 }
219
220 if($ajaxOutput) {
221 $this->ajaxStatus = true;
222 return $ajaxOutput;
223 }
224
225 // finally close the first ul
226 $out .= "</ul>\n";
227 return $out;
228 }
229
230
231 /**
232 * Generate the plus/minus icon for the browsable tree.
233 *
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.
240 * @access private
241 * @see t3lib_pageTree::PMicon()
242 */
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="" />';
247
248 if ($nextCount) {
249 $cmd = $this->bank.'_'.($exp?'0_':'1_').$row['uid'].'_'.$this->treeName;
250 $icon = $this->PMiconATagWrap($icon,$cmd,!$exp);
251 }
252 return $icon;
253 }
254
255
256 /**
257 * Wrap the plus/minus icon in a link
258 *
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
262 * @access private
263 */
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>';
269 } else {
270 return $icon;
271 }
272 }
273
274
275
276 /**
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)
279 *
280 * @return string HTML code for the browsable tree
281 */
282 function getBrowsableTree() {
283
284 // Get stored tree structure AND updating it if needed according to incoming PM GET var.
285 $this->initializePositionSaving();
286
287 // Init done:
288 $titleLen = intval($this->BE_USER->uc['titleLen']);
289 $treeArr = array();
290
291 // Traverse mounts:
292 foreach($this->MOUNTS as $key => $val) {
293 $hasSub = false;
294 $specUID = t3lib_div::md5int($val['path']);
295 $this->specUIDmap[$specUID] = $val['path'];
296
297 // Set first:
298 $this->bank = $val['nkey'];
299 $isOpen = $this->stored[$val['nkey']][$specUID] || $this->expandFirst;
300 $this->reset();
301
302 // Set PM icon:
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);
306
307 switch ($val['type']) {
308 case 'user':
309 $icon = 'apps-filetree-folder-user';
310 break;
311 case 'group':
312 $icon = 'apps-filetree-folder-user';
313 break;
314 case 'readonly':
315 $icon = 'apps-filetree-folder-locked';
316 break;
317 default:
318 $icon = 'apps-filetree-mount';
319 break;
320 }
321
322 // Preparing rootRec for the mount
323 $firstHtml.=$this->wrapIcon(t3lib_iconWorks::getSpriteIcon($icon),$val);
324 $row=array();
325 $row['uid'] = $specUID;
326 $row['path'] = $val['path'];
327 $row['title'] = $val['name'];
328
329 // hasSub is true when the root of the mount is expanded
330 if ($isOpen) {
331 $hasSub = true;
332 }
333 // Add the root of the mount to ->tree
334 $this->tree[] = array('HTML' => $firstHtml, 'row' => $row, 'bank' => $this->bank, 'hasSub' => $hasSub);
335
336 // If the mount is expanded, go down:
337 if ($isOpen)
338 $this->getFolderTree($val['path'], 999, $val['type']);
339
340 // Add tree:
341 $treeArr = array_merge($treeArr, $this->tree);
342
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) {
346 break;
347 }
348 }
349 return $this->printTree($treeArr);
350 }
351
352
353
354 /**
355 * Fetches the data for the tree
356 *
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()
361 */
362 function getFolderTree($files_path, $depth=999, $type='') {
363
364 // This generates the directory tree
365 $dirs = t3lib_div::get_dirs($files_path);
366 if (!is_array($dirs)) return 0;
367
368 sort($dirs);
369 $c = count($dirs);
370
371 $depth = intval($depth);
372 $HTML = '';
373 $a = 0;
374
375 foreach($dirs as $key => $val) {
376 $a++;
377 $this->tree[] = array(); // Reserve space.
378 end($this->tree);
379 $treeKey = key($this->tree); // Get the key for this space
380
381 $val = preg_replace('/^\.\//','',$val);
382 $title = $val;
383 $path = $files_path.$val.'/';
384
385 $specUID = t3lib_div::md5int($path);
386 $this->specUIDmap[$specUID] = $path;
387
388 $row = array();
389 $row['path'] = $path;
390 $row['uid'] = $specUID;
391 $row['title'] = $title;
392
393 // Make a recursive call to the next level
394 if ($depth > 1 && $this->expandNext($specUID)) {
395 $nextCount = $this->getFolderTree(
396 $path,
397 $depth-1,
398 $this->makeHTML ? '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.($a == $c ? 'blank' : 'line').'.gif','width="18" height="16"').' alt="" />' : '',
399 $type
400 );
401 $exp = 1; // Set "did expand" flag
402 } else {
403 $nextCount = $this->getCount($path);
404 $exp = 0; // Clear "did expand" flag
405 }
406
407 // Set HTML-icons, if any:
408 if ($this->makeHTML) {
409 $HTML = $this->PMicon($row,$a,$c,$nextCount,$exp);
410
411 $webpath = t3lib_BEfunc::getPathType_web_nonweb($path);
412
413 if (is_writable($path)) {
414 $type = '';
415 $overlays = array();
416 } else {
417 $type = 'readonly';
418 $overlays= array('status-overlay-locked'=>array());
419
420 }
421
422 if($webpath == 'web') {
423 $icon = 'apps-filetree-folder-default';
424 } else {
425 $icon = 'apps-filetree-folder-default';
426 }
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>';
431 }
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>';
436 }
437 $HTML .= $this->wrapIcon(t3lib_iconWorks::getSpriteIcon($icon,array('title'=>$row['title']),$overlays),$row);
438 }
439
440 // Finally, add the row/HTML content to the ->tree array in the reserved key.
441 $this->tree[$treeKey] = Array(
442 'row' => $row,
443 'HTML' => $HTML,
444 'hasSub' => $nextCount && $this->expandNext($specUID),
445 'isFirst'=> ($a == 1),
446 'isLast' => false,
447 'invertedDepth'=> $depth,
448 'bank' => $this->bank
449 );
450 }
451
452 if($a) { $this->tree[$treeKey]['isLast'] = true; }
453 return $c;
454 }
455 }
456
457 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.filelistfoldertree.php']) {
458 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.filelistfoldertree.php']);
459 }
460
461 ?>