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