[FEATURE] Add support for native date/time fields
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_foldertree.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 * Generate a folder tree
29 *
30 * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
31 *
32 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
33 * @coauthor René Fritz <r.fritz@colorcube.de>
34 */
35
36 /**
37 * Extension class for the t3lib_treeView class, specially made for browsing folders in the File module
38 *
39 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
40 * @coauthor René Fritz <r.fritz@colorcube.de>
41 * @package TYPO3
42 * @subpackage t3lib
43 * @see class t3lib_treeView
44 */
45 class t3lib_folderTree extends t3lib_treeView {
46
47 /**
48 * The users' file Storages
49 * @var t3lib_file_storage[]
50 */
51 protected $storages = NULL;
52
53 /**
54 * @var array
55 */
56 protected $storageHashNumbers;
57
58 /**
59 * Indicates, whether the AJAX call was successful,
60 * i.e. the requested page has been found
61 *
62 * @var boolean
63 */
64 protected $ajaxStatus = FALSE;
65
66 /**
67 * Constructor function of the class
68 */
69 public function __construct() {
70 parent::init();
71
72 $this->storages = $GLOBALS['BE_USER']->getFileStorages();
73
74 $this->treeName = 'folder';
75 // Don't apply any title
76 $this->titleAttrib = '';
77 $this->domIdPrefix = 'folder';
78 }
79
80 /**
81 * Generate the plus/minus icon for the browsable tree.
82 *
83 * @param t3lib_file_Folder $folderObject Entry folder object
84 * @param integer $subFolderCounter The current entry number
85 * @param integer $totalSubFolders The total number of entries. If equal to $a, a "bottom" element is returned.
86 * @param integer $nextCount The number of sub-elements to the current element.
87 * @param boolean $isExpanded The element was expanded to render subelements if this flag is set.
88 * @return string Image tag with the plus/minus icon.
89 * @internal
90 * @see t3lib_pageTree::PMicon()
91 */
92 public function PMicon(t3lib_file_Folder $folderObject, $subFolderCounter, $totalSubFolders, $nextCount, $isExpanded) {
93 $PM = ($nextCount ? ($isExpanded ? 'minus' : 'plus') : 'join');
94 $BTM = ($subFolderCounter == $totalSubFolders ? 'bottom' : '');
95 $icon = '<img' . t3lib_iconWorks::skinImg(
96 $this->backPath, 'gfx/ol/' . $PM . $BTM . '.gif',
97 'width="18" height="16"'
98 ) . ' alt="" />';
99
100 if ($nextCount) {
101 $cmd = $this->generateExpandCollapseParameter($this->bank, !$isExpanded, $folderObject);
102 $icon = $this->PMiconATagWrap($icon, $cmd, !$isExpanded);
103 }
104 return $icon;
105 }
106
107 /**
108 * Wrap the plus/minus icon in a link
109 *
110 * @param string $icon HTML string to wrap, probably an image tag.
111 * @param string $cmd Command for 'PM' get var
112 * @param boolean $isExpand Whether to be expanded
113 * @return string Link-wrapped input string
114 * @internal
115 */
116 public function PMiconATagWrap($icon, $cmd, $isExpand = TRUE) {
117 if ($this->thisScript) {
118 // Activates dynamic AJAX based tree
119 $js = htmlspecialchars('Tree.load(\'' . $cmd . '\', ' . intval($isExpand) . ', this);');
120 return '<a class="pm" onclick="' . $js . '">' . $icon . '</a>';
121 } else {
122 return $icon;
123 }
124 }
125
126 /**
127 * Wrapping the folder icon
128 *
129 * @param string $icon The image tag for the icon
130 * @param t3lib_file_Folder $folderObject The row for the current element
131 * @return string The processed icon input value.
132 * @internal
133 */
134 public function wrapIcon($icon, t3lib_file_Folder $folderObject) {
135 // Add title attribute to input icon tag
136 $theFolderIcon = $this->addTagAttributes($icon, ($this->titleAttrib ? $this->titleAttrib . '="' . $this->getTitleAttrib($folderObject) . '"' : ''));
137
138 // Wrap icon in click-menu link.
139 if (!$this->ext_IconMode) {
140 $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon, $folderObject->getCombinedIdentifier(), '', 0);
141 } elseif (!strcmp($this->ext_IconMode, 'titlelink')) {
142 $aOnClick = 'return jumpTo(\'' . $this->getJumpToParam($folderObject) . '\',this,\'' . $this->domIdPrefix . $this->getId($folderObject) . '\',' . $this->bank . ');';
143 $theFolderIcon = '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . $theFolderIcon . '</a>';
144 }
145
146 return $theFolderIcon;
147 }
148
149 /**
150 * Wrapping $title in a-tags.
151 *
152 * @param string $title Title string
153 * @param t3lib_file_Folder $folderObject the folder record
154 * @param integer $bank Bank pointer (which mount point number)
155 * @return string
156 * @internal
157 */
158 public function wrapTitle($title, t3lib_file_Folder $folderObject, $bank = 0) {
159 $aOnClick = 'return jumpTo(\'' . $this->getJumpToParam($folderObject) . '\', this, \'' . $this->domIdPrefix . $this->getId($folderObject) . '\', ' . $bank . ');';
160 $CSM = ' oncontextmenu="'.htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('', $folderObject->getCombinedIdentifier(), '', 0, '&bank=' . $this->bank, '', TRUE)) . '"';
161 return '<a href="#" title="' . htmlspecialchars($title) . '" onclick="' . htmlspecialchars($aOnClick) . '"' . $CSM . '>' . $title . '</a>';
162 }
163
164 /**
165 * Returns the id from the record - for folders, this is an md5 hash.
166 *
167 * @param t3lib_file_Folder $folderObject The folder object
168 * @return integer The "uid" field value.
169 */
170 public function getId(t3lib_file_Folder $folderObject) {
171 return t3lib_div::md5Int($folderObject->getCombinedIdentifier());
172 }
173
174 /**
175 * Returns jump-url parameter value.
176 *
177 * @param t3lib_file_Folder $folderObject The folder object
178 * @return string The jump-url parameter.
179 */
180 public function getJumpToParam(t3lib_file_Folder $folderObject) {
181 return rawurlencode($folderObject->getCombinedIdentifier());
182 }
183
184 /**
185 * Returns the title for the input record. If blank, a "no title" labele (localized) will be returned.
186 * '_title' is used for setting an alternative title for folders.
187 *
188 * @param array $row The input row array (where the key "_title" is used for the title)
189 * @param integer $titleLen Title length (30)
190 * @return string The title
191 */
192 public function getTitleStr($row, $titleLen = 30) {
193 return $row['_title'] ? $row['_title'] : parent::getTitleStr($row, $titleLen);
194 }
195
196 /**
197 * Returns the value for the image "title" attribute
198 *
199 * @param t3lib_file_Folder $folderObject The folder to be used
200 * @return string The attribute value (is htmlspecialchared() already)
201 */
202 function getTitleAttrib(t3lib_file_Folder $folderObject) {
203 return htmlspecialchars($folderObject->getName());
204 }
205
206 /**
207 * Will create and return the HTML code for a browsable tree of folders.
208 * Is based on the mounts found in the internal array ->MOUNTS (set in the constructor)
209 *
210 * @return string HTML code for the browsable tree
211 */
212 public function getBrowsableTree() {
213 // Get stored tree structure AND updating it if needed according to incoming PM GET var.
214 $this->initializePositionSaving();
215
216 // Init done:
217 $treeItems = array();
218
219 // Traverse mounts:
220 foreach ($this->storages as $storageObject) {
221 $this->getBrowseableTreeForStorage($storageObject);
222
223 // Add tree:
224 $treeItems = array_merge($treeItems, $this->tree);
225
226 // if this is an AJAX call, don't run through all mounts, only
227 // show the expansion of the current one, not the rest of the mounts
228 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) {
229 // @todo: currently the AJAX script runs through all storages thus, if something is expanded on storage #2, it does not work, the break stops this, the goal should be that only the $this->storages iterates over the selected storage/bank
230 }
231 }
232
233 return $this->printTree($treeItems);
234 }
235
236 /**
237 * Get a tree for one storage
238 *
239 * @param t3lib_file_Storage $storageObject
240 * @return void
241 */
242 public function getBrowseableTreeForStorage(t3lib_file_Storage $storageObject) {
243 // If there are filemounts, show each, otherwise just the rootlevel folder
244 $fileMounts = $storageObject->getFileMounts();
245 $rootLevelFolders = array();
246 if (count($fileMounts)) {
247 foreach ($fileMounts as $fileMountInfo) {
248 $rootLevelFolders[] = array(
249 'folder' => $fileMountInfo['folder'],
250 'name' => $fileMountInfo['title']
251 );
252 }
253 } else {
254 $rootLevelFolders[] = array(
255 'folder' => $storageObject->getRootLevelFolder(),
256 'name' => $storageObject->getName()
257 );
258 }
259
260 // Clean the tree
261 $this->reset();
262
263 // Go through all "root level folders" of this tree (can be the rootlevel folder or any file mount points)
264 foreach ($rootLevelFolders as $rootLevelFolderInfo) {
265 /** @var $rootLevelFolder t3lib_file_Folder */
266 $rootLevelFolder = $rootLevelFolderInfo['folder'];
267 $rootLevelFolderName = $rootLevelFolderInfo['name'];
268 $folderHashSpecUID = t3lib_div::md5int($rootLevelFolder->getCombinedIdentifier());
269 $this->specUIDmap[$folderHashSpecUID] = $rootLevelFolder->getCombinedIdentifier();
270
271 // Hash key
272 $storageHashNumber = $this->getShortHashNumberForStorage($storageObject, $rootLevelFolder);
273
274 // Set first:
275 $this->bank = $storageHashNumber;
276 $isOpen = $this->stored[$storageHashNumber][$folderHashSpecUID] || $this->expandFirst;
277
278 // Set PM icon:
279 $cmd = $this->generateExpandCollapseParameter($this->bank, !$isOpen, $rootLevelFolder);
280 if (!$storageObject->isBrowsable() || $this->getNumberOfSubfolders($storageObject->getRootLevelFolder()) === 0) {
281 $rootIcon = 'blank';
282 } elseif (!$isOpen) {
283 $rootIcon = 'plusonly';
284 } else {
285 $rootIcon = 'minusonly';
286 }
287 $icon = '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/ol/' . $rootIcon . '.gif') . ' alt="" />';
288 $firstHtml = $this->PM_ATagWrap($icon, $cmd);
289
290 // @todo: create sprite icons for user/group mounts etc
291 if ($storageObject->isBrowsable() === FALSE) {
292 $icon = 'apps-filetree-folder-locked';
293 } else {
294 $icon = 'apps-filetree-root';
295 }
296
297 // Mark a storage which is not online, as offline
298 // maybe someday there will be a special icon for this
299 if ($storageObject->isOnline() === FALSE) {
300 $rootLevelFolderName .= ' (' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file.xlf:sys_file_storage.isOffline') . ')';
301 }
302
303 // Preparing rootRec for the mount
304 $firstHtml .= $this->wrapIcon(t3lib_iconWorks::getSpriteIcon($icon), $rootLevelFolder);
305 $row = array(
306 'uid' => $folderHashSpecUID,
307 'title' => $rootLevelFolderName,
308 'path' => $rootLevelFolder->getCombinedIdentifier(),
309 'folder' => $rootLevelFolder
310 );
311
312 // Add the storage root to ->tree
313 $this->tree[] = array(
314 'HTML' => $firstHtml,
315 'row' => $row,
316 'bank' => $this->bank,
317 // hasSub is TRUE when the root of the storage is expanded
318 'hasSub' => ($isOpen && $storageObject->isBrowsable())
319 );
320
321 // If the mount is expanded, go down:
322 if ($isOpen && $storageObject->isBrowsable()) {
323 // Set depth:
324 $this->getFolderTree($rootLevelFolder, 999);
325 }
326 }
327 }
328
329 /**
330 * Fetches the data for the tree
331 *
332 * @param t3lib_file_Folder $folderObject the folderobject
333 * @param integer $depth Max depth (recursivity limit)
334 * @param string $type HTML-code prefix for recursive calls.
335 * @return integer The count of items on the level
336 * @see getBrowsableTree()
337 */
338 public function getFolderTree(t3lib_file_Folder $folderObject, $depth = 999, $type = '') {
339 $depth = intval($depth);
340
341 // This generates the directory tree
342 $subFolders = $folderObject->getSubfolders();
343
344 sort($subFolders);
345 $totalSubFolders = count($subFolders);
346
347 $HTML = '';
348 $subFolderCounter = 0;
349
350 foreach ($subFolders as $subFolder) {
351 $subFolderCounter++;
352 // Reserve space.
353 $this->tree[] = array();
354 // Get the key for this space
355 end($this->tree);
356 $treeKey = key($this->tree);
357
358 $specUID = t3lib_div::md5int($subFolder->getCombinedIdentifier());
359 $this->specUIDmap[$specUID] = $subFolder->getCombinedIdentifier();
360
361 $row = array(
362 'uid' => $specUID,
363 'path' => $subFolder->getCombinedIdentifier(),
364 'title' => $subFolder->getName(),
365 'folder' => $subFolder
366 );
367
368 // Make a recursive call to the next level
369 if ($depth > 1 && $this->expandNext($specUID)) {
370 $nextCount = $this->getFolderTree(
371 $subFolder,
372 $depth - 1,
373 $type
374 );
375
376 // Set "did expand" flag
377 $isOpen = 1;
378 } else {
379 $nextCount = $this->getNumberOfSubfolders($subFolder);
380 // Clear "did expand" flag
381 $isOpen = 0;
382 }
383
384 // Set HTML-icons, if any:
385 if ($this->makeHTML) {
386 $HTML = $this->PMicon($subFolder, $subFolderCounter, $totalSubFolders, $nextCount, $isOpen);
387 if ($subFolder->checkActionPermission('write')) {
388 $type = '';
389 $overlays = array();
390 } else {
391 $type = 'readonly';
392 $overlays = array('status-overlay-locked' => array());
393 }
394
395 if ($isOpen) {
396 $icon = 'apps-filetree-folder-opened';
397 } else {
398 $icon = 'apps-filetree-folder-default';
399 }
400
401 if ($subFolder->getIdentifier() == '_temp_') {
402 $icon = 'apps-filetree-folder-temp';
403 $row['title'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:temp', TRUE);
404 $row['_title'] = '<strong>' . $row['title'] . '</strong>';
405 }
406
407 if ($subFolder->getIdentifier() == '_recycler_') {
408 $icon = 'apps-filetree-folder-recycler';
409 $row['title'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:recycler', TRUE);
410 $row['_title'] = '<strong>' . $row['title'] . '</strong>';
411 }
412
413 $icon = t3lib_iconWorks::getSpriteIcon($icon, array('title' => $subFolder->getIdentifier()), $overlays);
414 $HTML .= $this->wrapIcon($icon, $subFolder);
415 }
416
417 // Finally, add the row/HTML content to the ->tree array in the reserved key.
418 $this->tree[$treeKey] = array(
419 'row' => $row,
420 'HTML' => $HTML,
421 'hasSub' => $nextCount && $this->expandNext($specUID),
422 'isFirst'=> ($subFolderCounter == 1),
423 'isLast' => FALSE,
424 'invertedDepth'=> $depth,
425 'bank' => $this->bank
426 );
427 }
428
429 if ($subFolderCounter > 0) {
430 $this->tree[$treeKey]['isLast'] = TRUE;
431 }
432
433 return $totalSubFolders;
434 }
435
436 /**
437 * Compiles the HTML code for displaying the structure found inside the ->tree array
438 *
439 * @param array|string $treeItems "tree-array" - if blank string, the internal ->tree array is used.
440 * @return string The HTML code for the tree
441 */
442 public function printTree($treeItems = '') {
443 $doExpand = FALSE;
444 $doCollapse = FALSE;
445 $ajaxOutput = '';
446
447 $titleLength = intval($this->BE_USER->uc['titleLen']);
448 if (!is_array($treeItems)) {
449 $treeItems = $this->tree;
450 }
451
452 $out = '
453 <!-- TYPO3 folder tree structure. -->
454 <ul class="tree" id="treeRoot">
455 ';
456
457 // Evaluate AJAX request
458 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) {
459 list(, $expandCollapseCommand, $expandedFolderHash,) = $this->evaluateExpandCollapseParameter();
460 if ($expandCollapseCommand == 1) {
461 // We don't know yet. Will be set later.
462 $invertedDepthOfAjaxRequestedItem = 0;
463 $doExpand = TRUE;
464 } else {
465 $doCollapse = TRUE;
466 }
467 }
468
469 // We need to count the opened <ul>'s every time we dig into another level,
470 // so we know how many we have to close when all children are done rendering
471 $closeDepth = array();
472
473 foreach ($treeItems as $treeItem) {
474 /** @var $folderObject t3lib_file_Folder */
475 $folderObject = $treeItem['row']['folder'];
476 $classAttr = $treeItem['row']['_CSSCLASS'];
477 $folderIdentifier = $folderObject->getCombinedIdentifier();
478 // this is set if the AJAX request has just opened this folder (via the PM command)
479 $isExpandedFolderIdentifier = ($expandedFolderHash == t3lib_div::md5int($folderIdentifier));
480 $idAttr = htmlspecialchars($this->domIdPrefix . $this->getId($folderObject) . '_' . $treeItem['bank']);
481 $itemHTML = '';
482
483 // If this item is the start of a new level,
484 // then a new level <ul> is needed, but not in ajax mode
485 if ($treeItem['isFirst'] && !($doCollapse) && !($doExpand && $isExpandedFolderIdentifier)) {
486 $itemHTML = "<ul>\n";
487 }
488
489 // Add CSS classes to the list item
490 if ($treeItem['hasSub']) {
491 $classAttr .= ' expanded';
492 }
493 if ($treeItem['isLast']) {
494 $classAttr .= ' last';
495 }
496
497 $itemHTML .='
498 <li id="' . $idAttr . '" ' . ($classAttr ? ' class="' . trim($classAttr) . '"' : '') . '><div class="treeLinkItem">'.
499 $treeItem['HTML'].
500 $this->wrapTitle($this->getTitleStr($treeItem['row'], $titleLength), $folderObject, $treeItem['bank']) . '</div>';
501
502 if (!$treeItem['hasSub']) {
503 $itemHTML .= "</li>\n";
504 }
505
506 // We have to remember if this is the last one
507 // on level X so the last child on level X+1 closes the <ul>-tag
508 if ($treeItem['isLast'] && !($doExpand && $isExpandedFolderIdentifier)) {
509 $closeDepth[$treeItem['invertedDepth']] = 1;
510 }
511
512 // If this is the last one and does not have subitems, we need to close
513 // the tree as long as the upper levels have last items too
514 if ($treeItem['isLast'] && !$treeItem['hasSub'] && !$doCollapse && !($doExpand && $isExpandedFolderIdentifier)) {
515 for ($i = $treeItem['invertedDepth']; $closeDepth[$i] == 1; $i++) {
516 $closeDepth[$i] = 0;
517 $itemHTML .= "</ul></li>\n";
518 }
519 }
520
521 // Ajax request: collapse
522 if ($doCollapse && $isExpandedFolderIdentifier) {
523 $this->ajaxStatus = TRUE;
524 return $itemHTML;
525 }
526
527 // Ajax request: expand
528 if ($doExpand && $isExpandedFolderIdentifier) {
529 $ajaxOutput .= $itemHTML;
530 $invertedDepthOfAjaxRequestedItem = $treeItem['invertedDepth'];
531 } elseif ($invertedDepthOfAjaxRequestedItem) {
532 if ($treeItem['invertedDepth'] < $invertedDepthOfAjaxRequestedItem) {
533 $ajaxOutput .= $itemHTML;
534 } else {
535 $this->ajaxStatus = TRUE;
536 return $ajaxOutput;
537 }
538 }
539
540 $out .= $itemHTML;
541 }
542
543 // If this is a AJAX request, output directly
544 if ($ajaxOutput) {
545 $this->ajaxStatus = TRUE;
546 return $ajaxOutput;
547 }
548
549 // Finally close the first ul
550 $out .= "</ul>\n";
551 return $out;
552 }
553
554 /**
555 * Counts the number of directories in a file path.
556 *
557 * @param string $file File path.
558 * @return integer
559 * @deprecated since TYPO3 6.0, as the folder objects do the counting automatically
560 */
561 public function getCount($file) {
562 t3lib_div::logDeprecatedFunction();
563 // This generates the directory tree
564 $dirs = t3lib_div::get_dirs($file);
565 $c = 0;
566 if (is_array($dirs)) {
567 $c = count($dirs);
568 }
569 return $c;
570 }
571
572 /**
573 * Counts the number of directories in a file path.
574 *
575 * @param t3lib_file_Folder $folderObject File path.
576 * @return integer
577 */
578 public function getNumberOfSubfolders(t3lib_file_Folder $folderObject) {
579 $subFolders = $folderObject->getSubfolders();
580 return count($subFolders);
581 }
582
583 /**
584 * Get stored tree structure AND updating it if needed according to incoming PM GET var.
585 *
586 * @return void
587 * @access private
588 */
589 function initializePositionSaving() {
590 // Get stored tree structure:
591 $this->stored = unserialize($this->BE_USER->uc['browseTrees'][$this->treeName]);
592
593 $this->getShortHashNumberForStorage();
594
595 // PM action:
596 // (If an plus/minus icon has been clicked,
597 // the PM GET var is sent and we must update the stored positions in the tree):
598 // 0: mount key, 1: set/clear boolean, 2: item ID (cannot contain "_"), 3: treeName
599 list($storageHashNumber, $doExpand, $numericFolderHash, $treeName) = $this->evaluateExpandCollapseParameter();
600 if ($treeName && $treeName == $this->treeName) {
601 if (in_array($storageHashNumber, $this->storageHashNumbers)) {
602 if ($doExpand == 1) {
603 // Set
604 $this->stored[$storageHashNumber][$numericFolderHash] = 1;
605 } else {
606 // Clear
607 unset($this->stored[$storageHashNumber][$numericFolderHash]);
608 }
609 $this->savePosition();
610 }
611 }
612 }
613
614 /**
615 * Helper method to map md5-hash to shorter number
616 *
617 * @param t3lib_file_Storage $storageObject
618 * @param t3lib_file_Folder $startingPointFolder
619 * @return integer
620 */
621 protected function getShortHashNumberForStorage(t3lib_file_Storage $storageObject = NULL, t3lib_file_Folder $startingPointFolder = NULL) {
622 if (!$this->storageHashNumbers) {
623 $this->storageHashNumbers = array();
624 // Mapping md5-hash to shorter number:
625 $hashMap = array();
626 foreach ($this->storages as $storageUid => $storage) {
627 $fileMounts = $storage->getFileMounts();
628 if (count($fileMounts)) {
629 foreach ($fileMounts as $fileMount) {
630 $nkey = hexdec(substr(t3lib_div::md5int($fileMount['folder']->getCombinedIdentifier()), 0, 4));
631 $this->storageHashNumbers[$storageUid . $fileMount['folder']->getCombinedIdentifier()] = $nkey;
632 }
633 } else {
634 $folder = $storage->getRootLevelFolder();
635 $nkey = hexdec(substr(t3lib_div::md5int($folder->getCombinedIdentifier()), 0, 4));
636 $this->storageHashNumbers[$storageUid . $folder->getCombinedIdentifier()] = $nkey;
637 }
638 }
639 }
640 if ($storageObject) {
641 if ($startingPointFolder) {
642 return $this->storageHashNumbers[$storageObject->getUid() . $startingPointFolder->getCombinedIdentifier()];
643 } else {
644 return $this->storageHashNumbers[$storageObject->getUid()];
645 }
646 } else {
647 return NULL;
648 }
649 }
650
651 /**
652 * Gets the values from the Expand/Collapse Parameter (&PM)
653 * previously known as "PM" (plus/minus)
654 * PM action:
655 * (If an plus/minus icon has been clicked,
656 * the PM GET var is sent and we must update the stored positions in the tree):
657 * 0: mount key, 1: set/clear boolean, 2: item ID (cannot contain "_"), 3: treeName
658 *
659 * @param string $PM The "plus/minus" command
660 * @return array
661 */
662 protected function evaluateExpandCollapseParameter($PM = NULL) {
663 if ($PM === NULL) {
664 $PM = t3lib_div::_GP('PM');
665 // IE takes anchor as parameter
666 if (($PMpos = strpos($PM, '#')) !== FALSE) {
667 $PM = substr($PM, 0, $PMpos);
668 }
669 }
670
671 // Take the first three parameters
672 list($mountKey, $doExpand, $folderIdentifier) = explode('_', $PM, 3);
673
674 // In case the folder identifier contains "_", we just need to get the fourth/last parameter
675 list($folderIdentifier, $treeName) = t3lib_div::revExplode('_', $folderIdentifier, 2);
676
677 return array(
678 $mountKey,
679 $doExpand,
680 $folderIdentifier,
681 $treeName
682 );
683 }
684
685 /**
686 * Generates the "PM" string to sent to expand/collapse items
687 *
688 * @param string $mountKey The mount key / storage UID
689 * @param boolean $doExpand Whether to expand/collapse
690 * @param t3lib_file_Folder $folderObject The folder object
691 * @param string $treeName The name of the tree
692 * @return string
693 */
694 protected function generateExpandCollapseParameter($mountKey = NULL, $doExpand = FALSE, t3lib_file_Folder $folderObject = NULL, $treeName = NULL) {
695 $parts = array(
696 ($mountKey !== NULL ? $mountKey : $this->bank),
697 ($doExpand == 1 ? 1 : 0),
698 ($folderObject !== NULL ? t3lib_div::md5int($folderObject->getCombinedIdentifier()) : ''),
699 ($treeName !== NULL ? $treeName : $this->treeName)
700 );
701
702 return implode('_', $parts);
703 }
704
705 /**
706 * Gets the AJAX status.
707 *
708 * @return boolean
709 */
710 public function getAjaxStatus() {
711 return $this->ajaxStatus;
712 }
713 }
714
715 ?>