2010-10-12 Steffen Kamper <steffen@typo3.org>
+ * Added feature #15950: Use t3editor in file_edit to edit files in fileadmin
* Fixed bug #15965: codemirror lib for t3editor should be moved to contrib and updated to latest version
* Fixed bug #15968: Remove block mode from syntaxhighlighted code
* Added feature #15621: Feature: TYPO3 misses page-option to force SSL oder Non-SSL to page (Thanks to Steffen Ritter)
const MODE_JAVASCRIPT = 'javascript';
const MODE_CSS = 'css';
const MODE_XML = 'xml';
+ const MODE_HTML = 'html';
protected $mode = '';
+ protected $ajaxSaveType = '';
+
/**
* counts the editors on the current page
*
return $this;
}
+ /**
+ *
+ * @param $ajaxSaveType
+ * @return tx_t3editor
+ */
+ public function setAjaxSaveType($ajaxSaveType) {
+ $this->ajaxSaveType = $ajaxSaveType;
+ return $this;
+ }
+
+ public function setModeByFile($file) {
+ $fileInfo = t3lib_div::split_fileref($file);
+ switch ($fileInfo['fileext']) {
+ case 'html':
+ case 'htm':
+ case 'tmpl':
+ $mode = self::MODE_HTML;
+ break;
+ case 'js':
+ $mode = self::MODE_JAVASCRIPT;
+ break;
+ case 'xml':
+ case 'svg':
+ $mode = self::MODE_XML;
+ break;
+ case 'css':
+ $mode = self::MODE_CSS;
+ break;
+ case 'ts':
+ $mode = self::MODE_TYPOSCRIPT;
+ break;
+ default:
+ $mode = FALSE;
+ }
+ $this->setMode($mode);
+ }
+
+ public function getMode() {
+ return $this->mode;
+ }
+
/**
* @return boolean true if the t3editor is enabled
*/
$path_codemirror = 'contrib/codemirror/js/';
// include needed javascript-frameworks
- /** @var $pageRenderer t3lib_PageRenderer */
$pageRenderer = $doc->getPageRenderer();
+ /** @var $pageRenderer t3lib_PageRenderer */
$pageRenderer->loadPrototype();
$pageRenderer->loadScriptaculous();
$doc->loadJavascriptLib($path_codemirror . 'codemirror.js');
$doc->loadJavascriptLib($path_t3e . 'res/jslib/t3editor.js');
- if ($this->mode == self::MODE_TYPOSCRIPT) {
- $doc->loadJavascriptLib($path_t3e . 'res/jslib/ts_codecompletion/tsref.js');
- $doc->loadJavascriptLib($path_t3e . 'res/jslib/ts_codecompletion/completionresult.js');
- $doc->loadJavascriptLib($path_t3e . 'res/jslib/ts_codecompletion/tsparser.js');
- $doc->loadJavascriptLib($path_t3e . 'res/jslib/ts_codecompletion/tscodecompletion.js');
- }
-
$content .= t3lib_div::wrapJS(
'T3editor = T3editor || {};' .
'T3editor.lang = ' . json_encode($this->getJavaScriptLabels()) .';' . LF.
'T3editor.PATH_codemirror = "' . $GLOBALS['BACK_PATH'] . $path_codemirror . '"; ' . LF.
'T3editor.URL_typo3 = "' . htmlspecialchars(t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir) . '"; ' .LF.
'T3editor.template = '. $this->getPreparedTemplate() .';' .LF.
- 'T3editor.parserfile = ' . $this->getParserfileByMode($this->mode) . ';' .LF.
- 'T3editor.stylesheet = ' . $this->getStylesheetByMode($this->mode) . ';'
+ ($this->ajaxSaveType ? 'T3editor.ajaxSavetype = "' . $this->ajaxSaveType . '";' . LF : '') .
+ ($this->mode ? 'T3editor.parserfile = ' . $this->getParserfileByMode($this->mode) . ';' . LF : '') .
+ ($this->mode ? 'T3editor.stylesheet = ' . $this->getStylesheetByMode($this->mode) . ';' : '')
);
+ $content .= $this->getModeSpecificJavascriptCode();
}
return $content;
}
+ public function getModeSpecificJavascriptCode() {
+ if (empty($this->mode)) {
+ return '';
+ }
+
+ $path_t3e = t3lib_extmgm::extRelPath('t3editor');
+
+ if ($this->mode == self::MODE_TYPOSCRIPT) {
+ $content .= '<script type="text/javascript" src="' . $path_t3e . 'res/jslib/ts_codecompletion/tsref.js' . '"></script>';
+ $content .= '<script type="text/javascript" src="' . $path_t3e . 'res/jslib/ts_codecompletion/completionresult.js' . '"></script>';
+ $content .= '<script type="text/javascript" src="' . $path_t3e . 'res/jslib/ts_codecompletion/tsparser.js' . '"></script>';
+ $content .= '<script type="text/javascript" src="' . $path_t3e . 'res/jslib/ts_codecompletion/tscodecompletion.js' . '"></script>';
+ }
+
+ $content .= t3lib_div::wrapJS(
+ 'T3editor.parserfile = ' . $this->getParserfileByMode($this->mode) . ';' . LF .
+ 'T3editor.stylesheet = ' . $this->getStylesheetByMode($this->mode) . ';'
+ );
+ return $content;
+ }
+
/**
- * get the template code, prepared for javascript (no line breaks, quoted in slinge quotes)
+ * get the template code, prepared for javascript (no line breaks, quoted in single quotes)
*
* @return string the template code, prepared to use in javascript
*/
case tx_t3editor::MODE_XML:
$parserfile = '"parsexml.js"';
break;
+
+ case tx_t3editor::MODE_HTML:
+ $parserfile = '["tokenizejavascript.js", "parsejavascript.js", "parsecss.js", "parsexml.js", "parsehtmlmixed.js"]';
+ break;
}
return $parserfile;
}
case tx_t3editor::MODE_XML:
$stylesheet = '"res/css/xmlcolors.css"';
break;
+
+ case tx_t3editor::MODE_HTML:
+ $stylesheet = '"res/css/xmlcolors.css"';
+ // FIXME add css and js files
+ break;
}
- return '[T3editor.PATH_t3e + "res/css/t3editor_inner.css", T3editor.PATH_t3e + ' . $stylesheet . ']';
+ return '[T3editor.PATH_t3e + ' . $stylesheet . ', T3editor.PATH_t3e + "res/css/t3editor_inner.css"]';
}
/**
if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/t3editor/classes/class.tx_t3editor.php']['ajaxSaveCode'])) {
$_params = array(
'pObj' => &$this,
- 'type' => $codeType
+ 'type' => $codeType,
+ 'ajaxObj' => &$ajaxObj,
);
foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/t3editor/classes/class.tx_t3editor.php']['ajaxSaveCode'] as $key => $_funcRef) {
$savingsuccess = t3lib_div::callUserFunction($_funcRef,$_params,$this) || $savingsuccess;
$ajaxObj->setContent($result);
$ajaxObj->setContentFormat('jsonbody');
}
+
}
}\r
\r
\r
+if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/t3editor/classes/class.tx_t3editor_hooks_fileedit.php']) {\r
+ include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/t3editor/classes/class.tx_t3editor_hooks_fileedit.php']);\r
+}\r
+\r
+?>\r
+<?php\r
+/***************************************************************\r
+* Copyright notice\r
+*\r
+* (c) 2010 Tobias Liebig <mail_typo3@etobi.de>\r
+* All rights reserved\r
+*\r
+* This script is part of the TYPO3 project. The TYPO3 project is\r
+* free software; you can redistribute it and/or modify\r
+* it under the terms of the GNU General Public License as published by\r
+* the Free Software Foundation; either version 2 of the License, or\r
+* (at your option) any later version.\r
+*\r
+* The GNU General Public License can be found at\r
+* http://www.gnu.org/copyleft/gpl.html.\r
+* A copy is found in the textfile GPL.txt and important notices to the license\r
+* from the author is found in LICENSE.txt distributed with these scripts.\r
+*\r
+*\r
+* This script is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+* GNU General Public License for more details.\r
+*\r
+* This copyright notice MUST APPEAR in all copies of the script!\r
+***************************************************************/\r
+\r
+require_once(t3lib_extMgm::extPath('t3editor', 'classes/class.tx_t3editor.php'));\r
+\r
+class tx_t3editor_hooks_fileedit {\r
+\r
+ /**\r
+ * @var tx_t3editor\r
+ */\r
+ protected $t3editor = NULL;\r
+ \r
+ /**\r
+ * @var string\r
+ */\r
+ protected $ajaxSaveType = 'tx_tstemplateinfo';\r
+\r
+ /**\r
+ * @return tx_t3editor\r
+ */\r
+ protected function getT3editor() {\r
+ if ($this->t3editor == NULL) {\r
+ $this->t3editor = t3lib_div::makeInstance('tx_t3editor')\r
+ ->setAjaxSaveType($this->ajaxSaveType);\r
+ }\r
+ return $this->t3editor;\r
+ }\r
+\r
+ /**\r
+ * Hook-function: inject t3editor JavaScript code before the page is compiled\r
+ * called in file_edit.php:SC_file_edit->main\r
+ *\r
+ * @param array $parameters\r
+ * @param SC_file_edit $pObj\r
+ */\r
+ public function preOutputProcessingHook($parameters, $pObj) {\r
+ $t3editor = $this->getT3editor();\r
+ $t3editor->setModeByFile($parameters['target']);\r
+\r
+ if (!$t3editor->isEnabled() || !$t3editor->getMode()) {\r
+ return;\r
+ }\r
+\r
+ $parameters['content'] = str_replace(\r
+ '<!--###POSTJSMARKER###-->',\r
+ '<!--###POSTJSMARKER###-->' . $t3editor->getModeSpecificJavascriptCode(),\r
+ $parameters['content']\r
+ );\r
+ }\r
+\r
+ /**\r
+ * Hook-function: inject t3editor JavaScript code before the page is compiled\r
+ * called in typo3/template.php:startPage\r
+ *\r
+ * @param array $parameters\r
+ * @param template $pObj\r
+ */\r
+ public function preStartPageHook($parameters, $pObj) {\r
+ if (preg_match('/typo3\/file_edit\.php/', $_SERVER['SCRIPT_NAME'])) {\r
+ $t3editor = $this->getT3editor();\r
+ if (!$t3editor->isEnabled()) {\r
+ return;\r
+ }\r
+ $pObj->JScode .= $t3editor->getJavascriptCode($pObj);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Hook-function:\r
+ * called in file_edit.php:SC_file_edit->main\r
+ *\r
+ * @param array $parameters\r
+ * @param SC_file_edit $pObj\r
+ */\r
+ public function postOutputProcessingHook($parameters, $pObj) {\r
+ $t3editor = $this->getT3editor();\r
+\r
+ if (!$t3editor->isEnabled() || !$t3editor->getMode()) {\r
+ return;\r
+ }\r
+ \r
+ $attributes = 'rows="30" ' .\r
+ 'wrap="off" ' .\r
+ $pObj->doc->formWidthText(48, 'width:98%;height:60%', 'off');\r
+\r
+ $title = $GLOBALS['LANG']->getLL('file') . ' ' .\r
+ htmlspecialchars($pObj->target);\r
+\r
+ $outCode = $t3editor->getCodeEditor(\r
+ 'file[editfile][0][data]',\r
+ 'fixed-font enable-tab',\r
+ '$1', // will be replaced with the actual code later, see preg_replace below\r
+ $attributes,\r
+ $title,\r
+ array(\r
+ 'target' => intval($pObj->target)\r
+ )\r
+ );\r
+\r
+ $parameters['pageContent'] = preg_replace(\r
+ '/\<textarea .*name="file\[editfile\]\[0\]\[data\]".*\>([^\<]*)\<\/textarea\>/mi',\r
+ $outCode,\r
+ $parameters['pageContent']\r
+ );\r
+\r
+ }\r
+\r
+ /**\r
+ * @return boolean true if successful\r
+ */\r
+ public function save($parameters, $pObj) {\r
+ $savingsuccess = false;\r
+ if ($parameters['type'] == $this->ajaxSaveType) {\r
+ require_once('init.php');\r
+ require_once('classes/class.typo3_tcefile.php');\r
+\r
+ $tceFile = t3lib_div::makeInstance('TYPO3_tcefile');\r
+ $tceFile->processAjaxRequest(array(), $parameters['ajaxObj']);\r
+\r
+ $result = $parameters['ajaxObj']->getContent('result');\r
+ $savingsuccess = is_array($result) && $result['editfile'][0];\r
+ }\r
+ return $savingsuccess;\r
+ }\r
+}\r
+\r
+\r
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/t3editor/classes/class.tx_t3editor_hooks_fileedit.php']) {\r
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/t3editor/classes/class.tx_t3editor_hooks_fileedit.php']);\r
}\r
class tx_t3editor_hooks_tstemplateinfo {
/**
- *
* @var tx_t3editor
*/
protected $t3editor = NULL;
+
+ /**
+ * @var string
+ */
+ protected $ajaxSaveType = 'tx_tstemplateinfo';
/**
- *
* @return tx_t3editor
*/
protected function getT3editor() {
if ($this->t3editor == NULL) {
$this->t3editor = t3lib_div::makeInstance('tx_t3editor')
- ->setMode(tx_t3editor::MODE_TYPOSCRIPT);
+ ->setMode(tx_t3editor::MODE_TYPOSCRIPT)
+ ->setAjaxSaveType($this->ajaxSaveType);
}
return $this->t3editor;
}
// insert javascript code in document header
$pObj->JScode .= $t3editor->getJavascriptCode($pObj);
- $pObj->loadJavascriptLib(t3lib_extmgm::extRelPath('t3editor') . 'res/jslib/tx_tstemplateinfo/tx_tstemplateinfo.js');
}
}
*/
public function save($parameters, $pObj) {
$savingsuccess = false;
- if ($parameters['type'] == 'tx_tstemplateinfo') {
+ if ($parameters['type'] == $this->ajaxSaveType) {
$pageId = t3lib_div::_GP('pageId');
if (!is_numeric($pageId) || $pageId < 1) {
$TYPO3_CONF_VARS['SC_OPTIONS']['ext/t3editor/classes/class.tx_t3editor.php']['ajaxSaveCode']['tx_tstemplateinfo'] =
'EXT:t3editor/classes/class.tx_t3editor_hooks_tstemplateinfo.php:&tx_t3editor_hooks_tstemplateinfo->save';
+ $TYPO3_CONF_VARS['SC_OPTIONS']['ext/t3editor/classes/class.tx_t3editor.php']['ajaxSaveCode']['file_edit'] =
+ 'EXT:t3editor/classes/class.tx_t3editor_hooks_fileedit.php:&tx_t3editor_hooks_fileedit->save';
+
+ $TYPO3_CONF_VARS['SC_OPTIONS']['typo3/template.php']['preStartPageHook'][] =
+ 'EXT:t3editor/classes/class.tx_t3editor_hooks_fileedit.php:&tx_t3editor_hooks_fileedit->preStartPageHook';
+ $TYPO3_CONF_VARS['SC_OPTIONS']['typo3/file_edit.php']['preOutputProcessingHook'][] =
+ 'EXT:t3editor/classes/class.tx_t3editor_hooks_fileedit.php:&tx_t3editor_hooks_fileedit->preOutputProcessingHook';
+ $TYPO3_CONF_VARS['SC_OPTIONS']['typo3/file_edit.php']['postOutputProcessingHook'][] =
+ 'EXT:t3editor/classes/class.tx_t3editor_hooks_fileedit.php:&tx_t3editor_hooks_fileedit->postOutputProcessingHook';
+
}
?>
\ No newline at end of file
<languageKey index="default" type="array">
<label index="deactivate">Deactivate t3editor</label>
<label index="template">Template</label>
+ <label index="file">File</label>
<label index="delimiter">:</label>
<label index="constants">Constants</label>
<label index="setup">Setup</label>
}
}
);
+
+ if (T3editor.ajaxSavetype != "") {
+ Event.observe(document, 't3editor:save',
+ function(event) {
+ var params = Object.extend({
+ ajaxID: "tx_t3editor::saveCode",
+ t3editor_savetype: T3editor.ajaxSavetype
+ }, event.memo.parameters);
+
+ new Ajax.Request(
+ T3editor.URL_typo3 + "ajax.php", {
+ parameters: params,
+ onComplete: function(ajaxrequest) {
+ var wasSuccessful = ajaxrequest.status == 200
+ && ajaxrequest.headerJSON.result == true
+ event.memo.t3editor.saveFunctionComplete(wasSuccessful);
+ }
+ }
+ );
+ }
+ );
+ }
}
);
}
+++ /dev/null
-document.observe('t3editor:save', function(event) {
- var params = Object.extend({
- ajaxID: "tx_t3editor::saveCode",
- t3editor_savetype: "tx_tstemplateinfo"
- }, event.memo.parameters);
-
- new Ajax.Request(
- T3editor.URL_typo3 + "ajax.php", {
- parameters: params,
- onComplete: function(ajaxrequest) {
- var wasSuccessful = ajaxrequest.status == 200
- && ajaxrequest.headerJSON.result == true
- event.memo.t3editor.saveFunctionComplete(wasSuccessful);
- }
- }
- );
-});
\ No newline at end of file