[TASK] BACK_PATH DocumentTemplate
[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->setModuleTemplate('EXT:backend/Resources/Private/Templates/alt_db_navframe.html');
141 $this->doc->showFlashMessages = FALSE;
142 // Get HTML-Template
143
144 // Adding javascript for drag & drop activation and highlighting
145 $dragDropCode = 'Tree.registerDragDropHandlers();';
146
147 // If highlighting is active, define the CSS class for the active item depending on the workspace
148 if ($doHighlight) {
149 $hlClass = $this->getBackendUser()->workspace === 0 ? 'active' : 'active active-ws wsver' . $this->getBackendUser()->workspace;
150 $dragDropCode .= '
151 Tree.highlightClass = "' . $hlClass . '";
152 Tree.highlightActiveItem("",top.fsMod.navFrameHighlightedID["web"]);';
153 }
154 // Adding javascript code for drag&drop and the pagetree as well as the click menu code
155 $this->doc->getDragDropCode('pages', $dragDropCode);
156 $this->doc->getContextMenuCode();
157 /** @var $pageRenderer PageRenderer */
158 $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
159 $pageRenderer->loadExtJS();
160 $this->doc->JScode .= $this->doc->wrapScriptTags(($this->currentSubScript ? 'top.currentSubScript=unescape("' . rawurlencode($this->currentSubScript) . '");' : '') . '
161 // Function, loading the list frame from navigation tree:
162 function jumpTo(id, linkObj, highlightID, bank) { //
163 var theUrl = top.currentSubScript ;
164 if (theUrl.indexOf("?") != -1) {
165 theUrl += "&id=" + id
166 } else {
167 theUrl += "?id=" + id
168 }
169 top.fsMod.currentBank = bank;
170 top.TYPO3.Backend.ContentContainer.setUrl(theUrl);
171
172 ' . ($doHighlight ? 'Tree.highlightActiveItem("web", highlightID + "_" + bank);' : '') . '
173 if (linkObj) { linkObj.blur(); }
174 return false;
175 }
176 ' . ($this->cMR ? 'jumpTo(top.fsMod.recentIds[\'web\'],\'\');' : '') . '
177
178 ');
179 $this->doc->bodyTagId = 'typo3-pagetree';
180 }
181
182 /**
183 * Main function, rendering the browsable page tree
184 *
185 * @return void
186 */
187 public function main() {
188 // Produce browse-tree:
189 $tree = $this->pagetree->getBrowsableTree();
190 // Outputting Temporary DB mount notice:
191 if ($this->active_tempMountPoint) {
192 $flashText = '
193 <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>
194 ';
195 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $flashText, '', FlashMessage::INFO);
196 $this->content .= $flashMessage->render();
197 }
198 // Outputting page tree:
199 $this->content .= '<div id="PageTreeDiv">' . $tree . '</div>';
200 // Setting up the buttons and markers for docheader
201 $docHeaderButtons = $this->getButtons();
202 $markers = array(
203 'WORKSPACEINFO' => $this->getWorkspaceInfo(),
204 'CONTENT' => $this->content
205 );
206 // Build the <body> for the module
207 $this->content = $this->doc->startPage('TYPO3 Page Tree');
208 $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markers);
209 $this->content .= $this->doc->endPage();
210 $this->content = $this->doc->insertStylesAndJS($this->content);
211 }
212
213 /**
214 * Outputting the accumulated content to screen
215 *
216 * @return void
217 */
218 public function printContent() {
219 echo $this->content;
220 }
221
222 /**
223 * Create the panel of buttons for submitting the form or otherwise perform operations.
224 *
225 * @return array All available buttons as an assoc. array
226 */
227 protected function getButtons() {
228 $buttons = array(
229 'csh' => '',
230 'new_page' => '',
231 'refresh' => ''
232 );
233 // New Page
234 $onclickNewPageWizard = 'top.content.list_frame.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('db_new', ['pagesOnly' => 1, 'id' => ''])) . '+Tree.pageID;';
235 $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>';
236 // Refresh
237 $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>';
238 // CSH
239 $buttons['csh'] = str_replace('typo3-csh-inline', 'typo3-csh-inline show-right', BackendUtility::cshItem('xMOD_csh_corebe', 'pagetree'));
240 return $buttons;
241 }
242
243 /**
244 * Create the workspace information
245 *
246 * @return string HTML containing workspace info
247 */
248 protected function getWorkspaceInfo() {
249 if (ExtensionManagementUtility::isLoaded('workspaces') && ($this->getBackendUser()->workspace !== 0 || $this->getBackendUser()->getTSConfigVal('options.pageTree.onlineWorkspaceInfo'))) {
250 $wsTitle = htmlspecialchars(WorkspaceService::getWorkspaceTitle($this->getBackendUser()->workspace));
251 $workspaceInfo = '
252 <div class="bgColor4 workspace-info">' . IconUtility::getSpriteIcon('apps-toolbar-menu-workspace', array(
253 'title' => $wsTitle,
254 'onclick' => 'top.goToModule(\'web_WorkspacesWorkspaces\');',
255 'style' => 'cursor:pointer;'
256 )) . $wsTitle . '</div>
257 ';
258 } else {
259 $workspaceInfo = '';
260 }
261 return $workspaceInfo;
262 }
263
264 /**********************************
265 *
266 * Temporary DB mounts
267 *
268 **********************************/
269 /**
270 * Getting temporary DB mount
271 *
272 * @return void
273 */
274 public function initializeTemporaryDBmount() {
275 $beUser = $this->getBackendUser();
276 // Set/Cancel Temporary DB Mount:
277 if ((string)$this->setTempDBmount !== '') {
278 $set = MathUtility::forceIntegerInRange($this->setTempDBmount, 0);
279 if ($set > 0 && $beUser->isInWebMount($set)) {
280 // Setting...:
281 $this->settingTemporaryMountPoint($set);
282 } else {
283 // Clear:
284 $this->settingTemporaryMountPoint(0);
285 }
286 }
287 // Getting temporary mount point ID:
288 $temporaryMountPoint = (int)$beUser->getSessionData('pageTree_temporaryMountPoint');
289 // If mount point ID existed and is within users real mount points, then set it temporarily:
290 if ($temporaryMountPoint > 0 && $beUser->isInWebMount($temporaryMountPoint)) {
291 if ($this->active_tempMountPoint = BackendUtility::readPageAccess($temporaryMountPoint, $beUser->getPagePermsClause(1))) {
292 $this->pagetree->MOUNTS = array($temporaryMountPoint);
293 } else {
294 // Clear temporary mount point as we have no access to it any longer
295 $this->settingTemporaryMountPoint(0);
296 }
297 }
298 }
299
300 /**
301 * Setting temporary page id as DB mount
302 *
303 * @param int $pageId The page id to set as DB mount
304 * @return void
305 */
306 public function settingTemporaryMountPoint($pageId) {
307 $this->getBackendUser()->setAndSaveSessionData('pageTree_temporaryMountPoint', (int)$pageId);
308 }
309
310 /**********************************
311 *
312 * AJAX Calls
313 *
314 **********************************/
315 /**
316 * Makes the AJAX call to expand or collapse the pagetree.
317 * Called by typo3/ajax.php
318 *
319 * @param array $params Additional parameters (not used here)
320 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj The AjaxRequestHandler object of this request
321 * @return void
322 */
323 public function ajaxExpandCollapse($params, $ajaxObj) {
324 $this->init();
325 $tree = $this->pagetree->getBrowsableTree();
326 if (!$this->pagetree->ajaxStatus) {
327 $ajaxObj->setError($tree);
328 } else {
329 $ajaxObj->addContent('tree', $tree);
330 }
331 }
332
333 /**
334 * Returns LanguageService
335 *
336 * @return \TYPO3\CMS\Lang\LanguageService
337 */
338 protected function getLanguageService() {
339 return $GLOBALS['LANG'];
340 }
341
342 /**
343 * Returns the current BE user.
344 *
345 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
346 */
347 protected function getBackendUser() {
348 return $GLOBALS['BE_USER'];
349 }
350
351 }