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