[BUGFIX] Fix PHP warning in EXT:beuser
[Packages/TYPO3.CMS.git] / typo3 / backend.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2007-2011 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 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_misc.xml');
30
31 /**
32 * Class for rendering the TYPO3 backend version 4.2+
33 *
34 * @author Ingo Renner <ingo@typo3.org>
35 * @package TYPO3
36 * @subpackage core
37 */
38 class TYPO3backend {
39 protected $content;
40 protected $css;
41 protected $cssFiles;
42 protected $js;
43 protected $jsFiles;
44 protected $jsFilesAfterInline;
45 protected $toolbarItems;
46 // intentionally private as nobody should modify defaults
47 private $menuWidthDefault = 190;
48 protected $menuWidth;
49 protected $debug;
50
51 /**
52 * Object for loading backend modules
53 *
54 * @var t3lib_loadModules
55 */
56 protected $moduleLoader;
57
58 /**
59 * module menu generating object
60 *
61 * @var ModuleMenu
62 */
63 protected $moduleMenu;
64
65 /**
66 * Pagerenderer
67 *
68 * @var t3lib_PageRenderer
69 */
70 protected $pageRenderer;
71
72 /**
73 * Constructor
74 */
75 public function __construct() {
76 // Set debug flag for BE development only
77 $this->debug = intval($GLOBALS['TYPO3_CONF_VARS']['BE']['debug']) === 1;
78
79 // Initializes the backend modules structure for use later.
80 $this->moduleLoader = t3lib_div::makeInstance('t3lib_loadModules');
81 $this->moduleLoader->load($GLOBALS['TBE_MODULES']);
82
83 $this->moduleMenu = t3lib_div::makeInstance('ModuleMenu');
84
85 $this->pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
86 $this->pageRenderer->loadScriptaculous('builder,effects,controls,dragdrop');
87 $this->pageRenderer->loadExtJS();
88 $this->pageRenderer->enableExtJSQuickTips();
89
90 $this->pageRenderer->addJsInlineCode(
91 'consoleOverrideWithDebugPanel',
92 '//already done',
93 FALSE
94 );
95 $this->pageRenderer->addExtDirectCode();
96
97 // Add default BE javascript
98 $this->js = '';
99 $this->jsFiles = array(
100 'common' => 'js/common.js',
101 'locallang' => $this->getLocalLangFileName(),
102 'modernizr' => 'contrib/modernizr/modernizr.min.js',
103 'swfupload' => 'contrib/swfupload/swfupload.js',
104 'swfupload.swfobject' => 'contrib/swfupload/plugins/swfupload.swfobject.js',
105 'swfupload.cookies' => 'contrib/swfupload/plugins/swfupload.cookies.js',
106 'swfupload.queue' => 'contrib/swfupload/plugins/swfupload.queue.js',
107 'md5' => 'md5.js',
108 'toolbarmanager' => 'js/toolbarmanager.js',
109 'modulemenu' => 'js/modulemenu.js',
110 'iecompatibility' => 'js/iecompatibility.js',
111 'flashupload' => 'js/flashupload.js',
112 'evalfield' => '../t3lib/jsfunc.evalfield.js',
113 'flashmessages' => '../t3lib/js/extjs/ux/flashmessages.js',
114 'tabclosemenu' => '../t3lib/js/extjs/ux/ext.ux.tabclosemenu.js',
115 'notifications' => '../t3lib/js/extjs/notifications.js',
116 'backend' => 'js/backend.js',
117 'loginrefresh' => 'js/loginrefresh.js',
118 'debugPanel' => 'js/extjs/debugPanel.js',
119 'viewport' => 'js/extjs/viewport.js',
120 'iframepanel' => 'js/extjs/iframepanel.js',
121 'backendcontentiframe' => 'js/extjs/backendcontentiframe.js',
122 'modulepanel' => 'js/extjs/modulepanel.js',
123 'viewportConfiguration' => 'js/extjs/viewportConfiguration.js',
124 'util' => '../t3lib/js/extjs/util.js',
125 );
126
127 if ($this->debug) {
128 unset($this->jsFiles['loginrefresh']);
129 }
130
131 // Add default BE css
132 $this->css = '';
133 $this->cssFiles = array();
134
135 $this->toolbarItems = array();
136 $this->initializeCoreToolbarItems();
137
138 $this->menuWidth = $this->menuWidthDefault;
139 if (isset($GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW']) && (int) $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'] != (int) $this->menuWidth) {
140 $this->menuWidth = (int) $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'];
141 }
142
143 $this->executeHook('constructPostProcess');
144 }
145
146 /**
147 * Initializes the core toolbar items
148 *
149 * @return void
150 */
151 protected function initializeCoreToolbarItems() {
152
153 $coreToolbarItems = array(
154 'shortcuts' => 'ShortcutMenu',
155 'clearCacheActions' => 'ClearCacheMenu',
156 'liveSearch' => 'LiveSearch'
157 );
158
159 foreach ($coreToolbarItems as $toolbarItemName => $toolbarItemClassName) {
160 $toolbarItem = t3lib_div::makeInstance($toolbarItemClassName, $this);
161
162 if (!($toolbarItem instanceof backend_toolbarItem)) {
163 throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195126772);
164 }
165
166 if ($toolbarItem->checkAccess()) {
167 $this->toolbarItems[$toolbarItemName] = $toolbarItem;
168 } else {
169 unset($toolbarItem);
170 }
171 }
172 }
173
174 /**
175 * Main function generating the BE scaffolding
176 *
177 * @return void
178 */
179 public function render() {
180 $this->executeHook('renderPreProcess');
181
182 // Prepare the scaffolding, at this point extension may still add javascript and css
183 $logo = t3lib_div::makeInstance('TYPO3Logo');
184 $logo->setLogo('gfx/typo3logo_mini.png');
185
186 // Create backend scaffolding
187 $backendScaffolding = '
188 <div id="typo3-top-container" class="x-hide-display">
189 <div id="typo3-logo">'.$logo->render().'</div>
190 <div id="typo3-top" class="typo3-top-toolbar">' .
191 $this->renderToolbar() .
192 '</div>
193 </div>';
194
195 /******************************************************
196 * Now put the complete backend document together
197 ******************************************************/
198
199 foreach ($this->cssFiles as $cssFileName => $cssFile) {
200 $this->pageRenderer->addCssFile($cssFile);
201
202 // Load addditional css files to overwrite existing core styles
203 if (!empty($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName])) {
204 $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName]);
205 }
206 }
207
208 if (!empty($this->css)) {
209 $this->pageRenderer->addCssInlineBlock('BackendInlineCSS', $this->css);
210 }
211
212 foreach ($this->jsFiles as $jsFile) {
213 $this->pageRenderer->addJsFile($jsFile);
214 }
215
216 $this->generateJavascript();
217 $this->pageRenderer->addJsInlineCode('BackendInlineJavascript', $this->js, FALSE);
218
219 $this->loadResourcesForRegisteredNavigationComponents();
220
221 // Add state provider
222 $GLOBALS['TBE_TEMPLATE']->setExtDirectStateProvider();
223 $states = $GLOBALS['BE_USER']->uc['BackendComponents']['States'];
224 // Save states in BE_USER->uc
225 $extOnReadyCode = '
226 Ext.state.Manager.setProvider(new TYPO3.state.ExtDirectProvider({
227 key: "BackendComponents.States",
228 autoRead: false
229 }));
230 ';
231 if ($states) {
232 $extOnReadyCode .= 'Ext.state.Manager.getProvider().initState(' . json_encode($states) . ');';
233 }
234 $extOnReadyCode .= '
235 TYPO3.Backend = new TYPO3.Viewport(TYPO3.Viewport.configuration);
236 if (typeof console === "undefined") {
237 console = TYPO3.Backend.DebugConsole;
238 }
239 TYPO3.ContextHelpWindow.init();';
240 $this->pageRenderer->addExtOnReadyCode($extOnReadyCode);
241
242 // Set document title:
243 $title = ($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']
244 ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'].' [TYPO3 '.TYPO3_version.']'
245 : 'TYPO3 '.TYPO3_version
246 );
247
248 $this->content = $backendScaffolding;
249 // Renders the module page
250 $this->content = $GLOBALS['TBE_TEMPLATE']->render(
251 $title,
252 $this->content
253 );
254
255 $hookConfiguration = array('content' => &$this->content);
256 $this->executeHook('renderPostProcess', $hookConfiguration);
257
258 echo $this->content;
259 }
260
261 /**
262 * Loads the css and javascript files of all registered navigation widgets
263 *
264 * @return void
265 */
266 protected function loadResourcesForRegisteredNavigationComponents() {
267 if (!is_array($GLOBALS['TBE_MODULES']['_navigationComponents'])) {
268 return;
269 }
270
271 $loadedComponents = array();
272 foreach ($GLOBALS['TBE_MODULES']['_navigationComponents'] as $module => $info) {
273 if (in_array($info['componentId'], $loadedComponents)) {
274 continue;
275 }
276 $loadedComponents[] = $info['componentId'];
277
278 $component = strtolower(substr($info['componentId'], strrpos($info['componentId'], '-') + 1));
279 $componentDirectory = 'components/' . $component . '/';
280
281 if ($info['isCoreComponent']) {
282 $absoluteComponentPath = PATH_t3lib . 'js/extjs/' . $componentDirectory;
283 $relativeComponentPath = '../' . str_replace(PATH_site, '', $absoluteComponentPath);
284 } else {
285 $absoluteComponentPath = t3lib_extMgm::extPath($info['extKey']) . $componentDirectory;
286 $relativeComponentPath = t3lib_extMgm::extRelPath($info['extKey']) . $componentDirectory;
287 }
288
289 $cssFiles = t3lib_div::getFilesInDir($absoluteComponentPath . 'css/', 'css');
290 if (file_exists($absoluteComponentPath . 'css/loadorder.txt')) {
291 // Don't allow inclusion outside directory
292 $loadOrder = str_replace('../', '', t3lib_div::getUrl($absoluteComponentPath . 'css/loadorder.txt'));
293 $cssFilesOrdered = t3lib_div::trimExplode(LF, $loadOrder, TRUE);
294 $cssFiles = array_merge($cssFilesOrdered, $cssFiles);
295 }
296 foreach ($cssFiles as $cssFile) {
297 $this->pageRenderer->addCssFile($relativeComponentPath . 'css/' . $cssFile);
298 }
299
300 $jsFiles = t3lib_div::getFilesInDir($absoluteComponentPath . 'javascript/', 'js');
301 if (file_exists($absoluteComponentPath . 'javascript/loadorder.txt')) {
302 // Don't allow inclusion outside directory
303 $loadOrder = str_replace('../', '', t3lib_div::getUrl($absoluteComponentPath . 'javascript/loadorder.txt'));
304 $jsFilesOrdered = t3lib_div::trimExplode(LF, $loadOrder, TRUE);
305 $jsFiles = array_merge($jsFilesOrdered, $jsFiles);
306 }
307
308 foreach ($jsFiles as $jsFile) {
309 $this->pageRenderer->addJsFile($relativeComponentPath . 'javascript/' . $jsFile);
310 }
311 }
312 }
313
314 /**
315 * Renders the items in the top toolbar
316 *
317 * @return string top toolbar elements as HTML
318 */
319 protected function renderToolbar() {
320
321 // Move search to last position
322 if (array_key_exists('liveSearch', $this->toolbarItems)) {
323 $search = $this->toolbarItems['liveSearch'];
324 unset($this->toolbarItems['liveSearch']);
325 $this->toolbarItems['liveSearch'] = $search;
326 }
327
328 $toolbar = '<ul id="typo3-toolbar">';
329 $toolbar .= '<li>' . $this->getLoggedInUserLabel() . '</li>';
330 $toolbar .= '<li class="separator"><div id="logout-button" class="toolbar-item no-separator">' . $this->moduleMenu->renderLogoutButton() . '</div></li>';
331
332 $i = 0;
333 foreach ($this->toolbarItems as $key => $toolbarItem) {
334 $i++;
335 $menu = $toolbarItem->render();
336 if ($menu) {
337 $additionalAttributes = $toolbarItem->getAdditionalAttributes();
338 if (sizeof($this->toolbarItems) > 1 && $i == sizeof($this->toolbarItems) -1) {
339 if (strpos($additionalAttributes, 'class="')) {
340 str_replace('class="', 'class="separator ', $additionalAttributes);
341 } else {
342 $additionalAttributes .= 'class="separator"';
343 }
344 }
345 $toolbar .= '<li' . $additionalAttributes . '>' .$menu. '</li>';
346 }
347 }
348
349 return $toolbar.'</ul>';
350 }
351
352 /**
353 * Gets the label of the BE user currently logged in
354 *
355 * @return string Html code snippet displaying the currently logged in user
356 */
357 protected function getLoggedInUserLabel() {
358 $css = 'toolbar-item';
359 $icon = t3lib_iconWorks::getSpriteIcon('status-user-' . ($GLOBALS['BE_USER']->isAdmin() ? 'admin' : 'backend'));
360 $realName = $GLOBALS['BE_USER']->user['realName'];
361 $username = $GLOBALS['BE_USER']->user['username'];
362
363 $label = $realName ? $realName : $username;
364 $title = $username;
365
366 // Link to user setup if it's loaded and user has access
367 $link = '';
368 if (t3lib_extMgm::isLoaded('setup') && $GLOBALS['BE_USER']->check('modules', 'user_setup')) {
369 $link = '<a href="#" onclick="top.goToModule(\'user_setup\'); this.blur(); return false;">';
370 }
371
372 // Superuser mode
373 if ($GLOBALS['BE_USER']->user['ses_backuserid']) {
374 $css .= ' su-user';
375 $title = $GLOBALS['LANG']->getLL('switchtouser') . ': ' . $username;
376 $label = $GLOBALS['LANG']->getLL('switchtousershort') . ' ' .
377 ($realName ? $realName . ' (' . $username . ')' : $username);
378 }
379
380 return '<div id="username" class="' . $css . '">' . $link . $icon .
381 '<span title="' . htmlspecialchars($title) . '">' . htmlspecialchars($label) . '</span>' .
382 ($link ? '</a>' : '') . '</div>';
383 }
384
385 /**
386 * Returns the file name to the LLL JavaScript, containing the localized labels,
387 * which can be used in JavaScript code.
388 *
389 * @return string File name of the JS file, relative to TYPO3_mainDir
390 */
391 protected function getLocalLangFileName() {
392 $code = $this->generateLocalLang();
393 $filePath = 'typo3temp/locallang-BE-' . sha1($code) . '.js';
394 if (!file_exists(PATH_site . $filePath)) {
395 // writeFileToTypo3tempDir() returns NULL on success (please double-read!)
396 if (t3lib_div::writeFileToTypo3tempDir(PATH_site . $filePath, $code) !== NULL) {
397 throw new RuntimeException('LocalLangFile could not be written to ' . $filePath, 1295193026);
398 }
399 }
400 return '../' . $filePath;
401 }
402
403 /**
404 * Reads labels required in JavaScript code from the localization system and returns them as JSON
405 * array in TYPO3.LLL.
406 *
407 * @return string JavaScript code containing the LLL labels in TYPO3.LLL
408 */
409 protected function generateLocalLang() {
410 $coreLabels = array(
411 'waitTitle' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_logging_in') ,
412 'refresh_login_failed' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed'),
413 'refresh_login_failed_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed_message'),
414 'refresh_login_title' => sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_title'), htmlspecialchars($GLOBALS['BE_USER']->user['username'])),
415 'login_expired' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_expired'),
416 'refresh_login_username' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_username'),
417 'refresh_login_password' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_password'),
418 'refresh_login_emptyPassword' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_emptyPassword'),
419 'refresh_login_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_button'),
420 'refresh_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_logout_button'),
421 'please_wait' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.please_wait'),
422 'loadingIndicator' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:loadingIndicator'),
423 'be_locked' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.be_locked'),
424 'refresh_login_countdown_singular' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown_singular'),
425 'refresh_login_countdown' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown'),
426 'login_about_to_expire' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire'),
427 'login_about_to_expire_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire_title'),
428 'refresh_login_refresh_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_refresh_button'),
429 'refresh_direct_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_direct_logout_button'),
430 'tabs_closeAll' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeAll'),
431 'tabs_closeOther' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeOther'),
432 'tabs_close' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.close'),
433 'tabs_openInBrowserWindow' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.openInBrowserWindow'),
434 'csh_tooltip_loading' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:csh_tooltip_loading'),
435 );
436
437 $labels = array(
438 'fileUpload' => array(
439 'windowTitle',
440 'buttonSelectFiles',
441 'buttonCancelAll',
442 'infoComponentMaxFileSize',
443 'infoComponentFileUploadLimit',
444 'infoComponentFileTypeLimit',
445 'infoComponentOverrideFiles',
446 'processRunning',
447 'uploadWait',
448 'uploadStarting',
449 'uploadProgress',
450 'uploadSuccess',
451 'errorQueueLimitExceeded',
452 'errorQueueFileSizeLimit',
453 'errorQueueZeroByteFile',
454 'errorQueueInvalidFiletype',
455 'errorUploadHttp',
456 'errorUploadMissingUrl',
457 'errorUploadIO',
458 'errorUploadSecurityError',
459 'errorUploadLimit',
460 'errorUploadFailed',
461 'errorUploadFileIDNotFound',
462 'errorUploadFileValidation',
463 'errorUploadFileCancelled',
464 'errorUploadStopped',
465 'allErrorMessageTitle',
466 'allErrorMessageText',
467 'allError401',
468 'allError2038',
469 ),
470 'liveSearch' => array(
471 'title',
472 'helpTitle',
473 'emptyText',
474 'loadingText',
475 'listEmptyText',
476 'showAllResults',
477 'helpDescription',
478 'helpDescriptionPages',
479 'helpDescriptionContent',
480 ),
481 'viewPort' => array(
482 'tooltipModuleMenuSplit',
483 'tooltipNavigationContainerSplitDrag',
484 'tooltipDebugPanelSplitDrag',
485
486 ),
487 );
488 $generatedLabels = array();
489 $generatedLabels['core'] = $coreLabels;
490
491 // First loop over all categories (fileUpload, liveSearch, ..)
492 foreach ($labels as $categoryName => $categoryLabels) {
493 // Then loop over every single label
494 foreach ($categoryLabels as $label) {
495 // LLL identifier must be called $categoryName_$label, e.g. liveSearch_loadingText
496 $generatedLabels[$categoryName][$label] = $GLOBALS['LANG']->getLL($categoryName . '_' . $label);
497 }
498 }
499
500 return 'TYPO3.LLL = ' . json_encode($generatedLabels) . ';';
501 }
502
503 /**
504 * Generates the JavaScript code for the backend.
505 *
506 * @return void
507 */
508 protected function generateJavascript() {
509
510 $pathTYPO3 = t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')) . '/';
511
512 // If another page module was specified, replace the default Page module with the new one
513 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
514 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
515 if (!$GLOBALS['BE_USER']->check('modules', $pageModule)) {
516 $pageModule = '';
517 }
518
519 $menuFrameName = 'menu';
520 if($GLOBALS['BE_USER']->uc['noMenuMode'] === 'icons') {
521 $menuFrameName = 'topmenuFrame';
522 }
523
524 // Determine security level from conf vars and default to super challenged
525 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) {
526 $this->loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'];
527 } else {
528 $this->loginSecurityLevel = 'superchallenged';
529 }
530
531 $t3Configuration = array(
532 'siteUrl' => t3lib_div::getIndpEnv('TYPO3_SITE_URL'),
533 'PATH_typo3' => $pathTYPO3,
534 'PATH_typo3_enc' => rawurlencode($pathTYPO3),
535 'username' => htmlspecialchars($GLOBALS['BE_USER']->user['username']),
536 'uniqueID' => t3lib_div::shortMD5(uniqid('')),
537 'securityLevel' => $this->loginSecurityLevel,
538 'TYPO3_mainDir' => TYPO3_mainDir,
539 'pageModule' => $pageModule,
540 'condensedMode' => $GLOBALS['BE_USER']->uc['condensedMode'] ? 1 : 0 ,
541 'inWorkspace' => $GLOBALS['BE_USER']->workspace !== 0 ? 1 : 0,
542 'workspaceFrontendPreviewEnabled' => $GLOBALS['BE_USER']->user['workspace_preview'] ? 1 : 0,
543 'veriCode' => $GLOBALS['BE_USER']->veriCode(),
544 'denyFileTypes' => PHP_EXTENSIONS_DEFAULT,
545 'moduleMenuWidth' => $this->menuWidth - 1,
546 'topBarHeight' => (isset($GLOBALS['TBE_STYLES']['dims']['topFrameH']) ? intval($GLOBALS['TBE_STYLES']['dims']['topFrameH']) : 30),
547 'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? intval($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) : FALSE,
548 'listModulePath' => t3lib_extMgm::isLoaded('recordlist') ? t3lib_extMgm::extRelPath('recordlist') . 'mod1/' : '',
549 'debugInWindow' => $GLOBALS['BE_USER']->uc['debugInWindow'] ? 1 : 0,
550 'ContextHelpWindows' => array(
551 'width' => 600,
552 'height' => 400
553 ),
554 'firstWebmountPid' => intval($GLOBALS['WEBMOUNTS'][0]),
555 );
556
557 $this->js .= '
558 TYPO3.configuration = ' . json_encode($t3Configuration) . ';
559
560 /**
561 * TypoSetup object.
562 */
563 function typoSetup() { //
564 this.PATH_typo3 = TYPO3.configuration.PATH_typo3;
565 this.PATH_typo3_enc = TYPO3.configuration.PATH_typo3_enc;
566 this.username = TYPO3.configuration.username;
567 this.uniqueID = TYPO3.configuration.uniqueID;
568 this.navFrameWidth = 0;
569 this.securityLevel = TYPO3.configuration.securityLevel;
570 this.veriCode = TYPO3.configuration.veriCode;
571 this.denyFileTypes = TYPO3.configuration.denyFileTypes;
572 }
573 var TS = new typoSetup();
574 //backwards compatibility
575 /**
576 * Frameset Module object
577 *
578 * Used in main modules with a frameset for submodules to keep the ID between modules
579 * Typically that is set by something like this in a Web>* sub module:
580 * if (top.fsMod) top.fsMod.recentIds["web"] = "\'.intval($this->id).\'";
581 * if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
582 */
583 function fsModules() { //
584 this.recentIds=new Array(); // used by frameset modules to track the most recent used id for list frame.
585 this.navFrameHighlightedID=new Array(); // used by navigation frames to track which row id was highlighted last time
586 this.currentMainLoaded="";
587 this.currentBank="0";
588 }
589 var fsMod = new fsModules();
590
591 top.goToModule = function(modName, cMR_flag, addGetVars) {
592 TYPO3.ModuleMenu.App.showModule(modName, addGetVars);
593 }
594 ' . $this->setStartupModule();
595
596 // Check editing of page:
597 $this->handlePageEditing();
598
599 }
600
601 /**
602 * Checking if the "&edit" variable was sent so we can open it for editing the page.
603 * Code based on code from "alt_shortcut.php"
604 *
605 * @return void
606 */
607 protected function handlePageEditing() {
608
609 if (!t3lib_extMgm::isLoaded('cms')) {
610 return;
611 }
612
613 // EDIT page:
614 $editId = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('edit'));
615 $editRecord = '';
616
617 if ($editId) {
618
619 // Looking up the page to edit, checking permissions:
620 $where = ' AND ('.$GLOBALS['BE_USER']->getPagePermsClause(2) .
621 ' OR ' . $GLOBALS['BE_USER']->getPagePermsClause(16) . ')';
622
623 if (t3lib_utility_Math::canBeInterpretedAsInteger($editId)) {
624 $editRecord = t3lib_BEfunc::getRecordWSOL('pages', $editId, '*', $where);
625 } else {
626 $records = t3lib_BEfunc::getRecordsByField('pages', 'alias', $editId, $where);
627
628 if (is_array($records)) {
629 $editRecord = reset($records);
630 t3lib_BEfunc::workspaceOL('pages', $editRecord);
631 }
632 }
633
634 // If the page was accessible, then let the user edit it.
635 if (is_array($editRecord) && $GLOBALS['BE_USER']->isInWebMount($editRecord['uid'])) {
636 // Setting JS code to open editing:
637 $this->js .= '
638 // Load page to edit:
639 window.setTimeout("top.loadEditId('.intval($editRecord['uid']).');", 500);
640 ';
641
642 // Checking page edit parameter:
643 if (!$GLOBALS['BE_USER']->getTSConfigVal('options.bookmark_onEditId_dontSetPageTree')) {
644 $bookmarkKeepExpanded = $GLOBALS['BE_USER']->getTSConfigVal('options.bookmark_onEditId_keepExistingExpanded');
645
646 // Expanding page tree:
647 t3lib_BEfunc::openPageTree(intval($editRecord['pid']), !$bookmarkKeepExpanded);
648 }
649 } else {
650 $this->js .= '
651 // Warning about page editing:
652 alert(' . $GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('noEditPage'), $editId)) . ');
653 ';
654 }
655 }
656 }
657
658 /**
659 * Sets the startup module from either GETvars module and mpdParams or user configuration.
660 *
661 * @return void
662 */
663 protected function setStartupModule() {
664 $startModule = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('module'));
665
666 if (!$startModule) {
667 if ($GLOBALS['BE_USER']->uc['startModule']) {
668 $startModule = $GLOBALS['BE_USER']->uc['startModule'];
669 } elseif ($GLOBALS['BE_USER']->uc['startInTaskCenter']) {
670 $startModule = 'user_task';
671 }
672 }
673
674 $moduleParameters = t3lib_div::_GET('modParams');
675 if ($startModule) {
676 return '
677 // start in module:
678 top.startInModule = [\'' . $startModule . '\', ' . t3lib_div::quoteJSvalue($moduleParameters) . '];
679 ';
680 } else {
681 return '';
682 }
683
684 }
685
686 /**
687 * Sdds a javascript snippet to the backend
688 *
689 * @param string $javascript Javascript snippet
690 * @return void
691 */
692 public function addJavascript($javascript) {
693 // TODO do we need more checks?
694 if (!is_string($javascript)) {
695 throw new InvalidArgumentException('parameter $javascript must be of type string', 1195129553);
696 }
697
698 $this->js .= $javascript;
699 }
700
701 /**
702 * Adds a javscript file to the backend after it has been checked that it exists
703 *
704 * @param string $javascriptFile Javascript file reference
705 * @return boolean TRUE if the javascript file was successfully added, FALSE otherwise
706 */
707 public function addJavascriptFile($javascriptFile) {
708 $jsFileAdded = FALSE;
709
710 //TODO add more checks if neccessary
711 if (file_exists(t3lib_div::resolveBackPath(PATH_typo3.$javascriptFile))) {
712 $this->jsFiles[] = $javascriptFile;
713 $jsFileAdded = TRUE;
714 }
715
716 return $jsFileAdded;
717 }
718
719 /**
720 * Adds a css snippet to the backend
721 *
722 * @param string $css Css snippet
723 * @return void
724 */
725 public function addCss($css) {
726 if (!is_string($css)) {
727 throw new InvalidArgumentException('parameter $css must be of type string', 1195129642);
728 }
729
730 $this->css .= $css;
731 }
732
733 /**
734 * Adds a css file to the backend after it has been checked that it exists
735 *
736 * @param string $cssFileName The css file's name with out the .css ending
737 * @param string $cssFile Css file reference
738 * @return boolean TRUE if the css file was added, FALSE otherwise
739 */
740 public function addCssFile($cssFileName, $cssFile) {
741 $cssFileAdded = FALSE;
742
743 if (empty($this->cssFiles[$cssFileName])) {
744 $this->cssFiles[$cssFileName] = $cssFile;
745 $cssFileAdded = TRUE;
746 }
747
748 return $cssFileAdded;
749 }
750
751 /**
752 * Adds an item to the toolbar, the class file for the toolbar item must be loaded at this point
753 *
754 * @param string $toolbarItemName Toolbar item name, f.e. tx_toolbarExtension_coolItem
755 * @param string $toolbarItemClassName Toolbar item class name, f.e. tx_toolbarExtension_coolItem
756 * @return void
757 */
758 public function addToolbarItem($toolbarItemName, $toolbarItemClassName) {
759 $toolbarItem = t3lib_div::makeInstance($toolbarItemClassName, $this);
760
761 if (!($toolbarItem instanceof backend_toolbarItem)) {
762 throw new UnexpectedValueException('$toolbarItem "' . $toolbarItemName . '" must implement interface backend_toolbarItem', 1195125501);
763 }
764
765 if ($toolbarItem->checkAccess()) {
766 $this->toolbarItems[$toolbarItemName] = $toolbarItem;
767 } else {
768 unset($toolbarItem);
769 }
770 }
771
772 /**
773 * Executes defined hooks functions for the given identifier.
774 *
775 * These hook identifiers are valid:
776 * + constructPostProcess
777 * + renderPreProcess
778 * + renderPostProcess
779 *
780 * @param string $identifier Specific hook identifier
781 * @param array $hookConfiguration Additional configuration passed to hook functions
782 * @return void
783 */
784 protected function executeHook($identifier, array $hookConfiguration = array()) {
785 $options =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/backend.php'];
786
787 if (isset($options[$identifier]) && is_array($options[$identifier])) {
788 foreach($options[$identifier] as $hookFunction) {
789 t3lib_div::callUserFunction($hookFunction, $hookConfiguration, $this);
790 }
791 }
792 }
793 }
794
795 // Document generation
796 $TYPO3backend = t3lib_div::makeInstance('TYPO3backend');
797
798 // Include extensions which may add css, javascript or toolbar items
799 if (is_array($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'])) {
800 foreach ($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'] as $additionalBackendItem) {
801 include_once($additionalBackendItem);
802 }
803 }
804 // Process ExtJS module js and css
805 if (is_array($GLOBALS['TBE_MODULES']['_configuration'])) {
806 foreach ($GLOBALS['TBE_MODULES']['_configuration'] as $moduleConfig) {
807 if (is_array($moduleConfig['cssFiles'])) {
808 foreach ($moduleConfig['cssFiles'] as $cssFileName => $cssFile) {
809 $files = array(t3lib_div::getFileAbsFileName($cssFile));
810 $files = t3lib_div::removePrefixPathFromList($files, PATH_site);
811 $TYPO3backend->addCssFile($cssFileName, '../' . $files[0]);
812 }
813 }
814 if (is_array($moduleConfig['jsFiles'])) {
815 foreach ($moduleConfig['jsFiles'] as $jsFile) {
816 $files = array(t3lib_div::getFileAbsFileName($jsFile));
817 $files = t3lib_div::removePrefixPathFromList($files, PATH_site);
818 $TYPO3backend->addJavascriptFile('../' . $files[0]);
819 }
820 }
821 }
822 }
823
824 $TYPO3backend->render();
825
826 Typo3_Bootstrap::getInstance()->shutdown();
827
828 ?>