Fixed bug #16311: move workspace-selector to sysext workspaces (Thanks to Tolleiv...
[Packages/TYPO3.CMS.git] / typo3 / backend.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2007-2010 Ingo Renner <ingo@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 require_once('init.php');
29 require_once('template.php');
30 require_once('interfaces/interface.backend_toolbaritem.php');
31
32 require('classes/class.typo3logo.php');
33 require('classes/class.modulemenu.php');
34 require_once('classes/class.donatewindow.php');
35
36 // core toolbar items
37 require('classes/class.clearcachemenu.php');
38 require('classes/class.shortcutmenu.php');
39 require('classes/class.backendsearchmenu.php');
40
41 require_once('class.alt_menu_functions.inc');
42 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_misc.xml');
43
44
45 /**
46 * Class for rendering the TYPO3 backend version 4.2+
47 *
48 * @author Ingo Renner <ingo@typo3.org>
49 * @package TYPO3
50 * @subpackage core
51 */
52 class TYPO3backend {
53
54 protected $content;
55 protected $css;
56 protected $cssFiles;
57 protected $js;
58 protected $jsFiles;
59 protected $jsFilesAfterInline;
60 protected $toolbarItems;
61 private $menuWidthDefault = 190; // intentionally private as nobody should modify defaults
62 protected $menuWidth;
63 protected $debug;
64
65 /**
66 * Object for loading backend modules
67 *
68 * @var t3lib_loadModules
69 */
70 protected $moduleLoader;
71
72 /**
73 * module menu generating object
74 *
75 * @var ModuleMenu
76 */
77 protected $moduleMenu;
78
79 /**
80 * Pagerenderer
81 *
82 * @var t3lib_PageRenderer
83 */
84 protected $pageRenderer;
85
86 /**
87 * constructor
88 *
89 * @return void
90 */
91 public function __construct() {
92 // set debug flag for BE development only
93 $this->debug = intval($GLOBALS['TYPO3_CONF_VARS']['BE']['debug']) === 1;
94
95 // Initializes the backend modules structure for use later.
96 $this->moduleLoader = t3lib_div::makeInstance('t3lib_loadModules');
97 $this->moduleLoader->load($GLOBALS['TBE_MODULES']);
98
99 $this->moduleMenu = t3lib_div::makeInstance('ModuleMenu');
100
101 $this->pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
102 $this->pageRenderer->loadScriptaculous('builder,effects,controls,dragdrop');
103 $this->pageRenderer->loadExtJS();
104
105 $this->pageRenderer->addExtOnReadyCode(
106 'TYPO3.Backend = new TYPO3.Viewport(TYPO3.Viewport.configuration);
107 if (typeof console === "undefined") {
108 console = TYPO3.Backend.DebugConsole;
109 }
110 TYPO3.ContextHelpWindow.init();',
111 TRUE
112 );
113 $this->pageRenderer->addJsInlineCode(
114 'consoleOverrideWithDebugPanel',
115 '//already done'
116 );
117 $this->pageRenderer->addExtDirectCode();
118
119 // add default BE javascript
120 $this->js = '';
121 $this->jsFiles = array(
122 'swfupload' => 'contrib/swfupload/swfupload.js',
123 'swfupload.swfobject' => 'contrib/swfupload/plugins/swfupload.swfobject.js',
124 'swfupload.cookies' => 'contrib/swfupload/plugins/swfupload.cookies.js',
125 'swfupload.queue' => 'contrib/swfupload/plugins/swfupload.queue.js',
126 'md5' => 'md5.js',
127 'common' => 'js/common.js',
128 'toolbarmanager' => 'js/toolbarmanager.js',
129 'modulemenu' => 'js/modulemenu.js',
130 'iecompatibility' => 'js/iecompatibility.js',
131 'flashupload' => 'js/flashupload.js',
132 'evalfield' => '../t3lib/jsfunc.evalfield.js',
133 'flashmessages' => '../t3lib/js/extjs/ux/flashmessages.js',
134 'tabclosemenu' => '../t3lib/js/extjs/ux/ext.ux.tabclosemenu.js',
135 'notifications' => '../t3lib/js/extjs/notifications.js',
136 'backend' => 'js/backend.js',
137 'loginrefresh' => 'js/loginrefresh.js',
138 'debugPanel' => 'js/extjs/debugPanel.js',
139 'viewport' => 'js/extjs/viewport.js',
140 'iframepanel' => 'js/extjs/iframepanel.js',
141 'viewportConfiguration' => 'js/extjs/viewportConfiguration.js',
142 );
143
144 if ($this->debug) {
145 unset($this->jsFiles['loginrefresh']);
146 }
147
148 // add default BE css
149 $this->css = '';
150 $this->cssFiles = array();
151
152 $this->toolbarItems = array();
153 $this->initializeCoreToolbarItems();
154
155 $this->menuWidth = $this->menuWidthDefault;
156 if (isset($GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW']) && (int) $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'] != (int) $this->menuWidth) {
157 $this->menuWidth = (int) $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'];
158 }
159
160 $this->executeHook('constructPostProcess');
161 }
162
163 /**
164 * initializes the core toolbar items
165 *
166 * @return void
167 */
168 protected function initializeCoreToolbarItems() {
169
170 $coreToolbarItems = array(
171 'shortcuts' => 'ShortcutMenu',
172 'clearCacheActions' => 'ClearCacheMenu',
173 'backendSearch' => 'BackendSearchMenu'
174 );
175
176 foreach($coreToolbarItems as $toolbarItemName => $toolbarItemClassName) {
177 $toolbarItem = t3lib_div::makeInstance($toolbarItemClassName, $this);
178
179 if(!($toolbarItem instanceof backend_toolbarItem)) {
180 throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195126772);
181 }
182
183 if($toolbarItem->checkAccess()) {
184 $this->toolbarItems[$toolbarItemName] = $toolbarItem;
185 } else {
186 unset($toolbarItem);
187 }
188 }
189 }
190
191 /**
192 * main function generating the BE scaffolding
193 *
194 * @return void
195 */
196 public function render() {
197 $this->executeHook('renderPreProcess');
198
199 if (t3lib_div::makeInstance('DonateWindow')->isDonateWindowAllowed()) {
200 $this->pageRenderer->addJsFile('js/donate.js');
201 }
202
203 // prepare the scaffolding, at this point extension may still add javascript and css
204 $logo = t3lib_div::makeInstance('TYPO3Logo');
205 $logo->setLogo('gfx/typo3logo_mini.png');
206
207
208
209 // create backend scaffolding
210 $backendScaffolding = '
211 <div id="typo3-top-container" class="x-hide-display">
212 <div id="typo3-logo">'.$logo->render().'</div>
213 <div id="typo3-top" class="typo3-top-toolbar">' .
214 $this->renderToolbar() .
215 '</div>
216 </div>
217
218 ';
219
220 /******************************************************
221 * now put the complete backend document together
222 ******************************************************/
223
224 foreach($this->cssFiles as $cssFileName => $cssFile) {
225 $this->pageRenderer->addCssFile($cssFile);
226
227 // load addditional css files to overwrite existing core styles
228 if(!empty($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName])) {
229 $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName]);
230 }
231 }
232
233 if(!empty($this->css)) {
234 $this->pageRenderer->addCssInlineBlock('BackendInlineCSS', $this->css);
235 }
236
237 foreach ($this->jsFiles as $jsFile) {
238 $this->pageRenderer->addJsFile($jsFile);
239 }
240
241 // Those lines can be removed once we have at least one official ExtDirect router within the backend.
242 $hasExtDirectRouter = FALSE;
243 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'])) {
244 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'] as $key => $value) {
245 if (strpos($key, 'TYPO3.Ajax.ExtDirect') !== FALSE) {
246 $hasExtDirectRouter = TRUE;
247 break;
248 }
249 }
250 }
251 if ($hasExtDirectRouter) {
252 $this->pageRenderer->addJsFile('ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.Ajax.ExtDirect', NULL, FALSE);
253 }
254
255 $this->generateJavascript();
256 $this->pageRenderer->addJsInlineCode('BackendInlineJavascript', $this->js);
257
258
259 // set document title:
260 $title = ($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']
261 ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'].' [TYPO3 '.TYPO3_version.']'
262 : 'TYPO3 '.TYPO3_version
263 );
264
265 // start page header:
266 $this->content .= $GLOBALS['TBE_TEMPLATE']->startPage($title);
267 $this->content .= $backendScaffolding;
268 $this->content .= $GLOBALS['TBE_TEMPLATE']->endPage();
269
270 $hookConfiguration = array('content' => &$this->content);
271 $this->executeHook('renderPostProcess', $hookConfiguration);
272
273 echo $this->content;
274 }
275
276 /**
277 * renders the items in the top toolbar
278 *
279 * @return string top toolbar elements as HTML
280 */
281 protected function renderToolbar() {
282
283 // move search to last position
284 $search = $this->toolbarItems['backendSearch'];
285 unset($this->toolbarItems['backendSearch']);
286 $this->toolbarItems['backendSearch'] = $search;
287
288 $toolbar = '<ul id="typo3-toolbar">';
289 $toolbar.= '<li>'.$this->getLoggedInUserLabel().'</li>
290 <li><div id="logout-button" class="toolbar-item no-separator">'.$this->moduleMenu->renderLogoutButton().'</div></li>';
291
292 foreach($this->toolbarItems as $toolbarItem) {
293 $menu = $toolbarItem->render();
294 if ($menu) {
295 $additionalAttributes = $toolbarItem->getAdditionalAttributes();
296 $toolbar .= '<li' . $additionalAttributes . '>' .$menu. '</li>';
297 }
298 }
299
300 return $toolbar.'</ul>';
301 }
302
303 /**
304 * Gets the label of the BE user currently logged in
305 *
306 * @return string html code snippet displaying the currently logged in user
307 */
308 protected function getLoggedInUserLabel() {
309 global $BE_USER, $BACK_PATH;
310
311 $icon = t3lib_iconWorks::getSpriteIcon('status-user-'. ($BE_USER->isAdmin() ? 'admin' : 'backend'));
312
313 $label = $GLOBALS['BE_USER']->user['realName'] ?
314 $BE_USER->user['realName'] . ' (' . $BE_USER->user['username'] . ')' :
315 $BE_USER->user['username'];
316
317 // Link to user setup if it's loaded and user has access
318 $link = '';
319 if (t3lib_extMgm::isLoaded('setup') && $BE_USER->check('modules','user_setup')) {
320 $link = '<a href="#" onclick="top.goToModule(\'user_setup\');this.blur();return false;">';
321 }
322
323 $username = '">'.$link.$icon.'<span>'.htmlspecialchars($label).'</span>'.($link?'</a>':'');
324
325 // superuser mode
326 if($BE_USER->user['ses_backuserid']) {
327 $username = ' su-user">'.$icon.
328 '<span title="' . $GLOBALS['LANG']->getLL('switchtouser') . '">' .
329 $GLOBALS['LANG']->getLL('switchtousershort') . ' </span>' .
330 '<span>' . htmlspecialchars($label) . '</span>';
331 }
332
333 return '<div id="username" class="toolbar-item no-separator'.$username.'</div>';
334 }
335
336 /**
337 * Generates the JavaScript code for the backend.
338 *
339 * @return void
340 */
341 protected function generateJavascript() {
342
343 $pathTYPO3 = t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')).'/';
344
345 // If another page module was specified, replace the default Page module with the new one
346 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
347 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
348 if (!$GLOBALS['BE_USER']->check('modules', $pageModule)) {
349 $pageModule = '';
350 }
351
352 $menuFrameName = 'menu';
353 if($GLOBALS['BE_USER']->uc['noMenuMode'] === 'icons') {
354 $menuFrameName = 'topmenuFrame';
355 }
356
357 // determine security level from conf vars and default to super challenged
358 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) {
359 $this->loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'];
360 } else {
361 $this->loginSecurityLevel = 'superchallenged';
362 }
363
364 $t3Configuration = array(
365 'siteUrl' => t3lib_div::getIndpEnv('TYPO3_SITE_URL'),
366 'PATH_typo3' => $pathTYPO3,
367 'PATH_typo3_enc' => rawurlencode($pathTYPO3),
368 'username' => htmlspecialchars($GLOBALS['BE_USER']->user['username']),
369 'uniqueID' => t3lib_div::shortMD5(uniqid('')),
370 'securityLevel' => $this->loginSecurityLevel,
371 'TYPO3_mainDir' => TYPO3_mainDir,
372 'pageModule' => $pageModule,
373 'condensedMode' => $GLOBALS['BE_USER']->uc['condensedMode'] ? 1 : 0 ,
374 'inWorkspace' => $GLOBALS['BE_USER']->workspace !== 0 ? 1 : 0,
375 'workspaceFrontendPreviewEnabled' => $GLOBALS['BE_USER']->user['workspace_preview'] ? 1 : 0,
376 'veriCode' => $GLOBALS['BE_USER']->veriCode(),
377 'denyFileTypes' => PHP_EXTENSIONS_DEFAULT,
378 'moduleMenuWidth' => $this->menuWidth - 1,
379 'topBarHeight' => (isset($GLOBALS['TBE_STYLES']['dims']['topFrameH']) ? intval($GLOBALS['TBE_STYLES']['dims']['topFrameH']) : 30),
380 'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? intval($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) : FALSE,
381 'listModulePath' => t3lib_extMgm::isLoaded('list') ? t3lib_extMgm::extRelPath('list') . 'mod1/' : '',
382 'debugInWindow' => $GLOBALS['BE_USER']->uc['debugInWindow'] ? 1 : 0,
383 'ContextHelpWindows' => array(
384 'width' => 600,
385 'height' => 400
386 )
387 );
388 $t3LLLcore = array(
389 'waitTitle' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_logging_in') ,
390 'refresh_login_failed' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed'),
391 'refresh_login_failed_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed_message'),
392 'refresh_login_title' => sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_title'), htmlspecialchars($GLOBALS['BE_USER']->user['username'])),
393 'login_expired' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_expired'),
394 'refresh_login_username' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_username'),
395 'refresh_login_password' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_password'),
396 'refresh_login_emptyPassword' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_emptyPassword'),
397 'refresh_login_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_button'),
398 'refresh_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_logout_button'),
399 'please_wait' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.please_wait'),
400 'loadingIndicator' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:loadingIndicator'),
401 'be_locked' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.be_locked'),
402 'refresh_login_countdown_singular' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown_singular'),
403 'refresh_login_countdown' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown'),
404 'login_about_to_expire' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire'),
405 'login_about_to_expire_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire_title'),
406 'refresh_login_refresh_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_refresh_button'),
407 'refresh_direct_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_direct_logout_button'),
408 'tabs_closeAll' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeAll'),
409 'tabs_closeOther' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeOther'),
410 'tabs_close' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.close'),
411 'tabs_openInBrowserWindow' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.openInBrowserWindow'),
412 'donateWindow_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.title'),
413 'donateWindow_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.message'),
414 'donateWindow_button_donate' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_donate'),
415 'donateWindow_button_disable' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_disable'),
416 'donateWindow_button_postpone' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_postpone'),
417 );
418 $t3LLLfileUpload = array(
419 'windowTitle' => $GLOBALS['LANG']->getLL('fileUpload_windowTitle'),
420 'buttonSelectFiles' => $GLOBALS['LANG']->getLL('fileUpload_buttonSelectFiles'),
421 'buttonCancelAll' => $GLOBALS['LANG']->getLL('fileUpload_buttonCancelAll'),
422 'infoComponentMaxFileSize' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentMaxFileSize'),
423 'infoComponentFileUploadLimit' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentFileUploadLimit'),
424 'infoComponentFileTypeLimit' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentFileTypeLimit'),
425 'infoComponentOverrideFiles' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentOverrideFiles'),
426 'processRunning' => $GLOBALS['LANG']->getLL('fileUpload_processRunning'),
427 'uploadWait' => $GLOBALS['LANG']->getLL('fileUpload_uploadWait'),
428 'uploadStarting' => $GLOBALS['LANG']->getLL('fileUpload_uploadStarting'),
429 'uploadProgress' => $GLOBALS['LANG']->getLL('fileUpload_uploadProgress'),
430 'uploadSuccess' => $GLOBALS['LANG']->getLL('fileUpload_uploadSuccess'),
431 'errorQueueLimitExceeded' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueLimitExceeded'),
432 'errorQueueFileSizeLimit' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueFileSizeLimit'),
433 'errorQueueZeroByteFile' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueZeroByteFile'),
434 'errorQueueInvalidFiletype' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueInvalidFiletype'),
435 'errorUploadHttp' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadHttpError'),
436 'errorUploadMissingUrl' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadMissingUrl'),
437 'errorUploadIO' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadIO'),
438 'errorUploadSecurityError' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadSecurityError'),
439 'errorUploadLimit' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadLimit'),
440 'errorUploadFailed' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFailed'),
441 'errorUploadFileIDNotFound' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileIDNotFound'),
442 'errorUploadFileValidation' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileValidation'),
443 'errorUploadFileCancelled' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileCancelled'),
444 'errorUploadStopped' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadStopped'),
445 'allErrorMessageTitle' => $GLOBALS['LANG']->getLL('fileUpload_allErrorMessageTitle'),
446 'allErrorMessageText' => $GLOBALS['LANG']->getLL('fileUpload_allErrorMessageText'),
447 'allError401' => $GLOBALS['LANG']->getLL('fileUpload_allError401'),
448 'allError2038' => $GLOBALS['LANG']->getLL('fileUpload_allError2038'),
449 );
450
451 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
452 if ($GLOBALS['LANG']->charSet !== 'utf-8') {
453 $t3Configuration['username'] = $GLOBALS['LANG']->csConvObj->conv($t3Configuration['username'], $GLOBALS['LANG']->charSet, 'utf-8');
454 $GLOBALS['LANG']->csConvObj->convArray($t3LLLcore, $GLOBALS['LANG']->charSet, 'utf-8');
455 $GLOBALS['LANG']->csConvObj->convArray($t3LLLfileUpload, $GLOBALS['LANG']->charSet, 'utf-8');
456 }
457
458 $this->js .= '
459 TYPO3.configuration = ' . json_encode($t3Configuration) . ';
460 TYPO3.LLL = {
461 core : ' . json_encode($t3LLLcore) . ',
462 fileUpload: ' . json_encode($t3LLLfileUpload) . '
463 };
464
465 /**
466 * TypoSetup object.
467 */
468 function typoSetup() { //
469 this.PATH_typo3 = TYPO3.configuration.PATH_typo3;
470 this.PATH_typo3_enc = TYPO3.configuration.PATH_typo3_enc;
471 this.username = TYPO3.configuration.username;
472 this.uniqueID = TYPO3.configuration.uniqueID;
473 this.navFrameWidth = 0;
474 this.securityLevel = TYPO3.configuration.securityLevel;
475 this.veriCode = TYPO3.configuration.veriCode;
476 this.denyFileTypes = TYPO3.configuration.denyFileTypes;
477 }
478 var TS = new typoSetup();
479 //backwards compatibility
480 /**
481 * Frameset Module object
482 *
483 * Used in main modules with a frameset for submodules to keep the ID between modules
484 * Typically that is set by something like this in a Web>* sub module:
485 * if (top.fsMod) top.fsMod.recentIds["web"] = "\'.intval($this->id).\'";
486 * if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
487 */
488 function fsModules() { //
489 this.recentIds=new Array(); // used by frameset modules to track the most recent used id for list frame.
490 this.navFrameHighlightedID=new Array(); // used by navigation frames to track which row id was highlighted last time
491 this.currentMainLoaded="";
492 this.currentBank="0";
493 }
494 var fsMod = new fsModules();
495
496 top.goToModule = function(modName, cMR_flag, addGetVars) {
497 TYPO3.ModuleMenu.App.showModule(modName, addGetVars);
498 }
499 ' . $this->setStartupModule();
500
501 // Check editing of page:
502 $this->handlePageEditing();
503
504 }
505
506 /**
507 * Checking if the "&edit" variable was sent so we can open it for editing the page.
508 * Code based on code from "alt_shortcut.php"
509 *
510 * @return void
511 */
512 protected function handlePageEditing() {
513
514 if(!t3lib_extMgm::isLoaded('cms')) {
515 return;
516 }
517
518 // EDIT page:
519 $editId = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('edit'));
520 $editRecord = '';
521
522 if($editId) {
523
524 // Looking up the page to edit, checking permissions:
525 $where = ' AND ('.$GLOBALS['BE_USER']->getPagePermsClause(2)
526 .' OR '.$GLOBALS['BE_USER']->getPagePermsClause(16).')';
527
528 if(t3lib_div::testInt($editId)) {
529 $editRecord = t3lib_BEfunc::getRecordWSOL('pages', $editId, '*', $where);
530 } else {
531 $records = t3lib_BEfunc::getRecordsByField('pages', 'alias', $editId, $where);
532
533 if(is_array($records)) {
534 reset($records);
535 $editRecord = current($records);
536 t3lib_BEfunc::workspaceOL('pages', $editRecord);
537 }
538 }
539
540 // If the page was accessible, then let the user edit it.
541 if(is_array($editRecord) && $GLOBALS['BE_USER']->isInWebMount($editRecord['uid'])) {
542 // Setting JS code to open editing:
543 $this->js .= '
544 // Load page to edit:
545 window.setTimeout("top.loadEditId('.intval($editRecord['uid']).');", 500);
546 ';
547
548 // "Shortcuts" have been renamed to "Bookmarks"
549 // @deprecated remove shortcuts code in TYPO3 4.7
550 $shortcutSetPageTree = $GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree');
551 $bookmarkSetPageTree = $GLOBALS['BE_USER']->getTSConfigVal('options.bookmark_onEditId_dontSetPageTree');
552 if ($shortcutSetPageTree !== '') {
553 t3lib_div::deprecationLog('options.shortcut_onEditId_dontSetPageTree - since TYPO3 4.5, will be removed in TYPO3 4.7 - use options.bookmark_onEditId_dontSetPageTree instead');
554 }
555
556 // Checking page edit parameter:
557 if (!$shortcutSetPageTree && !$bookmarkSetPageTree) {
558
559 $shortcutKeepExpanded = $GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded');
560 $bookmarkKeepExpanded = $GLOBALS['BE_USER']->getTSConfigVal('options.bookmark_onEditId_keepExistingExpanded');
561 $keepExpanded = ($shortcutKeepExpanded || $bookmarkKeepExpanded);
562
563 // Expanding page tree:
564 t3lib_BEfunc::openPageTree(intval($editRecord['pid']), !$keepExpanded);
565
566 if ($shortcutKeepExpanded) {
567 t3lib_div::deprecationLog('options.shortcut_onEditId_keepExistingExpanded - since TYPO3 4.5, will be removed in TYPO3 4.7 - use options.bookmark_onEditId_keepExistingExpanded instead');
568 }
569 }
570 } else {
571 $this->js .= '
572 // Warning about page editing:
573 alert('.$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('noEditPage'), $editId)).');
574 ';
575 }
576 }
577 }
578
579 /**
580 * Sets the startup module from either GETvars module and mpdParams or user configuration.
581 *
582 * @return void
583 */
584 protected function setStartupModule() {
585 $startModule = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('module'));
586
587 if(!$startModule) {
588 if ($GLOBALS['BE_USER']->uc['startModule']) {
589 $startModule = $GLOBALS['BE_USER']->uc['startModule'];
590 } else if($GLOBALS['BE_USER']->uc['startInTaskCenter']) {
591 $startModule = 'user_task';
592 }
593 }
594
595 $moduleParameters = t3lib_div::_GET('modParams');
596 if($startModule) {
597 return '
598 // start in module:
599 top.startInModule = [\'' . $startModule . '\', ' . t3lib_div::quoteJSvalue($moduleParameters) . '];
600 ';
601 } else {
602 return '';
603 }
604
605 }
606
607 /**
608 * adds a javascript snippet to the backend
609 *
610 * @param string javascript snippet
611 * @return void
612 */
613 public function addJavascript($javascript) {
614 // TODO do we need more checks?
615 if(!is_string($javascript)) {
616 throw new InvalidArgumentException('parameter $javascript must be of type string', 1195129553);
617 }
618
619 $this->js .= $javascript;
620 }
621
622 /**
623 * adds a javscript file to the backend after it has been checked that it exists
624 *
625 * @param string javascript file reference
626 * @return boolean true if the javascript file was successfully added, false otherwise
627 */
628 public function addJavascriptFile($javascriptFile) {
629 $jsFileAdded = false;
630
631 //TODO add more checks if neccessary
632 if(file_exists(t3lib_div::resolveBackPath(PATH_typo3.$javascriptFile))) {
633 $this->jsFiles[] = $javascriptFile;
634 $jsFileAdded = true;
635 }
636
637 return $jsFileAdded;
638 }
639
640 /**
641 * adds a css snippet to the backend
642 *
643 * @param string css snippet
644 * @return void
645 */
646 public function addCss($css) {
647 if(!is_string($css)) {
648 throw new InvalidArgumentException('parameter $css must be of type string', 1195129642);
649 }
650
651 $this->css .= $css;
652 }
653
654 /**
655 * adds a css file to the backend after it has been checked that it exists
656 *
657 * @param string the css file's name with out the .css ending
658 * @param string css file reference
659 * @return boolean true if the css file was added, false otherwise
660 */
661 public function addCssFile($cssFileName, $cssFile) {
662 $cssFileAdded = false;
663
664 if(empty($this->cssFiles[$cssFileName])) {
665 $this->cssFiles[$cssFileName] = $cssFile;
666 $cssFileAdded = true;
667 }
668
669 return $cssFileAdded;
670 }
671
672 /**
673 * adds an item to the toolbar, the class file for the toolbar item must be loaded at this point
674 *
675 * @param string toolbar item name, f.e. tx_toolbarExtension_coolItem
676 * @param string toolbar item class name, f.e. tx_toolbarExtension_coolItem
677 * @return void
678 */
679 public function addToolbarItem($toolbarItemName, $toolbarItemClassName) {
680 $toolbarItem = t3lib_div::makeInstance($toolbarItemClassName, $this);
681
682 if(!($toolbarItem instanceof backend_toolbarItem)) {
683 throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195125501);
684 }
685
686 if($toolbarItem->checkAccess()) {
687 $this->toolbarItems[$toolbarItemName] = $toolbarItem;
688 } else {
689 unset($toolbarItem);
690 }
691 }
692
693 /**
694 * Executes defined hooks functions for the given identifier.
695 *
696 * These hook identifiers are valid:
697 * + constructPostProcess
698 * + renderPreProcess
699 * + renderPostProcess
700 *
701 * @param string $identifier Specific hook identifier
702 * @param array $hookConfiguration Additional configuration passed to hook functions
703 * @return void
704 */
705 protected function executeHook($identifier, array $hookConfiguration = array()) {
706 $options =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/backend.php'];
707
708 if(isset($options[$identifier]) && is_array($options[$identifier])) {
709 foreach($options[$identifier] as $hookFunction) {
710 t3lib_div::callUserFunction($hookFunction, $hookConfiguration, $this);
711 }
712 }
713 }
714 }
715
716
717 // include XCLASS
718 if(defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']) {
719 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']);
720 }
721
722
723 // document generation
724 $TYPO3backend = t3lib_div::makeInstance('TYPO3backend');
725
726 // include extensions which may add css, javascript or toolbar items
727 if(is_array($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'])) {
728 foreach($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'] as $additionalBackendItem) {
729 include_once($additionalBackendItem);
730 }
731 }
732
733 $TYPO3backend->render();
734
735 ?>