f6ba3432da35bf8f308b7f388630c46d18f86e9e
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Tree / View / FolderTreeView.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tree\View;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\IconUtility;
18 use TYPO3\CMS\Core\Messaging\FlashMessage;
19 use TYPO3\CMS\Core\Resource\Folder;
20 use TYPO3\CMS\Core\Resource\FolderInterface;
21 use TYPO3\CMS\Core\Resource\InaccessibleFolder;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23 use TYPO3\CMS\Lang\LanguageService;
24
25 /**
26 * Generate a folder tree,
27 * specially made for browsing folders in the File module
28 */
29 class FolderTreeView extends AbstractTreeView {
30
31 /**
32 * The users' file Storages
33 *
34 * @var \TYPO3\CMS\Core\Resource\ResourceStorage[]
35 */
36 protected $storages = NULL;
37
38 /**
39 * @var array
40 */
41 protected $storageHashNumbers;
42
43 /**
44 * Indicates, whether the AJAX call was successful,
45 * i.e. the requested page has been found
46 *
47 * @var bool
48 */
49 protected $ajaxStatus = FALSE;
50
51 /**
52 * @var array
53 */
54 protected $scope;
55
56 /**
57 * If file-drag mode is set, temp and recycler folders are filtered out.
58 * @var bool
59 */
60 public $ext_noTempRecyclerDirs;
61
62 /**
63 * override to not use a title attribute
64 * @var string
65 */
66 public $titleAttrib = '';
67
68 /**
69 * override to use this treeName
70 * does not need to be set in __construct()
71 * @var string
72 */
73 public $treeName = 'folder';
74
75 /**
76 * override to use this domIdPrefix
77 * @var string
78 */
79 public $domIdPrefix = 'folder';
80
81 /**
82 * Constructor function of the class
83 */
84 public function __construct() {
85 parent::init();
86 $this->storages = $this->BE_USER->getFileStorages();
87 }
88
89 /**
90 * Generate the plus/minus icon for the browsable tree.
91 *
92 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject Entry folder object
93 * @param int $subFolderCounter The current entry number
94 * @param int $totalSubFolders The total number of entries. If equal to $a, a "bottom" element is returned.
95 * @param int $nextCount The number of sub-elements to the current element.
96 * @param bool $isExpanded The element was expanded to render subelements if this flag is set.
97 * @return string Image tag with the plus/minus icon.
98 * @internal
99 * @see \TYPO3\CMS\Backend\Tree\View\PageTreeView::PMicon()
100 */
101 public function PMicon($folderObject, $subFolderCounter, $totalSubFolders, $nextCount, $isExpanded) {
102 $icon = '';
103 if ($nextCount) {
104 $cmd = $this->generateExpandCollapseParameter($this->bank, !$isExpanded, $folderObject);
105 $icon = $this->PMiconATagWrap($icon, $cmd, !$isExpanded);
106 }
107 return $icon;
108 }
109
110 /**
111 * Wrap the plus/minus icon in a link
112 *
113 * @param string $icon HTML string to wrap, probably an image tag.
114 * @param string $cmd Command for 'PM' get var
115 * @param bool $isExpand Whether to be expanded
116 * @return string Link-wrapped input string
117 * @internal
118 */
119 public function PMiconATagWrap($icon, $cmd, $isExpand = TRUE) {
120
121 if (empty($this->scope)) {
122 $this->scope = array(
123 'class' => get_class($this),
124 'script' => $this->thisScript,
125 'ext_noTempRecyclerDirs' => $this->ext_noTempRecyclerDirs
126 );
127 }
128
129 if ($this->thisScript) {
130 // Activates dynamic AJAX based tree
131 $scopeData = serialize($this->scope);
132 $scopeHash = GeneralUtility::hmac($scopeData);
133 $js = htmlspecialchars('Tree.load(' . GeneralUtility::quoteJSvalue($cmd) . ', ' . (int)$isExpand . ', this, ' . GeneralUtility::quoteJSvalue($scopeData) . ', ' . GeneralUtility::quoteJSvalue($scopeHash) . ');');
134 return '<a class="list-tree-control' . (!$isExpand ? ' list-tree-control-open' : ' list-tree-control-closed') . '" onclick="' . $js . '"><i class="fa"></i></a>';
135 } else {
136 return $icon;
137 }
138 }
139
140 /**
141 * Wrapping the folder icon
142 *
143 * @param string $icon The image tag for the icon
144 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject The row for the current element
145 * @return string The processed icon input value.
146 * @internal
147 */
148 public function wrapIcon($icon, $folderObject) {
149 // Add title attribute to input icon tag
150 $theFolderIcon = '';
151 // Wrap icon in click-menu link.
152 if (!$this->ext_IconMode) {
153 // Check storage access to wrap with click menu
154 if (!$folderObject instanceof InaccessibleFolder) {
155 $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($icon, $folderObject->getCombinedIdentifier(), '', 0);
156 }
157 } elseif ($this->ext_IconMode === 'titlelink') {
158 $aOnClick = 'return jumpTo(' . GeneralUtility::quoteJSvalue($this->getJumpToParam($folderObject)) . ',this,' . GeneralUtility::quoteJSvalue($this->domIdPrefix . $this->getId($folderObject)) . ',' . $this->bank . ');';
159 $theFolderIcon = '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . $icon . '</a>';
160 }
161 return $theFolderIcon;
162 }
163
164 /**
165 * Wrapping $title in a-tags.
166 *
167 * @param string $title Title string
168 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject the folder record
169 * @param int $bank Bank pointer (which mount point number)
170 * @return string
171 * @internal
172 */
173 public function wrapTitle($title, $folderObject, $bank = 0) {
174 // Check storage access to wrap with click menu
175 if ($folderObject instanceof InaccessibleFolder) {
176 return $title;
177 }
178 $aOnClick = 'return jumpTo(' . GeneralUtility::quoteJSvalue($this->getJumpToParam($folderObject)) . ', this, ' . GeneralUtility::quoteJSvalue($this->domIdPrefix . $this->getId($folderObject)) . ', ' . $bank . ');';
179 $clickMenuParts = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('', $folderObject->getCombinedIdentifier(), '', 0, ('&bank=' . $this->bank), '', TRUE);
180
181 return '<a href="#" title="' . htmlspecialchars(strip_tags($title)) . '" onclick="' . htmlspecialchars($aOnClick) . '" ' . GeneralUtility::implodeAttributes($clickMenuParts) . '>' . $title . '</a>';
182 }
183
184 /**
185 * Returns the id from the record - for folders, this is an md5 hash.
186 *
187 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject The folder object
188 * @return int The "uid" field value.
189 */
190 public function getId($folderObject) {
191 return GeneralUtility::md5Int($folderObject->getCombinedIdentifier());
192 }
193
194 /**
195 * Returns jump-url parameter value.
196 *
197 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject The folder object
198 * @return string The jump-url parameter.
199 */
200 public function getJumpToParam($folderObject) {
201 return rawurlencode($folderObject->getCombinedIdentifier());
202 }
203
204 /**
205 * Returns the title for the input record. If blank, a "no title" labele (localized) will be returned.
206 * '_title' is used for setting an alternative title for folders.
207 *
208 * @param array $row The input row array (where the key "_title" is used for the title)
209 * @param int $titleLen Title length (30)
210 * @return string The title
211 */
212 public function getTitleStr($row, $titleLen = 30) {
213 return $row['_title'] ?: parent::getTitleStr($row, $titleLen);
214 }
215
216 /**
217 * Returns the value for the image "title" attribute
218 *
219 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject The folder to be used
220 * @return string The attribute value (is htmlspecialchared() already)
221 */
222 public function getTitleAttrib($folderObject) {
223 return htmlspecialchars($folderObject->getName());
224 }
225
226 /**
227 * Will create and return the HTML code for a browsable tree of folders.
228 * Is based on the mounts found in the internal array ->MOUNTS (set in the constructor)
229 *
230 * @return string HTML code for the browsable tree
231 */
232 public function getBrowsableTree() {
233 // Get stored tree structure AND updating it if needed according to incoming PM GET var.
234 $this->initializePositionSaving();
235 // Init done:
236 $treeItems = array();
237 // Traverse mounts:
238 foreach ($this->storages as $storageObject) {
239 $this->getBrowseableTreeForStorage($storageObject);
240 // Add tree:
241 $treeItems = array_merge($treeItems, $this->tree);
242 }
243 return $this->printTree($treeItems);
244 }
245
246 /**
247 * Get a tree for one storage
248 *
249 * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storageObject
250 * @return void
251 */
252 public function getBrowseableTreeForStorage(\TYPO3\CMS\Core\Resource\ResourceStorage $storageObject) {
253 // If there are filemounts, show each, otherwise just the rootlevel folder
254 $fileMounts = $storageObject->getFileMounts();
255 $rootLevelFolders = array();
256 if (!empty($fileMounts)) {
257 foreach ($fileMounts as $fileMountInfo) {
258 $rootLevelFolders[] = array(
259 'folder' => $fileMountInfo['folder'],
260 'name' => $fileMountInfo['title']
261 );
262 }
263 } elseif ($this->BE_USER->isAdmin()) {
264 $rootLevelFolders[] = array(
265 'folder' => $storageObject->getRootLevelFolder(),
266 'name' => $storageObject->getName()
267 );
268 }
269 // Clean the tree
270 $this->reset();
271 // Go through all "root level folders" of this tree (can be the rootlevel folder or any file mount points)
272 foreach ($rootLevelFolders as $rootLevelFolderInfo) {
273 /** @var $rootLevelFolder \TYPO3\CMS\Core\Resource\Folder */
274 $rootLevelFolder = $rootLevelFolderInfo['folder'];
275 $rootLevelFolderName = $rootLevelFolderInfo['name'];
276 $folderHashSpecUID = GeneralUtility::md5int($rootLevelFolder->getCombinedIdentifier());
277 $this->specUIDmap[$folderHashSpecUID] = $rootLevelFolder->getCombinedIdentifier();
278 // Hash key
279 $storageHashNumber = $this->getShortHashNumberForStorage($storageObject, $rootLevelFolder);
280 // Set first:
281 $this->bank = $storageHashNumber;
282 $isOpen = $this->stored[$storageHashNumber][$folderHashSpecUID] || $this->expandFirst;
283 // Set PM icon:
284 $cmd = $this->generateExpandCollapseParameter($this->bank, !$isOpen, $rootLevelFolder);
285 if (!$storageObject->isBrowsable() || $this->getNumberOfSubfolders($rootLevelFolder) === 0) {
286 $firstHtml = '';
287 } else {
288 // Only show and link icon if storage is browseable
289 if (get_class($this) !== ElementBrowserFolderTreeView::class) {
290 $link = '';
291 if ($this->thisScript) {
292 $link = ' href="' . htmlspecialchars($this->getThisScript() . 'PM=' . $cmd) . '"';
293 }
294 $firstHtml = '<a class="list-tree-control list-tree-control-' . ($isOpen ? 'open' : 'closed') . '"' . $link . '><i class="fa"></i></a>';
295 } else {
296 $firstHtml = $this->PMiconATagWrap('', $cmd, !$isOpen);
297 }
298 }
299 // Mark a storage which is not online, as offline
300 // maybe someday there will be a special icon for this
301 if ($storageObject->isOnline() === FALSE) {
302 $rootLevelFolderName .= ' (' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file.xlf:sys_file_storage.isOffline') . ')';
303 }
304 // Preparing rootRec for the mount
305 $firstHtml .= $this->wrapIcon(IconUtility::getSpriteIconForResource($rootLevelFolder, array('mount-root' => TRUE)), $rootLevelFolder);
306 $row = array(
307 'uid' => $folderHashSpecUID,
308 'title' => $rootLevelFolderName,
309 'path' => $rootLevelFolder->getCombinedIdentifier(),
310 'folder' => $rootLevelFolder
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 'invertedDepth' => 1000,
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 \TYPO3\CMS\Core\Resource\Folder $folderObject the folderobject
333 * @param int $depth Max depth (recursivity limit)
334 * @param string $type HTML-code prefix for recursive calls.
335 * @return int The count of items on the level
336 * @see getBrowsableTree()
337 */
338 public function getFolderTree(\TYPO3\CMS\Core\Resource\Folder $folderObject, $depth = 999, $type = '') {
339 $depth = (int)$depth;
340
341 // This generates the directory tree
342 /* array of \TYPO3\CMS\Core\Resource\Folder */
343 if ($folderObject instanceof InaccessibleFolder) {
344 $subFolders = array();
345 } else {
346 $subFolders = $folderObject->getSubfolders();
347 $subFolders = \TYPO3\CMS\Core\Resource\Utility\ListUtility::resolveSpecialFolderNames($subFolders);
348 uksort($subFolders, 'strnatcasecmp');
349 }
350
351 $totalSubFolders = count($subFolders);
352 $HTML = '';
353 $subFolderCounter = 0;
354 $treeKey = '';
355 /** @var Folder $subFolder */
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 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
426 if (empty($treeItems)) {
427 $message = GeneralUtility::makeInstance(
428 FlashMessage::class,
429 $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang.xlf:foldertreeview.noFolders.message'),
430 $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang.xlf:foldertreeview.noFolders.title'),
431 FlashMessage::INFO
432 );
433 return $message->render();
434 }
435
436 $expandedFolderHash = '';
437 $invertedDepthOfAjaxRequestedItem = 0;
438 $out = '<ul class="list-tree list-tree-root">';
439 // Evaluate AJAX request
440 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) {
441 list(, $expandCollapseCommand, $expandedFolderHash, ) = $this->evaluateExpandCollapseParameter();
442 if ($expandCollapseCommand == 1) {
443 $doExpand = TRUE;
444 } else {
445 $doCollapse = TRUE;
446 }
447 }
448 // We need to count the opened <ul>'s every time we dig into another level,
449 // so we know how many we have to close when all children are done rendering
450 $closeDepth = array();
451 foreach ($treeItems as $treeItem) {
452 /** @var $folderObject \TYPO3\CMS\Core\Resource\Folder */
453 $folderObject = $treeItem['row']['folder'];
454 $classAttr = $treeItem['row']['_CSSCLASS'];
455 $folderIdentifier = $folderObject->getCombinedIdentifier();
456 // this is set if the AJAX request has just opened this folder (via the PM command)
457 $isExpandedFolderIdentifier = $expandedFolderHash == GeneralUtility::md5int($folderIdentifier);
458 $idAttr = htmlspecialchars($this->domIdPrefix . $this->getId($folderObject) . '_' . $treeItem['bank']);
459 $itemHTML = '';
460 // If this item is the start of a new level,
461 // then a new level <ul> is needed, but not in ajax mode
462 if ($treeItem['isFirst'] && !$doCollapse && !($doExpand && $isExpandedFolderIdentifier)) {
463 $itemHTML = '<ul class="list-tree">';
464 }
465 // Add CSS classes to the list item
466 if ($treeItem['hasSub']) {
467 $classAttr .= ' list-tree-control-open';
468 }
469 $itemHTML .= '
470 <li id="' . $idAttr . '" ' . ($classAttr ? ' class="' . trim($classAttr) . '"' : '') . '><span class="list-tree-group">' . $treeItem['HTML'] . $this->wrapTitle($this->getTitleStr($treeItem['row'], $titleLength), $folderObject, $treeItem['bank']) . '</span>';
471 if (!$treeItem['hasSub']) {
472 $itemHTML .= '</li>';
473 }
474 // We have to remember if this is the last one
475 // on level X so the last child on level X+1 closes the <ul>-tag
476 if ($treeItem['isLast'] && !($doExpand && $isExpandedFolderIdentifier)) {
477 $closeDepth[$treeItem['invertedDepth']] = 1;
478 }
479 // If this is the last one and does not have subitems, we need to close
480 // the tree as long as the upper levels have last items too
481 if ($treeItem['isLast'] && !$treeItem['hasSub'] && !$doCollapse && !($doExpand && $isExpandedFolderIdentifier)) {
482 for ($i = $treeItem['invertedDepth']; $closeDepth[$i] == 1; $i++) {
483 $closeDepth[$i] = 0;
484 $itemHTML .= '</ul></li>';
485 }
486 }
487 // Ajax request: collapse
488 if ($doCollapse && $isExpandedFolderIdentifier) {
489 $this->ajaxStatus = TRUE;
490 return $itemHTML;
491 }
492 // Ajax request: expand
493 if ($doExpand && $isExpandedFolderIdentifier) {
494 $ajaxOutput .= $itemHTML;
495 $invertedDepthOfAjaxRequestedItem = $treeItem['invertedDepth'];
496 } elseif ($invertedDepthOfAjaxRequestedItem) {
497 if ($treeItem['invertedDepth'] && ($treeItem['invertedDepth'] < $invertedDepthOfAjaxRequestedItem)) {
498 $ajaxOutput .= $itemHTML;
499 } else {
500 $this->ajaxStatus = TRUE;
501 return $ajaxOutput;
502 }
503 }
504 $out .= $itemHTML;
505 }
506 // If this is an AJAX request, output directly
507 if ($ajaxOutput) {
508 $this->ajaxStatus = TRUE;
509 return $ajaxOutput;
510 }
511 // Finally close the first ul
512 $out .= '</ul>';
513 return $out;
514 }
515
516 /**
517 * Counts the number of directories in a file path.
518 *
519 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject File path.
520 * @return int
521 */
522 public function getNumberOfSubfolders(\TYPO3\CMS\Core\Resource\Folder $folderObject) {
523 $subFolders = $folderObject->getSubfolders();
524 return count($subFolders);
525 }
526
527 /**
528 * Get stored tree structure AND updating it if needed according to incoming PM GET var.
529 *
530 * @return void
531 * @access private
532 */
533 public function initializePositionSaving() {
534 // Get stored tree structure:
535 $this->stored = unserialize($this->BE_USER->uc['browseTrees'][$this->treeName]);
536 $this->getShortHashNumberForStorage();
537 // PM action:
538 // (If an plus/minus icon has been clicked,
539 // the PM GET var is sent and we must update the stored positions in the tree):
540 // 0: mount key, 1: set/clear boolean, 2: item ID (cannot contain "_"), 3: treeName
541 list($storageHashNumber, $doExpand, $numericFolderHash, $treeName) = $this->evaluateExpandCollapseParameter();
542 if ($treeName && $treeName == $this->treeName) {
543 if (in_array($storageHashNumber, $this->storageHashNumbers)) {
544 if ($doExpand == 1) {
545 // Set
546 $this->stored[$storageHashNumber][$numericFolderHash] = 1;
547 } else {
548 // Clear
549 unset($this->stored[$storageHashNumber][$numericFolderHash]);
550 }
551 $this->savePosition();
552 }
553 }
554 }
555
556 /**
557 * Helper method to map md5-hash to shorter number
558 *
559 * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storageObject
560 * @param \TYPO3\CMS\Core\Resource\Folder $startingPointFolder
561 * @return int
562 */
563 protected function getShortHashNumberForStorage(\TYPO3\CMS\Core\Resource\ResourceStorage $storageObject = NULL, \TYPO3\CMS\Core\Resource\Folder $startingPointFolder = NULL) {
564 if (!$this->storageHashNumbers) {
565 $this->storageHashNumbers = array();
566 // Mapping md5-hash to shorter number:
567 $hashMap = array();
568 foreach ($this->storages as $storageUid => $storage) {
569 $fileMounts = $storage->getFileMounts();
570 if (!empty($fileMounts)) {
571 foreach ($fileMounts as $fileMount) {
572 $nkey = hexdec(substr(GeneralUtility::md5int($fileMount['folder']->getCombinedIdentifier()), 0, 4));
573 $this->storageHashNumbers[$storageUid . $fileMount['folder']->getCombinedIdentifier()] = $nkey;
574 }
575 } else {
576 $folder = $storage->getRootLevelFolder();
577 $nkey = hexdec(substr(GeneralUtility::md5int($folder->getCombinedIdentifier()), 0, 4));
578 $this->storageHashNumbers[$storageUid . $folder->getCombinedIdentifier()] = $nkey;
579 }
580 }
581 }
582 if ($storageObject) {
583 if ($startingPointFolder) {
584 return $this->storageHashNumbers[$storageObject->getUid() . $startingPointFolder->getCombinedIdentifier()];
585 } else {
586 return $this->storageHashNumbers[$storageObject->getUid()];
587 }
588 } else {
589 return NULL;
590 }
591 }
592
593 /**
594 * Gets the values from the Expand/Collapse Parameter (&PM)
595 * previously known as "PM" (plus/minus)
596 * PM action:
597 * (If an plus/minus icon has been clicked,
598 * the PM GET var is sent and we must update the stored positions in the tree):
599 * 0: mount key, 1: set/clear boolean, 2: item ID (cannot contain "_"), 3: treeName
600 *
601 * @param string $PM The "plus/minus" command
602 * @return array
603 */
604 protected function evaluateExpandCollapseParameter($PM = NULL) {
605 if ($PM === NULL) {
606 $PM = GeneralUtility::_GP('PM');
607 // IE takes anchor as parameter
608 if (($PMpos = strpos($PM, '#')) !== FALSE) {
609 $PM = substr($PM, 0, $PMpos);
610 }
611 }
612 // Take the first three parameters
613 list($mountKey, $doExpand, $folderIdentifier) = explode('_', $PM, 3);
614 // In case the folder identifier contains "_", we just need to get the fourth/last parameter
615 list($folderIdentifier, $treeName) = GeneralUtility::revExplode('_', $folderIdentifier, 2);
616 return array(
617 $mountKey,
618 $doExpand,
619 $folderIdentifier,
620 $treeName
621 );
622 }
623
624 /**
625 * Generates the "PM" string to sent to expand/collapse items
626 *
627 * @param string $mountKey The mount key / storage UID
628 * @param bool $doExpand Whether to expand/collapse
629 * @param \TYPO3\CMS\Core\Resource\Folder $folderObject The folder object
630 * @param string $treeName The name of the tree
631 * @return string
632 */
633 protected function generateExpandCollapseParameter($mountKey = NULL, $doExpand = FALSE, \TYPO3\CMS\Core\Resource\Folder $folderObject = NULL, $treeName = NULL) {
634 $parts = array(
635 $mountKey !== NULL ? $mountKey : $this->bank,
636 $doExpand == 1 ? 1 : 0,
637 $folderObject !== NULL ? GeneralUtility::md5int($folderObject->getCombinedIdentifier()) : '',
638 $treeName !== NULL ? $treeName : $this->treeName
639 );
640 return implode('_', $parts);
641 }
642
643 /**
644 * Gets the AJAX status.
645 *
646 * @return bool
647 */
648 public function getAjaxStatus() {
649 return $this->ajaxStatus;
650 }
651
652 /**
653 * @return LanguageService
654 */
655 protected function getLanguageService() {
656 return $GLOBALS['LANG'];
657 }
658
659 }