TYPO3 CMS  TYPO3_7-6
FileEditHook.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
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.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
24 {
28  protected $t3editor = null;
29 
33  protected $ajaxSaveType = 'TypoScriptTemplateInformationModuleFunctionController';
34 
38  protected function getT3editor()
39  {
40  if ($this->t3editor === null) {
41  $this->t3editor = GeneralUtility::makeInstance(\TYPO3\CMS\T3editor\T3editor::class)->setAjaxSaveType($this->ajaxSaveType);
42  }
43  return $this->t3editor;
44  }
45 
53  public function preOutputProcessingHook($parameters, $pObj)
54  {
55  $t3editor = $this->getT3editor();
56  $t3editor->setModeByFile($parameters['target']);
57  if (!$t3editor->getMode()) {
58  return;
59  }
60  $t3editor->getJavascriptCode();
61  $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/T3editor/FileEdit');
62  }
63 
70  public function preStartPageHook()
71  {
72  // @todo: this is a workaround. Ideally the document template holds the current request so we can match the route
73  // against the name of the route and not the GET parameter
74  if (GeneralUtility::_GET('route') === '/file/editcontent') {
75  $t3editor = $this->getT3editor();
76  $t3editor->getJavascriptCode();
77  $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/T3editor/FileEdit');
78  }
79  }
80 
88  public function postOutputProcessingHook($parameters, $pObj)
89  {
90  $t3editor = $this->getT3editor();
91  if (!$t3editor->getMode()) {
92  return;
93  }
94  $attributes = 'rows="30" ' . 'wrap="off"' . $pObj->doc->formWidth(48, true, 'width:98%;height:60%');
95  $title = $GLOBALS['LANG']->getLL('file') . ' ' . htmlspecialchars($pObj->target);
96  $outCode = $t3editor->getCodeEditor('file[editfile][0][data]', 'text-monospace enable-tab', '$1', $attributes, $title, [
97  'target' => (int)$pObj->target
98  ]);
99  $parameters['pageContent'] = preg_replace('/\\<textarea .*name="file\\[editfile\\]\\[0\\]\\[data\\]".*\\>([^\\<]*)\\<\\/textarea\\>/mi', $outCode, $parameters['pageContent']);
100  }
101 
108  public function save($parameters, $pObj)
109  {
110  $savingsuccess = false;
111  if ($parameters['type'] === $this->ajaxSaveType) {
113  $tceFile = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Controller\File\FileController::class);
114  $response = $tceFile->processAjaxRequest($parameters['request'], $parameters['response']);
115  $result = json_decode((string)$response->getBody(), true);
116  $savingsuccess = is_array($result) && $result['editfile'][0];
117  }
118  return $savingsuccess;
119  }
120 
124  protected function getPageRenderer()
125  {
126  return GeneralUtility::makeInstance(PageRenderer::class);
127  }
128 }
preOutputProcessingHook($parameters, $pObj)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
postOutputProcessingHook($parameters, $pObj)