Template tools (Web>Template) had hard-coded background colours
[Packages/TYPO3.CMS.git] / typo3 / sysext / tstemplate_analyzer / class.tx_tstemplateanalyzer.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 Kasper Skaarhoj (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 require_once(PATH_t3lib."class.t3lib_extobjbase.php");
32
33 class tx_tstemplateanalyzer extends t3lib_extobjbase {
34 function modMenu() {
35 global $LANG;
36
37 return Array (
38 "ts_analyzer_checkSetup" => "",
39 "ts_analyzer_checkConst" => "",
40 "ts_analyzer_checkLinenum" => "",
41 "ts_analyzer_checkComments" => "",
42 "ts_analyzer_checkCrop" => "",
43 "ts_analyzer_checkSyntax" => "",
44 "ts_analyzer_checkSyntaxBlockmode" => "",
45 );
46 }
47
48 function initialize_editor($pageId,$template_uid=0) {
49 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
50 global $tmpl,$tplRow,$theConstants,$rootLine;
51
52 $tmpl = t3lib_div::makeInstance("t3lib_tsparser_ext"); // Defined global here!
53 $tmpl->tt_track = 0; // Do not log time-performance information
54 $tmpl->init();
55
56 // Gets the rootLine
57 $sys_page = t3lib_div::makeInstance("t3lib_pageSelect");
58 $rootLine = $sys_page->getRootLine($pageId);
59 $tmpl->runThroughTemplates($rootLine,$template_uid); // This generates the constants/config + hierarchy info for the template.
60
61 $tplRow = $tmpl->ext_getFirstTemplate($pageId,$template_uid); // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
62 if (is_array($tplRow)) { // IF there was a template...
63 return 1;
64 }
65 }
66 function main() {
67 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
68 global $SOBE,$BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
69 global $tmpl,$tplRow,$theConstants,$rootLine;
70
71 // **************************
72 // Checking for more than one template an if, set a menu...
73 // **************************
74 $manyTemplatesMenu = $this->pObj->templateMenu();
75 $template_uid = 0;
76 if ($manyTemplatesMenu) {
77 $template_uid = $this->pObj->MOD_SETTINGS["templatesOnPage"];
78 }
79
80 // **************************
81 // Main
82 // **************************
83
84 // BUGBUG: Should we check if the uset may at all read and write template-records???
85 $existTemplate = $this->initialize_editor($this->pObj->id,$template_uid); // initialize
86 if ($existTemplate) {
87 $theOutput.=$this->pObj->doc->divider(5);
88 $theOutput.=$this->pObj->doc->section("Current template:",'<img src="'.$BACK_PATH.t3lib_iconWorks::getIcon("sys_template",$tplRow).'" width=18 height=16 align=top><b>'.$this->pObj->linkWrapTemplateTitle($tplRow["title"]).'</b>'.htmlspecialchars(trim($tplRow["sitetitle"])?' - ('.$tplRow["sitetitle"].')':''));
89 }
90 if ($manyTemplatesMenu) {
91 $theOutput.=$this->pObj->doc->section("",$manyTemplatesMenu);
92 }
93
94 // debug($tmpl->hierarchyInfo);
95
96 $tmpl->clearList_const_temp = array_flip($tmpl->clearList_const);
97 $tmpl->clearList_setup_temp = array_flip($tmpl->clearList_setup);
98
99 $pointer = count($tmpl->hierarchyInfo);
100 $tmpl->hierarchyInfoArr = $tmpl->ext_process_hierarchyInfo(array(), $pointer);
101 $tmpl->procesIncludes();
102
103 $hierarArr = array();
104 $head= '<tr>';
105 $head.= '<td class="bgColor2"><b>Title&nbsp;&nbsp;</b></td>';
106 $head.= '<td class="bgColor2"><b>Rootlevel&nbsp;&nbsp;</b></td>';
107 $head.= '<td class="bgColor2"><b>C. Setup&nbsp;&nbsp;</b></td>';
108 $head.= '<td class="bgColor2"><b>C. Const&nbsp;&nbsp;</b></td>';
109 $head.= '<td class="bgColor2"><b>PID/RL&nbsp;&nbsp;</b></td>';
110 $head.= '<td class="bgColor2"><b>NL&nbsp;&nbsp;</b></td>';
111 $head.= '</tr>';
112 $hierar = implode(array_reverse($tmpl->ext_getTemplateHierarchyArr($tmpl->hierarchyInfoArr, "",array(),1)),"");
113 $hierar= '<table border=0 cellpadding=0 cellspacing=0>'.$head.$hierar.'</table>';
114
115 $theOutput.=$this->pObj->doc->spacer(5);
116 $theOutput.=$this->pObj->doc->section("Template hierarchy:",$hierar,0,1);
117
118
119 // Output constants
120 $theOutput.=$this->pObj->doc->spacer(25);
121 $theOutput.=$this->pObj->doc->divider(0);
122 $theOutput.=$this->pObj->doc->section("",
123 "Linenumbers".t3lib_BEfunc::getFuncCheck($this->pObj->id,"SET[ts_analyzer_checkLinenum]",$this->pObj->MOD_SETTINGS["ts_analyzer_checkLinenum"]).
124 "&nbsp;&nbsp;&nbsp;Syntax HL".t3lib_BEfunc::getFuncCheck($this->pObj->id,"SET[ts_analyzer_checkSyntax]",$this->pObj->MOD_SETTINGS["ts_analyzer_checkSyntax"]).
125 (!$this->pObj->MOD_SETTINGS["ts_analyzer_checkSyntax"] ?
126 "&nbsp;&nbsp;&nbsp;Comments".t3lib_BEfunc::getFuncCheck($this->pObj->id,"SET[ts_analyzer_checkComments]",$this->pObj->MOD_SETTINGS["ts_analyzer_checkComments"]).
127 "&nbsp;&nbsp;&nbsp;Crop lines".t3lib_BEfunc::getFuncCheck($this->pObj->id,"SET[ts_analyzer_checkCrop]",$this->pObj->MOD_SETTINGS["ts_analyzer_checkCrop"])
128 :
129 "&nbsp;&nbsp;&nbsp;Block mode".t3lib_BEfunc::getFuncCheck($this->pObj->id,"SET[ts_analyzer_checkSyntaxBlockmode]",$this->pObj->MOD_SETTINGS["ts_analyzer_checkSyntaxBlockmode"])
130 )
131 );
132 $theOutput.=$this->pObj->doc->divider(2);
133 //$theOutput.=$this->pObj->doc->section("Constants:",t3lib_BEfunc::getFuncCheck($this->pObj->id,"SET[ts_analyzer_checkConst]",$this->pObj->MOD_SETTINGS["ts_analyzer_checkConst"]).fw("Enable"));
134 $theOutput.=$this->pObj->doc->section("Constants:","",0,1);
135 $theOutput.=$this->pObj->doc->sectionEnd();
136 if (1==1 || $this->pObj->MOD_SETTINGS["ts_analyzer_checkConst"]) {
137 $theOutput.='
138 <table border=0 cellpadding=1 cellspacing=0>
139 ';
140 $tmpl->ext_lineNumberOffset=-2; // Don't know why -2 and not 0... :-) But works.
141 $tmpl->ext_lineNumberOffset_mode="const";
142 $tmpl->ext_lineNumberOffset+=count(explode(chr(10),t3lib_TSparser::checkIncludeLines("".$GLOBALS["TYPO3_CONF_VARS"]["FE"]["defaultTypoScript_constants"])))+1;
143
144 reset($tmpl->constants);
145 reset($tmpl->clearList_const);
146 while(list($key,$val)=each($tmpl->constants)) {
147 $cVal = current($tmpl->clearList_const);
148 if ($cVal==t3lib_div::_GET('template') || t3lib_div::_GET('template')=="all") {
149 $theOutput.='
150 <tr>
151 <td><img src=clear.gif width=3 height=1></td><td class="bgColor2"><b>'.$tmpl->templateTitles[$cVal].'</b></td></tr>
152 <tr>
153 <td><img src=clear.gif width=3 height=1></td>
154 <td class="bgColor2"><table border=0 cellpadding=0 cellspacing=0 class="bgColor4" width="100%"><tr><td nowrap>'.$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"],$this->pObj->MOD_SETTINGS["ts_analyzer_checkSyntaxBlockmode"]).'</td></tr></table>
155 </td>
156 </tr>
157 ';
158 if (t3lib_div::_GET('template')!="all") break;
159 }
160 $tmpl->ext_lineNumberOffset+=count(explode(chr(10),$val))+1;
161 next($tmpl->clearList_const);
162 }
163 $theOutput.='
164 </table>
165 ';
166 }
167
168 // Output setup
169 $theOutput.=$this->pObj->doc->spacer(15);
170 //$theOutput.=$this->pObj->doc->section("SETUP:",t3lib_BEfunc::getFuncCheck($this->pObj->id,"SET[ts_analyzer_checkSetup]",$this->pObj->MOD_SETTINGS["ts_analyzer_checkSetup"]).fw("Enable"));
171 $theOutput.=$this->pObj->doc->section("SETUP:","",0,1);
172 $theOutput.=$this->pObj->doc->sectionEnd();
173 if (1==1 || $this->pObj->MOD_SETTINGS["ts_analyzer_checkSetup"]) {
174 $theOutput.='
175 <table border=0 cellpadding=1 cellspacing=0>
176 ';
177 $tmpl->ext_lineNumberOffset=0;
178 $tmpl->ext_lineNumberOffset_mode="setup";
179 $tmpl->ext_lineNumberOffset+=count(explode(chr(10),t3lib_TSparser::checkIncludeLines("".$GLOBALS["TYPO3_CONF_VARS"]["FE"]["defaultTypoScript_setup"])))+1;
180
181 reset($tmpl->config);
182 reset($tmpl->clearList_setup);
183 while(list($key,$val)=each($tmpl->config)) {
184 if (current($tmpl->clearList_setup)==t3lib_div::_GET('template') || t3lib_div::_GET('template')=="all") {
185 $theOutput.='
186 <tr>
187 <td><img src=clear.gif width=3 height=1></td><td class="bgColor2"><b>'.$tmpl->templateTitles[current($tmpl->clearList_setup)].'</b></td></tr>
188 <tr>
189 <td><img src=clear.gif width=3 height=1></td>
190 <td class="bgColor2"><table border=0 cellpadding=0 cellspacing=0 class="bgColor4" width="100%"><tr><td nowrap>'.$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"],$this->pObj->MOD_SETTINGS["ts_analyzer_checkSyntaxBlockmode"]).'</td></tr></table>
191 </td>
192 </tr>
193 ';
194 if (t3lib_div::_GET('template')!="all") break;
195 }
196 $tmpl->ext_lineNumberOffset+=count(explode(chr(10),$val))+1;
197 next($tmpl->clearList_setup);
198 }
199 $theOutput.='
200 </table>
201 ';
202 }
203 return $theOutput;
204 }
205 }
206
207 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_analyzer/class.tx_tstemplateanalyzer.php"]) {
208 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_analyzer/class.tx_tstemplateanalyzer.php"]);
209 }
210 ?>