‪TYPO3CMS  9.5
FileSystemNavigationFrameController.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
34 
40 {
42 
48  protected ‪$deprecatedPublicProperties = [
49  'content' => 'Using $content of class FileSystemNavigationFrameController from the outside is discouraged, as this variable is only used for internal storage.',
50  'foldertree' => 'Using $foldertree of class FileSystemNavigationFrameController from the outside is discouraged, as this variable is only used for internal storage.',
51  'currentSubScript' => 'Using $currentSubScript of class FileSystemNavigationFrameController from the outside is discouraged, as this variable is only used for internal storage.',
52  'cMR' => 'Using $cMR of class FileSystemNavigationFrameController from the outside is discouraged, as this variable is only used for internal storage.',
53  ];
54 
60  protected ‪$content;
61 
65  protected ‪$foldertree;
66 
70  protected ‪$currentSubScript;
71 
75  protected ‪$cMR;
76 
80  protected ‪$scopeData;
81 
87  protected ‪$moduleTemplate;
88 
92  public function ‪__construct()
93  {
94  // @deprecated since TYPO3 v9, will be obsolete in TYPO3 v10.0 with removal of init()
95  $request = ‪$GLOBALS['TYPO3_REQUEST'];
96  ‪$GLOBALS['SOBE'] = $this;
97  // @deprecated since TYPO3 v9, will be moved out of __construct() in TYPO3 v10.0
98  $this->‪init($request);
99  }
100 
105  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
106  {
107  $this->‪initializePageTemplate();
108  $this->‪renderFolderTree($request);
109  return new ‪HtmlResponse($this->content);
110  }
111 
119  public function ‪ajaxExpandCollapse(ServerRequestInterface $request): ResponseInterface
120  {
121  $tree = $this->foldertree->getBrowsableTree();
122  if ($this->foldertree->getAjaxStatus() === false) {
123  return new ‪JsonResponse(null, 500);
124  }
125  return new ‪JsonResponse([$tree]);
126  }
127 
133  protected function ‪init(ServerRequestInterface $request = null)
134  {
135  if ($request === null) {
136  // Method signature in TYPO3 v10.0: protected function init(ServerRequestInterface $request)
137  trigger_error('FileSystemNavigationFrameController->init() will be set to protected in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
138  $request = ‪$GLOBALS['TYPO3_REQUEST'];
139  }
140 
141  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
142 
143  $parsedBody = $request->getParsedBody();
144  $queryParams = $request->getQueryParams();
145 
146  $this->currentSubScript = $parsedBody['currentSubScript'] ?? $queryParams['currentSubScript'] ?? null;
147  $this->cMR = (bool)($parsedBody['cMR'] ?? $queryParams['cMR'] ?? false);
148  ‪$scopeData = $parsedBody['scopeData'] ?? $queryParams['scopeData'] ?? '';
149  $scopeHash = $parsedBody['scopeHash'] ?? $queryParams['scopeHash'] ?? '';
150 
151  if (!empty(‪$scopeData) && hash_equals(GeneralUtility::hmac(‪$scopeData), $scopeHash)) {
152  $this->scopeData = json_decode(‪$scopeData, true);
153  }
154 
155  // Create folder tree object:
156  if (!empty($this->scopeData)) {
157  $this->foldertree = GeneralUtility::makeInstance($this->scopeData['class']);
158  $this->foldertree->thisScript = $this->scopeData['script'];
159  if ($this->foldertree instanceof ElementBrowserFolderTreeView) {
160  // create a fake provider to pass link data along properly
161  $linkParamProvider = GeneralUtility::makeInstance(
162  DummyLinkParameterProvider::class,
163  $this->scopeData['browser'],
164  $this->scopeData['script']
165  );
166  $this->foldertree->setLinkParameterProvider($linkParamProvider);
167  }
168  } else {
169  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
170  $this->foldertree = GeneralUtility::makeInstance(FileListFolderTree::class);
171  $this->foldertree->thisScript = (string)$uriBuilder->buildUriFromRoute('file_navframe');
172  }
173  }
174 
181  public function ‪initPage()
182  {
183  trigger_error('FileSystemNavigationFrameController->initPage() will be replaced by protected method initializePageTemplate() in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
184  $this->‪initializePageTemplate();
185  }
186 
191  protected function ‪initializePageTemplate(): void
192  {
193  $this->moduleTemplate->setBodyTag('<body id="ext-backend-Modules-FileSystemNavigationFrame-index-php">');
194 
195  // Adding javascript code for drag&drop and the file tree as well as the click menu code
196  $hlClass = $this->‪getBackendUser()->workspace === 0 ? 'active' : 'active active-ws wsver' . ‪$GLOBALS['BE_USER']->workspace;
197  $dragDropCode = '
198  Tree.highlightClass = "' . $hlClass . '";
199  Tree.highlightActiveItem("", top.fsMod.navFrameHighlightedID["file"]);
200  ';
201 
202  // Adding javascript for drag & drop activation and highlighting
203  $pageRenderer = $this->moduleTemplate->getPageRenderer();
204  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
205  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LegacyTree', 'function() {
206  DragDrop.table = "folders";
207  Tree.registerDragDropHandlers();
208  ' . $dragDropCode . '
209  }');
210 
211  // Setting JavaScript for menu.
212  $inlineJs = ($this->currentSubScript ? 'top.currentSubScript=unescape("' . rawurlencode($this->currentSubScript) . '");' : '') . '
213  // Function, loading the list frame from navigation tree:
214  function jumpTo(id, linkObj, highlightID, bank) {
215  var theUrl = top.currentSubScript;
216  if (theUrl.indexOf("?") != -1) {
217  theUrl += "&id=" + id
218  } else {
219  theUrl += "?id=" + id
220  }
221  top.fsMod.currentBank = bank;
222  top.TYPO3.Backend.ContentContainer.setUrl(theUrl);
223 
224  Tree.highlightActiveItem("file", highlightID + "_" + bank);
225  if (linkObj) { linkObj.blur(); }
226  return false;
227  }
228  ' . ($this->cMR ? ' jumpTo(top.fsMod.recentIds[\'file\'],\'\');' : '');
229 
230  $this->moduleTemplate->getPageRenderer()->addJsInlineCode(
231  'FileSystemNavigationFrame',
232  $inlineJs
233  );
234  }
235 
241  public function ‪main()
242  {
243  trigger_error('FileSystemNavigationFrameController->main() will be replaced by protected method renderFolderTree() in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
244  $this->‪renderFolderTree(‪$GLOBALS['TYPO3_REQUEST']);
245  }
246 
252  protected function ‪renderFolderTree(ServerRequestInterface $request): void
253  {
254  // Produce browse-tree:
255  $tree = $this->foldertree->getBrowsableTree();
256  // Outputting page tree:
257  $this->moduleTemplate->setContent($tree);
258  // Setting up the buttons
259  $this->‪getButtons($request);
260  // Build the <body> for the module
261  $this->moduleTemplate->setTitle('TYPO3 Folder Tree');
262  $this->content = $this->moduleTemplate->renderContent();
263  }
264 
270  protected function ‪getButtons(ServerRequestInterface $request): void
271  {
273  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
275  $iconFactory = $this->moduleTemplate->getIconFactory();
277  $normalizedParams = $request->getAttribute('normalizedParams');
278 
279  // Refresh
280  $refreshButton = $buttonBar->makeLinkButton()
281  ->setHref($normalizedParams->getRequestUri())
282  ->setTitle($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.reload'))
283  ->setIcon($iconFactory->getIcon('actions-refresh', ‪Icon::SIZE_SMALL));
284  $buttonBar->addButton($refreshButton, ‪ButtonBar::BUTTON_POSITION_RIGHT);
285 
286  // CSH
287  $cshButton = $buttonBar->makeHelpButton()
288  ->setModuleName('xMOD_csh_corebe')
289  ->setFieldName('filetree');
290  $buttonBar->addButton($cshButton);
291  }
292 
296  protected function ‪getBackendUser(): ‪BackendUserAuthentication
297  {
298  return ‪$GLOBALS['BE_USER'];
299  }
300 
306  protected function ‪getLanguageService(): ‪LanguageService
307  {
308  return ‪$GLOBALS['LANG'];
309  }
310 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: FileSystemNavigationFrameController.php:79
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\getButtons
‪getButtons(ServerRequestInterface $request)
Definition: FileSystemNavigationFrameController.php:262
‪TYPO3\CMS\Filelist\FileListFolderTree
Definition: FileListFolderTree.php:23
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:31
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\main
‪main()
Definition: FileSystemNavigationFrameController.php:233
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\renderFolderTree
‪renderFolderTree(ServerRequestInterface $request)
Definition: FileSystemNavigationFrameController.php:244
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: FileSystemNavigationFrameController.php:97
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController
Definition: FileSystemNavigationFrameController.php:40
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\$currentSubScript
‪string $currentSubScript
Definition: FileSystemNavigationFrameController.php:65
‪TYPO3\CMS\Backend\Tree\View\ElementBrowserFolderTreeView
Definition: ElementBrowserFolderTreeView.php:31
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\init
‪init(ServerRequestInterface $request=null)
Definition: FileSystemNavigationFrameController.php:125
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:31
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: FileSystemNavigationFrameController.php:288
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:40
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\$foldertree
‪TYPO3 CMS Backend Tree View FolderTreeView $foldertree
Definition: FileSystemNavigationFrameController.php:61
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:35
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\$scopeData
‪array $scopeData
Definition: FileSystemNavigationFrameController.php:73
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\getLanguageService
‪LanguageService getLanguageService()
Definition: FileSystemNavigationFrameController.php:298
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\ajaxExpandCollapse
‪ResponseInterface ajaxExpandCollapse(ServerRequestInterface $request)
Definition: FileSystemNavigationFrameController.php:111
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\$deprecatedPublicProperties
‪array $deprecatedPublicProperties
Definition: FileSystemNavigationFrameController.php:46
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\__construct
‪__construct()
Definition: FileSystemNavigationFrameController.php:84
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:25
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\$cMR
‪bool $cMR
Definition: FileSystemNavigationFrameController.php:69
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait
Definition: PublicPropertyDeprecationTrait.php:66
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_RIGHT
‪const BUTTON_POSITION_RIGHT
Definition: ButtonBar.php:40
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\initializePageTemplate
‪initializePageTemplate()
Definition: FileSystemNavigationFrameController.php:183
‪TYPO3\CMS\Backend\Controller
Definition: AbstractFormEngineAjaxController.php:3
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\$content
‪string $content
Definition: FileSystemNavigationFrameController.php:57
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:25
‪TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController\initPage
‪initPage()
Definition: FileSystemNavigationFrameController.php:173