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