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