[TASK] Fix typo in copyright notice
[Packages/TYPO3.CMS.git] / typo3 / sysext / tstemplate / Classes / Controller / TemplateAnalyzerModuleFunctionController.php
1 <?php
2 namespace TYPO3\CMS\TsTemplate\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * TypoScript template analyzer
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35 class TemplateAnalyzerModuleFunctionController extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule {
36
37 /**
38 * Init
39 *
40 * @param object $pObj
41 * @param array $conf
42 * @return void
43 * @todo Define visibility
44 */
45 public function init(&$pObj, $conf) {
46 parent::init($pObj, $conf);
47 $GLOBALS['LANG']->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_analyzer.xlf');
48 $this->pObj->modMenu_setDefaultList .= ',ts_analyzer_checkLinenum,ts_analyzer_checkSyntax';
49 }
50
51 /**
52 * Mod menu
53 *
54 * @return array
55 * @todo Define visibility
56 */
57 public function modMenu() {
58 return array(
59 'ts_analyzer_checkSetup' => '1',
60 'ts_analyzer_checkConst' => '1',
61 'ts_analyzer_checkLinenum' => '1',
62 'ts_analyzer_checkComments' => '1',
63 'ts_analyzer_checkCrop' => '1',
64 'ts_analyzer_checkSyntax' => '1'
65 );
66 }
67
68 /**
69 * Initialize editor
70 *
71 * @param integer $pageId
72 * @param integer $template_uid
73 * @return integer
74 * @todo Define visibility
75 */
76 public function initialize_editor($pageId, $template_uid = 0) {
77 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
78 $GLOBALS['tmpl'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\ExtendedTemplateService');
79 // Do not log time-performance information
80 $GLOBALS['tmpl']->tt_track = 0;
81 $GLOBALS['tmpl']->init();
82 // Gets the rootLine
83 $sys_page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
84 $GLOBALS['rootLine'] = $sys_page->getRootLine($pageId);
85 // This generates the constants/config + hierarchy info for the template.
86 $GLOBALS['tmpl']->runThroughTemplates($GLOBALS['rootLine'], $template_uid);
87 // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
88 $GLOBALS['tplRow'] = $GLOBALS['tmpl']->ext_getFirstTemplate($pageId, $template_uid);
89 if (is_array($GLOBALS['tplRow'])) {
90 // IF there was a template...
91 return 1;
92 }
93 }
94
95 /**
96 * Main
97 *
98 * @return string
99 * @todo Define visibility
100 */
101 public function main() {
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 // BUGBUG: Should we check if the uset may at all read and write template-records???
113 $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid);
114
115 // initialize
116 if ($existTemplate) {
117 $theOutput .= $this->pObj->doc->section(
118 $GLOBALS['LANG']->getLL('currentTemplate', TRUE),
119 \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'] . ')' : ''))
120 );
121 }
122 if ($manyTemplatesMenu) {
123 $theOutput .= $this->pObj->doc->section('', $manyTemplatesMenu);
124 }
125 $GLOBALS['tmpl']->clearList_const_temp = array_flip($GLOBALS['tmpl']->clearList_const);
126 $GLOBALS['tmpl']->clearList_setup_temp = array_flip($GLOBALS['tmpl']->clearList_setup);
127 $pointer = count($GLOBALS['tmpl']->hierarchyInfo);
128 $GLOBALS['tmpl']->hierarchyInfoArr = $GLOBALS['tmpl']->ext_process_hierarchyInfo(array(), $pointer);
129 $hierarArr = array();
130 $head = '<thead><tr>';
131 $head .= '<th>' . $GLOBALS['LANG']->getLL('title', TRUE) . '</th>';
132 $head .= '<th>' . $GLOBALS['LANG']->getLL('rootlevel', TRUE) . '</th>';
133 $head .= '<th>' . $GLOBALS['LANG']->getLL('clearSetup', TRUE) . '</th>';
134 $head .= '<th>' . $GLOBALS['LANG']->getLL('clearConstants', TRUE) . '</th>';
135 $head .= '<th>' . $GLOBALS['LANG']->getLL('pid', TRUE) . '</th>';
136 $head .= '<th>' . $GLOBALS['LANG']->getLL('rootline', TRUE) . '</th>';
137 $head .= '<th>' . $GLOBALS['LANG']->getLL('nextLevel', TRUE) . '</th>';
138 $head .= '</tr></thead>';
139 $hierar = implode(array_reverse($GLOBALS['tmpl']->ext_getTemplateHierarchyArr($GLOBALS['tmpl']->hierarchyInfoArr, '', array(), 1)), '');
140 $hierar = '<table class="t3-table" id="ts-analyzer">' . $head . $hierar . '</table>';
141 $theOutput .= $this->pObj->doc->spacer(5);
142 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('templateHierarchy', TRUE), $hierar, 0, 1);
143 $urlParameters = array(
144 'id' => $GLOBALS['SOBE']->id,
145 'template' => 'all'
146 );
147 $aHref = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_ts', $urlParameters);
148 $completeLink = '<p><a href="' . htmlspecialchars($aHref) . '">' . $GLOBALS['LANG']->getLL('viewCompleteTS', TRUE) . '</a></p>';
149 $theOutput .= $this->pObj->doc->spacer(5);
150 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('completeTS', TRUE), $completeLink, 0, 1);
151 $theOutput .= $this->pObj->doc->spacer(15);
152 // Output options
153 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('displayOptions', TRUE), '', FALSE, TRUE);
154 $addParams = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') ? '&template=' . \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') : '';
155 $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>';
156 $theOutput .= $this->pObj->doc->spacer(25);
157 // Output Constants
158 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template')) {
159 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('constants', TRUE), '', 0, 1);
160 $theOutput .= $this->pObj->doc->sectionEnd();
161 $theOutput .= '
162 <table class="t3-table ts-typoscript">
163 ';
164 // Don't know why -2 and not 0... :-) But works.
165 $GLOBALS['tmpl']->ext_lineNumberOffset = -2;
166 $GLOBALS['tmpl']->ext_lineNumberOffset_mode = 'const';
167 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines(('' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants'])))) + 1;
168 reset($GLOBALS['tmpl']->clearList_const);
169 foreach ($GLOBALS['tmpl']->constants as $key => $val) {
170 $cVal = current($GLOBALS['tmpl']->clearList_const);
171 if ($cVal == \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') || \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') == 'all') {
172 $theOutput .= '
173 <tr>
174 <td><strong>' . htmlspecialchars($GLOBALS['tmpl']->templateTitles[$cVal]) . '</strong></td>
175 </tr>
176 <tr>
177 <td>
178 <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>
179 </td>
180 </tr>
181 ';
182 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') != 'all') {
183 break;
184 }
185 }
186 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
187 next($GLOBALS['tmpl']->clearList_const);
188 }
189 $theOutput .= '
190 </table>
191 ';
192 }
193 // Output setup
194 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template')) {
195 $theOutput .= $this->pObj->doc->spacer(15);
196 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('setup', TRUE), '', 0, 1);
197 $theOutput .= $this->pObj->doc->sectionEnd();
198 $theOutput .= '
199 <table class="t3-table ts-typoscript">
200 ';
201 $GLOBALS['tmpl']->ext_lineNumberOffset = 0;
202 $GLOBALS['tmpl']->ext_lineNumberOffset_mode = 'setup';
203 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines(('' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'])))) + 1;
204 reset($GLOBALS['tmpl']->clearList_setup);
205 foreach ($GLOBALS['tmpl']->config as $key => $val) {
206 if (current($GLOBALS['tmpl']->clearList_setup) == \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') || \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') == 'all') {
207 $theOutput .= '
208 <tr>
209 <td><strong>' . htmlspecialchars($GLOBALS['tmpl']->templateTitles[current($GLOBALS['tmpl']->clearList_setup)]) . '</strong></td></tr>
210 <tr>
211 <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>
212 </td>
213 </tr>
214 ';
215 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('template') != 'all') {
216 break;
217 }
218 }
219 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
220 next($GLOBALS['tmpl']->clearList_setup);
221 }
222 $theOutput .= '
223 </table>
224 ';
225 }
226 return $theOutput;
227 }
228
229 }