TYPO3 CMS  TYPO3_8-7
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 
23 
28 {
32  public $pObj;
33 
38 
43  protected $templateRow;
44 
48  protected $templateService;
49 
56  public function init(&$pObj, $conf)
57  {
58  parent::init($pObj, $conf);
59  $this->localLanguageFilePath = 'EXT:tstemplate/Resources/Private/Language/locallang_analyzer.xlf';
60  $this->pObj->modMenu_setDefaultList .= ',ts_analyzer_checkLinenum,ts_analyzer_checkSyntax';
61  }
62 
68  public function modMenu()
69  {
70  return [
71  'ts_analyzer_checkSetup' => '1',
72  'ts_analyzer_checkConst' => '1',
73  'ts_analyzer_checkLinenum' => '1',
74  'ts_analyzer_checkComments' => '1',
75  'ts_analyzer_checkCrop' => '1',
76  'ts_analyzer_checkSyntax' => '1'
77  ];
78  }
79 
87  public function initialize_editor($pageId, $templateUid = 0)
88  {
89  // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
90  $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
91  $this->templateService->init();
92 
93  // Gets the rootLine
94  $rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $pageId);
95  $rootLine = $rootlineUtility->get();
96 
97  // This generates the constants/config + hierarchy info for the template.
98  $this->templateService->runThroughTemplates($rootLine, $templateUid);
99 
100  // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
101  $this->templateRow = $this->templateService->ext_getFirstTemplate($pageId, $templateUid);
102  return is_array($this->templateRow);
103  }
104 
110  public function main()
111  {
112  // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
113  // Checking for more than one template an if, set a menu...
114 
115  $assigns = [];
116  $template_uid = 0;
117  $assigns['manyTemplatesMenu'] = $this->pObj->templateMenu();
118  $assigns['LLPrefix'] = 'LLL:' . $this->localLanguageFilePath . ':';
119  if ($assigns['manyTemplatesMenu']) {
120  $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
121  }
122 
123  $assigns['existTemplate'] = $this->initialize_editor($this->pObj->id, $template_uid);
124  if ($assigns['existTemplate']) {
125  $assigns['siteTitle'] = trim($this->templateRow['sitetitle']);
126  $assigns['templateRecord'] = $this->templateRow;
127  $assigns['linkWrappedTemplateTitle'] = $this->pObj->linkWrapTemplateTitle($this->templateRow['title']);
128  }
129 
130  $this->templateService->clearList_const_temp = array_flip($this->templateService->clearList_const);
131  $this->templateService->clearList_setup_temp = array_flip($this->templateService->clearList_setup);
132  $pointer = count($this->templateService->hierarchyInfo);
133  $hierarchyInfo = $this->templateService->ext_process_hierarchyInfo([], $pointer);
134  $assigns['hierarchy'] = implode('', array_reverse($this->templateService->ext_getTemplateHierarchyArr(
135  $hierarchyInfo,
136  '',
137  [],
138  1
139  )));
140 
141  $urlParameters = [
142  'id' => $this->pObj->id,
143  'template' => 'all'
144  ];
145  $assigns['moduleLink'] = BackendUtility::getModuleUrl('web_ts', $urlParameters);
146 
147  $assigns['template'] = $template = GeneralUtility::_GET('template');
148  $addParams = $template ? '&template=' . $template : '';
149  $assigns['checkboxes'] = [
150  'ts_analyzer_checkLinenum' => [
151  'id' => 'checkTs_analyzer_checkLinenum',
152  'll' => 'lineNumbers'
153  ],
154  'ts_analyzer_checkSyntax' => [
155  'id' => 'checkTs_analyzer_checkSyntax',
156  'll' => 'syntaxHighlight'
157  ]
158  ];
159 
160  if (!$this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax']) {
161  $assigns['checkboxes']['ts_analyzer_checkComments'] = [
162  'id' => 'checkTs_analyzer_checkComments',
163  'll' => 'comments'
164  ];
165  $assigns['checkboxes']['ts_analyzer_checkCrop'] = [
166  'id' => 'checkTs_analyzer_checkCrop',
167  'll' => 'cropLines'
168  ];
169  }
170 
171  foreach ($assigns['checkboxes'] as $key => $conf) {
172  $assigns['checkboxes'][$key]['label'] = BackendUtility::getFuncCheck(
173  $this->pObj->id,
174  'SET[' . $key . ']',
175  $this->pObj->MOD_SETTINGS[$key],
176  '',
177  $addParams,
178  'id="' . $conf['id'] . '"'
179  );
180  }
181 
182  if ($template) {
183  $this->templateService->ext_lineNumberOffset = 0;
184  $this->templateService->ext_lineNumberOffset_mode = 'const';
185  $assigns['constants'] = [];
186  foreach ($this->templateService->constants as $key => $val) {
187  $currentTemplateId = $this->templateService->hierarchyInfo[$key]['templateID'];
188  if ($currentTemplateId == $template || $template === 'all') {
189  $assigns['constants'][] = [
190  'title' => $this->templateService->hierarchyInfo[$key]['title'],
191  'content' => $this->templateService->ext_outputTS(
192  [$val],
193  $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'],
194  $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'],
195  $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'],
196  $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'],
197  0
198  )
199  ];
200  if ($template !== 'all') {
201  break;
202  }
203  }
204  $this->templateService->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
205  }
206 
207  // Output Setup
208  $this->templateService->ext_lineNumberOffset = 0;
209  $this->templateService->ext_lineNumberOffset_mode = 'setup';
210  $assigns['setups'] = [];
211  foreach ($this->templateService->config as $key => $val) {
212  $currentTemplateId = $this->templateService->hierarchyInfo[$key]['templateID'];
213  if ($currentTemplateId == $template || $template === 'all') {
214  $assigns['setups'][] = [
215  'title' => $this->templateService->hierarchyInfo[$key]['title'],
216  'content' => $this->templateService->ext_outputTS(
217  [$val],
218  $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'],
219  $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'],
220  $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'],
221  $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'],
222  0
223  )
224  ];
225  if ($template !== 'all') {
226  break;
227  }
228  }
229  $this->templateService->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
230  }
231  }
232 
233  $view = GeneralUtility::makeInstance(StandaloneView::class);
234  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
235  'EXT:tstemplate/Resources/Private/Templates/TemplateAnalyzerModuleFunction.html'
236  ));
237  $view->assignMultiple($assigns);
238 
239  return $view->render();
240  }
241 }
static getFileAbsFileName($filename, $_=null, $_2=null)
static makeInstance($className,... $constructorArguments)
static getFuncCheck( $mainParams, $elementName, $currentValue, $script='', $addParams='', $tagParams='')