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