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