54f4a1f2956f651df0fdb16de89affde344b488f
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / PageTreeNavigationController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Backend\Utility\BackendUtility;
31 use TYPO3\CMS\Backend\Utility\IconUtility;
32 use TYPO3\CMS\Core\Utility\GeneralUtility;
33
34 /**
35 * Main script class for the page tree navigation frame
36 *
37 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
38 */
39 class PageTreeNavigationController {
40
41 // Internal:
42 /**
43 * @todo Define visibility
44 */
45 public $content;
46
47 /**
48 * @todo Define visibility
49 */
50 public $pagetree;
51
52 /**
53 * document template object
54 *
55 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
56 * @todo Define visibility
57 */
58 public $doc;
59
60 // Temporary mount point (record), if any
61 /**
62 * @todo Define visibility
63 */
64 public $active_tempMountPoint = 0;
65
66 /**
67 * @todo Define visibility
68 */
69 public $backPath;
70
71 // Internal, static: GPvar:
72 /**
73 * @todo Define visibility
74 */
75 public $currentSubScript;
76
77 /**
78 * @todo Define visibility
79 */
80 public $cMR;
81
82 // If not '' (blank) then it will clear (0) or set (>0) Temporary DB mount.
83 /**
84 * @todo Define visibility
85 */
86 public $setTempDBmount;
87
88 /**
89 * @todo Define visibility
90 */
91 public $template;
92
93 // Depends on userTS-setting
94 /**
95 * @todo Define visibility
96 */
97 public $hasFilterBox;
98
99 /**
100 * Initialiation of the class
101 *
102 * @return void
103 * @todo Define visibility
104 */
105 public function init() {
106 // Setting backPath
107 $this->backPath = $GLOBALS['BACK_PATH'];
108 // Setting GPvars:
109 $this->cMR = GeneralUtility::_GP('cMR');
110 $this->currentSubScript = GeneralUtility::_GP('currentSubScript');
111 $this->setTempDBmount = GeneralUtility::_GP('setTempDBmount');
112 // look for User setting
113 $this->hasFilterBox = !$GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.hideFilter');
114 // Create page tree object:
115 $this->pagetree = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\View\\PageTreeView');
116 $this->pagetree->ext_IconMode = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.disableIconLinkToContextmenu');
117 $this->pagetree->ext_showPageId = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
118 $this->pagetree->ext_showNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
119 $this->pagetree->ext_separateNotinmenuPages = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.separateNotinmenuPages');
120 $this->pagetree->ext_alphasortNotinmenuPages = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.alphasortNotinmenuPages');
121 $this->pagetree->thisScript = 'alt_db_navframe.php';
122 $this->pagetree->addField('alias');
123 $this->pagetree->addField('shortcut');
124 $this->pagetree->addField('shortcut_mode');
125 $this->pagetree->addField('mount_pid');
126 $this->pagetree->addField('mount_pid_ol');
127 $this->pagetree->addField('nav_hide');
128 $this->pagetree->addField('nav_title');
129 $this->pagetree->addField('url');
130 // Temporary DB mounts:
131 $this->initializeTemporaryDBmount();
132 }
133
134 /**
135 * Initialization for the visual parts of the class
136 * Use template rendering only if this is a non-AJAX call
137 *
138 * @return void
139 */
140 public function initPage() {
141 // Setting highlight mode:
142 $this->doHighlight = !$GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.disableTitleHighlight');
143 // If highlighting is active, define the CSS class for the active item depending on the workspace
144 if ($this->doHighlight) {
145 $hlClass = $GLOBALS['BE_USER']->workspace === 0 ? 'active' : 'active active-ws wsver' . $GLOBALS['BE_USER']->workspace;
146 }
147 // Create template object:
148 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
149 $this->doc->backPath = $GLOBALS['BACK_PATH'];
150 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/alt_db_navframe.html');
151 $this->doc->showFlashMessages = FALSE;
152 // Get HTML-Template
153 // Adding javascript code for AJAX (prototype), drag&drop and the pagetree as well as the click menu code
154 $this->doc->getDragDropCode('pages');
155 $this->doc->getContextMenuCode();
156 $this->doc->getPageRenderer()->loadScriptaculous('effects');
157 $this->doc->getPageRenderer()->loadExtJS();
158 if ($this->hasFilterBox) {
159 $this->doc->getPageRenderer()->addJsFile('sysext/backend/Resources/Public/JavaScript/pagetreefiltermenu.js');
160 }
161 $this->doc->JScode .= $this->doc->wrapScriptTags(($this->currentSubScript ? 'top.currentSubScript=unescape("' . rawurlencode($this->currentSubScript) . '");' : '') . '
162 // setting prefs for pagetree and drag & drop
163 ' . ($this->doHighlight ? 'Tree.highlightClass = "' . $hlClass . '";' : '') . '
164
165 // Function, loading the list frame from navigation tree:
166 function jumpTo(id, linkObj, highlightID, bank) { //
167 var theUrl = top.TS.PATH_typo3 + top.currentSubScript ;
168 if (theUrl.indexOf("?") != -1) {
169 theUrl += "&id=" + id
170 } else {
171 theUrl += "?id=" + id
172 }
173 top.fsMod.currentBank = bank;
174 top.TYPO3.Backend.ContentContainer.setUrl(theUrl);
175
176 ' . ($this->doHighlight ? 'Tree.highlightActiveItem("web", highlightID + "_" + bank);' : '') . '
177 ' . (!$GLOBALS['CLIENT']['FORMSTYLE'] ? '' : 'if (linkObj) linkObj.blur(); ') . '
178 return false;
179 }
180 ' . ($this->cMR ? 'jumpTo(top.fsMod.recentIds[\'web\'],\'\');' : '') . ($this->hasFilterBox ? 'var TYPO3PageTreeFilter = new PageTreeFilter();' : '') . '
181
182 ');
183 $this->doc->bodyTagId = 'typo3-pagetree';
184 }
185
186 /**
187 * Main function, rendering the browsable page tree
188 *
189 * @return void
190 * @todo Define visibility
191 */
192 public function main() {
193 // Produce browse-tree:
194 $tree = $this->pagetree->getBrowsableTree();
195 // Outputting Temporary DB mount notice:
196 if ($this->active_tempMountPoint) {
197 $flashText = '
198 <a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('setTempDBmount' => 0))) . '">' . $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xlf:labels.temporaryDBmount', 1) . '</a> <br />' . $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xlf:labels.path', 1) . ': <span title="' . htmlspecialchars($this->active_tempMountPoint['_thePathFull']) . '">' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($this->active_tempMountPoint['_thePath'], -50)) . '</span>
199 ';
200 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $flashText, '', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
201 $this->content .= $flashMessage->render();
202 }
203 // Outputting page tree:
204 $this->content .= '<div id="PageTreeDiv">' . $tree . '</div>';
205 // Adding javascript for drag & drop activation and highlighting
206 $this->content .= $this->doc->wrapScriptTags('
207 ' . ($this->doHighlight ? 'Tree.highlightActiveItem("",top.fsMod.navFrameHighlightedID["web"]);' : '') . '
208 Tree.registerDragDropHandlers();');
209 // Setting up the buttons and markers for docheader
210 $docHeaderButtons = $this->getButtons();
211 $markers = array(
212 'IMG_RESET' => IconUtility::getSpriteIcon('actions-document-close', array(
213 'id' => 'treeFilterReset',
214 'alt' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.resetFilter'),
215 'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.resetFilter')
216 )),
217 'WORKSPACEINFO' => $this->getWorkspaceInfo(),
218 'CONTENT' => $this->content
219 );
220 $subparts = array();
221 if (!$this->hasFilterBox) {
222 $subparts['###SECOND_ROW###'] = '';
223 }
224 // Build the <body> for the module
225 $this->content = $this->doc->startPage('TYPO3 Page Tree');
226 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers, $subparts);
227 $this->content .= $this->doc->endPage();
228 $this->content = $this->doc->insertStylesAndJS($this->content);
229 }
230
231 /**
232 * Outputting the accumulated content to screen
233 *
234 * @return void
235 * @todo Define visibility
236 */
237 public function printContent() {
238 echo $this->content;
239 }
240
241 /**
242 * Create the panel of buttons for submitting the form or otherwise perform operations.
243 *
244 * @return array All available buttons as an assoc. array
245 */
246 protected function getButtons() {
247 $buttons = array(
248 'csh' => '',
249 'new_page' => '',
250 'refresh' => '',
251 'filter' => ''
252 );
253 // New Page
254 $onclickNewPageWizard = 'top.content.list_frame.location.href=top.TS.PATH_typo3+\'db_new.php?pagesOnly=1&amp;id=\'+Tree.pageID;';
255 $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>';
256 // Refresh
257 $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>';
258 // CSH
259 $buttons['csh'] = str_replace('typo3-csh-inline', 'typo3-csh-inline show-right', BackendUtility::cshItem('xMOD_csh_corebe', 'pagetree', $GLOBALS['BACK_PATH'], '', TRUE));
260 // Filter
261 if ($this->hasFilterBox) {
262 $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', 1))) . '</a>';
263 }
264 return $buttons;
265 }
266
267 /**
268 * Create the workspace information
269 *
270 * @return string HTML containing workspace info
271 */
272 protected function getWorkspaceInfo() {
273 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('workspaces') && ($GLOBALS['BE_USER']->workspace !== 0 || $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.onlineWorkspaceInfo'))) {
274 $wsTitle = htmlspecialchars(\TYPO3\CMS\Workspaces\Service\WorkspaceService::getWorkspaceTitle($GLOBALS['BE_USER']->workspace));
275 $workspaceInfo = '
276 <div class="bgColor4 workspace-info">' . IconUtility::getSpriteIcon('apps-toolbar-menu-workspace', array(
277 'title' => $wsTitle,
278 'onclick' => 'top.goToModule(\'web_WorkspacesWorkspaces\');',
279 'style' => 'cursor:pointer;'
280 )) . $wsTitle . '</div>
281 ';
282 }
283 return $workspaceInfo;
284 }
285
286 /**********************************
287 *
288 * Temporary DB mounts
289 *
290 **********************************/
291 /**
292 * Getting temporary DB mount
293 *
294 * @return void
295 * @todo Define visibility
296 */
297 public function initializeTemporaryDBmount() {
298 // Set/Cancel Temporary DB Mount:
299 if (strlen($this->setTempDBmount)) {
300 $set = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->setTempDBmount, 0);
301 if ($set > 0 && $GLOBALS['BE_USER']->isInWebMount($set)) {
302 // Setting...:
303 $this->settingTemporaryMountPoint($set);
304 } else {
305 // Clear:
306 $this->settingTemporaryMountPoint(0);
307 }
308 }
309 // Getting temporary mount point ID:
310 $temporaryMountPoint = intval($GLOBALS['BE_USER']->getSessionData('pageTree_temporaryMountPoint'));
311 // If mount point ID existed and is within users real mount points, then set it temporarily:
312 if ($temporaryMountPoint > 0 && $GLOBALS['BE_USER']->isInWebMount($temporaryMountPoint)) {
313 if ($this->active_tempMountPoint = BackendUtility::readPageAccess($temporaryMountPoint, $GLOBALS['BE_USER']->getPagePermsClause(1))) {
314 $this->pagetree->MOUNTS = array($temporaryMountPoint);
315 } else {
316 // Clear temporary mount point as we have no access to it any longer
317 $this->settingTemporaryMountPoint(0);
318 }
319 }
320 }
321
322 /**
323 * Setting temporary page id as DB mount
324 *
325 * @param integer $pageId The page id to set as DB mount
326 * @return void
327 * @todo Define visibility
328 */
329 public function settingTemporaryMountPoint($pageId) {
330 $GLOBALS['BE_USER']->setAndSaveSessionData('pageTree_temporaryMountPoint', intval($pageId));
331 }
332
333 /**********************************
334 *
335 * AJAX Calls
336 *
337 **********************************/
338 /**
339 * Makes the AJAX call to expand or collapse the pagetree.
340 * Called by typo3/ajax.php
341 *
342 * @param array $params Additional parameters (not used here)
343 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj The AjaxRequestHandler object of this request
344 * @return void
345 */
346 public function ajaxExpandCollapse($params, $ajaxObj) {
347 $this->init();
348 $tree = $this->pagetree->getBrowsableTree();
349 if (!$this->pagetree->ajaxStatus) {
350 $ajaxObj->setError($tree);
351 } else {
352 $ajaxObj->addContent('tree', $tree);
353 }
354 }
355
356 }
357
358 ?>