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