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