TYPO3 CMS  TYPO3_6-2
TemplateAnalyzerModuleFunctionController.php
Go to the documentation of this file.
1 <?php
3 
23 
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 
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 
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 
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">' . \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>';
142  $theOutput .= $this->pObj->doc->spacer(25);
143  // Output Constants
144  if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template')) {
145  $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('constants', TRUE), '', 0, 1);
146  $theOutput .= $this->pObj->doc->sectionEnd();
147  $theOutput .= '
148  <table class="t3-table ts-typoscript">
149  ';
150  // Don't know why -2 and not 0... :-) But works.
151  $GLOBALS['tmpl']->ext_lineNumberOffset = 0;
152  $GLOBALS['tmpl']->ext_lineNumberOffset_mode = 'const';
153  foreach ($GLOBALS['tmpl']->constants as $key => $val) {
154  $currentTemplateId = $GLOBALS['tmpl']->hierarchyInfo[$key]['templateID'];
155  if ($currentTemplateId == \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') || \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') == 'all') {
156  $theOutput .= '
157  <tr>
158  <td><strong>' . htmlspecialchars($GLOBALS['tmpl']->hierarchyInfo[$key]['title']) . '</strong></td>
159  </tr>
160  <tr>
161  <td>
162  <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>
163  </td>
164  </tr>
165  ';
166  if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') != 'all') {
167  break;
168  }
169  }
170  $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
171  }
172  $theOutput .= '
173  </table>
174  ';
175  }
176  // Output setup
177  if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template')) {
178  $theOutput .= $this->pObj->doc->spacer(15);
179  $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('setup', TRUE), '', 0, 1);
180  $theOutput .= $this->pObj->doc->sectionEnd();
181  $theOutput .= '
182  <table class="t3-table ts-typoscript">
183  ';
184  $GLOBALS['tmpl']->ext_lineNumberOffset = 0;
185  $GLOBALS['tmpl']->ext_lineNumberOffset_mode = 'setup';
186  foreach ($GLOBALS['tmpl']->config as $key => $val) {
187  $currentTemplateId = $GLOBALS['tmpl']->hierarchyInfo[$key]['templateID'];
188  if ($currentTemplateId == \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') || \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') == 'all') {
189  $theOutput .= '
190  <tr>
191  <td><strong>' . htmlspecialchars($GLOBALS['tmpl']->hierarchyInfo[$key]['title']) . '</strong></td></tr>
192  <tr>
193  <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>
194  </td>
195  </tr>
196  ';
197  if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') != 'all') {
198  break;
199  }
200  }
201  $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
202  }
203  $theOutput .= '
204  </table>
205  ';
206  }
207  return $theOutput;
208  }
209 
210 }
static getFuncCheck($mainParams, $elementName, $currentValue, $script='', $addParams='', $tagParams='')
static getSpriteIconForRecord($table, array $row, array $options=array())
static getModuleUrl($moduleName, $urlParameters=array(), $backPathOverride=FALSE, $returnAbsoluteUrl=FALSE)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]