2 namespace TYPO3\CMS\T3editor\Hook
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Core\Utility\GeneralUtility
;
20 * File edit hook for t3editor
22 * @author Tobias Liebig <mail_typo3@etobi.de>
27 * @var \TYPO3\CMS\T3editor\T3editor
29 protected $t3editor = NULL;
34 protected $ajaxSaveType = 'TypoScriptTemplateInformationModuleFunctionController';
37 * @return \TYPO3\CMS\T3editor\T3editor
39 protected function getT3editor() {
40 if ($this->t3editor
== NULL) {
41 $this->t3editor
= GeneralUtility
::makeInstance(\TYPO3\CMS\T3editor\T3editor
::class)->setAjaxSaveType($this->ajaxSaveType
);
43 return $this->t3editor
;
47 * Hook-function: inject t3editor JavaScript code before the page is compiled
48 * called in file_edit module
50 * @param array $parameters
51 * @param \TYPO3\CMS\Backend\Controller\File\EditFileController $pObj
53 public function preOutputProcessingHook($parameters, $pObj) {
54 $t3editor = $this->getT3editor();
55 $t3editor->setModeByFile($parameters['target']);
56 if (!$t3editor->isEnabled() ||
!$t3editor->getMode()) {
59 $parameters['content'] = str_replace('<!--###POSTJSMARKER###-->', '<!--###POSTJSMARKER###-->' . $t3editor->getModeSpecificJavascriptCode(), $parameters['content']);
63 * Hook-function: inject t3editor JavaScript code before the page is compiled
64 * called in \TYPO3\CMS\Backend\Template\DocumentTemplate:startPage
66 * @param array $parameters
67 * @param \TYPO3\CMS\Backend\Template\DocumentTemplate $pObj
68 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate::startPage
70 public function preStartPageHook($parameters, $pObj) {
71 if (GeneralUtility
::_GET('M') === 'file_edit') {
72 $t3editor = $this->getT3editor();
73 if (!$t3editor->isEnabled()) {
76 $pObj->JScode
.= $t3editor->getJavascriptCode($pObj);
77 $pObj->loadJavascriptLib(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility
::extRelPath('t3editor') . 'res/jslib/fileedit.js');
83 * called in file_edit module
85 * @param array $parameters
86 * @param \TYPO3\CMS\Backend\Controller\File\EditFileController $pObj
88 public function postOutputProcessingHook($parameters, $pObj) {
89 $t3editor = $this->getT3editor();
90 if (!$t3editor->isEnabled() ||
!$t3editor->getMode()) {
93 $attributes = 'rows="30" ' . 'wrap="off" ' . $pObj->doc
->formWidth(48, TRUE, 'width:98%;height:60%');
94 $title = $GLOBALS['LANG']->getLL('file') . ' ' . htmlspecialchars($pObj->target
);
95 $outCode = $t3editor->getCodeEditor('file[editfile][0][data]', 'fixed-font enable-tab', '$1', $attributes, $title, array(
96 'target' => (int)$pObj->target
98 $parameters['pageContent'] = preg_replace('/\\<textarea .*name="file\\[editfile\\]\\[0\\]\\[data\\]".*\\>([^\\<]*)\\<\\/textarea\\>/mi', $outCode, $parameters['pageContent']);
102 * @param array $parameters
105 * @return bool TRUE if successful
107 public function save($parameters, $pObj) {
108 $savingsuccess = FALSE;
109 if ($parameters['type'] == $this->ajaxSaveType
) {
110 $tceFile = GeneralUtility
::makeInstance(\TYPO3\CMS\Backend\Controller\File\FileController
::class);
111 $tceFile->processAjaxRequest(array(), $parameters['ajaxObj']);
112 $result = $parameters['ajaxObj']->getContent('result');
113 $savingsuccess = is_array($result) && $result['editfile'][0];
115 return $savingsuccess;