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