‪TYPO3CMS  10.4
FileSystemNavigationFrameController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
35 
41 {
47  protected ‪$content;
48 
52  protected ‪$foldertree;
53 
57  protected ‪$currentSubScript;
58 
62  protected ‪$cMR;
63 
67  protected ‪$scopeData;
68 
74  protected ‪$moduleTemplate;
75 
80  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
81  {
82  $this->‪init($request);
84  $this->‪renderFolderTree($request);
85  return new ‪HtmlResponse($this->content);
86  }
87 
95  public function ‪ajaxExpandCollapse(ServerRequestInterface $request): ResponseInterface
96  {
97  $this->‪init($request);
98  $tree = $this->foldertree->getBrowsableTree();
99  if ($this->foldertree->getAjaxStatus() === false) {
100  return new ‪JsonResponse(null, 500);
101  }
102  return new JsonResponse([$tree]);
103  }
104 
110  protected function ‪init(ServerRequestInterface $request)
111  {
112  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
113 
114  $parsedBody = $request->getParsedBody();
115  $queryParams = $request->getQueryParams();
116 
117  $this->currentSubScript = $parsedBody['currentSubScript'] ?? $queryParams['currentSubScript'] ?? null;
118  $this->cMR = (bool)($parsedBody['cMR'] ?? $queryParams['cMR'] ?? false);
119  ‪$scopeData = $parsedBody['scopeData'] ?? $queryParams['scopeData'] ?? '';
120  $scopeHash = $parsedBody['scopeHash'] ?? $queryParams['scopeHash'] ?? '';
121 
122  if (!empty(‪$scopeData) && hash_equals(GeneralUtility::hmac(‪$scopeData), $scopeHash)) {
123  $this->scopeData = json_decode(‪$scopeData, true);
124  }
125 
126  // Create folder tree object:
127  if (!empty($this->scopeData)) {
128  $this->foldertree = GeneralUtility::makeInstance($this->scopeData['class']);
129  $this->foldertree->thisScript = $this->scopeData['script'];
130  if ($this->foldertree instanceof ‪ElementBrowserFolderTreeView) {
131  // create a fake provider to pass link data along properly
132  $linkParamProvider = GeneralUtility::makeInstance(
133  DummyLinkParameterProvider::class,
134  $this->scopeData['browser'],
135  $this->scopeData['script']
136  );
137  $this->foldertree->setLinkParameterProvider($linkParamProvider);
138  }
139  } else {
140  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
141  $this->foldertree = GeneralUtility::makeInstance(FileListFolderTree::class);
142  $this->foldertree->thisScript = (string)$uriBuilder->buildUriFromRoute('file_navframe');
143  }
144  }
145 
150  protected function ‪initializePageTemplate(): void
151  {
152  $this->moduleTemplate->setBodyTag('<body id="ext-backend-Modules-FileSystemNavigationFrame-index-php">');
153 
154  // Adding javascript code for drag&drop and the file tree as well as the click menu code
155  $hlClass = $this->‪getBackendUser()->workspace === 0 ? 'active' : 'active active-ws wsver' . ‪$GLOBALS['BE_USER']->workspace;
156  $dragDropCode = '
157  Tree.highlightClass = "' . $hlClass . '";
158  Tree.highlightActiveItem("", top.fsMod.navFrameHighlightedID["file"]);
159  ';
160 
161  // Adding javascript for drag & drop activation and highlighting
162  $pageRenderer = $this->moduleTemplate->getPageRenderer();
163  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
164  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/BroadcastService', 'function(service) { service.listen(); }');
165  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LegacyTree', 'function() {
166  DragDrop.table = "folders";
167  Tree.registerDragDropHandlers();
168  ' . $dragDropCode . '
169  }');
170 
171  // Setting JavaScript for menu.
172  $inlineJs = ($this->currentSubScript ? 'top.currentSubScript=unescape("' . rawurlencode($this->currentSubScript) . '");' : '') . '
173  // Function, loading the list frame from navigation tree:
174  function jumpTo(id, linkObj, highlightID, bank) {
175  var theUrl = top.currentSubScript;
176  if (theUrl.indexOf("?") != -1) {
177  theUrl += "&id=" + id
178  } else {
179  theUrl += "?id=" + id
180  }
181  top.fsMod.currentBank = bank;
182  top.TYPO3.Backend.ContentContainer.setUrl(theUrl);
183 
184  Tree.highlightActiveItem("file", highlightID + "_" + bank);
185  if (linkObj) { linkObj.blur(); }
186  return false;
187  }
188  ' . ($this->cMR ? ' jumpTo(top.fsMod.recentIds[\'file\'],\'\');' : '');
189 
190  $this->moduleTemplate->getPageRenderer()->addJsInlineCode(
191  'FileSystemNavigationFrame',
192  $inlineJs
193  );
194  }
195 
201  protected function ‪renderFolderTree(ServerRequestInterface $request): void
202  {
203  // Produce browse-tree:
204  $tree = $this->foldertree->getBrowsableTree();
205  // Outputting page tree:
206  $this->moduleTemplate->setContent($tree);
207  // Setting up the buttons
208  $this->‪getButtons($request);
209  // Build the <body> for the module
210  $this->moduleTemplate->setTitle('TYPO3 Folder Tree');
211  $this->content = $this->moduleTemplate->renderContent();
212  }
213 
219  protected function ‪getButtons(ServerRequestInterface $request): void
220  {
222  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
224  $iconFactory = $this->moduleTemplate->getIconFactory();
226  $normalizedParams = $request->getAttribute('normalizedParams');
227 
228  // Refresh
229  $refreshButton = $buttonBar->makeLinkButton()
230  ->setHref($normalizedParams->getRequestUri())
231  ->setTitle($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.reload'))
232  ->setIcon($iconFactory->getIcon('actions-refresh', ‪Icon::SIZE_SMALL));
233  $buttonBar->addButton($refreshButton, ‪ButtonBar::BUTTON_POSITION_RIGHT);
234 
235  // CSH
236  $cshButton = $buttonBar->makeHelpButton()
237  ->setModuleName('xMOD_csh_corebe')
238  ->setFieldName('filetree');
239  $buttonBar->addButton($cshButton);
240  }
241 
245  protected function ‪getBackendUser(): ‪BackendUserAuthentication
246  {
247  return ‪$GLOBALS['BE_USER'];
248  }
249 
255  protected function ‪getLanguageService(): ‪LanguageService
256  {
257  return ‪$GLOBALS['LANG'];
258  }
259 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: FileSystemNavigationFrameController.php:68
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\getButtons
‪getButtons(ServerRequestInterface $request)
Definition: FileSystemNavigationFrameController.php:213
‪TYPO3\CMS\Filelist\FileListFolderTree
Definition: FileListFolderTree.php:26
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:32
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\renderFolderTree
‪renderFolderTree(ServerRequestInterface $request)
Definition: FileSystemNavigationFrameController.php:195
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: FileSystemNavigationFrameController.php:74
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController
Definition: FileSystemNavigationFrameController.php:41
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\$currentSubScript
‪string $currentSubScript
Definition: FileSystemNavigationFrameController.php:54
‪TYPO3\CMS\Backend\Tree\View\ElementBrowserFolderTreeView
Definition: ElementBrowserFolderTreeView.php:31
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:33
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: FileSystemNavigationFrameController.php:239
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:43
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\init
‪init(ServerRequestInterface $request)
Definition: FileSystemNavigationFrameController.php:104
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\$foldertree
‪TYPO3 CMS Backend Tree View FolderTreeView $foldertree
Definition: FileSystemNavigationFrameController.php:50
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\$scopeData
‪array $scopeData
Definition: FileSystemNavigationFrameController.php:62
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\getLanguageService
‪LanguageService getLanguageService()
Definition: FileSystemNavigationFrameController.php:249
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\ajaxExpandCollapse
‪ResponseInterface ajaxExpandCollapse(ServerRequestInterface $request)
Definition: FileSystemNavigationFrameController.php:89
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:26
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\$cMR
‪bool $cMR
Definition: FileSystemNavigationFrameController.php:58
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_RIGHT
‪const BUTTON_POSITION_RIGHT
Definition: ButtonBar.php:41
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\initializePageTemplate
‪initializePageTemplate()
Definition: FileSystemNavigationFrameController.php:144
‪TYPO3\CMS\Backend\Controller
Definition: AbstractFormEngineAjaxController.php:18
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\$content
‪string $content
Definition: FileSystemNavigationFrameController.php:46
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26