Added feature #13580: htmlArea RTE: Extjize the RTE
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / pi2 / class.tx_rtehtmlarea_pi2.php
index 47765da..3e324c3 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2005 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
+*  (c) 2005-2010 Stanislas Rolland <typo3(arobas)sjbr.ca>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -27,7 +27,7 @@
 /**
  * Front end RTE based on htmlArea
  *
- * @author Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
+ * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
  *
  * $Id$  *
  */
@@ -37,8 +37,10 @@ require_once(t3lib_extMgm::extPath('rtehtmlarea').'class.tx_rtehtmlarea_base.php
 class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
 
                // External:
-       var $RTEdivStyle;                               // Alternative style for RTE <div> tag.
+       var $RTEWrapStyle = '';                         // Alternative style for RTE wrapper <div> tag.
+       var $RTEdivStyle = '';                          // Alternative style for RTE <div> tag.
        var $extHttpPath;                               // full Path to this extension for http (so no Server path). It ends with "/"
+       public $httpTypo3Path;
 
                // For the editor
        var $elementId;
@@ -46,13 +48,11 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
        var $tscPID;
        var $typeVal;
        var $thePid;
-       var $RTEsetup;
-       var $thisConfig;
+       var $RTEsetup = array();
+       var $thisConfig = array();
        var $confValues;
-       var $language;
-       var $spellCheckerLanguage;
-       var $spellCheckerCharset;
-       var $spellCheckerMode;
+       public $language;
+       public $OutputCharset;
        var $specConf;
        var $LOCAL_LANG;
 
@@ -71,12 +71,12 @@ 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) {
-                       //call $this->transformContent
-                       //call $this->triggerField
-                $this->TCEform = $pObj;
+       function drawRTE($parentObject,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue) {
+               global $TSFE, $TYPO3_CONF_VARS, $TYPO3_DB;
+
+               $this->TCEform = $parentObject;
                $this->client = $this->clientInfo();
-               $this->typoVersion = t3lib_div::int_from_ver($GLOBALS['TYPO_VERSION']);
+               $this->typoVersion = t3lib_div::int_from_ver(TYPO3_version);
 
                /* =======================================
                 * INIT THE EDITOR-SETTINGS
@@ -86,9 +86,9 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                        // first get the http-path to typo3:
                $this->httpTypo3Path = substr( substr( t3lib_div::getIndpEnv('TYPO3_SITE_URL'), strlen( t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') ) ), 0, -1 );
                if (strlen($this->httpTypo3Path) == 1) {
-                       $this->httpTypo3Path = "/";
+                       $this->httpTypo3Path = '/';
                } else {
-                       $this->httpTypo3Path .= "/";
+                       $this->httpTypo3Path .= '/';
                }
                        // Get the path to this extension:
                $this->extHttpPath = $this->httpTypo3Path.t3lib_extMgm::siteRelPath($this->ID);
@@ -107,146 +107,138 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                        // Record "type" field value:
                $this->typeVal = $RTEtypeVal; // TCA "type" value for record
 
-               unset($this->RTEsetup);
-               $pageTSConfig = $GLOBALS['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;
-               
-                       // Language
-               $GLOBALS['TSFE']->initLLvars();
-               $this->LOCAL_LANG = $GLOBALS['TSFE']->readLLfile('EXT:' . $this->ID . '/locallang.php');
-               $this->language = $GLOBALS['TSFE']->lang;
-               if ($this->language=='default' || !$this->language)     {
-                       $this->language='en';
-               }
-                       // Character set
-               $this->charset = $GLOBALS['TSFE']->labelsCharset;
-               if($this->typoVersion >= 3007000 ) {
-                       $this->OutputCharset  = $GLOBALS['TSFE']->metaCharset ? $GLOBALS['TSFE']->metaCharset : $GLOBALS['TSFE']->renderCharset;
-               } else {
-                       $renderCharset = $GLOBALS['TSFE']->csConvObj->parse_charset($GLOBALS['TSFE']->config['config']['renderCharset'] ? $GLOBALS['TSFE']->config['config']['renderCharset'] : ($GLOBALS['TSFE']->TYPO3_CONF_VARS['BE']['forceCharset'] ? $GLOBALS['TSFE']->TYPO3_CONF_VARS['BE']['forceCharset'] : $GLOBALS['TSFE']->defaultCharSet));    // REndering charset of HTML page.
-                       $metaCharset = $GLOBALS['TSFE']->csConvObj->parse_charset($GLOBALS['TSFE']->config['config']['metaCharset'] ? $GLOBALS['TSFE']->config['config']['metaCharset'] : $renderCharset);
-                       $this->OutputCharset  = $metaCharset ? $metaCharset : $renderCharset;
+                       // RTE configuration
+               $pageTSConfig = $TSFE->getPagesTSconfig();
+               if (is_array($pageTSConfig) && is_array($pageTSConfig['RTE.'])) {
+                       $this->RTEsetup = $pageTSConfig['RTE.'];
                }
 
-               /* =======================================
-                * TOOLBAR CONFIGURATION
-                * =======================================
-                */
-                       // htmlArea plugins list
-               $this->pluginEnableArray = array_intersect(t3lib_div::trimExplode(',', $this->pluginList , 1), t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['HTMLAreaPluginList'], 1));
-               $hidePlugins = array('TYPO3Browsers', 'UserElements', 'Acronym');
-               if ($this->client['BROWSER'] == 'opera') {
-                       $hidePlugins[] = 'ContextMenu';
-                       $this->thisConfig['hideTableOperationsInToolbar'] = 0;
+               if (is_array($thisConfig) && !empty($thisConfig)) {
+                       $this->thisConfig = $thisConfig;
+               } else if (is_array($this->RTEsetup['default.']) && is_array($this->RTEsetup['default.']['FE.'])) {
+                       $this->thisConfig = $this->RTEsetup['default.']['FE.'];
                }
-               if(!t3lib_extMgm::isLoaded('sr_static_info') || in_array($this->language, t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['noSpellCheckLanguages']))) $hidePlugins[] = 'SpellChecker';
-               $this->pluginEnableArray = array_diff($this->pluginEnableArray, $hidePlugins);
-               $this->pluginEnableArrayMultiple = $this->pluginEnableArray;
 
-                       // Toolbar
-               $this->setToolBar();
+                       // Special configuration (line) and default extras:
+               $this->specConf = $specConf;
 
-                       // Check if some plugins need to be disabled
-               $this->setPlugins();
+               if ($this->thisConfig['forceHTTPS']) {
+                       $this->httpTypo3Path = preg_replace('/^(http|https)/', 'https', $this->httpTypo3Path);
+                       $this->extHttpPath = preg_replace('/^(http|https)/', 'https', $this->extHttpPath);
+                       $this->siteURL = preg_replace('/^(http|https)/', 'https', $this->siteURL);
+                       $this->hostURL = preg_replace('/^(http|https)/', 'https', $this->hostURL);
+               }
 
                /* =======================================
-                * PLUGIN-SPECIFIC CONFIGURATION
+                * LANGUAGES & CHARACTER SETS
                 * =======================================
                 */
-
-               if( $this->isPluginEnable('SpellChecker') ) {
-                               // Set the language of the content for the SpellChecker
-                       $this->spellCheckerLanguage = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['defaultDictionary'];
-                       if($row['sys_language_uid']) {
+                       // Language
+               $TSFE->initLLvars();
+               $this->language = $TSFE->lang;
+               $this->LOCAL_LANG = t3lib_div::readLLfile('EXT:' . $this->ID . '/locallang.xml', $this->language);
+               if ($this->language == 'default' || !$this->language)   {
+                       $this->language = 'en';
+               }
+               $this->contentLanguageUid = ($row['sys_language_uid'] > 0) ? $row['sys_language_uid'] : 0;
+               if (t3lib_extMgm::isLoaded('static_info_tables')) {
+                       if ($this->contentLanguageUid) {
                                $tableA = 'sys_language';
                                $tableB = 'static_languages';
-                               $languagesUidsList = $row['sys_language_uid'];
+                               $languagesUidsList = $this->contentLanguageUid;
                                $selectFields = $tableA . '.uid,' . $tableB . '.lg_iso_2,' . $tableB . '.lg_country_iso_2,' . $tableB . '.lg_typo3';
-                               $table = $tableA . ' LEFT JOIN ' . $tableB . ' ON ' . $tableA . '.static_lang_isocode=' . $tableB . '.uid';
+                               $tableAB = $tableA . ' LEFT JOIN ' . $tableB . ' ON ' . $tableA . '.static_lang_isocode=' . $tableB . '.uid';
                                $whereClause = $tableA . '.uid IN (' . $languagesUidsList . ') ';
-                               $whereClause .= $GLOBALS['TSFE']->cObj->enableFields($tableA);
-                               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($selectFields, $table, $whereClause);
-                               while ( $languageRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res) ) {
-                                       $this->spellCheckerLanguage = strtolower(trim($languageRow['lg_iso_2']).(trim($languageRow['lg_country_iso_2'])?'_'.trim($languageRow['lg_country_iso_2']):''));
-                                       $this->spellCheckerTypo3Language = strtolower(trim($languageRow['lg_typo3']));
+                               $whereClause .= t3lib_BEfunc::BEenableFields($tableA);
+                               $whereClause .= t3lib_BEfunc::deleteClause($tableA);
+                               $res = $TYPO3_DB->exec_SELECTquery($selectFields, $tableAB, $whereClause);
+                               while($languageRow = $TYPO3_DB->sql_fetch_assoc($res)) {
+                                       $this->contentISOLanguage = strtolower(trim($languageRow['lg_iso_2']).(trim($languageRow['lg_country_iso_2'])?'_'.trim($languageRow['lg_country_iso_2']):''));
+                                       $this->contentTypo3Language = strtolower(trim($languageRow['lg_typo3']));
+                               }
+                       } else {
+                               $this->contentISOLanguage = $GLOBALS['TSFE']->sys_language_isocode ? $GLOBALS['TSFE']->sys_language_isocode : 'en';
+                               $selectFields = 'lg_iso_2, lg_typo3';
+                               $tableAB = 'static_languages';
+                               $whereClause = 'lg_iso_2 = ' . $TYPO3_DB->fullQuoteStr(strtoupper($this->contentISOLanguage), $tableAB);
+                               $res = $TYPO3_DB->exec_SELECTquery($selectFields, $tableAB, $whereClause);
+                               while($languageRow = $TYPO3_DB->sql_fetch_assoc($res)) {
+                                       $this->contentTypo3Language = strtolower(trim($languageRow['lg_typo3']));
                                }
                        }
-                       $this->spellCheckerLanguage = $this->spellCheckerLanguage?$this->spellCheckerLanguage:$this->language;
-                       $this->spellCheckerTypo3Language = $this->spellCheckerTypo3Language?$this->spellCheckerTypo3Language:$GLOBALS['TSFE']->lang;
-                       if ($this->spellCheckerTypo3Language=='default') {
-                               $this->spellCheckerTypo3Language='en';
-                       }
+               }
+               $this->contentISOLanguage = $this->contentISOLanguage ? $this->contentISOLanguage : ($GLOBALS['TSFE']->sys_language_isocode ? $GLOBALS['TSFE']->sys_language_isocode : 'en');
+               $this->contentTypo3Language = $this->contentTypo3Language ? $this->contentTypo3Language : $GLOBALS['TSFE']->lang;
+               if ($this->contentTypo3Language == 'default') {
+                       $this->contentTypo3Language = 'en';
+               }
 
-                               // Set the charset of the content for the SpellChecker
-                       $this->spellCheckerCharset = $GLOBALS['TSFE']->csConvObj->charSetArray[$this->spellCheckerTypo3Language];
-                       $this->spellCheckerCharset = $this->spellCheckerCharset ? $this->spellCheckerCharset : 'iso-8859-1';
-                       $this->spellCheckerCharset = trim($GLOBALS['TSFE']->config['config']['metaCharset']) ? trim($GLOBALS['TSFE']->config['config']['metaCharset']) : $this->spellCheckerCharset;
+                       // Character set
+               $this->charset = $TSFE->renderCharset;
+               $this->OutputCharset  = $TSFE->metaCharset ? $TSFE->metaCharset : $TSFE->renderCharset;
 
-                               // Set the SpellChecker mode
-                       $this->spellCheckerMode = isset($this->thisConfig['HTMLAreaPspellMode']) ? trim($this->thisConfig['HTMLAreaPspellMode']) : 'normal';
-                       if( !in_array($this->spellCheckerMode, $this->spellCheckerModes)) {
-                               $this->spellCheckerMode = 'normal';
-                       }
-               }
+                       // Set the charset of the content
+               $this->contentCharset = $TSFE->csConvObj->charSetArray[$this->contentTypo3Language];
+               $this->contentCharset = $this->contentCharset ? $this->contentCharset : 'iso-8859-1';
+               $this->contentCharset = trim($TSFE->config['config']['metaCharset']) ? trim($TSFE->config['config']['metaCharset']) : $this->contentCharset;
 
-               if( $this->isPluginEnable('QuickTag') && trim($this->thisConfig['hideTags'])) {
-                       $this->quickTagHideTags = implode(',', t3lib_div::trimExplode(',', $this->thisConfig['hideTags'], 1));
-               }
+               /* =======================================
+                * TOOLBAR CONFIGURATION
+                * =======================================
+                */
+               $this->initializeToolbarConfiguration();
 
                /* =======================================
                 * SET STYLES
                 * =======================================
                 */
 
-               $RTEWidth = 460+($pObj->docLarge ? 150 : 0);
-               $RTEHeight = 380;
-               $editorWrapWidth = $RTEWidth . 'px';
-               $editorWrapHeight = $RTEHeight . 'px';
-               $this->RTEdivStyle = $this->RTEdivStyle ? $this->RTEdivStyle : 'position:relative; left:0px; top:0px; height:' . $RTEHeight . 'px; width:'.$RTEWidth.'px; border: 1px solid black;';
-               $this->toolbar_level_size = $RTEWidth;
+               $width = 460+($this->TCEform->docLarge ? 150 : 0);
+               if (isset($this->thisConfig['RTEWidthOverride'])) {
+                       if (strstr($this->thisConfig['RTEWidthOverride'], '%')) {
+                               if ($this->client['BROWSER'] != 'msie') {
+                                       $width = (intval($this->thisConfig['RTEWidthOverride']) > 0) ? $this->thisConfig['RTEWidthOverride'] : '100%';
+                               }
+                       } else {
+                               $width = (intval($this->thisConfig['RTEWidthOverride']) > 0) ? intval($this->thisConfig['RTEWidthOverride']) : $width;
+                       }
+               }
+               $RTEWidth = strstr($width, '%') ? $width : $width . 'px';
+               $editorWrapWidth = strstr($width, '%') ? $width :  ($width+2) . 'px';
+               $height = 380;
+               $RTEHeightOverride = intval($this->thisConfig['RTEHeightOverride']);
+               $height = ($RTEHeightOverride > 0) ? $RTEHeightOverride : $height;
+               $RTEHeight = $height . 'px';
+               $editorWrapHeight = ($height+2) . 'px';
+               $this->RTEWrapStyle = $this->RTEWrapStyle ? $this->RTEWrapStyle : ($this->RTEdivStyle ? $this->RTEdivStyle : ('height:' . $editorWrapHeight . '; width:'. $editorWrapWidth . ';'));
+               $this->RTEdivStyle = $this->RTEdivStyle ? $this->RTEdivStyle : 'position:relative; left:0px; top:0px; height:' . $RTEHeight . '; width:'.$RTEWidth.'; border: 1px solid black;';
 
                /* =======================================
                 * LOAD JS, CSS and more
                 * =======================================
                 */
-                       // Preloading the pageStyle
-               $filename = trim($this->thisConfig['contentCSS']) ? trim($this->thisConfig['contentCSS']) : 'EXT:' . $this->ID . '/htmlarea/plugins/DynamicCSS/dynamiccss.css';
-               $additionalCode_loadCSS = '
-               <link rel="alternate stylesheet" type="text/css" href="' . $this->getFullFileName($filename) . '" />';
-
-                       // Loading the editor skin
-               $skinFilename = trim($this->thisConfig['skin']) ? trim($this->thisConfig['skin']) : 'EXT:' . $this->ID . '/htmlarea/skins/default/htmlarea.css';
-               if($this->client['BROWSER'] == 'gecko' && $this->client['VERSION'] == '1.3' && substr($skinFilename,0,4) == 'EXT:')  {
-                       $skinFilename = 'EXT:' . $this->ID . '/htmlarea/skins/default/htmlarea.css';
+               $pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
+               $pageRenderer->setBackPath(TYPO3_mainDir);
+                       // Preloading the pageStyle and including RTE skin stylesheets
+               $this->addPageStyle();
+               $this->addSkin();
+               $pageRenderer->addCssFile($this->hostURL . '/t3lib/js/extjs/ux/resize.css');
+                       // Loading JavaScript files and code
+               $pageRenderer->loadExtJs();
+               $pageRenderer->enableExtJSQuickTips();
+               if (!$GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableCompressedScripts']) {
+                       $pageRenderer->enableExtJsDebug();
                }
-               if (substr($skinFilename,0,4) == 'EXT:')      {       // extension
-                       list($extKey,$local) = explode('/',substr($skinFilename,4),2);
-                       $skinFilename='';
-                       if (strcmp($extKey,'') &&  t3lib_extMgm::isLoaded($extKey) && strcmp($local,'')) {
-                               $skinFilename = $this->httpTypo3Path . t3lib_extMgm::siteRelPath($extKey).$local;
-                               $skinDir = $this->siteURL . t3lib_extMgm::siteRelPath($extKey) . dirname($local);
-                       }
-               } elseif (substr($skinFilename,0,1) != '/') {
-                       $skinDir = $this->siteURL.dirname($skinFilename);
-                       $skinFilename = $this->siteURL.$skinFilename;
-               } else {
-                       $skinDir = substr($this->siteURL,0,-1) . dirname($skinFilename);
+               $pageRenderer->addJsFile($this->hostURL . '/t3lib/js/extjs/ux/ext.resizable.js');
+               if ($this->TCEform->RTEcounter == 1) {
+                       $this->TCEform->additionalJS_pre['rtehtmlarea-loadJScode'] = $this->loadJScode($this->TCEform->RTEcounter);
                }
-
-               $this->editorCSS = $skinFilename;
-               $this->editedContentCSS = $skinDir . '/htmlarea-edited-content.css';
-               $additionalCode_loadCSS .= '
-               <link rel="alternate stylesheet" type="text/css" href="' . $this->editedContentCSS . '" />';
-               $additionalCode_loadCSS .= '
-               <link rel="stylesheet" type="text/css" href="' . $this->editorCSS . '" />';
-
-                       // Loading CSS, JavaScript files and code
-               $GLOBALS['TSFE']->additionalHeaderData['htmlArea'] = $additionalCode_loadCSS . $this->loadJSfiles($pObj->RTEcounter) . '<script type="text/javascript">' . $this->loadJScode($pObj->RTEcounter) . '</script>'; 
+               $this->TCEform->additionalJS_initial = $this->loadJSfiles($this->TCEform->RTEcounter);
+               $resizableSettings = array(
+                       'textareaResize' => true,
+                       'textareaMaxHeight' => '600'
+               );
+               $pageRenderer->addInlineSettingArray('', $resizableSettings);
 
                /* =======================================
                 * DRAW THE EDITOR
@@ -254,51 +246,70 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                 */
                        // Transform value:
                $value = $this->transformContent('rte',$PA['itemFormElValue'],$table,$field,$row,$specConf,$thisConfig,$RTErelPath,$thePidValue);
-               if ($this->client['BROWSER'] == 'gecko') {
-                               // change <strong> to <b>
-                       $value = preg_replace("/<(\/?)strong>/i", "<$1b>", $value);
-                               // change <em> to <i>
-                       $value = preg_replace("/<(\/?)em>/i", "<$1i>", $value);
+
+                       // Further content transformation by registered plugins
+               foreach ($this->registeredPlugins as $pluginId => $plugin) {
+                       if ($this->isPluginEnabled($pluginId) && method_exists($plugin, "transformContent")) {
+                               $value = $plugin->transformContent($value);
+                       }
                }
 
                        // Register RTE windows:
-               $pObj->RTEwindows[] = $PA['itemFormElName'];
-                       
+               $this->TCEform->RTEwindows[] = $PA['itemFormElName'];
+               $textAreaId = htmlspecialchars($PA['itemFormElName']);
+
                        // Register RTE in JS:
-               $pObj->additionalJS_post[] = $this->registerRTEinJS($pObj->RTEcounter);
+               $this->TCEform->additionalJS_post[] = $this->registerRTEinJS($this->TCEform->RTEcounter, '', '', '',$textAreaId);
 
                        // 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, $textAreaId);
 
                        // draw the textarea
-               $visibility = 'hidden';
                $item = $this->triggerField($PA['itemFormElName']).'
-                       <div id="pleasewait' . $pObj->RTEcounter . '" class="pleasewait">' . $GLOBALS['TSFE']->csConvObj->conv($GLOBALS['TSFE']->getLLL('Please wait',$this->LOCAL_LANG), $this->charset, $GLOBALS['TSFE']->renderCharset) . '</div>
-                       <div id="editorWrap' . $pObj->RTEcounter . '" class="editorWrap" style="visibility:' . $visibility . '; width:' . $editorWrapWidth . '; height:' . $editorWrapHeight . ';">
-                       <textarea id="RTEarea'.$pObj->RTEcounter.'" name="'.htmlspecialchars($PA['itemFormElName']).'" style="'.htmlspecialchars($this->RTEdivStyle).'">'.t3lib_div::formatForTextarea($value).'</textarea>
-                       </div>' . ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableDebugMode'] ? '<div id="HTMLAreaLog"></div>' : '') . '
+                       <div id="pleasewait' . $textAreaId . '" class="pleasewait" style="display: block;" >' . $TSFE->csConvObj->conv($TSFE->getLLL('Please wait',$this->LOCAL_LANG), $this->charset, $TSFE->renderCharset) . '</div>
+                       <div id="editorWrap' . $textAreaId . '" class="editorWrap" style="visibility: hidden; '. htmlspecialchars($this->RTEWrapStyle). '">
+                       <textarea id="RTEarea' . $textAreaId . '" 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;
        }
-       
+
+       /**
+        * Add style sheet file to document header
+        *
+        * @param       string          $key: some key identifying the style sheet
+        * @param       string          $href: uri to the style sheet file
+        * @param       string          $title: value for the title attribute of the link element
+        * @return      string          $relation: value for the rel attribute of the link element
+        * @return      void
+        */
+       protected function addStyleSheet($key, $href, $title='', $relation='stylesheet') {
+               if (!isset($GLOBALS['TSFE']->additionalHeaderData[$key])) {
+                       $GLOBALS['TSFE']->additionalHeaderData[$key] = '<link rel="' . $relation . '" type="text/css" href="' . $href . '"' . ($title ? (' title="' . $title . '"') : '') . ' />';
+               }
+       }
+
        /**
         * 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          $textareaId: the id of the textarea
+        *
+        * @return      string          the JS-Code
         */
-       function setSaveRTE($number, $form, $textarea) {
+       function setSaveRTE($RTEcounter, $form, $textareaId) {
                return '
-               editornumber = '.$number.';
-               if (RTEarea[editornumber]) {
-                       fields = document.getElementsByName(\'' . $textarea . '\');
+               if (RTEarea[\'' . $textareaId . '\'] && !RTEarea[\'' . $textareaId . '\'].deleted) {
+                       fields = document.getElementsByName(\'' . $textareaId . '\');
                        field = fields.item(0);
-                       if(field && field.tagName.toLowerCase() == \'textarea\') field.value = RTEarea[editornumber][\'editor\'].getHTML();
-               }
-               else {
-                       OK=0;
-               }
-               ';
+                       if (field && field.nodeName.toLowerCase() == \'textarea\') {
+                               field.value = RTEarea[\'' . $textareaId . '\'][\'editor\'].getHTML();
+                       }
+               } else {
+                       OK = 0;
+               }';
        }
 }