[TASK] Remove old code related to the extension tstemplate_styler
[Packages/TYPO3.CMS.git] / typo3 / class.filelistfoldertree.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 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 * Init parent class
69 */
70 public function __construct() {
71 parent::__construct();
72 }
73
74 /**
75 * Compatibility constructor.
76 *
77 * @deprecated since TYPO3 4.6 and will be removed in TYPO3 4.8. Use __construct() instead.
78 */
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();
85 }
86
87 /**
88 * Wrapping icon in browse tree
89 *
90 * @param string Icon IMG code
91 * @param array Data row for element.
92 * @return string Page icon
93 */
94 function wrapIcon($theFolderIcon, &$row) {
95
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>';
102 }
103 // Wrap icon in a drag/drop span.
104 return '<span class="dragIcon" id="dragIconID_'.$this->getJumpToParam($row).'">'.$theFolderIcon.'</span>';
105 }
106
107
108 /**
109 * Wrapping $title in a-tags.
110 *
111 * @param string Title string
112 * @param string Item record
113 * @param integer Bank pointer (which mount point number)
114 * @return string
115 * @access private
116 */
117 function wrapTitle($title,$row,$bank=0) {
118 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'\','.$bank.');';
119 $CSM = ' oncontextmenu="'.htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('',$row['path'],'',0,'&bank='.$this->bank,'',TRUE)).'"';
120 $theFolderTitle='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"'.$CSM.'>'.$title.'</a>';
121
122 // Wrap title in a drag/drop span.
123 return '<span class="dragTitle" id="dragTitleID_'.$this->getJumpToParam($row).'">'.$theFolderTitle.'</span>';
124 }
125
126
127
128
129 /**
130 * Compiles the HTML code for displaying the structure found inside the ->tree array
131 *
132 * @param array "tree-array" - if blank string, the internal ->tree array is used.
133 * @return string The HTML code for the tree
134 */
135 function printTree($treeArr='') {
136 $titleLen = intval($this->BE_USER->uc['titleLen']);
137 if (!is_array($treeArr)) $treeArr = $this->tree;
138
139 $out = '
140 <!-- TYPO3 folder tree structure. -->
141 <ul class="tree" id="treeRoot">
142 ';
143 $titleLen=intval($this->BE_USER->uc['titleLen']);
144 if (!is_array($treeArr)) $treeArr=$this->tree;
145
146 // -- evaluate AJAX request
147 // IE takes anchor as parameter
148 $PM = t3lib_div::_GP('PM');
149 if(($PMpos = strpos($PM, '#')) !== FALSE) { $PM = substr($PM, 0, $PMpos); }
150 $PM = explode('_', $PM);
151 if((TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) && is_array($PM) && count($PM)==4) {
152 if($PM[1]) {
153 $expandedFolderUid = $PM[2];
154 $ajaxOutput = '';
155 $invertedDepthOfAjaxRequestedItem = 0; // We don't know yet. Will be set later.
156 $doExpand = TRUE;
157 } else {
158 $expandedFolderUid = $PM[2];
159 $doCollapse = TRUE;
160 }
161 }
162
163
164 // we need to count the opened <ul>'s every time we dig into another level,
165 // so we know how many we have to close when all children are done rendering
166 $closeDepth = array();
167
168 foreach($treeArr as $k => $v) {
169 $classAttr = $v['row']['_CSSCLASS'];
170 $uid = $v['row']['uid'];
171 $idAttr = htmlspecialchars($this->domIdPrefix.$this->getId($v['row']).'_'.$v['bank']);
172 $itemHTML = '';
173
174 // if this item is the start of a new level,
175 // then a new level <ul> is needed, but not in ajax mode
176 if($v['isFirst'] && !($doCollapse) && !($doExpand && $expandedFolderUid == $uid)) {
177 $itemHTML = "<ul>\n";
178 }
179
180 // add CSS classes to the list item
181 if($v['hasSub']) { $classAttr = ($classAttr) ? ' expanded': 'expanded'; }
182 if($v['isLast']) { $classAttr = ($classAttr) ? ' last' : 'last'; }
183
184 $itemHTML .='
185 <li id="'.$idAttr.'"'.($classAttr ? ' class="'.$classAttr.'"' : '').'><div class="treeLinkItem">'.
186 $v['HTML'].
187 $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$v['bank']) . '</div>';
188
189
190 if(!$v['hasSub']) { $itemHTML .= "</li>\n"; }
191
192 // we have to remember if this is the last one
193 // on level X so the last child on level X+1 closes the <ul>-tag
194 if($v['isLast'] && !($doExpand && $expandedFolderUid == $uid)) { $closeDepth[$v['invertedDepth']] = 1; }
195
196
197 // if this is the last one and does not have subitems, we need to close
198 // the tree as long as the upper levels have last items too
199 if($v['isLast'] && !$v['hasSub'] && !$doCollapse && !($doExpand && $expandedFolderUid == $uid)) {
200 for ($i = $v['invertedDepth']; $closeDepth[$i] == 1; $i++) {
201 $closeDepth[$i] = 0;
202 $itemHTML .= "</ul></li>\n";
203 }
204 }
205
206 // ajax request: collapse
207 if($doCollapse && $expandedFolderUid == $uid) {
208 $this->ajaxStatus = TRUE;
209 return $itemHTML;
210 }
211
212 // ajax request: expand
213 if($doExpand && $expandedFolderUid == $uid) {
214 $ajaxOutput .= $itemHTML;
215 $invertedDepthOfAjaxRequestedItem = $v['invertedDepth'];
216 } elseif($invertedDepthOfAjaxRequestedItem) {
217 if($v['invertedDepth'] < $invertedDepthOfAjaxRequestedItem) {
218 $ajaxOutput .= $itemHTML;
219 } else {
220 $this->ajaxStatus = TRUE;
221 return $ajaxOutput;
222 }
223 }
224
225 $out .= $itemHTML;
226 }
227
228 if($ajaxOutput) {
229 $this->ajaxStatus = TRUE;
230 return $ajaxOutput;
231 }
232
233 // finally close the first ul
234 $out .= "</ul>\n";
235 return $out;
236 }
237
238
239 /**
240 * Generate the plus/minus icon for the browsable tree.
241 *
242 * @param array record for the entry
243 * @param integer The current entry number
244 * @param integer The total number of entries. If equal to $a, a "bottom" element is returned.
245 * @param integer The number of sub-elements to the current element.
246 * @param boolean The element was expanded to render subelements if this flag is set.
247 * @return string Image tag with the plus/minus icon.
248 * @access private
249 * @see t3lib_pageTree::PMicon()
250 */
251 function PMicon($row,$a,$c,$nextCount,$exp) {
252 $PM = $nextCount ? ($exp ? 'minus' : 'plus') : 'join';
253 $BTM = ($a == $c) ? 'bottom' : '';
254 $icon = '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' alt="" />';
255
256 if ($nextCount) {
257 $cmd = $this->bank.'_'.($exp?'0_':'1_').$row['uid'].'_'.$this->treeName;
258 $icon = $this->PMiconATagWrap($icon,$cmd,!$exp);
259 }
260 return $icon;
261 }
262
263
264 /**
265 * Wrap the plus/minus icon in a link
266 *
267 * @param string HTML string to wrap, probably an image tag.
268 * @param string Command for 'PM' get var
269 * @return string Link-wrapped input string
270 * @access private
271 */
272 function PMiconATagWrap($icon, $cmd, $isExpand = TRUE) {
273 if ($this->thisScript) {
274 // activate dynamic ajax-based tree
275 $js = htmlspecialchars('Tree.load(\''.$cmd.'\', '.intval($isExpand).', this);');
276 return '<a class="pm" onclick="'.$js.'">'.$icon.'</a>';
277 } else {
278 return $icon;
279 }
280 }
281
282
283
284 /**
285 * Will create and return the HTML code for a browsable tree of folders.
286 * Is based on the mounts found in the internal array ->MOUNTS (set in the constructor)
287 *
288 * @return string HTML code for the browsable tree
289 */
290 function getBrowsableTree() {
291
292 // Get stored tree structure AND updating it if needed according to incoming PM GET var.
293 $this->initializePositionSaving();
294
295 // Init done:
296 $titleLen = intval($this->BE_USER->uc['titleLen']);
297 $treeArr = array();
298
299 // Traverse mounts:
300 foreach($this->MOUNTS as $key => $val) {
301 $hasSub = FALSE;
302 $specUID = t3lib_div::md5int($val['path']);
303 $this->specUIDmap[$specUID] = $val['path'];
304
305 // Set first:
306 $this->bank = $val['nkey'];
307 $isOpen = $this->stored[$val['nkey']][$specUID] || $this->expandFirst;
308 $this->reset();
309
310 // Set PM icon:
311 $cmd = $this->bank.'_'.($isOpen ? '0_' : '1_').$specUID.'_'.$this->treeName;
312 $icon='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.($isOpen? 'minus':'plus').'only.gif').' alt="" />';
313 $firstHtml= $this->PM_ATagWrap($icon,$cmd);
314
315 switch ($val['type']) {
316 case 'user':
317 $icon = 'apps-filetree-folder-user';
318 break;
319 case 'group':
320 $icon = 'apps-filetree-folder-user';
321 break;
322 case 'readonly':
323 $icon = 'apps-filetree-folder-locked';
324 break;
325 default:
326 $icon = 'apps-filetree-mount';
327 break;
328 }
329
330 // Preparing rootRec for the mount
331 $firstHtml.=$this->wrapIcon(t3lib_iconWorks::getSpriteIcon($icon),$val);
332 $row=array();
333 $row['uid'] = $specUID;
334 $row['path'] = $val['path'];
335 $row['title'] = $val['name'];
336
337 // hasSub is TRUE when the root of the mount is expanded
338 if ($isOpen) {
339 $hasSub = TRUE;
340 }
341 // Add the root of the mount to ->tree
342 $this->tree[] = array('HTML' => $firstHtml, 'row' => $row, 'bank' => $this->bank, 'hasSub' => $hasSub);
343
344 // If the mount is expanded, go down:
345 if ($isOpen)
346 $this->getFolderTree($val['path'], 999, $val['type']);
347
348 // Add tree:
349 $treeArr = array_merge($treeArr, $this->tree);
350
351 // if this is an AJAX call, don't run through all mounts, only
352 // show the expansion of the current one, not the rest of the mounts
353 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) {
354 break;
355 }
356 }
357 return $this->printTree($treeArr);
358 }
359
360
361
362 /**
363 * Fetches the data for the tree
364 *
365 * @param string Abs file path
366 * @param integer Max depth (recursivity limit)
367 * @return integer The count of items on the level
368 * @see getBrowsableTree()
369 */
370 function getFolderTree($files_path, $depth=999, $type='') {
371
372 // This generates the directory tree
373 $dirs = t3lib_div::get_dirs($files_path);
374 if (!is_array($dirs)) return 0;
375
376 sort($dirs);
377 $c = count($dirs);
378
379 $depth = intval($depth);
380 $HTML = '';
381 $a = 0;
382
383 foreach($dirs as $key => $val) {
384 $a++;
385 $this->tree[] = array(); // Reserve space.
386 end($this->tree);
387 $treeKey = key($this->tree); // Get the key for this space
388
389 $val = preg_replace('/^\.\//','',$val);
390 $title = $val;
391 $path = $files_path.$val.'/';
392
393 $specUID = t3lib_div::md5int($path);
394 $this->specUIDmap[$specUID] = $path;
395
396 $row = array();
397 $row['path'] = $path;
398 $row['uid'] = $specUID;
399 $row['title'] = $title;
400
401 // Make a recursive call to the next level
402 if ($depth > 1 && $this->expandNext($specUID)) {
403 $nextCount = $this->getFolderTree(
404 $path,
405 $depth-1,
406 $this->makeHTML ? '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.($a == $c ? 'blank' : 'line').'.gif','width="18" height="16"').' alt="" />' : '',
407 $type
408 );
409 $exp = 1; // Set "did expand" flag
410 } else {
411 $nextCount = $this->getCount($path);
412 $exp = 0; // Clear "did expand" flag
413 }
414
415 // Set HTML-icons, if any:
416 if ($this->makeHTML) {
417 $HTML = $this->PMicon($row,$a,$c,$nextCount,$exp);
418
419 $webpath = t3lib_BEfunc::getPathType_web_nonweb($path);
420
421 if (is_writable($path)) {
422 $type = '';
423 $overlays = array();
424 } else {
425 $type = 'readonly';
426 $overlays= array('status-overlay-locked'=>array());
427
428 }
429
430 if ($exp) {
431 $icon = 'apps-filetree-folder-opened';
432 } else {
433 $icon = 'apps-filetree-folder-default';
434 }
435 if ($val == '_temp_') {
436 $icon = 'apps-filetree-folder-temp';
437 $row['title'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:temp', TRUE);
438 $row['_title'] = '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:temp', TRUE) . '</strong>';
439 }
440 if ($val == '_recycler_') {
441 $icon = 'apps-filetree-folder-recycler';
442 $row['title'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:recycler', TRUE);
443 $row['_title'] = '<strong>' .$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:recycler', TRUE) . '</strong>';
444 }
445 $HTML .= $this->wrapIcon(t3lib_iconWorks::getSpriteIcon($icon,array('title'=>$row['title']),$overlays),$row);
446 }
447
448 // Finally, add the row/HTML content to the ->tree array in the reserved key.
449 $this->tree[$treeKey] = Array(
450 'row' => $row,
451 'HTML' => $HTML,
452 'hasSub' => $nextCount && $this->expandNext($specUID),
453 'isFirst'=> ($a == 1),
454 'isLast' => FALSE,
455 'invertedDepth'=> $depth,
456 'bank' => $this->bank
457 );
458 }
459
460 if($a) { $this->tree[$treeKey]['isLast'] = TRUE; }
461 return $c;
462 }
463 }
464
465 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/class.filelistfoldertree.php'])) {
466 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/class.filelistfoldertree.php']);
467 }
468
469 ?>