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