/**
     * Draws the RTE as an iframe
     *
     * @param FormEngine $parentObject Reference to parent object, which is an instance of the TCEforms.
     * @param string $table The table name
     * @param string $field The field name
     * @param array $row The current row from which field is being rendered
     * @param array $PA Array of standard content for rendering form fields from TCEforms. See TCEforms for details on this. Includes for instance the value and the form field name, java script actions and more.
     * @param array $specConf "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array.
     * @param array $thisConfig Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc.
     * @param string $RTEtypeVal Record "type" field value.
     * @param string $RTErelPath Relative path for images/links in RTE; this is used when the RTE edits content from static files where the path of such media has to be transformed forth and back!
     * @param integer $thePidValue PID value of record (true parent page id)
     * @return string HTML code for RTE!
     * @todo Define visibility
     */
    public function drawRTE($parentObject, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue)
    {
        global $LANG, $TYPO3_DB;
        $this->TCEform = $parentObject;
        $inline = $this->TCEform->inline;
        $LANG->includeLLFile('EXT:' . $this->ID . '/locallang.xml');
        $this->client = $this->clientInfo();
        $this->typoVersion = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version);
        $this->userUid = 'BE_' . $GLOBALS['BE_USER']->user['uid'];
        // Draw form element:
        if ($this->debugMode) {
            // Draws regular text area (debug mode)
            $item = parent::drawRTE($this->TCEform, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue);
        } else {
            // Draw real RTE
            /* =======================================
             * INIT THE EDITOR-SETTINGS
             * =======================================
             */
            // Set backPath
            $this->backPath = $this->TCEform->backPath;
            // Get the path to this extension:
            $this->extHttpPath = $this->backPath . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($this->ID);
            // Get the site URL
            $this->siteURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
            // Get the host URL
            $this->hostURL = $this->siteURL . TYPO3_mainDir;
            // Element ID + pid
            $this->elementId = $PA['itemFormElName'];
            // Form element name
            $this->elementParts = explode('][', preg_replace('/\\]$/', '', preg_replace('/^(TSFE_EDIT\\[data\\]\\[|data\\[)/', '', $this->elementId)));
            // Find the page PIDs:
            list($this->tscPID, $this->thePid) = BackendUtility::getTSCpid(trim($this->elementParts[0]), trim($this->elementParts[1]), $thePidValue);
            // Record "types" field value:
            $this->typeVal = $RTEtypeVal;
            // TCA "types" value for record
            // Find "thisConfig" for record/editor:
            unset($this->RTEsetup);
            $this->RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', BackendUtility::getPagesTSconfig($this->tscPID));
            $this->thisConfig = $thisConfig;
            // Special configuration and default extras:
            $this->specConf = $specConf;
            if ($this->thisConfig['forceHTTPS']) {
                $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);
            }
            // Register RTE windows
            $this->TCEform->RTEwindows[] = $PA['itemFormElName'];
            $textAreaId = preg_replace('/[^a-zA-Z0-9_:.-]/', '_', $PA['itemFormElName']);
            $textAreaId = htmlspecialchars(preg_replace('/^[^a-zA-Z]/', 'x', $textAreaId));
            /* =======================================
             * LANGUAGES & CHARACTER SETS
             * =======================================
             */
            // Languages: interface and content
            $this->language = $LANG->lang;
            if ($this->language == 'default' || !$this->language) {
                $this->language = 'en';
            }
            $this->contentTypo3Language = $this->language == 'en' ? 'default' : $this->language;
            $this->contentISOLanguage = 'en';
            $this->contentLanguageUid = max($row['sys_language_uid'], 0);
            if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('static_info_tables')) {
                if ($this->contentLanguageUid) {
                    $tableA = 'sys_language';
                    $tableB = 'static_languages';
                    $languagesUidsList = $this->contentLanguageUid;
                    $selectFields = $tableA . '.uid,' . $tableB . '.lg_iso_2,' . $tableB . '.lg_country_iso_2,' . $tableB . '.lg_typo3';
                    $tableAB = $tableA . ' LEFT JOIN ' . $tableB . ' ON ' . $tableA . '.static_lang_isocode=' . $tableB . '.uid';
                    $whereClause = $tableA . '.uid IN (' . $languagesUidsList . ') ';
                    $whereClause .= BackendUtility::BEenableFields($tableA);
                    $whereClause .= BackendUtility::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 = trim($languageRow['lg_typo3']) ? strtolower(trim($languageRow['lg_typo3'])) : 'default';
                    }
                } else {
                    $this->contentISOLanguage = trim($this->thisConfig['defaultContentLanguage']) ?: '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 = trim($languageRow['lg_typo3']) ? strtolower(trim($languageRow['lg_typo3'])) : 'default';
                    }
                }
            }
            // Create content laguage service
            $this->contentLanguageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Lang\\LanguageService');
            $this->contentLanguageService->init($this->contentTypo3Language);
            /* =======================================
             * TOOLBAR CONFIGURATION
             * =======================================
             */
            $this->initializeToolbarConfiguration();
            /* =======================================
             * SET STYLES
             * =======================================
             */
            // Check if wizard_rte called this for fullscreen edtition
            if (GeneralUtility::_GP('M') === 'wizard_rte') {
                $this->fullScreen = TRUE;
                $RTEWidth = '100%';
                $RTEHeight = '100%';
                $RTEPaddingRight = '0';
                $editorWrapWidth = '100%';
            } else {
                $options = $GLOBALS['BE_USER']->userTS['options.'];
                $RTEWidth = 530 + (isset($options['RTELargeWidthIncrement']) ? (int) $options['RTELargeWidthIncrement'] : 150);
                $RTEWidth -= $inline->getStructureDepth() > 0 ? ($inline->getStructureDepth() + 1) * $inline->getLevelMargin() : 0;
                $RTEWidthOverride = is_object($GLOBALS['BE_USER']) && isset($GLOBALS['BE_USER']->uc['rteWidth']) && trim($GLOBALS['BE_USER']->uc['rteWidth']) ? trim($GLOBALS['BE_USER']->uc['rteWidth']) : trim($this->thisConfig['RTEWidthOverride']);
                if ($RTEWidthOverride) {
                    if (strstr($RTEWidthOverride, '%')) {
                        if ($this->client['browser'] != 'msie') {
                            $RTEWidth = (int) $RTEWidthOverride > 0 ? $RTEWidthOverride : '100%';
                        }
                    } else {
                        $RTEWidth = (int) $RTEWidthOverride > 0 ? (int) $RTEWidthOverride : $RTEWidth;
                    }
                }
                $RTEWidth = strstr($RTEWidth, '%') ? $RTEWidth : $RTEWidth . 'px';
                $RTEHeight = 380 + (isset($options['RTELargeHeightIncrement']) ? (int) $options['RTELargeHeightIncrement'] : 0);
                $RTEHeightOverride = is_object($GLOBALS['BE_USER']) && isset($GLOBALS['BE_USER']->uc['rteHeight']) && (int) $GLOBALS['BE_USER']->uc['rteHeight'] ? (int) $GLOBALS['BE_USER']->uc['rteHeight'] : (int) $this->thisConfig['RTEHeightOverride'];
                $RTEHeight = $RTEHeightOverride > 0 ? $RTEHeightOverride : $RTEHeight;
                $RTEPaddingRight = '2px';
                $editorWrapWidth = '99%';
            }
            $editorWrapHeight = '100%';
            $this->RTEdivStyle = 'position:relative; left:0px; top:0px; height:' . $RTEHeight . 'px; width:' . $RTEWidth . '; border: 1px solid black; padding: 2px ' . $RTEPaddingRight . ' 2px 2px;';
            /* =======================================
             * LOAD CSS AND JAVASCRIPT
             * =======================================
             */
            $this->pageRenderer = $GLOBALS['SOBE']->doc->getPageRenderer();
            // Preloading the pageStyle and including RTE skin stylesheets
            $this->addPageStyle();
            $this->addSkin();
            // Register RTE in JS
            $this->TCEform->additionalJS_post[] = $this->registerRTEinJS($this->TCEform->RTEcounter, $table, $row['uid'], $field, $textAreaId);
            // Set the save option for the RTE
            $this->TCEform->additionalJS_submit[] = $this->setSaveRTE($this->TCEform->RTEcounter, $this->TCEform->formName, $textAreaId, $PA['itemFormElName']);
            $this->TCEform->additionalJS_delete[] = $this->setDeleteRTE($this->TCEform->RTEcounter, $this->TCEform->formName, $textAreaId);
            // Loading ExtJs inline code
            $this->pageRenderer->enableExtJSQuickTips();
            // Add TYPO3 notifications JavaScript
            $this->pageRenderer->addJsFile('sysext/backend/Resources/Public/JavaScript/notifications.js');
            // Add RTE JavaScript
            $this->addRteJsFiles($this->TCEform->RTEcounter);
            $this->pageRenderer->addJsFile($this->buildJSMainLangFile($this->TCEform->RTEcounter));
            $this->pageRenderer->addJsInlineCode('HTMLArea-init', $this->getRteInitJsCode(), TRUE);
            /* =======================================
             * DRAW THE EDITOR
             * =======================================
             */
            // Transform value:
            $value = $this->transformContent('rte', $PA['itemFormElValue'], $table, $field, $row, $specConf, $thisConfig, $RTErelPath, $thePidValue);
            // Further content transformation by registered plugins
            foreach ($this->registeredPlugins as $pluginId => $plugin) {
                if ($this->isPluginEnabled($pluginId) && method_exists($plugin, 'transformContent')) {
                    $value = $plugin->transformContent($value);
                }
            }
            // Draw the textarea
            $visibility = 'hidden';
            $item = $this->triggerField($PA['itemFormElName']) . '
				<div id="pleasewait' . $textAreaId . '" class="pleasewait" style="display: block;" >' . $LANG->getLL('Please wait') . '</div>
				<div id="editorWrap' . $textAreaId . '" class="editorWrap" style="visibility: hidden; width:' . $editorWrapWidth . '; height:' . $editorWrapHeight . ';">
				<textarea id="RTEarea' . $textAreaId . '" name="' . htmlspecialchars($PA['itemFormElName']) . '" rows="0" cols="0" style="' . htmlspecialchars($this->RTEdivStyle, ENT_COMPAT, 'UTF-8', FALSE) . '">' . GeneralUtility::formatForTextarea($value) . '</textarea>
				</div>' . LF;
        }
        // Return form item:
        return $item;
    }
 function div_rteToHtml($sRteHtml, $sTable = "", $sColumn = "")
 {
     $pageTSConfig = $GLOBALS['TSFE']->getPagesTSconfig();
     $aConfig = $pageTSConfig['RTE.']['default.']['FE.'];
     $aSpecConf['rte_transform']['parameters'] = array("flag" => "rte_enabled", "mode" => "ts");
     $aDataArray = array($sColumn => $sRteHtml);
     return \TYPO3\CMS\Backend\Rte\AbstractRte::transformContent('rte', $sRteHtml, $sTable, $sColumn, $aDataArray, $aSpecConf, $aConfig, '', 0);
 }