‪TYPO3CMS  9.5
TemplateAnalyzerModuleFunctionController.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 
25 
31 {
34 
39  'pObj' => 'Using TemplateAnalyzerModuleFunctionController::$pObj is deprecated and will not be possible anymore in TYPO3 v10.0.',
40  'function_key' => 'Using TemplateAnalyzerModuleFunctionController::$function_key is deprecated, property will be removed in TYPO3 v10.0.',
41  'extClassConf' => 'Using TemplateAnalyzerModuleFunctionController::$extClassConf is deprecated, property will be removed in TYPO3 v10.0.',
42  'localLangFile' => 'Using TemplateAnalyzerModuleFunctionController::$localLangFile is deprecated, property will be removed in TYPO3 v10.0.',
43  ];
44 
48  private ‪$deprecatedPublicMethods = [
49  'initialize_editor' => 'Using TemplateAnalyzerModuleFunctionController::initialize_editor() is deprecated and will not be possible anymore in TYPO3 v10.0.',
50  'modMenu' => 'Using TemplateAnalyzerModuleFunctionController::modMenu() is deprecated and will not be possible anymore in TYPO3 v10.0.',
51  'handleExternalFunctionValue' => 'Using TemplateAnalyzerModuleFunctionController::handleExternalFunctionValue() is deprecated, method will be removed in TYPO3 v10.0.',
52  ];
53 
57  protected ‪$pObj;
58 
62  protected ‪$localLanguageFilePath;
63 
68  protected ‪$templateRow;
69 
73  protected ‪$templateService;
74 
78  protected ‪$id;
79 
88  protected ‪$localLangFile = '';
89 
97  protected ‪$extClassConf;
98 
107  protected ‪$function_key = '';
108 
114  public function ‪init(‪$pObj)
115  {
116  $this->pObj = ‪$pObj;
117  // Local lang:
118  if (!empty($this->localLangFile)) {
119  // @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0.
120  $this->‪getLanguageService()->‪includeLLFile($this->localLangFile);
121  }
122  // Setting MOD_MENU items as we need them for logging:
123  $this->pObj->MOD_MENU = array_merge($this->pObj->MOD_MENU, $this->modMenu());
124  $this->localLanguageFilePath = 'EXT:tstemplate/Resources/Private/Language/locallang_analyzer.xlf';
125  $this->pObj->modMenu_setDefaultList .= ',ts_analyzer_checkLinenum,ts_analyzer_checkSyntax';
126  $this->id = (int)GeneralUtility::_GP('id');
127  }
128 
134  protected function ‪modMenu()
135  {
136  return [
137  'ts_analyzer_checkSetup' => '1',
138  'ts_analyzer_checkConst' => '1',
139  'ts_analyzer_checkLinenum' => '1',
140  'ts_analyzer_checkComments' => '1',
141  'ts_analyzer_checkCrop' => '1',
142  'ts_analyzer_checkSyntax' => '1'
143  ];
144  }
145 
153  protected function ‪initialize_editor($pageId, $templateUid = 0)
154  {
155  // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
156  $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
157 
158  // Gets the rootLine
159  $rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $pageId);
160  $rootLine = $rootlineUtility->get();
161 
162  // This generates the constants/config + hierarchy info for the template.
163  $this->templateService->runThroughTemplates($rootLine, $templateUid);
164 
165  // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
166  $this->templateRow = $this->templateService->ext_getFirstTemplate($pageId, $templateUid);
167  return is_array($this->templateRow);
168  }
169 
175  public function ‪main()
176  {
177  // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
178  // Checking for more than one template an if, set a menu...
179 
180  $assigns = [];
181  $template_uid = 0;
182  $assigns['manyTemplatesMenu'] = $this->pObj->templateMenu();
183  $assigns['LLPrefix'] = 'LLL:' . $this->localLanguageFilePath . ':';
184  if ($assigns['manyTemplatesMenu']) {
185  $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
186  }
187 
188  $assigns['existTemplate'] = $this->‪initialize_editor($this->id, $template_uid);
189  if ($assigns['existTemplate']) {
190  $assigns['siteTitle'] = trim($this->templateRow['sitetitle']);
191  $assigns['templateRecord'] = ‪$this->templateRow;
192  $assigns['linkWrappedTemplateTitle'] = $this->pObj->linkWrapTemplateTitle($this->templateRow['title']);
193  }
194 
195  $this->templateService->clearList_const_temp = array_flip($this->templateService->clearList_const);
196  $this->templateService->clearList_setup_temp = array_flip($this->templateService->clearList_setup);
197  $pointer = count($this->templateService->hierarchyInfo);
198  $hierarchyInfo = $this->templateService->ext_process_hierarchyInfo([], $pointer);
199  $assigns['hierarchy'] = implode('', array_reverse($this->templateService->ext_getTemplateHierarchyArr(
200  $hierarchyInfo,
201  '',
202  [],
203  1
204  )));
205 
206  $urlParameters = [
207  'id' => ‪$this->id,
208  'template' => 'all'
209  ];
211  $uriBuilder = GeneralUtility::makeInstance(\‪TYPO3\CMS\Backend\Routing\UriBuilder::class);
212  $assigns['moduleLink'] = (string)$uriBuilder->buildUriFromRoute('web_ts', $urlParameters);
213 
214  $assigns['template'] = $template = GeneralUtility::_GET('template');
215  $addParams = $template ? '&template=' . $template : '';
216  $assigns['checkboxes'] = [
217  'ts_analyzer_checkLinenum' => [
218  'id' => 'checkTs_analyzer_checkLinenum',
219  'll' => 'lineNumbers'
220  ],
221  'ts_analyzer_checkSyntax' => [
222  'id' => 'checkTs_analyzer_checkSyntax',
223  'll' => 'syntaxHighlight'
224  ]
225  ];
226 
227  if (!$this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax']) {
228  $assigns['checkboxes']['ts_analyzer_checkComments'] = [
229  'id' => 'checkTs_analyzer_checkComments',
230  'll' => 'comments'
231  ];
232  $assigns['checkboxes']['ts_analyzer_checkCrop'] = [
233  'id' => 'checkTs_analyzer_checkCrop',
234  'll' => 'cropLines'
235  ];
236  }
237 
238  foreach ($assigns['checkboxes'] as $key => $conf) {
239  $assigns['checkboxes'][$key]['label'] = ‪BackendUtility::getFuncCheck(
240  $this->id,
241  'SET[' . $key . ']',
242  $this->pObj->MOD_SETTINGS[$key],
243  '',
244  $addParams,
245  'id="' . $conf['id'] . '"'
246  );
247  }
248 
249  if ($template) {
250  $this->templateService->ext_lineNumberOffset = 0;
251  $this->templateService->ext_lineNumberOffset_mode = 'const';
252  $assigns['constants'] = [];
253  foreach ($this->templateService->constants as $key => $val) {
254  $currentTemplateId = $this->templateService->hierarchyInfo[$key]['templateID'];
255  if ($currentTemplateId == $template || $template === 'all') {
256  $assigns['constants'][] = [
257  'title' => $this->templateService->hierarchyInfo[$key]['title'],
258  'content' => $this->templateService->ext_outputTS(
259  [$val],
260  $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'],
261  $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'],
262  $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'],
263  $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'],
264  0
265  )
266  ];
267  if ($template !== 'all') {
268  break;
269  }
270  }
271  $this->templateService->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
272  }
273 
274  // Output Setup
275  $this->templateService->ext_lineNumberOffset = 0;
276  $this->templateService->ext_lineNumberOffset_mode = 'setup';
277  $assigns['setups'] = [];
278  foreach ($this->templateService->config as $key => $val) {
279  $currentTemplateId = $this->templateService->hierarchyInfo[$key]['templateID'];
280  if ($currentTemplateId == $template || $template === 'all') {
281  $assigns['setups'][] = [
282  'title' => $this->templateService->hierarchyInfo[$key]['title'],
283  'content' => $this->templateService->ext_outputTS(
284  [$val],
285  $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'],
286  $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'],
287  $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'],
288  $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'],
289  0
290  )
291  ];
292  if ($template !== 'all') {
293  break;
294  }
295  }
296  $this->templateService->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
297  }
298  }
299 
300  $view = GeneralUtility::makeInstance(StandaloneView::class);
301  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
302  'EXT:tstemplate/Resources/Private/Templates/TemplateAnalyzerModuleFunction.html'
303  ));
304  $view->assignMultiple($assigns);
305 
306  return $view->render();
307  }
308 
315  protected function ‪handleExternalFunctionValue()
316  {
317  // Must clean first to make sure the correct key is set...
318  $this->pObj->MOD_SETTINGS = ‪BackendUtility::getModuleData($this->pObj->MOD_MENU, GeneralUtility::_GP('SET'), 'web_ts');
319  if ($this->function_key) {
320  $this->extClassConf = $this->pObj->getExternalItemConfig('web_ts', $this->function_key, $this->pObj->MOD_SETTINGS[$this->function_key]);
321  }
322  }
323 
327  protected function ‪getLanguageService(): ‪LanguageService
328  {
329  return ‪$GLOBALS['LANG'];
330  }
331 }
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\handleExternalFunctionValue
‪handleExternalFunctionValue()
Definition: TemplateAnalyzerModuleFunctionController.php:304
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\initialize_editor
‪bool initialize_editor($pageId, $templateUid=0)
Definition: TemplateAnalyzerModuleFunctionController.php:142
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪mixed includeLLFile($fileRef, $setGlobal=true, $mergeLocalOntoDefault=false)
Definition: LanguageService.php:260
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\$id
‪$id
Definition: TemplateAnalyzerModuleFunctionController.php:70
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\modMenu
‪array modMenu()
Definition: TemplateAnalyzerModuleFunctionController.php:123
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\init
‪init($pObj)
Definition: TemplateAnalyzerModuleFunctionController.php:103
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\$localLangFile
‪string $localLangFile
Definition: TemplateAnalyzerModuleFunctionController.php:79
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\$deprecatedPublicMethods
‪array $deprecatedPublicMethods
Definition: TemplateAnalyzerModuleFunctionController.php:44
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\main
‪string main()
Definition: TemplateAnalyzerModuleFunctionController.php:164
‪TYPO3
‪TYPO3\CMS\Core\Utility\RootlineUtility
Definition: RootlineUtility.php:36
‪TYPO3\CMS\Tstemplate\Controller
Definition: TemplateAnalyzerModuleFunctionController.php:2
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\$deprecatedPublicProperties
‪array $deprecatedPublicProperties
Definition: TemplateAnalyzerModuleFunctionController.php:35
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\$localLanguageFilePath
‪string $localLanguageFilePath
Definition: TemplateAnalyzerModuleFunctionController.php:56
‪TYPO3\CMS\Core\TypoScript\ExtendedTemplateService
Definition: ExtendedTemplateService.php:39
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\$extClassConf
‪array $extClassConf
Definition: TemplateAnalyzerModuleFunctionController.php:87
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\$templateService
‪ExtendedTemplateService $templateService
Definition: TemplateAnalyzerModuleFunctionController.php:65
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\getLanguageService
‪LanguageService getLanguageService()
Definition: TemplateAnalyzerModuleFunctionController.php:316
‪TYPO3\CMS\Backend\Utility\BackendUtility\getModuleData
‪static array getModuleData( $MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='')
Definition: BackendUtility.php:3259
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController
Definition: TemplateAnalyzerModuleFunctionController.php:31
‪TYPO3\CMS\Backend\Utility\BackendUtility\getFuncCheck
‪static string getFuncCheck( $mainParams, $elementName, $currentValue, $script='', $addParams='', $tagParams='')
Definition: BackendUtility.php:3054
‪TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateModuleController
Definition: TypoScriptTemplateModuleController.php:50
‪TYPO3\CMS\Core\Compatibility\PublicMethodDeprecationTrait
Definition: PublicMethodDeprecationTrait.php:68
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\$function_key
‪string $function_key
Definition: TemplateAnalyzerModuleFunctionController.php:96
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait
Definition: PublicPropertyDeprecationTrait.php:66
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\$templateRow
‪array $templateRow
Definition: TemplateAnalyzerModuleFunctionController.php:61
‪TYPO3\CMS\Tstemplate\Controller\TemplateAnalyzerModuleFunctionController\$pObj
‪TypoScriptTemplateModuleController $pObj
Definition: TemplateAnalyzerModuleFunctionController.php:52