[TASK] Fix CGL errors
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / FileSystemNavigationFrameController.php
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
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
20 use TYPO3\CMS\Backend\Template\ModuleTemplate;
21 use TYPO3\CMS\Backend\Tree\View\ElementBrowserFolderTreeView;
22 use TYPO3\CMS\Core\Imaging\Icon;
23 use TYPO3\CMS\Core\Imaging\IconFactory;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\Filelist\FileListFolderTree;
26 use TYPO3\CMS\Backend\Utility\BackendUtility;
27 use TYPO3\CMS\Recordlist\Tree\View\DummyLinkParameterProvider;
28
29 /**
30 * Main script class for rendering of the folder tree
31 */
32 class FileSystemNavigationFrameController
33 {
34 /**
35 * Content accumulates in this variable.
36 *
37 * @var string
38 */
39 public $content;
40
41 /**
42 * @var \TYPO3\CMS\Backend\Tree\View\FolderTreeView
43 */
44 public $foldertree;
45
46 /**
47 * @var string
48 */
49 public $currentSubScript;
50
51 /**
52 * @var bool
53 */
54 public $cMR;
55
56 /**
57 * @var array
58 */
59 protected $scopeData;
60
61 /**
62 * @var bool
63 */
64 public $doHighlight;
65
66 /**
67 * ModuleTemplate Container
68 *
69 * @var ModuleTemplate
70 */
71 protected $moduleTemplate;
72
73 /**
74 * Constructor
75 */
76 public function __construct()
77 {
78 $GLOBALS['SOBE'] = $this;
79 $this->init();
80 }
81
82 /**
83 * @param ServerRequestInterface $request the current request
84 * @param ResponseInterface $response
85 * @return ResponseInterface the response with the content
86 */
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
96 /**
97 * Initialiation of the script class
98 *
99 * @return void
100 */
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 1.
136 if (!$this->foldertree instanceof ElementBrowserFolderTreeView) {
137 $this->foldertree->ext_IconMode = $this->getBackendUser()->getTSConfigVal('options.folderTree.disableIconLinkToContextmenu');
138 }
139 }
140
141 /**
142 * initialization for the visual parts of the class
143 * Use template rendering only if this is a non-AJAX call
144 *
145 * @return void
146 */
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
199 /**
200 * Main function, rendering the folder tree
201 *
202 * @return void
203 */
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
217 /**
218 * Outputting the accumulated content to screen
219 *
220 * @return void
221 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
222 */
223 public function printContent()
224 {
225 GeneralUtility::logDeprecatedFunction();
226 echo $this->content;
227 }
228
229 /**
230 * Register docHeader buttons
231 */
232 protected function getButtons()
233 {
234 /** @var ButtonBar $buttonBar */
235 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
236
237 /** @var IconFactory $iconFactory */
238 $iconFactory = $this->moduleTemplate->getIconFactory();
239
240 // Refresh
241 $refreshButton = $buttonBar->makeLinkButton()
242 ->setHref(GeneralUtility::getIndpEnv('REQUEST_URI'))
243 ->setTitle($this->getLanguageService()->makeEntities(
244 $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.reload', true)
245 ))->setIcon($iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL));
246 $buttonBar->addButton($refreshButton, ButtonBar::BUTTON_POSITION_RIGHT);
247
248 // CSH
249 $cshButton = $buttonBar->makeHelpButton()
250 ->setModuleName('xMOD_csh_corebe')
251 ->setFieldName('filetree');
252 $buttonBar->addButton($cshButton);
253 }
254
255 /**********************************
256 * AJAX Calls
257 **********************************/
258 /**
259 * Makes the AJAX call to expand or collapse the foldertree.
260 * Called by an AJAX Route, see AjaxRequestHandler
261 *
262 * @param ServerRequestInterface $request
263 * @param ResponseInterface $response
264 * @return ResponseInterface
265 */
266 public function ajaxExpandCollapse(ServerRequestInterface $request, ResponseInterface $response)
267 {
268 $this->init();
269 $tree = $this->foldertree->getBrowsableTree();
270 if ($this->foldertree->getAjaxStatus() === false) {
271 $response = $response->withStatus(500);
272 } else {
273 $response->getBody()->write(json_encode($tree));
274 }
275
276 return $response;
277 }
278
279 /**
280 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
281 */
282 protected function getBackendUser()
283 {
284 return $GLOBALS['BE_USER'];
285 }
286
287 /**
288 * Returns an instance of LanguageService
289 *
290 * @return \TYPO3\CMS\Lang\LanguageService
291 */
292 protected function getLanguageService()
293 {
294 return $GLOBALS['LANG'];
295 }
296 }