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