Follow-up to #15045: Trailing newlines after php closing tag. (Thanks to Nikolas...
[Packages/TYPO3.CMS.git] / typo3 / alt_db_navframe.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2010 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Page navigation tree for the Web module
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
32 * XHTML compliant
33 *
34 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 * 192: class SC_alt_db_navframe
41 * 210: function init()
42 * 313: function main()
43 * 387: function printContent()
44 *
45 * SECTION: Temporary DB mounts
46 * 415: function initializeTemporaryDBmount()
47 * 449: function settingTemporaryMountPoint($pageId)
48 *
49 * TOTAL FUNCTIONS: 9
50 * (This index is automatically created/updated by the extension "extdeveval")
51 *
52 */
53
54
55 $BACK_PATH = '';
56 require_once('init.php');
57 require('template.php');
58 require_once('class.webpagetree.php');
59
60
61 /**
62 * Main script class for the page tree navigation frame
63 *
64 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
65 * @package TYPO3
66 * @subpackage core
67 */
68 class SC_alt_db_navframe {
69
70 // Internal:
71 var $content;
72 var $pagetree;
73
74 /**
75 * document template object
76 *
77 * @var template
78 */
79 var $doc;
80 var $active_tempMountPoint = 0; // Temporary mount point (record), if any
81 var $backPath;
82
83 // Internal, static: GPvar:
84 var $currentSubScript;
85 var $cMR;
86 var $setTempDBmount; // If not '' (blank) then it will clear (0) or set (>0) Temporary DB mount.
87
88 var $template; // a static HTML template, usually in templates/alt_db_navframe.html
89 var $hasFilterBox; //depends on userTS-setting
90
91 /**
92 * Initialiation of the class
93 *
94 * @return void
95 */
96 function init() {
97 global $BE_USER,$BACK_PATH;
98
99 // Setting backPath
100 $this->backPath = $BACK_PATH;
101
102 // Setting GPvars:
103 $this->cMR = t3lib_div::_GP('cMR');
104 $this->currentSubScript = t3lib_div::_GP('currentSubScript');
105 $this->setTempDBmount = t3lib_div::_GP('setTempDBmount');
106
107 // look for User setting
108 $this->hasFilterBox = !$BE_USER->getTSConfigVal('options.pageTree.hideFilter');
109
110 // Create page tree object:
111 $this->pagetree = t3lib_div::makeInstance('webPageTree');
112 $this->pagetree->ext_IconMode = $BE_USER->getTSConfigVal('options.pageTree.disableIconLinkToContextmenu');
113 $this->pagetree->ext_showPageId = $BE_USER->getTSConfigVal('options.pageTree.showPageIdWithTitle');
114 $this->pagetree->ext_showNavTitle = $BE_USER->getTSConfigVal('options.pageTree.showNavTitle');
115 $this->pagetree->ext_separateNotinmenuPages = $BE_USER->getTSConfigVal('options.pageTree.separateNotinmenuPages');
116 $this->pagetree->ext_alphasortNotinmenuPages = $BE_USER->getTSConfigVal('options.pageTree.alphasortNotinmenuPages');
117 $this->pagetree->thisScript = 'alt_db_navframe.php';
118 $this->pagetree->addField('alias');
119 $this->pagetree->addField('shortcut');
120 $this->pagetree->addField('shortcut_mode');
121 $this->pagetree->addField('mount_pid');
122 $this->pagetree->addField('mount_pid_ol');
123 $this->pagetree->addField('nav_hide');
124 $this->pagetree->addField('nav_title');
125 $this->pagetree->addField('url');
126
127 // Temporary DB mounts:
128 $this->initializeTemporaryDBmount();
129 }
130
131
132 /**
133 * initialization for the visual parts of the class
134 * Use template rendering only if this is a non-AJAX call
135 *
136 * @return void
137 */
138 public function initPage() {
139 global $BE_USER;
140
141 // Setting highlight mode:
142 $this->doHighlight = !$BE_USER->getTSConfigVal('options.pageTree.disableTitleHighlight');
143
144 // If highlighting is active, define the CSS class for the active item depending on the workspace
145 if ($this->doHighlight) {
146 $hlClass = ($BE_USER->workspace === 0 ? 'active' : 'active active-ws wsver'.$BE_USER->workspace);
147 }
148
149 // Create template object:
150 $this->doc = t3lib_div::makeInstance('template');
151 $this->doc->backPath = $BACK_PATH;
152 $this->doc->setModuleTemplate('templates/alt_db_navframe.html');
153 $this->doc->showFlashMessages = FALSE;
154
155 // get HTML-Template
156
157
158 // Adding javascript code for AJAX (prototype), drag&drop and the pagetree as well as the click menu code
159 $this->doc->getDragDropCode('pages');
160 $this->doc->getContextMenuCode();
161 $this->doc->getPageRenderer()->loadScriptaculous('effects');
162 $this->doc->getPageRenderer()->loadExtJS();
163
164 $this->doc->getPageRenderer()->addJsFile('js/pagetreefiltermenu.js');
165
166 $this->doc->JScode .= $this->doc->wrapScriptTags(
167 ($this->currentSubScript?'top.currentSubScript=unescape("'.rawurlencode($this->currentSubScript).'");':'').'
168 // setting prefs for pagetree and drag & drop
169 '.($this->doHighlight ? 'Tree.highlightClass = "'.$hlClass.'";' : '').'
170
171 // Function, loading the list frame from navigation tree:
172 function jumpTo(id, linkObj, highlightID, bank) { //
173 var theUrl = top.TS.PATH_typo3 + top.currentSubScript ;
174 if (theUrl.indexOf("?") != -1) {
175 theUrl += "&id=" + id
176 } else {
177 theUrl += "?id=" + id
178 }
179 top.fsMod.currentBank = bank;
180
181 if (top.TYPO3.configuration.condensedMode) {
182 top.content.location.href = theUrl;
183 } else {
184 parent.list_frame.location.href=theUrl;
185 }
186
187 '.($this->doHighlight ? 'Tree.highlightActiveItem("web", highlightID + "_" + bank);' : '').'
188 '.(!$GLOBALS['CLIENT']['FORMSTYLE'] ? '' : 'if (linkObj) linkObj.blur(); ').'
189 return false;
190 }
191 '.($this->cMR?"jumpTo(top.fsMod.recentIds['web'],'');":'').
192
193 ($this->hasFilterBox ? 'var TYPO3PageTreeFilter = new PageTreeFilter();' : '') . '
194
195 ');
196
197 $this->doc->bodyTagId = 'typo3-pagetree';
198 }
199
200
201 /**
202 * Main function, rendering the browsable page tree
203 *
204 * @return void
205 */
206 function main() {
207 global $LANG,$CLIENT;
208
209 // Produce browse-tree:
210 $tree = $this->pagetree->getBrowsableTree();
211
212
213 // Outputting Temporary DB mount notice:
214 if ($this->active_tempMountPoint) {
215 $flashText = '
216 <a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('setTempDBmount' => 0))) . '">' .
217 $LANG->sl('LLL:EXT:lang/locallang_core.xml:labels.temporaryDBmount',1) .
218 '</a> <br />' .
219 $LANG->sl('LLL:EXT:lang/locallang_core.xml:labels.path',1) . ': <span title="' .
220 htmlspecialchars($this->active_tempMountPoint['_thePathFull']) . '">' .
221 htmlspecialchars(t3lib_div::fixed_lgd_cs($this->active_tempMountPoint['_thePath'],-50)).
222 '</span>
223 ';
224
225 $flashMessage = t3lib_div::makeInstance(
226 't3lib_FlashMessage',
227 $flashText,
228 '',
229 t3lib_FlashMessage::INFO
230 );
231
232
233 $this->content.= $flashMessage->render();
234 }
235
236 // Outputting page tree:
237 $this->content .= '<div id="PageTreeDiv">'.$tree.'</div>';
238
239 // Adding javascript for drag & drop activation and highlighting
240 $this->content .= $this->doc->wrapScriptTags('
241 '.($this->doHighlight ? 'Tree.highlightActiveItem("",top.fsMod.navFrameHighlightedID["web"]);' : '').'
242 '.(!$this->doc->isCMlayers() ? 'Tree.activateDragDrop = false;' : 'Tree.registerDragDropHandlers();')
243 );
244
245 // Setting up the buttons and markers for docheader
246 $docHeaderButtons = $this->getButtons();
247 $markers = array(
248 'IMG_RESET' => t3lib_iconWorks::getSpriteIcon('actions-document-close', array(
249 'id' =>'treeFilterReset',
250 'alt'=> $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.resetFilter'),
251 'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.resetFilter')
252 )),
253 'WORKSPACEINFO' => $this->getWorkspaceInfo(),
254 'CONTENT' => $this->content
255 );
256 $subparts = array();
257
258 if (!$this->hasFilterBox) {
259 $subparts['###SECOND_ROW###'] = '';
260 }
261 // Build the <body> for the module
262 $this->content = $this->doc->startPage('TYPO3 Page Tree');
263 $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers, $subparts);
264 $this->content.= $this->doc->endPage();
265
266 $this->content = $this->doc->insertStylesAndJS($this->content);
267 }
268
269 /**
270 * Outputting the accumulated content to screen
271 *
272 * @return void
273 */
274 function printContent() {
275 echo $this->content;
276 }
277
278 /**
279 * Create the panel of buttons for submitting the form or otherwise perform operations.
280 *
281 * @return array all available buttons as an assoc. array
282 */
283 protected function getButtons() {
284 global $LANG;
285
286 $buttons = array(
287 'csh' => '',
288 'new_page' => '',
289 'refresh' => '',
290 'filter' => '',
291 );
292
293 // New Page
294 $onclickNewPageWizard = 'top.content.list_frame.location.href=top.TS.PATH_typo3+\'db_new.php?pagesOnly=1&amp;id=\'+Tree.pageID;';
295 $buttons['new_page'] = '<a href="#" onclick="' . $onclickNewPageWizard . '" title="' . $LANG->sL('LLL:EXT:cms/layout/locallang.xml:newPage', TRUE) . '">' .
296 t3lib_iconWorks::getSpriteIcon('actions-page-new') .
297 '</a>';
298
299 // Refresh
300 $buttons['refresh'] = '<a href="' . htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')) . '" title="' . $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.refresh', TRUE) . '">' .
301 t3lib_iconWorks::getSpriteIcon('actions-system-refresh') .
302 '</a>';
303
304 // CSH
305 $buttons['csh'] = str_replace('typo3-csh-inline','typo3-csh-inline show-right',t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'pagetree', $GLOBALS['BACK_PATH'], '', TRUE));
306
307 // Filter
308 if ($this->hasFilterBox) {
309 $buttons['filter'] = '<a href="#" id="tree-toolbar-filter-item">' . t3lib_iconWorks::getSpriteIcon('actions-system-tree-search-open', array('title'=> $LANG->sL('LLL:EXT:cms/layout/locallang.xml:labels.filter', 1))) . '</a>';
310 }
311
312 return $buttons;
313 }
314
315 /**
316 * Create the workspace information
317 *
318 * @return string HTML containing workspace info
319 */
320 protected function getWorkspaceInfo() {
321 global $LANG;
322
323 if ($GLOBALS['BE_USER']->workspace!==0 || $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.onlineWorkspaceInfo')) {
324 switch($GLOBALS['BE_USER']->workspace) {
325 case 0:
326 $wsTitle = '&nbsp;'.$this->doc->icons(2).'['.$LANG->sL('LLL:EXT:lang/locallang_misc.xml:shortcut_onlineWS',1).']';
327 break;
328 case -1:
329 $wsTitle = '['.$LANG->sL('LLL:EXT:lang/locallang_misc.xml:shortcut_offlineWS',1).']';
330 break;
331 default:
332 $wsTitle = '['.$GLOBALS['BE_USER']->workspace.'] '.htmlspecialchars($GLOBALS['BE_USER']->workspaceRec['title']);
333 break;
334 }
335
336 $workspaceInfo = '
337 <div class="bgColor4 workspace-info">
338 <a href="'.htmlspecialchars('mod/user/ws/index.php').'" target="content">'.
339 t3lib_iconWorks::getSpriteIcon('apps-toolbar-menu-workspace') .
340 '</a>'.$wsTitle.'
341 </div>
342 ';
343 }
344
345 return $workspaceInfo;
346 }
347
348
349 /**********************************
350 *
351 * Temporary DB mounts
352 *
353 **********************************/
354
355 /**
356 * Getting temporary DB mount
357 *
358 * @return void
359 */
360 function initializeTemporaryDBmount(){
361 global $BE_USER;
362
363 // Set/Cancel Temporary DB Mount:
364 if (strlen($this->setTempDBmount)) {
365 $set = t3lib_div::intInRange($this->setTempDBmount,0);
366 if ($set>0 && $BE_USER->isInWebMount($set)) { // Setting...:
367 $this->settingTemporaryMountPoint($set);
368 } else { // Clear:
369 $this->settingTemporaryMountPoint(0);
370 }
371 }
372
373 // Getting temporary mount point ID:
374 $temporaryMountPoint = intval($BE_USER->getSessionData('pageTree_temporaryMountPoint'));
375
376 // If mount point ID existed and is within users real mount points, then set it temporarily:
377 if ($temporaryMountPoint > 0 && $BE_USER->isInWebMount($temporaryMountPoint)) {
378 if ($this->active_tempMountPoint = t3lib_BEfunc::readPageAccess($temporaryMountPoint, $BE_USER->getPagePermsClause(1))) {
379 $this->pagetree->MOUNTS = array($temporaryMountPoint);
380 }
381 else {
382 // Clear temporary mount point as we have no access to it any longer
383 $this->settingTemporaryMountPoint(0);
384 }
385 }
386 }
387
388
389 /**
390 * Setting temporary page id as DB mount
391 *
392 * @param integer The page id to set as DB mount
393 * @return void
394 */
395 function settingTemporaryMountPoint($pageId) {
396 $GLOBALS['BE_USER']->setAndSaveSessionData('pageTree_temporaryMountPoint',intval($pageId));
397 }
398
399
400 /**********************************
401 *
402 * AJAX Calls
403 *
404 **********************************/
405
406 /**
407 * Makes the AJAX call to expand or collapse the pagetree.
408 * Called by typo3/ajax.php
409 *
410 * @param array $params: additional parameters (not used here)
411 * @param TYPO3AJAX $ajaxObj: The TYPO3AJAX object of this request
412 * @return void
413 */
414 public function ajaxExpandCollapse($params, $ajaxObj) {
415 global $LANG;
416
417 $this->init();
418 $tree = $this->pagetree->getBrowsableTree();
419 if (!$this->pagetree->ajaxStatus) {
420 $ajaxObj->setError($tree);
421 } else {
422 $ajaxObj->addContent('tree', $tree);
423 }
424 }
425 }
426
427
428
429 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_db_navframe.php']) {
430 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_db_navframe.php']);
431 }
432
433
434 // Make instance if it is not an AJAX call
435 if (!(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX)) {
436 $SOBE = t3lib_div::makeInstance('SC_alt_db_navframe');
437 $SOBE->init();
438 $SOBE->initPage();
439 $SOBE->main();
440 $SOBE->printContent();
441 }
442
443 ?>