Added Feature #13799: ExtJS driven fading in/out Flashmessages
[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 'workspaceFrontendPreviewEnabled' => $GLOBALS['BE_USER']->workspace != 0 && !$GLOBALS['BE_USER']->user['workspace_preview'] ? 0 : 1,
369 'veriCode' => $GLOBALS['BE_USER']->veriCode(),
370 'denyFileTypes' => PHP_EXTENSIONS_DEFAULT,
371 'moduleMenuWidth' => $this->menuWidth - 1,
372 'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? intval($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) : FALSE,
373 );
374 $t3LLLcore = array(
375 'waitTitle' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_logging_in') ,
376 'refresh_login_failed' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed'),
377 'refresh_login_failed_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed_message'),
378 'refresh_login_title' => sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_title'), htmlspecialchars($GLOBALS['BE_USER']->user['username'])),
379 'login_expired' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_expired'),
380 'refresh_login_username' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_username'),
381 'refresh_login_password' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_password'),
382 'refresh_login_emptyPassword' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_emptyPassword'),
383 'refresh_login_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_button'),
384 'refresh_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_logout_button'),
385 'please_wait' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.please_wait'),
386 'be_locked' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.be_locked'),
387 'refresh_login_countdown_singular' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown_singular'),
388 'refresh_login_countdown' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown'),
389 'login_about_to_expire' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire'),
390 'login_about_to_expire_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire_title'),
391 'refresh_login_refresh_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_refresh_button'),
392 'refresh_direct_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_direct_logout_button'),
393 );
394 $t3LLLfileUpload = array(
395 'windowTitle' => $GLOBALS['LANG']->getLL('fileUpload_windowTitle'),
396 'buttonSelectFiles' => $GLOBALS['LANG']->getLL('fileUpload_buttonSelectFiles'),
397 'buttonCancelAll' => $GLOBALS['LANG']->getLL('fileUpload_buttonCancelAll'),
398 'infoComponentMaxFileSize' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentMaxFileSize'),
399 'infoComponentFileUploadLimit' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentFileUploadLimit'),
400 'infoComponentFileTypeLimit' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentFileTypeLimit'),
401 'infoComponentOverrideFiles' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentOverrideFiles'),
402 'processRunning' => $GLOBALS['LANG']->getLL('fileUpload_processRunning'),
403 'uploadWait' => $GLOBALS['LANG']->getLL('fileUpload_uploadWait'),
404 'uploadStarting' => $GLOBALS['LANG']->getLL('fileUpload_uploadStarting'),
405 'uploadProgress' => $GLOBALS['LANG']->getLL('fileUpload_uploadProgress'),
406 'uploadSuccess' => $GLOBALS['LANG']->getLL('fileUpload_uploadSuccess'),
407 'errorQueueLimitExceeded' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueLimitExceeded'),
408 'errorQueueFileSizeLimit' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueFileSizeLimit'),
409 'errorQueueZeroByteFile' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueZeroByteFile'),
410 'errorQueueInvalidFiletype' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueInvalidFiletype'),
411 'errorUploadHttp' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadHttpError'),
412 'errorUploadMissingUrl' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadMissingUrl'),
413 'errorUploadIO' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadIO'),
414 'errorUploadSecurityError' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadSecurityError'),
415 'errorUploadLimit' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadLimit'),
416 'errorUploadFailed' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFailed'),
417 'errorUploadFileIDNotFound' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileIDNotFound'),
418 'errorUploadFileValidation' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileValidation'),
419 'errorUploadFileCancelled' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileCancelled'),
420 'errorUploadStopped' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadStopped'),
421 'allErrorMessageTitle' => $GLOBALS['LANG']->getLL('fileUpload_allErrorMessageTitle'),
422 'allErrorMessageText' => $GLOBALS['LANG']->getLL('fileUpload_allErrorMessageText'),
423 'allError401' => $GLOBALS['LANG']->getLL('fileUpload_allError401'),
424 'allError2038' => $GLOBALS['LANG']->getLL('fileUpload_allError2038'),
425 );
426
427 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
428 if ($GLOBALS['LANG']->charSet !== 'utf-8') {
429 $t3Configuration['username'] = $GLOBALS['LANG']->csConvObj->conv($t3Configuration['username'], $GLOBALS['LANG']->charSet, 'utf-8');
430 $GLOBALS['LANG']->csConvObj->convArray($t3LLLcore, $GLOBALS['LANG']->charSet, 'utf-8');
431 $GLOBALS['LANG']->csConvObj->convArray($t3LLLfileUpload, $GLOBALS['LANG']->charSet, 'utf-8');
432 }
433
434 $this->js .= '
435 TYPO3.configuration = ' . json_encode($t3Configuration) . ';
436 TYPO3.LLL = {
437 core : ' . json_encode($t3LLLcore) . ',
438 fileUpload: ' . json_encode($t3LLLfileUpload) . '
439 };
440
441 /**
442 * TypoSetup object.
443 */
444 function typoSetup() { //
445 this.PATH_typo3 = TYPO3.configuration.PATH_typo3;
446 this.PATH_typo3_enc = TYPO3.configuration.PATH_typo3_enc;
447 this.username = TYPO3.configuration.username;
448 this.uniqueID = TYPO3.configuration.uniqueID;
449 this.navFrameWidth = 0;
450 this.securityLevel = TYPO3.configuration.securityLevel;
451 this.veriCode = TYPO3.configuration.veriCode;
452 this.denyFileTypes = TYPO3.configuration.denyFileTypes;
453 }
454 var TS = new typoSetup();
455
456 var currentModuleLoaded = "";
457
458 /**
459 * Frameset Module object
460 *
461 * Used in main modules with a frameset for submodules to keep the ID between modules
462 * Typically that is set by something like this in a Web>* sub module:
463 * if (top.fsMod) top.fsMod.recentIds["web"] = "\'.intval($this->id).\'";
464 * if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
465 */
466 function fsModules() { //
467 this.recentIds=new Array(); // used by frameset modules to track the most recent used id for list frame.
468 this.navFrameHighlightedID=new Array(); // used by navigation frames to track which row id was highlighted last time
469 this.currentMainLoaded="";
470 this.currentBank="0";
471 }
472 var fsMod = new fsModules();' . $moduleFramesHelper . ';';
473
474 // add goToModule code
475 $pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
476 $pageRenderer->addExtOnReadyCode('
477 top.goToModule = ' . $goToModuleSwitch . ';
478 ');
479
480 // Check editing of page:
481 $this->handlePageEditing();
482 $this->setStartupModule();
483 }
484
485 /**
486 * Checking if the "&edit" variable was sent so we can open it for editing the page.
487 * Code based on code from "alt_shortcut.php"
488 *
489 * @return void
490 */
491 protected function handlePageEditing() {
492
493 if(!t3lib_extMgm::isLoaded('cms')) {
494 return;
495 }
496
497 // EDIT page:
498 $editId = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('edit'));
499 $editRecord = '';
500
501 if($editId) {
502
503 // Looking up the page to edit, checking permissions:
504 $where = ' AND ('.$GLOBALS['BE_USER']->getPagePermsClause(2)
505 .' OR '.$GLOBALS['BE_USER']->getPagePermsClause(16).')';
506
507 if(t3lib_div::testInt($editId)) {
508 $editRecord = t3lib_BEfunc::getRecordWSOL('pages', $editId, '*', $where);
509 } else {
510 $records = t3lib_BEfunc::getRecordsByField('pages', 'alias', $editId, $where);
511
512 if(is_array($records)) {
513 reset($records);
514 $editRecord = current($records);
515 t3lib_BEfunc::workspaceOL('pages', $editRecord);
516 }
517 }
518
519 // If the page was accessible, then let the user edit it.
520 if(is_array($editRecord) && $GLOBALS['BE_USER']->isInWebMount($editRecord['uid'])) {
521 // Setting JS code to open editing:
522 $this->js .= '
523 // Load page to edit:
524 window.setTimeout("top.loadEditId('.intval($editRecord['uid']).');", 500);
525 ';
526 // Checking page edit parameter:
527 if(!$GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
528
529 // Expanding page tree:
530 t3lib_BEfunc::openPageTree(intval($editRecord['pid']), !$GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded'));
531 }
532 } else {
533 $this->js .= '
534 // Warning about page editing:
535 alert('.$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('noEditPage'), $editId)).');
536 ';
537 }
538 }
539 }
540
541 /**
542 * Sets the startup module from either GETvars module and mpdParams or user configuration.
543 *
544 * @return void
545 */
546 protected function setStartupModule() {
547 $startModule = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('module'));
548
549 if(!$startModule) {
550 if ($GLOBALS['BE_USER']->uc['startModule']) {
551 $startModule = $GLOBALS['BE_USER']->uc['startModule'];
552 } else if($GLOBALS['BE_USER']->uc['startInTaskCenter']) {
553 $startModule = 'user_task';
554 }
555 }
556
557 $moduleParameters = t3lib_div::_GET('modParams');
558 if($startModule) {
559 $pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
560 $pageRenderer->addExtOnReadyCode('
561 // start in module:
562 function startInModule(modName, cMR_flag, addGetVars) {
563 Event.observe(document, \'dom:loaded\', function() {
564 top.goToModule(modName, cMR_flag, addGetVars);
565 });
566 }
567
568 startInModule(\''.$startModule.'\', false, '.t3lib_div::quoteJSvalue($moduleParameters).');
569 ');
570 }
571 }
572
573 /**
574 * generates the code for the TYPO3 logo, either the default TYPO3 logo or a custom one
575 *
576 * @return string HTML code snippet to display the TYPO3 logo
577 */
578 protected function getLogo() {
579 $logo = '<a href="http://www.typo3.com/" target="_blank" onclick="'.$GLOBALS['TBE_TEMPLATE']->thisBlur().'">'.
580 '<img'.t3lib_iconWorks::skinImg('','gfx/alt_backend_logo.gif','width="117" height="32"').' title="TYPO3 Content Management Framework" alt="" />'.
581 '</a>';
582
583 // overwrite with custom logo
584 if($GLOBALS['TBE_STYLES']['logo']) {
585 if(substr($GLOBALS['TBE_STYLES']['logo'], 0, 3) == '../') {
586 $imgInfo = @getimagesize(PATH_site.substr($GLOBALS['TBE_STYLES']['logo'], 3));
587 }
588 $logo = '<a href="http://www.typo3.com/" target="_blank" onclick="'.$GLOBALS['TBE_TEMPLATE']->thisBlur().'">'.
589 '<img src="'.$GLOBALS['TBE_STYLES']['logo'].'" '.$imgInfo[3].' title="TYPO3 Content Management Framework" alt="" />'.
590 '</a>';
591 }
592
593 return $logo;
594 }
595
596 /**
597 * adds a javascript snippet to the backend
598 *
599 * @param string javascript snippet
600 * @return void
601 */
602 public function addJavascript($javascript) {
603 // TODO do we need more checks?
604 if(!is_string($javascript)) {
605 throw new InvalidArgumentException('parameter $javascript must be of type string', 1195129553);
606 }
607
608 $this->js .= $javascript;
609 }
610
611 /**
612 * adds a javscript file to the backend after it has been checked that it exists
613 *
614 * @param string javascript file reference
615 * @return boolean true if the javascript file was successfully added, false otherwise
616 */
617 public function addJavascriptFile($javascriptFile) {
618 $jsFileAdded = false;
619
620 //TODO add more checks if neccessary
621 if(file_exists(t3lib_div::resolveBackPath(PATH_typo3.$javascriptFile))) {
622 $this->jsFiles[] = $javascriptFile;
623 $jsFileAdded = true;
624 }
625
626 return $jsFileAdded;
627 }
628
629 /**
630 * adds a css snippet to the backend
631 *
632 * @param string css snippet
633 * @return void
634 */
635 public function addCss($css) {
636 if(!is_string($css)) {
637 throw new InvalidArgumentException('parameter $css must be of type string', 1195129642);
638 }
639
640 $this->css .= $css;
641 }
642
643 /**
644 * adds a css file to the backend after it has been checked that it exists
645 *
646 * @param string the css file's name with out the .css ending
647 * @param string css file reference
648 * @return boolean true if the css file was added, false otherwise
649 */
650 public function addCssFile($cssFileName, $cssFile) {
651 $cssFileAdded = false;
652
653 if(empty($this->cssFiles[$cssFileName])) {
654 $this->cssFiles[$cssFileName] = $cssFile;
655 $cssFileAdded = true;
656 }
657
658 return $cssFileAdded;
659 }
660
661 /**
662 * adds an item to the toolbar, the class file for the toolbar item must be loaded at this point
663 *
664 * @param string toolbar item name, f.e. tx_toolbarExtension_coolItem
665 * @param string toolbar item class name, f.e. tx_toolbarExtension_coolItem
666 * @return void
667 */
668 public function addToolbarItem($toolbarItemName, $toolbarItemClassName) {
669 $toolbarItem = t3lib_div::makeInstance($toolbarItemClassName, $this);
670
671 if(!($toolbarItem instanceof backend_toolbarItem)) {
672 throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195125501);
673 }
674
675 if($toolbarItem->checkAccess()) {
676 $this->toolbarItems[$toolbarItemName] = $toolbarItem;
677 } else {
678 unset($toolbarItem);
679 }
680 }
681 }
682
683
684 // include XCLASS
685 if(defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']) {
686 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']);
687 }
688
689
690 // document generation
691 $TYPO3backend = t3lib_div::makeInstance('TYPO3backend');
692
693 // include extensions which may add css, javascript or toolbar items
694 if(is_array($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'])) {
695 foreach($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'] as $additionalBackendItem) {
696 include_once($additionalBackendItem);
697 }
698 }
699
700 $TYPO3backend->render();
701
702 ?>