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