* Fixes and features to htmlArea RTE extension (see details in local ChangeLog)
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / class.tx_rtehtmlarea_base.php
index 7b0620b..85895f5 100644 (file)
@@ -4,7 +4,7 @@
 *
 *  (c) 2004 Kasper Skaarhoj (kasper@typo3.com)
 *  (c) 2004 Philipp Borgmann <philipp.borgmann@gmx.de>
-*  (c) 2004-2005 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
+*  (c) 2004, 2005, 2006 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -205,17 +205,27 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                );
                                
        var $defaultFontSizes = array(
-               '1' =>  '1 (8 pt)',
-               '2' =>  '2 (10 pt)',
-               '3' =>  '3 (12 pt)',
-               '4' =>  '4 (14 pt)',
-               '5' =>  '5 (18 pt)',
-               '6' =>  '6 (24 pt)',
-               '7' =>  '7 (36 pt)',
+               '1'     =>      '1 (8 pt)',
+               '2'     =>      '2 (10 pt)',
+               '3'     =>      '3 (12 pt)',
+               '4'     =>      '4 (14 pt)',
+               '5'     =>      '5 (18 pt)',
+               '6'     =>      '6 (24 pt)',
+               '7'     =>      '7 (36 pt)',
                );
-
+       
+       var $defaultFontSizes_safari = array(
+               '1'     =>      'xx-small',
+               '2'     =>      'x-small',
+               '3'     =>      'small',
+               '4'     =>      'medium',
+               '5'     =>      'large',
+               '6'     =>      'x-large',
+               '7'     =>      'xx-large',
+               );
+       
        var $pluginList = 'TableOperations, ContextMenu, SpellChecker, SelectColor, TYPO3Browsers, InsertSmiley, FindReplace, RemoveFormat, CharacterMap, QuickTag, InlineCSS, DynamicCSS, UserElements, Acronym, TYPO3HtmlParser';
-
+       
        var $pluginButton = array(
                'InlineCSS'             => 'textstyle',
                'DynamicCSS'            => 'blockstyle',
@@ -282,7 +292,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         *
         * @return      boolean         TRUE if this RTE object offers an RTE in the current browser environment
         */
-
+       
        function isAvailable()  {
                $this->client = $this->clientInfo();
                $this->errorLog = array();
@@ -315,7 +325,11 @@ 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. Only msie Version 5 or higher and Mozilla based client 1. and higher.';
+                       }
+                       if (t3lib_div::int_from_ver(TYPO3_version) < 3007000) {
+                               $rteIsAvailable = 0;
+                               $this->errorLog[] = 'rte: This version of htmlArea RTE cannot run under this version of TYPO3.';
                        }
                }
                if ($rteIsAvailable)    return true;
@@ -338,12 +352,12 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         */
 
        function drawRTE(&$pObj,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue)      {
-               global $BE_USER,$LANG;
+               global $BE_USER,$LANG, $TYPO3_DB, $TYPO3_CONF_VARS;
 
                $this->TCEform = $pObj;
-               $LANG->includeLLFile('EXT:' . $this->ID . '/locallang.php');
+               $LANG->includeLLFile('EXT:' . $this->ID . '/locallang.xml');
                $this->client = $this->clientInfo();
-               $this->typoVersion = t3lib_div::int_from_ver($GLOBALS['TYPO_VERSION']);
+               $this->typoVersion = t3lib_div::int_from_ver(TYPO3_version);
                $this->userUid = 'BE_' . $BE_USER->user['uid'];
                
                        // Draw form element:
@@ -359,9 +373,9 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                // first get the http-path to typo3:
                        $this->httpTypo3Path = substr( substr( t3lib_div::getIndpEnv('TYPO3_SITE_URL'), strlen( t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') ) ), 0, -1 );
                        if (strlen($this->httpTypo3Path) == 1) {
-                               $this->httpTypo3Path = "/";
+                               $this->httpTypo3Path = '/';
                        } else {
-                               $this->httpTypo3Path .= "/";
+                               $this->httpTypo3Path .= '/';
                        }
                                // Get the path to this extension:
                        $this->extHttpPath = $this->httpTypo3Path . t3lib_extMgm::siteRelPath($this->ID);
@@ -388,6 +402,13 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                // Special configuration and default extras:
                        $this->specConf = $specConf;
                        
+                       if ($this->thisConfig['forceHTTPS']) {
+                               $this->httpTypo3Path = preg_replace('/^(http|https)/', 'https', $this->httpTypo3Path);
+                               $this->extHttpPath = preg_replace('/^(http|https)/', 'https', $this->extHttpPath);
+                               $this->siteURL = preg_replace('/^(http|https)/', 'https', $this->siteURL);
+                               $this->hostURL = preg_replace('/^(http|https)/', 'https', $this->hostURL);
+                       }
+                       
                        /* =======================================
                         * LANGUAGES & CHARACTER SETS
                         * =======================================
@@ -411,18 +432,18 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                        $whereClause = $tableA . '.uid IN (' . $languagesUidsList . ') ';
                                        $whereClause .= t3lib_BEfunc::BEenableFields($tableA);
                                        $whereClause .= t3lib_BEfunc::deleteClause($tableA);
-                                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($selectFields, $table, $whereClause);
-                                       while($languageRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+                                       $res = $TYPO3_DB->exec_SELECTquery($selectFields, $table, $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']));
                                        }
                                } else {
-                                       $this->contentISOLanguage = trim($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['defaultDictionary']) ? trim($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['defaultDictionary']) : 'en';
+                                       $this->contentISOLanguage = trim($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['defaultDictionary']) ? trim($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['defaultDictionary']) : 'en';
                                        $selectFields = 'lg_iso_2, lg_typo3';
                                        $table = 'static_languages';
-                                       $whereClause = 'lg_iso_2 = "' . strtoupper($this->contentISOLanguage) . '"';
-                                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($selectFields, $table, $whereClause);
-                                       while($languageRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+                                       $whereClause = 'lg_iso_2 = ' . $TYPO3_DB->fullQuoteStr(strtoupper($this->contentISOLanguage), $table);
+                                       $res = $TYPO3_DB->exec_SELECTquery($selectFields, $table, $whereClause);
+                                       while($languageRow = $TYPO3_DB->sql_fetch_assoc($res)) {
                                                $this->contentTypo3Language = strtolower(trim($languageRow['lg_typo3']));
                                        }
                                }
@@ -431,13 +452,13 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                // Character sets: interface and content
                        $this->charset = $LANG->csConvObj->charSetArray[$this->language];
                        $this->charset = $this->charset ? $this->charset : 'iso-8859-1';
-                       $this->BECharset = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']) ? trim($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']) : $this->charset;
+                       $this->BECharset = trim($TYPO3_CONF_VARS['BE']['forceCharset']) ? trim($TYPO3_CONF_VARS['BE']['forceCharset']) : $this->charset;
                        $this->OutputCharset = $this->BECharset;
                        
                        $this->contentCharset = $LANG->csConvObj->charSetArray[$this->contentTypo3Language];
                        $this->contentCharset = $this->contentCharset ? $this->contentCharset : 'iso-8859-1';
                        $this->origContentCharSet = $this->contentCharset;
-                       $this->contentCharset = (trim($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']) ? trim($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']) : $this->contentCharset);
+                       $this->contentCharset = (trim($TYPO3_CONF_VARS['BE']['forceCharset']) ? trim($TYPO3_CONF_VARS['BE']['forceCharset']) : $this->contentCharset);
 
                        /* =======================================
                         * TOOLBAR CONFIGURATION
@@ -445,9 +466,9 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                         */
 
                                // htmlArea plugins list
-                       $this->pluginEnableArray = array_intersect(t3lib_div::trimExplode(',', $this->pluginList , 1), t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['HTMLAreaPluginList'], 1));
+                       $this->pluginEnableArray = array_intersect(t3lib_div::trimExplode(',', $this->pluginList , 1), t3lib_div::trimExplode(',', $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['HTMLAreaPluginList'], 1));
                        $hidePlugins = array();
-                       if(!t3lib_extMgm::isLoaded('sr_static_info') || in_array($this->language, t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['noSpellCheckLanguages']))) $hidePlugins[] = 'SpellChecker';
+                       if(!t3lib_extMgm::isLoaded('sr_static_info') || in_array($this->language, t3lib_div::trimExplode(',', $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['noSpellCheckLanguages']))) $hidePlugins[] = 'SpellChecker';
                        if ($this->client['BROWSER'] == 'msie') $hidePlugins[] = 'Acronym';
                        if ($this->client['BROWSER'] == 'opera') {
                                $hidePlugins[] = 'ContextMenu';
@@ -474,7 +495,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                
                                        // Set the charset of the content for the SpellChecker
                                $this->spellCheckerCharset = $this->contentCharset;
-                               $this->spellCheckerCharset = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']) ? trim($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']) : $this->spellCheckerCharset;
+                               $this->spellCheckerCharset = trim($TYPO3_CONF_VARS['BE']['forceCharset']) ? trim($TYPO3_CONF_VARS['BE']['forceCharset']) : $this->spellCheckerCharset;
                                
                                        // Set the SpellChecker mode
                                $this->spellCheckerMode = isset($BE_USER->userTS['options.']['HTMLAreaPspellMode']) ? trim($BE_USER->userTS['options.']['HTMLAreaPspellMode']) : 'normal';
@@ -489,16 +510,12 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                }
                        }
 
-                       if ($this->isPluginEnable('QuickTag') && trim($this->thisConfig['hideTags'])) {
-                               $this->quickTagHideTags = implode(',', t3lib_div::trimExplode(',', $this->thisConfig['hideTags'], 1));
-                       }
-
                        /* =======================================
                         * SET STYLES
                         * =======================================
                         */
 
-                       $RTEWidth = isset($BE_USER->userTS['options.']['RTESmallWidth']) ? $BE_USER->userTS['options.']['RTESmallWidth'] : '460';
+                       $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 + ($pObj->docLarge ? (isset($BE_USER->userTS['options.']['RTELargeWidthIncrement']) ? $BE_USER->userTS['options.']['RTELargeWidthIncrement'] : '150') : 0);
                        $RTEHeight = $RTEHeight + ($pObj->docLarge ?  (isset($BE_USER->userTS['options.']['RTELargeHeightIncrement']) ? $BE_USER->userTS['options.']['RTELargeHeightIncrement'] : 0) : 0);
@@ -558,13 +575,13 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                // Change some tags
                        if ($this->client['BROWSER'] == 'gecko') {
                                        // change <strong> to <b>
-                               $value = preg_replace("/<(\/?)strong/i", "<$1b", $value);
+                               $value = preg_replace('/<(\/?)strong/i', "<$1b", $value);
                                        // change <em> to <i>
-                               $value = preg_replace("/<(\/?)em/i", "<$1i", $value);
+                               $value = preg_replace('/<(\/?)em([^b>]*>)/i', "<$1i$2", $value);
                        }
                        if ($this->client['BROWSER'] == 'msie') {
                                        // change <abbr> to <acronym>
-                               $value = preg_replace("/<(\/?)abbr/i", "<$1acronym", $value);
+                               $value = preg_replace('/<(\/?)abbr/i', "<$1acronym", $value);
                        }
 
                                // Register RTE windows
@@ -593,10 +610,10 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                // Draw the textarea
                        $visibility = 'hidden';
                        $item = $this->triggerField($PA['itemFormElName']).'
-                               <div id="pleasewait' . $pObj->RTEcounter . '" class="pleasewait">' . $LANG->getLL('Please wait') . '</div>
-                               <div id="editorWrap' . $pObj->RTEcounter . '" class="editorWrap" style="visibility:' . $visibility . '; width:' . $editorWrapWidth . '; height:' . $editorWrapHeight . ';">
+                               <div id="pleasewait' . $pObj->RTEcounter . '" class="pleasewait" style="display: none;" >' . $LANG->getLL('Please wait') . '</div>
+                               <div id="editorWrap' . $pObj->RTEcounter . '" class="editorWrap" style="width:' . $editorWrapWidth . '; height:' . $editorWrapHeight . ';">
                                <textarea id="RTEarea'.$pObj->RTEcounter.'" name="'.htmlspecialchars($PA['itemFormElName']).'" style="'.t3lib_div::deHSCentities(htmlspecialchars($this->RTEdivStyle)).'">'.t3lib_div::formatForTextarea($value).'</textarea>
-                               </div>' . ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableDebugMode'] ? '<div id="HTMLAreaLog"></div>' : '') . '
+                               </div>' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableDebugMode'] ? '<div id="HTMLAreaLog"></div>' : '') . '
                                ';
                }
 
@@ -617,29 +634,29 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        bar, bold, italic, underline, strikethrough, subscript, superscript,
                        bar, lefttoright, righttoleft, bar, left, center, right, justifyfull,
                        bar, orderedlist, unorderedlist, outdent, indent, bar, textcolor, bgcolor, textindicator,
-                       bar, emoticon, insertcharacter, line, link, image, table,' . (trim($this->thisConfig['hideTableOperationsInToolbar'] && trim($this->thisConfig['keepToggleBordersInToolbar'])) ? ' toggleborders,': '') . ' user, acronym, bar, findreplace, spellcheck,
+                       bar, emoticon, insertcharacter, line, link, 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, bar, undo, redo, bar, showhelp, about, linebreak, 
-                       ' . (trim($this->thisConfig['hideTableOperationsInToolbar']) ? '': 'bar, toggleborders,') . ' bar, tableproperties, bar, rowproperties, rowinsertabove, rowinsertunder, rowdelete, rowsplit, bar,
+                       ' . ($this->thisConfig['hideTableOperationsInToolbar'] ? '': 'bar, toggleborders,') . ' bar, tableproperties, bar, rowproperties, rowinsertabove, rowinsertunder, rowdelete, rowsplit, bar,
                        columninsertbefore, columninsertafter, columndelete, columnsplit, bar,
                        cellproperties, cellinsertbefore, cellinsertafter, celldelete, cellsplit, cellmerge';
                
                        // Special toolbar for Mozilla Wamcom on Mac OS 9
                if($this->client['BROWSER'] == 'gecko' && $this->client['VERSION'] == '1.3')  {
-                       $this->defaultToolbarOrder = $this->TCEform->docLarge ? 'bar, blockstylelabel, blockstyle, space, textstylelabel, textstyle, linebreak, 
-                               bar, fontstyle, space, fontsize, space, formatblock, bar, bold, italic, underline, strikethrough, 
-                               subscript, superscript, lefttoright, righttoleft, bar, left, center, right, justifyfull, linebreak, 
-                               bar, orderedlist, unorderedlist, outdent, indent, bar, textcolor, bgcolor, textindicator, bar, emoticon, 
-                               insertcharacter, line, link, image, table, user, acronym, bar, findreplace, spellcheck, bar, chMode, inserttag, 
-                               removeformat, bar, copy, cut, paste, bar, undo, redo, bar, showhelp, about, linebreak, 
+                       $this->defaultToolbarOrder = $this->TCEform->docLarge ? 'bar, blockstylelabel, blockstyle, space, textstylelabel, textstyle, linebreak,
+                               bar, fontstyle, space, fontsize, space, formatblock, bar, bold, italic, underline, strikethrough,
+                               subscript, superscript, lefttoright, righttoleft, bar, left, center, right, justifyfull, linebreak,
+                               bar, orderedlist, unorderedlist, outdent, indent, bar, textcolor, bgcolor, textindicator, bar, emoticon,
+                               insertcharacter, line, link, image, table, user, acronym, bar, findreplace, spellcheck, bar, chMode, inserttag,
+                               removeformat, bar, copy, cut, paste, bar, undo, redo, bar, showhelp, about, linebreak,
                                bar, toggleborders, bar, tableproperties, bar, rowproperties, rowinsertabove, rowinsertunder, rowdelete, rowsplit, bar,
                                columninsertbefore, columninsertafter, columndelete, columnsplit, bar,
                                cellproperties, cellinsertbefore, cellinsertafter, celldelete, cellsplit, cellmerge'
-                               : 'bar, blockstylelabel, blockstyle, space, textstylelabel, textstyle, linebreak, 
-                               bar, fontstyle, space, fontsize, space, formatblock, bar, bold, italic, underline, strikethrough, 
-                               subscript, superscript, linebreak, bar, lefttoright, righttoleft, bar, left, center, right, justifyfull, 
-                               orderedlist, unorderedlist, outdent, indent, bar, textcolor, bgcolor, textindicator, bar, emoticon, 
-                               insertcharacter, line, link, image, table, user, acronym, linebreak, bar, findreplace, spellcheck, bar, chMode, inserttag, 
-                               removeformat, bar, copy, cut, paste, bar, undo, redo, bar, showhelp, about, linebreak, 
+                               : 'bar, blockstylelabel, blockstyle, space, textstylelabel, textstyle, linebreak,
+                               bar, fontstyle, space, fontsize, space, formatblock, bar, bold, italic, underline, strikethrough,
+                               subscript, superscript, linebreak, bar, lefttoright, righttoleft, bar, left, center, right, justifyfull,
+                               orderedlist, unorderedlist, outdent, indent, bar, textcolor, bgcolor, textindicator, bar, emoticon,
+                               insertcharacter, line, link, image, table, user, acronym, linebreak, bar, findreplace, spellcheck, bar, chMode, inserttag,
+                               removeformat, bar, copy, cut, paste, bar, undo, redo, bar, showhelp, about, linebreak,
                                bar, toggleborders, bar, tableproperties, bar, rowproperties, rowinsertabove, rowinsertunder, rowdelete, rowsplit, bar,
                                columninsertbefore, columninsertafter, columndelete, columnsplit, bar,
                                cellproperties, cellinsertbefore, cellinsertafter, celldelete, cellsplit, cellmerge';
@@ -736,6 +753,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         */
 
        function setPlugins() {
+               global $TYPO3_CONF_VARS;
                
                $hideButtons = array();
                        // Disabling the plugins if their buttons are not in the toolbar
@@ -754,7 +772,8 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                if($this->thisConfig['disableContextMenu'] || $this->thisConfig['disableRightClick']) $hidePlugins[] = 'ContextMenu';
                if($this->thisConfig['disableSelectColor']) $hidePlugins[] = 'SelectColor';
                if($this->thisConfig['disableTYPO3Browsers']) $hidePlugins[] = 'TYPO3Browsers';
-               if(!t3lib_extMgm::isLoaded('sr_static_info') || in_array($this->language, t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['noSpellCheckLanguages']))) $hidePlugins[] = 'SpellChecker';
+               if(!$this->thisConfig['enableWordClean'] || !is_array($this->thisConfig['enableWordClean.'])) $hidePlugins[] = 'TYPO3HtmlParser';
+               if(!t3lib_extMgm::isLoaded('sr_static_info') || in_array($this->language, t3lib_div::trimExplode(',', $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['noSpellCheckLanguages']))) $hidePlugins[] = 'SpellChecker';
                
                $this->pluginEnableArray = array_diff($this->pluginEnableArray, $hidePlugins);
                
@@ -803,61 +822,73 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         * @return string               the html-code for loading the Javascript-Files
         */
        function loadJSfiles($number) {
+               global $TYPO3_CONF_VARS;
+               
                return '
                <script type="text/javascript">
                /*<![CDATA[*/
+                       var i=1;
+                       while (document.getElementById("pleasewait" + i)) {
+                               document.getElementById("pleasewait" + i).style.display = "block";
+                               document.getElementById("editorWrap" + i).style.visibility = "hidden";
+                               i++;
+                       };
+                       var RTEarea = new Array();
+                       RTEarea[0] = new Array();
+                       RTEarea[0]["version"] = "' . $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['version'] . '";
+                       RTEarea[0]["popupwin"] = "' . $this->writeJSFileToTypo3tempDir('EXT:' . $this->ID . '/htmlarea/popupwin' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts']?'-compressed':'') .'.js', "popupwin", $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'])  . '";
+                       RTEarea[0]["htmlarea-gecko"] = "' . $this->writeJSFileToTypo3tempDir('EXT:' . $this->ID . '/htmlarea/htmlarea-gecko' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts']?'-compressed':'') .'.js', "htmlarea-gecko", $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'])  . '";
+                       RTEarea[0]["htmlarea-ie"] = "' . $this->writeJSFileToTypo3tempDir('EXT:' . $this->ID . '/htmlarea/htmlarea-ie' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts']?'-compressed':'') .'.js', "htmlarea-ie", $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'])  . '";
                        var _editor_url = "' . $this->extHttpPath . 'htmlarea";
                        var _editor_lang = "' . $this->language . '";
                        var _editor_CSS = "' . $this->editorCSS . '";
                        var _editor_skin = "' . dirname($this->editorCSS) . '";
                        var _editor_edited_content_CSS = "' .  $this->editedContentCSS  . '";
                        var _typo3_host_url = "' . $this->hostURL . '";
-                       var _editor_debug_mode = ' . ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableDebugMode'] ? 'true' : 'false') . ';
-                       var _editor_compressed_scripts = ' . ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableCompressedScripts'] ? 'true' : 'false') . ';
-                       var _editor_mozAllowClipboard_url = "' . ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['mozAllowClipboardUrl'] ? $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['mozAllowClipboardUrl'] : '') . '";
+                       var _editor_debug_mode = ' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableDebugMode'] ? 'true' : 'false') . ';
+                       var _editor_compressed_scripts = ' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'] ? 'true' : 'false') . ';
+                       var _editor_mozAllowClipboard_url = "' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['mozAllowClipboardUrl'] ? $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['mozAllowClipboardUrl'] : '') . '";
                        var _spellChecker_lang = "' . $this->spellCheckerLanguage . '";
                        var _spellChecker_charset = "' . $this->spellCheckerCharset . '";
                        var _spellChecker_mode = "' . $this->spellCheckerMode . '";
-                       var _quickTag_hideTags = "' . $this->quickTagHideTags . '";
                /*]]>*/
                </script>
                <script type="text/javascript" src="' . $this->buildJSMainLangFile($number) . '"></script>
-               <script type="text/javascript" src="' . $this->extHttpPath . 'htmlarea/htmlarea' . ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableCompressedScripts']?'-compressed':'') .'.js"></script>
+               <script type="text/javascript" src="' . $this->writeJSFileToTypo3tempDir('EXT:' . $this->ID . '/htmlarea/htmlarea' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts']?'-compressed':'') .'.js', "htmlarea", $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts']) . '"></script>
                ';
        }
-
+       
        /**
         * Return the JS-Code to initialize the Editor
         *
         * @return string       the html-code for loading the Javascript-Files
         */
-
+        
        function loadJScode($number) {
-               global $TSFE;
+               global $TSFE, $TYPO3_CONF_VARS;
+               
                $loadPluginCode = '';
                $pluginArray = t3lib_div::trimExplode(',', $this->pluginList , 1);
                while( list(,$plugin) = each($pluginArray) ) {
                        if ($this->isPluginEnable($plugin) || (intval($number) > 1 && in_array($plugin, $this->pluginEnableArrayMultiple))) {
                                $loadPluginCode .= '
-                       HTMLArea.loadPlugin("' . $plugin . '", true);';
+                       HTMLArea.loadPlugin("' . $plugin . '", true, "' . $this->writeJSFileToTypo3tempDir('EXT:' . $this->ID . '/htmlarea/plugins/' . $plugin . '/' . strtolower(preg_replace('/([a-z])([A-Z])([a-z])/', "$1".'-'."$2"."$3", $plugin)) . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts']?'-compressed':'') .'.js', $plugin, $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts']) . '");';
                        }
                }
                return (!is_object($TSFE) ? '' : '
-               ' . '/*<![CDATA[*/') . '
-                       var conf_RTEtsConfigParams = "&RTEtsConfigParams=' . rawurlencode($this->RTEtsConfigParams()) . '";
-                       var RTEarea = new Array();
-                       var extHttpPath = "'.$this->extHttpPath.'";
-                       var rtePathImageFile = "'. $this->extHttpPath . $this->ID . '_select_image.php";
-                       var rtePathLinkFile = "' . $this->extHttpPath . $this->ID . '_browse_links.php";
-                       var rtePathUserFile = "' . $this->extHttpPath . $this->ID . '_user.php";
-                       var rtePathAcronymFile = "' . $this->extHttpPath . $this->ID . '_acronym.php";
-                       var rtePathParseHtmlFile = "' . $this->extHttpPath . $this->ID . '_parse_html.php";'
+               ' . '/*<![CDATA[*/') . (is_object($TSFE) ? '' : '
+                       RTEarea[0]["RTEtsConfigParams"] = "&RTEtsConfigParams=' . rawurlencode($this->RTEtsConfigParams()) . '";
+                       RTEarea[0]["pathAcronymModule"] = "../../mod2/acronym.php";
+                       RTEarea[0]["pathLinkModule"] = "../../mod3/browse_links.php";
+                       RTEarea[0]["pathImageModule"] = "../../mod4/select_image.php";
+                       RTEarea[0]["pathUserModule"] = "../../mod5/user.php";
+                       RTEarea[0]["pathParseHtmlModule"] = "' . $this->extHttpPath . 'mod6/parse_html.php";')
                        . $loadPluginCode .  '
                        HTMLArea.init();' . (!is_object($TSFE) ? '' : '
                /*]]>*/
                ');
        }
-
+       
        /**
         * Return the JS-Code for Register the RTE in JS
         *
@@ -865,7 +896,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         */
        
        function registerRTEinJS($number) {
-               global $TSFE;
+               global $TSFE, $TYPO3_CONF_VARS;
                
                $registerRTEinJSString = (!is_object($TSFE) ? '' : '
                        ' . '/*<![CDATA[*/') . '
@@ -881,12 +912,13 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        RTEarea['.$number.']["disablePCexamples"] = ' . (trim($this->thisConfig['disablePCexamples'])?'true':'false') . ';
                        RTEarea['.$number.']["statusBar"] = ' . (trim($this->thisConfig['showStatusBar'])?'true':'false') . ';
                        RTEarea['.$number.']["showTagFreeClasses"] = ' . (trim($this->thisConfig['showTagFreeClasses'])?'true':'false') . ';
-                       RTEarea['.$number.']["useHTTPS"] = ' . (trim(stristr($this->siteURL, 'https'))?'true':'false') . ';
-                       RTEarea['.$number.']["enableMozillaExtension"] = ' . (($this->client['BROWSER'] == 'gecko' && $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableMozillaExtension'])?'true':'false') . ';';
+                       RTEarea['.$number.']["useHTTPS"] = ' . ((trim(stristr($this->siteURL, 'https')) || $this->thisConfig['forceHTTPS'])?'true':'false') . ';
+                       RTEarea['.$number.']["enableMozillaExtension"] = ' . (($this->client['BROWSER'] == 'gecko' && $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableMozillaExtension'])?'true':'false') . ';';
                
                        // The following properties apply only to the backend
                if (!is_object($TSFE)) {
                        $registerRTEinJSString .= '
+                       RTEarea['.$number.']["sys_language_content"] = "' . $this->contentLanguageUid . '";
                        RTEarea['.$number.']["typo3ContentLanguage"] = "' . $this->contentTypo3Language . '";
                        RTEarea['.$number.']["typo3ContentCharset"] = "' . $this->contentCharset . '";
                        RTEarea['.$number.']["enablePersonalDicts"] = ' . ($this->spellCheckerPersonalDicts ? 'true' : 'false') . ';
@@ -898,19 +930,109 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        RTEarea['.$number.']["plugin"] = new Array();';
                
                $pluginArray = t3lib_div::trimExplode(',', $this->pluginList , 1);
+               reset($pluginArray);
                while( list(,$plugin) = each($pluginArray) ) {
                        if ($this->isPluginEnable($plugin)) {
                                $registerRTEinJSString .= '
                        RTEarea['.$number.']["plugin"]["'.$plugin.'"] = true;';
                        }
                }
-
+               
+                       // Setting the buttons configuration
+               $registerRTEinJSString .= '
+                       RTEarea['.$number.']["buttons"] = new Array();';
+               if (is_array($this->thisConfig['buttons.'])) {
+                       reset($this->thisConfig['buttons.']);
+                       while( list($buttonIndex,$conf) = each($this->thisConfig['buttons.']) ) {
+                               $button = substr($buttonIndex, 0, -1);
+                               if (in_array($button,$this->toolBar)) {
+                                       $indexButton = 0;
+                                       $registerRTEinJSString .= '
+                       RTEarea['.$number.']["buttons"]["'.$button.'"] = {';
+                                       if (is_array($conf)) {
+                                               reset($conf);
+                                               while (list($propertyName,$conf1) = each($conf)) {
+                                                       $property = $propertyName;
+                                                       if ($indexButton) {
+                                                               $registerRTEinJSString .= ', ';
+                                                       }
+                                                       if (is_array($conf1)) {
+                                                               $property = substr($property, 0, -1);
+                                                               $indexProperty = 0;
+                                                               $registerRTEinJSString .= '"'.$property.'" : {';
+                                                               reset($conf1);
+                                                               while (list($property1Name,$conf2) = each($conf1)) {
+                                                                       $property1 = $property1Name;
+                                                                       if ($indexProperty) {
+                                                                               $registerRTEinJSString .= ', ';
+                                                                       }
+                                                                       if (is_array($conf2)) {
+                                                                               $property1 = substr($property1, 0, -1);
+                                                                               $indexProperty1 = 0;
+                                                                               $registerRTEinJSString .= '"'.$property1.'" : {';
+                                                                               reset($conf2);
+                                                                               while (list($property2Name,$conf3) = each($conf2)) {
+                                                                                       $property2 = $property2Name;
+                                                                                       if ($indexProperty1) {
+                                                                                               $registerRTEinJSString .= ', ';
+                                                                                       }
+                                                                                       if (is_array($conf3)) {
+                                                                                               $property2 = substr($property2, 0, -1);
+                                                                                               $indexProperty2 = 0;
+                                                                                               $registerRTEinJSString .= '"'.$property2.'" : {';
+                                                                                               reset($conf3);
+                                                                                               while (list($property3Name,$conf4) = each($conf3)) {
+                                                                                                       $property3 = $property3Name;
+                                                                                                       if ($indexProperty2) {
+                                                                                                               $registerRTEinJSString .= ', ';
+                                                                                                       }
+                                                                                                       if (!is_array($conf4)) {
+                                                                                                               $registerRTEinJSString .= '"'.$property3.'" : '.($conf4?'"'.$conf4.'"':'false');
+                                                                                                       }
+                                                                                                       $indexProperty2++;
+                                                                                               }
+                                                                                               $registerRTEinJSString .= '}';
+                                                                                       } else {
+                                                                                               $registerRTEinJSString .= '"'.$property2.'" : '.($conf3?'"'.$conf3.'"':'false');                                                                                                
+                                                                                       }
+                                                                                       $indexProperty1++;
+                                                                               }
+                                                                               $registerRTEinJSString .= '}';
+                                                                       } else {
+                                                                               $registerRTEinJSString .= '"'.$property1.'" : '.($conf2?'"'.$conf2.'"':'false');
+                                                                       }
+                                                                       $indexProperty++;
+                                                               }
+                                                               $registerRTEinJSString .= '}';
+                                                       } else {
+                                                               $registerRTEinJSString .= '"'.$property.'" : '.($conf1?'"'.$conf1.'"':'false');
+                                                       }
+                                                       $indexButton++;
+                                               }
+                                       }
+                                       $registerRTEinJSString .= '};';
+                               }
+                       }
+               }
+               
+                       // Deprecated inserttag button configuration
+               if (in_array('inserttag', $this->toolBar) && trim($this->thisConfig['hideTags'])) {
+                       if (!is_array($this->thisConfig['buttons.']['inserttag.'])) {
+                               $registerRTEinJSString .= '
+                       RTEarea['.$number.']["buttons"]["inserttag"] = new Array();
+                       RTEarea['.$number.']["buttons"]["inserttag"]["denyTags"] = "'.implode(',', t3lib_div::trimExplode(',', $this->thisConfig['hideTags'], 1)).'";';
+                       } elseif (!$this->thisConfig['buttons.']['inserttag.']['denyTags']) {
+                               $registerRTEinJSString .= '
+                       RTEarea['.$number.']["buttons"]["inserttag"]["denyTags"] = "'.implode(',', t3lib_div::trimExplode(',', $this->thisConfig['hideTags'], 1)).'";';
+                       }
+               }
+               
                        // Setting the list of tags to be removed if specified in the RTE config
                if (trim($this->thisConfig['removeTags']))  {
                        $registerRTEinJSString .= '
                        RTEarea['.$number.']["htmlRemoveTags"] = /^(' . implode('|', t3lib_div::trimExplode(',', $this->thisConfig['removeTags'], 1)) . ')$/i;';
                }
-
+               
                        // Setting the list of tags to be removed with their contents if specified in the RTE config
                if (trim($this->thisConfig['removeTagsAndContents']))  {
                        $registerRTEinJSString .= '
@@ -919,7 +1041,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                
                        // Process default style configuration
                $registerRTEinJSString .= '
-                       RTEarea['.$number.']["defaultPageStyle"] = "' . substr($this->siteURL,0,-1) . $this->buildJSFile('css', $this->buildStyleSheet(), 'css') . '";';
+                       RTEarea['.$number.']["defaultPageStyle"] = "' . $this->hostURL . $this->buildJSFile('css', $this->buildStyleSheet(), 'css') . '";';
                        
                        // Setting the pageStyle
                $filename = trim($this->thisConfig['contentCSS']) ? trim($this->thisConfig['contentCSS']) : 'EXT:' . $this->ID . '/htmlarea/plugins/DynamicCSS/dynamiccss.css';
@@ -948,12 +1070,22 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                if ($this->isPluginEnable('TableOperations')) {
                        $registerRTEinJSString .= '
                        RTEarea['.$number.']["hideTableOperationsInToolbar"] = ' . (trim($this->thisConfig['hideTableOperationsInToolbar']) ? 'true' : 'false') . ';
-                       RTEarea['.$number.']["keepToggleBordersInToolbar"] = ' . (trim($this->thisConfig['keepToggleBordersInToolbar'])?'true':'false') . ';
                        RTEarea['.$number.']["disableLayoutFieldsetInTableOperations"] = ' . (trim($this->thisConfig['disableLayoutFieldsetInTableOperations'])?'true':'false') . ';
                        RTEarea['.$number.']["disableAlignmentFieldsetInTableOperations"] = ' . (trim($this->thisConfig['disableAlignmentFieldsetInTableOperations'])?'true':'false') . ';
                        RTEarea['.$number.']["disableSpacingFieldsetInTableOperations"] = ' . (trim($this->thisConfig['disableSpacingFieldsetInTableOperations'])?'true':'false') . ';
                        RTEarea['.$number.']["disableBordersFieldsetInTableOperations"] = ' . (trim($this->thisConfig['disableBordersFieldsetInTableOperations'])?'true':'false') . ';
                        RTEarea['.$number.']["disableColorFieldsetInTableOperations"] = ' . (trim($this->thisConfig['disableColorFieldsetInTableOperations'])?'true':'false') . ';';
+                               // // Deprecated toggleborders button configuration
+                       if (in_array('toggleborders',$this->toolBar) && $this->thisConfig['keepToggleBordersInToolbar']) {
+                               if (!is_array($this->thisConfig['buttons.']['toggleborders.'])) {
+                                       $registerRTEinJSString .= '
+                       RTEarea['.$number.']["buttons"]["toggleborders"] = new Array();
+                       RTEarea['.$number.']["buttons"]["toggleborders"]["keepInToolbar"] = true;';
+                               } elseif (!$this->thisConfig['buttons.']['toggleborders.']['keepInToolbar']) {
+                                       $registerRTEinJSString .= '
+                       RTEarea['.$number.']["buttons"]["toggleborders"]["keepInToolbar"] = true;';
+                               }
+                       }
                }
                
                if ($this->isPluginEnable('Acronym')) {
@@ -999,15 +1131,28 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                } else {
                        $HTMLAreaFontSizes[0] = $LANG->getLL('No size');
                }
-               
-               //$HTMLAreaFontSizes = $this->defaultFontSizes;
+
                reset($this->defaultFontSizes);
                while( list($FontSizeItem,$FontSizeLabel) = each($this->defaultFontSizes)) {
-                       $HTMLAreaFontSizes[$FontSizeItem] = $FontSizeLabel;
+                       if ($this->client['BROWSER'] == 'safari') {
+                               $HTMLAreaFontSizes[$this->defaultFontSizes_safari[$FontSizeItem]] = $FontSizeLabel;
+                       } else {
+                               $HTMLAreaFontSizes[$FontSizeItem] = $FontSizeLabel;
+                       }
                }
                if ($this->thisConfig['hideFontSizes'] ) {
                        $hideFontSizes =  t3lib_div::trimExplode(',', $this->cleanList($this->thisConfig['hideFontSizes']), 1);
-                       foreach($hideFontSizes as $item)  unset($HTMLAreaFontSizes[strtolower($item)]);
+                       foreach($hideFontSizes as $item)  {
+                               if ($HTMLAreaFontSizes[strtolower($item)]) {
+                                       if ($this->client['BROWSER'] == 'safari') {
+                                               unset($HTMLAreaFontSizes[$this->defaultFontSizes_safari[strtolower($item)]]);
+                                       } else {
+                                               unset($HTMLAreaFontSizes[strtolower($item)]);
+                                       }
+                               } else {
+                                       
+                               }
+                       }
                }
                
                $HTMLAreaJSFontSize = '{';
@@ -1234,7 +1379,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        $addElementCode = '';
                        reset($mainElements);
                        while(list($elListName,$elValue)=each($mainElements))   {
-                               $addElementCode .= strToLower($elListName) . ' {'.$elValue."}\n";
+                               $addElementCode .= strToLower($elListName) . ' {' . $elValue . '}\n';
                        }
                        
                        $stylesheet = $this->thisConfig['mainStyleOverride'] ? $this->thisConfig['mainStyleOverride'] : chr(10) .
@@ -1281,7 +1426,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                
                        // Include JS arrays of configured classes
                $registerRTEinJSString .= '
-                       RTEarea['.$number.']["classesUrl"] = "' . substr($this->siteURL,0,-1) . $this->buildJSFile('classes_'.$this->contentLanguageUid, $this->buildJSClassesArray()) . '";';
+                       RTEarea['.$number.']["classesUrl"] = "' . $this->hostURL . $this->buildJSFile('classes_'.$this->contentLanguageUid, $this->buildJSClassesArray()) . '";';
                
                return $registerRTEinJSString;
        }
@@ -1292,7 +1437,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         * @return string               JS classes arrays
         */
        function buildJSClassesArray() {
-               global $TSFE, $LANG;
+               global $TSFE, $LANG, $TYPO3_CONF_VARS;
                
                if (is_object($TSFE)) {
                        $RTEProperties = $this->RTEsetup;
@@ -1300,7 +1445,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        $RTEProperties = $this->RTEsetup['properties'];
                }
                
-               $linebreak = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableCompressedScripts'] ? '' : chr(10);
+               $linebreak = $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'] ? '' : chr(10);
                $index = 0;
                $JSClassesLabelsArray = 'HTMLArea.classesLabels = { ' . $linebreak;
                $JSClassesValuesArray = 'HTMLArea.classesValues = { ' . $linebreak;
@@ -1338,9 +1483,9 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         * @return string               JS language array
         */
        function buildJSMainLangArray() { 
-               global $TSFE, $LANG;
-
-               $linebreak = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableCompressedScripts'] ? '' : chr(10);
+               global $TSFE, $LANG, $TYPO3_CONF_VARS;
+               
+               $linebreak = $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'] ? '' : chr(10);
                $JSLanguageArray .= 'var HTMLArea_langArray = new Array();' . $linebreak;
                $JSLanguageArray .= 'HTMLArea_langArray = { ' . $linebreak;
                if(is_object($TSFE)) {
@@ -1354,23 +1499,13 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                foreach($subArrays as $labels) {
                        $JSLanguageArray .= (($subArraysIndex++)?',':'') . $labels . ': {' . $linebreak;
                        if(is_object($TSFE)) {
-                               $LOCAL_LANG = $TSFE->readLLfile(t3lib_extMgm::extPath($this->ID).'htmlarea/locallang_' . $labels . '.php');
-                               if($this->typoVersion >= 3007000 ) {
-                                       $TSFE->csConvObj->convArray($LOCAL_LANG['default'], 'iso-8859-1', $this->OutputCharset);
-                                       if(!empty($LOCAL_LANG[$this->language])) $TSFE->csConvObj->convArray($LOCAL_LANG[$this->language], $this->charset, $this->OutputCharset);
-                               } else {
-                                       $this->convArray($LOCAL_LANG['default'], 'iso-8859-1', $this->OutputCharset);
-                                       if(!empty($LOCAL_LANG[$this->language])) $this->convArray($LOCAL_LANG[$this->language], $this->charset, $this->OutputCharset);
-                               }
+                               $LOCAL_LANG = $TSFE->readLLfile(t3lib_extMgm::extPath($this->ID).'htmlarea/locallang_' . $labels . '.xml', $this->language);
+                               $TSFE->csConvObj->convArray($LOCAL_LANG['default'], 'iso-8859-1', $this->OutputCharset);
+                               if(!empty($LOCAL_LANG[$this->language])) $TSFE->csConvObj->convArray($LOCAL_LANG[$this->language], $this->charset, $this->OutputCharset);
                        } else {
-                               $LOCAL_LANG = $LANG->readLLfile(t3lib_extMgm::extPath($this->ID).'htmlarea/locallang_' . $labels . '.php');
-                               if($this->typoVersion >= 3007000 ) {
-                                       $LANG->csConvObj->convArray($LOCAL_LANG['default'], 'iso-8859-1', $this->OutputCharset);
-                                       if(!empty($LOCAL_LANG[$this->language])) $LANG->csConvObj->convArray($LOCAL_LANG[$this->language], $this->charset, $this->OutputCharset);
-                               } else {
-                                       $this->convArray($LOCAL_LANG['default'], 'iso-8859-1', $this->OutputCharset);
-                                       if(!empty($LOCAL_LANG[$this->language])) $this->convArray($LOCAL_LANG[$this->language], $this->charset, $this->OutputCharset);
-                               }
+                               $LOCAL_LANG = $LANG->readLLfile(t3lib_extMgm::extPath($this->ID).'htmlarea/locallang_' . $labels . '.xml');
+                               $LANG->csConvObj->convArray($LOCAL_LANG['default'], 'iso-8859-1', $this->OutputCharset);
+                               if(!empty($LOCAL_LANG[$this->language])) $LANG->csConvObj->convArray($LOCAL_LANG[$this->language], $this->charset, $this->OutputCharset);
                        }
                        if(!empty($LOCAL_LANG[$this->language])) {
                                $LOCAL_LANG[$this->language] = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG['default'], $LOCAL_LANG[$this->language]);
@@ -1403,8 +1538,9 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         */
 
        function buildJSAcronymArray() {
-
-               $linebreak = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableCompressedScripts'] ? '' : chr(10);
+               global $TYPO3_CONF_VARS, $TYPO3_DB;
+               
+               $linebreak = $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'] ? '' : chr(10);
                $acronymIndex = 0;
                $abbraviationIndex = 0;
                $JSAcronymArray .= 'acronyms = { ' . $linebreak;
@@ -1417,8 +1553,8 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                }
                $whereClause .= t3lib_BEfunc::BEenableFields($table);
                $whereClause .= t3lib_BEfunc::deleteClause($table);
-               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('type,term,acronym', $table, $whereClause);
-               while($acronymRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))    {
+               $res = $TYPO3_DB->exec_SELECTquery('type,term,acronym', $table, $whereClause);
+               while($acronymRow = $TYPO3_DB->sql_fetch_assoc($res))    {
                        if($acronymRow['type'] == 1) $JSAcronymArray .= (($acronymIndex++)?',':'') . '"' . $acronymRow['acronym'] . '":"' . $acronymRow['term'] . '"' . $linebreak;
                        if($acronymRow['type'] == 2) $JSAbbreviationArray .= (($AbbreviationIndex++)?',':'') . '"' . $acronymRow['acronym'] . '":"' . $acronymRow['term'] . '"' . $linebreak;
                }
@@ -1456,26 +1592,28 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         * @return string               classesAnchor array definition
         */
        function buildJSClassesAnchorArray() {
-               global $LANG;
+               global $LANG, $TYPO3_CONF_VARS;
                
-               $linebreak = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableCompressedScripts'] ? '' : chr(10);
+               $linebreak = $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'] ? '' : chr(10);
                $JSClassesAnchorArray .= 'editor.classesAnchorSetup = [ ' . $linebreak;
                $classesAnchorIndex = 0;
                reset($this->RTEsetup['properties']['classesAnchor.']);
                while(list($label,$conf)=each($this->RTEsetup['properties']['classesAnchor.'])) {
-                       if(is_array($conf) && $conf['class']) {
+                       if (is_array($conf) && $conf['class']) {
                                $JSClassesAnchorArray .= (($classesAnchorIndex++)?',':'') . ' { ' . $linebreak;
                                $index = 0;
                                $JSClassesAnchorArray .= (($index++)?',':'') . 'name : "' . $conf['class'] . '"' . $linebreak;
-                               if($conf['type']) $JSClassesAnchorArray .= (($index++)?',':'') . 'type : "' . $conf['type'] . '"' . $linebreak;
-                               if(trim($conf['image'])) {
-                                       $JSClassesAnchorArray .= (($index++)?',':'') . 'image : "' . $this->getFullFileName(trim($conf['image'])) . '"' . $linebreak;
+                               if ($conf['type']) {
+                                       $JSClassesAnchorArray .= (($index++)?',':'') . 'type : "' . $conf['type'] . '"' . $linebreak;
                                }
-                               if(trim($conf['altText'])) {
+                               if (trim(str_replace('\'', '', str_replace('"', '', $conf['image'])))) {
+                                       $JSClassesAnchorArray .= (($index++)?',':'') . 'image : "' . $this->getFullFileName(trim(str_replace('\'', '', str_replace('"', '', $conf['image'])))) . '"' . $linebreak;
+                               }
+                               if (trim($conf['altText'])) {
                                        $string = $this->getLLContent(trim($conf['altText']));
                                        $JSClassesAnchorArray .= (($index++)?',':'') . 'altText : ' . str_replace('"', '\"', str_replace('\\\'', '\'', $string)) . $linebreak;
                                }
-                               if(trim($conf['titleText'])) {
+                               if (trim($conf['titleText'])) {
                                        $string = $this->getLLContent(trim($conf['titleText']));
                                        $JSClassesAnchorArray .= (($index++)?',':'') . 'titleText : ' . str_replace('"', '\"', str_replace('\\\'', '\'', $string)) . $linebreak;
                                }
@@ -1491,7 +1629,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         *
         * @return string               filename
         */
-
+        
        function buildJSFile($label,$contents,$ext='js') {
                $relFilename = 'typo3temp/' . $this->ID . '_' . $label . '_' . md5($contents) . '.' . $ext;
                $outputFilename = PATH_site . $relFilename;
@@ -1499,16 +1637,36 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        $outputHandle = fopen($outputFilename,'wb');
                        fwrite($outputHandle, $contents);
                        fclose($outputHandle);
+                       t3lib_div::fixPermissions($outputFilename);
                }
                return $this->httpTypo3Path . $relFilename;
        }
+       
+       /**
+        * Return a file name built with the label and containing a cached copy of the specified file
+        *
+        * @return string               filename
+        */
+        
+       function writeJSFileToTypo3tempDir($JSFile,$label,$compressed=FALSE,$ext='js') {
+               global $TYPO3_CONF_VARS;
 
+               $source = t3lib_div::getFileAbsFileName($JSFile);
+               $relFilename = 'typo3temp/' . $this->ID . '_' . $label . '_' . md5($JSFile . $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['version']) . ($compressed ? '-compressed' : '') . '.' . $ext;
+               $destination = PATH_site . $relFilename;
+               if(!file_exists($destination)) {
+                       @copy($source,$destination);
+                       t3lib_div::fixPermissions($destination);
+               }
+               return $this->httpTypo3Path . $relFilename;
+       }
+       
        /**
         * Return a file name containing the main JS language array for HTMLArea
         *
         * @return string               filename
         */
-
+        
        function buildJSMainLangFile($number) { 
                $contents = $this->buildJSMainLangArray() . chr(10);
                $pluginArray = t3lib_div::trimExplode(',', $this->pluginList , 1);
@@ -1525,31 +1683,21 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         *
         * @return string               JS language array
         */
-
+        
        function buildJSLangArray($plugin) {
-               global $TSFE, $LANG;
-
-               $linebreak = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableCompressedScripts'] ? '' : chr(10);
+               global $TSFE, $LANG, $TYPO3_CONF_VARS;
+               
+               $linebreak = $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'] ? '' : chr(10);
                if(is_object($TSFE)) {
-                       $LOCAL_LANG = $TSFE->readLLfile(t3lib_extMgm::extPath($this->ID).'htmlarea/plugins/' . $plugin . '/locallang.php');
-                       if($this->typoVersion >= 3007000 ) {
-                               if(!empty($LOCAL_LANG['default'])) $TSFE->csConvObj->convArray($LOCAL_LANG['default'], 'iso-8859-1', $this->OutputCharset);
-                               if(!empty($LOCAL_LANG[$this->language])) $TSFE->csConvObj->convArray($LOCAL_LANG[$this->language], $this->charset, $this->OutputCharset);
-                       } else {
-                               if(!empty($LOCAL_LANG['default'])) $this->convArray($LOCAL_LANG['default'], 'iso-8859-1', $this->OutputCharset);
-                               if(!empty($LOCAL_LANG[$this->language])) $this->convArray($LOCAL_LANG[$this->language], $this->charset, $this->OutputCharset);
-                       }
+                       $LOCAL_LANG = $TSFE->readLLfile(t3lib_extMgm::extPath($this->ID).'htmlarea/plugins/' . $plugin . '/locallang.xml', $this->language);
+                       if(!empty($LOCAL_LANG['default'])) $TSFE->csConvObj->convArray($LOCAL_LANG['default'], 'iso-8859-1', $this->OutputCharset);
+                       if(!empty($LOCAL_LANG[$this->language])) $TSFE->csConvObj->convArray($LOCAL_LANG[$this->language], $this->charset, $this->OutputCharset);
                } else {
-                       $LOCAL_LANG = $LANG->readLLfile(t3lib_extMgm::extPath($this->ID).'htmlarea/plugins/' . $plugin . '/locallang.php');
-                       if($this->typoVersion >= 3007000 ) {
-                               if(!empty($LOCAL_LANG['default'])) $LANG->csConvObj->convArray($LOCAL_LANG['default'], 'iso-8859-1', $this->OutputCharset);
-                               if(!empty($LOCAL_LANG[$this->language])) $LANG->csConvObj->convArray($LOCAL_LANG[$this->language], $this->charset, $this->OutputCharset);
-                       } else {
-                               if(!empty($LOCAL_LANG['default'])) $this->convArray($LOCAL_LANG['default'], 'iso-8859-1', $this->OutputCharset);
-                               if(!empty($LOCAL_LANG[$this->language])) $this->convArray($LOCAL_LANG[$this->language], $this->charset, $this->OutputCharset);
-                       }
+                       $LOCAL_LANG = $LANG->readLLfile(t3lib_extMgm::extPath($this->ID).'htmlarea/plugins/' . $plugin . '/locallang.xml');
+                       if(!empty($LOCAL_LANG['default'])) $LANG->csConvObj->convArray($LOCAL_LANG['default'], 'iso-8859-1', $this->OutputCharset);
+                       if(!empty($LOCAL_LANG[$this->language])) $LANG->csConvObj->convArray($LOCAL_LANG[$this->language], $this->charset, $this->OutputCharset);
                }
-
+               
                if(!empty($LOCAL_LANG[$this->language])) {
                        $LOCAL_LANG[$this->language] = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG['default'],$LOCAL_LANG[$this->language]);
                } else {
@@ -1585,8 +1733,8 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         */
 
        function getJSToolbarArray() {
-               $toolbar = "";                  // The JS-Code for the toolbar
-               $group = "";                    // The TS-Code for the group in the moment, each group are between "bar"s
+               $toolbar = '';                  // The JS-Code for the toolbar
+               $group = '';                    // The TS-Code for the group in the moment, each group are between "bar"s
                $group_has_button = false;      // True if the group has any enabled buttons
                $group_needs_starting_bar = false;
                $previous_is_space = false;
@@ -1615,7 +1763,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                $toolbar .= ', "' . $this->convertToolBarForHTMLArea($button) . '"';
                        } elseif ($button == 'bar' && !$group_has_button) {
                                $group_needs_starting_bar = true;
-                       } elseif ($button == "space" && $group_has_button && !$previous_is_space) {
+                       } elseif ($button == 'space' && $group_has_button && !$previous_is_space) {
                                $convertButton = $this->convertToolBarForHTMLArea($button);
                                $convertButton = '"' . $convertButton . '"';
                                $group .= $group ? (', ' . $convertButton) : ($group_needs_starting_bar ? ('"' . $this->convertToolBarForHTMLArea('bar') . '", ' . $convertButton) : $convertButton);
@@ -1636,12 +1784,13 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                }
                        // add the last group
                if($group_has_button) $toolbar .= $toolbar ? (', ' . $group) : ('[[' . $group);
-               $toolbar = $toolbar . "]]";
+               $toolbar = $toolbar . ']]';
                return $toolbar;
        }
        
        function getLLContent($string) {
                global $LANG;
+               
                $BE_lang = $LANG->lang;
                $BE_origCharset = $LANG->origCharSet;
                $BE_charSet = $LANG->charSet;
@@ -1708,6 +1857,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         */
 
        function clientInfo($useragent='')      {
+               global $TYPO3_CONF_VARS;
                
                if (!$useragent) $useragent=t3lib_div::getIndpEnv('HTTP_USER_AGENT');
                
@@ -1715,13 +1865,13 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        // Which browser?
                if (strstr($useragent,'Konqueror'))     {
                        $bInfo['BROWSER']= 'konqu';
-               } elseif (strstr($useragent,'Opera') &&  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['opera_test'] == 1)      {
+               } elseif (strstr($useragent,'Opera') &&  $TYPO3_CONF_VARS['EXTCONF']['rtehtmlarea']['opera_test'] == 1) {
                        $bInfo['BROWSER']= 'opera';
-               } elseif (strstr($useragent,'MSIE 4') || strstr($useragent,'MSIE 5') || strstr($useragent,'MSIE 6'))    {
+               } elseif (strstr($useragent,'MSIE'))    {
                        $bInfo['BROWSER']= 'msie';
                } elseif (strstr($useragent,'Gecko/'))  {
                        $bInfo['BROWSER']='gecko';
-               } elseif (strstr($useragent,'Safari/') &&  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['safari_test'] == 1) {
+               } elseif (strstr($useragent,'Safari/') &&  $TYPO3_CONF_VARS['EXTCONF']['rtehtmlarea']['safari_test'] == 1) {
                        $bInfo['BROWSER']='safari';
                } elseif (strstr($useragent,'Mozilla/4')) {
                        $bInfo['BROWSER']='net';
@@ -1822,21 +1972,6 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                return implode('; ',$nStyle);
        }
        
-       function convArray(&$array,$fromCS,$toCS,$useEntityForNoChar=0) {
-               global $TSFE, $LANG;
-               foreach($array as $key => $value)       {
-                       if (is_array($array[$key]))     {
-                               $this->convArray($array[$key],$fromCS,$toCS,$useEntityForNoChar);
-                       } else {
-                               if(is_object($TSFE)) {
-                                       $array[$key] = $TSFE->csConvObj->conv($array[$key],$fromCS,$toCS,$useEntityForNoChar);
-                               } else {
-                                       $array[$key] = $LANG->csConvObj->conv($array[$key],$fromCS,$toCS,$useEntityForNoChar);
-                               }
-                       }
-               }
-       }
-       
                // Hook on lorem_ipsum extension to insert text into the RTE in wysiwyg mode
        function loremIpsumInsert($params) {
                return "