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