TYPO3 CMS  TYPO3_7-6
TypoScriptTemplateInfoHook.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 
21 {
25  protected $t3editor = null;
26 
30  protected $ajaxSaveType = 'TypoScriptTemplateInformationModuleFunctionController';
31 
35  protected function getT3editor()
36  {
37  if ($this->t3editor == null) {
38  $this->t3editor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\T3editor\T3editor::class)->setMode(\TYPO3\CMS\T3editor\T3editor::MODE_TYPOSCRIPT)->setAjaxSaveType($this->ajaxSaveType);
39  }
40  return $this->t3editor;
41  }
42 
50  public function preStartPageHook()
51  {
52  // Enable editor in Template-Modul
53  if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('M') === 'web_ts') {
54  $t3editor = $this->getT3editor();
55  // Insert javascript code
56  $t3editor->getJavascriptCode();
57  }
58  }
59 
68  public function postOutputProcessingHook($parameters, $pObj)
69  {
70  $t3editor = $this->getT3editor();
71  $t3editor->getJavascriptCode();
72  foreach (['constants', 'config'] as $type) {
73  if ($parameters['e'][$type]) {
74  $attributes = 'rows="' . (int)$parameters['numberOfRows'] . '" wrap="off"' . $pObj->pObj->doc->formWidth(48, true, 'width:98%;height:60%');
75  $title = $GLOBALS['LANG']->getLL('template') . ' ' . $parameters['tplRow']['title'] . $GLOBALS['LANG']->getLL('delimiter') . ' ' . $GLOBALS['LANG']->getLL($type);
76  $outCode = $t3editor->getCodeEditor('data[' . $type . ']', 'text-monospace enable-tab', '$1', $attributes, $title, [
77  'pageId' => (int)$pObj->pObj->id
78  ]);
79  $parameters['theOutput'] = preg_replace('/\\<textarea name="data\\[' . $type . '\\]".*\\>([^\\<]*)\\<\\/textarea\\>/mi', $outCode, $parameters['theOutput']);
80  }
81  }
82  }
83 
89  public function save($parameters, $pObj)
90  {
91  $savingsuccess = false;
92  if ($parameters['type'] == $this->ajaxSaveType) {
94  if (!is_numeric($pageId) || $pageId < 1) {
95  return false;
96  }
97  // If given use the requested template_uid
98  // if not, use the first template-record on the page (in this case there should only be one record!)
100  $template_uid = $set['templatesOnPage'] ?: 0;
101  // Defined global here!
102  $tmpl = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\ExtendedTemplateService::class);
103  // Do not log time-performance information
104  $tmpl->tt_track = 0;
105  $tmpl->init();
106  // Get the first template record on the page, which might be hidden as well
107  // (for instance the TypoScript constant editor is persisting to the first template)
108  $tplRow = $tmpl->ext_getFirstTemplate($pageId, $template_uid);
109  $existTemplate = is_array($tplRow);
110  if ($existTemplate) {
111  $saveId = $tplRow['_ORIG_uid'] ?: $tplRow['uid'];
112  // Update template ?
114  if ($POST['submit']) {
115  // Set the data to be saved
116  $recData = [];
117  if (is_array($POST['data'])) {
118  foreach ($POST['data'] as $field => $val) {
119  switch ($field) {
120  case 'constants':
121  case 'config':
122  // Replace Windows- and Mac linebreaks
123  $val = str_replace([CRLF, CR], LF, $val);
124  $recData['sys_template'][$saveId][$field] = $val;
125  break;
126  }
127  }
128  }
129  if (!empty($recData)) {
130  // process template row before saving
131  $tstemplateinfo = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController::class);
132  /* @var $tstemplateinfo \TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateInformationModuleFunctionController */
133  // load the MOD_SETTINGS in order to check if the includeTypoScriptFileContent is set
134  $tstemplateinfo->pObj = $pObj;
135  $tstemplateinfo->pObj->MOD_SETTINGS = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleData(['includeTypoScriptFileContent' => true], [], 'web_ts');
136  $recData['sys_template'][$saveId] = $tstemplateinfo->processTemplateRowBeforeSaving($recData['sys_template'][$saveId]);
137  // Create new tce-object
138  $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
139  $tce->stripslashes_values = 0;
140  // Initialize
141  $tce->start($recData, []);
142  // Saved the stuff
143  $tce->process_datamap();
144  // Clear the cache (note: currently only admin-users can clear the
145  // cache in tce_main.php)
146  $tce->clear_cacheCmd('all');
147  $savingsuccess = true;
148  }
149  }
150  }
151  }
152  return $savingsuccess;
153  }
154 }
static getModuleData($MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']