TYPO3 CMS  TYPO3_8-7
FileSystemNavigationFrameController.php
Go to the documentation of this file.
1 <?php
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 
28 
33 {
39  public $content;
40 
44  public $foldertree;
45 
50 
54  public $cMR;
55 
59  protected $scopeData;
60 
66  protected $moduleTemplate;
67 
71  public function __construct()
72  {
73  $GLOBALS['SOBE'] = $this;
74  $this->init();
75  }
76 
82  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
83  {
84  $this->initPage();
85  $this->main();
86 
87  $response->getBody()->write($this->content);
88  return $response;
89  }
90 
94  protected function init()
95  {
96  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
97 
98  // Setting GPvars:
99  $this->currentSubScript = GeneralUtility::_GP('currentSubScript');
100  $this->cMR = GeneralUtility::_GP('cMR');
101 
102  $scopeData = (string)GeneralUtility::_GP('scopeData');
103  $scopeHash = (string)GeneralUtility::_GP('scopeHash');
104 
105  if (!empty($scopeData) && hash_equals(GeneralUtility::hmac($scopeData), $scopeHash)) {
106  $this->scopeData = unserialize($scopeData);
107  }
108 
109  // Create folder tree object:
110  if (!empty($this->scopeData)) {
111  $this->foldertree = GeneralUtility::makeInstance($this->scopeData['class']);
112  $this->foldertree->thisScript = $this->scopeData['script'];
113  $this->foldertree->ext_noTempRecyclerDirs = $this->scopeData['ext_noTempRecyclerDirs'];
114  if ($this->foldertree instanceof ElementBrowserFolderTreeView) {
115  // create a fake provider to pass link data along properly
116  $linkParamProvider = GeneralUtility::makeInstance(
117  DummyLinkParameterProvider::class,
118  $this->scopeData['browser'],
119  $this->scopeData['script']
120  );
121  $this->foldertree->setLinkParameterProvider($linkParamProvider);
122  }
123  } else {
124  $this->foldertree = GeneralUtility::makeInstance(FileListFolderTree::class);
125  $this->foldertree->thisScript = BackendUtility::getModuleUrl('file_navframe');
126  }
127  // Only set ext_IconMode if we are not running an ajax request from the ElementBrowser,
128  // which has this property hardcoded to "titlelink".
129  if (!$this->foldertree instanceof ElementBrowserFolderTreeView) {
130  $this->foldertree->ext_IconMode = $this->getBackendUser()->getTSConfigVal('options.folderTree.disableIconLinkToContextmenu');
131  }
132  }
133 
138  public function initPage()
139  {
140  $this->moduleTemplate->setBodyTag('<body id="ext-backend-Modules-FileSystemNavigationFrame-index-php">');
141 
142  // Adding javascript code for drag&drop and the file tree as well as the click menu code
143  $hlClass = $this->getBackendUser()->workspace === 0 ? 'active' : 'active active-ws wsver' . $GLOBALS['BE_USER']->workspace;
144  $dragDropCode = '
145  Tree.highlightClass = "' . $hlClass . '";
146  Tree.highlightActiveItem("", top.fsMod.navFrameHighlightedID["file"]);
147  ';
148 
149  // Adding javascript for drag & drop activation and highlighting
150  $pageRenderer = $this->moduleTemplate->getPageRenderer();
151  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
152  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LegacyTree', 'function() {
153  DragDrop.table = "folders";
154  Tree.registerDragDropHandlers();
155  ' . $dragDropCode . '
156  }');
157 
158  // Setting JavaScript for menu.
159  $inlineJs = ($this->currentSubScript ? 'top.currentSubScript=unescape("' . rawurlencode($this->currentSubScript) . '");' : '') . '
160  // Function, loading the list frame from navigation tree:
161  function jumpTo(id, linkObj, highlightID, bank) {
162  var theUrl = top.currentSubScript;
163  if (theUrl.indexOf("?") != -1) {
164  theUrl += "&id=" + id
165  } else {
166  theUrl += "?id=" + id
167  }
168  top.fsMod.currentBank = bank;
169  top.TYPO3.Backend.ContentContainer.setUrl(theUrl);
170 
171  Tree.highlightActiveItem("file", highlightID + "_" + bank);
172  if (linkObj) { linkObj.blur(); }
173  return false;
174  }
175  ' . ($this->cMR ? ' jumpTo(top.fsMod.recentIds[\'file\'],\'\');' : '');
176 
177  $this->moduleTemplate->getPageRenderer()->addJsInlineCode(
178  'FileSystemNavigationFrame',
179  $inlineJs
180  );
181  }
182 
186  public function main()
187  {
188  // Produce browse-tree:
189  $tree = $this->foldertree->getBrowsableTree();
190  // Outputting page tree:
191  $this->moduleTemplate->setContent($tree);
192  // Setting up the buttons
193  $this->getButtons();
194  // Build the <body> for the module
195  $this->moduleTemplate->setTitle('TYPO3 Folder Tree');
196  $this->content = $this->moduleTemplate->renderContent();
197  }
198 
202  protected function getButtons()
203  {
205  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
206 
208  $iconFactory = $this->moduleTemplate->getIconFactory();
209 
210  // Refresh
211  $refreshButton = $buttonBar->makeLinkButton()
212  ->setHref(GeneralUtility::getIndpEnv('REQUEST_URI'))
213  ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.reload'))
214  ->setIcon($iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL));
215  $buttonBar->addButton($refreshButton, ButtonBar::BUTTON_POSITION_RIGHT);
216 
217  // CSH
218  $cshButton = $buttonBar->makeHelpButton()
219  ->setModuleName('xMOD_csh_corebe')
220  ->setFieldName('filetree');
221  $buttonBar->addButton($cshButton);
222  }
223 
224  /**********************************
225  * AJAX Calls
226  **********************************/
235  public function ajaxExpandCollapse(ServerRequestInterface $request, ResponseInterface $response)
236  {
237  $this->init();
238  $tree = $this->foldertree->getBrowsableTree();
239  if ($this->foldertree->getAjaxStatus() === false) {
240  $response = $response->withStatus(500);
241  } else {
242  $response->getBody()->write(json_encode($tree));
243  }
244 
245  return $response;
246  }
247 
251  protected function getBackendUser()
252  {
253  return $GLOBALS['BE_USER'];
254  }
255 
261  protected function getLanguageService()
262  {
263  return $GLOBALS['LANG'];
264  }
265 }
static hmac($input, $additionalSecret='')
static makeInstance($className,... $constructorArguments)
ajaxExpandCollapse(ServerRequestInterface $request, ResponseInterface $response)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
mainAction(ServerRequestInterface $request, ResponseInterface $response)