[TASK] Remove unneeded parenthesis on array-access
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / PageTreeNavigationController.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\DocumentTemplate;
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
21 use TYPO3\CMS\Backend\View\PageTreeView;
22 use TYPO3\CMS\Core\Imaging\Icon;
23 use TYPO3\CMS\Core\Imaging\IconFactory;
24 use TYPO3\CMS\Core\Messaging\FlashMessage;
25 use TYPO3\CMS\Core\Page\PageRenderer;
26 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
27 use TYPO3\CMS\Core\Utility\GeneralUtility;
28 use TYPO3\CMS\Core\Utility\MathUtility;
29 use TYPO3\CMS\Workspaces\Service\WorkspaceService;
30
31 /**
32 * Main script class for the page tree navigation frame
33 * This is the class for rendering the "page tree" navigation frame without ExtJS, used prior to TYPO3 CMS 4.5.
34 * This functionality is deprecated since TYPO3 CMS 7, and will be removed with TYPO3 CMS 8
35 */
36 class PageTreeNavigationController
37 {
38 /**
39 * @var string
40 */
41 public $content;
42
43 /**
44 * @var \TYPO3\CMS\Backend\View\PageTreeView
45 */
46 public $pagetree;
47
48 /**
49 * document template object
50 *
51 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
52 */
53 public $doc;
54
55 /**
56 * Temporary mount point (record), if any
57 *
58 * @var int
59 */
60 public $active_tempMountPoint = 0;
61
62 /**
63 * @var string
64 */
65 public $currentSubScript;
66
67 /**
68 * @var bool
69 */
70 public $cMR;
71
72 /**
73 * If not '' (blank) then it will clear (0) or set (>0) Temporary DB mount.
74 *
75 * @var string
76 */
77 public $setTempDBmount;
78
79 /**
80 * @var string
81 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
82 */
83 public $template;
84
85 /**
86 * @var IconFactory
87 */
88 protected $iconFactory;
89
90 /**
91 * Constructor
92 */
93 public function __construct()
94 {
95 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
96 GeneralUtility::deprecationLog('PageTreeNavigationController is deprecated in favor of new pagetrees');
97 $GLOBALS['SOBE'] = $this;
98 $this->init();
99 }
100
101 /**
102 * Initialization of the class
103 *
104 * @return void
105 */
106 protected function init()
107 {
108 // Setting GPvars:
109 $this->cMR = (bool)GeneralUtility::_GP('cMR');
110 $this->currentSubScript = GeneralUtility::_GP('currentSubScript');
111 $this->setTempDBmount = GeneralUtility::_GP('setTempDBmount');
112 // Create page tree object:
113 $beUser = $this->getBackendUser();
114 $this->pagetree = GeneralUtility::makeInstance(PageTreeView::class);
115 $this->pagetree->ext_IconMode = $beUser->getTSConfigVal('options.pageTree.disableIconLinkToContextmenu');
116 $this->pagetree->ext_showPageId = (bool)$beUser->getTSConfigVal('options.pageTree.showPageIdWithTitle');
117 $this->pagetree->ext_showNavTitle = (bool)$beUser->getTSConfigVal('options.pageTree.showNavTitle');
118 $this->pagetree->ext_separateNotinmenuPages = $beUser->getTSConfigVal('options.pageTree.separateNotinmenuPages');
119 $this->pagetree->ext_alphasortNotinmenuPages = $beUser->getTSConfigVal('options.pageTree.alphasortNotinmenuPages');
120 $this->pagetree->thisScript = 'alt_db_navframe.php';
121 $this->pagetree->addField('alias');
122 $this->pagetree->addField('shortcut');
123 $this->pagetree->addField('shortcut_mode');
124 $this->pagetree->addField('mount_pid');
125 $this->pagetree->addField('mount_pid_ol');
126 $this->pagetree->addField('url');
127 // Temporary DB mounts:
128 $this->initializeTemporaryDBmount();
129 }
130
131 /**
132 * Initialization for the visual parts of the class
133 * Use template rendering only if this is a non-AJAX call
134 *
135 * @return void
136 */
137 public function initPage()
138 {
139 // Setting highlight mode:
140 $doHighlight = !$this->getBackendUser()->getTSConfigVal('options.pageTree.disableTitleHighlight');
141 // Create template object:
142 $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
143 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/alt_db_navframe.html');
144 $this->doc->showFlashMessages = false;
145 // Get HTML-Template
146
147 // Adding javascript for drag & drop activation and highlighting
148 $dragDropCode = 'Tree.registerDragDropHandlers();';
149
150 // If highlighting is active, define the CSS class for the active item depending on the workspace
151 if ($doHighlight) {
152 $hlClass = $this->getBackendUser()->workspace === 0 ? 'active' : 'active active-ws wsver' . $this->getBackendUser()->workspace;
153 $dragDropCode .= '
154 Tree.highlightClass = "' . $hlClass . '";
155 Tree.highlightActiveItem("",top.fsMod.navFrameHighlightedID["web"]);';
156 }
157 // Adding javascript code for drag&drop and the pagetree as well as the click menu code
158 $this->doc->getDragDropCode('pages', $dragDropCode);
159 $this->doc->getContextMenuCode();
160 /** @var $pageRenderer PageRenderer */
161 $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
162 $pageRenderer->loadExtJS();
163 $this->doc->JScode .= $this->doc->wrapScriptTags(($this->currentSubScript ? 'top.currentSubScript=unescape("' . rawurlencode($this->currentSubScript) . '");' : '') . '
164 // Function, loading the list frame from navigation tree:
165 function jumpTo(id, linkObj, highlightID, bank) { //
166 var theUrl = top.currentSubScript ;
167 if (theUrl.indexOf("?") != -1) {
168 theUrl += "&id=" + id
169 } else {
170 theUrl += "?id=" + id
171 }
172 top.fsMod.currentBank = bank;
173 top.TYPO3.Backend.ContentContainer.setUrl(theUrl);
174
175 ' . ($doHighlight ? 'Tree.highlightActiveItem("web", highlightID + "_" + bank);' : '') . '
176 if (linkObj) { linkObj.blur(); }
177 return false;
178 }
179 ' . ($this->cMR ? 'jumpTo(top.fsMod.recentIds[\'web\'],\'\');' : '') . '
180
181 ');
182 $this->doc->bodyTagId = 'typo3-pagetree';
183 }
184
185 /**
186 * Main function, rendering the browsable page tree
187 *
188 * @return void
189 */
190 public function main()
191 {
192 // Produce browse-tree:
193 $tree = $this->pagetree->getBrowsableTree();
194 // Outputting Temporary DB mount notice:
195 if ($this->active_tempMountPoint) {
196 $flashText = '
197 <a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('setTempDBmount' => 0))) . '">' . $this->getLanguageService()->sl('LLL:EXT:lang/locallang_core.xlf:labels.temporaryDBmount', true) . '</a> <br />' . $this->getLanguageService()->sl('LLL:EXT:lang/locallang_core.xlf:labels.path', true) . ': <span title="' . htmlspecialchars($this->active_tempMountPoint['_thePathFull']) . '">' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($this->active_tempMountPoint['_thePath'], -50)) . '</span>
198 ';
199 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $flashText, '', FlashMessage::INFO);
200 $this->content .= $flashMessage->render();
201 }
202 // Outputting page tree:
203 $this->content .= '<div id="PageTreeDiv">' . $tree . '</div>';
204 // Setting up the buttons and markers for docheader
205 $docHeaderButtons = $this->getButtons();
206 $markers = array(
207 'WORKSPACEINFO' => $this->getWorkspaceInfo(),
208 'CONTENT' => $this->content
209 );
210 // Build the <body> for the module
211 $this->content = $this->doc->startPage('TYPO3 Page Tree');
212 $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markers);
213 $this->content .= $this->doc->endPage();
214 $this->content = $this->doc->insertStylesAndJS($this->content);
215 }
216
217 /**
218 * Outputting the accumulated content to screen
219 *
220 * @return void
221 */
222 public function printContent()
223 {
224 echo $this->content;
225 }
226
227 /**
228 * Create the panel of buttons for submitting the form or otherwise perform operations.
229 *
230 * @return array All available buttons as an assoc. array
231 */
232 protected function getButtons()
233 {
234 $buttons = array(
235 'csh' => '',
236 'new_page' => '',
237 'refresh' => ''
238 );
239 // New Page
240 $onclickNewPageWizard = 'top.content.list_frame.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('db_new', ['pagesOnly' => 1, 'id' => ''])) . '+Tree.pageID;';
241 $buttons['new_page'] = '<a href="#" onclick="' . $onclickNewPageWizard . '" title="' . $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newPage', true) . '">'
242 . $this->iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL)->render()
243 . '</a>';
244 // Refresh
245 $buttons['refresh'] = '<a href="' . htmlspecialchars(GeneralUtility::getIndpEnv('REQUEST_URI')) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.refresh', true) . '">' . $this->iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL)->render() . '</a>';
246 // CSH
247 $buttons['csh'] = str_replace('typo3-csh-inline', 'typo3-csh-inline show-right', BackendUtility::cshItem('xMOD_csh_corebe', 'pagetree'));
248 return $buttons;
249 }
250
251 /**
252 * Create the workspace information
253 *
254 * @return string HTML containing workspace info
255 */
256 protected function getWorkspaceInfo()
257 {
258 if (ExtensionManagementUtility::isLoaded('workspaces') && ($this->getBackendUser()->workspace !== 0 || $this->getBackendUser()->getTSConfigVal('options.pageTree.onlineWorkspaceInfo'))) {
259 $wsTitle = htmlspecialchars(WorkspaceService::getWorkspaceTitle($this->getBackendUser()->workspace));
260
261 $workspaceInfo = '<div class="bgColor4 workspace-info"><span title="' . $wsTitle . '" onclick="top.goToModule(\'web_WorkspacesWorkspaces\');" style="cursor:pointer;">'
262 . $this->iconFactory->getIcon('apps-toolbar-menu-workspace', Icon::SIZE_SMALL)->render() . '</span>'
263 . $wsTitle . '</div>';
264 } else {
265 $workspaceInfo = '';
266 }
267 return $workspaceInfo;
268 }
269
270 /**********************************
271 *
272 * Temporary DB mounts
273 *
274 **********************************/
275 /**
276 * Getting temporary DB mount
277 *
278 * @return void
279 */
280 public function initializeTemporaryDBmount()
281 {
282 $beUser = $this->getBackendUser();
283 // Set/Cancel Temporary DB Mount:
284 if ((string)$this->setTempDBmount !== '') {
285 $set = MathUtility::forceIntegerInRange($this->setTempDBmount, 0);
286 if ($set > 0 && $beUser->isInWebMount($set)) {
287 // Setting...:
288 $this->settingTemporaryMountPoint($set);
289 } else {
290 // Clear:
291 $this->settingTemporaryMountPoint(0);
292 }
293 }
294 // Getting temporary mount point ID:
295 $temporaryMountPoint = (int)$beUser->getSessionData('pageTree_temporaryMountPoint');
296 // If mount point ID existed and is within users real mount points, then set it temporarily:
297 if ($temporaryMountPoint > 0 && $beUser->isInWebMount($temporaryMountPoint)) {
298 if ($this->active_tempMountPoint = BackendUtility::readPageAccess($temporaryMountPoint, $beUser->getPagePermsClause(1))) {
299 $this->pagetree->MOUNTS = array($temporaryMountPoint);
300 } else {
301 // Clear temporary mount point as we have no access to it any longer
302 $this->settingTemporaryMountPoint(0);
303 }
304 }
305 }
306
307 /**
308 * Setting temporary page id as DB mount
309 *
310 * @param int $pageId The page id to set as DB mount
311 * @return void
312 */
313 public function settingTemporaryMountPoint($pageId)
314 {
315 $this->getBackendUser()->setAndSaveSessionData('pageTree_temporaryMountPoint', (int)$pageId);
316 }
317
318 /**********************************
319 *
320 * AJAX Calls
321 *
322 **********************************/
323 /**
324 * Makes the AJAX call to expand or collapse the pagetree.
325 * Called by an AJAX Route, see AjaxRequestHandler
326 *
327 * @param ServerRequestInterface $request
328 * @param ResponseInterface $response
329 * @return ResponseInterface
330 */
331 public function ajaxExpandCollapse(ServerRequestInterface $request, ResponseInterface $response)
332 {
333 $this->init();
334 $tree = $this->pagetree->getBrowsableTree();
335 if (!$this->pagetree->ajaxStatus) {
336 $response = $response->withStatus(500);
337 } else {
338 $response->getBody()->write(json_encode($tree));
339 }
340
341 return $response;
342 }
343
344 /**
345 * Returns LanguageService
346 *
347 * @return \TYPO3\CMS\Lang\LanguageService
348 */
349 protected function getLanguageService()
350 {
351 return $GLOBALS['LANG'];
352 }
353
354 /**
355 * Returns the current BE user.
356 *
357 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
358 */
359 protected function getBackendUser()
360 {
361 return $GLOBALS['BE_USER'];
362 }
363 }