2 namespace TYPO3\CMS\TstemplateAnalyzer\Controller
;
5 * TypoScript template analyzer
7 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
9 class TemplateAnalyzerModuleFunctionController
extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule
{
17 * @todo Define visibility
19 public function init(&$pObj, $conf) {
20 parent
::init($pObj, $conf);
21 $this->pObj
->modMenu_setDefaultList
.= ',ts_analyzer_checkLinenum,ts_analyzer_checkSyntax';
28 * @todo Define visibility
30 public function modMenu() {
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'
44 * @param integer $pageId
45 * @param integer $template_uid
47 * @todo Define visibility
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();
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...
72 * @todo Define visibility
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();
79 if ($manyTemplatesMenu) {
80 $template_uid = $this->pObj
->MOD_SETTINGS
['templatesOnPage'];
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);
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'] . ')' : '')));
88 if ($manyTemplatesMenu) {
89 $theOutput .= $this->pObj
->doc
->section('', $manyTemplatesMenu);
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();
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>';
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
,
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);
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);
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();
129 <table class="ts-typoscript" border="0" cellpadding="1" cellspacing="0">
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') {
141 </td><td class="bgColor2"><strong>' . htmlspecialchars($GLOBALS['tmpl']->templateTitles
[$cVal]) . '</strong></td></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>
147 if (\TYPO3\CMS\Core\Utility\GeneralUtility
::_GET('template') != 'all') {
151 $GLOBALS['tmpl']->ext_lineNumberOffset +
= count(explode(LF
, $val)) +
1;
152 next($GLOBALS['tmpl']->clearList_const
);
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();
164 <table class="ts-typoscript" border="0" cellpadding="1" cellspacing="0">
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') {
174 <td class="bgColor2"><strong>' . htmlspecialchars($GLOBALS['tmpl']->templateTitles
[current($GLOBALS['tmpl']->clearList_setup
)]) . '</strong></td></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>
180 if (\TYPO3\CMS\Core\Utility\GeneralUtility
::_GET('template') != 'all') {
184 $GLOBALS['tmpl']->ext_lineNumberOffset +
= count(explode(LF
, $val)) +
1;
185 next($GLOBALS['tmpl']->clearList_setup
);