*/
public $isEnabled;
-
/**
* Creates a new instance of the class
*
$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>';
}
* @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.' />
- <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.' /> ' .
+ '<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;
* @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();
}
- /**
- * Hook-function:
- * called in typo3/sysext/tstemplate_info/class.tx_tstemplateinfo.php
- *
- * @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
// 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',
// 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',
}
}
-
+ /**
+ * 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;
+ }
}
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/t3editor/class.tx_t3editor.php']);
}
-?>
\ No newline at end of file
+?>