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