TYPO3  7.6
FileSystemNavigationFrameController.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Controller;
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 {
34 
40  public $content;
41 
45  public $foldertree;
46 
51 
55  public $cMR;
56 
60  protected $scopeData;
61 
65  public $doHighlight;
66 
72  protected $moduleTemplate;
73 
77  public function __construct()
78  {
79  $GLOBALS['SOBE'] = $this;
80  $this->init();
81  }
82 
89  {
90  $this->initPage();
91  $this->main();
92 
93  $response->getBody()->write($this->content);
94  return $response;
95  }
96 
102  protected function init()
103  {
104  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
105 
106  // Setting GPvars:
107  $this->currentSubScript = GeneralUtility::_GP('currentSubScript');
108  $this->cMR = GeneralUtility::_GP('cMR');
109 
110  $scopeData = (string)GeneralUtility::_GP('scopeData');
111  $scopeHash = (string)GeneralUtility::_GP('scopeHash');
112 
113  if (!empty($scopeData) && GeneralUtility::hmac($scopeData) === $scopeHash) {
114  $this->scopeData = unserialize($scopeData);
115  }
116 
117  // Create folder tree object:
118  if (!empty($this->scopeData)) {
119  $this->foldertree = GeneralUtility::makeInstance($this->scopeData['class']);
120  $this->foldertree->thisScript = $this->scopeData['script'];
121  $this->foldertree->ext_noTempRecyclerDirs = $this->scopeData['ext_noTempRecyclerDirs'];
122  if ($this->foldertree instanceof ElementBrowserFolderTreeView) {
123  // create a fake provider to pass link data along properly
124  $linkParamProvider = GeneralUtility::makeInstance(
125  DummyLinkParameterProvider::class,
126  $this->scopeData['browser'],
127  $this->scopeData['script']
128  );
129  $this->foldertree->setLinkParameterProvider($linkParamProvider);
130  }
131  } else {
132  $this->foldertree = GeneralUtility::makeInstance(FileListFolderTree::class);
133  $this->foldertree->thisScript = BackendUtility::getModuleUrl('file_navframe');
134  }
135  // Only set ext_IconMode if we are not running an ajax request from the ElementBrowser,
136  // which has this property hardcoded to 1.
137  if (!$this->foldertree instanceof ElementBrowserFolderTreeView) {
138  $this->foldertree->ext_IconMode = $this->getBackendUser()->getTSConfigVal('options.folderTree.disableIconLinkToContextmenu');
139  }
140  }
141 
148  public function initPage()
149  {
150  // Setting highlight mode:
151  $this->doHighlight = !$this->getBackendUser()->getTSConfigVal('options.pageTree.disableTitleHighlight');
152 
153  $this->moduleTemplate->setBodyTag('<body id="ext-backend-Modules-FileSystemNavigationFrame-index-php">');
154 
155  // Adding javascript code for drag&drop and the filetree as well as the click menu code
156  $dragDropCode = '
157  Tree.ajaxID = "sc_alt_file_navframe_expandtoggle";
158  Tree.registerDragDropHandlers()';
159  if ($this->doHighlight) {
160  $hlClass = $this->getBackendUser()->workspace === 0 ? 'active' : 'active active-ws wsver' . $GLOBALS['BE_USER']->workspace;
161  $dragDropCode .= '
162  Tree.highlightClass = "' . $hlClass . '";
163  Tree.highlightActiveItem("", top.fsMod.navFrameHighlightedID["file"]);
164  ';
165  }
166 
167  // Adding javascript for drag & drop activation and highlighting
168  $pageRenderer = $this->moduleTemplate->getPageRenderer();
169  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
170  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LegacyTree', 'function() {
171  DragDrop.table = "folders";
172  ' . $dragDropCode . '
173  }');
174 
175  // Setting JavaScript for menu.
176  $inlineJs = ($this->currentSubScript ? 'top.currentSubScript=unescape("' . rawurlencode($this->currentSubScript) . '");' : '') . '
177  // Function, loading the list frame from navigation tree:
178  function jumpTo(id, linkObj, highlightID, bank) {
179  var theUrl = top.currentSubScript;
180  if (theUrl.indexOf("?") != -1) {
181  theUrl += "&id=" + id
182  } else {
183  theUrl += "?id=" + id
184  }
185  top.fsMod.currentBank = bank;
186  top.TYPO3.Backend.ContentContainer.setUrl(theUrl);
187 
188  ' . ($this->doHighlight ? 'Tree.highlightActiveItem("file", highlightID + "_" + bank);' : '') . '
189  if (linkObj) { linkObj.blur(); }
190  return false;
191  }
192  ' . ($this->cMR ? ' jumpTo(top.fsMod.recentIds[\'file\'],\'\');' : '');
193 
194  $this->moduleTemplate->getPageRenderer()->addJsInlineCode(
195  'FileSystemNavigationFrame',
196  $inlineJs
197  );
198  }
199 
205  public function main()
206  {
207  // Produce browse-tree:
208  $tree = $this->foldertree->getBrowsableTree();
209  // Outputting page tree:
210  $this->moduleTemplate->setContent($tree);
211  // Setting up the buttons
212  $this->getButtons();
213  // Build the <body> for the module
214  $this->moduleTemplate->setTitle('TYPO3 Folder Tree');
215  $this->content = $this->moduleTemplate->renderContent();
216  }
217 
224  public function printContent()
225  {
227  echo $this->content;
228  }
229 
233  protected function getButtons()
234  {
236  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
237 
239  $iconFactory = $this->moduleTemplate->getIconFactory();
240 
241  // Refresh
242  $refreshButton = $buttonBar->makeLinkButton()
243  ->setHref(GeneralUtility::getIndpEnv('REQUEST_URI'))
244  ->setTitle($this->getLanguageService()->makeEntities(
245  $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.reload', true)
246  ))->setIcon($iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL));
247  $buttonBar->addButton($refreshButton, ButtonBar::BUTTON_POSITION_RIGHT);
248 
249  // CSH
250  $cshButton = $buttonBar->makeHelpButton()
251  ->setModuleName('xMOD_csh_corebe')
252  ->setFieldName('filetree');
253  $buttonBar->addButton($cshButton);
254  }
255 
256  /**********************************
257  * AJAX Calls
258  **********************************/
268  {
269  $this->init();
270  $tree = $this->foldertree->getBrowsableTree();
271  if ($this->foldertree->getAjaxStatus() === false) {
272  $response = $response->withStatus(500);
273  } else {
274  $response->getBody()->write(json_encode($tree));
275  }
276 
277  return $response;
278  }
279 
283  protected function getBackendUser()
284  {
285  return $GLOBALS['BE_USER'];
286  }
287 
293  protected function getLanguageService()
294  {
295  return $GLOBALS['LANG'];
296  }
297 }