Added feature #14490: A new skin for the TYPO3 Backend (Thanks to Steffen Gebert...
[Packages/TYPO3.CMS.git] / typo3 / backend.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2007-2009 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
153 /**
154 * initializes the core toolbar items
155 *
156 * @return void
157 */
158 protected function initializeCoreToolbarItems() {
159
160 $coreToolbarItems = array(
161 'workspaceSelector' => 'WorkspaceSelector',
162 'shortcuts' => 'ShortcutMenu',
163 'clearCacheActions' => 'ClearCacheMenu',
164 'backendSearch' => 'BackendSearchMenu'
165 );
166
167 foreach($coreToolbarItems as $toolbarItemName => $toolbarItemClassName) {
168 $toolbarItem = t3lib_div::makeInstance($toolbarItemClassName, $this);
169
170 if(!($toolbarItem instanceof backend_toolbarItem)) {
171 throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195126772);
172 }
173
174 if($toolbarItem->checkAccess()) {
175 $this->toolbarItems[$toolbarItemName] = $toolbarItem;
176 } else {
177 unset($toolbarItem);
178 }
179 }
180 }
181
182 /**
183 * main function generating the BE scaffolding
184 *
185 * @return void
186 */
187 public function render() {
188
189 if (t3lib_div::makeInstance('DonateWindow')->isDonateWindowAllowed()) {
190 $this->pageRenderer->addJsFile('js/donate.js');
191 }
192
193 // prepare the scaffolding, at this point extension may still add javascript and css
194 $logo = t3lib_div::makeInstance('TYPO3Logo');
195 $logo->setLogo('gfx/typo3logo_mini.png');
196
197 $menu = $this->moduleMenu->render();
198
199 if ($this->menuWidth != $this->menuWidthDefault) {
200 $this->css .= '
201 #typo3-top {
202 margin-left: ' . $this->menuWidth . 'px;
203 }
204 ';
205 }
206
207 // create backend scaffolding
208 $backendScaffolding = '
209 <div id="typo3-backend">
210 <div id="typo3-top-container" class="x-hide-display">
211 <div id="typo3-logo">'.$logo->render().'</div>
212 <div id="typo3-top" class="typo3-top-toolbar">' .
213 $this->renderToolbar() .
214 '</div>
215 </div>
216 <div id="typo3-main-container">
217 <div id="typo3-side-menu" class="x-hide-display">' .
218 $menu .
219 '</div>
220 <div id="typo3-content" class="x-hide-display">
221 <iframe src="alt_intro.php" name="content" id="content" marginwidth="0" marginheight="0" frameborder="0" scrolling="auto"></iframe>
222 </div>
223 </div>
224 </div>
225 ';
226
227 /******************************************************
228 * now put the complete backend document together
229 ******************************************************/
230
231 foreach($this->cssFiles as $cssFileName => $cssFile) {
232 $this->pageRenderer->addCssFile($cssFile);
233
234 // load addditional css files to overwrite existing core styles
235 if(!empty($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName])) {
236 $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName]);
237 }
238 }
239
240 if(!empty($this->css)) {
241 $this->pageRenderer->addCssInlineBlock('BackendInlineCSS', $this->css);
242 }
243
244 foreach ($this->jsFiles as $jsFile) {
245 $this->pageRenderer->addJsFile($jsFile);
246 }
247 // we mustn't compress this file
248 $this->pageRenderer->addJsFile('ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.Backend', NULL, FALSE);
249
250 $this->generateJavascript();
251 $this->pageRenderer->addJsInlineCode('BackendInlineJavascript', $this->js);
252
253
254 // set document title:
255 $title = ($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']
256 ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'].' [TYPO3 '.TYPO3_version.']'
257 : 'TYPO3 '.TYPO3_version
258 );
259
260 // start page header:
261 $this->content .= $GLOBALS['TBE_TEMPLATE']->startPage($title);
262 $this->content .= $backendScaffolding;
263 $this->content .= $GLOBALS['TBE_TEMPLATE']->endPage();
264
265 echo $this->content;
266 }
267
268 /**
269 * renders the items in the top toolbar
270 *
271 * @return string top toolbar elements as HTML
272 */
273 protected function renderToolbar() {
274
275 // move search to last position
276 $search = $this->toolbarItems['backendSearch'];
277 unset($this->toolbarItems['backendSearch']);
278 $this->toolbarItems['backendSearch'] = $search;
279
280 $toolbar = '<ul id="typo3-toolbar">';
281 $toolbar.= '<li>'.$this->getLoggedInUserLabel().'</li>
282 <li><div id="logout-button" class="toolbar-item no-separator">'.$this->moduleMenu->renderLogoutButton().'</div></li>';
283
284 foreach($this->toolbarItems as $toolbarItem) {
285 $menu = $toolbarItem->render();
286 if ($menu) {
287 $additionalAttributes = $toolbarItem->getAdditionalAttributes();
288 $toolbar .= '<li' . $additionalAttributes . '>' .$menu. '</li>';
289 }
290 }
291
292 return $toolbar.'</ul>';
293 }
294
295 /**
296 * Gets the label of the BE user currently logged in
297 *
298 * @return string html code snippet displaying the currently logged in user
299 */
300 protected function getLoggedInUserLabel() {
301 global $BE_USER, $BACK_PATH;
302
303 $icon = t3lib_iconWorks::getSpriteIcon('status-user-'. ($BE_USER->isAdmin() ? 'admin' : 'backend'));
304
305 $label = $GLOBALS['BE_USER']->user['realName'] ?
306 $BE_USER->user['realName'] . ' (' . $BE_USER->user['username'] . ')' :
307 $BE_USER->user['username'];
308
309 // Link to user setup if it's loaded and user has access
310 $link = '';
311 if (t3lib_extMgm::isLoaded('setup') && $BE_USER->check('modules','user_setup')) {
312 $link = '<a href="#" onclick="top.goToModule(\'user_setup\');this.blur();return false;">';
313 }
314
315 $username = '">'.$link.$icon.'<span>'.htmlspecialchars($label).'</span>'.($link?'</a>':'');
316
317 // superuser mode
318 if($BE_USER->user['ses_backuserid']) {
319 $username = ' su-user">'.$icon.
320 '<span title="' . $GLOBALS['LANG']->getLL('switchtouser') . '">' .
321 $GLOBALS['LANG']->getLL('switchtousershort') . ' </span>' .
322 '<span>' . htmlspecialchars($label) . '</span>';
323 }
324
325 return '<div id="username" class="toolbar-item no-separator'.$username.'</div>';
326 }
327
328 /**
329 * Generates the JavaScript code for the backend.
330 *
331 * @return void
332 */
333 protected function generateJavascript() {
334
335 $pathTYPO3 = t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')).'/';
336 $goToModuleSwitch = $this->moduleMenu->getGotoModuleJavascript();
337 $moduleFramesHelper = implode(LF, $this->moduleMenu->getFsMod());
338
339 // If another page module was specified, replace the default Page module with the new one
340 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
341 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
342
343 $menuFrameName = 'menu';
344 if($GLOBALS['BE_USER']->uc['noMenuMode'] === 'icons') {
345 $menuFrameName = 'topmenuFrame';
346 }
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 $t3Configuration = array(
356 'siteUrl' => t3lib_div::getIndpEnv('TYPO3_SITE_URL'),
357 'PATH_typo3' => $pathTYPO3,
358 'PATH_typo3_enc' => rawurlencode($pathTYPO3),
359 'username' => htmlspecialchars($GLOBALS['BE_USER']->user['username']),
360 'uniqueID' => t3lib_div::shortMD5(uniqid('')),
361 'securityLevel' => $this->loginSecurityLevel,
362 'TYPO3_mainDir' => TYPO3_mainDir,
363 'pageModule' => $pageModule,
364 'condensedMode' => $GLOBALS['BE_USER']->uc['condensedMode'] ? 1 : 0 ,
365 'inWorkspace' => $GLOBALS['BE_USER']->workspace !== 0 ? 1 : 0,
366 'workspaceFrontendPreviewEnabled' => $GLOBALS['BE_USER']->user['workspace_preview'] ? 1 : 0,
367 'veriCode' => $GLOBALS['BE_USER']->veriCode(),
368 'denyFileTypes' => PHP_EXTENSIONS_DEFAULT,
369 'moduleMenuWidth' => $this->menuWidth - 1,
370 'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? intval($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) : FALSE,
371 );
372 $t3LLLcore = array(
373 'waitTitle' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_logging_in') ,
374 'refresh_login_failed' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed'),
375 'refresh_login_failed_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed_message'),
376 'refresh_login_title' => sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_title'), htmlspecialchars($GLOBALS['BE_USER']->user['username'])),
377 'login_expired' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_expired'),
378 'refresh_login_username' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_username'),
379 'refresh_login_password' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_password'),
380 'refresh_login_emptyPassword' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_emptyPassword'),
381 'refresh_login_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_button'),
382 'refresh_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_logout_button'),
383 'please_wait' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.please_wait'),
384 'be_locked' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.be_locked'),
385 'refresh_login_countdown_singular' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown_singular'),
386 'refresh_login_countdown' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown'),
387 'login_about_to_expire' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire'),
388 'login_about_to_expire_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire_title'),
389 'refresh_login_refresh_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_refresh_button'),
390 'refresh_direct_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_direct_logout_button'),
391 'tabs_closeAll' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeAll'),
392 'tabs_closeOther' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeOther'),
393 'tabs_close' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.close'),
394 'donateWindow_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.title'),
395 'donateWindow_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.message'),
396 'donateWindow_button_donate' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_donate'),
397 'donateWindow_button_disable' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_disable'),
398 'donateWindow_button_postpone' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_postpone'),
399 );
400 $t3LLLfileUpload = array(
401 'windowTitle' => $GLOBALS['LANG']->getLL('fileUpload_windowTitle'),
402 'buttonSelectFiles' => $GLOBALS['LANG']->getLL('fileUpload_buttonSelectFiles'),
403 'buttonCancelAll' => $GLOBALS['LANG']->getLL('fileUpload_buttonCancelAll'),
404 'infoComponentMaxFileSize' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentMaxFileSize'),
405 'infoComponentFileUploadLimit' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentFileUploadLimit'),
406 'infoComponentFileTypeLimit' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentFileTypeLimit'),
407 'infoComponentOverrideFiles' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentOverrideFiles'),
408 'processRunning' => $GLOBALS['LANG']->getLL('fileUpload_processRunning'),
409 'uploadWait' => $GLOBALS['LANG']->getLL('fileUpload_uploadWait'),
410 'uploadStarting' => $GLOBALS['LANG']->getLL('fileUpload_uploadStarting'),
411 'uploadProgress' => $GLOBALS['LANG']->getLL('fileUpload_uploadProgress'),
412 'uploadSuccess' => $GLOBALS['LANG']->getLL('fileUpload_uploadSuccess'),
413 'errorQueueLimitExceeded' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueLimitExceeded'),
414 'errorQueueFileSizeLimit' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueFileSizeLimit'),
415 'errorQueueZeroByteFile' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueZeroByteFile'),
416 'errorQueueInvalidFiletype' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueInvalidFiletype'),
417 'errorUploadHttp' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadHttpError'),
418 'errorUploadMissingUrl' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadMissingUrl'),
419 'errorUploadIO' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadIO'),
420 'errorUploadSecurityError' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadSecurityError'),
421 'errorUploadLimit' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadLimit'),
422 'errorUploadFailed' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFailed'),
423 'errorUploadFileIDNotFound' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileIDNotFound'),
424 'errorUploadFileValidation' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileValidation'),
425 'errorUploadFileCancelled' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileCancelled'),
426 'errorUploadStopped' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadStopped'),
427 'allErrorMessageTitle' => $GLOBALS['LANG']->getLL('fileUpload_allErrorMessageTitle'),
428 'allErrorMessageText' => $GLOBALS['LANG']->getLL('fileUpload_allErrorMessageText'),
429 'allError401' => $GLOBALS['LANG']->getLL('fileUpload_allError401'),
430 'allError2038' => $GLOBALS['LANG']->getLL('fileUpload_allError2038'),
431 );
432
433 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
434 if ($GLOBALS['LANG']->charSet !== 'utf-8') {
435 $t3Configuration['username'] = $GLOBALS['LANG']->csConvObj->conv($t3Configuration['username'], $GLOBALS['LANG']->charSet, 'utf-8');
436 $GLOBALS['LANG']->csConvObj->convArray($t3LLLcore, $GLOBALS['LANG']->charSet, 'utf-8');
437 $GLOBALS['LANG']->csConvObj->convArray($t3LLLfileUpload, $GLOBALS['LANG']->charSet, 'utf-8');
438 }
439
440 $this->js .= '
441 TYPO3.configuration = ' . json_encode($t3Configuration) . ';
442 TYPO3.LLL = {
443 core : ' . json_encode($t3LLLcore) . ',
444 fileUpload: ' . json_encode($t3LLLfileUpload) . '
445 };
446
447 /**
448 * TypoSetup object.
449 */
450 function typoSetup() { //
451 this.PATH_typo3 = TYPO3.configuration.PATH_typo3;
452 this.PATH_typo3_enc = TYPO3.configuration.PATH_typo3_enc;
453 this.username = TYPO3.configuration.username;
454 this.uniqueID = TYPO3.configuration.uniqueID;
455 this.navFrameWidth = 0;
456 this.securityLevel = TYPO3.configuration.securityLevel;
457 this.veriCode = TYPO3.configuration.veriCode;
458 this.denyFileTypes = TYPO3.configuration.denyFileTypes;
459 }
460 var TS = new typoSetup();
461
462 var currentModuleLoaded = "";
463
464 /**
465 * Frameset Module object
466 *
467 * Used in main modules with a frameset for submodules to keep the ID between modules
468 * Typically that is set by something like this in a Web>* sub module:
469 * if (top.fsMod) top.fsMod.recentIds["web"] = "\'.intval($this->id).\'";
470 * if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
471 */
472 function fsModules() { //
473 this.recentIds=new Array(); // used by frameset modules to track the most recent used id for list frame.
474 this.navFrameHighlightedID=new Array(); // used by navigation frames to track which row id was highlighted last time
475 this.currentMainLoaded="";
476 this.currentBank="0";
477 }
478 var fsMod = new fsModules();' . $moduleFramesHelper . ';';
479
480 // add goToModule code
481 $pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
482 $pageRenderer->addExtOnReadyCode('
483 top.goToModule = ' . $goToModuleSwitch . ';
484 ');
485
486 // Check editing of page:
487 $this->handlePageEditing();
488 $this->setStartupModule();
489 }
490
491 /**
492 * Checking if the "&edit" variable was sent so we can open it for editing the page.
493 * Code based on code from "alt_shortcut.php"
494 *
495 * @return void
496 */
497 protected function handlePageEditing() {
498
499 if(!t3lib_extMgm::isLoaded('cms')) {
500 return;
501 }
502
503 // EDIT page:
504 $editId = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('edit'));
505 $editRecord = '';
506
507 if($editId) {
508
509 // Looking up the page to edit, checking permissions:
510 $where = ' AND ('.$GLOBALS['BE_USER']->getPagePermsClause(2)
511 .' OR '.$GLOBALS['BE_USER']->getPagePermsClause(16).')';
512
513 if(t3lib_div::testInt($editId)) {
514 $editRecord = t3lib_BEfunc::getRecordWSOL('pages', $editId, '*', $where);
515 } else {
516 $records = t3lib_BEfunc::getRecordsByField('pages', 'alias', $editId, $where);
517
518 if(is_array($records)) {
519 reset($records);
520 $editRecord = current($records);
521 t3lib_BEfunc::workspaceOL('pages', $editRecord);
522 }
523 }
524
525 // If the page was accessible, then let the user edit it.
526 if(is_array($editRecord) && $GLOBALS['BE_USER']->isInWebMount($editRecord['uid'])) {
527 // Setting JS code to open editing:
528 $this->js .= '
529 // Load page to edit:
530 window.setTimeout("top.loadEditId('.intval($editRecord['uid']).');", 500);
531 ';
532 // Checking page edit parameter:
533 if(!$GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
534
535 // Expanding page tree:
536 t3lib_BEfunc::openPageTree(intval($editRecord['pid']), !$GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded'));
537 }
538 } else {
539 $this->js .= '
540 // Warning about page editing:
541 alert('.$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('noEditPage'), $editId)).');
542 ';
543 }
544 }
545 }
546
547 /**
548 * Sets the startup module from either GETvars module and mpdParams or user configuration.
549 *
550 * @return void
551 */
552 protected function setStartupModule() {
553 $startModule = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('module'));
554
555 if(!$startModule) {
556 if ($GLOBALS['BE_USER']->uc['startModule']) {
557 $startModule = $GLOBALS['BE_USER']->uc['startModule'];
558 } else if($GLOBALS['BE_USER']->uc['startInTaskCenter']) {
559 $startModule = 'user_task';
560 }
561 }
562
563 $moduleParameters = t3lib_div::_GET('modParams');
564 if($startModule) {
565 $pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
566 $pageRenderer->addExtOnReadyCode('
567 // start in module:
568 function startInModule(modName, cMR_flag, addGetVars) {
569 Ext.onReady(function() {
570 top.goToModule(modName, cMR_flag, addGetVars);
571 });
572 }
573
574 startInModule(\''.$startModule.'\', false, '.t3lib_div::quoteJSvalue($moduleParameters).');
575 ');
576 }
577 }
578
579 /**
580 * generates the code for the TYPO3 logo, either the default TYPO3 logo or a custom one
581 *
582 * @return string HTML code snippet to display the TYPO3 logo
583 */
584 protected function getLogo() {
585 $logo = '<a href="http://www.typo3.com/" target="_blank" onclick="'.$GLOBALS['TBE_TEMPLATE']->thisBlur().'">'.
586 '<img'.t3lib_iconWorks::skinImg('','gfx/alt_backend_logo.gif','width="117" height="32"').' title="TYPO3 Content Management Framework" alt="" />'.
587 '</a>';
588
589 // overwrite with custom logo
590 if($GLOBALS['TBE_STYLES']['logo']) {
591 if(substr($GLOBALS['TBE_STYLES']['logo'], 0, 3) == '../') {
592 $imgInfo = @getimagesize(PATH_site.substr($GLOBALS['TBE_STYLES']['logo'], 3));
593 }
594 $logo = '<a href="http://www.typo3.com/" target="_blank" onclick="'.$GLOBALS['TBE_TEMPLATE']->thisBlur().'">'.
595 '<img src="'.$GLOBALS['TBE_STYLES']['logo'].'" '.$imgInfo[3].' title="TYPO3 Content Management Framework" alt="" />'.
596 '</a>';
597 }
598
599 return $logo;
600 }
601
602 /**
603 * adds a javascript snippet to the backend
604 *
605 * @param string javascript snippet
606 * @return void
607 */
608 public function addJavascript($javascript) {
609 // TODO do we need more checks?
610 if(!is_string($javascript)) {
611 throw new InvalidArgumentException('parameter $javascript must be of type string', 1195129553);
612 }
613
614 $this->js .= $javascript;
615 }
616
617 /**
618 * adds a javscript file to the backend after it has been checked that it exists
619 *
620 * @param string javascript file reference
621 * @return boolean true if the javascript file was successfully added, false otherwise
622 */
623 public function addJavascriptFile($javascriptFile) {
624 $jsFileAdded = false;
625
626 //TODO add more checks if neccessary
627 if(file_exists(t3lib_div::resolveBackPath(PATH_typo3.$javascriptFile))) {
628 $this->jsFiles[] = $javascriptFile;
629 $jsFileAdded = true;
630 }
631
632 return $jsFileAdded;
633 }
634
635 /**
636 * adds a css snippet to the backend
637 *
638 * @param string css snippet
639 * @return void
640 */
641 public function addCss($css) {
642 if(!is_string($css)) {
643 throw new InvalidArgumentException('parameter $css must be of type string', 1195129642);
644 }
645
646 $this->css .= $css;
647 }
648
649 /**
650 * adds a css file to the backend after it has been checked that it exists
651 *
652 * @param string the css file's name with out the .css ending
653 * @param string css file reference
654 * @return boolean true if the css file was added, false otherwise
655 */
656 public function addCssFile($cssFileName, $cssFile) {
657 $cssFileAdded = false;
658
659 if(empty($this->cssFiles[$cssFileName])) {
660 $this->cssFiles[$cssFileName] = $cssFile;
661 $cssFileAdded = true;
662 }
663
664 return $cssFileAdded;
665 }
666
667 /**
668 * adds an item to the toolbar, the class file for the toolbar item must be loaded at this point
669 *
670 * @param string toolbar item name, f.e. tx_toolbarExtension_coolItem
671 * @param string toolbar item class name, f.e. tx_toolbarExtension_coolItem
672 * @return void
673 */
674 public function addToolbarItem($toolbarItemName, $toolbarItemClassName) {
675 $toolbarItem = t3lib_div::makeInstance($toolbarItemClassName, $this);
676
677 if(!($toolbarItem instanceof backend_toolbarItem)) {
678 throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195125501);
679 }
680
681 if($toolbarItem->checkAccess()) {
682 $this->toolbarItems[$toolbarItemName] = $toolbarItem;
683 } else {
684 unset($toolbarItem);
685 }
686 }
687 }
688
689
690 // include XCLASS
691 if(defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']) {
692 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']);
693 }
694
695
696 // document generation
697 $TYPO3backend = t3lib_div::makeInstance('TYPO3backend');
698
699 // include extensions which may add css, javascript or toolbar items
700 if(is_array($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'])) {
701 foreach($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'] as $additionalBackendItem) {
702 include_once($additionalBackendItem);
703 }
704 }
705
706 $TYPO3backend->render();
707
708 ?>