Fixed bug #14202: htmlArea RTE: Tables may get lost when using remove format feature
[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 '../t3lib/js/extjs/ux/flashmessages.js',
131 'js/backend.js',
132 'js/loginrefresh.js',
133 'js/extjs/viewport.js',
134 'js/extjs/viewportConfiguration.js',
135 );
136
137 // add default BE css
138 $this->css = '';
139 $this->cssFiles = array();
140
141 $this->toolbarItems = array();
142 $this->initializeCoreToolbarItems();
143
144 $this->menuWidth = $this->menuWidthDefault;
145 if (isset($GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW']) && (int) $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'] != (int) $this->menuWidth) {
146 $this->menuWidth = (int) $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'];
147 }
148 }
149
150 /**
151 * initializes the core toolbar items
152 *
153 * @return void
154 */
155 protected function initializeCoreToolbarItems() {
156
157 $coreToolbarItems = array(
158 'workspaceSelector' => 'WorkspaceSelector',
159 'shortcuts' => 'ShortcutMenu',
160 'clearCacheActions' => 'ClearCacheMenu',
161 'backendSearch' => 'BackendSearchMenu'
162 );
163
164 foreach($coreToolbarItems as $toolbarItemName => $toolbarItemClassName) {
165 $toolbarItem = t3lib_div::makeInstance($toolbarItemClassName, $this);
166
167 if(!($toolbarItem instanceof backend_toolbarItem)) {
168 throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195126772);
169 }
170
171 if($toolbarItem->checkAccess()) {
172 $this->toolbarItems[$toolbarItemName] = $toolbarItem;
173 } else {
174 unset($toolbarItem);
175 }
176 }
177 }
178
179 /**
180 * main function generating the BE scaffolding
181 *
182 * @return void
183 */
184 public function render() {
185
186 // prepare the scaffolding, at this point extension may still add javascript and css
187 $logo = t3lib_div::makeInstance('TYPO3Logo');
188 $logo->setLogo('gfx/typo3logo_mini.png');
189
190 $menu = $this->moduleMenu->render();
191
192 if ($this->menuWidth != $this->menuWidthDefault) {
193 $this->css .= '
194 #typo3-top {
195 margin-left: ' . $this->menuWidth . 'px;
196 }
197 ';
198 }
199
200 // create backend scaffolding
201 $backendScaffolding = '
202 <div id="typo3-backend">
203 <div id="typo3-top-container" class="x-hide-display">
204 <div id="typo3-logo">'.$logo->render().'</div>
205 <div id="typo3-top" class="typo3-top-toolbar">' .
206 $this->renderToolbar() .
207 '</div>
208 </div>
209 <div id="typo3-main-container">
210 <div id="typo3-side-menu" class="x-hide-display">' .
211 $menu .
212 '</div>
213 <div id="typo3-content" class="x-hide-display">
214 <iframe src="alt_intro.php" name="content" id="content" marginwidth="0" marginheight="0" frameborder="0" scrolling="auto"></iframe>
215 </div>
216 </div>
217 </div>
218 ';
219
220 /******************************************************
221 * now put the complete backend document together
222 ******************************************************/
223
224 foreach($this->cssFiles as $cssFileName => $cssFile) {
225 $this->pageRenderer->addCssFile($cssFile);
226
227 // load addditional css files to overwrite existing core styles
228 if(!empty($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName])) {
229 $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName]);
230 }
231 }
232
233 if(!empty($this->css)) {
234 $this->pageRenderer->addCssInlineBlock('BackendInlineCSS', $this->css);
235 }
236
237 foreach ($this->jsFiles as $jsFile) {
238 $this->pageRenderer->addJsFile($jsFile);
239 }
240 // we mustn't compress this file
241 $this->pageRenderer->addJsFile('ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.Backend', NULL, FALSE);
242
243 $this->generateJavascript();
244 $this->pageRenderer->addJsInlineCode('BackendInlineJavascript', $this->js);
245
246
247 // set document title:
248 $title = ($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']
249 ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'].' [TYPO3 '.TYPO3_version.']'
250 : 'TYPO3 '.TYPO3_version
251 );
252
253 // start page header:
254 $this->content .= $GLOBALS['TBE_TEMPLATE']->startPage($title);
255 $this->content .= $backendScaffolding;
256 $this->content .= $GLOBALS['TBE_TEMPLATE']->endPage();
257
258 echo $this->content;
259 }
260
261 /**
262 * renders the items in the top toolbar
263 *
264 * @return string top toolbar elements as HTML
265 */
266 protected function renderToolbar() {
267
268 // move search to last position
269 $search = $this->toolbarItems['backendSearch'];
270 unset($this->toolbarItems['backendSearch']);
271 $this->toolbarItems['backendSearch'] = $search;
272
273 $toolbar = '<ul id="typo3-toolbar">';
274 $toolbar.= '<li>'.$this->getLoggedInUserLabel().'</li>
275 <li><div id="logout-button" class="toolbar-item no-separator">'.$this->moduleMenu->renderLogoutButton().'</div></li>';
276
277 foreach($this->toolbarItems as $toolbarItem) {
278 $menu = $toolbarItem->render();
279 if ($menu) {
280 $additionalAttributes = $toolbarItem->getAdditionalAttributes();
281 $toolbar .= '<li' . $additionalAttributes . '>' .$menu. '</li>';
282 }
283 }
284
285 return $toolbar.'</ul>';
286 }
287
288 /**
289 * Gets the label of the BE user currently logged in
290 *
291 * @return string html code snippet displaying the currently logged in user
292 */
293 protected function getLoggedInUserLabel() {
294 global $BE_USER, $BACK_PATH;
295
296 $icon = '<img'.t3lib_iconWorks::skinImg(
297 '',
298 $BE_USER->isAdmin() ?
299 'gfx/i/be_users_admin.gif' :
300 'gfx/i/be_users.gif',
301 'width="18" height="16"'
302 )
303 .' title="" alt="" />';
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 );
393 $t3LLLfileUpload = array(
394 'windowTitle' => $GLOBALS['LANG']->getLL('fileUpload_windowTitle'),
395 'buttonSelectFiles' => $GLOBALS['LANG']->getLL('fileUpload_buttonSelectFiles'),
396 'buttonCancelAll' => $GLOBALS['LANG']->getLL('fileUpload_buttonCancelAll'),
397 'infoComponentMaxFileSize' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentMaxFileSize'),
398 'infoComponentFileUploadLimit' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentFileUploadLimit'),
399 'infoComponentFileTypeLimit' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentFileTypeLimit'),
400 'infoComponentOverrideFiles' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentOverrideFiles'),
401 'processRunning' => $GLOBALS['LANG']->getLL('fileUpload_processRunning'),
402 'uploadWait' => $GLOBALS['LANG']->getLL('fileUpload_uploadWait'),
403 'uploadStarting' => $GLOBALS['LANG']->getLL('fileUpload_uploadStarting'),
404 'uploadProgress' => $GLOBALS['LANG']->getLL('fileUpload_uploadProgress'),
405 'uploadSuccess' => $GLOBALS['LANG']->getLL('fileUpload_uploadSuccess'),
406 'errorQueueLimitExceeded' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueLimitExceeded'),
407 'errorQueueFileSizeLimit' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueFileSizeLimit'),
408 'errorQueueZeroByteFile' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueZeroByteFile'),
409 'errorQueueInvalidFiletype' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueInvalidFiletype'),
410 'errorUploadHttp' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadHttpError'),
411 'errorUploadMissingUrl' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadMissingUrl'),
412 'errorUploadIO' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadIO'),
413 'errorUploadSecurityError' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadSecurityError'),
414 'errorUploadLimit' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadLimit'),
415 'errorUploadFailed' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFailed'),
416 'errorUploadFileIDNotFound' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileIDNotFound'),
417 'errorUploadFileValidation' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileValidation'),
418 'errorUploadFileCancelled' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileCancelled'),
419 'errorUploadStopped' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadStopped'),
420 'allErrorMessageTitle' => $GLOBALS['LANG']->getLL('fileUpload_allErrorMessageTitle'),
421 'allErrorMessageText' => $GLOBALS['LANG']->getLL('fileUpload_allErrorMessageText'),
422 'allError401' => $GLOBALS['LANG']->getLL('fileUpload_allError401'),
423 'allError2038' => $GLOBALS['LANG']->getLL('fileUpload_allError2038'),
424 );
425
426 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
427 if ($GLOBALS['LANG']->charSet !== 'utf-8') {
428 $t3Configuration['username'] = $GLOBALS['LANG']->csConvObj->conv($t3Configuration['username'], $GLOBALS['LANG']->charSet, 'utf-8');
429 $GLOBALS['LANG']->csConvObj->convArray($t3LLLcore, $GLOBALS['LANG']->charSet, 'utf-8');
430 $GLOBALS['LANG']->csConvObj->convArray($t3LLLfileUpload, $GLOBALS['LANG']->charSet, 'utf-8');
431 }
432
433 $this->js .= '
434 TYPO3.configuration = ' . json_encode($t3Configuration) . ';
435 TYPO3.LLL = {
436 core : ' . json_encode($t3LLLcore) . ',
437 fileUpload: ' . json_encode($t3LLLfileUpload) . '
438 };
439
440 /**
441 * TypoSetup object.
442 */
443 function typoSetup() { //
444 this.PATH_typo3 = TYPO3.configuration.PATH_typo3;
445 this.PATH_typo3_enc = TYPO3.configuration.PATH_typo3_enc;
446 this.username = TYPO3.configuration.username;
447 this.uniqueID = TYPO3.configuration.uniqueID;
448 this.navFrameWidth = 0;
449 this.securityLevel = TYPO3.configuration.securityLevel;
450 this.veriCode = TYPO3.configuration.veriCode;
451 this.denyFileTypes = TYPO3.configuration.denyFileTypes;
452 }
453 var TS = new typoSetup();
454
455 var currentModuleLoaded = "";
456
457 /**
458 * Frameset Module object
459 *
460 * Used in main modules with a frameset for submodules to keep the ID between modules
461 * Typically that is set by something like this in a Web>* sub module:
462 * if (top.fsMod) top.fsMod.recentIds["web"] = "\'.intval($this->id).\'";
463 * if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
464 */
465 function fsModules() { //
466 this.recentIds=new Array(); // used by frameset modules to track the most recent used id for list frame.
467 this.navFrameHighlightedID=new Array(); // used by navigation frames to track which row id was highlighted last time
468 this.currentMainLoaded="";
469 this.currentBank="0";
470 }
471 var fsMod = new fsModules();' . $moduleFramesHelper . ';';
472
473 // add goToModule code
474 $pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
475 $pageRenderer->addExtOnReadyCode('
476 top.goToModule = ' . $goToModuleSwitch . ';
477 ');
478
479 // Check editing of page:
480 $this->handlePageEditing();
481 $this->setStartupModule();
482 }
483
484 /**
485 * Checking if the "&edit" variable was sent so we can open it for editing the page.
486 * Code based on code from "alt_shortcut.php"
487 *
488 * @return void
489 */
490 protected function handlePageEditing() {
491
492 if(!t3lib_extMgm::isLoaded('cms')) {
493 return;
494 }
495
496 // EDIT page:
497 $editId = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('edit'));
498 $editRecord = '';
499
500 if($editId) {
501
502 // Looking up the page to edit, checking permissions:
503 $where = ' AND ('.$GLOBALS['BE_USER']->getPagePermsClause(2)
504 .' OR '.$GLOBALS['BE_USER']->getPagePermsClause(16).')';
505
506 if(t3lib_div::testInt($editId)) {
507 $editRecord = t3lib_BEfunc::getRecordWSOL('pages', $editId, '*', $where);
508 } else {
509 $records = t3lib_BEfunc::getRecordsByField('pages', 'alias', $editId, $where);
510
511 if(is_array($records)) {
512 reset($records);
513 $editRecord = current($records);
514 t3lib_BEfunc::workspaceOL('pages', $editRecord);
515 }
516 }
517
518 // If the page was accessible, then let the user edit it.
519 if(is_array($editRecord) && $GLOBALS['BE_USER']->isInWebMount($editRecord['uid'])) {
520 // Setting JS code to open editing:
521 $this->js .= '
522 // Load page to edit:
523 window.setTimeout("top.loadEditId('.intval($editRecord['uid']).');", 500);
524 ';
525 // Checking page edit parameter:
526 if(!$GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
527
528 // Expanding page tree:
529 t3lib_BEfunc::openPageTree(intval($editRecord['pid']), !$GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded'));
530 }
531 } else {
532 $this->js .= '
533 // Warning about page editing:
534 alert('.$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('noEditPage'), $editId)).');
535 ';
536 }
537 }
538 }
539
540 /**
541 * Sets the startup module from either GETvars module and mpdParams or user configuration.
542 *
543 * @return void
544 */
545 protected function setStartupModule() {
546 $startModule = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('module'));
547
548 if(!$startModule) {
549 if ($GLOBALS['BE_USER']->uc['startModule']) {
550 $startModule = $GLOBALS['BE_USER']->uc['startModule'];
551 } else if($GLOBALS['BE_USER']->uc['startInTaskCenter']) {
552 $startModule = 'user_task';
553 }
554 }
555
556 $moduleParameters = t3lib_div::_GET('modParams');
557 if($startModule) {
558 $pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
559 $pageRenderer->addExtOnReadyCode('
560 // start in module:
561 function startInModule(modName, cMR_flag, addGetVars) {
562 Ext.onReady(function() {
563 top.goToModule(modName, cMR_flag, addGetVars);
564 });
565 }
566
567 startInModule(\''.$startModule.'\', false, '.t3lib_div::quoteJSvalue($moduleParameters).');
568 ');
569 }
570 }
571
572 /**
573 * generates the code for the TYPO3 logo, either the default TYPO3 logo or a custom one
574 *
575 * @return string HTML code snippet to display the TYPO3 logo
576 */
577 protected function getLogo() {
578 $logo = '<a href="http://www.typo3.com/" target="_blank" onclick="'.$GLOBALS['TBE_TEMPLATE']->thisBlur().'">'.
579 '<img'.t3lib_iconWorks::skinImg('','gfx/alt_backend_logo.gif','width="117" height="32"').' title="TYPO3 Content Management Framework" alt="" />'.
580 '</a>';
581
582 // overwrite with custom logo
583 if($GLOBALS['TBE_STYLES']['logo']) {
584 if(substr($GLOBALS['TBE_STYLES']['logo'], 0, 3) == '../') {
585 $imgInfo = @getimagesize(PATH_site.substr($GLOBALS['TBE_STYLES']['logo'], 3));
586 }
587 $logo = '<a href="http://www.typo3.com/" target="_blank" onclick="'.$GLOBALS['TBE_TEMPLATE']->thisBlur().'">'.
588 '<img src="'.$GLOBALS['TBE_STYLES']['logo'].'" '.$imgInfo[3].' title="TYPO3 Content Management Framework" alt="" />'.
589 '</a>';
590 }
591
592 return $logo;
593 }
594
595 /**
596 * adds a javascript snippet to the backend
597 *
598 * @param string javascript snippet
599 * @return void
600 */
601 public function addJavascript($javascript) {
602 // TODO do we need more checks?
603 if(!is_string($javascript)) {
604 throw new InvalidArgumentException('parameter $javascript must be of type string', 1195129553);
605 }
606
607 $this->js .= $javascript;
608 }
609
610 /**
611 * adds a javscript file to the backend after it has been checked that it exists
612 *
613 * @param string javascript file reference
614 * @return boolean true if the javascript file was successfully added, false otherwise
615 */
616 public function addJavascriptFile($javascriptFile) {
617 $jsFileAdded = false;
618
619 //TODO add more checks if neccessary
620 if(file_exists(t3lib_div::resolveBackPath(PATH_typo3.$javascriptFile))) {
621 $this->jsFiles[] = $javascriptFile;
622 $jsFileAdded = true;
623 }
624
625 return $jsFileAdded;
626 }
627
628 /**
629 * adds a css snippet to the backend
630 *
631 * @param string css snippet
632 * @return void
633 */
634 public function addCss($css) {
635 if(!is_string($css)) {
636 throw new InvalidArgumentException('parameter $css must be of type string', 1195129642);
637 }
638
639 $this->css .= $css;
640 }
641
642 /**
643 * adds a css file to the backend after it has been checked that it exists
644 *
645 * @param string the css file's name with out the .css ending
646 * @param string css file reference
647 * @return boolean true if the css file was added, false otherwise
648 */
649 public function addCssFile($cssFileName, $cssFile) {
650 $cssFileAdded = false;
651
652 if(empty($this->cssFiles[$cssFileName])) {
653 $this->cssFiles[$cssFileName] = $cssFile;
654 $cssFileAdded = true;
655 }
656
657 return $cssFileAdded;
658 }
659
660 /**
661 * adds an item to the toolbar, the class file for the toolbar item must be loaded at this point
662 *
663 * @param string toolbar item name, f.e. tx_toolbarExtension_coolItem
664 * @param string toolbar item class name, f.e. tx_toolbarExtension_coolItem
665 * @return void
666 */
667 public function addToolbarItem($toolbarItemName, $toolbarItemClassName) {
668 $toolbarItem = t3lib_div::makeInstance($toolbarItemClassName, $this);
669
670 if(!($toolbarItem instanceof backend_toolbarItem)) {
671 throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195125501);
672 }
673
674 if($toolbarItem->checkAccess()) {
675 $this->toolbarItems[$toolbarItemName] = $toolbarItem;
676 } else {
677 unset($toolbarItem);
678 }
679 }
680 }
681
682
683 // include XCLASS
684 if(defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']) {
685 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']);
686 }
687
688
689 // document generation
690 $TYPO3backend = t3lib_div::makeInstance('TYPO3backend');
691
692 // include extensions which may add css, javascript or toolbar items
693 if(is_array($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'])) {
694 foreach($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'] as $additionalBackendItem) {
695 include_once($additionalBackendItem);
696 }
697 }
698
699 $TYPO3backend->render();
700
701 ?>