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