Fixed bug #14946: Switching workplaces causes nesting of BE (Thanks to Stefan Galinski)
[Packages/TYPO3.CMS.git] / typo3 / backend.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2007-2010 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 require_once('classes/class.donatewindow.php');
35
36 // core toolbar items
37 require('classes/class.workspaceselector.php');
38 require('classes/class.clearcachemenu.php');
39 require('classes/class.shortcutmenu.php');
40 require('classes/class.backendsearchmenu.php');
41
42 require_once('class.alt_menu_functions.inc');
43 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_misc.xml');
44
45
46 /**
47 * Class for rendering the TYPO3 backend version 4.2+
48 *
49 * @author Ingo Renner <ingo@typo3.org>
50 * @package TYPO3
51 * @subpackage core
52 */
53 class TYPO3backend {
54
55 protected $content;
56 protected $css;
57 protected $cssFiles;
58 protected $js;
59 protected $jsFiles;
60 protected $jsFilesAfterInline;
61 protected $toolbarItems;
62 private $menuWidthDefault = 190; // 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 * Pagerenderer
81 *
82 * @var t3lib_PageRenderer
83 */
84 protected $pageRenderer;
85
86 /**
87 * constructor
88 *
89 * @return void
90 */
91 public function __construct() {
92
93 // Initializes the backend modules structure for use later.
94 $this->moduleLoader = t3lib_div::makeInstance('t3lib_loadModules');
95 $this->moduleLoader->load($GLOBALS['TBE_MODULES']);
96
97 $this->moduleMenu = t3lib_div::makeInstance('ModuleMenu');
98
99 $this->pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
100 $this->pageRenderer->loadScriptaculous('builder,effects,controls,dragdrop');
101 $this->pageRenderer->loadExtJS();
102
103 // register the extDirect API providers
104 // Note: we need to iterate thru the object, because the addProvider method
105 // does this only with multiple arguments
106 $this->pageRenderer->addExtOnReadyCode(
107 'for (var api in Ext.app.ExtDirectAPI) {
108 Ext.Direct.addProvider(Ext.app.ExtDirectAPI[api]);
109 }
110 TYPO3.Backend = new TYPO3.Viewport(TYPO3.Viewport.configuration);
111 ',
112 TRUE
113 );
114
115
116 // add default BE javascript
117 $this->js = '';
118 $this->jsFiles = array(
119 'contrib/swfupload/swfupload.js',
120 'contrib/swfupload/plugins/swfupload.swfobject.js',
121 'contrib/swfupload/plugins/swfupload.cookies.js',
122 'contrib/swfupload/plugins/swfupload.queue.js',
123 'md5.js',
124 'js/common.js',
125 'js/extjs/backendsizemanager.js',
126 'js/toolbarmanager.js',
127 'js/modulemenu.js',
128 'js/iecompatibility.js',
129 'js/flashupload.js',
130 '../t3lib/jsfunc.evalfield.js',
131 '../t3lib/js/extjs/ux/flashmessages.js',
132 '../t3lib/js/extjs/ux/ext.ux.tabclosemenu.js',
133 'js/backend.js',
134 'js/loginrefresh.js',
135 'js/extjs/debugPanel.js',
136 'js/extjs/viewport.js',
137 'js/extjs/viewportConfiguration.js',
138 );
139
140 // add default BE css
141 $this->css = '';
142 $this->cssFiles = array();
143
144 $this->toolbarItems = array();
145 $this->initializeCoreToolbarItems();
146
147 $this->menuWidth = $this->menuWidthDefault;
148 if (isset($GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW']) && (int) $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'] != (int) $this->menuWidth) {
149 $this->menuWidth = (int) $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'];
150 }
151
152 $this->executeHook('constructPostProcess');
153 }
154
155 /**
156 * initializes the core toolbar items
157 *
158 * @return void
159 */
160 protected function initializeCoreToolbarItems() {
161
162 $coreToolbarItems = array(
163 'workspaceSelector' => 'WorkspaceSelector',
164 'shortcuts' => 'ShortcutMenu',
165 'clearCacheActions' => 'ClearCacheMenu',
166 'backendSearch' => 'BackendSearchMenu'
167 );
168
169 foreach($coreToolbarItems as $toolbarItemName => $toolbarItemClassName) {
170 $toolbarItem = t3lib_div::makeInstance($toolbarItemClassName, $this);
171
172 if(!($toolbarItem instanceof backend_toolbarItem)) {
173 throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195126772);
174 }
175
176 if($toolbarItem->checkAccess()) {
177 $this->toolbarItems[$toolbarItemName] = $toolbarItem;
178 } else {
179 unset($toolbarItem);
180 }
181 }
182 }
183
184 /**
185 * main function generating the BE scaffolding
186 *
187 * @return void
188 */
189 public function render() {
190 $this->executeHook('renderPreProcess');
191
192 if (t3lib_div::makeInstance('DonateWindow')->isDonateWindowAllowed()) {
193 $this->pageRenderer->addJsFile('js/donate.js');
194 }
195
196 // prepare the scaffolding, at this point extension may still add javascript and css
197 $logo = t3lib_div::makeInstance('TYPO3Logo');
198 $logo->setLogo('gfx/typo3logo_mini.png');
199
200 $menu = $this->moduleMenu->render();
201
202 if ($this->menuWidth != $this->menuWidthDefault) {
203 $this->css .= '
204 #typo3-top {
205 margin-left: ' . $this->menuWidth . 'px;
206 }
207 ';
208 }
209
210 // create backend scaffolding
211 $backendScaffolding = '
212 <div id="typo3-backend">
213 <div id="typo3-top-container" class="x-hide-display">
214 <div id="typo3-logo">'.$logo->render().'</div>
215 <div id="typo3-top" class="typo3-top-toolbar">' .
216 $this->renderToolbar() .
217 '</div>
218 </div>
219 <div id="typo3-main-container">
220 <div id="typo3-side-menu" class="x-hide-display">' .
221 $menu .
222 '</div>
223 <div id="typo3-content" class="x-hide-display">
224 <iframe src="alt_intro.php" name="content" id="content" marginwidth="0" marginheight="0" frameborder="0" scrolling="auto"></iframe>
225 </div>
226 </div>
227 </div>
228 ';
229
230 /******************************************************
231 * now put the complete backend document together
232 ******************************************************/
233
234 foreach($this->cssFiles as $cssFileName => $cssFile) {
235 $this->pageRenderer->addCssFile($cssFile);
236
237 // load addditional css files to overwrite existing core styles
238 if(!empty($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName])) {
239 $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName]);
240 }
241 }
242
243 if(!empty($this->css)) {
244 $this->pageRenderer->addCssInlineBlock('BackendInlineCSS', $this->css);
245 }
246
247 foreach ($this->jsFiles as $jsFile) {
248 $this->pageRenderer->addJsFile($jsFile);
249 }
250
251 // Those lines can be removed once we have at least one official ExtDirect router within the backend.
252 $hasExtDirectRouter = FALSE;
253 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'])) {
254 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'] as $key => $value) {
255 if (strpos($key, 'TYPO3.Ajax.ExtDirect') !== FALSE) {
256 $hasExtDirectRouter = TRUE;
257 break;
258 }
259 }
260 }
261 if ($hasExtDirectRouter) {
262 $this->pageRenderer->addJsFile('ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.Ajax.ExtDirect', NULL, FALSE);
263 }
264
265 $this->generateJavascript();
266 $this->pageRenderer->addJsInlineCode('BackendInlineJavascript', $this->js);
267
268
269 // set document title:
270 $title = ($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']
271 ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'].' [TYPO3 '.TYPO3_version.']'
272 : 'TYPO3 '.TYPO3_version
273 );
274
275 // start page header:
276 $this->content .= $GLOBALS['TBE_TEMPLATE']->startPage($title);
277 $this->content .= $backendScaffolding;
278 $this->content .= $GLOBALS['TBE_TEMPLATE']->endPage();
279
280 $hookConfiguration = array('content' => &$this->content);
281 $this->executeHook('renderPostProcess', $hookConfiguration);
282
283 echo $this->content;
284 }
285
286 /**
287 * renders the items in the top toolbar
288 *
289 * @return string top toolbar elements as HTML
290 */
291 protected function renderToolbar() {
292
293 // move search to last position
294 $search = $this->toolbarItems['backendSearch'];
295 unset($this->toolbarItems['backendSearch']);
296 $this->toolbarItems['backendSearch'] = $search;
297
298 $toolbar = '<ul id="typo3-toolbar">';
299 $toolbar.= '<li>'.$this->getLoggedInUserLabel().'</li>
300 <li><div id="logout-button" class="toolbar-item no-separator">'.$this->moduleMenu->renderLogoutButton().'</div></li>';
301
302 foreach($this->toolbarItems as $toolbarItem) {
303 $menu = $toolbarItem->render();
304 if ($menu) {
305 $additionalAttributes = $toolbarItem->getAdditionalAttributes();
306 $toolbar .= '<li' . $additionalAttributes . '>' .$menu. '</li>';
307 }
308 }
309
310 return $toolbar.'</ul>';
311 }
312
313 /**
314 * Gets the label of the BE user currently logged in
315 *
316 * @return string html code snippet displaying the currently logged in user
317 */
318 protected function getLoggedInUserLabel() {
319 global $BE_USER, $BACK_PATH;
320
321 $icon = t3lib_iconWorks::getSpriteIcon('status-user-'. ($BE_USER->isAdmin() ? 'admin' : 'backend'));
322
323 $label = $GLOBALS['BE_USER']->user['realName'] ?
324 $BE_USER->user['realName'] . ' (' . $BE_USER->user['username'] . ')' :
325 $BE_USER->user['username'];
326
327 // Link to user setup if it's loaded and user has access
328 $link = '';
329 if (t3lib_extMgm::isLoaded('setup') && $BE_USER->check('modules','user_setup')) {
330 $link = '<a href="#" onclick="top.goToModule(\'user_setup\');this.blur();return false;">';
331 }
332
333 $username = '">'.$link.$icon.'<span>'.htmlspecialchars($label).'</span>'.($link?'</a>':'');
334
335 // superuser mode
336 if($BE_USER->user['ses_backuserid']) {
337 $username = ' su-user">'.$icon.
338 '<span title="' . $GLOBALS['LANG']->getLL('switchtouser') . '">' .
339 $GLOBALS['LANG']->getLL('switchtousershort') . ' </span>' .
340 '<span>' . htmlspecialchars($label) . '</span>';
341 }
342
343 return '<div id="username" class="toolbar-item no-separator'.$username.'</div>';
344 }
345
346 /**
347 * Generates the JavaScript code for the backend.
348 *
349 * @return void
350 */
351 protected function generateJavascript() {
352
353 $pathTYPO3 = t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')).'/';
354 $goToModuleSwitch = $this->moduleMenu->getGotoModuleJavascript();
355 $moduleFramesHelper = implode(LF, $this->moduleMenu->getFsMod());
356
357 // If another page module was specified, replace the default Page module with the new one
358 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
359 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
360 if (!$GLOBALS['BE_USER']->check('modules', $pageModule)) {
361 $pageModule = '';
362 }
363
364 $menuFrameName = 'menu';
365 if($GLOBALS['BE_USER']->uc['noMenuMode'] === 'icons') {
366 $menuFrameName = 'topmenuFrame';
367 }
368
369 // determine security level from conf vars and default to super challenged
370 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) {
371 $this->loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'];
372 } else {
373 $this->loginSecurityLevel = 'superchallenged';
374 }
375
376 $t3Configuration = array(
377 'siteUrl' => t3lib_div::getIndpEnv('TYPO3_SITE_URL'),
378 'PATH_typo3' => $pathTYPO3,
379 'PATH_typo3_enc' => rawurlencode($pathTYPO3),
380 'username' => htmlspecialchars($GLOBALS['BE_USER']->user['username']),
381 'uniqueID' => t3lib_div::shortMD5(uniqid('')),
382 'securityLevel' => $this->loginSecurityLevel,
383 'TYPO3_mainDir' => TYPO3_mainDir,
384 'pageModule' => $pageModule,
385 'condensedMode' => $GLOBALS['BE_USER']->uc['condensedMode'] ? 1 : 0 ,
386 'inWorkspace' => $GLOBALS['BE_USER']->workspace !== 0 ? 1 : 0,
387 'workspaceFrontendPreviewEnabled' => $GLOBALS['BE_USER']->user['workspace_preview'] ? 1 : 0,
388 'veriCode' => $GLOBALS['BE_USER']->veriCode(),
389 'denyFileTypes' => PHP_EXTENSIONS_DEFAULT,
390 'moduleMenuWidth' => $this->menuWidth - 1,
391 'topBarHeight' => (isset($GLOBALS['TBE_STYLES']['dims']['topFrameH']) ? intval($GLOBALS['TBE_STYLES']['dims']['topFrameH']) : 30),
392 'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? intval($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) : FALSE,
393 'listModulePath' => t3lib_extMgm::isLoaded('list') ? t3lib_extMgm::extRelPath('list') . 'mod1/' : '',
394 );
395 $t3LLLcore = array(
396 'waitTitle' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_logging_in') ,
397 'refresh_login_failed' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed'),
398 'refresh_login_failed_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed_message'),
399 'refresh_login_title' => sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_title'), htmlspecialchars($GLOBALS['BE_USER']->user['username'])),
400 'login_expired' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_expired'),
401 'refresh_login_username' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_username'),
402 'refresh_login_password' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_password'),
403 'refresh_login_emptyPassword' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_emptyPassword'),
404 'refresh_login_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_button'),
405 'refresh_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_logout_button'),
406 'please_wait' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.please_wait'),
407 'be_locked' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.be_locked'),
408 'refresh_login_countdown_singular' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown_singular'),
409 'refresh_login_countdown' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown'),
410 'login_about_to_expire' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire'),
411 'login_about_to_expire_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire_title'),
412 'refresh_login_refresh_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_refresh_button'),
413 'refresh_direct_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_direct_logout_button'),
414 'tabs_closeAll' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeAll'),
415 'tabs_closeOther' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeOther'),
416 'tabs_close' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.close'),
417 'donateWindow_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.title'),
418 'donateWindow_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.message'),
419 'donateWindow_button_donate' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_donate'),
420 'donateWindow_button_disable' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_disable'),
421 'donateWindow_button_postpone' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_postpone'),
422 );
423 $t3LLLfileUpload = array(
424 'windowTitle' => $GLOBALS['LANG']->getLL('fileUpload_windowTitle'),
425 'buttonSelectFiles' => $GLOBALS['LANG']->getLL('fileUpload_buttonSelectFiles'),
426 'buttonCancelAll' => $GLOBALS['LANG']->getLL('fileUpload_buttonCancelAll'),
427 'infoComponentMaxFileSize' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentMaxFileSize'),
428 'infoComponentFileUploadLimit' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentFileUploadLimit'),
429 'infoComponentFileTypeLimit' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentFileTypeLimit'),
430 'infoComponentOverrideFiles' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentOverrideFiles'),
431 'processRunning' => $GLOBALS['LANG']->getLL('fileUpload_processRunning'),
432 'uploadWait' => $GLOBALS['LANG']->getLL('fileUpload_uploadWait'),
433 'uploadStarting' => $GLOBALS['LANG']->getLL('fileUpload_uploadStarting'),
434 'uploadProgress' => $GLOBALS['LANG']->getLL('fileUpload_uploadProgress'),
435 'uploadSuccess' => $GLOBALS['LANG']->getLL('fileUpload_uploadSuccess'),
436 'errorQueueLimitExceeded' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueLimitExceeded'),
437 'errorQueueFileSizeLimit' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueFileSizeLimit'),
438 'errorQueueZeroByteFile' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueZeroByteFile'),
439 'errorQueueInvalidFiletype' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueInvalidFiletype'),
440 'errorUploadHttp' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadHttpError'),
441 'errorUploadMissingUrl' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadMissingUrl'),
442 'errorUploadIO' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadIO'),
443 'errorUploadSecurityError' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadSecurityError'),
444 'errorUploadLimit' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadLimit'),
445 'errorUploadFailed' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFailed'),
446 'errorUploadFileIDNotFound' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileIDNotFound'),
447 'errorUploadFileValidation' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileValidation'),
448 'errorUploadFileCancelled' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileCancelled'),
449 'errorUploadStopped' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadStopped'),
450 'allErrorMessageTitle' => $GLOBALS['LANG']->getLL('fileUpload_allErrorMessageTitle'),
451 'allErrorMessageText' => $GLOBALS['LANG']->getLL('fileUpload_allErrorMessageText'),
452 'allError401' => $GLOBALS['LANG']->getLL('fileUpload_allError401'),
453 'allError2038' => $GLOBALS['LANG']->getLL('fileUpload_allError2038'),
454 );
455
456 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
457 if ($GLOBALS['LANG']->charSet !== 'utf-8') {
458 $t3Configuration['username'] = $GLOBALS['LANG']->csConvObj->conv($t3Configuration['username'], $GLOBALS['LANG']->charSet, 'utf-8');
459 $GLOBALS['LANG']->csConvObj->convArray($t3LLLcore, $GLOBALS['LANG']->charSet, 'utf-8');
460 $GLOBALS['LANG']->csConvObj->convArray($t3LLLfileUpload, $GLOBALS['LANG']->charSet, 'utf-8');
461 }
462
463 $this->js .= '
464 TYPO3.configuration = ' . json_encode($t3Configuration) . ';
465 TYPO3.LLL = {
466 core : ' . json_encode($t3LLLcore) . ',
467 fileUpload: ' . json_encode($t3LLLfileUpload) . '
468 };
469
470 /**
471 * TypoSetup object.
472 */
473 function typoSetup() { //
474 this.PATH_typo3 = TYPO3.configuration.PATH_typo3;
475 this.PATH_typo3_enc = TYPO3.configuration.PATH_typo3_enc;
476 this.username = TYPO3.configuration.username;
477 this.uniqueID = TYPO3.configuration.uniqueID;
478 this.navFrameWidth = 0;
479 this.securityLevel = TYPO3.configuration.securityLevel;
480 this.veriCode = TYPO3.configuration.veriCode;
481 this.denyFileTypes = TYPO3.configuration.denyFileTypes;
482 }
483 var TS = new typoSetup();
484
485 var currentModuleLoaded = "";
486
487 /**
488 * Frameset Module object
489 *
490 * Used in main modules with a frameset for submodules to keep the ID between modules
491 * Typically that is set by something like this in a Web>* sub module:
492 * if (top.fsMod) top.fsMod.recentIds["web"] = "\'.intval($this->id).\'";
493 * if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
494 */
495 function fsModules() { //
496 this.recentIds=new Array(); // used by frameset modules to track the most recent used id for list frame.
497 this.navFrameHighlightedID=new Array(); // used by navigation frames to track which row id was highlighted last time
498 this.currentMainLoaded="";
499 this.currentBank="0";
500 }
501 var fsMod = new fsModules();' . $moduleFramesHelper . ';';
502
503 // add goToModule code
504 $this->pageRenderer->addExtOnReadyCode('
505 top.goToModule = ' . $goToModuleSwitch . ';
506 ');
507
508 // Check editing of page:
509 $this->handlePageEditing();
510 $this->setStartupModule();
511 }
512
513 /**
514 * Checking if the "&edit" variable was sent so we can open it for editing the page.
515 * Code based on code from "alt_shortcut.php"
516 *
517 * @return void
518 */
519 protected function handlePageEditing() {
520
521 if(!t3lib_extMgm::isLoaded('cms')) {
522 return;
523 }
524
525 // EDIT page:
526 $editId = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('edit'));
527 $editRecord = '';
528
529 if($editId) {
530
531 // Looking up the page to edit, checking permissions:
532 $where = ' AND ('.$GLOBALS['BE_USER']->getPagePermsClause(2)
533 .' OR '.$GLOBALS['BE_USER']->getPagePermsClause(16).')';
534
535 if(t3lib_div::testInt($editId)) {
536 $editRecord = t3lib_BEfunc::getRecordWSOL('pages', $editId, '*', $where);
537 } else {
538 $records = t3lib_BEfunc::getRecordsByField('pages', 'alias', $editId, $where);
539
540 if(is_array($records)) {
541 reset($records);
542 $editRecord = current($records);
543 t3lib_BEfunc::workspaceOL('pages', $editRecord);
544 }
545 }
546
547 // If the page was accessible, then let the user edit it.
548 if(is_array($editRecord) && $GLOBALS['BE_USER']->isInWebMount($editRecord['uid'])) {
549 // Setting JS code to open editing:
550 $this->js .= '
551 // Load page to edit:
552 window.setTimeout("top.loadEditId('.intval($editRecord['uid']).');", 500);
553 ';
554 // Checking page edit parameter:
555 if(!$GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
556
557 // Expanding page tree:
558 t3lib_BEfunc::openPageTree(intval($editRecord['pid']), !$GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded'));
559 }
560 } else {
561 $this->js .= '
562 // Warning about page editing:
563 alert('.$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('noEditPage'), $editId)).');
564 ';
565 }
566 }
567 }
568
569 /**
570 * Sets the startup module from either GETvars module and mpdParams or user configuration.
571 *
572 * @return void
573 */
574 protected function setStartupModule() {
575 $startModule = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('module'));
576
577 if(!$startModule) {
578 if ($GLOBALS['BE_USER']->uc['startModule']) {
579 $startModule = $GLOBALS['BE_USER']->uc['startModule'];
580 } else if($GLOBALS['BE_USER']->uc['startInTaskCenter']) {
581 $startModule = 'user_task';
582 }
583 }
584
585 $moduleParameters = t3lib_div::_GET('modParams');
586 if($startModule) {
587 $this->pageRenderer->addExtOnReadyCode('
588 // start in module:
589 function startInModule(modName, cMR_flag, addGetVars) {
590 Ext.onReady(function() {
591 top.goToModule(modName, cMR_flag, addGetVars);
592 });
593 }
594
595 startInModule(\''.$startModule.'\', false, '.t3lib_div::quoteJSvalue($moduleParameters).');
596 ');
597 }
598 }
599
600 /**
601 * generates the code for the TYPO3 logo, either the default TYPO3 logo or a custom one
602 *
603 * @return string HTML code snippet to display the TYPO3 logo
604 */
605 protected function getLogo() {
606 $logo = '<a href="http://www.typo3.com/" target="_blank" onclick="'.$GLOBALS['TBE_TEMPLATE']->thisBlur().'">'.
607 '<img'.t3lib_iconWorks::skinImg('','gfx/alt_backend_logo.gif','width="117" height="32"').' title="TYPO3 Content Management Framework" alt="" />'.
608 '</a>';
609
610 // overwrite with custom logo
611 if($GLOBALS['TBE_STYLES']['logo']) {
612 if(substr($GLOBALS['TBE_STYLES']['logo'], 0, 3) == '../') {
613 $imgInfo = @getimagesize(PATH_site.substr($GLOBALS['TBE_STYLES']['logo'], 3));
614 }
615 $logo = '<a href="http://www.typo3.com/" target="_blank" onclick="'.$GLOBALS['TBE_TEMPLATE']->thisBlur().'">'.
616 '<img src="'.$GLOBALS['TBE_STYLES']['logo'].'" '.$imgInfo[3].' title="TYPO3 Content Management Framework" alt="" />'.
617 '</a>';
618 }
619
620 return $logo;
621 }
622
623 /**
624 * adds a javascript snippet to the backend
625 *
626 * @param string javascript snippet
627 * @return void
628 */
629 public function addJavascript($javascript) {
630 // TODO do we need more checks?
631 if(!is_string($javascript)) {
632 throw new InvalidArgumentException('parameter $javascript must be of type string', 1195129553);
633 }
634
635 $this->js .= $javascript;
636 }
637
638 /**
639 * adds a javscript file to the backend after it has been checked that it exists
640 *
641 * @param string javascript file reference
642 * @return boolean true if the javascript file was successfully added, false otherwise
643 */
644 public function addJavascriptFile($javascriptFile) {
645 $jsFileAdded = false;
646
647 //TODO add more checks if neccessary
648 if(file_exists(t3lib_div::resolveBackPath(PATH_typo3.$javascriptFile))) {
649 $this->jsFiles[] = $javascriptFile;
650 $jsFileAdded = true;
651 }
652
653 return $jsFileAdded;
654 }
655
656 /**
657 * adds a css snippet to the backend
658 *
659 * @param string css snippet
660 * @return void
661 */
662 public function addCss($css) {
663 if(!is_string($css)) {
664 throw new InvalidArgumentException('parameter $css must be of type string', 1195129642);
665 }
666
667 $this->css .= $css;
668 }
669
670 /**
671 * adds a css file to the backend after it has been checked that it exists
672 *
673 * @param string the css file's name with out the .css ending
674 * @param string css file reference
675 * @return boolean true if the css file was added, false otherwise
676 */
677 public function addCssFile($cssFileName, $cssFile) {
678 $cssFileAdded = false;
679
680 if(empty($this->cssFiles[$cssFileName])) {
681 $this->cssFiles[$cssFileName] = $cssFile;
682 $cssFileAdded = true;
683 }
684
685 return $cssFileAdded;
686 }
687
688 /**
689 * adds an item to the toolbar, the class file for the toolbar item must be loaded at this point
690 *
691 * @param string toolbar item name, f.e. tx_toolbarExtension_coolItem
692 * @param string toolbar item class name, f.e. tx_toolbarExtension_coolItem
693 * @return void
694 */
695 public function addToolbarItem($toolbarItemName, $toolbarItemClassName) {
696 $toolbarItem = t3lib_div::makeInstance($toolbarItemClassName, $this);
697
698 if(!($toolbarItem instanceof backend_toolbarItem)) {
699 throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195125501);
700 }
701
702 if($toolbarItem->checkAccess()) {
703 $this->toolbarItems[$toolbarItemName] = $toolbarItem;
704 } else {
705 unset($toolbarItem);
706 }
707 }
708
709 /**
710 * Executes defined hooks functions for the given identifier.
711 *
712 * These hook identifiers are valid:
713 * + constructPostProcess
714 * + renderPreProcess
715 * + renderPostProcess
716 *
717 * @param string $identifier Specific hook identifier
718 * @param array $hookConfiguration Additional configuration passed to hook functions
719 * @return void
720 */
721 protected function executeHook($identifier, array $hookConfiguration = array()) {
722 $options =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/backend.php'];
723
724 if(isset($options[$identifier]) && is_array($options[$identifier])) {
725 foreach($options[$identifier] as $hookFunction) {
726 t3lib_div::callUserFunction($hookFunction, $hookConfiguration, $this);
727 }
728 }
729 }
730 }
731
732
733 // include XCLASS
734 if(defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']) {
735 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']);
736 }
737
738
739 // document generation
740 $TYPO3backend = t3lib_div::makeInstance('TYPO3backend');
741
742 // include extensions which may add css, javascript or toolbar items
743 if(is_array($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'])) {
744 foreach($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'] as $additionalBackendItem) {
745 include_once($additionalBackendItem);
746 }
747 }
748
749 $TYPO3backend->render();
750
751 ?>