[TASK] Unify backend: header/section
[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 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
29 */
30
31 $GLOBALS['LANG']->includeLLFile('EXT:tstemplate_analyzer/locallang.xml');
32
33 class tx_tstemplateanalyzer extends t3lib_extobjbase {
34 function init(&$pObj,$conf) {
35 parent::init($pObj,$conf);
36
37 $this->pObj->modMenu_setDefaultList.= ',ts_analyzer_checkLinenum,ts_analyzer_checkSyntax';
38 }
39
40 function modMenu() {
41 return array (
42 'ts_analyzer_checkSetup' => '1',
43 'ts_analyzer_checkConst' => '1',
44 'ts_analyzer_checkLinenum' => '1',
45 'ts_analyzer_checkComments' => '1',
46 'ts_analyzer_checkCrop' => '1',
47 'ts_analyzer_checkSyntax' => '1',
48 );
49 }
50
51 function initialize_editor($pageId,$template_uid=0) {
52 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
53
54 $GLOBALS['tmpl'] = t3lib_div::makeInstance("t3lib_tsparser_ext");
55 // Do not log time-performance information
56 $GLOBALS['tmpl']->tt_track = 0;
57 $GLOBALS['tmpl']->init();
58
59 // Gets the rootLine
60 $sys_page = t3lib_div::makeInstance("t3lib_pageSelect");
61 $GLOBALS['rootLine'] = $sys_page->getRootLine($pageId);
62 // This generates the constants/config + hierarchy info for the template.
63 $GLOBALS['tmpl']->runThroughTemplates($GLOBALS['rootLine'], $template_uid);
64
65 // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
66 $GLOBALS['tplRow'] = $GLOBALS['tmpl']->ext_getFirstTemplate($pageId,$template_uid);
67 if (is_array($GLOBALS['tplRow'])) {
68 // IF there was a template...
69 return 1;
70 }
71 }
72
73 function main() {
74 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
75
76 // **************************
77 // Checking for more than one template an if, set a menu...
78 // **************************
79 $manyTemplatesMenu = $this->pObj->templateMenu();
80 $template_uid = 0;
81 if ($manyTemplatesMenu) {
82 $template_uid = $this->pObj->MOD_SETTINGS["templatesOnPage"];
83 }
84
85 // **************************
86 // Main
87 // **************************
88
89 // BUGBUG: Should we check if the uset may at all read and write template-records???
90 $existTemplate = $this->initialize_editor($this->pObj->id,$template_uid); // initialize
91 if ($existTemplate) {
92 $theOutput.=$this->pObj->doc->section($GLOBALS['LANG']->getLL('currentTemplate', TRUE) ,
93 t3lib_iconWorks::getSpriteIconForRecord('sys_template', $GLOBALS['tplRow']) . '<strong>' .
94 $this->pObj->linkWrapTemplateTitle($GLOBALS['tplRow']["title"]) . '</strong>' .
95 htmlspecialchars(trim($GLOBALS['tplRow']["sitetitle"]) ? ' - (' . $GLOBALS['tplRow']["sitetitle"] . ')' : ''));
96 }
97 if ($manyTemplatesMenu) {
98 $theOutput.=$this->pObj->doc->section("",$manyTemplatesMenu);
99 }
100
101 // debug($GLOBALS['tmpl']->hierarchyInfo);
102
103 $GLOBALS['tmpl']->clearList_const_temp = array_flip($GLOBALS['tmpl']->clearList_const);
104 $GLOBALS['tmpl']->clearList_setup_temp = array_flip($GLOBALS['tmpl']->clearList_setup);
105
106 $pointer = count($GLOBALS['tmpl']->hierarchyInfo);
107 $GLOBALS['tmpl']->hierarchyInfoArr = $GLOBALS['tmpl']->ext_process_hierarchyInfo(array(), $pointer);
108 $GLOBALS['tmpl']->processIncludes();
109
110 $hierarArr = array();
111 $head = '<tr class="t3-row-header">';
112 $head.= '<td>' . $GLOBALS['LANG']->getLL('title', TRUE) . '</td>';
113 $head.= '<td>' . $GLOBALS['LANG']->getLL('rootlevel', TRUE) . '</td>';
114 $head.= '<td>' . $GLOBALS['LANG']->getLL('clearSetup', TRUE) . '</td>';
115 $head.= '<td>' . $GLOBALS['LANG']->getLL('clearConstants', TRUE) . '</td>';
116 $head.= '<td>' . $GLOBALS['LANG']->getLL('pid', TRUE) . '</td>';
117 $head.= '<td>' . $GLOBALS['LANG']->getLL('rootline', TRUE) . '</td>';
118 $head.= '<td>' . $GLOBALS['LANG']->getLL('nextLevel', TRUE) . '</td>';
119 $head.= '</tr>';
120 $hierar = implode(array_reverse($GLOBALS['tmpl']->ext_getTemplateHierarchyArr($GLOBALS['tmpl']->hierarchyInfoArr, "", array(), 1)), "");
121 $hierar= '<table id="ts-analyzer" border="0" cellpadding="0" cellspacing="0">' . $head . $hierar . '</table>';
122
123 $theOutput.=$this->pObj->doc->spacer(5);
124 $theOutput.=$this->pObj->doc->section($GLOBALS['LANG']->getLL('templateHierarchy', TRUE), $hierar, 0, 1);
125
126 $completeLink = '<p><a href="index.php?id=' . $GLOBALS['SOBE']->id . '&amp;template=all">' . $GLOBALS['LANG']->getLL('viewCompleteTS', TRUE) . '</a></p>';
127 $theOutput .= $this->pObj->doc->spacer(5);
128 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('completeTS', TRUE), $completeLink, 0, 1);
129
130
131 // Output options
132 $theOutput.=$this->pObj->doc->spacer(25);
133 $theOutput.=$this->pObj->doc->divider(0);
134 $theOutput.=$this->pObj->doc->section($GLOBALS['LANG']->getLL('displayOptions', TRUE), '', 1, 1);
135 $addParams = t3lib_div::_GET('template') ? '&template=' . t3lib_div::_GET('template') : '';
136 $theOutput .= '<div class="tst-analyzer-options">' .
137 t3lib_BEfunc::getFuncCheck($this->pObj->id, "SET[ts_analyzer_checkLinenum]", $this->pObj->MOD_SETTINGS["ts_analyzer_checkLinenum"], '', $addParams, 'id="checkTs_analyzer_checkLinenum"') .
138 '<label for="checkTs_analyzer_checkLinenum">' . $GLOBALS['LANG']->getLL('lineNumbers', TRUE) . '</label> ' .
139 t3lib_BEfunc::getFuncCheck($this->pObj->id, "SET[ts_analyzer_checkSyntax]", $this->pObj->MOD_SETTINGS["ts_analyzer_checkSyntax"], '', $addParams, 'id="checkTs_analyzer_checkSyntax"') .
140 '<label for="checkTs_analyzer_checkSyntax">' . $GLOBALS['LANG']->getLL('syntaxHighlight', TRUE) . '</label> ' .
141 (!$this->pObj->MOD_SETTINGS["ts_analyzer_checkSyntax"] ?
142 t3lib_BEfunc::getFuncCheck($this->pObj->id, "SET[ts_analyzer_checkComments]", $this->pObj->MOD_SETTINGS["ts_analyzer_checkComments"], '', $addParams, 'id="checkTs_analyzer_checkComments"') .
143 '<label for="checkTs_analyzer_checkComments">' . $GLOBALS['LANG']->getLL('comments', TRUE) . '</label> ' .
144 t3lib_BEfunc::getFuncCheck($this->pObj->id, "SET[ts_analyzer_checkCrop]", $this->pObj->MOD_SETTINGS["ts_analyzer_checkCrop"], '', $addParams, 'id="checkTs_analyzer_checkCrop"') .
145 '<label for="checkTs_analyzer_checkCrop">' . $GLOBALS['LANG']->getLL('cropLines', TRUE) . '</label> '
146 :
147 ''
148 ) . '</div>';
149
150
151
152 // Output Constants
153 if (t3lib_div::_GET('template')) {
154 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('constants', TRUE), "", 0, 1);
155 $theOutput .= $this->pObj->doc->sectionEnd();
156 $theOutput .= '
157 <table border="0" cellpadding="1" cellspacing="0">
158 ';
159 // Don't know why -2 and not 0... :-) But works.
160 $GLOBALS['tmpl']->ext_lineNumberOffset = -2;
161 $GLOBALS['tmpl']->ext_lineNumberOffset_mode = "const";
162 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, t3lib_TSparser::checkIncludeLines("" . $GLOBALS["TYPO3_CONF_VARS"]["FE"]["defaultTypoScript_constants"]))) + 1;
163
164 reset($GLOBALS['tmpl']->clearList_const);
165 foreach ($GLOBALS['tmpl']->constants as $key => $val) {
166 $cVal = current($GLOBALS['tmpl']->clearList_const);
167 if ($cVal == t3lib_div::_GET('template') || t3lib_div::_GET('template') == 'all') {
168 $theOutput .= '
169 <tr>
170 <td><img src="clear.gif" width="3" height="1" alt="" /></td><td class="bgColor2"><strong>' . htmlspecialchars($GLOBALS['tmpl']->templateTitles[$cVal]) . '</strong></td></tr>
171 <tr>
172 <td><img src="clear.gif" width="3" height="1" alt="" /></td>
173 <td class="bgColor2"><table border="0" cellpadding="0" cellspacing="0" class="bgColor0" width="100%"><tr><td nowrap="nowrap">' .
174 $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) .
175 '</td></tr></table>
176 </td>
177 </tr>
178 ';
179 if (t3lib_div::_GET('template') != "all") {
180 break;
181 }
182 }
183 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
184 next($GLOBALS['tmpl']->clearList_const);
185 }
186 $theOutput .= '
187 </table>
188 ';
189 }
190
191 // Output setup
192 if (t3lib_div::_GET('template')) {
193 $theOutput .= $this->pObj->doc->spacer(15);
194 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('setup', TRUE), "", 0, 1);
195 $theOutput .= $this->pObj->doc->sectionEnd();
196 $theOutput .= '
197 <table border="0" cellpadding="1" cellspacing="0">
198 ';
199 $GLOBALS['tmpl']->ext_lineNumberOffset = 0;
200 $GLOBALS['tmpl']->ext_lineNumberOffset_mode = "setup";
201 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, t3lib_TSparser::checkIncludeLines("" . $GLOBALS["TYPO3_CONF_VARS"]["FE"]["defaultTypoScript_setup"]))) + 1;
202
203 reset($GLOBALS['tmpl']->clearList_setup);
204 foreach ($GLOBALS['tmpl']->config as $key => $val) {
205 if (current($GLOBALS['tmpl']->clearList_setup) == t3lib_div::_GET('template') || t3lib_div::_GET('template') == 'all') {
206 $theOutput .= '
207 <tr>
208 <td><img src="clear.gif" width="3" height="1" alt="" /></td><td class="bgColor2"><strong>' . htmlspecialchars($GLOBALS['tmpl']->templateTitles[current($GLOBALS['tmpl']->clearList_setup)]) . '</strong></td></tr>
209 <tr>
210 <td><img src="clear.gif" width="3" height="1" alt="" /></td>
211 <td class="bgColor2"><table border="0" cellpadding="0" cellspacing="0" class="bgColor0" width="100%"><tr><td nowrap="nowrap">' .
212 $GLOBALS['tmpl']->ext_outputTS(
213 array($val),
214 $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'],
215 $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'],
216 $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'],
217 $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'],
218 0) .
219 '</td></tr></table>
220 </td>
221 </tr>
222 ';
223 if (t3lib_div::_GET('template') != "all") {
224 break;
225 }
226 }
227 $GLOBALS['tmpl']->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
228 next($GLOBALS['tmpl']->clearList_setup);
229 }
230 $theOutput .= '
231 </table>
232 ';
233 }
234
235 return $theOutput;
236 }
237 }
238
239 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_analyzer/class.tx_tstemplateanalyzer.php"]) {
240 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_analyzer/class.tx_tstemplateanalyzer.php"]);
241 }
242
243 ?>