TYPO3 CMS  TYPO3_8-7
TypoScriptTemplateInformationModuleFunctionController.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 
26 
31 {
37  public $tce_processed = false;
38 
42  public $pObj;
43 
48  protected $templateRow;
49 
53  protected $templateService;
54 
64  public function tableRowData($label, $data, $field, $id)
65  {
66  if ($field === 'config' || $field === 'constants') {
67  $urlParameters = [
68  'id' => $this->pObj->id,
69  'e' => [
70  $field => 1
71  ]
72  ];
73  $url = BackendUtility::getModuleUrl('web_ts', $urlParameters);
74  } else {
75  $urlParameters = [
76  'edit' => [
77  'sys_template' => [
78  $id => 'edit'
79  ]
80  ],
81  'columnsOnly' => $field,
82  'createExtension' => 0,
83  'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
84  ];
85  $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
86  }
87  $row = [];
88  $row['url'] = $url;
89  $row['data'] = $data;
90  $row['label'] = $label;
91  return $row;
92  }
93 
105  public function initialize_editor($pageId, $template_uid = 0)
106  {
107  $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
108  $this->templateService->init();
109 
110  // Get the row of the first VISIBLE template of the page. where clause like the frontend.
111  $this->templateRow = $this->templateService->ext_getFirstTemplate($pageId, $template_uid);
112  if (is_array($this->templateRow)) {
113  $this->templateRow = $this->processTemplateRowAfterLoading($this->templateRow);
114  return true;
115  }
116  return false;
117  }
118 
125  public function processTemplateRowAfterLoading(array $tplRow)
126  {
127  if ($this->pObj->MOD_SETTINGS['includeTypoScriptFileContent']) {
128  // Let the recursion detection counter start at 91, so that only 10 recursive calls will be resolved
129  // Otherwise the editor will be bloated with way to many lines making it hard the break the cyclic recursion.
130  $tplRow['config'] = TypoScriptParser::checkIncludeLines($tplRow['config'], 91);
131  $tplRow['constants'] = TypoScriptParser::checkIncludeLines($tplRow['constants'], 91);
132  }
133  return $tplRow;
134  }
135 
142  public function processTemplateRowBeforeSaving(array $tplRow)
143  {
144  if ($this->pObj->MOD_SETTINGS['includeTypoScriptFileContent']) {
145  $tplRow = TypoScriptParser::extractIncludes_array($tplRow);
146  }
147  return $tplRow;
148  }
149 
153  protected function getLanguageService()
154  {
155  return $GLOBALS['LANG'];
156  }
157 
163  public function main()
164  {
165  $this->pObj->MOD_MENU['includeTypoScriptFileContent'] = true;
166  $e = $this->pObj->e;
167  // Checking for more than one template an if, set a menu...
168  $manyTemplatesMenu = $this->pObj->templateMenu();
169  $template_uid = 0;
170  if ($manyTemplatesMenu) {
171  $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
172  }
173  // Initialize
174  $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
175  $saveId = 0;
176  if ($existTemplate) {
177  $saveId = $this->templateRow['_ORIG_uid'] ? : $this->templateRow['uid'];
178  }
179  // Create extension template
180  $newId = $this->pObj->createTemplate($this->pObj->id, $saveId);
181  if ($newId) {
182  // Switch to new template
183  $urlParameters = [
184  'id' => $this->pObj->id,
185  'SET[templatesOnPage]' => $newId
186  ];
187  $url = BackendUtility::getModuleUrl('web_ts', $urlParameters);
188  HttpUtility::redirect($url);
189  }
190  $tce = null;
191  if ($existTemplate) {
192  $lang = $this->getLanguageService();
193  $lang->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_info.xlf');
194  $assigns = [];
195  $assigns['LLPrefix'] = 'LLL:EXT:tstemplate/Resources/Private/Language/locallang_info.xlf:';
196  // Update template ?
197  $POST = GeneralUtility::_POST();
198  if (
199  isset($POST['_savedok'])
200  || isset($POST['_saveandclosedok'])
201  ) {
202  // Set the data to be saved
203  $recData = [];
204  $alternativeFileName = [];
205  if (is_array($POST['data'])) {
206  foreach ($POST['data'] as $field => $val) {
207  switch ($field) {
208  case 'constants':
209  case 'config':
210  $recData['sys_template'][$saveId][$field] = $val;
211  break;
212  }
213  }
214  }
215  if (!empty($recData)) {
216  $recData['sys_template'][$saveId] = $this->processTemplateRowBeforeSaving($recData['sys_template'][$saveId]);
217  // Create new tce-object
218  $tce = GeneralUtility::makeInstance(DataHandler::class);
219  $tce->alternativeFileName = $alternativeFileName;
220  // Initialize
221  $tce->start($recData, []);
222  // Saved the stuff
223  $tce->process_datamap();
224  // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php)
225  $tce->clear_cacheCmd('all');
226  // tce were processed successfully
227  $this->tce_processed = true;
228  // re-read the template ...
229  $this->initialize_editor($this->pObj->id, $template_uid);
230  // reload template menu
231  $manyTemplatesMenu = $this->pObj->templateMenu();
232  }
233  }
234  // Hook post updating template/TCE processing
235  if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postTCEProcessingHook'])) {
236  $postTCEProcessingHook = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postTCEProcessingHook'];
237  if (is_array($postTCEProcessingHook)) {
238  $hookParameters = [
239  'POST' => $POST,
240  'tce' => $tce
241  ];
242  foreach ($postTCEProcessingHook as $hookFunction) {
243  GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
244  }
245  }
246  }
247  $assigns['title'] = trim($this->templateRow['title']);
248  $assigns['siteTitle'] = trim($this->templateRow['sitetitle']);
249  $assigns['templateRecord'] = $this->templateRow;
250  if ($manyTemplatesMenu) {
251  $assigns['manyTemplatesMenu'] = $manyTemplatesMenu;
252  }
253  $numberOfRows = 35;
254  $assigns['numberOfRows'] = $numberOfRows;
255  // If abort pressed, nothing should be edited:
256  if (isset($POST['_saveandclosedok'])) {
257  unset($e);
258  }
259  if (isset($e['constants'])) {
260  $assigns['showConstantsEditor'] = true;
261  $assigns['constants'] = $this->templateRow['constants'];
262  $assigns['constantsLabel'] = BackendUtility::getFuncCheck($this->pObj->id, 'SET[includeTypoScriptFileContent]', $this->pObj->MOD_SETTINGS['includeTypoScriptFileContent'], '', '&e[constants]=1', 'id="checkIncludeTypoScriptFileContent"');
263  }
264  if (isset($e['config'])) {
265  $assigns['showConfigEditor'] = true;
266  $assigns['config'] = $this->templateRow['config'];
267  $assigns['configLabel'] = BackendUtility::getFuncCheck($this->pObj->id, 'SET[includeTypoScriptFileContent]', $this->pObj->MOD_SETTINGS['includeTypoScriptFileContent'], '', '&e[config]=1', 'id="checkIncludeTypoScriptFileContent"');
268  }
269 
270  // Processing:
271  $tableRows = [];
272  $tableRows[] = $this->tableRowData($lang->getLL('title'), $this->templateRow['title'], 'title', $this->templateRow['uid']);
273  $tableRows[] = $this->tableRowData($lang->getLL('sitetitle'), $this->templateRow['sitetitle'], 'sitetitle', $this->templateRow['uid']);
274  $tableRows[] = $this->tableRowData($lang->getLL('description'), $this->templateRow['description'], 'description', $this->templateRow['uid']);
275  $tableRows[] = $this->tableRowData($lang->getLL('constants'), sprintf($lang->getLL('editToView'), trim($this->templateRow['constants']) ? count(explode(LF, $this->templateRow['constants'])) : 0), 'constants', $this->templateRow['uid']);
276  $tableRows[] = $this->tableRowData($lang->getLL('setup'), sprintf($lang->getLL('editToView'), trim($this->templateRow['config']) ? count(explode(LF, $this->templateRow['config'])) : 0), 'config', $this->templateRow['uid']);
277  $assigns['tableRows'] = $tableRows;
278 
279  // Edit all icon:
280  $urlParameters = [
281  'edit' => [
282  'sys_template' => [
283  $this->templateRow['uid'] => 'edit'
284  ]
285  ],
286  'createExtension' => 0,
287  'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
288  ];
289  $assigns['editAllUrl'] = BackendUtility::getModuleUrl('record_edit', $urlParameters);
290 
291  // Rendering of the output via fluid
292  $view = GeneralUtility::makeInstance(StandaloneView::class);
293  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
294  'EXT:tstemplate/Resources/Private/Templates/InformationModule.html'
295  ));
296  $view->assignMultiple($assigns);
297  $theOutput = $view->render();
298 
299  // hook after compiling the output
300  if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postOutputProcessingHook'])) {
301  $postOutputProcessingHook = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postOutputProcessingHook'];
302  if (is_array($postOutputProcessingHook)) {
303  $hookParameters = [
304  'theOutput' => &$theOutput,
305  'POST' => $POST,
306  'e' => $e,
307  'tplRow' => $this->templateRow,
308  'numberOfRows' => $numberOfRows
309  ];
310  foreach ($postOutputProcessingHook as $hookFunction) {
311  GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
312  }
313  }
314  }
315  } else {
316  $theOutput = $this->pObj->noTemplate(1);
317  }
318  return $theOutput;
319  }
320 }
static callUserFunction($funcName, &$params, &$ref, $_='', $errorMode=0)
static getFileAbsFileName($filename, $_=null, $_2=null)
static makeInstance($className,... $constructorArguments)
static getFuncCheck( $mainParams, $elementName, $currentValue, $script='', $addParams='', $tagParams='')
static redirect($url, $httpStatus=self::HTTP_STATUS_303)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']