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