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