* Added feature #6579: Make htmlArea RTE extensible
authorStanislas Rolland <typo3@sjbr.ca>
Thu, 1 Nov 2007 04:40:22 +0000 (04:40 +0000)
committerStanislas Rolland <typo3@sjbr.ca>
Thu, 1 Nov 2007 04:40:22 +0000 (04:40 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@2646 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/rtehtmlarea/ChangeLog
typo3/sysext/rtehtmlarea/class.tx_rtehtmlarea_base.php
typo3/sysext/rtehtmlarea/class.tx_rtehtmlareaapi.php [new file with mode: 0644]
typo3/sysext/rtehtmlarea/ext_emconf.php
typo3/sysext/rtehtmlarea/ext_localconf.php
typo3/sysext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php

index 3820f99..7140552 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2007-11-01  Stanislas Rolland  <stanislas.rolland@fructifor.ca>
+
+       * Added feature #6579: Make htmlArea RTE extensible
+
 2007-10-31  Ingo Renner  <ingo@typo3.org>
 
        * Added feature 6169: Add user function support to Constant Editor
index 27c2658..98562a2 100644 (file)
@@ -1,3 +1,7 @@
+2007-11-01  Stanislas Rolland  <stanislas.rolland@fructifor.ca>
+
+       * Added feature #6579: Make htmlArea RTE extensible
+
 2007-10-30  Oliver Hader  <oh@inpublica.de>
 
        * Fixed bug #6613: IRRE/RTE - Creating a new child record fails if record uses htmlArea RTE
index fe17ec9..ccf03a5 100644 (file)
@@ -70,20 +70,11 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                'showhelp',             // Has no content yet
                );
        
-               // Hide these toolbar buttons not implemented in Safari
-       var $conf_toolbar_safari_hide = array (
-               'strikethrough',
-               'line',
-               'orderedlist',
-               'unorderedlist',
-               );
-       
-               // Hide these toolbar buttons not implemented in Opera
-       var $conf_toolbar_opera_hide = array (
-               'copy',
-               'cut',
-               'paste',
-               );
+               // Hide toolbar buttons not implemented in client browsers
+       var $hideButtonsFromClient = array (
+               'safari'        =>      array('strikethrough', 'line', 'orderedlist', 'unorderedlist'),
+               'opera'         =>      array('copy', 'cut', 'paste'),
+               );
        
                // Always show these toolbar buttons (TYPO3 button name)
        var $conf_toolbar_show = array (
@@ -100,7 +91,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
        var $defaultHotKeyList = 'selectall, bold, italic, underline, strikethrough, left, center, right, justifyfull, formatblock, paste, cleanword, undo, redo';
 
                // Conversion array: TYPO3 button names to htmlArea button names
-       var $conf_toolbar_convert = array (
+       var $convertToolbarForHtmlAreaArray = array (
                        // 'TYPO3 name' => 'htmlArea name'
                'fontstyle'             => 'FontName',
                'fontsize'              => 'FontSize',
@@ -284,13 +275,13 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
        var $spellCheckerMode;
        var $quickTagHideTags;
        var $specConf;
-       var $toolBar = array();                 // Save the buttons for the toolbar
-       var $toolbar_level_size;                // The size for each level in the toolbar:
+       var $toolbar = array();                         // Save the buttons for the toolbar
+       var $toolbar_level_size;                        // The size for each level in the toolbar:
        var $toolbarOrderArray = array();
-       var $pluginEnableList;
-       var $pluginEnableArray = array();
-       var $pluginEnableArrayMultiple = array();
-
+       private $pluginEnabledArray = array();          // Array of plugin id's enabled in the current RTE editing area
+       private $pluginEnabledCumulativeArray = array();// Cumulative array of plugin id's enabled so far in any of the RTE editing areas of the form
+       private $registeredPlugins = array();           // Array of registered plugins indexed by their plugin Id's
+       
        /**
         * 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
@@ -308,13 +299,11 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        $rteConfBrowser = $this->conf_supported_browser;
                        if (!$TYPO3_CONF_VARS['EXTCONF']['rtehtmlarea']['enableInOpera9']) unset($rteConfBrowser['opera']);
                        if (is_array($rteConfBrowser)) {
-                               reset($rteConfBrowser);
-                               while(list ($browser, $browserConf) = each($rteConfBrowser)){
+                               foreach ($rteConfBrowser as $browser => $browserConf) {
                                        if ($browser == $this->client['BROWSER']) {
                                                        // Config for Browser found, check it:
                                                if (is_array($browserConf)) {
-                                                       reset($browserConf);
-                                                       while(list ($browserConfNr, $browserConfSub) = each($browserConf)){
+                                                       foreach ($browserConf as $browserConfNr => $browserConfSub) {
                                                                if ($browserConfSub['version'] <= $this->client['VERSION'] || empty($browserConfSub['version'])) {
                                                                        // Version is correct
                                                                        if ($browserConfSub['system'] == $this->client['SYSTEM'] || empty($browserConfSub['system'])) {
@@ -322,13 +311,13 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                                                                $rteIsAvailable = 1;
                                                                        }// End of System
                                                                }// End of Version
-                                                       }// End of while-BrowserSubpart
+                                                       }// End of foreach-BrowserSubpart
                                                } else {
                                                        // no config for this browser found, so all versions or system with this browsers are allow
                                                        $rteIsAvailable = 1;
                                                }
                                        } // End of Browser Check
-                               } // while: Browser Check
+                               } // foreach: Browser Check
                        } else {
                                // no Browser config for this RTE-Editor, so all Clients are allow                         
                        }
@@ -358,13 +347,12 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         * @param       integer         PID value of record (true parent page id)
         * @return      string          HTML code for RTE!
         */
-
-       function drawRTE(&$pObj,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue)      {
-               global $BE_USER,$LANG, $TYPO3_DB, $TYPO3_CONF_VARS;
-
-               $this->TCEform = $pObj;
+       
+       function drawRTE($parentObject, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue) {
+               global $BE_USER, $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);
@@ -372,7 +360,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                
                        // Draw form element:
                if ($this->debugMode)   {       // Draws regular text area (debug mode)
-                       $item = parent::drawRTE($pObj,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue);
+                       $item = parent::drawRTE($this->TCEform, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue);
                } else {        // Draw real RTE
                
                        /* =======================================
@@ -474,9 +462,23 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                         * TOOLBAR CONFIGURATION
                         * =======================================
                         */
-
+                               // 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 = &t3lib_div::getUserObj($pluginObjectConfiguration['objectReference']);
+                                       if (is_object($plugin)) {
+                                               if ($plugin->main($this)) {
+                                                       $this->registeredPlugins[$pluginId] = $plugin;
+                                                       $this->pluginButton[$pluginId] = $plugin->getPluginButtons();
+                                                       $this->pluginList .= ','.$pluginId;
+                                                       $this->convertToolbarForHtmlAreaArray = array_unique(array_merge($this->convertToolbarForHtmlAreaArray, $plugin->getConvertToolbarForHtmlAreaArray()));
+                                               }
+                                       }
+                               }
+                       }
+                       
                                // htmlArea plugins list
-                       $this->pluginEnableArray = t3lib_div::trimExplode(',', $this->pluginList, 1);
+                       $this->pluginEnabledArray = t3lib_div::trimExplode(',', $this->pluginList, 1);
                        $hidePlugins = array();
                        if(!t3lib_extMgm::isLoaded('static_info_tables') || in_array($this->language, t3lib_div::trimExplode(',', $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['noSpellCheckLanguages']))) $hidePlugins[] = 'SpellChecker';
                        if ($this->client['BROWSER'] == 'msie') $hidePlugins[] = 'Acronym';
@@ -485,26 +487,26 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                $this->thisConfig['hideTableOperationsInToolbar'] = 0;
                                $this->thisConfig['disableEnterParagraphs'] = 1;
                        }
-                       $this->pluginEnableArray = array_diff($this->pluginEnableArray, $hidePlugins);
+                       $this->pluginEnabledArray = array_diff($this->pluginEnabledArray, $hidePlugins);
 
                                // Toolbar
-                       $this->setToolBar();
+                       $this->setToolbar();
 
                                // Check if some plugins need to be disabled
                        $this->setPlugins();
                        
                                // Merge the list of enabled plugins with the lists from the previous RTE editing areas on the same form
-                       $this->pluginEnableArrayMultiple[$pObj->RTEcounter] = $this->pluginEnableArray;
-                       if ($pObj->RTEcounter > 1 && isset($this->pluginEnableArrayMultiple[$pObj->RTEcounter-1]) && is_array($this->pluginEnableArrayMultiple[$pObj->RTEcounter-1])) {
-                               $this->pluginEnableArrayMultiple[$pObj->RTEcounter] = array_unique(array_values(array_merge($this->pluginEnableArray,$this->pluginEnableArrayMultiple[$pObj->RTEcounter-1])));
+                       $this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter] = $this->pluginEnabledArray;
+                       if ($this->TCEform->RTEcounter > 1 && isset($this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter-1]) && is_array($this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter-1])) {
+                               $this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter] = array_unique(array_values(array_merge($this->pluginEnabledArray,$this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter-1])));
                        }
-
+                       
                        /* =======================================
                         * PLUGIN-SPECIFIC CONFIGURATION
                         * =======================================
                         */
                        
-                       if ($this->isPluginEnable('SpellChecker')) {
+                       if ($this->isPluginEnabled('SpellChecker')) {
                                        // Set the language of the content for the SpellChecker
                                $this->spellCheckerLanguage = $this->contentISOLanguage;
                                $this->spellCheckerTypo3Language = $this->contentTypo3Language;
@@ -533,9 +535,9 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
 
                        $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);
+                       $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);
-                       $RTEHeight = $RTEHeight + ($pObj->docLarge ?  (isset($BE_USER->userTS['options.']['RTELargeHeightIncrement']) ? $BE_USER->userTS['options.']['RTELargeHeightIncrement'] : 0) : 0);
+                       $RTEHeight = $RTEHeight + ($this->TCEform->docLarge ?  (isset($BE_USER->userTS['options.']['RTELargeHeightIncrement']) ? $BE_USER->userTS['options.']['RTELargeHeightIncrement'] : 0) : 0);
                        $editorWrapWidth = $RTEWidth . 'px';
                        $editorWrapHeight = $RTEHeight . 'px';
                        $this->RTEdivStyle = 'position:relative; left:0px; top:0px; height:' . $RTEHeight . 'px; width:'.$RTEWidth.'px; border: 1px solid black; padding: 2px 0px 2px 2px;';
@@ -548,7 +550,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
 
                                // Preloading the pageStyle
                        $filename = trim($this->thisConfig['contentCSS']) ? trim($this->thisConfig['contentCSS']) : 'EXT:' . $this->ID . '/htmlarea/plugins/DynamicCSS/dynamiccss.css';
-                       $pObj->additionalCode_pre['loadCSS'] = '
+                       $this->TCEform->additionalCode_pre['loadCSS'] = '
                <link rel="alternate stylesheet" type="text/css" href="' . $this->getFullFileName($filename) . '" />';
 
                                // Loading the editor skin
@@ -571,15 +573,26 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        }
                        $this->editorCSS = $skinFilename;
                        $this->editedContentCSS = $skinDir . '/htmlarea-edited-content.css';
-                       $pObj->additionalCode_pre['loadCSS'] .= '
+                       $this->TCEform->additionalCode_pre['loadCSS'] .= '
                <link rel="alternate stylesheet" type="text/css" href="' . $this->editedContentCSS . '" />';
-
-                       $pObj->additionalCode_pre['loadCSS'] .= '
+                       
+                               // Additional icons from registered plugins
+                       foreach ($this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter] as $pluginId) {
+                               if (is_object($this->registeredPlugins[$pluginId])) {
+                                       $pathToSkin = $this->registeredPlugins[$pluginId]->getPathToSkin();
+                                       if ($pathToSkin) {
+                                               $this->TCEform->additionalCode_pre['loadCSS'] .= '
+               <link rel="stylesheet" type="text/css" href="' . $this->httpTypo3Path . t3lib_extMgm::siteRelPath($this->registeredPlugins[$pluginId]->getExtensionKey()) . $pathToSkin . '" />';
+                                       }
+                               }
+                       }
+                               // Main skin
+                       $this->TCEform->additionalCode_pre['loadCSS'] .= '
                <link rel="stylesheet" type="text/css" href="' . $this->editorCSS . '" />';
-
+                       
                                // Loading JavaScript files and code
-                       $pObj->additionalCode_pre['loadJSfiles'] = $this->loadJSfiles($pObj->RTEcounter);
-                       $pObj->additionalJS_pre['loadJScode'] = $this->loadJScode($pObj->RTEcounter);
+                       $this->TCEform->additionalCode_pre['loadJSfiles'] = $this->loadJSfiles($this->TCEform->RTEcounter);
+                       $this->TCEform->additionalJS_pre['loadJScode'] = $this->loadJScode($this->TCEform->RTEcounter);
 
                        /* =======================================
                         * DRAW THE EDITOR
@@ -602,7 +615,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        }
 
                                // Register RTE windows
-                       $pObj->RTEwindows[] = $PA['itemFormElName'];
+                       $this->TCEform->RTEwindows[] = $PA['itemFormElName'];
 
                                // 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') {
@@ -615,21 +628,21 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                $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;';
-                               $pObj->additionalJS_post[] = $this->setRTEsizeByJS('RTEarea'.$pObj->RTEcounter, $height, $width);
+                               $this->TCEform->additionalJS_post[] = $this->setRTEsizeByJS('RTEarea'.$this->TCEform->RTEcounter, $height, $width);
                        }
 
                                // Register RTE in JS:
-                       $pObj->additionalJS_post[] = $this->registerRTEinJS($pObj->RTEcounter, $table, $row['uid'], $field);
+                       $this->TCEform->additionalJS_post[] = $this->registerRTEinJS($this->TCEform->RTEcounter, $table, $row['uid'], $field);
 
                                // Set the save option for the RTE:
-                       $pObj->additionalJS_submit[] = $this->setSaveRTE($pObj->RTEcounter, $pObj->formName, htmlspecialchars($PA['itemFormElName']));
+                       $this->TCEform->additionalJS_submit[] = $this->setSaveRTE($this->TCEform->RTEcounter, $this->TCEform->formName, htmlspecialchars($PA['itemFormElName']));
 
                                // Draw the textarea
                        $visibility = 'hidden';
                        $item = $this->triggerField($PA['itemFormElName']).'
-                               <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 id="pleasewait' . $this->TCEform->RTEcounter . '" class="pleasewait" style="display: none;" >' . $LANG->getLL('Please wait') . '</div>
+                               <div id="editorWrap' . $this->TCEform->RTEcounter . '" class="editorWrap" style="width:' . $editorWrapWidth . '; height:' . $editorWrapHeight . ';">
+                               <textarea id="RTEarea'.$this->TCEform->RTEcounter.'" name="'.htmlspecialchars($PA['itemFormElName']).'" style="'.t3lib_div::deHSCentities(htmlspecialchars($this->RTEdivStyle)).'">'.t3lib_div::formatForTextarea($value).'</textarea>
                                </div>' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableDebugMode'] ? '<div id="HTMLAreaLog"></div>' : '') . '
                                ';
                }
@@ -643,7 +656,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         *
         */
 
-       function setToolBar() {
+       function setToolbar() {
                global $BE_USER;
                
                $this->defaultToolbarOrder = 'bar, blockstylelabel, blockstyle, space, textstylelabel, textstyle, linebreak,
@@ -678,6 +691,13 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                columninsertbefore, columninsertafter, columndelete, columnsplit, bar,
                                cellproperties, cellinsertbefore, cellinsertafter, celldelete, cellsplit, cellmerge';
                }
+               
+                       // Additional buttons from registered plugins
+               foreach($this->registeredPlugins as $pluginId => $plugin) {
+                       if ($this->isPluginEnabled($pluginId)) {
+                               $this->defaultToolbarOrder = $plugin->addButtonsToToolbar();
+                       }
+               }
                $toolbarOrder = $this->thisConfig['toolbarOrder'] ? $this->thisConfig['toolbarOrder'] : $this->defaultToolbarOrder;
 
                        // Getting rid of undefined buttons
@@ -696,9 +716,8 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                }
                        }
                        if (is_array($this->thisConfig['showButtons.'])) {
-                               reset($this->thisConfig['showButtons.']);
-                               while(list($button,$value) = each($this->thisConfig['showButtons.'])) {
-                                       if ($value) $show[] = $button;
+                               foreach ($this->thisConfig['showButtons.'] as $buttonId => $value) {
+                                       if ($value) $show[] = $buttonId;
                                }
                                $show = array_unique($show);
                        }
@@ -716,52 +735,44 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                
                        // Hiding buttons of disabled plugins
                $hideButtons = array('space', 'bar', 'linebreak');
-               reset($this->pluginButton);
-               while(list($plugin, $buttonList) = each($this->pluginButton) ) {
-                       if(!$this->isPluginEnable($plugin)) {
+               foreach ($this->pluginButton as $pluginId => $buttonList) {
+                       if (!$this->isPluginEnabled($pluginId)) {
                                $buttonArray = t3lib_div::trimExplode(',',$buttonList,1);
-                               foreach($buttonArray as $button) {
+                               foreach ($buttonArray as $button) {
                                        $hideButtons[] = $button;
                                }
                        }
                }
-
+               
                        // Hiding labels of disabled plugins
-               reset($this->pluginLabel);
-               while(list($plugin, $label) = each($this->pluginLabel) ) {
-                       if(!$this->isPluginEnable($plugin)) $hideButtons[] = $label;
-               }
-
-                       // Hiding buttons not implemented in Safari
-               if ($this->client['BROWSER'] == 'safari') {
-                       reset($this->conf_toolbar_safari_hide);
-                       while(list(, $button) = each($this->conf_toolbar_safari_hide) ) {
-                               $hideButtons[] = $button;
+               foreach ($this->pluginLabel as $pluginId => $label) {
+                       if (!$this->isPluginEnabled($pluginId)) {
+                               $hideButtons[] = $label;
                        }
                }
                
-                       // Hiding buttons not implemented in Opera
-               if ($this->client['BROWSER'] == 'opera') {
-                       reset($this->conf_toolbar_opera_hide);
-                       while(list(, $button) = each($this->conf_toolbar_opera_hide) ) {
-                               $hideButtons[] = $button;
+                       // Hiding buttons not implemented in some clients
+               foreach ($this->hideButtonsFromClient as $client => $buttonArray) {
+                       if ($this->client['BROWSER'] == $client) {
+                               foreach($buttonArray as $buttonId) {
+                                       $hideButtons[] = $buttonId;
+                               }
                        }
                }
-
+               
                        // Hiding the buttons
                $show = array_diff($show, $this->conf_toolbar_hide, $hideButtons, t3lib_div::trimExplode(',',$this->thisConfig['hideButtons'],1));
 
                        // Adding the always show buttons
                $show = array_unique(array_merge($show, $this->conf_toolbar_show));
                $toolbarOrder = array_unique(array_merge($toolbarOrder, $this->conf_toolbar_show));
-               reset($this->conf_toolbar_show);
-               while(list(,$button) = each($this->conf_toolbar_show)) {
-                       if(!in_array($button, $this->toolbarOrderArray)) $this->toolbarOrderArray[] = $button;
+               foreach ($this->conf_toolbar_show as $buttonId) {
+                       if (!in_array($buttonId, $this->toolbarOrderArray)) $this->toolbarOrderArray[] = $buttonId;
                }
-
+               
                        // Getting rid of the buttons for which we have no position
                $show = array_intersect($show, $toolbarOrder);
-               $this->toolBar = $show;
+               $this->toolbar = $show;
        }
 
        /**
@@ -773,37 +784,40 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                global $TYPO3_CONF_VARS;
                
                $hideButtons = array();
+               
                        // Disabling the plugins if their buttons are not in the toolbar
                $hidePlugins = array();
-               reset($this->pluginButton);
-               while(list($plugin, $buttonList) = each($this->pluginButton) ) {
-                       $buttonArray = t3lib_div::trimExplode(',',$buttonList,1);
+               foreach ($this->pluginButton as $pluginId => $buttonList) {
+                       $buttonArray = t3lib_div::trimExplode(',', $buttonList, 1);
                        $showPlugin = false;
-                       while(list(,$button) = each($buttonArray) ) {
-                               if (in_array($button,$this->toolBar)) $showPlugin = true;
+                       foreach ($buttonArray as $button) {
+                               if (in_array($button, $this->toolbar)) {
+                                       $showPlugin = true;
+                               }
+                       }
+                       if (!$showPlugin) {
+                               $hidePlugins[] = $pluginId;
                        }
-                       if (!$showPlugin) $hidePlugins[] = $plugin;
                }
-               
                if($this->thisConfig['disableContextMenu'] || $this->thisConfig['disableRightClick']) $hidePlugins[] = 'ContextMenu';
                if($this->thisConfig['disableSelectColor']) $hidePlugins[] = 'SelectColor';
                if($this->thisConfig['disableTYPO3Browsers']) $hidePlugins[] = 'TYPO3Browsers';
                if(!$this->thisConfig['enableWordClean'] || !is_array($this->thisConfig['enableWordClean.'])) $hidePlugins[] = 'TYPO3HtmlParser';
                if(!t3lib_extMgm::isLoaded('static_info_tables') || in_array($this->language, t3lib_div::trimExplode(',', $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['noSpellCheckLanguages']))) $hidePlugins[] = 'SpellChecker';
-               
-               $this->pluginEnableArray = array_diff($this->pluginEnableArray, $hidePlugins);
+               $this->pluginEnabledArray = array_diff($this->pluginEnabledArray, $hidePlugins);
                
                        // Hiding labels of disabled plugins
-               reset($this->pluginLabel);
-               while(list($plugin, $label) = each($this->pluginLabel) ) {
-                       if(!$this->isPluginEnable($plugin)) $hideButtons[] = $label;
+               foreach ($this->pluginLabel as $pluginId => $label) {
+                       if (!$this->isPluginEnabled($pluginId)) {
+                               $hideButtons[] = $label;
+                       }
                }
-               $this->toolBar = array_diff($this->toolBar, $hideButtons);
-
+               $this->toolbar = array_diff($this->toolbar, $hideButtons);
+               
                        // Renaming buttons of replacement plugins
-               if( $this->isPluginEnable('SelectColor') ) {
-                       $this->conf_toolbar_convert['textcolor'] = 'CO-forecolor';
-                       $this->conf_toolbar_convert['bgcolor'] = 'CO-hilitecolor';
+               if( $this->isPluginEnabled('SelectColor') ) {
+                       $this->convertToolbarForHtmlAreaArray['textcolor'] = 'CO-forecolor';
+                       $this->convertToolbarForHtmlAreaArray['bgcolor'] = 'CO-hilitecolor';
                }
        }
 
@@ -814,8 +828,8 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         * @return      string  buttonname (htmlarea-name)
         */
 
-        function convertToolBarForHTMLArea($button) {
-               return $this->conf_toolbar_convert[$button];
+        function convertToolbarForHTMLArea($button) {
+               return $this->convertToolbarForHtmlAreaArray[$button];
         }
 
        /**
@@ -833,14 +847,16 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
        }
 
        /**
-        * Return the HTML-Code for loading the Javascript-Files
+        * Return the HTML code for loading the Javascript files
         *
-        * @return string               the html-code for loading the Javascript-Files
-        */
-       function loadJSfiles($number) {
+        * @param       integer         $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) {
                global $TYPO3_CONF_VARS;
                
-               return '
+               $loadJavascriptCode = '
                <script type="text/javascript">
                /*<![CDATA[*/
                        var i=1;
@@ -872,28 +888,30 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        var _spellChecker_charset = "' . $this->spellCheckerCharset . '";
                        var _spellChecker_mode = "' . $this->spellCheckerMode . '";
                /*]]>*/
-               </script>
-               <script type="text/javascript" src="' . $this->buildJSMainLangFile($number) . '"></script>
+               </script>';
+               $loadJavascriptCode .= '
+               <script type="text/javascript" src="' . $this->buildJSMainLangFile($RTEcounter) . '"></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 $loadJavascriptCode;
        }
        
        /**
-        * Return the JS-Code to initialize the Editor
+        * Return the inline Javascript code for initializing the RTE
         *
-        * @return string       the html-code for loading the Javascript-Files
+        * @param       integer         $RTEcounter: The index number of the current RTE editing area within the form.
+        *
+        * @return      string          the inline Javascript code for initializing the RTE
         */
         
-       function loadJScode($number) {
-               global $TSFE, $TYPO3_CONF_VARS;
+       function loadJScode($RTEcounter) {
+               global $TYPO3_CONF_VARS;
                
                $loadPluginCode = '';
-               $pluginArray = t3lib_div::trimExplode(',', $this->pluginList , 1);
-               while( list(,$plugin) = each($pluginArray) ) {
-                       if (in_array($plugin, $this->pluginEnableArrayMultiple[$number])) {
-                               $loadPluginCode .= '
-                       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']) . '");';
-                       }
+               foreach ($this->pluginEnabledCumulativeArray[$RTEcounter] as $pluginId) {
+                       $extensionKey = is_object($this->registeredPlugins[$pluginId]) ? $this->registeredPlugins[$pluginId]->getExtensionKey() : $this->ID;
+                       $loadPluginCode .= '
+                       HTMLArea.loadPlugin("' . $pluginId . '", true, "' . $this->writeJSFileToTypo3tempDir('EXT:' . $extensionKey . '/htmlarea/plugins/' . $pluginId . '/' . strtolower(preg_replace('/([a-z])([A-Z])([a-z])/', "$1".'-'."$2"."$3", $pluginId)) . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts']?'-compressed':'') .'.js', $pluginId, $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts']) . '");';
                }
                return (!$this->is_FE() ? '' : '
                ' . '/*<![CDATA[*/') . ($this->is_FE() ? '' : '
@@ -910,251 +928,255 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
        }
        
        /**
-        * Return the JS-Code for Register the RTE in JS
+        * Return the Javascript code for configuring the RTE
         * 
-        * @param       integer         $number: The index number of the RTE.
+        * @param       integer         $RTEcounter: The index number of the current RTE editing area within the form.
         * @param       string          $table: The table that includes this RTE (optional, necessary for IRRE).
         * @param       string          $uid: The uid of that table that includes this RTE (optional, necessary for IRRE).
         * @param       string          $field: The field of that record that includes this RTE (optional).
         *
-        * @return string               the JS-Code for Register the RTE in JS
+        * @return      string          the Javascript code for configuring the RTE
         */
-       
-       function registerRTEinJS($number, $table='', $uid='', $field='') {
-               global $TSFE, $TYPO3_CONF_VARS;
-
-               $registerRTEinJSString = (!$this->is_FE() ? '' : '
+       function registerRTEinJS($RTEcounter, $table='', $uid='', $field='') {
+               global $TYPO3_CONF_VARS;
+               
+               $configureRTEInJavascriptString = (!$this->is_FE() ? '' : '
                        ' . '/*<![CDATA[*/') . '
-                       RTEarea['.$number.'] = new Object();
-                       RTEarea['.$number.']["RTEtsConfigParams"] = "&RTEtsConfigParams=' . rawurlencode($this->RTEtsConfigParams()) . '";
-                       RTEarea['.$number.']["number"] = '.$number.';
-                       RTEarea['.$number.']["id"] = "RTEarea'.$number.'";
-                       RTEarea['.$number.']["enableWordClean"] = ' . (trim($this->thisConfig['enableWordClean'])?'true':'false') . ';
-                       RTEarea['.$number.']["htmlRemoveComments"] = ' . (trim($this->thisConfig['removeComments'])?'true':'false') . ';
-                       RTEarea['.$number.']["disableEnterParagraphs"] = ' . (trim($this->thisConfig['disableEnterParagraphs'])?'true':'false') . ';
-                       RTEarea['.$number.']["removeTrailingBR"] = ' . (trim($this->thisConfig['removeTrailingBR'])?'true':'false') . ';
-                       RTEarea['.$number.']["useCSS"] = ' . (trim($this->thisConfig['useCSS'])?'true':'false') . ';
-                       RTEarea['.$number.']["keepButtonGroupTogether"] = ' . (trim($this->thisConfig['keepButtonGroupTogether'])?'true':'false') . ';
-                       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')) || $this->thisConfig['forceHTTPS'])?'true':'false') . ';
-                       RTEarea['.$number.']["enableMozillaExtension"] = ' . (($this->client['BROWSER'] == 'gecko' && $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableMozillaExtension'])?'true':'false') . ';
-                       RTEarea['.$number.']["tceformsNested"] = ' . (is_object($this->TCEform) && method_exists($this->TCEform, 'getDynNestedStack') ? $this->TCEform->getDynNestedStack(true) : '[]') . ';';
+                       RTEarea['.$RTEcounter.'] = new Object();
+                       RTEarea['.$RTEcounter.']["RTEtsConfigParams"] = "&RTEtsConfigParams=' . rawurlencode($this->RTEtsConfigParams()) . '";
+                       RTEarea['.$RTEcounter.']["number"] = '.$RTEcounter.';
+                       RTEarea['.$RTEcounter.']["id"] = "RTEarea'.$RTEcounter.'";
+                       RTEarea['.$RTEcounter.']["enableWordClean"] = ' . (trim($this->thisConfig['enableWordClean'])?'true':'false') . ';
+                       RTEarea['.$RTEcounter.']["htmlRemoveComments"] = ' . (trim($this->thisConfig['removeComments'])?'true':'false') . ';
+                       RTEarea['.$RTEcounter.']["disableEnterParagraphs"] = ' . (trim($this->thisConfig['disableEnterParagraphs'])?'true':'false') . ';
+                       RTEarea['.$RTEcounter.']["removeTrailingBR"] = ' . (trim($this->thisConfig['removeTrailingBR'])?'true':'false') . ';
+                       RTEarea['.$RTEcounter.']["useCSS"] = ' . (trim($this->thisConfig['useCSS'])?'true':'false') . ';
+                       RTEarea['.$RTEcounter.']["keepButtonGroupTogether"] = ' . (trim($this->thisConfig['keepButtonGroupTogether'])?'true':'false') . ';
+                       RTEarea['.$RTEcounter.']["disablePCexamples"] = ' . (trim($this->thisConfig['disablePCexamples'])?'true':'false') . ';
+                       RTEarea['.$RTEcounter.']["statusBar"] = ' . (trim($this->thisConfig['showStatusBar'])?'true':'false') . ';
+                       RTEarea['.$RTEcounter.']["showTagFreeClasses"] = ' . (trim($this->thisConfig['showTagFreeClasses'])?'true':'false') . ';
+                       RTEarea['.$RTEcounter.']["useHTTPS"] = ' . ((trim(stristr($this->siteURL, 'https')) || $this->thisConfig['forceHTTPS'])?'true':'false') . ';
+                       RTEarea['.$RTEcounter.']["enableMozillaExtension"] = ' . (($this->client['BROWSER'] == 'gecko' && $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableMozillaExtension'])?'true':'false') . ';
+                       RTEarea['.$RTEcounter.']["tceformsNested"] = ' . (is_object($this->TCEform) && method_exists($this->TCEform, 'getDynNestedStack') ? $this->TCEform->getDynNestedStack(true) : '[]') . ';';
 
                        // The following properties apply only to the backend
                if (!$this->is_FE()) {
-                       $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') . ';
-                       RTEarea['.$number.']["userUid"] = "' . $this->userUid . '";';
+                       $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["sys_language_content"] = "' . $this->contentLanguageUid . '";
+                       RTEarea['.$RTEcounter.']["typo3ContentLanguage"] = "' . $this->contentTypo3Language . '";
+                       RTEarea['.$RTEcounter.']["typo3ContentCharset"] = "' . $this->contentCharset . '";
+                       RTEarea['.$RTEcounter.']["enablePersonalDicts"] = ' . ($this->spellCheckerPersonalDicts ? 'true' : 'false') . ';
+                       RTEarea['.$RTEcounter.']["userUid"] = "' . $this->userUid . '";';
                }
+               
                        // Setting the plugin flags
-               $registerRTEinJSString .= '
-                       RTEarea['.$number.']["plugin"] = new Object();';
-
+               $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["plugin"] = new Object();';
                $pluginArray = t3lib_div::trimExplode(',', $this->pluginList , 1);
-               reset($pluginArray);
-               while( list(,$plugin) = each($pluginArray) ) {
-                       if ($this->isPluginEnable($plugin)) {
-                               $registerRTEinJSString .= '
-                       RTEarea['.$number.']["plugin"]["'.$plugin.'"] = true;';
+               foreach ($pluginArray as $pluginId) {
+                       if ($this->isPluginEnabled($pluginId)) {
+                               $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["plugin"]["'.$pluginId.'"] = true;';
                        }
                }
                
                        // Setting the buttons configuration
-               $registerRTEinJSString .= '
-                       RTEarea['.$number.']["buttons"] = new Object();';
+               $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["buttons"] = new Object();';
                if (is_array($this->thisConfig['buttons.'])) {
-                       reset($this->thisConfig['buttons.']);
-                       while( list($buttonIndex,$conf) = each($this->thisConfig['buttons.']) ) {
+                       foreach ($this->thisConfig['buttons.'] as $buttonIndex => $conf) {
                                $button = substr($buttonIndex, 0, -1);
-                               if (in_array($button,$this->toolBar)) {
+                               if (in_array($button,$this->toolbar)) {
                                        $indexButton = 0;
-                                       $registerRTEinJSString .= '
-                       RTEarea['.$number.']["buttons"]["'.$button.'"] = {';
+                                       $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["buttons"]["'.$button.'"] = {';
                                        if (is_array($conf)) {
-                                               reset($conf);
-                                               while (list($propertyName,$conf1) = each($conf)) {
+                                               foreach ($conf as $propertyName => $conf1) {
                                                        $property = $propertyName;
                                                        if ($indexButton) {
-                                                               $registerRTEinJSString .= ', ';
+                                                               $configureRTEInJavascriptString .= ', ';
                                                        }
                                                        if (is_array($conf1)) {
                                                                $property = substr($property, 0, -1);
                                                                $indexProperty = 0;
-                                                               $registerRTEinJSString .= '"'.$property.'" : {';
-                                                               reset($conf1);
-                                                               while (list($property1Name,$conf2) = each($conf1)) {
+                                                               $configureRTEInJavascriptString .= '"'.$property.'" : {';
+                                                               foreach ($conf1 as $property1Name => $conf2) {
                                                                        $property1 = $property1Name;
                                                                        if ($indexProperty) {
-                                                                               $registerRTEinJSString .= ', ';
+                                                                               $configureRTEInJavascriptString .= ', ';
                                                                        }
                                                                        if (is_array($conf2)) {
                                                                                $property1 = substr($property1, 0, -1);
                                                                                $indexProperty1 = 0;
-                                                                               $registerRTEinJSString .= '"'.$property1.'" : {';
-                                                                               reset($conf2);
-                                                                               while (list($property2Name,$conf3) = each($conf2)) {
+                                                                               $configureRTEInJavascriptString .= '"'.$property1.'" : {';
+                                                                               foreach ($conf2 as $property2Name => $conf3) {
                                                                                        $property2 = $property2Name;
                                                                                        if ($indexProperty1) {
-                                                                                               $registerRTEinJSString .= ', ';
+                                                                                               $configureRTEInJavascriptString .= ', ';
                                                                                        }
                                                                                        if (is_array($conf3)) {
                                                                                                $property2 = substr($property2, 0, -1);
                                                                                                $indexProperty2 = 0;
-                                                                                               $registerRTEinJSString .= '"'.$property2.'" : {';
-                                                                                               reset($conf3);
-                                                                                               while (list($property3Name,$conf4) = each($conf3)) {
+                                                                                               $configureRTEInJavascriptString .= '"'.$property2.'" : {';
+                                                                                               foreach($conf3 as $property3Name => $conf4) {
                                                                                                        $property3 = $property3Name;
                                                                                                        if ($indexProperty2) {
-                                                                                                               $registerRTEinJSString .= ', ';
+                                                                                                               $configureRTEInJavascriptString .= ', ';
                                                                                                        }
                                                                                                        if (!is_array($conf4)) {
-                                                                                                               $registerRTEinJSString .= '"'.$property3.'" : '.($conf4?'"'.$conf4.'"':'false');
+                                                                                                               $configureRTEInJavascriptString .= '"'.$property3.'" : '.($conf4?'"'.$conf4.'"':'false');
                                                                                                        }
                                                                                                        $indexProperty2++;
                                                                                                }
-                                                                                               $registerRTEinJSString .= '}';
+                                                                                               $configureRTEInJavascriptString .= '}';
                                                                                        } else {
-                                                                                               $registerRTEinJSString .= '"'.$property2.'" : '.($conf3?'"'.$conf3.'"':'false');                                                                                                
+                                                                                               $configureRTEInJavascriptString .= '"'.$property2.'" : '.($conf3?'"'.$conf3.'"':'false');                                                                                               
                                                                                        }
                                                                                        $indexProperty1++;
                                                                                }
-                                                                               $registerRTEinJSString .= '}';
+                                                                               $configureRTEInJavascriptString .= '}';
                                                                        } else {
-                                                                               $registerRTEinJSString .= '"'.$property1.'" : '.($conf2?'"'.$conf2.'"':'false');
+                                                                               $configureRTEInJavascriptString .= '"'.$property1.'" : '.($conf2?'"'.$conf2.'"':'false');
                                                                        }
                                                                        $indexProperty++;
                                                                }
-                                                               $registerRTEinJSString .= '}';
+                                                               $configureRTEInJavascriptString .= '}';
                                                        } else {
-                                                               $registerRTEinJSString .= '"'.$property.'" : '.($conf1?'"'.$conf1.'"':'false');
+                                                               $configureRTEInJavascriptString .= '"'.$property.'" : '.($conf1?'"'.$conf1.'"':'false');
                                                        }
                                                        $indexButton++;
                                                }
                                        }
-                                       $registerRTEinJSString .= '};';
+                                       $configureRTEInJavascriptString .= '};';
                                }
                        }
                }
                
                        // Deprecated inserttag button configuration
-               if (in_array('inserttag', $this->toolBar) && trim($this->thisConfig['hideTags'])) {
+               if (in_array('inserttag', $this->toolbar) && trim($this->thisConfig['hideTags'])) {
                        if (!is_array($this->thisConfig['buttons.']['inserttag.'])) {
-                               $registerRTEinJSString .= '
-                       RTEarea['.$number.']["buttons"]["inserttag"] = new Object();
-                       RTEarea['.$number.']["buttons"]["inserttag"]["denyTags"] = "'.implode(',', t3lib_div::trimExplode(',', $this->thisConfig['hideTags'], 1)).'";';
+                               $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["buttons"]["inserttag"] = new Object();
+                       RTEarea['.$RTEcounter.']["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)).'";';
+                               $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["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;';
+                       $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["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 .= '
-                       RTEarea['.$number.']["htmlRemoveTagsAndContents"] = /^(' . implode('|', t3lib_div::trimExplode(',', $this->thisConfig['removeTagsAndContents'], 1)) . ')$/i;';
+                       $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["htmlRemoveTagsAndContents"] = /^(' . implode('|', t3lib_div::trimExplode(',', $this->thisConfig['removeTagsAndContents'], 1)) . ')$/i;';
                }
                
                        // Process default style configuration
-               $registerRTEinJSString .= '
-                       RTEarea['.$number.']["defaultPageStyle"] = "' . $this->hostURL . $this->buildJSFile('css', $this->buildStyleSheet(), 'css') . '";';
+               $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["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';
-               $registerRTEinJSString .= '
-                       RTEarea['.$number.']["pageStyle"] = "' . $this->getFullFileName($filename) .'";';
+               $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["pageStyle"] = "' . $this->getFullFileName($filename) .'";';
                
                        // Process colors configuration
-               if ( $this->isPluginEnable('SelectColor') ) {
-                       $registerRTEinJSString .= $this->buildJSColorsConfig($number);
+               if ( $this->isPluginEnabled('SelectColor') ) {
+                       $configureRTEInJavascriptString .= $this->buildJSColorsConfig($RTEcounter);
                }
                
                        // Process classes configuration
-               if ($this->isPluginEnable('InlineCSS') || $this->isPluginEnable('DynamicCSS')) {
-                       $registerRTEinJSString .= $this->buildJSClassesConfig($number);
+               if ($this->isPluginEnabled('InlineCSS') || $this->isPluginEnabled('DynamicCSS')) {
+                       $configureRTEInJavascriptString .= $this->buildJSClassesConfig($RTEcounter);
                }
                
                        // Process font faces configuration
-               if (in_array('fontstyle',$this->toolBar)) {
-                       $registerRTEinJSString .= $this->buildJSFontFacesConfig($number);
+               if (in_array('fontstyle',$this->toolbar)) {
+                       $configureRTEInJavascriptString .= $this->buildJSFontFacesConfig($RTEcounter);
                }
                
                        // Process paragraphs configuration
-               if (in_array('formatblock',$this->toolBar)) {
-                       $registerRTEinJSString .= $this->buildJSParagraphsConfig($number);
+               if (in_array('formatblock',$this->toolbar)) {
+                       $configureRTEInJavascriptString .= $this->buildJSParagraphsConfig($RTEcounter);
                }
                
                        // Process font sizes configuration
-               if (in_array('fontsize',$this->toolBar)) {
-                       $registerRTEinJSString .= $this->buildJSFontSizesConfig($number);
-               }
-               
-               if ($this->isPluginEnable('TableOperations')) {
-                       $registerRTEinJSString .= '
-                       RTEarea['.$number.']["hideTableOperationsInToolbar"] = ' . (trim($this->thisConfig['hideTableOperationsInToolbar']) ? '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') . ';';
+               if (in_array('fontsize',$this->toolbar)) {
+                       $configureRTEInJavascriptString .= $this->buildJSFontSizesConfig($RTEcounter);
+               }
+               
+               if ($this->isPluginEnabled('TableOperations')) {
+                       $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["hideTableOperationsInToolbar"] = ' . (trim($this->thisConfig['hideTableOperationsInToolbar']) ? 'true' : 'false') . ';
+                       RTEarea['.$RTEcounter.']["disableLayoutFieldsetInTableOperations"] = ' . (trim($this->thisConfig['disableLayoutFieldsetInTableOperations'])?'true':'false') . ';
+                       RTEarea['.$RTEcounter.']["disableAlignmentFieldsetInTableOperations"] = ' . (trim($this->thisConfig['disableAlignmentFieldsetInTableOperations'])?'true':'false') . ';
+                       RTEarea['.$RTEcounter.']["disableSpacingFieldsetInTableOperations"] = ' . (trim($this->thisConfig['disableSpacingFieldsetInTableOperations'])?'true':'false') . ';
+                       RTEarea['.$RTEcounter.']["disableBordersFieldsetInTableOperations"] = ' . (trim($this->thisConfig['disableBordersFieldsetInTableOperations'])?'true':'false') . ';
+                       RTEarea['.$RTEcounter.']["disableColorFieldsetInTableOperations"] = ' . (trim($this->thisConfig['disableColorFieldsetInTableOperations'])?'true':'false') . ';';
                                // // Deprecated toggleborders button configuration
-                       if (in_array('toggleborders',$this->toolBar) && $this->thisConfig['keepToggleBordersInToolbar']) {
+                       if (in_array('toggleborders',$this->toolbar) && $this->thisConfig['keepToggleBordersInToolbar']) {
                                if (!is_array($this->thisConfig['buttons.']['toggleborders.'])) {
-                                       $registerRTEinJSString .= '
-                       RTEarea['.$number.']["buttons"]["toggleborders"] = new Object();
-                       RTEarea['.$number.']["buttons"]["toggleborders"]["keepInToolbar"] = true;';
+                                       $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["buttons"]["toggleborders"] = new Object();
+                       RTEarea['.$RTEcounter.']["buttons"]["toggleborders"]["keepInToolbar"] = true;';
                                } elseif (!$this->thisConfig['buttons.']['toggleborders.']['keepInToolbar']) {
-                                       $registerRTEinJSString .= '
-                       RTEarea['.$number.']["buttons"]["toggleborders"]["keepInToolbar"] = true;';
+                                       $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["buttons"]["toggleborders"]["keepInToolbar"] = true;';
                                }
                        }
                }
                
-               if ($this->isPluginEnable('Acronym')) {
-                       $registerRTEinJSString .= '
-                       RTEarea['.$number.']["acronymUrl"] = "' . $this->buildJSFile('acronym_'.$this->contentLanguageUid, $this->buildJSAcronymArray()) . '";';
+               if ($this->isPluginEnabled('Acronym')) {
+                       $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["acronymUrl"] = "' . $this->buildJSFile('acronym_'.$this->contentLanguageUid, $this->buildJSAcronymArray()) . '";';
                }
                
-               if ($this->isPluginEnable('TYPO3Browsers')) {
-                       $registerRTEinJSString .= $this->buildJSClassesAnchorConfig($number);
+               if ($this->isPluginEnabled('TYPO3Browsers')) {
+                       $configureRTEInJavascriptString .= $this->buildJSClassesAnchorConfig($RTEcounter);
                }
                
-               $registerRTEinJSString .= '
-                       RTEarea['.$number.']["toolbar"] = '.$this->getJSToolbarArray().';
-                       HTMLArea.initEditor('.$number.');' . (!$this->is_FE() ? '' : '
+                       // Add Javascript configuration for registered plugins
+               foreach ($this->registeredPlugins as $pluginId => $plugin) {
+                       if ($this->isPluginEnabled($pluginId)) {
+                               $configureRTEInJavascriptString .= $plugin->buildJavascriptConfiguration($RTEcounter);
+                       }
+               }
+               
+               $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["toolbar"] = '.$this->getJSToolbarArray().';
+                       HTMLArea.initEditor('.$RTEcounter.');' . (!$this->is_FE() ? '' : '
                        /*]]>*/');
-               return $registerRTEinJSString;
+               return $configureRTEInJavascriptString;
        }
 
        /**
-        * Return ture, if the plugin can loaded
+        * Return true, if the plugin can be loaded
         *
-        * @return boolean              1 if the plugin can be loaded
+        * @param       string          $pluginId: The identification string of the plugin
+        *
+        * @return      boolean         true if the plugin can be loaded
         */
-
-       function isPluginEnable($plugin) { 
-               return in_array($plugin, $this->pluginEnableArray);
+       
+       function isPluginEnabled($pluginId) { 
+               return in_array($pluginId, $this->pluginEnabledArray);
        }
        
        
        /**
-        * Return JS configuration of font sizes
+        * Return Javascript configuration of font sizes
+        *
+        * @param       integer         $RTEcounter: The index number of the current RTE editing area within the form.
         *
-        * @return string               JS font sizes configuration
+        * @return      string          Javascript font sizes configuration
         */
-       function buildJSFontSizesConfig($number) {
+       function buildJSFontSizesConfig($RTEcounter) {
                global $LANG, $TSFE;
-               $registerRTEinJSString = '';
+               $configureRTEInJavascriptString = '';
                
                        // Builing JS array of default font sizes
                $HTMLAreaFontSizes = array();
@@ -1163,9 +1185,8 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                } else {
                        $HTMLAreaFontSizes[0] = $LANG->getLL('No size');
                }
-
-               reset($this->defaultFontSizes);
-               while( list($FontSizeItem,$FontSizeLabel) = each($this->defaultFontSizes)) {
+               
+               foreach ($this->defaultFontSizes as $FontSizeItem => $FontSizeLabel) {
                        if ($this->client['BROWSER'] == 'safari') {
                                $HTMLAreaFontSizes[$this->defaultFontSizes_safari[$FontSizeItem]] = $FontSizeLabel;
                        } else {
@@ -1174,7 +1195,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                }
                if ($this->thisConfig['hideFontSizes'] ) {
                        $hideFontSizes =  t3lib_div::trimExplode(',', $this->cleanList($this->thisConfig['hideFontSizes']), 1);
-                       foreach($hideFontSizes as $item)  {
+                       foreach ($hideFontSizes as $item)  {
                                if ($HTMLAreaFontSizes[strtolower($item)]) {
                                        if ($this->client['BROWSER'] == 'safari') {
                                                unset($HTMLAreaFontSizes[$this->defaultFontSizes_safari[strtolower($item)]]);
@@ -1189,9 +1210,8 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                
                $HTMLAreaJSFontSize = '{';
                if ($this->cleanList($this->thisConfig['hideFontSizes']) != '*') {
-                       reset($HTMLAreaFontSizes);
-                       $HTMLAreaParagraphIndex = 0;
-                       while( list($FontSizeItem,$FontSizeLabel) = each($HTMLAreaFontSizes)) {
+                       $HTMLAreaFontSizeIndex = 0;
+                       foreach ($HTMLAreaFontSizes as $FontSizeItem => $FontSizeLabel) {
                                if($HTMLAreaFontSizeIndex) { 
                                        $HTMLAreaJSFontSize .= ',';
                                }
@@ -1201,19 +1221,21 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        }
                }
                $HTMLAreaJSFontSize .= '};';
-               $registerRTEinJSString .= '
-                       RTEarea['.$number.']["fontsize"] = '. $HTMLAreaJSFontSize;
+               $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["fontsize"] = '. $HTMLAreaJSFontSize;
                        
-               return $registerRTEinJSString;
+               return $configureRTEInJavascriptString;
        }
        /**
-        * Return JS configuration of paragraphs
+        * Return Javascript configuration of block elements
+        *
+        * @param       integer         $RTEcounter: The index number of the current RTE editing area within the form.
         *
-        * @return string               JS paragraphs configuration
+        * @return      string          Javascript configuration of block elements
         */
-       function buildJSParagraphsConfig($number) {
+       function buildJSParagraphsConfig($RTEcounter) {
                global $TSFE, $LANG;
-               $registerRTEinJSString = '';
+               $configureRTEInJavascriptString = '';
                
                        // Paragraphs
                $HTMLAreaParagraphs = $this->defaultParagraphs;
@@ -1223,9 +1245,8 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                }
                $HTMLAreaJSParagraph = '{';
                if ($this->cleanList($this->thisConfig['hidePStyleItems']) != '*') {
-                       reset($HTMLAreaParagraphs);
                        $HTMLAreaParagraphIndex = 0;
-                       while( list($PStyleItem,$PStyleLabel) = each($HTMLAreaParagraphs)) {
+                       foreach ($HTMLAreaParagraphs as $PStyleItem => $PStyleLabel) {
                                if($HTMLAreaParagraphIndex) { 
                                        $HTMLAreaJSParagraph .= ',';
                                }
@@ -1241,18 +1262,20 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        }
                }
                $HTMLAreaJSParagraph .= '};';
-               $registerRTEinJSString .= '
-                       RTEarea['.$number.']["paragraphs"] = '. $HTMLAreaJSParagraph;
+               $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["paragraphs"] = '. $HTMLAreaJSParagraph;
                        
-               return $registerRTEinJSString;
+               return $configureRTEInJavascriptString;
        }
        
        /**
-        * Return JS configuration of font faces
+        * Return Javascript configuration of font faces
         *
-        * @return string               JS font faces configuration
-        */
-       function buildJSFontfacesConfig($number) {
+        * @param       integer         $RTEcounter: The index number of the current RTE editing area within the form.
+        *
+        * @return      string          Javascript configuration of font faces
+        */
+       function buildJSFontfacesConfig($RTEcounter) {
                global $TSFE, $LANG;
                
                if ($this->is_FE()) {
@@ -1261,7 +1284,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        $RTEProperties = $this->RTEsetup['properties'];
                }
                
-               $registerRTEinJSString = '';
+               $configureRTEInJavascriptString = '';
                
                        // Builing JS array of default font faces
                $HTMLAreaFontname = array();
@@ -1279,8 +1302,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                $hideFontFaces = $this->cleanList($this->thisConfig['hideFontFaces']);
                if ($hideFontFaces != '*') {
                        $index = 0;
-                       reset($this->defaultFontFaces);
-                       while (list($fontName,$fontValue) = each($this->defaultFontFaces)) {
+                       foreach ($this->defaultFontFaces as $fontName => $fontValue) {
                                if (!t3lib_div::inList($hideFontFaces, $index+1)) {
                                        $HTMLAreaFontname[$fontName] = '
                                "' . $fontName . '" : "' . $this->cleanList($fontValue) . '"';
@@ -1292,8 +1314,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                
                        // Adding configured font faces
                if (is_array($RTEProperties['fonts.'])) {
-                       reset($RTEProperties['fonts.']);
-                       while(list($fontName,$conf)=each($RTEProperties['fonts.'])) {
+                       foreach ($RTEProperties['fonts.'] as $fontName => $conf) {
                                $fontName = substr($fontName,0,-1);
                                $fontLabel = $this->getPageConfigLabel($conf['name'],0);
                                $HTMLAreaFontname[$fontName] = '
@@ -1304,9 +1325,8 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        // Setting the list of font faces
                $HTMLAreaJSFontface = '{';
                $HTMLAreaFontface = t3lib_div::trimExplode(',' , $this->cleanList($defaultFontFacesList . ',' . $this->thisConfig['fontFace']));
-               reset($HTMLAreaFontface);
                $HTMLAreaFontfaceIndex = 0;
-               while( list(,$fontName) = each($HTMLAreaFontface)) {
+               foreach ($HTMLAreaFontface as $fontName) {
                        if($HTMLAreaFontfaceIndex) { 
                                $HTMLAreaJSFontface .= ',';
                        }
@@ -1315,18 +1335,20 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                }
                $HTMLAreaJSFontface .= '};';
                
-               $registerRTEinJSString .= '
-                       RTEarea['.$number.']["fontname"] = '. $HTMLAreaJSFontface;
+               $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["fontname"] = '. $HTMLAreaJSFontface;
                
-               return $registerRTEinJSString;
+               return $configureRTEInJavascriptString;
        }
        
        /**
-        * Return JS configuration of colors
+        * Return Javascript configuration of colors
+        *
+        * @param       integer         $RTEcounter: The index number of the current RTE editing area within the form.
         *
-        * @return string               JS colors configuration
+        * @return      string          Javascript configuration of colors
         */
-       function buildJSColorsConfig($number) {
+       function buildJSColorsConfig($RTEcounter) {
                global $TSFE, $LANG;
                
                if ($this->is_FE()) {
@@ -1335,21 +1357,20 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        $RTEProperties = $this->RTEsetup['properties'];
                }
                
-               $registerRTEinJSString = '';
+               $configureRTEInJavascriptString = '';
                
                if(trim($this->thisConfig['disableColorPicker'])) {
-                       $registerRTEinJSString .= '
-                       RTEarea['.$number.']["disableColorPicker"] = true;';
+                       $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["disableColorPicker"] = true;';
                } else {
-                       $registerRTEinJSString .= '
-                       RTEarea['.$number.']["disableColorPicker"] = false;';
+                       $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["disableColorPicker"] = false;';
                }
                
                        // Building JS array of configured colors
                if (is_array($RTEProperties['colors.']) )  {
                        $HTMLAreaColorname = array();
-                       reset($RTEProperties['colors.']);
-                       while(list($colorName,$conf)=each($RTEProperties['colors.']))      {
+                       foreach ($RTEProperties['colors.'] as $colorName => $conf) {
                                $colorName=substr($colorName,0,-1);
                                $colorLabel = $this->getPageConfigLabel($conf['name']);
                                $HTMLAreaColorname[$colorName] = '
@@ -1361,9 +1382,8 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                if ($this->thisConfig['colors'] ) {
                        $HTMLAreaJSColors = '[';
                        $HTMLAreaColors = t3lib_div::trimExplode(',' , $this->cleanList($this->thisConfig['colors']));
-                       reset($HTMLAreaColors);
                        $HTMLAreaColorsIndex = 0;
-                       while( list(,$colorName) = each($HTMLAreaColors)) {
+                       foreach ($HTMLAreaColors as $colorName) {
                                if($HTMLAreaColorsIndex && $HTMLAreaColorname[$colorName]) { 
                                        $HTMLAreaJSColors .= ',';
                                }
@@ -1371,11 +1391,11 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                $HTMLAreaColorsIndex++;
                        }
                        $HTMLAreaJSColors .= '];';
-                       $registerRTEinJSString .= '
-                       RTEarea['.$number.']["colors"] = '. $HTMLAreaJSColors;
+                       $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["colors"] = '. $HTMLAreaJSColors;
                }
                
-               return $registerRTEinJSString;
+               return $configureRTEInJavascriptString;
        }
        
        /**
@@ -1391,16 +1411,14 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        $mainElements = array();
                        $mainElements['P'] = $this->thisConfig['mainStyleOverride_add.']['P'];
                        $elList = explode(',','H1,H2,H3,H4,H5,H6,PRE');
-                       reset($elList);
-                       while(list(,$elListName)=each($elList)) {
+                       foreach ($elList as $elListName) {
                                if ($this->thisConfig['mainStyleOverride_add.'][$elListName]) {
                                        $mainElements[$elListName] = $this->thisConfig['mainStyleOverride_add.'][$elListName];
                                }
                        }
                        
                        $addElementCode = '';
-                       reset($mainElements);
-                       while(list($elListName,$elValue)=each($mainElements))   {
+                       foreach ($mainElements as $elListName => $elValue) {
                                $addElementCode .= strToLower($elListName) . ' {' . $elValue . '}' . chr(10);
                        }
                        
@@ -1428,29 +1446,30 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
        }
        
        /**
-        * Return JS configuration of classes
+        * Return Javascript configuration of classes
         *
-        * @return string               JS classes configuration
+        * @param       integer         $RTEcounter: The index number of the current RTE editing area within the form.
+        *
+        * @return      string          Javascript configuration of classes
         */
-       function buildJSClassesConfig($number) {
-               
+       function buildJSClassesConfig($RTEcounter) {
                        // Build JS array of lists of classes
                $classesTagList = 'classesCharacter, classesParagraph, classesImage, classesTable, classesLinks, classesTD';
                $classesTagConvert = array( 'classesCharacter' => 'span', 'classesParagraph' => 'p', 'classesImage' => 'img', 'classesTable' => 'table', 'classesLinks' => 'a', 'classesTD' => 'td');
                $classesTagArray = t3lib_div::trimExplode(',' , $classesTagList);
-               $registerRTEinJSString = '
-                       RTEarea['.$number.']["classesTag"] = new Object();';
-               while( list(,$classesTagName) = each($classesTagArray)) {
+               $configureRTEInJavascriptString = '
+                       RTEarea['.$RTEcounter.']["classesTag"] = new Object();';
+               foreach ($classesTagArray as $classesTagName) {
                        $HTMLAreaJSClasses = ($this->thisConfig[$classesTagName])?('"' . $this->cleanList($this->thisConfig[$classesTagName]) . '";'):'null;';
-                       $registerRTEinJSString .= '
-                       RTEarea['.$number.']["classesTag"]["'. $classesTagConvert[$classesTagName] .'"] = '. $HTMLAreaJSClasses;
+                       $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["classesTag"]["'. $classesTagConvert[$classesTagName] .'"] = '. $HTMLAreaJSClasses;
                }
                
                        // Include JS arrays of configured classes
-               $registerRTEinJSString .= '
-                       RTEarea['.$number.']["classesUrl"] = "' . $this->hostURL . $this->buildJSFile('classes_'.$this->contentLanguageUid, $this->buildJSClassesArray()) . '";';
+               $configureRTEInJavascriptString .= '
+               RTEarea['.$RTEcounter.']["classesUrl"] = "' . $this->hostURL . $this->buildJSFile('classes_'.$this->language, $this->buildJSClassesArray()) . '";';
                
-               return $registerRTEinJSString;
+               return $configureRTEInJavascriptString;
        }
        
        /**
@@ -1476,8 +1495,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        // Scanning the list of classes if specified in the RTE config
                if (is_array($RTEProperties['classes.']))  {
                        $stylesheet = '';
-                       reset($RTEProperties['classes.']);
-                       while(list($className,$conf)=each($RTEProperties['classes.'])) {
+                       foreach ($RTEProperties['classes.'] as $className => $conf) {
                                $className = substr($className,0,-1);
                                $classLabel = $this->getPageConfigLabel($conf['name']);
                                $JSClassesLabelsArray .= (($index)?',':'') . '"' . $className . '": ' . $classLabel . $linebreak;
@@ -1494,11 +1512,11 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
        }
        
        /**
-        * Return a JS language array for htmlArea RTE
+        * Return a Javascript localization array for htmlArea RTE
         *
-        * @return string               JS language array
+        * @return      string          Javascript localization array
         */
-       function buildJSMainLangArray() { 
+       function buildJSMainLangArray() {
                global $TSFE, $LANG, $TYPO3_CONF_VARS;
                
                $linebreak = $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'] ? '' : chr(10);
@@ -1550,7 +1568,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
        /**
         * Return an acronym array for the Acronym plugin
         *
-        * @return string               acronym array
+        * @return      string          acronym Javascript array
         */
 
        function buildJSAcronymArray() {
@@ -1581,12 +1599,13 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
        }
        
        /**
-        * Return JS configuration of special anchor classes
+        * Return Javascript configuration of special anchor classes
         *
-        * @return string               JS special anchor classes configuration
+        * @param       integer         $RTEcounter: The index number of the current RTE editing area within the form.
+        *
+        * @return      string          Javascript configuration of special anchor classes
         */
-       function buildJSClassesAnchorConfig($number) {
-               global $TSFE;
+       function buildJSClassesAnchorConfig($RTEcounter) {
                
                if ($this->is_FE()) {
                        $RTEProperties = $this->RTEsetup;
@@ -1594,18 +1613,18 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        $RTEProperties = $this->RTEsetup['properties'];
                }
                
-               $registerRTEinJSString = '';
+               $configureRTEInJavascriptString = '';
                if (is_array($RTEProperties['classesAnchor.'])) {
-                       $registerRTEinJSString .= '
-                       RTEarea['.$number.']["classesAnchorUrl"] = "' . $this->buildJSFile('classesAnchor_'.$this->contentLanguageUid, $this->buildJSClassesAnchorArray()) . '";';
+                       $configureRTEInJavascriptString .= '
+                       RTEarea['.$RTEcounter.']["classesAnchorUrl"] = "' . $this->buildJSFile('classesAnchor_'.$this->contentLanguageUid, $this->buildJSClassesAnchorArray()) . '";';
                }
-               return $registerRTEinJSString;
+               return $configureRTEInJavascriptString;
        }
        
        /**
         * Return a JS array for special anchor classes
         *
-        * @return string               classesAnchor array definition
+        * @return      string          classesAnchor array definition
         */
        function buildJSClassesAnchorArray() {
                global $LANG, $TYPO3_CONF_VARS;
@@ -1613,8 +1632,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                $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.'])) {
+               foreach ($this->RTEsetup['properties']['classesAnchor.'] as $label => $conf) {
                        if (is_array($conf) && $conf['class']) {
                                $JSClassesAnchorArray .= (($classesAnchorIndex++)?',':'') . ' { ' . $linebreak;
                                $index = 0;
@@ -1680,14 +1698,16 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
        /**
         * Return a file name containing the main JS language array for HTMLArea
         *
-        * @return string               filename
+        * @param       integer         $RTEcounter: The index number of the current RTE editing area within the form.
+        *
+        * @return      string          filename
         */
         
-       function buildJSMainLangFile($number) { 
+       function buildJSMainLangFile($RTEcounter) { 
                $contents = $this->buildJSMainLangArray() . chr(10);
-               $pluginArray = t3lib_div::trimExplode(',', $this->pluginList , 1);
-               while( list(,$plugin) = each($pluginArray) ) {
-                       if (in_array($plugin, $this->pluginEnableArrayMultiple[$number])) {
+               $pluginArray = t3lib_div::trimExplode(',', $this->pluginList, 1);
+               foreach ($pluginArray as $plugin) {
+                       if (in_array($plugin, $this->pluginEnabledCumulativeArray[$RTEcounter])) {
                                $contents .= $this->buildJSLangArray($plugin) . chr(10);
                        }
                }
@@ -1695,21 +1715,25 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
        }
 
        /**
-        * Return a JS language array for the plugin
+        * Return a Javascript localization array for the plugin
         *
-        * @return string               JS language array
+        * @param       string          $plugin: identification string of the plugin
+        *
+        * @return      string          Javascript localization array
         */
         
        function buildJSLangArray($plugin) {
                global $TSFE, $LANG, $TYPO3_CONF_VARS;
                
+               $extensionKey = is_object($this->registeredPlugins[$plugin]) ? $this->registeredPlugins[$plugin]->getExtensionKey() : $this->ID;
+               
                $linebreak = $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'] ? '' : chr(10);
                if($this->is_FE()) {
-                       $LOCAL_LANG = $TSFE->readLLfile(t3lib_extMgm::extPath($this->ID).'htmlarea/plugins/' . $plugin . '/locallang.xml', $this->language);
+                       $LOCAL_LANG = $TSFE->readLLfile(t3lib_extMgm::extPath($extensionKey).'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.xml');
+                       $LOCAL_LANG = $LANG->readLLfile(t3lib_extMgm::extPath($extensionKey).'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);
                }
@@ -1756,13 +1780,12 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                $previous_is_space = false;
 
                        // process each button in the order list
-               reset($this->toolbarOrderArray);
-               while (list(, $button) = each($this->toolbarOrderArray) ) {
+               foreach ($this->toolbarOrderArray as $button) {
                        // check if a new group starts
                        if (($button == 'bar' || $button == 'linebreak') && $group_has_button) {
                                        // New line
                                if ($button == 'linebreak') {
-                                       $convertButton = '"' . $this->convertToolBarForHTMLArea('linebreak') . '"';
+                                       $convertButton = '"' . $this->convertToolbarForHTMLArea('linebreak') . '"';
                                        $group = ($group!='') ? ($group . ', ' . $convertButton) : $convertButton;
                                }
                                        // New group
@@ -1776,21 +1799,21 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                $group = '';
                                $previous_is_space = false;
                                $group_needs_starting_bar = false;
-                               $toolbar .= ', "' . $this->convertToolBarForHTMLArea($button) . '"';
+                               $toolbar .= ', "' . $this->convertToolbarForHTMLArea($button) . '"';
                        } elseif ($button == 'bar' && !$group_has_button) {
                                $group_needs_starting_bar = true;
                        } elseif ($button == 'space' && $group_has_button && !$previous_is_space) {
-                               $convertButton = $this->convertToolBarForHTMLArea($button);
+                               $convertButton = $this->convertToolbarForHTMLArea($button);
                                $convertButton = '"' . $convertButton . '"';
-                               $group .= $group ? (', ' . $convertButton) : ($group_needs_starting_bar ? ('"' . $this->convertToolBarForHTMLArea('bar') . '", ' . $convertButton) : $convertButton);
+                               $group .= $group ? (', ' . $convertButton) : ($group_needs_starting_bar ? ('"' . $this->convertToolbarForHTMLArea('bar') . '", ' . $convertButton) : $convertButton);
                                $group_needs_starting_bar = false;
                                $previous_is_space = true;
-                       } elseif (in_array($button, $this->toolBar)) {
+                       } elseif (in_array($button, $this->toolbar)) {
                                        // Add the button to the group
-                               $convertButton = $this->convertToolBarForHTMLArea($button);
+                               $convertButton = $this->convertToolbarForHTMLArea($button);
                                if ($convertButton) {
                                        $convertButton = '"' . $convertButton . '"';
-                                       $group .= $group ? (', ' . $convertButton) : ($group_needs_starting_bar ? ('"' . $this->convertToolBarForHTMLArea('bar') . '", ' . $convertButton) : $convertButton);
+                                       $group .= $group ? (', ' . $convertButton) : ($group_needs_starting_bar ? ('"' . $this->convertToolbarForHTMLArea('bar') . '", ' . $convertButton) : $convertButton);
                                        $group_has_button = true;
                                        $group_needs_starting_bar = false;
                                        $previous_is_space = false;
@@ -1864,17 +1887,20 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
        }
 
        /**
-        * Return the JS-Code to copy the HTML-Code from the editor in the hidden input field.
-        * This is for submit function from the form.
+        * Return the Javascript code for copying the HTML code from the editor into the hidden input field.
+        * This is for submit function of the form.
+        *
+        * @param       integer         $RTEcounter: The index number of the current RTE editing area within the form.
+        * @param       string          $formName: the name of the form
+        * @param       string          $textareaId: the id of the textarea
         *
-        * @return string               the JS-Code
+        * @return      string          Javascript code
         */
-
-       function setSaveRTE($number, $form, $textarea) {
+       function setSaveRTE($RTEcounter, $formName, $textareaId) {
                return '
-               editornumber = '.$number.';
+               editornumber = '.$RTEcounter.';
                if (RTEarea[editornumber]) {
-                       document.'.$form.'["'.$textarea.'"].value = RTEarea[editornumber]["editor"].getHTML();
+                       document.'.$formName.'["'.$textareaId.'"].value = RTEarea[editornumber]["editor"].getHTML();
                }
                else {
                        OK=0;
@@ -1979,7 +2005,6 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         */
 
        function RTEtsConfigParams()    {
-               global $TSFE;
                if($this->is_FE()) {
                        return '';
                } else {
@@ -2001,11 +2026,10 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                $matchParts = t3lib_div::trimExplode(',',$matchList,1);
                $styleParts = explode(';',$elValue);
                $nStyle=array();
-               while(list($k,$p)=each($styleParts))    {
+               foreach ($styleParts as $k => $p) {
                        $pp = t3lib_div::trimExplode(':',$p);
                        if ($pp[0]&&$pp[1])     {
-                               reset($matchParts);
-                               while(list(,$el)=each($matchParts))     {
+                               foreach ($matchParts as $el) {
                                        $star=substr($el,-1)=='*';
                                        if (!strcmp($pp[0],$el) || ($star && t3lib_div::isFirstPartOfStr($pp[0],substr($el,0,-1)) ))    {
                                                $nStyle[]=$pp[0].':'.$pp[1];
diff --git a/typo3/sysext/rtehtmlarea/class.tx_rtehtmlareaapi.php b/typo3/sysext/rtehtmlarea/class.tx_rtehtmlareaapi.php
new file mode 100644 (file)
index 0000000..b8cd4ca
--- /dev/null
@@ -0,0 +1,157 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2007 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
+*  All rights reserved
+*
+*  This script is part of the Typo3 project. The Typo3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+/**
+ * API for extending htmlArea RTE
+ *
+ * @author Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
+ *
+ * TYPO3 CVS ID: $Id: class.tx_rtehtmlarea_pi1.php 2449 2007-08-15 08:12:19Z ingorenner $
+ *
+ */
+
+require_once(PATH_t3lib.'class.t3lib_div.php');
+
+abstract class tx_rtehtmlareaapi {
+       
+       protected $extensionKey;                                // The key of the extension that is extending htmlArea RTE
+       protected $relativePathToLocallangFile;                 // Path to this main locallang file of the extension relative to the extension dir.
+       protected $relativePathToSkin;                          // Path to the skin (css) file relative to the extension dir.
+       protected $htmlAreaRTE;                                 // Reference to the invoking object
+       protected $thisConfig;                                  // Reference to RTE PageTSConfig
+       protected $toolBar;                                     // Refrence to RTE toolbar array
+       protected $LOCAL_LANG;                                  // Frontend language array
+       protected $pluginButtons = '';                          // The comma-seperated list of button names that the extension id adding to the htmlArea RTE tollbar
+       protected $convertToolbarForHtmlAreaArray = array();    // The name-converting array, converting the button names used in the RTE PageTSConfing to the button id's used by the JS scripts
+       
+       /**
+        * Returns true if the plugin is available and correctly initialized
+        *
+        * @param       object          Reference to parent object, which is an instance of the htmlArea RTE
+        *
+        * @return      boolean         true if this plugin object should be made available in the current environment and is correctly initialized
+        */
+       public function main($parentObject) {
+               global $TYPO3_CONF_VARS, $LANG;
+               
+               $this->htmlAreaRTE =& $parentObject;
+               $this->thisConfig =& $this->htmlAreaRTE->thisConfig;
+               $this->toolbar =& $this->htmlAreaRTE->toolbar;
+               
+                       // Check if the plugin should be disabled in frontend
+               if ($this->htmlAreaRTE->is_FE() && is_array($TYPO3_CONF_VARS['EXTCONF'][$this->extensionKey]) && $TYPO3_CONF_VARS['EXTCONF'][$this->extensionKey]['disableInFE']) {
+                       return false;
+               }
+               
+                       // Localization array must be initialized here
+               if ($this->htmlAreaRTE->is_FE()) {
+                       $this->LOCAL_LANG = t3lib_div::readLLfile('EXT:' . $this->extensionKey . '/' . $this->relativePathToLocallangFile, $this->htmlAreaRTE->language);
+               } else {
+                       $LANG->includeLLFile('EXT:' . $this->extensionKey . '/' . $this->relativePathToLocallangFile);
+               }
+               return true;
+       }
+       
+       /**
+        * Returns a modified toolbar order string
+        *
+        * @return      string          a modified tollbar order list
+        */
+       public function addButtonsToToolbar() {
+               return ('bar,'.$this->pluginButtons.',linebreak,'.$this->htmlAreaRTE->defaultToolbarOrder);
+       }
+       
+       /**
+        * Returns the path to the skin component (button icons) that should be added to linked stylesheets
+        *
+        * @return      string          path to the skin (css) file
+        */
+       public function getPathToSkin() {
+               global $TYPO3_CONF_VARS;
+               if (is_array($TYPO3_CONF_VARS['EXTCONF'][$this->extensionKey]) && $TYPO3_CONF_VARS['EXTCONF'][$this->extensionKey]['addIconsToSkin']) {
+                       return $this->relativePathToSkin;
+               } else {
+                       return '';
+               }
+       }
+       
+       /**
+        * Return JS configuration of the htmlArea plugins registered by the extension
+        *
+        * @param       integer         Relative id of the RTE editing area in the form
+        *
+        * @return      string          JS configuration for registered plugins
+        * 
+        * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
+        * Each of the instructions should be of the form:
+        *      RTEarea['.$RTEcounter.']["buttons"]["button-id"]["property"] = "value";
+        */
+       public function buildJavascriptConfiguration($RTEcounter) {
+               global $TSFE, $LANG;
+               
+               $registerRTEinJavascriptString = '';
+               foreach($this->pluginButtons as $button) {
+                       if (in_array($button, $this->toolBar)) {
+                               if (!is_array( $this->thisConfig['buttons.']) || !is_array( $this->thisConfig['buttons.'][$button.'.'])) {
+                                       $registerRTEinJavascriptString .= '
+                                       RTEarea['.$RTEcounter.']["buttons"]["'. $button .'"] = new Object();';
+                               }
+                       }
+               }
+               return $registerRTEinJavascriptString;
+       }
+       
+       /**
+        * Returns the extension key
+        *
+        * @return      string          the extension key
+        */
+       public function getExtensionKey() {
+               return $this->extensionKey;
+       }
+       
+       /**
+        * Returns the list of buttons implemented by the plugin
+        *
+        * @return      string          the list of buttons implemented by the plugin
+        */
+       public function getPluginButtons() {
+               return $this->pluginButtons;
+       }
+       
+       /**
+        * Returns the conversion array from TYPO3 button names to htmlArea button names
+        *
+        * @return      array           the conversion array from TYPO3 button names to htmlArea button names
+        */
+       public function getConvertToolbarForHtmlAreaArray() {
+               return $this->convertToolbarForHtmlAreaArray;
+       }
+
+} // end of class
+
+if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/class.tx_rtehtmlareaapi.php']) {
+       include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/class.tx_rtehtmlareaapi.php']);
+}
+
+?>
\ No newline at end of file
index 7ece3cc..446191a 100644 (file)
@@ -37,8 +37,8 @@ $EM_CONF[$_EXTKEY] = array(
        'constraints' => array(
                'depends' => array(
                        'cms' => '',
-                       'php' => '4.1.0-',
-                       'typo3' => '4.0-',
+                       'php' => '5.0-',
+                       'typo3' => '4.1-',
                ),
                'conflicts' => array(
                        'rte_conf' => '',
index d1b9266..9ce25b7 100644 (file)
@@ -43,6 +43,9 @@ $TYPO3_CONF_VARS['BE']['RTE_reg'][$_EXTKEY] = array('objRef' => 'EXT:'.$_EXTKEY.
 require_once(t3lib_extMgm::extPath($_EXTKEY) . 'ext_emconf.php');
 $TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['version'] = $EM_CONF[$_EXTKEY]['version'];
 
+// Initialize plugin registration array
+$TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['plugins'] = array();
+
 $_EXTCONF = unserialize($_EXTCONF);    // unserializing the configuration so we can use it here:
 
 if (strstr($_EXTCONF['defaultConfiguration'],'Minimal')) {
index ead0701..bc494a3 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2005-2006 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
+*  (c) 2005-2007 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -74,20 +74,18 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
         * @param       integer         PID value of record (true parent page id)
         * @return      string          HTML code for RTE!
         */
-       function drawRTE(&$pObj,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue) {
+       function drawRTE($parentObject,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue) {
                global $TSFE, $TYPO3_CONF_VARS, $TYPO3_DB;
                
-                       //call $this->transformContent
-                       //call $this->triggerField
-                $this->TCEform = $pObj;
+               $this->TCEform =& $parentObject;
                $this->client = $this->clientInfo();
                $this->typoVersion = t3lib_div::int_from_ver(TYPO3_version);
-
+               
                /* =======================================
                 * INIT THE EDITOR-SETTINGS
                 * =======================================
                 */
-
+                
                        // 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) {
@@ -101,23 +99,22 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                $this->siteURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL');
                        // Get the host URL
                $this->hostURL = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST');
-
+               
                        // Element ID + pid
                $this->elementId = $PA['itemFormElName'];
                $this->elementParts[0] = $table;
                $this->elementParts[1] = $row['uid'];
                $this->tscPID = $thePidValue;
                $this->thePid = $thePidValue;
-
+               
                        // Record "type" field value:
                $this->typeVal = $RTEtypeVal; // TCA "type" value for record
-
                unset($this->RTEsetup);
                $pageTSConfig = $TSFE->getPagesTSconfig();
                $this->RTEsetup = $pageTSConfig['RTE.'];
                $this->thisConfig = $this->RTEsetup['default.'];
                $this->thisConfig = $this->thisConfig['FE.'];
-
+               
                        // Special configuration (line) and default extras:
                $this->specConf = $specConf;
                
@@ -138,13 +135,29 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                        // Character set
                $this->charset = $TSFE->labelsCharset;
                $this->OutputCharset  = $TSFE->metaCharset ? $TSFE->metaCharset : $TSFE->renderCharset;
-
+               
                /* =======================================
                 * TOOLBAR CONFIGURATION
                 * =======================================
                 */
+                
+                       // 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 = &t3lib_div::getUserObj($pluginObjectConfiguration['objectReference']);
+                               if (is_object($plugin)) {
+                                       if ($plugin->main($this)) {
+                                               $this->registeredPlugins[$pluginId] = $plugin;
+                                               $this->pluginButton[$pluginId] = $plugin->getPluginButtons();
+                                               $this->pluginList .= ','.$pluginId;
+                                               $this->convertToolbarForHtmlAreaArray = array_unique(array_merge($this->convertToolbarForHtmlAreaArray, $plugin->getConvertToolbarForHtmlAreaArray()));
+                                       }
+                               }
+                       }
+               }
+               
                        // htmlArea plugins list
-               $this->pluginEnableArray = array_intersect(t3lib_div::trimExplode(',', $this->pluginList , 1), t3lib_div::trimExplode(',', $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['HTMLAreaPluginList'], 1));
+               $this->pluginEnabledArray = t3lib_div::trimExplode(',', $this->pluginList, 1);
                $hidePlugins = array('TYPO3Browsers', 'UserElements', 'Acronym', 'TYPO3HtmlParser');
                if ($this->client['BROWSER'] == 'opera') {
                        $hidePlugins[] = 'ContextMenu';
@@ -152,21 +165,24 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                        $this->thisConfig['disableEnterParagraphs'] = 1;
                }
                if(!t3lib_extMgm::isLoaded('static_info_tables') || in_array($this->language, t3lib_div::trimExplode(',', $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['noSpellCheckLanguages']))) $hidePlugins[] = 'SpellChecker';
-               $this->pluginEnableArray = array_diff($this->pluginEnableArray, $hidePlugins);
-               $this->pluginEnableArrayMultiple = $this->pluginEnableArray;
-
+               $this->pluginEnabledArray = array_diff($this->pluginEnabledArray, $hidePlugins);
+               
                        // Toolbar
-               $this->setToolBar();
-
+               $this->settoolbar();
+               
                        // Check if some plugins need to be disabled
                $this->setPlugins();
-
+               
+                       // Merge the list of enabled plugins with the lists from the previous RTE editing areas on the same form
+               $this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter] = $this->pluginEnabledArray;
+               if ($this->TCEform->RTEcounter > 1) $this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter] = array_unique(array_values(array_merge($this->pluginEnabledArray,$this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter-1])));
+               
                /* =======================================
                 * PLUGIN-SPECIFIC CONFIGURATION
                 * =======================================
                 */
-
-               if( $this->isPluginEnable('SpellChecker') ) {
+                
+               if( $this->isPluginEnabled('SpellChecker') ) {
                                // Set the language of the content for the SpellChecker
                        $this->spellCheckerLanguage = $TYPO3_CONF_VARS['EXTCONF']['rtehtmlarea']['defaultDictionary'];
                        if($row['sys_language_uid']) {
@@ -201,7 +217,7 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                        }
                }
 
-               if( $this->isPluginEnable('QuickTag') && trim($this->thisConfig['hideTags'])) {
+               if( $this->isPluginEnabled('QuickTag') && trim($this->thisConfig['hideTags'])) {
                        $this->quickTagHideTags = implode(',', t3lib_div::trimExplode(',', $this->thisConfig['hideTags'], 1));
                }
 
@@ -210,7 +226,7 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                 * =======================================
                 */
 
-               $RTEWidth = 460+($pObj->docLarge ? 150 : 0);
+               $RTEWidth = 460+($this->TCEform->docLarge ? 150 : 0);
                $RTEHeight = 380;
                $editorWrapWidth = $RTEWidth . 'px';
                $editorWrapHeight = $RTEHeight . 'px';
@@ -250,13 +266,26 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                $this->editedContentCSS = $skinDir . '/htmlarea-edited-content.css';
                $additionalCode_loadCSS .= '
                <link rel="alternate stylesheet" type="text/css" href="' . $this->editedContentCSS . '" />';
+               
+                       // Additional icons from registered plugins
+               foreach ($this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter] as $pluginId) {
+                       if (is_object($this->registeredPlugins[$pluginId])) {
+                               $pathToSkin = $this->registeredPlugins[$pluginId]->getPathToSkin();
+                               if ($pathToSkin) {
+                                       $additionalCode_loadCSS .= '
+               <link rel="stylesheet" type="text/css" href="' . $this->httpTypo3Path . t3lib_extMgm::siteRelPath($this->registeredPlugins[$pluginId]->getExtensionKey()) . . $pathToSkin . '" />';
+                               }
+                       }
+               }
+               
+                       // Main stylesheet
                $additionalCode_loadCSS .= '
                <link rel="stylesheet" type="text/css" href="' . $this->editorCSS . '" />';
-
+               
                        // Loading CSS, JavaScript files and code
                $TSFE->additionalHeaderData['htmlArea'] = $additionalCode_loadCSS;
-               $pObj->additionalJS_initial = $this->loadJSfiles($pObj->RTEcounter);
-               $pObj->additionalJS_pre[] = $this->loadJScode($pObj->RTEcounter);
+               $this->TCEform->additionalJS_initial = $this->loadJSfiles($this->TCEform->RTEcounter);
+               $this->TCEform->additionalJS_pre[] = $this->loadJScode($this->TCEform->RTEcounter);
 
                /* =======================================
                 * DRAW THE EDITOR
@@ -272,20 +301,20 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                }
                
                        // Register RTE windows:
-               $pObj->RTEwindows[] = $PA['itemFormElName'];
-                       
+               $this->TCEform->RTEwindows[] = $PA['itemFormElName'];
+               
                        // Register RTE in JS:
-               $pObj->additionalJS_post[] = $this->registerRTEinJS($pObj->RTEcounter);
+               $this->TCEform->additionalJS_post[] = $this->registerRTEinJS($this->TCEform->RTEcounter);
                
                        // Set the save option for the RTE:
-               $pObj->additionalJS_submit[] = $this->setSaveRTE($pObj->RTEcounter, $pObj->formName, htmlspecialchars($PA['itemFormElName']));
+               $this->TCEform->additionalJS_submit[] = $this->setSaveRTE($this->TCEform->RTEcounter, $this->TCEform->formName, htmlspecialchars($PA['itemFormElName']));
                
                        // draw the textarea
                $visibility = 'hidden';
                $item = $this->triggerField($PA['itemFormElName']).'
-                       <div id="pleasewait' . $pObj->RTEcounter . '" class="pleasewait" style="display: none;" >' . $TSFE->csConvObj->conv($TSFE->getLLL('Please wait',$this->LOCAL_LANG), $this->charset, $TSFE->renderCharset) . '</div>
-                       <div id="editorWrap' . $pObj->RTEcounter . '" class="editorWrap" style="'. htmlspecialchars($this->RTEWrapStyle). '">
-                       <textarea id="RTEarea'.$pObj->RTEcounter.'" name="'.htmlspecialchars($PA['itemFormElName']).'" style="'.htmlspecialchars($this->RTEdivStyle).'">'.t3lib_div::formatForTextarea($value).'</textarea>
+                       <div id="pleasewait' . $this->TCEform->RTEcounter . '" class="pleasewait" style="display: none;" >' . $TSFE->csConvObj->conv($TSFE->getLLL('Please wait',$this->LOCAL_LANG), $this->charset, $TSFE->renderCharset) . '</div>
+                       <div id="editorWrap' . $this->TCEform->RTEcounter . '" class="editorWrap" style="'. htmlspecialchars($this->RTEWrapStyle). '">
+                       <textarea id="RTEarea'.$this->TCEform->RTEcounter.'" name="'.htmlspecialchars($PA['itemFormElName']).'" style="'.htmlspecialchars($this->RTEdivStyle).'">'.t3lib_div::formatForTextarea($value).'</textarea>
                        </div>' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableDebugMode'] ? '<div id="HTMLAreaLog"></div>' : '') . '
                        ';
                return $item;
@@ -295,11 +324,15 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
         * Return the JS-Code for copy the HTML-Code from the editor in the hidden input field.
         * This is for submit function from the form.
         *
-        * @return string               the JS-Code
+        * @param       integer         $RTEcounter: The index number of the RTE editing area.
+        * @param       string          $form: the name of the form
+        * @param       string          $textarea: the name of the textarea
+        *
+        * @return      string          the JS-Code
         */
-       function setSaveRTE($number, $form, $textarea) {
+       function setSaveRTE($RTEcounter, $form, $textarea) {
                return '
-               editornumber = '.$number.';
+               editornumber = '.$RTEcounter.';
                if (RTEarea[editornumber]) {
                        fields = document.getElementsByName(\'' . $textarea . '\');
                        field = fields.item(0);