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