[BUGFIX] Wrong icon in db_new tree
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / PageTreeNavigationController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller;
3
4 /**
5 * Main script class for the page tree navigation frame
6 *
7 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
8 * @package TYPO3
9 * @subpackage core
10 */
11 class PageTreeNavigationController {
12
13 // Internal:
14 /**
15 * @todo Define visibility
16 */
17 public $content;
18
19 /**
20 * @todo Define visibility
21 */
22 public $pagetree;
23
24 /**
25 * document template object
26 *
27 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
28 * @todo Define visibility
29 */
30 public $doc;
31
32 // Temporary mount point (record), if any
33 /**
34 * @todo Define visibility
35 */
36 public $active_tempMountPoint = 0;
37
38 /**
39 * @todo Define visibility
40 */
41 public $backPath;
42
43 // Internal, static: GPvar:
44 /**
45 * @todo Define visibility
46 */
47 public $currentSubScript;
48
49 /**
50 * @todo Define visibility
51 */
52 public $cMR;
53
54 // If not '' (blank) then it will clear (0) or set (>0) Temporary DB mount.
55 /**
56 * @todo Define visibility
57 */
58 public $setTempDBmount;
59
60 // A static HTML template, usually in templates/alt_db_navframe.html
61 /**
62 * @todo Define visibility
63 */
64 public $template;
65
66 // Depends on userTS-setting
67 /**
68 * @todo Define visibility
69 */
70 public $hasFilterBox;
71
72 /**
73 * Initialiation of the class
74 *
75 * @return void
76 * @todo Define visibility
77 */
78 public function init() {
79 // Setting backPath
80 $this->backPath = $GLOBALS['BACK_PATH'];
81 // Setting GPvars:
82 $this->cMR = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('cMR');
83 $this->currentSubScript = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('currentSubScript');
84 $this->setTempDBmount = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('setTempDBmount');
85 // look for User setting
86 $this->hasFilterBox = !$GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.hideFilter');
87 // Create page tree object:
88 $this->pagetree = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\View\\PageTreeView');
89 $this->pagetree->ext_IconMode = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.disableIconLinkToContextmenu');
90 $this->pagetree->ext_showPageId = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
91 $this->pagetree->ext_showNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
92 $this->pagetree->ext_separateNotinmenuPages = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.separateNotinmenuPages');
93 $this->pagetree->ext_alphasortNotinmenuPages = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.alphasortNotinmenuPages');
94 $this->pagetree->thisScript = 'alt_db_navframe.php';
95 $this->pagetree->addField('alias');
96 $this->pagetree->addField('shortcut');
97 $this->pagetree->addField('shortcut_mode');
98 $this->pagetree->addField('mount_pid');
99 $this->pagetree->addField('mount_pid_ol');
100 $this->pagetree->addField('nav_hide');
101 $this->pagetree->addField('nav_title');
102 $this->pagetree->addField('url');
103 // Temporary DB mounts:
104 $this->initializeTemporaryDBmount();
105 }
106
107 /**
108 * Initialization for the visual parts of the class
109 * Use template rendering only if this is a non-AJAX call
110 *
111 * @return void
112 */
113 public function initPage() {
114 // Setting highlight mode:
115 $this->doHighlight = !$GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.disableTitleHighlight');
116 // If highlighting is active, define the CSS class for the active item depending on the workspace
117 if ($this->doHighlight) {
118 $hlClass = $GLOBALS['BE_USER']->workspace === 0 ? 'active' : 'active active-ws wsver' . $GLOBALS['BE_USER']->workspace;
119 }
120 // Create template object:
121 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
122 $this->doc->backPath = $GLOBALS['BACK_PATH'];
123 $this->doc->setModuleTemplate('templates/alt_db_navframe.html');
124 $this->doc->showFlashMessages = FALSE;
125 // Get HTML-Template
126 // Adding javascript code for AJAX (prototype), drag&drop and the pagetree as well as the click menu code
127 $this->doc->getDragDropCode('pages');
128 $this->doc->getContextMenuCode();
129 $this->doc->getPageRenderer()->loadScriptaculous('effects');
130 $this->doc->getPageRenderer()->loadExtJS();
131 if ($this->hasFilterBox) {
132 $this->doc->getPageRenderer()->addJsFile('js/pagetreefiltermenu.js');
133 }
134 $this->doc->JScode .= $this->doc->wrapScriptTags((((((((((($this->currentSubScript ? ('top.currentSubScript=unescape("' . rawurlencode($this->currentSubScript)) . '");' : '') . '
135 // setting prefs for pagetree and drag & drop
136 ') . ($this->doHighlight ? ('Tree.highlightClass = "' . $hlClass) . '";' : '')) . '
137
138 // Function, loading the list frame from navigation tree:
139 function jumpTo(id, linkObj, highlightID, bank) { //
140 var theUrl = top.TS.PATH_typo3 + top.currentSubScript ;
141 if (theUrl.indexOf("?") != -1) {
142 theUrl += "&id=" + id
143 } else {
144 theUrl += "?id=" + id
145 }
146 top.fsMod.currentBank = bank;
147 top.TYPO3.Backend.ContentContainer.setUrl(theUrl);
148
149 ') . ($this->doHighlight ? 'Tree.highlightActiveItem("web", highlightID + "_" + bank);' : '')) . '
150 ') . (!$GLOBALS['CLIENT']['FORMSTYLE'] ? '' : 'if (linkObj) linkObj.blur(); ')) . '
151 return false;
152 }
153 ') . ($this->cMR ? 'jumpTo(top.fsMod.recentIds[\'web\'],\'\');' : '')) . ($this->hasFilterBox ? 'var TYPO3PageTreeFilter = new PageTreeFilter();' : '')) . '
154
155 ');
156 $this->doc->bodyTagId = 'typo3-pagetree';
157 }
158
159 /**
160 * Main function, rendering the browsable page tree
161 *
162 * @return void
163 * @todo Define visibility
164 */
165 public function main() {
166 // Produce browse-tree:
167 $tree = $this->pagetree->getBrowsableTree();
168 // Outputting Temporary DB mount notice:
169 if ($this->active_tempMountPoint) {
170 $flashText = ((((((((('
171 <a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('setTempDBmount' => 0)))) . '">') . $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.temporaryDBmount', 1)) . '</a> <br />') . $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.path', 1)) . ': <span title="') . htmlspecialchars($this->active_tempMountPoint['_thePathFull'])) . '">') . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($this->active_tempMountPoint['_thePath'], -50))) . '</span>
172 ';
173 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $flashText, '', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
174 $this->content .= $flashMessage->render();
175 }
176 // Outputting page tree:
177 $this->content .= ('<div id="PageTreeDiv">' . $tree) . '</div>';
178 // Adding javascript for drag & drop activation and highlighting
179 $this->content .= $this->doc->wrapScriptTags((('
180 ' . ($this->doHighlight ? 'Tree.highlightActiveItem("",top.fsMod.navFrameHighlightedID["web"]);' : '')) . '
181 ') . (!$this->doc->isCMlayers() ? 'Tree.activateDragDrop = false;' : 'Tree.registerDragDropHandlers();'));
182 // Setting up the buttons and markers for docheader
183 $docHeaderButtons = $this->getButtons();
184 $markers = array(
185 'IMG_RESET' => \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-close', array(
186 'id' => 'treeFilterReset',
187 'alt' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.resetFilter'),
188 'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.resetFilter')
189 )),
190 'WORKSPACEINFO' => $this->getWorkspaceInfo(),
191 'CONTENT' => $this->content
192 );
193 $subparts = array();
194 if (!$this->hasFilterBox) {
195 $subparts['###SECOND_ROW###'] = '';
196 }
197 // Build the <body> for the module
198 $this->content = $this->doc->startPage('TYPO3 Page Tree');
199 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers, $subparts);
200 $this->content .= $this->doc->endPage();
201 $this->content = $this->doc->insertStylesAndJS($this->content);
202 }
203
204 /**
205 * Outputting the accumulated content to screen
206 *
207 * @return void
208 * @todo Define visibility
209 */
210 public function printContent() {
211 echo $this->content;
212 }
213
214 /**
215 * Create the panel of buttons for submitting the form or otherwise perform operations.
216 *
217 * @return array All available buttons as an assoc. array
218 */
219 protected function getButtons() {
220 $buttons = array(
221 'csh' => '',
222 'new_page' => '',
223 'refresh' => '',
224 'filter' => ''
225 );
226 // New Page
227 $onclickNewPageWizard = 'top.content.list_frame.location.href=top.TS.PATH_typo3+\'db_new.php?pagesOnly=1&amp;id=\'+Tree.pageID;';
228 $buttons['new_page'] = ((((('<a href="#" onclick="' . $onclickNewPageWizard) . '" title="') . $GLOBALS['LANG']->sL('LLL:EXT:cms/layout/locallang.xml:newPage', TRUE)) . '">') . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-page-new')) . '</a>';
229 // Refresh
230 $buttons['refresh'] = ((((('<a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'))) . '" title="') . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.refresh', TRUE)) . '">') . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-system-refresh')) . '</a>';
231 // CSH
232 $buttons['csh'] = str_replace('typo3-csh-inline', 'typo3-csh-inline show-right', \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_csh_corebe', 'pagetree', $GLOBALS['BACK_PATH'], '', TRUE));
233 // Filter
234 if ($this->hasFilterBox) {
235 $buttons['filter'] = ('<a href="#" id="tree-toolbar-filter-item">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-system-tree-search-open', array('title' => $GLOBALS['LANG']->sL('LLL:EXT:cms/layout/locallang.xml:labels.filter', 1)))) . '</a>';
236 }
237 return $buttons;
238 }
239
240 /**
241 * Create the workspace information
242 *
243 * @return string HTML containing workspace info
244 */
245 protected function getWorkspaceInfo() {
246 if (\TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded('workspaces') && ($GLOBALS['BE_USER']->workspace !== 0 || $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.onlineWorkspaceInfo'))) {
247 $wsTitle = htmlspecialchars(\tx_Workspaces_Service_Workspaces::getWorkspaceTitle($GLOBALS['BE_USER']->workspace));
248 $workspaceInfo = (('
249 <div class="bgColor4 workspace-info">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-toolbar-menu-workspace', array(
250 'title' => $wsTitle,
251 'onclick' => 'top.goToModule(\'web_WorkspacesWorkspaces\');',
252 'style' => 'cursor:pointer;'
253 ))) . $wsTitle) . '</div>
254 ';
255 }
256 return $workspaceInfo;
257 }
258
259 /**********************************
260 *
261 * Temporary DB mounts
262 *
263 **********************************/
264 /**
265 * Getting temporary DB mount
266 *
267 * @return void
268 * @todo Define visibility
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 = intval($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 = \TYPO3\CMS\Backend\Utility\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 integer $pageId The page id to set as DB mount
299 * @return void
300 * @todo Define visibility
301 */
302 public function settingTemporaryMountPoint($pageId) {
303 $GLOBALS['BE_USER']->setAndSaveSessionData('pageTree_temporaryMountPoint', intval($pageId));
304 }
305
306 /**********************************
307 *
308 * AJAX Calls
309 *
310 **********************************/
311 /**
312 * Makes the AJAX call to expand or collapse the pagetree.
313 * Called by typo3/ajax.php
314 *
315 * @param array $params Additional parameters (not used here)
316 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj The TYPO3AJAX object of this request
317 * @return void
318 */
319 public function ajaxExpandCollapse($params, $ajaxObj) {
320 $this->init();
321 $tree = $this->pagetree->getBrowsableTree();
322 if (!$this->pagetree->ajaxStatus) {
323 $ajaxObj->setError($tree);
324 } else {
325 $ajaxObj->addContent('tree', $tree);
326 }
327 }
328
329 }
330
331
332 ?>