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