TYPO3 CMS  TYPO3_7-6
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 
24 
29 {
33  public $pObj;
34 
42  public function init(&$pObj, $conf)
43  {
44  parent::init($pObj, $conf);
45  $this->getLanguageService()->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_analyzer.xlf');
46  $this->pObj->modMenu_setDefaultList .= ',ts_analyzer_checkLinenum,ts_analyzer_checkSyntax';
47  }
48 
54  public function modMenu()
55  {
56  return [
57  'ts_analyzer_checkSetup' => '1',
58  'ts_analyzer_checkConst' => '1',
59  'ts_analyzer_checkLinenum' => '1',
60  'ts_analyzer_checkComments' => '1',
61  'ts_analyzer_checkCrop' => '1',
62  'ts_analyzer_checkSyntax' => '1'
63  ];
64  }
65 
73  public function initialize_editor($pageId, $template_uid = 0)
74  {
75  // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
76  $templateService = GeneralUtility::makeInstance(ExtendedTemplateService::class);
77  $GLOBALS['tmpl'] = $templateService;
78 
79  // Do not log time-performance information
80  $templateService->tt_track = false;
81  $templateService->init();
82 
83  // Gets the rootLine
84  $sys_page = GeneralUtility::makeInstance(PageRepository::class);
85  $GLOBALS['rootLine'] = $sys_page->getRootLine($pageId);
86 
87  // This generates the constants/config + hierarchy info for the template.
88  $templateService->runThroughTemplates($GLOBALS['rootLine'], $template_uid);
89 
90  // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
91  $GLOBALS['tplRow'] = $templateService->ext_getFirstTemplate($pageId, $template_uid);
92  return is_array($GLOBALS['tplRow']);
93  }
94 
100  public function main()
101  {
102  $theOutput = '';
103 
104  // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
105  // Checking for more than one template an if, set a menu...
106  $manyTemplatesMenu = $this->pObj->templateMenu();
107  $template_uid = 0;
108  if ($manyTemplatesMenu) {
109  $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
110  }
111 
112  $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
113 
114  // initialize
115  $lang = $this->getLanguageService();
116  if ($existTemplate) {
117  $siteTitle = trim($GLOBALS['tplRow']['sitetitle']);
118  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
119  $theOutput .= '<h3>' . $lang->getLL('currentTemplate', true) . '</h3>';
120  $theOutput .= $iconFactory->getIconForRecord('sys_template', $GLOBALS['tplRow'], Icon::SIZE_SMALL)->render()
121  . '<strong>' . $this->pObj->linkWrapTemplateTitle($GLOBALS['tplRow']['title']) . '</strong>'
122  . htmlspecialchars($siteTitle ? ' (' . $siteTitle . ')' : '');
123  }
124  if ($manyTemplatesMenu) {
125  $theOutput .= '<div>' . $manyTemplatesMenu . '</div>';
126  }
127  $templateService = $this->getExtendedTemplateService();
128  $templateService->clearList_const_temp = array_flip($templateService->clearList_const);
129  $templateService->clearList_setup_temp = array_flip($templateService->clearList_setup);
130  $pointer = count($templateService->hierarchyInfo);
131  $hierarchyInfo = $templateService->ext_process_hierarchyInfo([], $pointer);
132  $head = '<thead><tr>';
133  $head .= '<th>' . $lang->getLL('title', true) . '</th>';
134  $head .= '<th>' . $lang->getLL('rootlevel', true) . '</th>';
135  $head .= '<th>' . $lang->getLL('clearSetup', true) . '</th>';
136  $head .= '<th>' . $lang->getLL('clearConstants', true) . '</th>';
137  $head .= '<th>' . $lang->getLL('pid', true) . '</th>';
138  $head .= '<th>' . $lang->getLL('rootline', true) . '</th>';
139  $head .= '<th>' . $lang->getLL('nextLevel', true) . '</th>';
140  $head .= '</tr></thead>';
141  $hierar = implode(array_reverse($templateService->ext_getTemplateHierarchyArr($hierarchyInfo, '', [], 1)), '');
142  $hierar = '<div class="table-fit"><table class="table table-striped table-hover" id="ts-analyzer">' . $head . $hierar . '</table></div>';
143  $theOutput .= '<div style="padding-top: 5px;"></div>';
144  $theOutput .= '<h2>' . $lang->getLL('templateHierarchy', true) . '</h2>';
145  $theOutput .= '<div>' . $hierar . '</div>';
146  $urlParameters = [
147  'id' => $GLOBALS['SOBE']->id,
148  'template' => 'all'
149  ];
150  $aHref = BackendUtility::getModuleUrl('web_ts', $urlParameters);
151 
152  $completeLink = '<p><a href="' . htmlspecialchars($aHref) . '" class="btn btn-default">' . $lang->getLL('viewCompleteTS', true) . '</a></p>';
153  $theOutput .= '<div style="padding-top: 5px;"></div>';
154  $theOutput .= '<h2>' . $lang->getLL('completeTS', true) . '</h2>';
155  $theOutput .= '<div>' . $completeLink . '</div>';
156  $theOutput .= '<div style="padding-top: 15px;"></div>';
157  // Output options
158  $theOutput .= '<h2>' . $lang->getLL('displayOptions', true) . '</h2>';
159 
160  $template = GeneralUtility::_GET('template');
161  $addParams = $template ? '&template=' . $template : '';
162  $theOutput .= '<div class="tst-analyzer-options">' .
163  '<div class="checkbox"><label for="checkTs_analyzer_checkLinenum">' .
164  BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkLinenum]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'], '', $addParams, 'id="checkTs_analyzer_checkLinenum"') .
165  $lang->getLL('lineNumbers', true) .
166  '</label></div>' .
167  '<div class="checkbox"><label for="checkTs_analyzer_checkSyntax">' .
168  BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkSyntax]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'], '', $addParams, 'id="checkTs_analyzer_checkSyntax"') .
169  $lang->getLL('syntaxHighlight', true) . '</label> ' .
170  '</label></div>';
171  if (!$this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax']) {
172  $theOutput .=
173  '<div class="checkbox"><label for="checkTs_analyzer_checkComments">' .
174  BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkComments]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'], '', $addParams, 'id="checkTs_analyzer_checkComments"') .
175  $lang->getLL('comments', true) .
176  '</label></div>' .
177  '<div class="checkbox"><label for="checkTs_analyzer_checkCrop">' .
178  BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkCrop]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'], '', $addParams, 'id="checkTs_analyzer_checkCrop"') .
179  $lang->getLL('cropLines', true) .
180  '</label></div>';
181  }
182  $theOutput .= '</div>';
183  $theOutput .= '<div style="padding-top: 25px;"></div>';
184 
185  if ($template) {
186  // Output Constants
187  $theOutput .= '<h2>' . $lang->getLL('constants', true) . '</h2>';
188 
189  $templateService->ext_lineNumberOffset = 0;
190  $templateService->ext_lineNumberOffset_mode = 'const';
191  foreach ($templateService->constants as $key => $val) {
192  $currentTemplateId = $templateService->hierarchyInfo[$key]['templateID'];
193  if ($currentTemplateId == $template || $template === 'all') {
194  $theOutput .= '
195  <h3>' . htmlspecialchars($templateService->hierarchyInfo[$key]['title']) . '</h3>
196  <div class="nowrap">' .
197  $templateService->ext_outputTS([$val], $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'], 0) .
198  '</div>
199  ';
200  if ($template !== 'all') {
201  break;
202  }
203  }
204  $templateService->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
205  }
206 
207  // Output Setup
208  $theOutput .= '<div style="padding-top: 15px;"></div>';
209  $theOutput .= '<h2>' . $lang->getLL('setup', true) . '</h2>';
210  $templateService->ext_lineNumberOffset = 0;
211  $templateService->ext_lineNumberOffset_mode = 'setup';
212  foreach ($templateService->config as $key => $val) {
213  $currentTemplateId = $templateService->hierarchyInfo[$key]['templateID'];
214  if ($currentTemplateId == $template || $template == 'all') {
215  $theOutput .= '
216  <h3>' . htmlspecialchars($templateService->hierarchyInfo[$key]['title']) . '</h3>
217  <div class="nowrap">' .
218  $templateService->ext_outputTS([$val], $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'], 0) .
219  '</div>
220  ';
221  if ($template !== 'all') {
222  break;
223  }
224  }
225  $templateService->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
226  }
227  }
228  return $theOutput;
229  }
230 
234  protected function getExtendedTemplateService()
235  {
236  return $GLOBALS['tmpl'];
237  }
238 }
static getFuncCheck($mainParams, $elementName, $currentValue, $script='', $addParams='', $tagParams='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']