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