Fixed bug #8264: t3ditor - "+" (plus) signs are replaced by spaces (Thanks to Tobias...
authorBenni Mack <benni.mack@typo3.org>
Tue, 10 Jun 2008 15:25:34 +0000 (15:25 +0000)
committerBenni Mack <benni.mack@typo3.org>
Tue, 10 Jun 2008 15:25:34 +0000 (15:25 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@3792 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/t3editor/class.tx_t3editor.php
typo3/sysext/t3editor/ext_localconf.php
typo3/sysext/t3editor/ext_tables.php [new file with mode: 0644]
typo3/sysext/t3editor/jslib/codemirror/util.js
typo3/sysext/t3editor/jslib/t3editor.js

index 46da493..ce2f20e 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2008-06-10  Benjamin Mack  <benni@typo3.org>
 
+       * Fixed bug #8264: t3ditor - "+" (plus) signs are replaced by spaces (Thanks to Tobias Liebig)
        * Fixed bug 8591: AJAX encoding is UTF-8, thus has problems with backend charsets (Thanks to Tobias Liebig)
 
 2008-06-10  Jeff Segars  <jeff@webempoweredchurch.org>
index c0c2fef..5dcbc70 100755 (executable)
@@ -76,7 +76,6 @@ class tx_t3editor {
         */
        public $isEnabled;
 
-
        /**
         * Creates a new instance of the class
         *
@@ -130,14 +129,20 @@ class tx_t3editor {
                        $doc->loadJavascriptLib('contrib/scriptaculous/scriptaculous.js');
 
                                // include editor-css
-                       $code.= '<link href="'.$GLOBALS['BACK_PATH'].t3lib_extmgm::extRelPath('t3editor').$this->filepathEditorcss.'" type="text/css" rel="stylesheet" />';
+                       $code.= '<link href="' . 
+                               $GLOBALS['BACK_PATH'] .  
+                               t3lib_extmgm::extRelPath('t3editor') . 
+                               $this->filepathEditorcss . 
+                               '" type="text/css" rel="stylesheet" />';
+
                                // include editor-js-lib
-                       $doc->loadJavascriptLib($path_t3e.'jslib/codemirror/codemirror.js');
-                       $doc->loadJavascriptLib($path_t3e.'jslib/t3editor.js');
+                       $doc->loadJavascriptLib($path_t3e . 'jslib/codemirror/codemirror.js');
+                       $doc->loadJavascriptLib($path_t3e . 'jslib/t3editor.js');
 
                        // set correct path to the editor
-                       $code.= '<script type="text/javascript">'.
-                               'PATH_t3e = "'.$GLOBALS['BACK_PATH']. t3lib_extmgm::extRelPath('t3editor').'"; '.
+                       $code.= '<script type="text/javascript">' .
+                               'PATH_t3e = "' .
+                               $GLOBALS['BACK_PATH'] . t3lib_extmgm::extRelPath('t3editor') . '"; ' .
                                '</script>';
 
                }
@@ -155,36 +160,58 @@ class tx_t3editor {
         * @param       string          $alt    Alt attribute
         * @return      string          Generated HTML code for editor
         */
-       public function getCodeEditor($name, $class='', $content='', $additionalParams='', $alt='') {
+       public function getCodeEditor($name, $class='', $content='', $additionalParams='', $alt='', array $hiddenfields = array()) {
                $code = '';
 
                if ($this->isEnabled) {
                        $this->editorCounter++;
 
                        $class .= ' t3editor';
-                       if(!empty($alt)) {
-                               $alt = ' alt="'.$alt.'"';
+                       if (!empty($alt)) {
+                               $alt = ' alt="' . $alt . '"';
                        }
 
-                       $code.= '<div>
-                               <textarea id="t3editor_'.$this->editorCounter.'" name="'.$name.'" class="'.$class.'" '.$additionalParams.' '.$alt.'>'
-                               .$content
-                               .'</textarea></div>';
+                       $code .= '<div>' .
+                               '<textarea id="t3editor_' . $this->editorCounter . '" ' . 
+                               'name="' . $name . '" ' .
+                               'class="' . $class . '" ' . 
+                               $additionalParams . ' ' . 
+                               $alt . '>' . 
+                               $content .
+                               '</textarea></div>';
 
                        $checked = $GLOBALS['BE_USER']->uc['disableT3Editor'] ? 'checked="checked"' : '';
-                       $code.= '<br/><br/>
-                               <input type="checkbox" onclick="t3editor_toggleEditor(this);" name="t3editor_disableEditor" value="true" id="t3editor_disableEditor_'.$this->editorCounter.'_checkbox" '.$checked.' />&nbsp;
-                               <label for="t3editor_disableEditor_'.$this->editorCounter.'_checkbox">deactivate t3editor</label>
-                               <input type="hidden" name="submitAjax" id="submitAjax" value="0" />
-                               <br/><br/>';
+
+                       $code .= '<br/><br/>' .
+                               '<input type="checkbox" ' .
+                               'onclick="t3editor_toggleEditor(this);" ' .
+                               'name="t3editor_disableEditor" ' .
+                               'value="true" ' .
+                               'id="t3editor_disableEditor_' . $this->editorCounter.'_checkbox" ' .
+                               $checked.' />&nbsp;' .
+                               '<label for="t3editor_disableEditor_' . $this->editorCounter . '_checkbox">' .
+                               'deactivate t3editor' .
+                               '</label>' .
+                               '<br/><br/>';
+                       
+                       if (count($hiddenfields)) {
+                               foreach ($hiddenfields as $name => $value) {
+                                       $code.= '<input type="hidden" ' .
+                                               'name="' . $name . '" ' .
+                                               'value="' . $value . 
+                                               '" />';
+                               }
+                       }
 
                } else {
-                               // fallback
+                       // fallback
                        if (!empty($class)) {
-                               $class = 'class="'.$class.'" ';
+                               $class = 'class="' . $class . '" ';
                        }
 
-                       $code .= '<textarea name="'.$name.'" '.$class.$additionalParams.'>'.$content.'</textarea>';
+                       $code .= '<textarea name="' . $name . '" ' .
+                               $class . $additionalParams.'>' .
+                               $content . '</textarea>';
                }
 
                return $code;
@@ -205,7 +232,7 @@ class tx_t3editor {
         * @param template $pObj
         */
        public function preStartPageHook($parameters, $pObj) {
-                       // enable editor in Template-Modul
+               // enable editor in Template-Modul
                if (preg_match('/sysext\/tstemplate\/ts\/index\.php/', $_SERVER['SCRIPT_NAME'])) {
 
                        tx_t3editor::makeGlobalEditorInstance();
@@ -223,24 +250,6 @@ class tx_t3editor {
         * @param array $parameters
         * @param tx_tstemplateinfo $pObj
         */
-       public function postTCEProcessingHook($parameters, $pObj) {
-               if ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
-                       tx_t3editor::makeGlobalEditorInstance();
-                       $GLOBALS['T3_VAR']['t3editorObj']->setBEUCdisableT3Editor(false);
-
-                       header('X-JSON: ('.t3lib_div::array2json(array('result' => $pObj->tce_processed)).')');
-                       // Stop further processing here!
-                       exit();
-               }
-       }
-
-       /**
-        * Hook-function:
-        * called in typo3/sysext/tstemplate_info/class.tx_tstemplateinfo.php
-        *
-        * @param array $parameters
-        * @param tx_tstemplateinfo $pObj
-        */
        public function postOutputProcessingHook($parameters, $pObj) {
                tx_t3editor::makeGlobalEditorInstance();
                if (!$GLOBALS['T3_VAR']['t3editorObj']->isEnabled) {
@@ -249,12 +258,22 @@ class tx_t3editor {
 
                // Template Constants
                if ($parameters['e']['constants']) {
+                       $attributes = 'rows="' . $parameters['numberOfRows'] . '" ' . 
+                               'wrap="off" ' . 
+                               $pObj->pObj->doc->formWidthText(48, 'width:98%;height:60%', 'off');
+
+                       $title = 'Template: ' . htmlspecialchars($parameters['tplRow']['title']) . ': Constants';
+
                        $outCode = $GLOBALS['T3_VAR']['t3editorObj']->getCodeEditor(
-                                               'data[constants]',      // name
-                                               'fixed-font enable-tab',        // class
-                                               t3lib_div::formatForTextarea($parameters['tplRow']['constants']),       // content
-                                               'rows="'.$parameters['numberOfRows'].'" wrap="off" '.$pObj->pObj->doc->formWidthText(48, 'width:98%;height:60%', 'off'),
-                                               'Template: '.htmlspecialchars($parameters['tplRow']['title']).': Constants' // title
+                                               'data[constants]',
+                                               'fixed-font enable-tab',
+                                               t3lib_div::formatForTextarea($parameters['tplRow']['constants']),
+                                               $attributes,
+                                               $title,
+                                               array(
+                                                       'pageId' => intval($pObj->pObj->id),
+                                                       't3editor_savetype' => 'tx_tstemplateinfo',
+                                               )
                                        );
                        $parameters['theOutput'] = preg_replace(
                                '/\<textarea name="data\[constants\]".*\>([^\<]*)\<\/textarea\>/mi',
@@ -265,12 +284,22 @@ class tx_t3editor {
 
                // Template Setup
                if ($parameters['e']['config']) {
+                       $attributes = 'rows="' . $parameters['numberOfRows'] . '" ' .
+                               'wrap="off" ' . 
+                               $pObj->pObj->doc->formWidthText(48, 'width:98%;height:60%', 'off');
+
+                       $title = 'Template: ' . htmlspecialchars($parameters['tplRow']['title']) . ': Setup';
+
                        $outCode = $GLOBALS['T3_VAR']['t3editorObj']->getCodeEditor(
-                                               'data[config]', // name
-                                               'fixed-font enable-tab',        // class
-                                               t3lib_div::formatForTextarea($parameters['tplRow']['config']),  // content
-                                               'rows="'.$parameters['numberOfRows'].'" wrap="off" '.$pObj->pObj->doc->formWidthText(48, 'width:98%;height:60%', 'off'),
-                                               'Template: '.htmlspecialchars($parameters['tplRow']['title']).': Setup' // title
+                                               'data[config]',
+                                               'fixed-font enable-tab',
+                                               t3lib_div::formatForTextarea($parameters['tplRow']['config']),
+                                               $attributes,
+                                               $title,
+                                               array(
+                                                       'pageId' => intval($pObj->pObj->id),
+                                                       't3editor_savetype' => 'tx_tstemplateinfo',
+                                               )
                                        );
                        $parameters['theOutput'] = preg_replace(
                                '/\<textarea name="data\[config\]".*\>([^\<]*)\<\/textarea\>/mi',
@@ -280,7 +309,113 @@ class tx_t3editor {
                }
        }
 
-
+       /**
+        * Save the content from t3editor retrieved via Ajax
+        *
+        * new Ajax.Request('/dev/t3e/dummy/typo3/ajax.php', {
+        *      parameters: {
+        *              ajaxID: 'tx_t3editor::saveCode',
+        *              t3editor_savetype: 'tx_tstemplateinfo'
+        *      }
+        * }); 
+        * 
+        * @param array params  Parameters (not used yet)
+        * @param TYPO3AJAX ajaxObj     AjaxObject to handle response
+        */
+       public function saveCode($params, $ajaxObj) {
+               // cancel if its not an Ajax request
+               if((TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX)) {
+                       $ajaxObj->setContentFormat('json');
+                       $codeType = t3lib_div::_GP('t3editor_savetype');
+                       $savingsuccess = false;
+                       
+                       switch ($codeType) {
+                               case 'tx_tstemplateinfo':
+                                       $savingsuccess = $this->saveCodeTsTemplateInfo();
+                                       break;
+                                       
+                               // TODO: fileadmin, extmng, TCEform, ...
+                               
+                               default:
+                                       $ajaxObj->setError('Unknown content type: ' . $codeType);
+                       }
+                       $ajaxObj->setContent(array('result' => $savingsuccess));
+               }
+       }
+       
+       /**
+        * Process saving request like in class.tstemplateinfo.php (TCE processing)
+        *
+        * @return boolean true if successful
+        */
+       public function saveCodeTsTemplateInfo() {
+               $savingsuccess = false;
+               
+               $pageId = t3lib_div::_GP('pageId');
+               
+               if (!is_numeric($pageId) || $pageId < 1) {
+                       return false;
+               }
+               
+               // if given use the requested template_uid
+               // if not, use the first template-record on the page (in this case there should only be one record!)
+               $set = t3lib_div::_GP('SET');
+               $template_uid = $set['templatesOnPage'] ? $set['templatesOnPage'] : 0;
+               
+               $tmpl = t3lib_div::makeInstance('t3lib_tsparser_ext');  // Defined global here!
+               $tmpl->tt_track = 0;    // Do not log time-performance information
+               $tmpl->init();
+               
+               // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
+               $tplRow = $tmpl->ext_getFirstTemplate($pageId, $template_uid);  
+               $existTemplate =  (is_array($tplRow) ? true : false);
+       
+               if ($existTemplate)     {
+                       $saveId = ($tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid']);
+
+                       // Update template ?
+                       $POST = t3lib_div::_POST();
+                       
+                       if ($POST['submit']) {
+                               require_once(PATH_t3lib . 'class.t3lib_tcemain.php');
+
+                               // Set the data to be saved
+                               $recData = array();
+
+                               if (is_array($POST['data'])) {
+                                       foreach ($POST['data'] as $field => $val) {
+                                               switch ($field) {
+                                                       case 'constants':
+                                                       case 'config':
+                                                       case 'title':
+                                                       case 'sitetitle':
+                                                       case 'description':
+                                                               $recData['sys_template'][$saveId][$field] = $val;
+                                                               break;
+                                               }
+                                       }
+                               }
+                               if (count($recData)) {
+                                       // Create new tce-object
+                                       $tce = t3lib_div::makeInstance('t3lib_TCEmain');
+                                       $tce->stripslashes_values = 0;
+
+                                       // Initialize
+                                       $tce->start($recData, array());
+
+                                       // Saved the stuff
+                                       $tce->process_datamap();
+
+                                       // Clear the cache (note: currently only admin-users can clear the 
+                                       // cache in tce_main.php)
+                                       $tce->clear_cacheCmd('all');
+                                       
+                                       $savingsuccess = true;
+                               }
+                       }
+               }
+               return $savingsuccess;  
+       }
 }
 
 
@@ -289,4 +424,4 @@ if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/t3edito
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/t3editor/class.tx_t3editor.php']);
 }
 
-?>
\ No newline at end of file
+?>
index 89ea1a3..92a99d7 100644 (file)
@@ -3,7 +3,6 @@ if (!defined ('TYPO3_MODE'))    die ('Access denied.');
 
 
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['preStartPageHook'][] = 'EXT:t3editor/class.tx_t3editor.php:&tx_t3editor->preStartPageHook';
-$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postTCEProcessingHook'][] = 'EXT:t3editor/class.tx_t3editor.php:&tx_t3editor->postTCEProcessingHook';
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postOutputProcessingHook'][] = 'EXT:t3editor/class.tx_t3editor.php:&tx_t3editor->postOutputProcessingHook';
 
- ?>
\ No newline at end of file
+ ?>
diff --git a/typo3/sysext/t3editor/ext_tables.php b/typo3/sysext/t3editor/ext_tables.php
new file mode 100644 (file)
index 0000000..bdc4440
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+
+if (!defined('TYPO3_MODE')) {
+       die('Access denied.');
+}
+
+if (TYPO3_MODE == 'BE') {
+       $t3editorPath = t3lib_extMgm::extPath('t3editor');
+
+       // register AJAX calls
+       $GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX']['tx_t3editor::saveCode'] = $t3editorPath . 'class.tx_t3editor.php:tx_t3editor->saveCode';
+}
+
+?>
index 7b329f8..d63a28f 100644 (file)
@@ -140,8 +140,3 @@ function addEventHandler(node, type, handler) {
 }
 
 
-
-// fix prototype issue: ajax request do not respect charset of the page and screw up code
-if (document.characterSet != "UTF-8") {
-       encodeURIComponent = escape;
-}
index 1f391c8..8a63e65 100755 (executable)
@@ -240,10 +240,17 @@ T3editor.prototype = {
                        }
                        this.modalOverlay.show();
                        this.textarea.value = this.mirror.editor.getCode();
-                       $('submitAjax').value = '1';
-                       Form.request($(this.textarea.form), {
-                               onComplete: this.saveFunctionComplete.bind(this)
-                       });
+                       
+                       params = $(this.textarea.form).serialize(true);
+                       params = Object.extend( { ajaxID: 'tx_t3editor::saveCode' }, params);
+                       
+                       new Ajax.Request(
+                               (top && top.TS ? top.TS.PATH_typo3 : PATH_t3e + '../../' ) + 'ajax.php', { 
+                                       parameters: params,
+                                       onComplete: this.saveFunctionComplete.bind(this)
+                               }
+                       );
+                       
                },
 
                // callback if ajax saving was successful
@@ -256,7 +263,6 @@ T3editor.prototype = {
                        } else {
                                alert("An error occured while saving the data.");
                        };
-                       $('submitAjax').value = '0';
                        this.modalOverlay.hide();
                },
                
@@ -439,12 +445,6 @@ T3editor.prototype = {
 } // T3editor.prototype
 
 
-// fix prototype issue: ajax request do not respect charset of the page and screw up code
-if (document.characterSet != "UTF-8") {
-       encodeURIComponent = escape;
-}
-
-
 // ------------------------------------------------------------------------