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