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