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