[TASK] Remove superfluous parenthesis in sysexts
[Packages/TYPO3.CMS.git] / typo3 / sysext / tstemplate_analyzer / Classes / Controller / TemplateAnalyzerModuleFunctionController.php
1 <?php
2 namespace TYPO3\CMS\TstemplateAnalyzer\Controller;
3
4 /**
5 * TypoScript template analyzer
6 *
7 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
8 */
9 class TemplateAnalyzerModuleFunctionController extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule {
10
11 /**
12 * Init
13 *
14 * @param object $pObj
15 * @param array $conf
16 * @return void
17 * @todo Define visibility
18 */
19 public function init(&$pObj, $conf) {
20 parent::init($pObj, $conf);
21 $this->pObj->modMenu_setDefaultList .= ',ts_analyzer_checkLinenum,ts_analyzer_checkSyntax';
22 }
23
24 /**
25 * Mod menu
26 *
27 * @return array
28 * @todo Define visibility
29 */
30 public function modMenu() {
31 return array(
32 'ts_analyzer_checkSetup' => '1',
33 'ts_analyzer_checkConst' => '1',
34 'ts_analyzer_checkLinenum' => '1',
35 'ts_analyzer_checkComments' => '1',
36 'ts_analyzer_checkCrop' => '1',
37 'ts_analyzer_checkSyntax' => '1'
38 );
39 }
40
41 /**
42 * Initialize editor
43 *
44 * @param integer $pageId
45 * @param integer $template_uid
46 * @return integer
47 * @todo Define visibility
48 */
49 public function initialize_editor($pageId, $template_uid = 0) {
50 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
51 $GLOBALS['tmpl'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\ExtendedTemplateService');
52 // Do not log time-performance information
53 $GLOBALS['tmpl']->tt_track = 0;
54 $GLOBALS['tmpl']->init();
55 // Gets the rootLine
56 $sys_page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
57 $GLOBALS['rootLine'] = $sys_page->getRootLine($pageId);
58 // This generates the constants/config + hierarchy info for the template.
59 $GLOBALS['tmpl']->runThroughTemplates($GLOBALS['rootLine'], $template_uid);
60 // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
61 $GLOBALS['tplRow'] = $GLOBALS['tmpl']->ext_getFirstTemplate($pageId, $template_uid);
62 if (is_array($GLOBALS['tplRow'])) {
63 // IF there was a template...
64 return 1;
65 }
66 }
67
68 /**
69 * Main
70 *
71 * @return string
72 * @todo Define visibility
73 */
74 public function main() {
75 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
76 // Checking for more than one template an if, set a menu...
77 $manyTemplatesMenu = $this->pObj->templateMenu();
78 $template_uid = 0;
79 if ($manyTemplatesMenu) {
80 $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
81 }
82 // BUGBUG: Should we check if the uset may at all read and write template-records???
83 $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
84 // initialize
85 if ($existTemplate) {
86 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('currentTemplate', TRUE), \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('sys_template', $GLOBALS['tplRow']) . '<strong>' . $this->pObj->linkWrapTemplateTitle($GLOBALS['tplRow']['title']) . '</strong>' . htmlspecialchars((trim($GLOBALS['tplRow']['sitetitle']) ? ' (' . $GLOBALS['tplRow']['sitetitle'] . ')' : '')));
87 }
88 if ($manyTemplatesMenu) {
89 $theOutput .= $this->pObj->doc->section('', $manyTemplatesMenu);
90 }
91 $GLOBALS['tmpl']->clearList_const_temp = array_flip($GLOBALS['tmpl']->clearList_const);
92 $GLOBALS['tmpl']->clearList_setup_temp = array_flip($GLOBALS['tmpl']->clearList_setup);
93 $pointer = count($GLOBALS['tmpl']->hierarchyInfo);
94 $GLOBALS['tmpl']->hierarchyInfoArr = $GLOBALS['tmpl']->ext_process_hierarchyInfo(array(), $pointer);
95 $GLOBALS['tmpl']->processIncludes();
96 $hierarArr = array();
97 $head = '<tr class="t3-row-header">';
98 $head .= '<td>' . $GLOBALS['LANG']->getLL('title', TRUE) . '</td>';
99 $head .= '<td>' . $GLOBALS['LANG']->getLL('rootlevel', TRUE) . '</td>';
100 $head .= '<td>' . $GLOBALS['LANG']->getLL('clearSetup', TRUE) . '</td>';
101 $head .= '<td>' . $GLOBALS['LANG']->getLL('clearConstants', TRUE) . '</td>';
102 $head .= '<td>' . $GLOBALS['LANG']->getLL('pid', TRUE) . '</td>';
103 $head .= '<td>' . $GLOBALS['LANG']->getLL('rootline', TRUE) . '</td>';
104 $head .= '<td>' . $GLOBALS['LANG']->getLL('nextLevel', TRUE) . '</td>';
105 $head .= '</tr>';
106 $hierar = implode(array_reverse($GLOBALS['tmpl']->ext_getTemplateHierarchyArr($GLOBALS['tmpl']->hierarchyInfoArr, '', array(), 1)), '');
107 $hierar = '<table id="ts-analyzer" cellpadding="0" cellspacing="0">' . $head . $hierar . '</table>';
108 $theOutput .= $this->pObj->doc->spacer(5);
109 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('templateHierarchy', TRUE), $hierar, 0, 1);
110 $urlParameters = array(
111 'id' => $GLOBALS['SOBE']->id,
112 'template' => 'all'
113 );
114 $aHref = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_ts', $urlParameters);
115 $completeLink = '<p><a href="' . htmlspecialchars($aHref) . '">' . $GLOBALS['LANG']->getLL('viewCompleteTS', TRUE) . '</a></p>';
116 $theOutput .= $this->pObj->doc->spacer(5);
117 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('completeTS', TRUE), $completeLink, 0, 1);
118 $theOutput .= $this->pObj->doc->spacer(15);
119 // Output options
120 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('displayOptions', TRUE), '', FALSE, TRUE);
121 $addParams = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') ? '&template=' . \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') : '';
122 $theOutput .= '<div class="tst-analyzer-options">' . \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkLinenum]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'], '', $addParams, 'id="checkTs_analyzer_checkLinenum"') . '<label for="checkTs_analyzer_checkLinenum">' . $GLOBALS['LANG']->getLL('lineNumbers', TRUE) . '</label> ' . \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkSyntax]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'], '', $addParams, 'id="checkTs_analyzer_checkSyntax"') . '<label for="checkTs_analyzer_checkSyntax">' . $GLOBALS['LANG']->getLL('syntaxHighlight', TRUE) . '</label> ' . (!$this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'] ? \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkComments]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'], '', $addParams, 'id="checkTs_analyzer_checkComments"') . '<label for="checkTs_analyzer_checkComments">' . $GLOBALS['LANG']->getLL('comments', TRUE) . '</label> ' . \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkCrop]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'], '', $addParams, 'id="checkTs_analyzer_checkCrop"') . '<label for="checkTs_analyzer_checkCrop">' . $GLOBALS['LANG']->getLL('cropLines', TRUE) . '</label> ' : '') . '</div>';
123 $theOutput .= $this->pObj->doc->spacer(25);
124 // Output Constants
125 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template')) {
126 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('constants', TRUE), '', 0, 1);
127 $theOutput .= $this->pObj->doc->sectionEnd();
128 $theOutput .= '
129 <table class="ts-typoscript" border="0" cellpadding="1" cellspacing="0">
130 ';
131 // Don't know why -2 and not 0... :-) But works.
132 $GLOBALS['tmpl']->ext_lineNumberOffset = -2;
133 $GLOBALS['tmpl']->ext_lineNumberOffset_mode = 'const';
134 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines(('' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants'])))) + 1;
135 reset($GLOBALS['tmpl']->clearList_const);
136 foreach ($GLOBALS['tmpl']->constants as $key => $val) {
137 $cVal = current($GLOBALS['tmpl']->clearList_const);
138 if ($cVal == \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') || \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') == 'all') {
139 $theOutput .= '
140 <tr>
141 </td><td class="bgColor2"><strong>' . htmlspecialchars($GLOBALS['tmpl']->templateTitles[$cVal]) . '</strong></td></tr>
142 <tr>
143 <td class="bgColor2"><table border="0" cellpadding="0" cellspacing="0" class="bgColor0" width="100%"><tr><td nowrap="nowrap">' . $GLOBALS['tmpl']->ext_outputTS(array($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) . '</td></tr></table>
144 </td>
145 </tr>
146 ';
147 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') != 'all') {
148 break;
149 }
150 }
151 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
152 next($GLOBALS['tmpl']->clearList_const);
153 }
154 $theOutput .= '
155 </table>
156 ';
157 }
158 // Output setup
159 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template')) {
160 $theOutput .= $this->pObj->doc->spacer(15);
161 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('setup', TRUE), '', 0, 1);
162 $theOutput .= $this->pObj->doc->sectionEnd();
163 $theOutput .= '
164 <table class="ts-typoscript" border="0" cellpadding="1" cellspacing="0">
165 ';
166 $GLOBALS['tmpl']->ext_lineNumberOffset = 0;
167 $GLOBALS['tmpl']->ext_lineNumberOffset_mode = 'setup';
168 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines(('' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'])))) + 1;
169 reset($GLOBALS['tmpl']->clearList_setup);
170 foreach ($GLOBALS['tmpl']->config as $key => $val) {
171 if (current($GLOBALS['tmpl']->clearList_setup) == \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') || \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') == 'all') {
172 $theOutput .= '
173 <tr>
174 <td class="bgColor2"><strong>' . htmlspecialchars($GLOBALS['tmpl']->templateTitles[current($GLOBALS['tmpl']->clearList_setup)]) . '</strong></td></tr>
175 <tr>
176 <td class="bgColor2"><table border="0" cellpadding="0" cellspacing="0" class="bgColor0" width="100%"><tr><td nowrap="nowrap">' . $GLOBALS['tmpl']->ext_outputTS(array($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) . '</td></tr></table>
177 </td>
178 </tr>
179 ';
180 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') != 'all') {
181 break;
182 }
183 }
184 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
185 next($GLOBALS['tmpl']->clearList_setup);
186 }
187 $theOutput .= '
188 </table>
189 ';
190 }
191 return $theOutput;
192 }
193
194 }
195
196
197 ?>