[!!!][TASK] Remove deprecated code from EXT:tstemplate
[Packages/TYPO3.CMS.git] / typo3 / sysext / tstemplate / Classes / Controller / TemplateAnalyzerModuleFunctionController.php
1 <?php
2 namespace TYPO3\CMS\Tstemplate\Controller;
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
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Localization\LanguageService;
19 use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Core\Utility\RootlineUtility;
22 use TYPO3\CMS\Fluid\View\StandaloneView;
23
24 /**
25 * TypoScript template analyzer
26 * @internal This is a specific Backend Controller implementation and is not considered part of the Public TYPO3 API.
27 */
28 class TemplateAnalyzerModuleFunctionController
29 {
30
31 /**
32 * @var TypoScriptTemplateModuleController
33 */
34 protected $pObj;
35
36 /**
37 * @var string
38 */
39 protected $localLanguageFilePath;
40
41 /**
42 * The currently selected sys_template record
43 * @var array
44 */
45 protected $templateRow;
46
47 /**
48 * @var ExtendedTemplateService
49 */
50 protected $templateService;
51
52 /**
53 * @var int GET/POST var 'id'
54 */
55 protected $id;
56
57 /**
58 * Init, called from parent object
59 *
60 * @param TypoScriptTemplateModuleController $pObj
61 */
62 public function init($pObj)
63 {
64 $this->pObj = $pObj;
65
66 // Setting MOD_MENU items as we need them for logging:
67 $this->pObj->MOD_MENU = array_merge($this->pObj->MOD_MENU, $this->modMenu());
68 $this->localLanguageFilePath = 'EXT:tstemplate/Resources/Private/Language/locallang_analyzer.xlf';
69 $this->pObj->modMenu_setDefaultList .= ',ts_analyzer_checkLinenum,ts_analyzer_checkSyntax';
70 $this->id = (int)GeneralUtility::_GP('id');
71 }
72
73 /**
74 * Mod menu
75 *
76 * @return array
77 */
78 protected function modMenu()
79 {
80 return [
81 'ts_analyzer_checkSetup' => '1',
82 'ts_analyzer_checkConst' => '1',
83 'ts_analyzer_checkLinenum' => '1',
84 'ts_analyzer_checkComments' => '1',
85 'ts_analyzer_checkCrop' => '1',
86 'ts_analyzer_checkSyntax' => '1'
87 ];
88 }
89
90 /**
91 * Initialize editor
92 *
93 * @param int $pageId
94 * @param int $templateUid
95 * @return bool
96 */
97 protected function initialize_editor($pageId, $templateUid = 0)
98 {
99 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
100 $this->templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
101
102 // Gets the rootLine
103 $rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $pageId);
104 $rootLine = $rootlineUtility->get();
105
106 // This generates the constants/config + hierarchy info for the template.
107 $this->templateService->runThroughTemplates($rootLine, $templateUid);
108
109 // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
110 $this->templateRow = $this->templateService->ext_getFirstTemplate($pageId, $templateUid);
111 return is_array($this->templateRow);
112 }
113
114 /**
115 * Main, called from parent object
116 *
117 * @return string
118 */
119 public function main()
120 {
121 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
122 // Checking for more than one template an if, set a menu...
123
124 $assigns = [];
125 $template_uid = 0;
126 $assigns['manyTemplatesMenu'] = $this->pObj->templateMenu();
127 $assigns['LLPrefix'] = 'LLL:' . $this->localLanguageFilePath . ':';
128 if ($assigns['manyTemplatesMenu']) {
129 $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
130 }
131
132 $assigns['existTemplate'] = $this->initialize_editor($this->id, $template_uid);
133 if ($assigns['existTemplate']) {
134 $assigns['siteTitle'] = trim($this->templateRow['sitetitle']);
135 $assigns['templateRecord'] = $this->templateRow;
136 $assigns['linkWrappedTemplateTitle'] = $this->pObj->linkWrapTemplateTitle($this->templateRow['title']);
137 }
138
139 $this->templateService->clearList_const_temp = array_flip($this->templateService->clearList_const);
140 $this->templateService->clearList_setup_temp = array_flip($this->templateService->clearList_setup);
141 $pointer = count($this->templateService->hierarchyInfo);
142 $hierarchyInfo = $this->templateService->ext_process_hierarchyInfo([], $pointer);
143 $assigns['hierarchy'] = implode(array_reverse($this->templateService->ext_getTemplateHierarchyArr(
144 $hierarchyInfo,
145 '',
146 [],
147 1
148 )), '');
149
150 $urlParameters = [
151 'id' => $this->id,
152 'template' => 'all'
153 ];
154 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
155 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
156 $assigns['moduleLink'] = (string)$uriBuilder->buildUriFromRoute('web_ts', $urlParameters);
157
158 $assigns['template'] = $template = GeneralUtility::_GET('template');
159 $addParams = $template ? '&template=' . $template : '';
160 $assigns['checkboxes'] = [
161 'ts_analyzer_checkLinenum' => [
162 'id' => 'checkTs_analyzer_checkLinenum',
163 'll' => 'lineNumbers'
164 ],
165 'ts_analyzer_checkSyntax' => [
166 'id' => 'checkTs_analyzer_checkSyntax',
167 'll' => 'syntaxHighlight'
168 ]
169 ];
170
171 if (!$this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax']) {
172 $assigns['checkboxes']['ts_analyzer_checkComments'] = [
173 'id' => 'checkTs_analyzer_checkComments',
174 'll' => 'comments'
175 ];
176 $assigns['checkboxes']['ts_analyzer_checkCrop'] = [
177 'id' => 'checkTs_analyzer_checkCrop',
178 'll' => 'cropLines'
179 ];
180 }
181
182 foreach ($assigns['checkboxes'] as $key => $conf) {
183 $assigns['checkboxes'][$key]['label'] = BackendUtility::getFuncCheck(
184 $this->id,
185 'SET[' . $key . ']',
186 $this->pObj->MOD_SETTINGS[$key],
187 '',
188 $addParams,
189 'id="' . $conf['id'] . '"'
190 );
191 }
192
193 if ($template) {
194 $this->templateService->ext_lineNumberOffset = 0;
195 $this->templateService->ext_lineNumberOffset_mode = 'const';
196 $assigns['constants'] = [];
197 foreach ($this->templateService->constants as $key => $val) {
198 $currentTemplateId = $this->templateService->hierarchyInfo[$key]['templateID'];
199 if ($currentTemplateId == $template || $template === 'all') {
200 $assigns['constants'][] = [
201 'title' => $this->templateService->hierarchyInfo[$key]['title'],
202 'content' => $this->templateService->ext_outputTS(
203 [$val],
204 $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'],
205 $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'],
206 $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'],
207 $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'],
208 0
209 )
210 ];
211 if ($template !== 'all') {
212 break;
213 }
214 }
215 $this->templateService->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
216 }
217
218 // Output Setup
219 $this->templateService->ext_lineNumberOffset = 0;
220 $this->templateService->ext_lineNumberOffset_mode = 'setup';
221 $assigns['setups'] = [];
222 foreach ($this->templateService->config as $key => $val) {
223 $currentTemplateId = $this->templateService->hierarchyInfo[$key]['templateID'];
224 if ($currentTemplateId == $template || $template === 'all') {
225 $assigns['setups'][] = [
226 'title' => $this->templateService->hierarchyInfo[$key]['title'],
227 'content' => $this->templateService->ext_outputTS(
228 [$val],
229 $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'],
230 $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'],
231 $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'],
232 $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'],
233 0
234 )
235 ];
236 if ($template !== 'all') {
237 break;
238 }
239 }
240 $this->templateService->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
241 }
242 }
243
244 $view = GeneralUtility::makeInstance(StandaloneView::class);
245 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
246 'EXT:tstemplate/Resources/Private/Templates/TemplateAnalyzerModuleFunction.html'
247 ));
248 $view->assignMultiple($assigns);
249
250 return $view->render();
251 }
252
253 /**
254 * @return LanguageService
255 */
256 protected function getLanguageService(): LanguageService
257 {
258 return $GLOBALS['LANG'];
259 }
260 }