Fixed bug #10178: Toolbar menu fails if there are no menu items
[Packages/TYPO3.CMS.git] / typo3 / backend.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2007 Ingo Renner <ingo@typo3.org>
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 require_once('init.php');
29 require_once('template.php');
30 require_once('interfaces/interface.backend_toolbaritem.php');
31
32 require('classes/class.typo3logo.php');
33 require('classes/class.modulemenu.php');
34
35 // core toolbar items
36 require('classes/class.workspaceselector.php');
37 require('classes/class.clearcachemenu.php');
38 require('classes/class.shortcutmenu.php');
39 require('classes/class.backendsearchmenu.php');
40
41 require_once(PATH_t3lib.'class.t3lib_loadmodules.php');
42 require_once(PATH_t3lib.'class.t3lib_basicfilefunc.php');
43 require_once('class.alt_menu_functions.inc');
44 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_misc.xml');
45
46
47 /**
48 * Class for rendering the TYPO3 backend version 4.2+
49 *
50 * @author Ingo Renner <ingo@typo3.org>
51 * @package TYPO3
52 * @subpackage core
53 */
54 class TYPO3backend {
55
56 protected $content;
57 protected $css;
58 protected $cssFiles;
59 protected $js;
60 protected $jsFiles;
61 protected $toolbarItems;
62 private $menuWidthDefault = 160; // intentionally private as nobody should modify defaults
63 protected $menuWidth;
64
65 /**
66 * Object for loading backend modules
67 *
68 * @var t3lib_loadModules
69 */
70 protected $moduleLoader;
71
72 /**
73 * module menu generating object
74 *
75 * @var ModuleMenu
76 */
77 protected $moduleMenu;
78
79 /**
80 * constructor
81 *
82 * @return void
83 */
84 public function __construct() {
85
86 // Initializes the backend modules structure for use later.
87 $this->moduleLoader = t3lib_div::makeInstance('t3lib_loadModules');
88 $this->moduleLoader->load($GLOBALS['TBE_MODULES']);
89
90 $this->moduleMenu = t3lib_div::makeInstance('ModuleMenu');
91
92 // add default BE javascript
93 $this->js = '';
94 $this->jsFiles = array(
95 'contrib/prototype/prototype.js',
96 'contrib/scriptaculous/scriptaculous.js?load=builder,effects,controls,dragdrop',
97 'contrib/extjs/adapter/prototype/ext-prototype-adapter.js',
98 'contrib/extjs/ext-all.js',
99 'md5.js',
100 'js/backend.js',
101 'js/common.js',
102 'js/sizemanager.js',
103 'js/toolbarmanager.js',
104 'js/modulemenu.js',
105 'js/iecompatibility.js',
106 '../t3lib/jsfunc.evalfield.js'
107 );
108
109 // add default BE css
110 $this->css = '';
111 $this->cssFiles = array(
112 'backend-scaffolding' => 'css/backend-scaffolding.css',
113 'backend-style' => 'css/backend-style.css',
114 'modulemenu' => 'css/modulemenu.css',
115 'extJS' => 'contrib/extjs/resources/css/ext-all.css',
116 'extJS-gray' => 'contrib/extjs/resources/css/xtheme-gray.css'
117 );
118
119 $this->toolbarItems = array();
120 $this->initializeCoreToolbarItems();
121
122 $this->menuWidth = $this->menuWidthDefault;
123 if (isset($GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW']) && (int) $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'] != (int) $this->menuWidth) {
124 $this->menuWidth = (int) $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'];
125 }
126 }
127
128 /**
129 * initializes the core toolbar items
130 *
131 * @return void
132 */
133 protected function initializeCoreToolbarItems() {
134
135 $coreToolbarItems = array(
136 'workspaceSelector' => 'WorkspaceSelector',
137 'shortcuts' => 'ShortcutMenu',
138 'clearCacheActions' => 'ClearCacheMenu',
139 'backendSearch' => 'BackendSearchMenu'
140 );
141
142 foreach($coreToolbarItems as $toolbarItemName => $toolbarItemClassName) {
143 // Get name of XCLASS (if any):
144 $toolbarItemClassName = t3lib_div::makeInstanceClassName($toolbarItemClassName);
145 $toolbarItem = new $toolbarItemClassName($this);
146
147 if(!($toolbarItem instanceof backend_toolbarItem)) {
148 throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195126772);
149 }
150
151 if($toolbarItem->checkAccess()) {
152 $this->toolbarItems[$toolbarItemName] = $toolbarItem;
153 } else {
154 unset($toolbarItem);
155 }
156 }
157 }
158
159 /**
160 * main function generating the BE scaffolding
161 *
162 * @return void
163 */
164 public function render() {
165
166 // prepare the scaffolding, at this point extension may still add javascript and css
167 $logo = t3lib_div::makeInstance('TYPO3Logo');
168 $logo->setLogo('gfx/typo3logo_mini.png');
169
170 $menu = $this->moduleMenu->render();
171
172 if ($this->menuWidth != $this->menuWidthDefault) {
173 $this->css .= '
174 #typo3-logo,
175 #typo3-side-menu {
176 width: ' . ($this->menuWidth - 1) . 'px;
177 }
178
179 #typo3-top,
180 #typo3-content {
181 margin-left: ' . $this->menuWidth . 'px;
182 }
183 ';
184 }
185
186 // create backend scaffolding
187 $backendScaffolding = '
188 <div id="typo3-backend">
189 <div id="typo3-top-container">
190 <div id="typo3-logo">'.$logo->render().'</div>
191 <div id="typo3-top" class="typo3-top-toolbar">'
192 .$this->renderToolbar()
193 .'</div>
194 </div>
195 <div id="typo3-main-container">
196 <div id="typo3-side-menu">
197 '.$menu.'
198 </div>
199 <div id="typo3-content">
200 <iframe src="alt_intro.php" name="content" id="content" marginwidth="0" marginheight="0" frameborder="0" scrolling="auto" noresize="noresize"></iframe>
201 </div>
202 </div>
203 </div>
204 ';
205
206 /******************************************************
207 * now put the complete backend document together
208 ******************************************************/
209
210 // remove duplicate entries
211 $this->jsFiles = array_unique($this->jsFiles);
212
213 // add javascript
214 foreach($this->jsFiles as $jsFile) {
215 $GLOBALS['TBE_TEMPLATE']->JScode .= '
216 <script type="text/javascript" src="'.$jsFile.'"></script>';
217 }
218 $GLOBALS['TBE_TEMPLATE']->JScode .= chr(10);
219 $this->generateJavascript();
220 $GLOBALS['TBE_TEMPLATE']->JScode .= $GLOBALS['TBE_TEMPLATE']->wrapScriptTags($this->js);
221
222 // FIXME abusing the JS container to add CSS, need to fix template.php
223 foreach($this->cssFiles as $cssFileName => $cssFile) {
224 $GLOBALS['TBE_TEMPLATE']->JScode .= '
225 <link rel="stylesheet" type="text/css" href="'.$cssFile.'" />
226 ';
227
228 // load addditional css files to overwrite existing core styles
229 if(!empty($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName])) {
230 $GLOBALS['TBE_TEMPLATE']->JScode .= '
231 <link rel="stylesheet" type="text/css" href="'.$GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName].'" />
232 ';
233 }
234 }
235
236 if(!empty($this->css)) {
237 $GLOBALS['TBE_TEMPLATE']->JScode .= '
238 <style type="text/css" id="internalStyle">
239 '.$this->css.'
240 </style>';
241 }
242
243 // set document title:
244 $title = ($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']
245 ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'].' [TYPO3 '.TYPO3_version.']'
246 : 'TYPO3 '.TYPO3_version
247 );
248
249 // start page header:
250 $this->content .= $GLOBALS['TBE_TEMPLATE']->startPage($title);
251 $this->content .= $backendScaffolding;
252 $this->content .= $GLOBALS['TBE_TEMPLATE']->endPage();
253
254 echo $this->content;
255 }
256
257 /**
258 * renders the items in the top toolbar
259 *
260 * @return string top toolbar elements as HTML
261 */
262 protected function renderToolbar() {
263
264 // move search to last position
265 $search = $this->toolbarItems['backendSearch'];
266 unset($this->toolbarItems['backendSearch']);
267 $this->toolbarItems['backendSearch'] = $search;
268
269 $toolbar = '<ul id="typo3-toolbar">';
270 $toolbar.= '<li>'.$this->getLoggedInUserLabel().'</li>
271 <li><div id="logout-button" class="toolbar-item no-separator">'.$this->moduleMenu->renderLogoutButton().'</div></li>';
272
273 foreach($this->toolbarItems as $toolbarItem) {
274 $menu = $toolbarItem->render();
275 if ($menu) {
276 $additionalAttributes = $toolbarItem->getAdditionalAttributes();
277 $toolbar .= '<li' . $additionalAttributes . '>' .$menu. '</li>';
278 }
279 }
280
281 return $toolbar.'</ul>';
282 }
283
284 /**
285 * gets the label of the currently loged in BE user
286 *
287 * @return string html code snippet displaying the currently logged in user
288 */
289 protected function getLoggedInUserLabel() {
290 global $BE_USER, $BACK_PATH;
291
292 $icon = '<img'.t3lib_iconWorks::skinImg(
293 '',
294 $BE_USER->isAdmin() ?
295 'gfx/i/be_users_admin.gif' :
296 'gfx/i/be_users.gif',
297 'width="18" height="16"'
298 )
299 .' title="" alt="" />';
300
301 $label = $GLOBALS['BE_USER']->user['realName'] ?
302 $BE_USER->user['realName'].' ['.$BE_USER->user['username'].']' :
303 $BE_USER->user['username'];
304
305 // Link to user setup if it's loaded and user has access
306 $link = '';
307 if (t3lib_extMgm::isLoaded('setup') && $BE_USER->check('modules','user_setup')) {
308 $link = '<a href="#" onclick="top.goToModule(\'user_setup\');this.blur();return false;">';
309 }
310
311 $username = '">'.$link.$icon.'<span>'.htmlspecialchars($label).'</span>'.($link?'</a>':'');
312
313 // superuser mode
314 if($BE_USER->user['ses_backuserid']) {
315 $username = ' su-user">'.$icon.
316 '<span title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xml:switchtouser').'">SU: </span>'.
317 '<span>'.htmlspecialchars($label).'</span>';
318 }
319
320 return '<div id="username" class="toolbar-item no-separator'.$username.'</div>';
321 }
322
323 /**
324 * Generates the JavaScript code for the backend.
325 *
326 * @return void
327 */
328 protected function generateJavascript() {
329
330 $pathTYPO3 = t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')).'/';
331 $goToModuleSwitch = $this->moduleMenu->getGotoModuleJavascript();
332 $moduleFramesHelper = implode(chr(10), $this->moduleMenu->getFsMod());
333
334 // If another page module was specified, replace the default Page module with the new one
335 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
336 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
337
338 $menuFrameName = 'menu';
339 if($GLOBALS['BE_USER']->uc['noMenuMode'] === 'icons') {
340 $menuFrameName = 'topmenuFrame';
341 }
342
343 // create challenge for the (re)login form and save it in the session.
344 $challenge = md5(uniqid('').getmypid());
345 session_start();
346 $_SESSION['login_challenge'] = $challenge;
347
348 // determine security level from conf vars and default to super challenged
349 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) {
350 $this->loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'];
351 } else {
352 $this->loginSecurityLevel = 'superchallenged';
353 }
354
355 $this->js .= '
356 Ext.BLANK_IMAGE_URL = "' .
357 // t3lib_div::locationHeaderUrl() will include '/typo3/' in the URL
358 htmlspecialchars(t3lib_div::locationHeaderUrl('gfx/clear.gif')) .
359 '";
360
361 /**
362 * Function similar to PHPs rawurlencode();
363 */
364 function rawurlencode(str) {
365 var output = escape(str);
366 output = str_replace("*","%2A", output);
367 output = str_replace("+","%2B", output);
368 output = str_replace("/","%2F", output);
369 output = str_replace("@","%40", output);
370 return output;
371 }
372
373 /**
374 * Function to similar to PHPs rawurlencode() which removes TYPO3_SITE_URL;
375 */
376 function rawurlencodeAndRemoveSiteUrl(str) { //
377 var siteUrl = "' . t3lib_div::getIndpEnv('TYPO3_SITE_URL') . '";
378 return rawurlencode(str_replace(siteUrl, \'\', str));
379 }
380
381 /**
382 * String-replace function
383 */
384 function str_replace(match,replace,string) { //
385 var input = ""+string;
386 var matchStr = ""+match;
387 if (!matchStr) {return string;}
388 var output = "";
389 var pointer=0;
390 var pos = input.indexOf(matchStr);
391 while (pos!=-1) {
392 output+=""+input.substr(pointer, pos-pointer)+replace;
393 pointer=pos+matchStr.length;
394 pos = input.indexOf(match,pos+1);
395 }
396 output+=""+input.substr(pointer);
397 return output;
398 }
399
400 /**
401 * TypoSetup object.
402 */
403 function typoSetup() { //
404 this.PATH_typo3 = "'.$pathTYPO3.'";
405 this.PATH_typo3_enc = "'.rawurlencode($pathTYPO3).'";
406 this.username = "'.$GLOBALS['BE_USER']->user['username'].'";
407 this.uniqueID = "'.t3lib_div::shortMD5(uniqid('')).'";
408 this.navFrameWidth = 0;
409 this.securityLevel = "'.$this->loginSecurityLevel.'";
410 }
411 var TS = new typoSetup();
412
413 /**
414 * Functions for session-expiry detection:
415 */
416 function busy() { //
417 this.loginRefreshed = busy_loginRefreshed;
418 this.openRefreshWindow = busy_OpenRefreshWindow;
419 this.busyloadTime=0;
420 this.openRefreshW=0;
421 this.reloginCancelled=0;
422 this.earlyRelogin=0;
423
424 // starts the timer and resets the earlyRelogin variable so that
425 // the countdown works properly.
426 this.startTimer = function() {
427 this.earlyRelogin = 0;
428 this.timer.start();
429 }
430
431 this.stopTimer = function() {
432 this.timer.stop();
433 }
434
435 // simple timer that polls the server to determine imminent timeout.
436 this.timer = new Ajax.PeriodicalUpdater("","ajax.php", {
437 method: "get",
438 frequency: 60,
439 parameters: "ajaxID=BackendLogin::isTimedOut&skipSessionUpdate=1",
440 onSuccess: function(e) {
441 var login = e.responseJSON.login.evalJSON();
442 if(login.timed_out) {
443 busy.openRefreshWindow();
444 }
445 }
446 });
447
448 // this function runs the countdown and opens the login window
449 // as soon as the countdown expires.
450 this.countDown = function(progressControl, progressTextFormatPlural, progressTextFormatSingular, secondsRemaining, totalSeconds) {
451
452 if(busy.earlyRelogin == 0) {
453 if(secondsRemaining > 1) {
454 progressControl.updateText(String.format(progressTextFormatPlural, secondsRemaining));
455 progressControl.updateProgress(secondsRemaining/(1.0*totalSeconds));
456 setTimeout(function () {
457 busy.countDown(progressControl, progressTextFormatPlural, progressTextFormatSingular,secondsRemaining - 1, totalSeconds);
458 }, 1000);
459 } else if(secondsRemaining > 0) {
460 progressControl.updateText(String.format(progressTextFormatSingular, secondsRemaining));
461 progressControl.updateProgress(secondsRemaining/(1.0*totalSeconds));
462 setTimeout(function () {
463 busy.countDown(progressControl, progressTextFormatPlural, progressTextFormatSingular,secondsRemaining - 1, totalSeconds);
464 }, 1000);
465 } else {
466 busy.openRefreshW = 1;
467 busy.openLogin();
468 }
469 }
470 };
471
472 // Closes the countdown window and opens a new one with a login form.
473 this.openLogin = function() {
474 var login;
475 doChallengeResponse = function(superchallenged) {
476 password = $$("#loginform form")[0].p_field.value;
477
478 if (password) {
479 if (superchallenged) {
480 password = MD5(password); // this makes it superchallenged!!
481 }
482 str = $("login_username").value+":"+password+":"+$("challenge").value;
483 $("userident").value = MD5(str);
484 $("password").value = "";
485
486 return true;
487 }
488 }
489
490 submitForm = function() {
491 if(TS.securityLevel == "superchallenged") {
492 doChallengeResponse(1);
493 } else if (TS.securityLevel == "challenged") {
494 doChallengeResponse(0);
495 } else {
496 $("userident").value = $$("#loginform form")[0].p_field.value;
497 $("password").value= "";
498 }
499
500 login.getForm().submit({
501 method: "post",
502 waitTitle: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_logging_in') . '",
503 waitMsg: " ",
504 params: "ajaxID=BackendLogin::login&login_status=login",
505 success: function() {
506 win.close();
507 setTimeout("busy.startTimer()", 2000);
508
509 },
510
511 failure: function() {
512 // TODO: add failure to notification system instead of alert
513 // Ext.tip.msg("Login failed", "Username or Password incorrect!");
514 Ext.Msg.alert("' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_failed') . '", "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_failed_message') . '");
515 }
516 });
517 }
518
519 logout = new Ajax.Request("ajax.php", {
520 method: "get",
521 parameters: "ajaxID=BackendLogin::logout"
522 });
523
524 Ext.onReady(function(){
525 login = new Ext.FormPanel({
526 url: "ajax.php",
527 id: "loginform",
528 title: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_title') . '",
529 defaultType: "textfield",
530 width: "100%",
531 bodyStyle: "padding: 5px 5px 3px 5px; border-width: 0; margin-bottom: 7px;",
532
533 items: [{
534 xtype: "panel",
535 bodyStyle: "margin-bottom: 7px; border: none;",
536 html: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.login_expired') . '"
537 },{
538 fieldLabel: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_username') . '",
539 name: "username",
540 id: "login_username",
541 allowBlank: false,
542 width: 250
543 },{
544 fieldLabel: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_password') . '",
545 name: "p_field",
546 width: 250,
547 id: "password",
548 inputType: "password"
549 },{
550 xtype: "hidden",
551 name: "userident",
552 id: "userident",
553 value: ""
554 }, {
555 xtype: "hidden",
556 name: "challenge",
557 id: "challenge",
558 value: "' . $challenge . '"
559 }
560 ],
561 keys:({
562 key: Ext.EventObject.ENTER,
563 fn: submitForm,
564 scope: this
565 }),
566 buttons: [{
567 text: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_button') . '",
568 formBind: true,
569 handler: submitForm
570 }, {
571 text: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_logout_button') . '",
572 formBind: true,
573 handler: function() {
574 top.location.href = "' . t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . '";
575 }
576 }]
577 });
578 win.close();
579 win = new Ext.Window({
580 width: 450,
581 autoHeight: true,
582 closable: false,
583 resizable: false,
584 plain: true,
585 border: false,
586 modal: true,
587 draggable: false,
588 items: [login]
589 });
590 win.show();
591 });
592 }
593 }
594
595 function busy_loginRefreshed() { //
596 this.openRefreshW=0;
597 this.earlyRelogin=0;
598 }
599
600 function busy_OpenRefreshWindow() {
601 this.openRefreshW = 1;
602
603 busy.stopTimer();
604
605 var seconds = 30;
606 var progressTextFormatSingular = "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_countdown_singular') . '";
607 var progressTextFormatPlural = "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_countdown') . '";
608 var progressText = String.format(progressTextFormatPlural, seconds);
609 var progressControl = new Ext.ProgressBar({
610 autoWidth: true,
611 autoHeight: true,
612 value: 1,
613 text: progressText
614 });
615
616 win = new Ext.Window({
617 closable: false,
618 resizable: false,
619 draggable: false,
620 modal: true,
621 items: [{
622 xtype: "panel",
623 bodyStyle: "padding: 5px 5px 3px 5px; border-width: 0; margin-bottom: 7px;",
624 bodyBorder: false,
625 autoHeight: true,
626 autoWidth: true,
627 html: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.login_about_to_expire') . '"
628 },
629 progressControl
630 ],
631 title: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.login_about_to_expire_title') . '",
632 width: 450,
633
634 buttons: [{
635 text: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_refresh_button') . '",
636 handler: function() {
637 refresh = new Ajax.Request("ajax.php", {
638 method: "get",
639 parameters: "ajaxID=BackendLogin::refreshLogin"
640 });
641 win.close();
642 busy.earlyRelogin = 1;
643 setTimeout("busy.startTimer()", 2000);
644 }
645 }, {
646 text: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_direct_logout_button') . '",
647 handler: function() {
648 top.location.href = "' . t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . 'logout.php";
649 }
650 }]
651 });
652 win.show();
653 busy.countDown(progressControl, progressTextFormatPlural, progressTextFormatSingular, seconds, seconds);
654 }
655
656 /**
657 * Launcing information window for records/files (fileref as "table" argument)
658 */
659 function launchView(table,uid,bP) { //
660 var backPath= bP ? bP : "";
661 var thePreviewWindow="";
662 thePreviewWindow = window.open(TS.PATH_typo3+"show_item.php?table="+encodeURIComponent(table)+"&uid="+encodeURIComponent(uid),"ShowItem"+TS.uniqueID,"height=400,width=550,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0");
663 if (thePreviewWindow && thePreviewWindow.focus) {
664 thePreviewWindow.focus();
665 }
666 }
667
668 /**
669 * Opens plain window with url
670 */
671 function openUrlInWindow(url,windowName) { //
672 regularWindow = window.open(url,windowName,"status=1,menubar=1,resizable=1,location=1,directories=0,scrollbars=1,toolbar=1");
673 regularWindow.focus();
674 return false;
675 }
676
677 /**
678 * Loads a page id for editing in the page edit module:
679 */
680 function loadEditId(id,addGetVars) { //
681 top.fsMod.recentIds["web"]=id;
682 top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_0"; // For highlighting
683
684 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
685 top.content.nav_frame.refresh_nav();
686 }
687
688 top.goToModule("'.$pageModule.'", 0, addGetVars?addGetVars:"");
689 }
690
691 /**
692 * Returns incoming URL (to a module) unless nextLoadModuleUrl is set. If that is the case nextLoadModuleUrl is returned (and cleared)
693 * Used by the shortcut frame to set a "intermediate URL"
694 */
695 var nextLoadModuleUrl="";
696 function getModuleUrl(inUrl) { //
697 var nMU;
698 if (top.nextLoadModuleUrl) {
699 nMU=top.nextLoadModuleUrl;
700 top.nextLoadModuleUrl="";
701 return nMU;
702 } else {
703 return inUrl;
704 }
705 }
706
707 /**
708 * Print properties of an object
709 */
710 function debugObj(obj,name) { //
711 var acc;
712 for (i in obj) {
713 if (obj[i]) {
714 acc+=i+": "+obj[i]+"\n";
715 }
716 }
717 alert("Object: "+name+"\n\n"+acc);
718 }
719
720 /**
721 * Initialize login expiration warning object
722 */
723 var busy = new busy();
724 busy.loginRefreshed();
725
726 /**
727 * Function used to switch modules
728 */
729 var currentModuleLoaded = "";
730 var goToModule = '.$goToModuleSwitch.'
731
732 /**
733 * Frameset Module object
734 *
735 * Used in main modules with a frameset for submodules to keep the ID between modules
736 * Typically that is set by something like this in a Web>* sub module:
737 * if (top.fsMod) top.fsMod.recentIds["web"] = "\'.intval($this->id).\'";
738 * if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
739 */
740 function fsModules() { //
741 this.recentIds=new Array(); // used by frameset modules to track the most recent used id for list frame.
742 this.navFrameHighlightedID=new Array(); // used by navigation frames to track which row id was highlighted last time
743 this.currentMainLoaded="";
744 this.currentBank="0";
745 }
746 var fsMod = new fsModules();
747 '.$moduleFramesHelper.'
748
749 // Used by Frameset Modules
750 var condensedMode = '.($GLOBALS['BE_USER']->uc['condensedMode']?1:0).';
751 var currentSubScript = "";
752 var currentSubNavScript = "";
753
754 // Used for tab-panels:
755 var DTM_currentTabs = new Array();
756
757 // status of WS FE preview
758 var WorkspaceFrontendPreviewEnabled = ' . (($GLOBALS['BE_USER']->workspace != 0 && !$GLOBALS['BE_USER']->user['workspace_preview']) ? 'false' : 'true') . ';
759 ';
760
761 // Check editing of page:
762 $this->handlePageEditing();
763 $this->setStartupModule();
764 }
765
766 /**
767 * Checking if the "&edit" variable was sent so we can open it for editing the page.
768 * Code based on code from "alt_shortcut.php"
769 *
770 * @return void
771 */
772 protected function handlePageEditing() {
773
774 if(!t3lib_extMgm::isLoaded('cms')) {
775 return;
776 }
777
778 // EDIT page:
779 $editId = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('edit'));
780 $editRecord = '';
781
782 if($editId) {
783
784 // Looking up the page to edit, checking permissions:
785 $where = ' AND ('.$GLOBALS['BE_USER']->getPagePermsClause(2)
786 .' OR '.$GLOBALS['BE_USER']->getPagePermsClause(16).')';
787
788 if(t3lib_div::testInt($editId)) {
789 $editRecord = t3lib_BEfunc::getRecordWSOL('pages', $editId, '*', $where);
790 } else {
791 $records = t3lib_BEfunc::getRecordsByField('pages', 'alias', $editId, $where);
792
793 if(is_array($records)) {
794 reset($records);
795 $editRecord = current($records);
796 t3lib_BEfunc::workspaceOL('pages', $editRecord);
797 }
798 }
799
800 // If the page was accessible, then let the user edit it.
801 if(is_array($editRecord) && $GLOBALS['BE_USER']->isInWebMount($editRecord['uid'])) {
802 // Setting JS code to open editing:
803 $this->js .= '
804 // Load page to edit:
805 window.setTimeout("top.loadEditId('.intval($editRecord['uid']).');", 500);
806 ';
807 // Checking page edit parameter:
808 if(!$GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
809
810 // Expanding page tree:
811 t3lib_BEfunc::openPageTree(intval($editRecord['pid']), !$GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded'));
812 }
813 } else {
814 $this->js .= '
815 // Warning about page editing:
816 alert('.$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('noEditPage'), $editId)).');
817 ';
818 }
819 }
820 }
821
822 /**
823 * Sets the startup module from either GETvars module and mpdParams or user configuration.
824 *
825 * @return void
826 */
827 protected function setStartupModule() {
828 $startModule = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('module'));
829
830 if(!$startModule) {
831 if ($GLOBALS['BE_USER']->uc['startModule']) {
832 $startModule = $GLOBALS['BE_USER']->uc['startModule'];
833 } else if($GLOBALS['BE_USER']->uc['startInTaskCenter']) {
834 $startModule = 'user_task';
835 }
836 }
837
838 $moduleParameters = t3lib_div::_GET('modParams');
839 if($startModule) {
840 $this->js .= '
841 // start in module:
842 function startInModule(modName, cMR_flag, addGetVars) {
843 Event.observe(document, \'dom:loaded\', function() {
844 top.goToModule(modName, cMR_flag, addGetVars);
845 });
846 }
847
848 startInModule(\''.$startModule.'\', false, \''.$moduleParameters.'\');
849 ';
850 }
851 }
852
853 /**
854 * generates the code for the TYPO3 logo, either the default TYPO3 logo or a custom one
855 *
856 * @return string HTML code snippet to display the TYPO3 logo
857 */
858 protected function getLogo() {
859 $logo = '<a href="http://www.typo3.com/" target="_blank" onclick="'.$GLOBALS['TBE_TEMPLATE']->thisBlur().'">'.
860 '<img'.t3lib_iconWorks::skinImg('','gfx/alt_backend_logo.gif','width="117" height="32"').' title="TYPO3 Content Management Framework" alt="" />'.
861 '</a>';
862
863 // overwrite with custom logo
864 if($GLOBALS['TBE_STYLES']['logo']) {
865 if(substr($GLOBALS['TBE_STYLES']['logo'], 0, 3) == '../') {
866 $imgInfo = @getimagesize(PATH_site.substr($GLOBALS['TBE_STYLES']['logo'], 3));
867 }
868 $logo = '<a href="http://www.typo3.com/" target="_blank" onclick="'.$GLOBALS['TBE_TEMPLATE']->thisBlur().'">'.
869 '<img src="'.$GLOBALS['TBE_STYLES']['logo'].'" '.$imgInfo[3].' title="TYPO3 Content Management Framework" alt="" />'.
870 '</a>';
871 }
872
873 return $logo;
874 }
875
876 /**
877 * adds a javascript snippet to the backend
878 *
879 * @param string javascript snippet
880 * @return void
881 */
882 public function addJavascript($javascript) {
883 // TODO do we need more checks?
884 if(!is_string($javascript)) {
885 throw new InvalidArgumentException('parameter $javascript must be of type string', 1195129553);
886 }
887
888 $this->js .= $javascript;
889 }
890
891 /**
892 * adds a javscript file to the backend after it has been checked that it exists
893 *
894 * @param string javascript file reference
895 * @return boolean true if the javascript file was successfully added, false otherwise
896 */
897 public function addJavascriptFile($javascriptFile) {
898 $jsFileAdded = false;
899
900 //TODO add more checks if neccessary
901 if(file_exists(t3lib_div::resolveBackPath(PATH_typo3.$javascriptFile))) {
902 $this->jsFiles[] = $javascriptFile;
903 $jsFileAdded = true;
904 }
905
906 return $jsFileAdded;
907 }
908
909 /**
910 * adds a css snippet to the backend
911 *
912 * @param string css snippet
913 * @return void
914 */
915 public function addCss($css) {
916 if(!is_string($css)) {
917 throw new InvalidArgumentException('parameter $css must be of type string', 1195129642);
918 }
919
920 $this->css .= $css;
921 }
922
923 /**
924 * adds a css file to the backend after it has been checked that it exists
925 *
926 * @param string the css file's name with out the .css ending
927 * @param string css file reference
928 * @return boolean true if the css file was added, false otherwise
929 */
930 public function addCssFile($cssFileName, $cssFile) {
931 $cssFileAdded = false;
932
933 //TODO add more checks if neccessary
934 if(file_exists(t3lib_div::resolveBackPath(PATH_typo3.$cssFile))) {
935 // prevent overwriting existing css files
936 if(empty($this->cssFiles[$cssFileName])) {
937 $this->cssFiles[$cssFileName] = $cssFile;
938 $cssFileAdded = true;
939 }
940 }
941
942 return $cssFileAdded;
943 }
944
945 /**
946 * adds an item to the toolbar, the class file for the toolbar item must be loaded at this point
947 *
948 * @param string toolbar item name, f.e. tx_toolbarExtension_coolItem
949 * @param string toolbar item class name, f.e. tx_toolbarExtension_coolItem
950 * @return void
951 */
952 public function addToolbarItem($toolbarItemName, $toolbarItemClassName) {
953 $toolbarItemResolvedClassName = t3lib_div::makeInstanceClassName($toolbarItemClassName);
954 $toolbarItem = new $toolbarItemResolvedClassName($this);
955
956 if(!($toolbarItem instanceof backend_toolbarItem)) {
957 throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195125501);
958 }
959
960 if($toolbarItem->checkAccess()) {
961 $this->toolbarItems[$toolbarItemName] = $toolbarItem;
962 } else {
963 unset($toolbarItem);
964 }
965 }
966 }
967
968
969 // include XCLASS
970 if(defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']) {
971 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']);
972 }
973
974
975 // document generation
976 $TYPO3backend = t3lib_div::makeInstance('TYPO3backend');
977
978 // include extensions which may add css, javascript or toolbar items
979 if(is_array($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'])) {
980 foreach($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'] as $additionalBackendItem) {
981 include_once($additionalBackendItem);
982 }
983 }
984
985 $TYPO3backend->render();
986
987 ?>