[BUGFIX] BE User Settings cannot be saved by clicking enter
[Packages/TYPO3.CMS.git] / typo3 / sysext / tstemplate_analyzer / class.tx_tstemplateanalyzer.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 $GLOBALS['LANG']->includeLLFile('EXT:tstemplate_analyzer/locallang.xml');
29
30 /**
31 * TypoScript template analyzer
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35 class tx_tstemplateanalyzer extends t3lib_extobjbase {
36 /**
37 * Init
38 *
39 * @param object $pObj
40 * @param array $conf
41 * @return void
42 */
43 function init(&$pObj, $conf) {
44 parent::init($pObj, $conf);
45
46 $this->pObj->modMenu_setDefaultList.= ',ts_analyzer_checkLinenum,ts_analyzer_checkSyntax';
47 }
48
49 /**
50 * Mod menu
51 *
52 * @return array
53 */
54 function modMenu() {
55 return array (
56 'ts_analyzer_checkSetup' => '1',
57 'ts_analyzer_checkConst' => '1',
58 'ts_analyzer_checkLinenum' => '1',
59 'ts_analyzer_checkComments' => '1',
60 'ts_analyzer_checkCrop' => '1',
61 'ts_analyzer_checkSyntax' => '1',
62 );
63 }
64
65 /**
66 * Initialize editor
67 *
68 * @param integer $pageId
69 * @param integer $template_uid
70 * @return integer
71 */
72 function initialize_editor($pageId, $template_uid=0) {
73 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
74
75 $GLOBALS['tmpl'] = t3lib_div::makeInstance('t3lib_tsparser_ext');
76 // Do not log time-performance information
77 $GLOBALS['tmpl']->tt_track = 0;
78 $GLOBALS['tmpl']->init();
79
80 // Gets the rootLine
81 $sys_page = t3lib_div::makeInstance('t3lib_pageSelect');
82 $GLOBALS['rootLine'] = $sys_page->getRootLine($pageId);
83 // This generates the constants/config + hierarchy info for the template.
84 $GLOBALS['tmpl']->runThroughTemplates($GLOBALS['rootLine'], $template_uid);
85
86 // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
87 $GLOBALS['tplRow'] = $GLOBALS['tmpl']->ext_getFirstTemplate($pageId, $template_uid);
88 if (is_array($GLOBALS['tplRow'])) {
89 // IF there was a template...
90 return 1;
91 }
92 }
93
94 /**
95 * Main
96 *
97 * @return string
98 */
99 function main() {
100 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
101
102 // Checking for more than one template an if, set a menu...
103 $manyTemplatesMenu = $this->pObj->templateMenu();
104 $template_uid = 0;
105 if ($manyTemplatesMenu) {
106 $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
107 }
108
109 // BUGBUG: Should we check if the uset may at all read and write template-records???
110 $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid); // initialize
111 if ($existTemplate) {
112 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('currentTemplate', TRUE),
113 t3lib_iconWorks::getSpriteIconForRecord('sys_template', $GLOBALS['tplRow']) . '<strong>' .
114 $this->pObj->linkWrapTemplateTitle($GLOBALS['tplRow']['title']) . '</strong>' .
115 htmlspecialchars(trim($GLOBALS['tplRow']['sitetitle']) ? ' (' . $GLOBALS['tplRow']['sitetitle'] . ')' : ''));
116 }
117 if ($manyTemplatesMenu) {
118 $theOutput .= $this->pObj->doc->section('', $manyTemplatesMenu);
119 }
120
121 $GLOBALS['tmpl']->clearList_const_temp = array_flip($GLOBALS['tmpl']->clearList_const);
122 $GLOBALS['tmpl']->clearList_setup_temp = array_flip($GLOBALS['tmpl']->clearList_setup);
123
124 $pointer = count($GLOBALS['tmpl']->hierarchyInfo);
125 $GLOBALS['tmpl']->hierarchyInfoArr = $GLOBALS['tmpl']->ext_process_hierarchyInfo(array(), $pointer);
126 $GLOBALS['tmpl']->processIncludes();
127
128 $hierarArr = array();
129 $head = '<tr class="t3-row-header">';
130 $head .= '<td>' . $GLOBALS['LANG']->getLL('title', TRUE) . '</td>';
131 $head .= '<td>' . $GLOBALS['LANG']->getLL('rootlevel', TRUE) . '</td>';
132 $head .= '<td>' . $GLOBALS['LANG']->getLL('clearSetup', TRUE) . '</td>';
133 $head .= '<td>' . $GLOBALS['LANG']->getLL('clearConstants', TRUE) . '</td>';
134 $head .= '<td>' . $GLOBALS['LANG']->getLL('pid', TRUE) . '</td>';
135 $head .= '<td>' . $GLOBALS['LANG']->getLL('rootline', TRUE) . '</td>';
136 $head .= '<td>' . $GLOBALS['LANG']->getLL('nextLevel', TRUE) . '</td>';
137 $head .= '</tr>';
138 $hierar = implode(array_reverse($GLOBALS['tmpl']->ext_getTemplateHierarchyArr($GLOBALS['tmpl']->hierarchyInfoArr, '', array(), 1)), '');
139 $hierar= '<table id="ts-analyzer" cellpadding="0" cellspacing="0">' . $head . $hierar . '</table>';
140
141 $theOutput.=$this->pObj->doc->spacer(5);
142 $theOutput.=$this->pObj->doc->section($GLOBALS['LANG']->getLL('templateHierarchy', TRUE), $hierar, 0, 1);
143
144 $urlParameters = array(
145 'id' => $GLOBALS['SOBE']->id,
146 'template' => 'all',
147 );
148 $aHref = t3lib_BEfunc::getModuleUrl('web_ts', $urlParameters);
149
150 $completeLink = '<p><a href="' . htmlspecialchars($aHref) . '">' . $GLOBALS['LANG']->getLL('viewCompleteTS', TRUE) . '</a></p>';
151 $theOutput .= $this->pObj->doc->spacer(5);
152 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('completeTS', TRUE), $completeLink, 0, 1);
153 $theOutput.=$this->pObj->doc->spacer(15);
154
155 // Output options
156 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('displayOptions', TRUE), '', FALSE, TRUE);
157 $addParams = t3lib_div::_GET('template') ? '&template=' . t3lib_div::_GET('template') : '';
158 $theOutput .= '<div class="tst-analyzer-options">' .
159 t3lib_BEfunc::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkLinenum]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'], '', $addParams, 'id="checkTs_analyzer_checkLinenum"') .
160 '<label for="checkTs_analyzer_checkLinenum">' . $GLOBALS['LANG']->getLL('lineNumbers', TRUE) . '</label> ' .
161 t3lib_BEfunc::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkSyntax]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'], '', $addParams, 'id="checkTs_analyzer_checkSyntax"') .
162 '<label for="checkTs_analyzer_checkSyntax">' . $GLOBALS['LANG']->getLL('syntaxHighlight', TRUE) . '</label> ' .
163 (!$this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'] ?
164 t3lib_BEfunc::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkComments]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'], '', $addParams, 'id="checkTs_analyzer_checkComments"') .
165 '<label for="checkTs_analyzer_checkComments">' . $GLOBALS['LANG']->getLL('comments', TRUE) . '</label> ' .
166 t3lib_BEfunc::getFuncCheck($this->pObj->id, 'SET[ts_analyzer_checkCrop]', $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'], '', $addParams, 'id="checkTs_analyzer_checkCrop"') .
167 '<label for="checkTs_analyzer_checkCrop">' . $GLOBALS['LANG']->getLL('cropLines', TRUE) . '</label> '
168 :
169 ''
170 ) . '</div>';
171 $theOutput .=$this->pObj->doc->spacer(25);
172
173 // Output Constants
174 if (t3lib_div::_GET('template')) {
175 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('constants', TRUE), '', 0, 1);
176 $theOutput .= $this->pObj->doc->sectionEnd();
177 $theOutput .= '
178 <table class="ts-typoscript" border="0" cellpadding="1" cellspacing="0">
179 ';
180 // Don't know why -2 and not 0... :-) But works.
181 $GLOBALS['tmpl']->ext_lineNumberOffset = -2;
182 $GLOBALS['tmpl']->ext_lineNumberOffset_mode = 'const';
183 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, t3lib_TSparser::checkIncludeLines('' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']))) + 1;
184
185 reset($GLOBALS['tmpl']->clearList_const);
186 foreach ($GLOBALS['tmpl']->constants as $key => $val) {
187 $cVal = current($GLOBALS['tmpl']->clearList_const);
188 if ($cVal == t3lib_div::_GET('template') || t3lib_div::_GET('template') == 'all') {
189 $theOutput .= '
190 <tr>
191 </td><td class="bgColor2"><strong>' . htmlspecialchars($GLOBALS['tmpl']->templateTitles[$cVal]) . '</strong></td></tr>
192 <tr>
193 <td class="bgColor2"><table border="0" cellpadding="0" cellspacing="0" class="bgColor0" width="100%"><tr><td nowrap="nowrap">' .
194 $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) .
195 '</td></tr></table>
196 </td>
197 </tr>
198 ';
199 if (t3lib_div::_GET('template') != 'all') {
200 break;
201 }
202 }
203 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
204 next($GLOBALS['tmpl']->clearList_const);
205 }
206 $theOutput .= '
207 </table>
208 ';
209 }
210
211 // Output setup
212 if (t3lib_div::_GET('template')) {
213 $theOutput .= $this->pObj->doc->spacer(15);
214 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('setup', TRUE), '', 0, 1);
215 $theOutput .= $this->pObj->doc->sectionEnd();
216 $theOutput .= '
217 <table class="ts-typoscript" border="0" cellpadding="1" cellspacing="0">
218 ';
219 $GLOBALS['tmpl']->ext_lineNumberOffset = 0;
220 $GLOBALS['tmpl']->ext_lineNumberOffset_mode = 'setup';
221 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, t3lib_TSparser::checkIncludeLines('' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']))) + 1;
222
223 reset($GLOBALS['tmpl']->clearList_setup);
224 foreach ($GLOBALS['tmpl']->config as $key => $val) {
225 if (current($GLOBALS['tmpl']->clearList_setup) == t3lib_div::_GET('template') || t3lib_div::_GET('template') == 'all') {
226 $theOutput .= '
227 <tr>
228 <td class="bgColor2"><strong>' . htmlspecialchars($GLOBALS['tmpl']->templateTitles[current($GLOBALS['tmpl']->clearList_setup)]) . '</strong></td></tr>
229 <tr>
230 <td class="bgColor2"><table border="0" cellpadding="0" cellspacing="0" class="bgColor0" width="100%"><tr><td nowrap="nowrap">' .
231 $GLOBALS['tmpl']->ext_outputTS(
232 array($val),
233 $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'],
234 $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'],
235 $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'],
236 $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'],
237 0) .
238 '</td></tr></table>
239 </td>
240 </tr>
241 ';
242 if (t3lib_div::_GET('template') != 'all') {
243 break;
244 }
245 }
246 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
247 next($GLOBALS['tmpl']->clearList_setup);
248 }
249 $theOutput .= '
250 </table>
251 ';
252 }
253
254 return $theOutput;
255 }
256 }
257 ?>