Added feature #13580: htmlArea RTE: Extjize the RTE
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / pi2 / class.tx_rtehtmlarea_pi2.php
index 35ec538..3e324c3 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2005-2008 Stanislas Rolland <typo3(arobas)sjbr.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
@@ -33,8 +33,6 @@
  */
 
 require_once(t3lib_extMgm::extPath('rtehtmlarea').'class.tx_rtehtmlarea_base.php');
-require_once(PATH_t3lib.'class.t3lib_parsehtml_proc.php');
-require_once(PATH_t3lib.'class.t3lib_befunc.php');
 
 class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
 
@@ -76,7 +74,7 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
        function drawRTE($parentObject,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue) {
                global $TSFE, $TYPO3_CONF_VARS, $TYPO3_DB;
 
-               $this->TCEform =& $parentObject;
+               $this->TCEform = $parentObject;
                $this->client = $this->clientInfo();
                $this->typoVersion = t3lib_div::int_from_ver(TYPO3_version);
 
@@ -142,8 +140,6 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                if ($this->language == 'default' || !$this->language)   {
                        $this->language = 'en';
                }
-
-               $this->contentISOLanguage = $TYPO3_CONF_VARS['EXTCONF']['rtehtmlarea']['defaultDictionary'];
                $this->contentLanguageUid = ($row['sys_language_uid'] > 0) ? $row['sys_language_uid'] : 0;
                if (t3lib_extMgm::isLoaded('static_info_tables')) {
                        if ($this->contentLanguageUid) {
@@ -161,7 +157,7 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                                        $this->contentTypo3Language = strtolower(trim($languageRow['lg_typo3']));
                                }
                        } else {
-                               $this->contentISOLanguage = trim($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['defaultDictionary']) ? trim($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['defaultDictionary']) : 'en';
+                               $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);
@@ -171,9 +167,8 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                                }
                        }
                }
-
-               $this->contentISOLanguage = $this->contentISOLanguage?$this->contentISOLanguage:$this->language;
-               $this->contentTypo3Language = $this->contentTypo3Language?$this->contentTypo3Language:$TSFE->lang;
+               $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';
                }
@@ -191,97 +186,59 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                 * TOOLBAR CONFIGURATION
                 * =======================================
                 */
-
-                       // htmlArea plugins list
-               $this->pluginEnabledArray = t3lib_div::trimExplode(',', $this->pluginList, 1);
-               $this->enableRegisteredPlugins();
-               $hidePlugins = array();
-               if ($this->client['BROWSER'] == 'opera') {
-                       $hidePlugins[] = 'ContextMenu';
-                       $this->thisConfig['hideTableOperationsInToolbar'] = 0;
-                       $this->thisConfig['disableEnterParagraphs'] = 1;
-               }
-               $this->pluginEnabledArray = array_diff($this->pluginEnabledArray, $hidePlugins);
-
-                       // Toolbar
-               $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 && 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])));
-               }
+               $this->initializeToolbarConfiguration();
 
                /* =======================================
                 * SET STYLES
                 * =======================================
                 */
 
-               $RTEWidth = 460+($this->TCEform->docLarge ? 150 : 0);
-               $RTEHeight = 380;
+               $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']);
-               $RTEHeight = ($RTEHeightOverride > 0) ? $RTEHeightOverride : $RTEHeight;
-               $editorWrapWidth = $RTEWidth . 'px';
-               $editorWrapHeight = $RTEHeight . 'px';
-               $this->RTEWrapStyle = $this->RTEWrapStyle ? $this->RTEWrapStyle : ($this->RTEdivStyle ? $this->RTEdivStyle : ('height:' . ($RTEHeight+2) . 'px; width:'. ($RTEWidth+2) . '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;
+               $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 . '/res/contentcss/default.css';
-               $additionalCode_loadCSS = '
-               <link rel="alternate stylesheet" type="text/css" href="' . $this->getFullFileName($filename) . '" title="HTMLArea RTE Content CSS" />';
-
-                       // 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);
-               }
-
-               $this->editorCSS = $skinFilename;
-               $this->editedContentCSS = $skinDir . '/htmlarea-edited-content.css';
-               $additionalCode_loadCSS .= '
-               <link rel="alternate stylesheet" type="text/css" href="' . $this->editedContentCSS . '" />';
-
-                       // Main stylesheet
-               $additionalCode_loadCSS .= '
-               <link rel="stylesheet" type="text/css" href="' . $this->editorCSS . '" />';
-
-                       // 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 . '" />';
-                               }
-                       }
+               $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);
                }
-
-                       // Loading CSS, JavaScript files and code
-               $TSFE->additionalHeaderData['htmlArea'] = $additionalCode_loadCSS;
                $this->TCEform->additionalJS_initial = $this->loadJSfiles($this->TCEform->RTEcounter);
-               $this->TCEform->additionalJS_pre[] = $this->loadJScode($this->TCEform->RTEcounter);
+               $resizableSettings = array(
+                       'textareaResize' => true,
+                       'textareaMaxHeight' => '600'
+               );
+               $pageRenderer->addInlineSettingArray('', $resizableSettings);
 
                /* =======================================
                 * DRAW THE EDITOR
@@ -302,16 +259,15 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
                $textAreaId = htmlspecialchars($PA['itemFormElName']);
 
                        // Register RTE in JS:
-               $this->TCEform->additionalJS_post[] = $this->registerRTEinJS($this->TCEform->RTEcounter, $textAreaId);
+               $this->TCEform->additionalJS_post[] = $this->registerRTEinJS($this->TCEform->RTEcounter, '', '', '',$textAreaId);
 
                        // Set the save option for the RTE:
                $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' . $textAreaId . '" class="pleasewait" style="display: none;" >' . $TSFE->csConvObj->conv($TSFE->getLLL('Please wait',$this->LOCAL_LANG), $this->charset, $TSFE->renderCharset) . '</div>
-                       <div id="editorWrap' . $$textAreaId . '" class="editorWrap" style="'. htmlspecialchars($this->RTEWrapStyle). '">
+                       <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>' : '') . '
                        ';
@@ -319,36 +275,42 @@ class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
        }
 
        /**
+        * 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.
         *
         * @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
+        * @param       string          $textareaId: the id of the textarea
         *
         * @return      string          the JS-Code
         */
-       function setSaveRTE($RTEcounter, $form, $textarea) {
+       function setSaveRTE($RTEcounter, $form, $textareaId) {
                return '
-               rteFound = false;
-               for (editornumber = 1; editornumber < RTEarea.length; editornumber++) {
-                       if (RTEarea[editornumber].textAreaId == "' . $textarea . '") {
-                               if (!RTEarea[editornumber].deleted) {
-                                       fields = document.getElementsByName(\'' . $textarea . '\');
-                                       field = fields.item(0);
-                                       if(field && field.tagName.toLowerCase() == \'textarea\') field.value = RTEarea[editornumber][\'editor\'].getHTML();
-                               }
-                               rteFound = true;
-                               break;
+               if (RTEarea[\'' . $textareaId . '\'] && !RTEarea[\'' . $textareaId . '\'].deleted) {
+                       fields = document.getElementsByName(\'' . $textareaId . '\');
+                       field = fields.item(0);
+                       if (field && field.nodeName.toLowerCase() == \'textarea\') {
+                               field.value = RTEarea[\'' . $textareaId . '\'][\'editor\'].getHTML();
                        }
-               }
-               if (!rteFound) {
+               } else {
                        OK = 0;
-               }
-               ';
+               }';
        }
-
-
 }
 
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php'])       {