‪TYPO3CMS  10.4
TemplateAnalyzerModuleFunctionController.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\Http\Message\ServerRequestInterface;
26 
32 {
33 
37  protected ‪$pObj;
38 
42  protected ‪$localLanguageFilePath;
43 
48  protected ‪$templateRow;
49 
53  protected ‪$templateService;
54 
58  protected ‪$id;
59 
63  protected ‪$request;
64 
71  public function ‪init(‪$pObj, ServerRequestInterface ‪$request)
72  {
73  $this->pObj = ‪$pObj;
74  $this->request = ‪$request;
75 
76  // Setting MOD_MENU items as we need them for logging:
77  $this->pObj->MOD_MENU = array_merge($this->pObj->MOD_MENU, $this->modMenu());
78  $this->localLanguageFilePath = 'EXT:tstemplate/Resources/Private/Language/locallang_analyzer.xlf';
79  $this->pObj->modMenu_setDefaultList .= ',ts_analyzer_checkLinenum,ts_analyzer_checkSyntax';
80  $this->id = (int)(‪$request->getParsedBody()['id'] ?? ‪$request->getQueryParams()['id'] ?? 0);
81  }
82 
88  protected function ‪modMenu()
89  {
90  return [
91  'ts_analyzer_checkSetup' => '1',
92  'ts_analyzer_checkConst' => '1',
93  'ts_analyzer_checkLinenum' => '1',
94  'ts_analyzer_checkComments' => '1',
95  'ts_analyzer_checkCrop' => '1',
96  'ts_analyzer_checkSyntax' => '1'
97  ];
98  }
99 
107  protected function ‪initialize_editor($pageId, $templateUid = 0)
108  {
109  // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
110  $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
111 
112  // Gets the rootLine
113  $rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $pageId);
114  $rootLine = $rootlineUtility->get();
115 
116  // This generates the constants/config + hierarchy info for the template.
117  $this->templateService->runThroughTemplates($rootLine, $templateUid);
118 
119  // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
120  $this->templateRow = $this->templateService->ext_getFirstTemplate($pageId, $templateUid);
121  return is_array($this->templateRow);
122  }
123 
129  public function ‪main()
130  {
131  // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
132  // Checking for more than one template an if, set a menu...
133 
134  $assigns = [];
135  $template_uid = 0;
136  $assigns['manyTemplatesMenu'] = $this->pObj->templateMenu($this->request);
137  $assigns['LLPrefix'] = 'LLL:' . $this->localLanguageFilePath . ':';
138  if ($assigns['manyTemplatesMenu']) {
139  $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
140  }
141 
142  $assigns['existTemplate'] = $this->‪initialize_editor($this->id, $template_uid);
143  if ($assigns['existTemplate']) {
144  $assigns['siteTitle'] = trim($this->templateRow['sitetitle']);
145  $assigns['templateRecord'] = ‪$this->templateRow;
146  $assigns['linkWrappedTemplateTitle'] = $this->pObj->linkWrapTemplateTitle($this->templateRow['title']);
147  }
148 
149  $this->templateService->clearList_const_temp = array_flip($this->templateService->clearList_const);
150  $this->templateService->clearList_setup_temp = array_flip($this->templateService->clearList_setup);
151  $pointer = count($this->templateService->hierarchyInfo);
152  $hierarchyInfo = $this->templateService->ext_process_hierarchyInfo([], $pointer);
153  $assigns['hierarchy'] = implode('', array_reverse($this->templateService->ext_getTemplateHierarchyArr(
154  $hierarchyInfo,
155  '',
156  [],
157  1
158  )));
159 
160  $urlParameters = [
161  'id' => ‪$this->id,
162  'template' => 'all'
163  ];
165  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
166  $assigns['moduleLink'] = (string)$uriBuilder->buildUriFromRoute('web_ts', $urlParameters);
167 
168  $assigns['template'] = $template = ($this->request->getQueryParams()['template'] ?? null);
169  $addParams = $template ? '&template=' . $template : '';
170  $assigns['checkboxes'] = [
171  'ts_analyzer_checkLinenum' => [
172  'id' => 'checkTs_analyzer_checkLinenum',
173  'll' => 'lineNumbers'
174  ],
175  'ts_analyzer_checkSyntax' => [
176  'id' => 'checkTs_analyzer_checkSyntax',
177  'll' => 'syntaxHighlight'
178  ]
179  ];
180 
181  if (!$this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax']) {
182  $assigns['checkboxes']['ts_analyzer_checkComments'] = [
183  'id' => 'checkTs_analyzer_checkComments',
184  'll' => 'comments'
185  ];
186  $assigns['checkboxes']['ts_analyzer_checkCrop'] = [
187  'id' => 'checkTs_analyzer_checkCrop',
188  'll' => 'cropLines'
189  ];
190  }
191 
192  foreach ($assigns['checkboxes'] as $key => $conf) {
193  $assigns['checkboxes'][$key]['label'] = ‪BackendUtility::getFuncCheck(
194  $this->id,
195  'SET[' . $key . ']',
196  $this->pObj->MOD_SETTINGS[$key],
197  '',
198  $addParams,
199  'id="' . $conf['id'] . '"'
200  );
201  }
202 
203  if ($template) {
204  $this->templateService->ext_lineNumberOffset = 0;
205  $this->templateService->ext_lineNumberOffset_mode = 'const';
206  $assigns['constants'] = [];
207  foreach ($this->templateService->constants as $key => $val) {
208  $currentTemplateId = $this->templateService->hierarchyInfo[$key]['templateID'];
209  if ($currentTemplateId == $template || $template === 'all') {
210  $assigns['constants'][] = [
211  'title' => $this->templateService->hierarchyInfo[$key]['title'],
212  'content' => $this->templateService->ext_outputTS(
213  [$val],
214  $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'],
215  $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'],
216  $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'],
217  $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'],
218  0
219  )
220  ];
221  if ($template !== 'all') {
222  break;
223  }
224  }
225  $this->templateService->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
226  }
227 
228  // Output Setup
229  $this->templateService->ext_lineNumberOffset = 0;
230  $this->templateService->ext_lineNumberOffset_mode = 'setup';
231  $assigns['setups'] = [];
232  foreach ($this->templateService->config as $key => $val) {
233  $currentTemplateId = $this->templateService->hierarchyInfo[$key]['templateID'];
234  if ($currentTemplateId == $template || $template === 'all') {
235  $assigns['setups'][] = [
236  'title' => $this->templateService->hierarchyInfo[$key]['title'],
237  'content' => $this->templateService->ext_outputTS(
238  [$val],
239  $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'],
240  $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'],
241  $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'],
242  $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'],
243  0
244  )
245  ];
246  if ($template !== 'all') {
247  break;
248  }
249  }
250  $this->templateService->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
251  }
252  }
253 
254  $view = GeneralUtility::makeInstance(StandaloneView::class);
255  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
256  'EXT:tstemplate/Resources/Private/Templates/TemplateAnalyzerModuleFunction.html'
257  ));
258  $view->assignMultiple($assigns);
259 
260  return $view->render();
261  }
262 
266  protected function ‪getLanguageService(): ‪LanguageService
267  {
268  return ‪$GLOBALS['LANG'];
269  }
270 }
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\initialize_editor
‪bool initialize_editor($pageId, $templateUid=0)
Definition: TemplateAnalyzerModuleFunctionController.php:102
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\$id
‪$id
Definition: TemplateAnalyzerModuleFunctionController.php:54
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\modMenu
‪array modMenu()
Definition: TemplateAnalyzerModuleFunctionController.php:83
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\main
‪string main()
Definition: TemplateAnalyzerModuleFunctionController.php:124
‪TYPO3\CMS\Core\Utility\RootlineUtility
Definition: RootlineUtility.php:39
‪TYPO3\CMS\Tstemplate\Controller
Definition: TemplateAnalyzerModuleFunctionController.php:16
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\$localLanguageFilePath
‪string $localLanguageFilePath
Definition: TemplateAnalyzerModuleFunctionController.php:40
‪TYPO3\CMS\Core\TypoScript\ExtendedTemplateService
Definition: ExtendedTemplateService.php:43
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\$templateService
‪ExtendedTemplateService $templateService
Definition: TemplateAnalyzerModuleFunctionController.php:49
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\getLanguageService
‪LanguageService getLanguageService()
Definition: TemplateAnalyzerModuleFunctionController.php:261
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController
Definition: TemplateAnalyzerModuleFunctionController.php:32
‪TYPO3\CMS\Backend\Utility\BackendUtility\getFuncCheck
‪static string getFuncCheck( $mainParams, $elementName, $currentValue, $script='', $addParams='', $tagParams='')
Definition: BackendUtility.php:2709
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateModuleController
Definition: TypoScriptTemplateModuleController.php:48
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\$request
‪ServerRequestInterface $request
Definition: TemplateAnalyzerModuleFunctionController.php:58
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\init
‪init($pObj, ServerRequestInterface $request)
Definition: TemplateAnalyzerModuleFunctionController.php:66
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\$templateRow
‪array $templateRow
Definition: TemplateAnalyzerModuleFunctionController.php:45
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\$pObj
‪TypoScriptTemplateModuleController $pObj
Definition: TemplateAnalyzerModuleFunctionController.php:36