[BUGFIX] Adjustments to FAL-enabled RTE image and link dialogues
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / class.tx_rtehtmlarea_base.php
index a276718..f45ece2 100644 (file)
@@ -4,7 +4,7 @@
 *
 *  (c) 2004-2011 Kasper Skårhøj (kasper@typo3.com)
 *  (c) 2004-2011 Philipp Borgmann <philipp.borgmann@gmx.de>
-*  (c) 2004-2011 Stanislas Rolland <typo3(arobas)sjbr.ca>
+*  (c) 2004-2012 Stanislas Rolland <typo3(arobas)sjbr.ca>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  *
  * @author     Philipp Borgmann <philipp.borgmann@gmx.de>
  * @author     Stanislas Rolland <typo3(arobas)sjbr.ca>
- *
- * $Id$  *
  */
 
 class tx_rtehtmlarea_base extends t3lib_rteapi {
                // Configuration of supported browsers
        var $conf_supported_browser = array (
                        'msie' => array (
-                               1 => array (
-                                       'version' => 6.0,
-                                       'system' => 'winNT'
-                               ),
-                               2 => array (
+                               array (
                                        'version' => 6.0,
-                                       'system' => 'win98'
+                                       'system' => array(
+                                               'allowed' => array(
+                                                       'winNT',
+                                                       'win98',
+                                                       'win95',
+                                               ),
+                                       ),
                                ),
-                               3 => array (
-                                       'version' => 6.0,
-                                       'system' => 'win95'
-                               )
                        ),
                        'gecko' => array (
-                               1 => array (
-                                       'version' => 1.8
-                               )
+                               array (
+                                       'version' => 1.8,
+                               ),
                        ),
                        'webkit' => array (
-                               1 => array (
+                               array (
                                        'version' => 523,
-                                       'system' => 'mac'
+                                       'system' => array(
+                                               'disallowed' => array(
+                                                       'iOS',
+                                                       'android',
+                                               ),
+                                       ),
                                ),
-                               2 => array (
-                                       'version' => 523,
-                                       'system' => 'winNT'
-                               ),
-                               3 => array (
-                                       'version' => 523,
-                                       'system' => 'linux'
-                               ),
-                               4 => array (
-                                       'version' => 523,
-                                       'system' => 'win98'
-                               ),
-                               5 => array (
-                                       'version' => 523,
-                                       'system' => 'win95'
-                               )
                        ),
                        'opera' => array (
-                               1 => array (
-                                       'version' => 9.62
-                               )
+                               array (
+                                       'version' => 9.62,
+                                       'system' => array(
+                                               'disallowed' => array(
+                                                       'iOS',
+                                                       'android',
+                                               ),
+                                       ),
+                               ),
                        )
                );
 
@@ -139,50 +130,73 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
        public $language;
        public $contentTypo3Language;
        public $contentISOLanguage;
-       public $contentCharset;
-       public $OutputCharset;
+       public $charset = 'utf-8';
+       public $contentCharset = 'utf-8';
+       public $OutputCharset = 'utf-8';
        var $editorCSS;
        var $specConf;
        var $toolbar = array();                                 // Save the buttons for the toolbar
        var $toolbarOrderArray = array();
        protected $pluginEnabledArray = array();                // Array of plugin id's enabled in the current RTE editing area
        protected $pluginEnabledCumulativeArray = array();      // Cumulative array of plugin id's enabled so far in any of the RTE editing areas of the form
-       protected $cumulativeScripts = array();
        public $registeredPlugins = array();                    // Array of registered plugins indexed by their plugin Id's
-       protected $fullScreen = false;
+       protected $fullScreen = FALSE;
+       protected $pageRenderer;
 
        /**
-        * Returns true if the RTE is available. Here you check if the browser requirements are met.
+        * Returns TRUE if the RTE is available. Here you check if the browser requirements are met.
         * If there are reasons why the RTE cannot be displayed you simply enter them as text in ->errorLog
         *
         * @return      boolean         TRUE if this RTE object offers an RTE in the current browser environment
         */
-
        function isAvailable()  {
-               global $TYPO3_CONF_VARS;
 
                $this->client = $this->clientInfo();
                $this->errorLog = array();
                if (!$this->debugMode)  {       // If debug-mode, let any browser through
-                       $rteIsAvailable = 0;
+                       $rteIsAvailable = FALSE;
                        $rteConfBrowser = $this->conf_supported_browser;
                        if (is_array($rteConfBrowser)) {
                                foreach ($rteConfBrowser as $browser => $browserConf) {
                                        if ($browser == $this->client['browser']) {
                                                        // Config for Browser found, check it:
                                                if (is_array($browserConf)) {
-                                                       foreach ($browserConf as $browserConfNr => $browserConfSub) {
+                                                       foreach ($browserConf as $browserConfSub) {
                                                                if ($browserConfSub['version'] <= $this->client['version'] || empty($browserConfSub['version'])) {
-                                                                       // Version is correct
-                                                                       if ($browserConfSub['system'] == $this->client['system'] || empty($browserConfSub['system'])) {
-                                                                                       // System is correctly
-                                                                               $rteIsAvailable = 1;
+                                                                               // Version is supported
+                                                                       if (is_array($browserConfSub['system'])) {
+                                                                                       // Check against allowed systems
+                                                                               if (is_array($browserConfSub['system']['allowed'])) {
+                                                                                       foreach ($browserConfSub['system']['allowed'] as $system) {
+                                                                                               if (in_array($system, $this->client['all_systems'])) {
+                                                                                                       $rteIsAvailable = TRUE;
+                                                                                                       break;
+                                                                                               }
+                                                                                       }
+                                                                               } else {
+                                                                                               // All allowed
+                                                                                       $rteIsAvailable = TRUE;
+                                                                               }
+                                                                                       // Check against disallowed systems
+                                                                               if (is_array($browserConfSub['system']['disallowed'])) {
+                                                                                       foreach ($browserConfSub['system']['disallowed'] as $system) {
+                                                                                               if (in_array($system, $this->client['all_systems'])) {
+                                                                                                       $rteIsAvailable = FALSE;
+                                                                                                       break;
+                                                                                               }
+                                                                                       }
+                                                                               }
+                                                                       } else {
+                                                                                       // No system config: system is supported
+                                                                               $rteIsAvailable = TRUE;
+                                                                               break;
                                                                        }// End of System
                                                                }// End of Version
                                                        }// End of foreach-BrowserSubpart
                                                } else {
                                                        // no config for this browser found, so all versions or system with this browsers are allow
-                                                       $rteIsAvailable = 1;
+                                                       $rteIsAvailable = TRUE;
+                                                       break;
                                                }
                                        } // End of Browser Check
                                } // foreach: Browser Check
@@ -190,14 +204,14 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                // no Browser config for this RTE-Editor, so all Clients are allow
                        }
                        if (!$rteIsAvailable) {
-                               $this->errorLog[] = 'rte: Browser not supported. Only msie Version 5 or higher and Mozilla based client 1. and higher.';
+                               $this->errorLog[] = 'RTE: Browser not supported.';
                        }
-                       if (t3lib_div::int_from_ver(TYPO3_version) < 4000000) {
-                               $rteIsAvailable = 0;
+                       if (t3lib_utility_VersionNumber::convertVersionNumberToInteger(TYPO3_version) < 4000000) {
+                               $rteIsAvailable = FALSE;
                                $this->errorLog[] = 'rte: This version of htmlArea RTE cannot run under this version of TYPO3.';
                        }
                }
-               if ($rteIsAvailable)    return true;
+               return $rteIsAvailable;
        }
 
        /**
@@ -217,14 +231,14 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         */
 
        function drawRTE($parentObject, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue) {
-               global $BE_USER, $LANG, $TYPO3_DB, $TYPO3_CONF_VARS;
+               global $LANG, $TYPO3_DB, $TYPO3_CONF_VARS;
 
                $this->TCEform = $parentObject;
                $inline = $this->TCEform->inline;
                $LANG->includeLLFile('EXT:' . $this->ID . '/locallang.xml');
                $this->client = $this->clientInfo();
-               $this->typoVersion = t3lib_div::int_from_ver(TYPO3_version);
-               $this->userUid = 'BE_' . $BE_USER->user['uid'];
+               $this->typoVersion = t3lib_utility_VersionNumber::convertVersionNumberToInteger(TYPO3_version);
+               $this->userUid = 'BE_' . $GLOBALS['BE_USER']->user['uid'];
 
                        // Draw form element:
                if ($this->debugMode)   {       // Draws regular text area (debug mode)
@@ -254,7 +268,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
 
                                // Find "thisConfig" for record/editor:
                        unset($this->RTEsetup);
-                       $this->RTEsetup = $BE_USER->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($this->tscPID));
+                       $this->RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', t3lib_BEfunc::getPagesTSconfig($this->tscPID));
                        $this->thisConfig = $thisConfig;
 
                                // Special configuration and default extras:
@@ -265,6 +279,10 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                $this->siteURL = preg_replace('/^(http|https)/', 'https', $this->siteURL);
                                $this->hostURL = preg_replace('/^(http|https)/', 'https', $this->hostURL);
                        }
+                               // Register RTE windows
+                       $this->TCEform->RTEwindows[] = $PA['itemFormElName'];
+                       $textAreaId = preg_replace('/[^a-zA-Z0-9_:.-]/', '_', $PA['itemFormElName']);
+                       $textAreaId = htmlspecialchars(preg_replace('/^[^a-zA-Z]/', 'x', $textAreaId));
 
                        /* =======================================
                         * LANGUAGES & CHARACTER SETS
@@ -273,10 +291,10 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
 
                                // Languages: interface and content
                        $this->language = $LANG->lang;
-                       if ($this->language=='default' || !$this->language)     {
-                               $this->language='en';
+                       if ($this->language == 'default' || !$this->language)   {
+                               $this->language = 'en';
                        }
-                       $this->contentTypo3Language = $this->language;
+                       $this->contentTypo3Language = ($this->language == 'en') ? 'default' : $this->language;
                        $this->contentISOLanguage = 'en';
                        $this->contentLanguageUid = ($row['sys_language_uid'] > 0) ? $row['sys_language_uid'] : 0;
                        if (t3lib_extMgm::isLoaded('static_info_tables')) {
@@ -292,7 +310,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                        $res = $TYPO3_DB->exec_SELECTquery($selectFields, $tableAB, $whereClause);
                                        while($languageRow = $TYPO3_DB->sql_fetch_assoc($res)) {
                                                $this->contentISOLanguage = strtolower(trim($languageRow['lg_iso_2']).(trim($languageRow['lg_country_iso_2'])?'_'.trim($languageRow['lg_country_iso_2']):''));
-                                               $this->contentTypo3Language = strtolower(trim($languageRow['lg_typo3']));
+                                               $this->contentTypo3Language = trim($languageRow['lg_typo3']) ? strtolower(trim($languageRow['lg_typo3'])) : 'default';
                                        }
                                } else {
                                        $this->contentISOLanguage = trim($this->thisConfig['defaultContentLanguage']) ? trim($this->thisConfig['defaultContentLanguage']) : 'en';
@@ -301,20 +319,11 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                        $whereClause = 'lg_iso_2 = ' . $TYPO3_DB->fullQuoteStr(strtoupper($this->contentISOLanguage), $tableAB);
                                        $res = $TYPO3_DB->exec_SELECTquery($selectFields, $tableAB, $whereClause);
                                        while($languageRow = $TYPO3_DB->sql_fetch_assoc($res)) {
-                                               $this->contentTypo3Language = strtolower(trim($languageRow['lg_typo3']));
+                                               $this->contentTypo3Language = trim($languageRow['lg_typo3']) ? strtolower(trim($languageRow['lg_typo3'])) : 'default';
                                        }
                                }
                        }
 
-                               // Character sets: interface and content
-                       $this->charset = $LANG->charSet;
-                       $this->OutputCharset = $this->charset;
-
-                       $this->contentCharset = $LANG->csConvObj->charSetArray[$this->contentTypo3Language];
-                       $this->contentCharset = $this->contentCharset ? $this->contentCharset : 'iso-8859-1';
-                       $this->origContentCharSet = $this->contentCharset;
-                       $this->contentCharset = (trim($TYPO3_CONF_VARS['BE']['forceCharset']) ? trim($TYPO3_CONF_VARS['BE']['forceCharset']) : $this->contentCharset);
-
                        /* =======================================
                         * TOOLBAR CONFIGURATION
                         * =======================================
@@ -325,47 +334,58 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                         * SET STYLES
                         * =======================================
                         */
-
-                       $RTEWidth = isset($BE_USER->userTS['options.']['RTESmallWidth']) ? $BE_USER->userTS['options.']['RTESmallWidth'] : '530';
-                       $RTEHeight = isset($BE_USER->userTS['options.']['RTESmallHeight']) ? $BE_USER->userTS['options.']['RTESmallHeight'] : '380';
-                       $RTEWidth  = $RTEWidth + ($this->TCEform->docLarge ? (isset($BE_USER->userTS['options.']['RTELargeWidthIncrement']) ? $BE_USER->userTS['options.']['RTELargeWidthIncrement'] : '150') : 0);
-                       $RTEWidth -= ($inline->getStructureDepth() > 0 ? ($inline->getStructureDepth()+1)*$inline->getLevelMargin() : 0);
-                       $RTEWidthOverride = (is_object($GLOBALS['BE_USER']) && isset($GLOBALS['BE_USER']->uc['rteWidth']) && trim($GLOBALS['BE_USER']->uc['rteWidth'])) ? trim($GLOBALS['BE_USER']->uc['rteWidth']) : trim($this->thisConfig['RTEWidthOverride']);
-                       if ($RTEWidthOverride) {
-                               if (strstr($RTEWidthOverride, '%')) {
-                                       if ($this->client['browser'] != 'msie') {
-                                               $RTEWidth = (intval($RTEWidthOverride) > 0) ? $RTEWidthOverride : '100%';
+                               // Check if wizard_rte called this for fullscreen edtition
+                       if (basename(PATH_thisScript) == 'wizard_rte.php') {
+                               $this->fullScreen = TRUE;
+                               $RTEWidth = '100%';
+                               $RTEHeight = '100%';
+                               $RTEPaddingRight = '0';
+                               $editorWrapWidth = '100%';
+                       } else {
+                               $RTEWidth = isset($GLOBALS['BE_USER']->userTS['options.']['RTESmallWidth']) ? $GLOBALS['BE_USER']->userTS['options.']['RTESmallWidth'] : '530';
+                               $RTEHeight = isset($GLOBALS['BE_USER']->userTS['options.']['RTESmallHeight']) ? $GLOBALS['BE_USER']->userTS['options.']['RTESmallHeight'] : '380';
+                               $RTEWidth  = $RTEWidth + ($this->TCEform->docLarge ? (isset($GLOBALS['BE_USER']->userTS['options.']['RTELargeWidthIncrement']) ? $GLOBALS['BE_USER']->userTS['options.']['RTELargeWidthIncrement'] : '150') : 0);
+                               $RTEWidth -= ($inline->getStructureDepth() > 0 ? ($inline->getStructureDepth()+1)*$inline->getLevelMargin() : 0);
+                               $RTEWidthOverride = (is_object($GLOBALS['BE_USER']) && isset($GLOBALS['BE_USER']->uc['rteWidth']) && trim($GLOBALS['BE_USER']->uc['rteWidth'])) ? trim($GLOBALS['BE_USER']->uc['rteWidth']) : trim($this->thisConfig['RTEWidthOverride']);
+                               if ($RTEWidthOverride) {
+                                       if (strstr($RTEWidthOverride, '%')) {
+                                               if ($this->client['browser'] != 'msie') {
+                                                       $RTEWidth = (intval($RTEWidthOverride) > 0) ? $RTEWidthOverride : '100%';
+                                               }
+                                       } else {
+                                               $RTEWidth = (intval($RTEWidthOverride) > 0) ? intval($RTEWidthOverride) : $RTEWidth;
                                        }
-                               } else {
-                                       $RTEWidth = (intval($RTEWidthOverride) > 0) ? intval($RTEWidthOverride) : $RTEWidth;
                                }
+                               $RTEWidth = strstr($RTEWidth, '%') ? $RTEWidth :  $RTEWidth . 'px';
+                               $RTEHeight = $RTEHeight + ($this->TCEform->docLarge ?  (isset($GLOBALS['BE_USER']->userTS['options.']['RTELargeHeightIncrement']) ? $GLOBALS['BE_USER']->userTS['options.']['RTELargeHeightIncrement'] : 0) : 0);
+                               $RTEHeightOverride = (is_object($GLOBALS['BE_USER']) && isset($GLOBALS['BE_USER']->uc['rteHeight']) && intval($GLOBALS['BE_USER']->uc['rteHeight'])) ? intval($GLOBALS['BE_USER']->uc['rteHeight']) : intval($this->thisConfig['RTEHeightOverride']);
+                               $RTEHeight = ($RTEHeightOverride > 0) ? $RTEHeightOverride : $RTEHeight;
+                               $RTEPaddingRight = '2px';
+                               $editorWrapWidth = '99%';
                        }
-                       $RTEWidth = strstr($RTEWidth, '%') ? $RTEWidth :  $RTEWidth . 'px';
-                       $RTEHeight = $RTEHeight + ($this->TCEform->docLarge ?  (isset($BE_USER->userTS['options.']['RTELargeHeightIncrement']) ? $BE_USER->userTS['options.']['RTELargeHeightIncrement'] : 0) : 0);
-                       $RTEHeightOverride = (is_object($GLOBALS['BE_USER']) && isset($GLOBALS['BE_USER']->uc['rteHeight']) && intval($GLOBALS['BE_USER']->uc['rteHeight'])) ? intval($GLOBALS['BE_USER']->uc['rteHeight']) : intval($this->thisConfig['RTEHeightOverride']);
-                       $RTEHeight = ($RTEHeightOverride > 0) ? $RTEHeightOverride : $RTEHeight;
-                       $editorWrapWidth = '99%';
                        $editorWrapHeight = '100%';
-                       $this->RTEdivStyle = 'position:relative; left:0px; top:0px; height:' . $RTEHeight . 'px; width:'.$RTEWidth.'; border: 1px solid black; padding: 2px 2px 2px 2px;';
-
+                       $this->RTEdivStyle = 'position:relative; left:0px; top:0px; height:' . $RTEHeight . 'px; width:' . $RTEWidth . '; border: 1px solid black; padding: 2px ' . $RTEPaddingRight . ' 2px 2px;';
                        /* =======================================
                         * LOAD CSS AND JAVASCRIPT
                         * =======================================
                         */
+                       $this->pageRenderer = $GLOBALS['SOBE']->doc->getPageRenderer();
                                // Preloading the pageStyle and including RTE skin stylesheets
                        $this->addPageStyle();
                        $this->addSkin();
-                               // Loading JavaScript files and code
-                       if ($this->TCEform->RTEcounter == 1) {
-                               $this->TCEform->additionalJS_pre['rtehtmlarea-loadJScode'] = $this->loadJScode($this->TCEform->RTEcounter);
-                       }
-                       $this->TCEform->additionalCode_pre['rtehtmlarea-loadJSfiles'] = $this->loadJSfiles($this->TCEform->RTEcounter);
-                       $pageRenderer = $GLOBALS['SOBE']->doc->getPageRenderer();
-                       $pageRenderer->enableExtJSQuickTips();
-                       if (!$GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableCompressedScripts']) {
-                               $pageRenderer->enableExtJsDebug();
-                       }
-                       $pageRenderer->addJsFile('../t3lib/js/extjs/notifications.js');
+                               // Register RTE in JS
+                       $this->TCEform->additionalJS_post[] = $this->registerRTEinJS($this->TCEform->RTEcounter, $table, $row['uid'], $field, $textAreaId);
+                               // Set the save option for the RTE
+                       $this->TCEform->additionalJS_submit[] = $this->setSaveRTE($this->TCEform->RTEcounter, $this->TCEform->formName, $textAreaId, $PA['itemFormElName']);
+                       $this->TCEform->additionalJS_delete[] = $this->setDeleteRTE($this->TCEform->RTEcounter, $this->TCEform->formName, $textAreaId);
+                               // Loading ExtJs inline code
+                       $this->pageRenderer->enableExtJSQuickTips();
+                               // Add TYPO3 notifications JavaScript
+                       $this->pageRenderer->addJsFile('../t3lib/js/extjs/notifications.js');
+                               // Add RTE JavaScript
+                       $this->addRteJsFiles($this->TCEform->RTEcounter);
+                       $this->pageRenderer->addJsFile($this->buildJSMainLangFile($this->TCEform->RTEcounter));
+                       $this->pageRenderer->addJsInlineCode('HTMLArea-init', $this->getRteInitJsCode(), TRUE);
                        /* =======================================
                         * DRAW THE EDITOR
                         * =======================================
@@ -380,34 +400,13 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                        $value = $plugin->transformContent($value);
                                }
                        }
-                               // Register RTE windows
-                       $this->TCEform->RTEwindows[] = $PA['itemFormElName'];
-                       $textAreaId = preg_replace('/[^a-zA-Z0-9_:.-]/', '_', $PA['itemFormElName']);
-                       $textAreaId = htmlspecialchars(preg_replace('/^[^a-zA-Z]/', 'x', $textAreaId));
-
-                               // Check if wizard_rte called this for fullscreen edtition; if so, change the size of the RTE to fullscreen using JS
-                       if (basename(PATH_thisScript) == 'wizard_rte.php') {
-                               $this->fullScreen = true;
-                               $editorWrapWidth = '100%';
-                               $editorWrapHeight = '100%';
-                               $this->RTEdivStyle = 'position:relative; left:0px; top:0px; height:100%; width:100%; border: 1px solid black; padding: 2px 0px 2px 2px;';
-                       }
-
-                               // Register RTE in JS:
-                       $this->TCEform->additionalJS_post[] = $this->registerRTEinJS($this->TCEform->RTEcounter, $table, $row['uid'], $field, $textAreaId);
-
-                               // Set the save option for the RTE:
-                       $this->TCEform->additionalJS_submit[] = $this->setSaveRTE($this->TCEform->RTEcounter, $this->TCEform->formName, $textAreaId, $PA['itemFormElName']);
-                       $this->TCEform->additionalJS_delete[] = $this->setDeleteRTE($this->TCEform->RTEcounter, $this->TCEform->formName, $textAreaId);
-
                                // Draw the textarea
                        $visibility = 'hidden';
                        $item = $this->triggerField($PA['itemFormElName']).'
                                <div id="pleasewait' . $textAreaId . '" class="pleasewait" style="display: block;" >' . $LANG->getLL('Please wait') . '</div>
                                <div id="editorWrap' . $textAreaId . '" class="editorWrap" style="visibility: hidden; width:' . $editorWrapWidth . '; height:' . $editorWrapHeight . ';">
                                <textarea id="RTEarea' . $textAreaId . '" name="'.htmlspecialchars($PA['itemFormElName']).'" rows="0" cols="0" style="'.t3lib_div::deHSCentities(htmlspecialchars($this->RTEdivStyle)).'">'.t3lib_div::formatForTextarea($value).'</textarea>
-                               </div>' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableDebugMode'] ? '<div id="HTMLAreaLog"></div>' : '') . '
-                               ';
+                               </div>' . LF;
                }
 
                        // Return form item:
@@ -420,14 +419,34 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         * @return      void
         */
        protected function addPageStyle() {
-                       // Get stylesheet file name from Page TSConfig if any
-               $filename = trim($this->thisConfig['contentCSS']) ? trim($this->thisConfig['contentCSS']) : 'EXT:' . $this->ID . '/res/contentcss/default.css';
                $this->addStyleSheet(
                        'rtehtmlarea-page-style',
-                       $this->getFullFileName($filename),
+                       $this->getContentCssFileName(),
                        'htmlArea RTE Content CSS',
                        'alternate stylesheet'
-                       );
+               );
+       }
+
+       /**
+        * Get the name of the contentCSS file to use
+        *
+        * @return      the full file name of the content css file to use
+        */
+       protected function getContentCssFileName() {
+                       // Get stylesheet file name from Page TSConfig if any
+               $fileName = trim($this->thisConfig['contentCSS']);
+               if ($fileName) {
+                       $fileName = $this->getFullFileName($fileName);
+               }
+               $absolutePath = $fileName
+                       ? t3lib_div::resolveBackPath(PATH_site . (($this->is_FE() || $this->isFrontendEditActive()) ? '' : TYPO3_mainDir) . $fileName)
+                       : '';
+
+                       // Fallback to default content css file if configured file does not exists or is of zero size
+               if (!$fileName || !file_exists($absolutePath) || !filesize($absolutePath)) {
+                       $fileName = $this->getFullFileName('EXT:' . $this->ID . '/res/contentcss/default.css');
+               }
+               return $fileName;
        }
 
        /**
@@ -480,8 +499,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                if (is_object($this->TCEform->inline) && $this->TCEform->inline->isAjaxCall) {
                        $this->TCEform->additionalCode_pre[$key] = '<link rel="' . $relation . '" type="text/css" href="' . $href . '" title="' . $title. '" />';
                } else {
-                       $pageRenderer = $GLOBALS['SOBE']->doc->getPageRenderer();
-                       $pageRenderer->addCssFile($href, $relation, 'screen', $title);
+                       $this->pageRenderer->addCssFile($href, $relation, 'screen', $title);
                }
        }
 
@@ -517,7 +535,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                        // Traverse registered plugins
                if (is_array($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['plugins'])) {
                        foreach($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['plugins'] as $pluginId => $pluginObjectConfiguration) {
-                               $plugin = false;
+                               $plugin = FALSE;
                                if (is_array($pluginObjectConfiguration) && count($pluginObjectConfiguration)) {
                                        $plugin = t3lib_div::getUserObj($pluginObjectConfiguration['objectReference']);
                                }
@@ -556,8 +574,6 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         */
 
        function setToolbar() {
-               global $BE_USER;
-
                if ($this->client['browser'] == 'msie' || $this->client['browser'] == 'opera') {
                        $this->thisConfig['keepButtonGroupTogether'] = 0;
                }
@@ -568,7 +584,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        bar, left, center, right, justifyfull,
                        bar, orderedlist, unorderedlist, definitionlist, definitionitem, outdent, indent,  bar, lefttoright, righttoleft, language, showlanguagemarks,
                        bar, textcolor, bgcolor, textindicator,
-                       bar, editelement, emoticon, insertcharacter, link, unlink, image, table,' . (($this->thisConfig['hideTableOperationsInToolbar'] && is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['toggleborders.']) && $this->thisConfig['buttons.']['toggleborders.']['keepInToolbar']) ? ' toggleborders,': '') . ' user, acronym, bar, findreplace, spellcheck,
+                       bar, editelement, showmicrodata, emoticon, insertcharacter, insertsofthyphen, link, unlink, image, table,' . (($this->thisConfig['hideTableOperationsInToolbar'] && is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['toggleborders.']) && $this->thisConfig['buttons.']['toggleborders.']['keepInToolbar']) ? ' toggleborders,': '') . ' user, acronym, bar, findreplace, spellcheck,
                        bar, chMode, inserttag, removeformat, bar, copy, cut, paste, pastetoggle, pastebehaviour, bar, undo, redo, bar, showhelp, about, linebreak,
                        ' . ($this->thisConfig['hideTableOperationsInToolbar'] ? '': 'bar, toggleborders,') . ' bar, tableproperties, tablerestyle, bar, rowproperties, rowinsertabove, rowinsertunder, rowdelete, rowsplit, bar,
                        columnproperties, columninsertbefore, columninsertafter, columndelete, columnsplit, bar,
@@ -608,8 +624,8 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                }
 
                        // Resticting to RTEkeyList for backend user
-               if(is_object($BE_USER)) {
-                       $RTEkeyList = isset($BE_USER->userTS['options.']['RTEkeyList']) ? $BE_USER->userTS['options.']['RTEkeyList'] : '*';
+               if(is_object($GLOBALS['BE_USER'])) {
+                       $RTEkeyList = isset($GLOBALS['BE_USER']->userTS['options.']['RTEkeyList']) ? $GLOBALS['BE_USER']->userTS['options.']['RTEkeyList'] : '*';
                        if ($RTEkeyList != '*') {       // If not all
                                $show = array_intersect($show, t3lib_div::trimExplode(',',$RTEkeyList,1));
                        }
@@ -657,11 +673,11 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                $hidePlugins = array();
                foreach ($this->pluginButton as $pluginId => $buttonList) {
                        if ($this->registeredPlugins[$pluginId]->addsButtons()) {
-                               $showPlugin = false;
+                               $showPlugin = FALSE;
                                $buttonArray = t3lib_div::trimExplode(',', $buttonList, 1);
                                foreach ($buttonArray as $button) {
                                        if (in_array($button, $this->toolbar)) {
-                                               $showPlugin = true;
+                                               $showPlugin = TRUE;
                                        }
                                }
                                if (!$showPlugin) {
@@ -702,41 +718,37 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        }
                }
        }
-
        /**
         * Convert the TYPO3 names of buttons into the names for htmlArea RTE
         *
         * @param       string  buttonname (typo3-name)
+        *
         * @return      string  buttonname (htmlarea-name)
         */
-
-        function convertToolbarForHTMLArea($button) {
+       function convertToolbarForHTMLArea($button) {
                return $this->convertToolbarForHtmlAreaArray[$button];
-        }
+       }
        /**
-        * Return the HTML code for loading the Javascript files
+        * Add RTE main scripts and plugin scripts
         *
-        * @param       integer         $RTEcounter: The index number of the current RTE editing area within the form.
+        * @param string $RTEcounter:  The index number of the current RTE editing area within the form.
         *
-        * @return      string          the html code for loading the Javascript Files
-        */
-       function loadJSfiles($RTEcounter) {
-                       // Re-initialize the scripts array so that only the cumulative set of plugins of the last RTE on the page is used
-               $this->cumulativeScripts[$RTEcounter] = array();
-               $this->writeTemporaryFile('EXT:' . $this->ID . '/htmlarea/htmlarea.js', 'htmlarea', 'js', '', TRUE);
-               if ($this->client['browser'] == 'msie') {
-                       $this->writeTemporaryFile('EXT:' . $this->ID . '/htmlarea/htmlarea-ie.js', 'htmlarea-ie', 'js', '', TRUE);
-               } else {
-                       $this->writeTemporaryFile('EXT:' . $this->ID . '/htmlarea/htmlarea-gecko.js', 'htmlarea-gecko', 'js', '', TRUE);
-               }
+        * @return void
+        */
+       protected function addRteJsFiles($RTEcounter) {
+               $this->pageRenderer->addJsFile($this->getFullFileName('EXT:' . $this->ID . '/htmlarea/htmlarea.js'));
                foreach ($this->pluginEnabledCumulativeArray[$RTEcounter] as $pluginId) {
                        $extensionKey = is_object($this->registeredPlugins[$pluginId]) ? $this->registeredPlugins[$pluginId]->getExtensionKey() : $this->ID;
-                       $this->writeTemporaryFile('EXT:' . $extensionKey . '/htmlarea/plugins/' . $pluginId . '/' . strtolower(preg_replace('/([a-z])([A-Z])([a-z])/', "$1".'-'."$2"."$3", $pluginId)) . '.js', $pluginId, 'js', '', TRUE);
+                       $this->pageRenderer->addJsFile($this->getFullFileName('EXT:' . $extensionKey . '/htmlarea/plugins/' . $pluginId . '/' . strtolower(preg_replace('/([a-z])([A-Z])([a-z])/', "$1".'-'."$2"."$3", $pluginId)) . '.js'));
                }
-               $this->buildJSMainLangFile($RTEcounter);
-                       // Avoid re-initialization on AJax call when RTEarea object was already initialized
-               $loadJavascriptCode = '<script type="text/javascript" src="' . $this->doConcatenate($RTEcounter) . '"></script>'. LF;
-               $loadJavascriptCode .= t3lib_div::wrapJS('
+       }
+       /**
+        * Return RTE initialization inline JavaScript code
+        *
+        * @return string RTE initialization inline JavaScript code
+        */
+       protected function getRteInitJsCode() {
+               return '
                        if (typeof(RTEarea) == "undefined") {
                                RTEarea = new Object();
                                RTEarea[0] = new Object();
@@ -746,38 +758,24 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                RTEarea[0].editorSkin = "' . dirname($this->editorCSS) . '/";
                                RTEarea[0].editedContentCSS = "' . t3lib_div::createVersionNumberedFilename($this->editedContentCSS)  . '";
                                RTEarea[0].hostUrl = "' . $this->hostURL . '";
-                               RTEarea[0].enableDebugMode = ' . ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableDebugMode'] ? 'true' : 'false') . ';
                                RTEarea.init = function() {
                                        if (typeof(HTMLArea) == "undefined" || !Ext.isReady) {
-                                               window.setTimeout("RTEarea.init();", 40);
+                                               window.setTimeout("RTEarea.init();", 10);
                                        } else {
                                                Ext.QuickTips.init();
                                                HTMLArea.init();
                                        }
                                };
                                RTEarea.initEditor = function(editorNumber) {
-                                       if (typeof(HTMLArea) == "undefined") {
+                                       if (typeof(HTMLArea) == "undefined" || !HTMLArea.isReady) {
                                                RTEarea.initEditor.defer(40, null, [editorNumber]);
                                        } else {
                                                HTMLArea.initEditor(editorNumber);
                                        }
                                };
-                       }'
-               );
-               return $loadJavascriptCode;
-       }
-
-       /**
-        * Return the Javascript code for initializing the RTE
-        *
-        * @param       integer         $RTEcounter: The index number of the current RTE editing area within the form.
-        *
-        * @return      string          the Javascript code for initializing the RTE
-        */
-       function loadJScode($RTEcounter) {
-               return TAB . 'RTEarea.init();';
+                       }
+                       RTEarea.init();';
        }
-
        /**
         * Return the Javascript code for configuring the RTE
         *
@@ -820,13 +818,26 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        RTEarea[editornumber].disablePCexamples = ' . (trim($this->thisConfig['disablePCexamples'])?'true':'false') . ';
                        RTEarea[editornumber].showTagFreeClasses = ' . (trim($this->thisConfig['showTagFreeClasses'])?'true':'false') . ';
                        RTEarea[editornumber].useHTTPS = ' . ((trim(stristr($this->siteURL, 'https')) || $this->thisConfig['forceHTTPS'])?'true':'false') . ';
-                       RTEarea[editornumber].tceformsNested = ' . (is_object($this->TCEform) && method_exists($this->TCEform, 'getDynNestedStack') ? $this->TCEform->getDynNestedStack(true) : '[]') . ';
-                       RTEarea[editornumber].dialogueWindows = new Object();
-                       RTEarea[editornumber].dialogueWindows.defaultPositionFromTop = ' . (isset($this->thisConfig['dialogueWindows.']['defaultPositionFromTop'])? intval($this->thisConfig['dialogueWindows.']['defaultPositionFromTop']) : '100') . ';
-                       RTEarea[editornumber].dialogueWindows.defaultPositionFromLeft = ' . (isset($this->thisConfig['dialogueWindows.']['defaultPositionFromLeft'])? intval($this->thisConfig['dialogueWindows.']['defaultPositionFromLeft']) : '100') . ';
-                       RTEarea[editornumber].dialogueWindows.doNotResize = ' . (trim($this->thisConfig['dialogueWindows.']['doNotResize'])?'true':'false') . ';
-                       RTEarea[editornumber].dialogueWindows.doNotCenter = ' . (trim($this->thisConfig['dialogueWindows.']['doNotCenter'])?'true':'false') . ';';
-
+                       RTEarea[editornumber].tceformsNested = ' . (is_object($this->TCEform) && method_exists($this->TCEform, 'getDynNestedStack') ? $this->TCEform->getDynNestedStack(TRUE) : '[]') . ';
+                       RTEarea[editornumber].dialogueWindows = new Object();';
+                       // The following property is deprecated as of TYPO3 4.6 and will be removed in TYPO3 4.8
+               if (isset($this->thisConfig['showTagFreeClasses'])) {
+                       $this->logDeprecatedProperty('showTagFreeClasses', 'buttons.blockstyle.showTagFreeClasses', '4.8');
+                       $this->logDeprecatedProperty('showTagFreeClasses', 'buttons.textstyle.showTagFreeClasses', '4.8');
+               }
+                       // The following property is deprecated as of TYPO3 4.6 and will be removed in TYPO3 4.8
+               if (isset($this->thisConfig['disablePCexamples'])) {
+                       $this->logDeprecatedProperty('disablePCexamples', 'buttons.blockstyle.disableStyleOnOptionLabel', '4.8');
+                       $this->logDeprecatedProperty('disablePCexamples', 'buttons.textstyle.disableStyleOnOptionLabel', '4.8');
+               }
+               if (isset($this->thisConfig['dialogueWindows.']['defaultPositionFromTop'])) {
+                       $configureRTEInJavascriptString .= '
+                       RTEarea[editornumber].dialogueWindows.positionFromTop = ' . intval($this->thisConfig['dialogueWindows.']['defaultPositionFromTop']) . ';';
+               }
+               if (isset($this->thisConfig['dialogueWindows.']['defaultPositionFromLeft'])) {
+                       $configureRTEInJavascriptString .= '
+                       RTEarea[editornumber].dialogueWindows.positionFromLeft = ' . intval($this->thisConfig['dialogueWindows.']['defaultPositionFromLeft']) . ';';
+               }
                        // The following properties apply only to the backend
                if (!$this->is_FE()) {
                        $configureRTEInJavascriptString .= '
@@ -872,19 +883,28 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                }
 
                        // Setting the list of tags to be removed with their contents if specified in the RTE config
-               if (trim($this->thisConfig['removeTagsAndContents']))  {
+               if (trim($this->thisConfig['removeTagsAndContents'])) {
                        $configureRTEInJavascriptString .= '
                        RTEarea[editornumber].htmlRemoveTagsAndContents = /^(' . implode('|', t3lib_div::trimExplode(',', $this->thisConfig['removeTagsAndContents'], 1)) . ')$/i;';
                }
+                       // Setting array of custom tags if specified in the RTE config
+               if (!empty($this->thisConfig['customTags'])) {
+                       $customTags = t3lib_div::trimExplode(',', $this->thisConfig['customTags'], 1);
+                       if (!empty($customTags)) {
+                               $configureRTEInJavascriptString .= '
+                               RTEarea[editornumber].customTags= ' . json_encode($customTags) . ';';
+                       }
+               }
                        // Process default style configuration
+                       // This default configuration is deprecated as of TYPO3 4.6 and will be removed in TYPO3 4.8.
+                       // Use contentCSS instead.
                $configureRTEInJavascriptString .= '
                        RTEarea[editornumber].defaultPageStyle = "' . $this->writeTemporaryFile('', 'defaultPageStyle', 'css', $this->buildStyleSheet()) . '";';
                        // Setting the pageStyle
-               $filename = trim($this->thisConfig['contentCSS']) ? trim($this->thisConfig['contentCSS']) : 'EXT:' . $this->ID . '/res/contentcss/default.css';
                $configureRTEInJavascriptString .= '
-                       RTEarea[editornumber].pageStyle = "' . t3lib_div::createVersionNumberedFilename($this->getFullFileName($filename)) .'";';
+                       RTEarea[editornumber].pageStyle = "' . t3lib_div::createVersionNumberedFilename($this->getContentCssFileName()) .'";';
                        // Process classes configuration
-               $classesConfigurationRequired = false;
+               $classesConfigurationRequired = FALSE;
                foreach ($this->registeredPlugins as $pluginId => $plugin) {
                        if ($this->isPluginEnabled($pluginId)) {
                                $classesConfigurationRequired = $classesConfigurationRequired || $plugin->requiresClassesConfiguration();
@@ -911,11 +931,11 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
        }
 
        /**
-        * Return true, if the plugin can be loaded
+        * Return TRUE, if the plugin can be loaded
         *
         * @param       string          $pluginId: The identification string of the plugin
         *
-        * @return      boolean         true if the plugin can be loaded
+        * @return      boolean         TRUE if the plugin can be loaded
         */
 
        function isPluginEnabled($pluginId) {
@@ -926,12 +946,26 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         * Build the default content style sheet
         *
         * @return string               Style sheet
+        * @deprecated since TYPO3 4.8, will be removed in TYPO3 4.10
         */
        function buildStyleSheet() {
-
+                       // This function will be DEPRECATED as of TYPO3 4.8 and will be removed in TYPO3 4.10
+               //t3lib_div::logDeprecatedFunction();
+                       // These PageTSConfig properties are DEPRECATED as of TYPO3 4.6 and will be removed in TYPO3 4.8
+               $properties = array('mainStyle_font', 'mainStyle_size', 'mainStyle_color', 'mainStyle_bgcolor', 'mainStyleOverride');
+               foreach ($properties as $property) {
+                       if (isset($this->thisConfig[$property])) {
+                               $this->logDeprecatedProperty($property, 'contentCSS', '4.8');
+                       }
+               }
+               if (is_array($this->thisConfig['mainStyleOverride_add.'])) {
+                       $this->logDeprecatedProperty('mainStyleOverride_add', 'contentCSS', '4.8');
+               }
+               if (is_array($this->thisConfig['inlineStyle.']))        {
+                       $this->logDeprecatedProperty('inlineStyle', 'contentCSS', '4.8');
+               }
                if (!trim($this->thisConfig['ignoreMainStyleOverride'])) {
                        $mainStyle_font = $this->thisConfig['mainStyle_font'] ? $this->thisConfig['mainStyle_font']: 'Verdana,sans-serif';
-
                        $mainElements = array();
                        $mainElements['P'] = $this->thisConfig['mainStyleOverride_add.']['P'];
                        $elList = explode(',','H1,H2,H3,H4,H5,H6,PRE');
@@ -978,19 +1012,24 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         */
        function buildJSClassesConfig($RTEcounter) {
                        // Build JS array of lists of classes
+                       // These PageTSConfig properties are DEPRECATED as of TYPO3 4.6 and will be removed in TYPO3 4.8
                $classesTagList = 'classesCharacter, classesParagraph, classesImage, classesTable, classesLinks, classesTD';
-               $classesTagConvert = array( 'classesCharacter' => 'span', 'classesParagraph' => 'div', 'classesImage' => 'img', 'classesTable' => 'table', 'classesLinks' => 'a', 'classesTD' => 'td');
+               $classesTagConvert = array('classesCharacter' => 'span', 'classesParagraph' => 'div', 'classesImage' => 'img', 'classesTable' => 'table', 'classesLinks' => 'a', 'classesTD' => 'td');
+               $classesUseInstead = array('classesCharacter' => 'buttons.textstyle.tags.span.allowedClasses', 'classesParagraph' => 'buttons.blockstyle.tags.div.allowedClasses', 'classesImage' => 'buttons.image.properties.class.allowedClasses', 'classesTable' => 'buttons.blockstyle.tags.table.allowedClasses', 'classesLinks' => 'buttons.link.properties.class.allowedClasses', 'classesTD' => 'buttons.blockstyle.tags.td.allowedClasses');
                $classesTagArray = t3lib_div::trimExplode(',' , $classesTagList);
                $configureRTEInJavascriptString = '
                        RTEarea[editornumber].classesTag = new Object();';
                foreach ($classesTagArray as $classesTagName) {
-                       $HTMLAreaJSClasses = ($this->thisConfig[$classesTagName])?('"' . $this->cleanList($this->thisConfig[$classesTagName]) . '";'):'null;';
+                       $HTMLAreaJSClasses = $this->thisConfig[$classesTagName] ? ('"' . $this->cleanList($this->thisConfig[$classesTagName]) . '";') : 'null;';
                        $configureRTEInJavascriptString .= '
                        RTEarea[editornumber].classesTag.'. $classesTagConvert[$classesTagName] .' = '. $HTMLAreaJSClasses;
+                       if (isset($this->thisConfig[$classesTagName])) {
+                               $this->logDeprecatedProperty($classesTagName, $classesUseInstead[$classesTagName], '4.8');
+                       }
                }
                        // Include JS arrays of configured classes
                $configureRTEInJavascriptString .= '
-                       RTEarea[editornumber].classesUrl = "' . $this->writeTemporaryFile('', 'classes_'.$LANG->lang, 'js', $this->buildJSClassesArray()) . '";';
+                       RTEarea[editornumber].classesUrl = "' . (($this->is_FE() && $GLOBALS['TSFE']->absRefPrefix) ? $GLOBALS['TSFE']->absRefPrefix : '') . $this->writeTemporaryFile('', 'classes_' . $this->language, 'js', $this->buildJSClassesArray(), TRUE) . '";';
                return $configureRTEInJavascriptString;
        }
 
@@ -1052,11 +1091,6 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         */
        function buildNestedJSArray($conf) {
                $convertedConf = t3lib_div::removeDotsFromTS($conf);
-               if ($this->is_FE()) {
-                       $GLOBALS['TSFE']->csConvObj->convArray($convertedConf, ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] ? $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] : 'iso-8859-1'), 'utf-8');
-               } else {
-                       $GLOBALS['LANG']->csConvObj->convArray($convertedConf, $GLOBALS['LANG']->charSet, 'utf-8');
-               }
                return str_replace(array(':"0"', ':"\/^(', ')$\/i"', ':"\/^(', ')$\/"', '[]'), array(':false', ':/^(', ')$/i', ':/^(', ')$/', '{}'), json_encode($convertedConf));
        }
 
@@ -1071,7 +1105,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                foreach ($labelsArray as $labels => $subArray) {
                        $LOCAL_LANG = t3lib_div::readLLfile('EXT:' . $this->ID . '/htmlarea/locallang_' . $labels . '.xml', $this->language, 'utf-8');
                        if (!empty($LOCAL_LANG[$this->language])) {
-                               $LOCAL_LANG[$this->language] = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG['default'], $LOCAL_LANG[$this->language]);
+                               $LOCAL_LANG[$this->language] = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG['default'], $LOCAL_LANG[$this->language], FALSE, FALSE);
                        } else {
                                $LOCAL_LANG[$this->language] = $LOCAL_LANG['default'];
                        }
@@ -1092,8 +1126,6 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         * @return      string          The name of the file writtten to typo3temp/rtehtmlarea
         */
        public function writeTemporaryFile($sourceFileName='', $label, $fileExtension='js', $contents='', $concatenate = FALSE) {
-               global $TYPO3_CONF_VARS;
-
                if ($sourceFileName) {
                        $output = '';
                        $source = t3lib_div::getFileAbsFileName($sourceFileName);
@@ -1101,74 +1133,25 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                } else {
                        $output = $contents;
                }
-               $compress = $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'] && ($fileExtension == 'js') && ($output != '');
-               $relativeFilename = 'typo3temp/' . $this->ID . '/' . str_replace('-','_',$label) . '_' . t3lib_div::shortMD5(($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['version'] . ($sourceFileName ? $sourceFileName : $output)), 20) . ($compress ? '_compressed' : '') . '.' . $fileExtension;
+               $relativeFilename = 'typo3temp/' . $this->ID . '_' . str_replace('-','_',$label) . '_' . t3lib_div::shortMD5((TYPO3_version . $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['version'] . ($sourceFileName ? $sourceFileName : $output)), 20) . '.' . $fileExtension;
                $destination = PATH_site . $relativeFilename;
-               if(!file_exists($destination)) {
-                       $compressedJavaScript = '';
-                       if ($compress && $fileExtension == 'js') {
-                               $compressedJavaScript = t3lib_div::minifyJavaScript($output);
+               if (!file_exists($destination)) {
+                       $minifiedJavaScript = '';
+                       if ($fileExtension == 'js' && $output != '') {
+                               $minifiedJavaScript = t3lib_div::minifyJavaScript($output);
                        }
-                       $failure = t3lib_div::writeFileToTypo3tempDir($destination, $compressedJavaScript ? $compressedJavaScript : $output);
+                       $failure = t3lib_div::writeFileToTypo3tempDir($destination, $minifiedJavaScript ? $minifiedJavaScript : $output);
                        if ($failure)  {
-                               die($failure);
-                       }
-               }
-               if ($concatenate && $fileExtension == 'js') {
-                       $this->cumulativeScripts[$this->TCEform->RTEcounter][] = $destination;
-               }
-               if ($this->is_FE()) {
-                       $filename =  ($GLOBALS['TSFE']->absRefPrefix ? $GLOBALS['TSFE']->absRefPrefix : '') . t3lib_div::createVersionNumberedFilename($relativeFilename);
-               } else {
-                       $filename = t3lib_div::createVersionNumberedFilename(($this->isFrontendEditActive() ? '' : ($this->backPath . '../')) . $relativeFilename);
-               }
-               return t3lib_div::resolveBackPath($filename);
-       }
-       /**
-        * Concatenates all accumulated scripts in a file in typo3temp/rtehtmlarea directory and returns the file name
-        *
-        * @param       integer         $RTEcounter: The index number of the current RTE editing area within the form.
-        *
-        * @return      string          The name of the file writtten to typo3temp/rtehtmlarea
-        */
-       protected function doConcatenate($RTEcounter) {
-               $fileExtension = 'js';
-               $compress = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableCompressedScripts'];
-               $token = implode('|', $this->cumulativeScripts[$RTEcounter]);
-               $relativeFilename = 'typo3temp/' . $this->ID . '/' . 'htmlarea_cumulative' . '_' . t3lib_div::shortMD5(($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['version'] . $token ), 20) . ($compress ? '_compressed' : '') . '.' . $fileExtension;
-               $destination = PATH_site . $relativeFilename;
-               if (!file_exists($destination)) {
-                       foreach ($this->cumulativeScripts[$RTEcounter] as $fileName) {
-                               $contents = file_get_contents($fileName);
-                               if (!file_exists($destination)) {
-                                       $failure = t3lib_div::writeFileToTypo3tempDir($destination, $contents);
-                                       if ($failure)  {
-                                               die($failure);
-                                       }
-                               } else {
-                                       $success = file_put_contents($destination, $contents, FILE_APPEND);
-                                       if (!$success)  {
-                                               die('Could not append script' + $fileName);
-                                       }
-                               }
+                               throw new RuntimeException($failure, 1294585668);
                        }
                }
                if ($this->is_FE()) {
-                       $filename = ($GLOBALS['TSFE']->absRefPrefix ? $GLOBALS['TSFE']->absRefPrefix : '') . t3lib_div::createVersionNumberedFilename($relativeFilename);
+                       $filename = $relativeFilename;
                } else {
-                       if ($compress) {
-                               $compressor = t3lib_div::makeInstance('t3lib_Compressor');
-                               $filename = $compressor->compressJsFile(($this->isFrontendEditActive() ? '' : $this->backPath) . '../' . $relativeFilename);
-                               if ($this->isFrontendEditActive()) {
-                                       $filename = preg_replace('/^..\//', '', $filename);
-                               }
-                       } else {
-                               $filename = t3lib_div::createVersionNumberedFilename(($this->isFrontendEditActive() ? '' : ($this->backPath . '../')) . $relativeFilename);
-                       }
+                       $filename = ($this->isFrontendEditActive() ? '' : ($this->backPath . '../')) . $relativeFilename;
                }
                return t3lib_div::resolveBackPath($filename);
        }
-
        /**
         * Return a file name containing the main JS language array for HTMLArea
         *
@@ -1191,16 +1174,14 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         *
         * @return      string          Javascript localization array
         */
-
        function buildJSLangArray($plugin) {
                $LOCAL_LANG = FALSE;
                $extensionKey = is_object($this->registeredPlugins[$plugin]) ? $this->registeredPlugins[$plugin]->getExtensionKey() : $this->ID;
                $LOCAL_LANG = t3lib_div::readLLfile('EXT:' . $extensionKey . '/htmlarea/plugins/' . $plugin . '/locallang.xml', $this->language, 'utf-8', 1);
-               $linebreak = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableCompressedScripts'] ? '' : LF;
-               $JSLanguageArray = 'HTMLArea.I18N["' . $plugin . '"] = new Object();' . $linebreak;
+               $JSLanguageArray = 'HTMLArea.I18N["' . $plugin . '"] = new Object();' . LF;
                if (is_array($LOCAL_LANG)) {
                        if (!empty($LOCAL_LANG[$this->language])) {
-                               $LOCAL_LANG[$this->language] = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG['default'],$LOCAL_LANG[$this->language]);
+                               $LOCAL_LANG[$this->language] = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG['default'], $LOCAL_LANG[$this->language], FALSE, FALSE);
                        } else {
                                $LOCAL_LANG[$this->language] = $LOCAL_LANG['default'];
                        }
@@ -1268,16 +1249,19 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                return json_encode($toolbar);
        }
 
+       /**
+        * Localize a string using the language of the content element rather than the language of the BE interface
+        *
+        * @param       string          string: the label to be localized
+        * @return      string          Localized string.
+        */
        public function getLLContent($string) {
-               global $LANG;
-
-               $BE_lang = $LANG->lang;
-               $BE_charSet = $LANG->charSet;
-               $LANG->lang = $this->contentTypo3Language;
-               $LANG->charSet = $this->contentCharset;
-               $LLString = $LANG->JScharCode($LANG->sL($string));
-               $LANG->lang = $BE_lang;
-               $LANG->charSet = $BE_charSet;
+               $BE_lang = $GLOBALS['LANG']->lang;
+
+               $GLOBALS['LANG']->lang = $this->contentTypo3Language;
+               $LLString = $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->sL($string));
+
+               $GLOBALS['LANG']->lang = $BE_lang;
                return $LLString;
        }
 
@@ -1285,9 +1269,9 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                global $LANG, $TSFE, $TYPO3_CONF_VARS;
 
                if ($this->is_FE()) {
-                       if (strcmp(substr($string,0,4),'LLL:') && $TYPO3_CONF_VARS['BE']['forceCharset'])       {
-                                       // A pure string coming from Page TSConfig must be in forceCharset, otherwise we just don't know..
-                               $label = $TSFE->csConvObj->conv($TSFE->sL(trim($string)), $TYPO3_CONF_VARS['BE']['forceCharset'], $this->OutputCharset);
+                       if (strcmp(substr($string,0,4),'LLL:')) {
+                                       // A pure string coming from Page TSConfig must be in utf-8
+                               $label = $TSFE->csConvObj->conv($TSFE->sL(trim($string)), 'utf-8', $this->OutputCharset);
                        } else {
                                $label = $TSFE->csConvObj->conv($TSFE->sL(trim($string)), $this->charset, $this->OutputCharset);
                        }
@@ -1306,12 +1290,13 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
        }
 
        function feJScharCode($str) {
-               global $TSFE;
                        // Convert string to UTF-8:
-               if ($this->OutputCharset != 'utf-8') $str = $TSFE->csConvObj->utf8_encode($str,$this->OutputCharset);
+               if ($this->OutputCharset != 'utf-8') {
+                       $str = $GLOBALS['TSFE']->csConvObj->utf8_encode($str, $this->OutputCharset);
+               }
                        // Convert the UTF-8 string into a array of char numbers:
-               $nArr = $TSFE->csConvObj->utf8_to_numberarray($str);
-               return 'String.fromCharCode('.implode(',',$nArr).')';
+               $nArr = $GLOBALS['TSFE']->csConvObj->utf8_to_numberarray($str);
+               return 'String.fromCharCode('.implode(',', $nArr).')';
        }
 
        public function getFullFileName($filename) {
@@ -1359,7 +1344,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
        }
 
        /**
-        * Return true if we are in the FE, but not in the FE editing feature of BE.
+        * Return TRUE if we are in the FE, but not in the FE editing feature of BE.
         *
         * @return boolean
         */
@@ -1400,16 +1385,26 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                }
                        }
                }
-               if ($browserInfo['system'] == 'mac') {
-                       if (strstr($userAgent,'iPad')) {
-                               $browserInfo['system'] = 'iPad';
-                       } elseif (strstr($userAgent,'iPhone')) {
-                               $browserInfo['system'] = 'iPhone';
-                       } elseif (strstr($userAgent,'iPod')) {
-                               $browserInfo['system'] = 'iPod';
+               return $browserInfo;
+       }
+       /**
+        * Log usage of deprecated Page TS Config Property
+        *
+        * @param string $deprecatedProperty: Name of deprecated property
+        * @param string $useProperty: Name of property to use instead
+        * @param string $version: Version of TYPO3 in which the property will be removed
+        *
+        * @return void
+        */
+       public function logDeprecatedProperty ($deprecatedProperty, $useProperty, $version) {
+               if (!$this->thisConfig['logDeprecatedProperties.']['disabled']) {
+                       $message = sprintf('RTE Page TSConfig property "%1$s" used on page id #%4$s is DEPRECATED and will be removed in TYPO3 %3$s. Use "%2$s" instead.', $deprecatedProperty, $useProperty, $version, $this->thePid);
+                       t3lib_div::deprecationLog($message);
+                       if (is_object($GLOBALS['BE_USER']) && $this->thisConfig['logDeprecatedProperties.']['logAlsoToBELog']) {
+                               $message = sprintf($GLOBALS['LANG']->getLL('deprecatedPropertyMessage'), $deprecatedProperty, $useProperty, $version, $this->thePid);
+                               $GLOBALS['BE_USER']->simplelog($message, $this->ID);
                        }
                }
-               return $browserInfo;
        }
        /***************************
         *