[BUGFIX] Adjustments to FAL-enabled RTE image and link dialogues
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / class.tx_rtehtmlarea_base.php
index eb5377c..f45ece2 100644 (file)
@@ -130,8 +130,9 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
        public $language;
        public $contentTypo3Language;
        public $contentISOLanguage;
-       public $contentCharset;
-       public $OutputCharset;
+       public $charset = 'utf-8';
+       public $contentCharset = 'utf-8';
+       public $OutputCharset = 'utf-8';
        var $editorCSS;
        var $specConf;
        var $toolbar = array();                                 // Save the buttons for the toolbar
@@ -323,15 +324,6 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                                }
                        }
 
-                               // Character sets: interface and content
-                       $this->charset = $LANG->charSet;
-                       $this->OutputCharset = $this->charset;
-
-                       $this->contentCharset = $LANG->csConvObj->charSetArray[$this->contentTypo3Language];
-                       $this->contentCharset = $this->contentCharset ? $this->contentCharset : 'iso-8859-1';
-                       $this->origContentCharSet = $this->contentCharset;
-                       $this->contentCharset = (trim($TYPO3_CONF_VARS['BE']['forceCharset']) ? trim($TYPO3_CONF_VARS['BE']['forceCharset']) : $this->contentCharset);
-
                        /* =======================================
                         * TOOLBAR CONFIGURATION
                         * =======================================
@@ -388,9 +380,6 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        $this->TCEform->additionalJS_delete[] = $this->setDeleteRTE($this->TCEform->RTEcounter, $this->TCEform->formName, $textAreaId);
                                // Loading ExtJs inline code
                        $this->pageRenderer->enableExtJSQuickTips();
-                       if (!$GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableCompressedScripts']) {
-                               $this->pageRenderer->enableExtJsDebug();
-                       }
                                // Add TYPO3 notifications JavaScript
                        $this->pageRenderer->addJsFile('../t3lib/js/extjs/notifications.js');
                                // Add RTE JavaScript
@@ -595,7 +584,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                        bar, left, center, right, justifyfull,
                        bar, orderedlist, unorderedlist, definitionlist, definitionitem, outdent, indent,  bar, lefttoright, righttoleft, language, showlanguagemarks,
                        bar, textcolor, bgcolor, textindicator,
-                       bar, editelement, emoticon, insertcharacter, insertsofthyphen, link, unlink, image, table,' . (($this->thisConfig['hideTableOperationsInToolbar'] && is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['toggleborders.']) && $this->thisConfig['buttons.']['toggleborders.']['keepInToolbar']) ? ' toggleborders,': '') . ' user, acronym, bar, findreplace, spellcheck,
+                       bar, editelement, showmicrodata, emoticon, insertcharacter, insertsofthyphen, link, unlink, image, table,' . (($this->thisConfig['hideTableOperationsInToolbar'] && is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['toggleborders.']) && $this->thisConfig['buttons.']['toggleborders.']['keepInToolbar']) ? ' toggleborders,': '') . ' user, acronym, bar, findreplace, spellcheck,
                        bar, chMode, inserttag, removeformat, bar, copy, cut, paste, pastetoggle, pastebehaviour, bar, undo, redo, bar, showhelp, about, linebreak,
                        ' . ($this->thisConfig['hideTableOperationsInToolbar'] ? '': 'bar, toggleborders,') . ' bar, tableproperties, tablerestyle, bar, rowproperties, rowinsertabove, rowinsertunder, rowdelete, rowsplit, bar,
                        columnproperties, columninsertbefore, columninsertafter, columndelete, columnsplit, bar,
@@ -748,11 +737,6 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         */
        protected function addRteJsFiles($RTEcounter) {
                $this->pageRenderer->addJsFile($this->getFullFileName('EXT:' . $this->ID . '/htmlarea/htmlarea.js'));
-               if ($this->client['browser'] == 'msie') {
-                       $this->pageRenderer->addJsFile($this->getFullFileName('EXT:' . $this->ID . '/htmlarea/htmlarea-ie.js'));
-               } else {
-                       $this->pageRenderer->addJsFile($this->getFullFileName('EXT:' . $this->ID . '/htmlarea/htmlarea-gecko.js'));
-               }
                foreach ($this->pluginEnabledCumulativeArray[$RTEcounter] as $pluginId) {
                        $extensionKey = is_object($this->registeredPlugins[$pluginId]) ? $this->registeredPlugins[$pluginId]->getExtensionKey() : $this->ID;
                        $this->pageRenderer->addJsFile($this->getFullFileName('EXT:' . $extensionKey . '/htmlarea/plugins/' . $pluginId . '/' . strtolower(preg_replace('/([a-z])([A-Z])([a-z])/', "$1".'-'."$2"."$3", $pluginId)) . '.js'));
@@ -899,10 +883,18 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                }
 
                        // Setting the list of tags to be removed with their contents if specified in the RTE config
-               if (trim($this->thisConfig['removeTagsAndContents']))  {
+               if (trim($this->thisConfig['removeTagsAndContents'])) {
                        $configureRTEInJavascriptString .= '
                        RTEarea[editornumber].htmlRemoveTagsAndContents = /^(' . implode('|', t3lib_div::trimExplode(',', $this->thisConfig['removeTagsAndContents'], 1)) . ')$/i;';
                }
+                       // Setting array of custom tags if specified in the RTE config
+               if (!empty($this->thisConfig['customTags'])) {
+                       $customTags = t3lib_div::trimExplode(',', $this->thisConfig['customTags'], 1);
+                       if (!empty($customTags)) {
+                               $configureRTEInJavascriptString .= '
+                               RTEarea[editornumber].customTags= ' . json_encode($customTags) . ';';
+                       }
+               }
                        // Process default style configuration
                        // This default configuration is deprecated as of TYPO3 4.6 and will be removed in TYPO3 4.8.
                        // Use contentCSS instead.
@@ -1037,7 +1029,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                }
                        // Include JS arrays of configured classes
                $configureRTEInJavascriptString .= '
-                       RTEarea[editornumber].classesUrl = "' . $this->writeTemporaryFile('', 'classes_' . $this->language, 'js', $this->buildJSClassesArray(), TRUE) . '";';
+                       RTEarea[editornumber].classesUrl = "' . (($this->is_FE() && $GLOBALS['TSFE']->absRefPrefix) ? $GLOBALS['TSFE']->absRefPrefix : '') . $this->writeTemporaryFile('', 'classes_' . $this->language, 'js', $this->buildJSClassesArray(), TRUE) . '";';
                return $configureRTEInJavascriptString;
        }
 
@@ -1099,11 +1091,6 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         */
        function buildNestedJSArray($conf) {
                $convertedConf = t3lib_div::removeDotsFromTS($conf);
-               if ($this->is_FE()) {
-                       $GLOBALS['TSFE']->csConvObj->convArray($convertedConf, ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] ? $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] : 'iso-8859-1'), 'utf-8');
-               } else {
-                       $GLOBALS['LANG']->csConvObj->convArray($convertedConf, $GLOBALS['LANG']->charSet, 'utf-8');
-               }
                return str_replace(array(':"0"', ':"\/^(', ')$\/i"', ':"\/^(', ')$\/"', '[]'), array(':false', ':/^(', ')$/i', ':/^(', ')$/', '{}'), json_encode($convertedConf));
        }
 
@@ -1118,7 +1105,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                foreach ($labelsArray as $labels => $subArray) {
                        $LOCAL_LANG = t3lib_div::readLLfile('EXT:' . $this->ID . '/htmlarea/locallang_' . $labels . '.xml', $this->language, 'utf-8');
                        if (!empty($LOCAL_LANG[$this->language])) {
-                               $LOCAL_LANG[$this->language] = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG['default'], $LOCAL_LANG[$this->language]);
+                               $LOCAL_LANG[$this->language] = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG['default'], $LOCAL_LANG[$this->language], FALSE, FALSE);
                        } else {
                                $LOCAL_LANG[$this->language] = $LOCAL_LANG['default'];
                        }
@@ -1139,8 +1126,6 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         * @return      string          The name of the file writtten to typo3temp/rtehtmlarea
         */
        public function writeTemporaryFile($sourceFileName='', $label, $fileExtension='js', $contents='', $concatenate = FALSE) {
-               global $TYPO3_CONF_VARS;
-
                if ($sourceFileName) {
                        $output = '';
                        $source = t3lib_div::getFileAbsFileName($sourceFileName);
@@ -1148,72 +1133,26 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                } else {
                        $output = $contents;
                }
-               $compress = $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'] && ($fileExtension == 'js') && ($output != '');
-               $relativeFilename = 'typo3temp/' . $this->ID . '/' . str_replace('-','_',$label) . '_' . t3lib_div::shortMD5((TYPO3_version . $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['version'] . ($sourceFileName ? $sourceFileName : $output)), 20) . ($compress ? '_compressed' : '') . '.' . $fileExtension;
+               $relativeFilename = 'typo3temp/' . $this->ID . '_' . str_replace('-','_',$label) . '_' . t3lib_div::shortMD5((TYPO3_version . $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['version'] . ($sourceFileName ? $sourceFileName : $output)), 20) . '.' . $fileExtension;
                $destination = PATH_site . $relativeFilename;
-               if(!file_exists($destination)) {
-                       $compressedJavaScript = '';
-                       if ($compress && $fileExtension == 'js') {
-                               $compressedJavaScript = t3lib_div::minifyJavaScript($output);
+               if (!file_exists($destination)) {
+                       $minifiedJavaScript = '';
+                       if ($fileExtension == 'js' && $output != '') {
+                               $minifiedJavaScript = t3lib_div::minifyJavaScript($output);
                        }
-                       $failure = t3lib_div::writeFileToTypo3tempDir($destination, $compressedJavaScript ? $compressedJavaScript : $output);
+                       $failure = t3lib_div::writeFileToTypo3tempDir($destination, $minifiedJavaScript ? $minifiedJavaScript : $output);
                        if ($failure)  {
                                throw new RuntimeException($failure, 1294585668);
                        }
                }
                if ($this->is_FE()) {
-                       $filename =  ($GLOBALS['TSFE']->absRefPrefix ? $GLOBALS['TSFE']->absRefPrefix : '') . $relativeFilename;
+                       $filename = $relativeFilename;
                } else {
                        $filename = ($this->isFrontendEditActive() ? '' : ($this->backPath . '../')) . $relativeFilename;
                }
                return t3lib_div::resolveBackPath($filename);
        }
        /**
-        * Concatenates all accumulated scripts in a file in typo3temp/rtehtmlarea directory and returns the file name
-        *
-        * @param       integer         $RTEcounter: The index number of the current RTE editing area within the form.
-        *
-        * @return      string          The name of the file writtten to typo3temp/rtehtmlarea
-        */
-       protected function doConcatenate($RTEcounter) {
-               $fileExtension = 'js';
-               $compress = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableCompressedScripts'];
-               $token = implode('|', $this->cumulativeScripts[$RTEcounter]);
-               $relativeFilename = 'typo3temp/' . $this->ID . '/' . 'htmlarea_cumulative' . '_' . t3lib_div::shortMD5((TYPO3_version . $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['version'] . $token ), 20) . ($compress ? '_compressed' : '') . '.' . $fileExtension;
-               $destination = PATH_site . $relativeFilename;
-               if (!file_exists($destination)) {
-                       foreach ($this->cumulativeScripts[$RTEcounter] as $fileName) {
-                               $contents = file_get_contents($fileName);
-                               if (!file_exists($destination)) {
-                                       $failure = t3lib_div::writeFileToTypo3tempDir($destination, $contents);
-                                       if ($failure)  {
-                                               throw new RuntimeException($failure, 1294585669);
-                                       }
-                               } else {
-                                       $success = file_put_contents($destination, $contents, FILE_APPEND);
-                                       if (!$success)  {
-                                               throw new RuntimeException('Could not append script: ' . $fileName, 1294585670);
-                                       }
-                               }
-                       }
-               }
-               if ($this->is_FE()) {
-                       $filename = ($GLOBALS['TSFE']->absRefPrefix ? $GLOBALS['TSFE']->absRefPrefix : '') . t3lib_div::createVersionNumberedFilename($relativeFilename);
-               } else {
-                       if ($compress) {
-                               $compressor = t3lib_div::makeInstance('t3lib_Compressor');
-                               $filename = $compressor->compressJsFile(($this->isFrontendEditActive() ? '' : $this->backPath) . '../' . $relativeFilename);
-                               if ($this->isFrontendEditActive()) {
-                                       $filename = preg_replace('/^..\//', '', $filename);
-                               }
-                       } else {
-                               $filename = t3lib_div::createVersionNumberedFilename(($this->isFrontendEditActive() ? '' : ($this->backPath . '../')) . $relativeFilename);
-                       }
-               }
-               return t3lib_div::resolveBackPath($filename);
-       }
-
-       /**
         * Return a file name containing the main JS language array for HTMLArea
         *
         * @param       integer         $RTEcounter: The index number of the current RTE editing area within the form.
@@ -1235,16 +1174,14 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
         *
         * @return      string          Javascript localization array
         */
-
        function buildJSLangArray($plugin) {
                $LOCAL_LANG = FALSE;
                $extensionKey = is_object($this->registeredPlugins[$plugin]) ? $this->registeredPlugins[$plugin]->getExtensionKey() : $this->ID;
                $LOCAL_LANG = t3lib_div::readLLfile('EXT:' . $extensionKey . '/htmlarea/plugins/' . $plugin . '/locallang.xml', $this->language, 'utf-8', 1);
-               $linebreak = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableCompressedScripts'] ? '' : LF;
-               $JSLanguageArray = 'HTMLArea.I18N["' . $plugin . '"] = new Object();' . $linebreak;
+               $JSLanguageArray = 'HTMLArea.I18N["' . $plugin . '"] = new Object();' . LF;
                if (is_array($LOCAL_LANG)) {
                        if (!empty($LOCAL_LANG[$this->language])) {
-                               $LOCAL_LANG[$this->language] = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG['default'],$LOCAL_LANG[$this->language]);
+                               $LOCAL_LANG[$this->language] = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG['default'], $LOCAL_LANG[$this->language], FALSE, FALSE);
                        } else {
                                $LOCAL_LANG[$this->language] = $LOCAL_LANG['default'];
                        }
@@ -1312,16 +1249,19 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                return json_encode($toolbar);
        }
 
+       /**
+        * Localize a string using the language of the content element rather than the language of the BE interface
+        *
+        * @param       string          string: the label to be localized
+        * @return      string          Localized string.
+        */
        public function getLLContent($string) {
-               global $LANG;
-
-               $BE_lang = $LANG->lang;
-               $BE_charSet = $LANG->charSet;
-               $LANG->lang = $this->contentTypo3Language;
-               $LANG->charSet = $this->contentCharset;
-               $LLString = $LANG->JScharCode($LANG->sL($string));
-               $LANG->lang = $BE_lang;
-               $LANG->charSet = $BE_charSet;
+               $BE_lang = $GLOBALS['LANG']->lang;
+
+               $GLOBALS['LANG']->lang = $this->contentTypo3Language;
+               $LLString = $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->sL($string));
+
+               $GLOBALS['LANG']->lang = $BE_lang;
                return $LLString;
        }
 
@@ -1329,9 +1269,9 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
                global $LANG, $TSFE, $TYPO3_CONF_VARS;
 
                if ($this->is_FE()) {
-                       if (strcmp(substr($string,0,4),'LLL:') && $TYPO3_CONF_VARS['BE']['forceCharset'])       {
-                                       // A pure string coming from Page TSConfig must be in forceCharset, otherwise we just don't know..
-                               $label = $TSFE->csConvObj->conv($TSFE->sL(trim($string)), $TYPO3_CONF_VARS['BE']['forceCharset'], $this->OutputCharset);
+                       if (strcmp(substr($string,0,4),'LLL:')) {
+                                       // A pure string coming from Page TSConfig must be in utf-8
+                               $label = $TSFE->csConvObj->conv($TSFE->sL(trim($string)), 'utf-8', $this->OutputCharset);
                        } else {
                                $label = $TSFE->csConvObj->conv($TSFE->sL(trim($string)), $this->charset, $this->OutputCharset);
                        }
@@ -1350,12 +1290,13 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
        }
 
        function feJScharCode($str) {
-               global $TSFE;
                        // Convert string to UTF-8:
-               if ($this->OutputCharset != 'utf-8') $str = $TSFE->csConvObj->utf8_encode($str,$this->OutputCharset);
+               if ($this->OutputCharset != 'utf-8') {
+                       $str = $GLOBALS['TSFE']->csConvObj->utf8_encode($str, $this->OutputCharset);
+               }
                        // Convert the UTF-8 string into a array of char numbers:
-               $nArr = $TSFE->csConvObj->utf8_to_numberarray($str);
-               return 'String.fromCharCode('.implode(',',$nArr).')';
+               $nArr = $GLOBALS['TSFE']->csConvObj->utf8_to_numberarray($str);
+               return 'String.fromCharCode('.implode(',', $nArr).')';
        }
 
        public function getFullFileName($filename) {