[TASK] Make login_frameset.php dispatched
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / BackendController.php
index 0bbfac3..8dd1a57 100644 (file)
 <?php
 namespace TYPO3\CMS\Backend\Controller;
 
-/***************************************************************
- *  Copyright notice
+/*
+ * This file is part of the TYPO3 CMS project.
  *
- *  (c) 2007-2013 Ingo Renner <ingo@typo3.org>
- *  All rights reserved
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
  *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
  *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *  A copy is found in the text file GPL.txt and important notices to the license
- *  from the author is found in LICENSE.txt distributed with these scripts.
- *
- *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
+ * The TYPO3 project - inspiring people to share!
+ */
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
- * Class for rendering the TYPO3 backend version 4.2+
+ * Class for rendering the TYPO3 backend
  *
  * @author Ingo Renner <ingo@typo3.org>
  */
 class BackendController {
 
-       protected $content;
-
-       protected $css;
-
-       protected $cssFiles;
+       /**
+        * @var string
+        */
+       protected $content = '';
 
-       protected $js;
+       /**
+        * @var string
+        */
+       protected $css = '';
 
-       protected $jsFiles;
+       /**
+        * @var array
+        */
+       protected $cssFiles = array();
 
-       protected $jsFilesAfterInline;
+       /**
+        * @var string
+        */
+       protected $js = '';
 
-       protected $toolbarItems;
+       /**
+        * @var array
+        */
+       protected $jsFiles = array();
 
-       // intentionally private as nobody should modify defaults
-       private $menuWidthDefault = 190;
+       /**
+        * @var array
+        */
+       protected $toolbarItems = array();
 
-       protected $menuWidth;
+       /**
+        * @var int
+        */
+       protected $menuWidth = 190;
 
+       /**
+        * @var bool
+        */
        protected $debug;
 
        /**
-        * Object for loading backend modules
-        *
-        * @var \TYPO3\CMS\Backend\Module\ModuleLoader
+        * @var string
         */
-       protected $moduleLoader;
+       protected $templatePath = 'EXT:backend/Resources/Private/Templates/';
 
        /**
-        * module menu generating object
-        *
-        * @var \TYPO3\CMS\Backend\View\ModuleMenuView
+        * @var \TYPO3\CMS\Backend\Domain\Repository\Module\BackendModuleRepository
         */
-       protected $moduleMenu;
+       protected $backendModuleRepository;
+
+       /**
+        * @var \TYPO3\CMS\Backend\Module\ModuleLoader Object for loading backend modules
+        */
+       protected $moduleLoader;
 
        /**
-        * Pagerenderer
-        *
         * @var \TYPO3\CMS\Core\Page\PageRenderer
         */
        protected $pageRenderer;
 
        /**
+        * @return \TYPO3\CMS\Core\Page\PageRenderer
+        */
+       public function getPageRenderer() {
+               return $this->pageRenderer;
+       }
+
+       /**
         * Constructor
         */
        public function __construct() {
+               $this->backendModuleRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Domain\Repository\Module\BackendModuleRepository::class);
+
                // Set debug flag for BE development only
-               $this->debug = intval($GLOBALS['TYPO3_CONF_VARS']['BE']['debug']) === 1;
+               $this->debug = (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] === 1;
                // Initializes the backend modules structure for use later.
-               $this->moduleLoader = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Module\\ModuleLoader');
+               $this->moduleLoader = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Module\ModuleLoader::class);
                $this->moduleLoader->load($GLOBALS['TBE_MODULES']);
-               $this->moduleMenu = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\View\\ModuleMenuView');
                $this->pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
-               $this->pageRenderer->loadScriptaculous('builder,effects,controls,dragdrop');
                $this->pageRenderer->loadExtJS();
+               // included for the module menu JavaScript, please note that this is subject to change
+               $this->pageRenderer->loadJquery();
                $this->pageRenderer->enableExtJSQuickTips();
                $this->pageRenderer->addJsInlineCode('consoleOverrideWithDebugPanel', '//already done', FALSE);
                $this->pageRenderer->addExtDirectCode();
                // Add default BE javascript
-               $this->js = '';
                $this->jsFiles = array(
-                       'common' => 'sysext/backend/Resources/Public/JavaScript/common.js',
                        'locallang' => $this->getLocalLangFileName(),
                        'modernizr' => 'contrib/modernizr/modernizr.min.js',
                        'md5' => 'sysext/backend/Resources/Public/JavaScript/md5.js',
-                       'toolbarmanager' => 'sysext/backend/Resources/Public/JavaScript/toolbarmanager.js',
                        'modulemenu' => 'sysext/backend/Resources/Public/JavaScript/modulemenu.js',
-                       'iecompatibility' => 'sysext/backend/Resources/Public/JavaScript/iecompatibility.js',
                        'evalfield' => 'sysext/backend/Resources/Public/JavaScript/jsfunc.evalfield.js',
-                       'flashmessages' => 'sysext/backend/Resources/Public/JavaScript/flashmessages.js',
                        'tabclosemenu' => 'js/extjs/ux/ext.ux.tabclosemenu.js',
                        'notifications' => 'sysext/backend/Resources/Public/JavaScript/notifications.js',
                        'backend' => 'sysext/backend/Resources/Public/JavaScript/backend.js',
-                       'loginrefresh' => 'sysext/backend/Resources/Public/JavaScript/loginrefresh.js',
                        'debugPanel' => 'js/extjs/debugPanel.js',
                        'viewport' => 'js/extjs/viewport.js',
                        'iframepanel' => 'sysext/backend/Resources/Public/JavaScript/iframepanel.js',
                        'backendcontentiframe' => 'js/extjs/backendcontentiframe.js',
-                       'modulepanel' => 'js/extjs/modulepanel.js',
                        'viewportConfiguration' => 'js/extjs/viewportConfiguration.js',
                        'util' => 'sysext/backend/Resources/Public/JavaScript/util.js'
                );
-               if ($this->debug) {
-                       unset($this->jsFiles['loginrefresh']);
+               if (!$this->debug) {
+                       $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LoginRefresh', 'function(LoginRefresh) {
+                               LoginRefresh.setLoginFramesetUrl(' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('login_frameset')) . ');
+                       }');
                }
-               // Add default BE css
+
+               // load FlashMessages functionality
+               $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/FlashMessages');
+
+               // load Modals
+               $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
+
+               // load Legacy CSS Support
+               $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LegacyCssClasses');
+
+               // load the storage API and fill the UC into the PersistentStorage, so no additional AJAX call is needed
+               $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Storage', 'function(Storage) {
+                       Storage.Persistent.load(' . json_encode($GLOBALS['BE_USER']->uc) . ');
+               }');
                $this->css = '';
-               $this->cssFiles = array();
-               $this->toolbarItems = array();
-               $this->initializeCoreToolbarItems();
-               $this->menuWidth = $this->menuWidthDefault;
-               if (isset($GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW']) && (int) $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'] != (int) $this->menuWidth) {
-                       $this->menuWidth = (int) $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'];
+
+               $this->initializeToolbarItems();
+               if (isset($GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'])) {
+                       $this->menuWidth = (int)$GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'];
                }
                $this->executeHook('constructPostProcess');
        }
 
        /**
-        * Initializes the core toolbar items
+        * Initialize toolbar item objects
         *
+        * @throws \RuntimeException
         * @return void
         */
-       protected function initializeCoreToolbarItems() {
-               $coreToolbarItems = array(
-                       'shortcuts' => 'TYPO3\\CMS\\Backend\\Toolbar\\ShortcutToolbarItem',
-                       'clearCacheActions' => 'TYPO3\\CMS\\Backend\\Toolbar\\ClearCacheToolbarItem',
-                       'liveSearch' => '\\TYPO3\\CMS\\Backend\\Toolbar\\LiveSearchToolbarItem'
-               );
-               foreach ($coreToolbarItems as $toolbarItemName => $toolbarItemClassName) {
-                       $toolbarItem = GeneralUtility::makeInstance($toolbarItemClassName, $this);
-                       if (!$toolbarItem instanceof \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookInterface) {
-                               throw new \UnexpectedValueException('$toolbarItem "' . $toolbarItemName . '" must implement interface TYPO3\\CMS\\Backend\\Toolbar\\ToolbarItemHookInterface', 1195126772);
+       protected function initializeToolbarItems() {
+               $toolbarItemInstances = array();
+               $classNameRegistry = $GLOBALS['TYPO3_CONF_VARS']['BE']['toolbarItems'];
+               foreach ($classNameRegistry as $className) {
+                       $toolbarItemInstance = GeneralUtility::makeInstance($className);
+                       if (!$toolbarItemInstance instanceof \TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface) {
+                               throw new \RuntimeException(
+                                       'class ' . $className . ' is registered as toolbar item but does not implement'
+                                               . \TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface::class,
+                                       1415958218
+                               );
                        }
-                       if ($toolbarItem->checkAccess()) {
-                               $this->toolbarItems[$toolbarItemName] = $toolbarItem;
-                       } else {
-                               unset($toolbarItem);
+                       $index = (int)$toolbarItemInstance->getIndex();
+                       if ($index < 0 || $index > 100) {
+                               throw new \RuntimeException(
+                                       'getIndex() must return an integer between 0 and 100',
+                                       1415968498
+                               );
+                       }
+                       // Find next free position in array
+                       while(array_key_exists($index, $toolbarItemInstances)) {
+                               $index++;
                        }
+                       $toolbarItemInstances[$index] = $toolbarItemInstance;
                }
+               ksort($toolbarItemInstances);
+               $this->toolbarItems = $toolbarItemInstances;
        }
 
        /**
@@ -168,20 +199,18 @@ class BackendController {
                $this->executeHook('renderPreProcess');
 
                // Prepare the scaffolding, at this point extension may still add javascript and css
-               $logo = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\View\\LogoView');
-
-               // Create backend scaffolding
-               $backendScaffolding = '
-               <div id="typo3-top-container" class="x-hide-display">
-                       <div id="typo3-logo">' . $logo->render() . '</div>
-                       <div id="typo3-top" class="typo3-top-toolbar">' . $this->renderToolbar() . '</div>
-               </div>';
+               $view = $this->getFluidTemplateObject($this->templatePath . 'Backend/Main.html');
+               // @todo: kick logo view class and move all logic to Fluid
+               $view->assign('logo', GeneralUtility::makeInstance(\TYPO3\CMS\Backend\View\LogoView::class)->render());
+               $view->assign('moduleMenu', $this->generateModuleMenu());
+               $view->assign('toolbar', $this->renderToolbar());
+
                /******************************************************
                 * Now put the complete backend document together
                 ******************************************************/
                foreach ($this->cssFiles as $cssFileName => $cssFile) {
                        $this->pageRenderer->addCssFile($cssFile);
-                       // Load addditional css files to overwrite existing core styles
+                       // Load additional css files to overwrite existing core styles
                        if (!empty($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName])) {
                                $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName]);
                        }
@@ -195,6 +224,7 @@ class BackendController {
                $this->generateJavascript();
                $this->pageRenderer->addJsInlineCode('BackendInlineJavascript', $this->js, FALSE);
                $this->loadResourcesForRegisteredNavigationComponents();
+
                // Add state provider
                $GLOBALS['TBE_TEMPLATE']->setExtDirectStateProvider();
                $states = $GLOBALS['BE_USER']->uc['BackendComponents']['States'];
@@ -205,21 +235,22 @@ class BackendController {
                                autoRead: false
                        }));
                ';
+
                if ($states) {
                        $extOnReadyCode .= 'Ext.state.Manager.getProvider().initState(' . json_encode($states) . ');';
                }
+
                $extOnReadyCode .= '
                        TYPO3.Backend = new TYPO3.Viewport(TYPO3.Viewport.configuration);
                        if (typeof console === "undefined") {
                                console = TYPO3.Backend.DebugConsole;
                        }
-                       TYPO3.ContextHelpWindow.init();';
+                       TYPO3.ContextHelpWindow.init(' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('help_cshmanual')) . ');';
                $this->pageRenderer->addExtOnReadyCode($extOnReadyCode);
                // Set document title:
                $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . ' [TYPO3 CMS ' . TYPO3_version . ']' : 'TYPO3 CMS ' . TYPO3_version;
-               $this->content = $backendScaffolding;
                // Renders the module page
-               $this->content = $GLOBALS['TBE_TEMPLATE']->render($title, $this->content);
+               $this->content = $GLOBALS['TBE_TEMPLATE']->render($title, $view->render());
                $hookConfiguration = array('content' => &$this->content);
                $this->executeHook('renderPostProcess', $hookConfiguration);
                echo $this->content;
@@ -269,6 +300,7 @@ class BackendController {
                        foreach ($jsFiles as $jsFile) {
                                $this->pageRenderer->addJsFile($relativeComponentPath . 'javascript/' . $jsFile);
                        }
+                       $this->pageRenderer->addInlineSetting('RecordHistory', 'moduleUrl', BackendUtility::getModuleUrl('record_history'));
                }
        }
 
@@ -278,58 +310,54 @@ class BackendController {
         * @return string top toolbar elements as HTML
         */
        protected function renderToolbar() {
-               // Move search to last position
-               if (array_key_exists('liveSearch', $this->toolbarItems)) {
-                       $search = $this->toolbarItems['liveSearch'];
-                       unset($this->toolbarItems['liveSearch']);
-                       $this->toolbarItems['liveSearch'] = $search;
-               }
-               $toolbar = '<ul id="typo3-toolbar">';
-               $toolbar .= '<li>' . $this->getLoggedInUserLabel() . '</li>';
-               $toolbar .= '<li class="separator"><div id="logout-button" class="toolbar-item no-separator">' . $this->moduleMenu->renderLogoutButton() . '</div></li>';
-               $i = 0;
-               foreach ($this->toolbarItems as $key => $toolbarItem) {
-                       $i++;
-                       $menu = $toolbarItem->render();
-                       if ($menu) {
-                               $additionalAttributes = $toolbarItem->getAdditionalAttributes();
-                               if (sizeof($this->toolbarItems) > 1 && $i == sizeof($this->toolbarItems) - 1) {
-                                       if (strpos($additionalAttributes, 'class="')) {
-                                               str_replace('class="', 'class="separator ', $additionalAttributes);
-                                       } else {
-                                               $additionalAttributes .= 'class="separator"';
-                                       }
+               $toolbar = array();
+               foreach ($this->toolbarItems as $toolbarItem) {
+                       /** @var \TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface $toolbarItem */
+                       if ($toolbarItem->checkAccess()) {
+                               $hasDropDown = (bool)$toolbarItem->hasDropDown();
+                               $additionalAttributes = (array)$toolbarItem->getAdditionalAttributes();
+
+                               $liAttributes = array();
+
+                               // Merge class: Add dropdown class if hasDropDown, add classes from additonal attributes
+                               $classes = array();
+                               if ($hasDropDown) {
+                                       $classes[] = 'dropdown';
                                }
-                               $toolbar .= '<li ' . $additionalAttributes . '>' . $menu . '</li>';
-                       }
-               }
-               return $toolbar . '</ul>';
-       }
+                               if (isset($additionalAttributes['class'])) {
+                                       $classes[] = $additionalAttributes['class'];
+                                       unset($additionalAttributes['class']);
+                               }
+                               $liAttributes[] = 'class="' . implode(' ', $classes) . '"';
 
-       /**
-        * Gets the label of the BE user currently logged in
-        *
-        * @return string Html code snippet displaying the currently logged in user
-        */
-       protected function getLoggedInUserLabel() {
-               $css = 'toolbar-item';
-               $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('status-user-' . ($GLOBALS['BE_USER']->isAdmin() ? 'admin' : 'backend'));
-               $realName = $GLOBALS['BE_USER']->user['realName'];
-               $username = $GLOBALS['BE_USER']->user['username'];
-               $label = $realName ?: $username;
-               $title = $username;
-               // Link to user setup if it's loaded and user has access
-               $link = '';
-               if (ExtensionManagementUtility::isLoaded('setup') && $GLOBALS['BE_USER']->check('modules', 'user_setup')) {
-                       $link = '<a href="#" onclick="top.goToModule(\'user_setup\'); this.blur(); return false;">';
-               }
-               // Superuser mode
-               if ($GLOBALS['BE_USER']->user['ses_backuserid']) {
-                       $css .= ' su-user';
-                       $title = $GLOBALS['LANG']->getLL('switchtouser') . ': ' . $username;
-                       $label = $GLOBALS['LANG']->getLL('switchtousershort') . ' ' . ($realName ? $realName . ' (' . $username . ')' : $username);
+                               // Add further attributes
+                               foreach($additionalAttributes as $name => $value) {
+                                       $liAttributes[] = $name . '="' . $value . '"';
+                               }
+
+                               // Create a unique id from class name
+                               $className = get_class($toolbarItem);
+                               $className = GeneralUtility::underscoredToLowerCamelCase($className);
+                               $className = GeneralUtility::camelCaseToLowerCaseUnderscored($className);
+                               $className = str_replace(array('_', '\\'), '-', $className);
+                               $liAttributes[] = 'id="' . $className . '"';
+
+                               $toolbar[] = '<li ' . implode(' ', $liAttributes) . '>';
+
+                               if ($hasDropDown) {
+                                       $toolbar[] = '<a href="#" class="dropdown-toggle" data-toggle="dropdown">';
+                                       $toolbar[] = $toolbarItem->getItem();
+                                       $toolbar[] = '</a>';
+                                       $toolbar[] = '<div class="dropdown-menu" role="menu">';
+                                       $toolbar[] = $toolbarItem->getDropDown();
+                                       $toolbar[] = '</div>';
+                               } else {
+                                       $toolbar[] = $toolbarItem->getItem();
+                               }
+                               $toolbar[] = '</li>';
+                       }
                }
-               return '<div id="username" class="' . $css . '">' . $link . $icon . '<span title="' . htmlspecialchars($title) . '">' . htmlspecialchars($label) . '</span>' . ($link ? '</a>' : '') . '</div>';
+               return implode(LF, $toolbar);
        }
 
        /**
@@ -452,6 +480,26 @@ class BackendController {
         * @return void
         */
        protected function generateJavascript() {
+
+               // Needed for FormEngine manipulation (date picker)
+               $dateFormat = ($GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'] ? array('MM-DD-YYYY', 'HH:mm MM-DD-YYYY') : array('DD-MM-YYYY', 'HH:mm DD-MM-YYYY'));
+               $this->pageRenderer->addInlineSetting('DateTimePicker', 'DateFormat', $dateFormat);
+               // define the window size of the element browser etc.
+               $popupWindowSize = trim($GLOBALS['BE_USER']->getTSConfigVal('options.popupWindowSize'));
+               if (!empty($popupWindowSize)) {
+                       list($popupWindowWidth, $popupWindowHeight) = GeneralUtility::trimExplode('x', $popupWindowSize);
+               }
+               $popupWindowWidth  = !empty($popupWindowWidth) ? (int)$popupWindowWidth : 700;
+               $popupWindowHeight = !empty($popupWindowHeight) ? (int)$popupWindowHeight : 750;
+
+               // define the window size of the popups within the RTE
+               $rtePopupWindowSize = trim($GLOBALS['BE_USER']->getTSConfigVal('options.rte.popupWindowSize'));
+               if (!empty($rtePopupWindowSize)) {
+                       list($rtePopupWindowWidth, $rtePopupWindowHeight) = GeneralUtility::trimExplode('x', $rtePopupWindowSize);
+               }
+               $rtePopupWindowWidth  = !empty($rtePopupWindowWidth) ? (int)$rtePopupWindowWidth : ($popupWindowWidth-200);
+               $rtePopupWindowHeight = !empty($rtePopupWindowHeight) ? (int)$rtePopupWindowHeight : ($popupWindowHeight-250);
+
                $pathTYPO3 = GeneralUtility::dirname(GeneralUtility::getIndpEnv('SCRIPT_NAME')) . '/';
                // If another page module was specified, replace the default Page module with the new one
                $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
@@ -459,10 +507,6 @@ class BackendController {
                if (!$GLOBALS['BE_USER']->check('modules', $pageModule)) {
                        $pageModule = '';
                }
-               $menuFrameName = 'menu';
-               if ($GLOBALS['BE_USER']->uc['noMenuMode'] === 'icons') {
-                       $menuFrameName = 'topmenuFrame';
-               }
                // Determine security level from conf vars and default to super challenged
                if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) {
                        $this->loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'];
@@ -474,24 +518,31 @@ class BackendController {
                        'PATH_typo3' => $pathTYPO3,
                        'PATH_typo3_enc' => rawurlencode($pathTYPO3),
                        'username' => htmlspecialchars($GLOBALS['BE_USER']->user['username']),
-                       'uniqueID' => GeneralUtility::shortMD5(uniqid('')),
+                       'uniqueID' => GeneralUtility::shortMD5(uniqid('', TRUE)),
                        'securityLevel' => $this->loginSecurityLevel,
                        'TYPO3_mainDir' => TYPO3_mainDir,
                        'pageModule' => $pageModule,
-                       'condensedMode' => $GLOBALS['BE_USER']->uc['condensedMode'] ? 1 : 0,
-                       'inWorkspace' => $GLOBALS['BE_USER']->workspace !== 0 ? 1 : 0,
+                       'inWorkspace' => $GLOBALS['BE_USER']->workspace !== 0,
                        'workspaceFrontendPreviewEnabled' => $GLOBALS['BE_USER']->user['workspace_preview'] ? 1 : 0,
                        'veriCode' => $GLOBALS['BE_USER']->veriCode(),
                        'denyFileTypes' => PHP_EXTENSIONS_DEFAULT,
                        'moduleMenuWidth' => $this->menuWidth - 1,
-                       'topBarHeight' => isset($GLOBALS['TBE_STYLES']['dims']['topFrameH']) ? intval($GLOBALS['TBE_STYLES']['dims']['topFrameH']) : 30,
-                       'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? intval($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) : FALSE,
-                       'listModulePath' => ExtensionManagementUtility::isLoaded('recordlist') ? ExtensionManagementUtility::extRelPath('recordlist') . 'mod1/' : '',
+                       'topBarHeight' => isset($GLOBALS['TBE_STYLES']['dims']['topFrameH']) ? (int)$GLOBALS['TBE_STYLES']['dims']['topFrameH'] : 30,
+                       'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup'] : FALSE,
+                       'listModulePath' => ExtensionManagementUtility::extRelPath('recordlist') . 'mod1/',
                        'debugInWindow' => $GLOBALS['BE_USER']->uc['debugInWindow'] ? 1 : 0,
                        'ContextHelpWindows' => array(
                                'width' => 600,
                                'height' => 400
                        ),
+                       'PopupWindow' => array(
+                               'width' => $popupWindowWidth,
+                               'height' => $popupWindowHeight
+                       ),
+                       'RTEPopupWindow' => array(
+                               'width' => $rtePopupWindowWidth,
+                               'height' => $rtePopupWindowHeight
+                       )
                );
                $this->js .= '
        TYPO3.configuration = ' . json_encode($t3Configuration) . ';
@@ -516,7 +567,7 @@ class BackendController {
         *
         * Used in main modules with a frameset for submodules to keep the ID between modules
         * Typically that is set by something like this in a Web>* sub module:
-        *              if (top.fsMod) top.fsMod.recentIds["web"] = "\'.intval($this->id).\'";
+        *              if (top.fsMod) top.fsMod.recentIds["web"] = "\'.(int)$this->id.\'";
         *              if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
         */
        function fsModules() {  //
@@ -541,9 +592,6 @@ class BackendController {
         * @return void
         */
        protected function handlePageEditing() {
-               if (!ExtensionManagementUtility::isLoaded('cms')) {
-                       return;
-               }
                // EDIT page:
                $editId = preg_replace('/[^[:alnum:]_]/', '', GeneralUtility::_GET('edit'));
                $editRecord = '';
@@ -564,38 +612,55 @@ class BackendController {
                                // Setting JS code to open editing:
                                $this->js .= '
                // Load page to edit:
-       window.setTimeout("top.loadEditId(' . intval($editRecord['uid']) . ');", 500);
+       window.setTimeout("top.loadEditId(' . (int)$editRecord['uid'] . ');", 500);
                        ';
                                // Checking page edit parameter:
                                if (!$GLOBALS['BE_USER']->getTSConfigVal('options.bookmark_onEditId_dontSetPageTree')) {
                                        $bookmarkKeepExpanded = $GLOBALS['BE_USER']->getTSConfigVal('options.bookmark_onEditId_keepExistingExpanded');
                                        // Expanding page tree:
-                                       BackendUtility::openPageTree(intval($editRecord['pid']), !$bookmarkKeepExpanded);
+                                       BackendUtility::openPageTree((int)$editRecord['pid'], !$bookmarkKeepExpanded);
                                }
                        } else {
                                $this->js .= '
                // Warning about page editing:
-       alert(' . $GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('noEditPage'), $editId)) . ');
+       alert(' . GeneralUtility::quoteJSvalue(sprintf($GLOBALS['LANG']->getLL('noEditPage'), $editId)) . ');
                        ';
                        }
                }
        }
 
        /**
-        * Sets the startup module from either GETvars module and mpdParams or user configuration.
+        * Sets the startup module from either GETvars module and modParams or user configuration.
         *
-        * @return void
+        * @return string the JavaScript code for the startup module
         */
        protected function setStartupModule() {
                $startModule = preg_replace('/[^[:alnum:]_]/', '', GeneralUtility::_GET('module'));
                if (!$startModule) {
-                       if ($GLOBALS['BE_USER']->uc['startModule']) {
+                       // start module on first login, will be removed once used the first time
+                       if (isset($GLOBALS['BE_USER']->uc['startModuleOnFirstLogin'])) {
+                               $startModule = $GLOBALS['BE_USER']->uc['startModuleOnFirstLogin'];
+                               unset($GLOBALS['BE_USER']->uc['startModuleOnFirstLogin']);
+                               $GLOBALS['BE_USER']->writeUC();
+                       } elseif ($GLOBALS['BE_USER']->uc['startModule']) {
                                $startModule = $GLOBALS['BE_USER']->uc['startModule'];
                        } elseif ($GLOBALS['BE_USER']->uc['startInTaskCenter']) {
                                $startModule = 'user_task';
                        }
+
+                       // check if the start module has additional parameters, so a redirect to a specific
+                       // action is possible
+                       if (strpos($startModule, '->') !== FALSE) {
+                               list($startModule, $startModuleParameters) = explode('->', $startModule, 2);
+                       }
                }
+
                $moduleParameters = GeneralUtility::_GET('modParams');
+               // if no GET parameters are set, check if there are parameters given from the UC
+               if (!$moduleParameters && $startModuleParameters) {
+                       $moduleParameters = $startModuleParameters;
+               }
+
                if ($startModule) {
                        return '
                                        // start in module:
@@ -607,13 +672,14 @@ class BackendController {
        }
 
        /**
-        * Sdds a javascript snippet to the backend
+        * Adds a javascript snippet to the backend
         *
         * @param string $javascript Javascript snippet
         * @return void
+        * @throws \InvalidArgumentException
         */
        public function addJavascript($javascript) {
-               // TODO do we need more checks?
+               // @todo do we need more checks?
                if (!is_string($javascript)) {
                        throw new \InvalidArgumentException('parameter $javascript must be of type string', 1195129553);
                }
@@ -624,11 +690,11 @@ class BackendController {
         * Adds a javscript file to the backend after it has been checked that it exists
         *
         * @param string $javascriptFile Javascript file reference
-        * @return boolean TRUE if the javascript file was successfully added, FALSE otherwise
+        * @return bool TRUE if the javascript file was successfully added, FALSE otherwise
         */
        public function addJavascriptFile($javascriptFile) {
                $jsFileAdded = FALSE;
-               //TODO add more checks if neccessary
+               // @todo add more checks if necessary
                if (file_exists(GeneralUtility::resolveBackPath(PATH_typo3 . $javascriptFile))) {
                        $this->jsFiles[] = $javascriptFile;
                        $jsFileAdded = TRUE;
@@ -654,7 +720,7 @@ class BackendController {
         *
         * @param string $cssFileName The css file's name with out the .css ending
         * @param string $cssFile Css file reference
-        * @return boolean TRUE if the css file was added, FALSE otherwise
+        * @return bool TRUE if the css file was added, FALSE otherwise
         */
        public function addCssFile($cssFileName, $cssFile) {
                $cssFileAdded = FALSE;
@@ -671,17 +737,11 @@ class BackendController {
         * @param string $toolbarItemName Toolbar item name, f.e. tx_toolbarExtension_coolItem
         * @param string $toolbarItemClassName Toolbar item class name, f.e. tx_toolbarExtension_coolItem
         * @return void
+        * @throws \UnexpectedValueException
+        * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8. Toolbar items are registered in $GLOBALS['TYPO3_CONF_VARS']['BE']['toolbarItems'] now.
         */
        public function addToolbarItem($toolbarItemName, $toolbarItemClassName) {
-               $toolbarItem = GeneralUtility::makeInstance($toolbarItemClassName, $this);
-               if (!$toolbarItem instanceof \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookInterface) {
-                       throw new \UnexpectedValueException('$toolbarItem "' . $toolbarItemName . '" must implement interface TYPO3\\CMS\\Backend\\Toolbar\\ToolbarItemHookInterface', 1195125501);
-               }
-               if ($toolbarItem->checkAccess()) {
-                       $this->toolbarItems[$toolbarItemName] = $toolbarItem;
-               } else {
-                       unset($toolbarItem);
-               }
+               GeneralUtility::logDeprecatedFunction();
        }
 
        /**
@@ -705,4 +765,46 @@ class BackendController {
                }
        }
 
+       /**
+        * loads all modules from the repository
+        * and renders it with a template
+        *
+        * @return string
+        */
+       protected function generateModuleMenu() {
+               // get all modules except the user modules for the side menu
+               $moduleStorage = $this->backendModuleRepository->loadAllowedModules(array('user', 'help'));
+
+               $view = $this->getFluidTemplateObject($this->templatePath . 'ModuleMenu/Main.html');
+               $view->assign('modules', $moduleStorage);
+               return $view->render();
+       }
+
+       /**
+        * Returns the Module menu for the AJAX API
+        *
+        * @param array $params
+        * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxRequestHandler
+        * @return void
+        */
+       public function getModuleMenuForReload($params, $ajaxRequestHandler) {
+               $content = $this->generateModuleMenu();
+               $ajaxRequestHandler->addContent('menu', $content);
+               $ajaxRequestHandler->setContentFormat('json');
+       }
+
+       /**
+        * returns a new standalone view, shorthand function
+        *
+        * @param string $templatePathAndFileName optional the path to set the template path and filename
+        * @return \TYPO3\CMS\Fluid\View\StandaloneView
+        */
+       protected function getFluidTemplateObject($templatePathAndFileName = NULL) {
+               $view = GeneralUtility::makeInstance(\TYPO3\CMS\Fluid\View\StandaloneView::class);
+               if ($templatePathAndFileName) {
+                       $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templatePathAndFileName));
+               }
+               return $view;
+       }
+
 }