Added feature #14490: A new skin for the TYPO3 Backend (Thanks to Steffen Gebert...
[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 $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,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($GLOBALS['LANG']->getLL('currentTemplate', true) ,
95 t3lib_iconWorks::getSpriteIconForRecord('sys_template', $tplRow) . '<b>' .
96 $this->pObj->linkWrapTemplateTitle($tplRow["title"]) . '</b>' .
97 htmlspecialchars(trim($tplRow["sitetitle"]) ? ' - (' . $tplRow["sitetitle"] . ')' : ''));
98 }
99 if ($manyTemplatesMenu) {
100 $theOutput.=$this->pObj->doc->section("",$manyTemplatesMenu);
101 }
102
103 // debug($tmpl->hierarchyInfo);
104
105 $tmpl->clearList_const_temp = array_flip($tmpl->clearList_const);
106 $tmpl->clearList_setup_temp = array_flip($tmpl->clearList_setup);
107
108 $pointer = count($tmpl->hierarchyInfo);
109 $tmpl->hierarchyInfoArr = $tmpl->ext_process_hierarchyInfo(array(), $pointer);
110 $tmpl->procesIncludes();
111
112 $hierarArr = array();
113 $head = '<tr class="t3-row-header">';
114 $head.= '<td>' . $GLOBALS['LANG']->getLL('title', true) . '</td>';
115 $head.= '<td>' . $GLOBALS['LANG']->getLL('rootlevel', true) . '</td>';
116 $head.= '<td>' . $GLOBALS['LANG']->getLL('clearSetup', true) . '</td>';
117 $head.= '<td>' . $GLOBALS['LANG']->getLL('clearConstants', true) . '</td>';
118 $head.= '<td>' . $GLOBALS['LANG']->getLL('pid', true) . '</td>';
119 $head.= '<td>' . $GLOBALS['LANG']->getLL('rootline', true) . '</td>';
120 $head.= '<td>' . $GLOBALS['LANG']->getLL('nextLevel', true) . '</td>';
121 $head.= '</tr>';
122 $hierar = implode(array_reverse($tmpl->ext_getTemplateHierarchyArr($tmpl->hierarchyInfoArr, "", array(), 1)), "");
123 $hierar= '<table id="ts-analyzer" border="0" cellpadding="0" cellspacing="1">' . $head . $hierar . '</table>';
124
125 $theOutput.=$this->pObj->doc->spacer(5);
126 $theOutput.=$this->pObj->doc->section($GLOBALS['LANG']->getLL('templateHierarchy', true), $hierar, 0, 1);
127
128 $completeLink = '<p><a href="index.php?id=' . $GLOBALS['SOBE']->id . '&amp;template=all">' . $GLOBALS['LANG']->getLL('viewCompleteTS', TRUE) . '</a></p>';
129 $theOutput .= $this->pObj->doc->spacer(5);
130 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('completeTS', TRUE), $completeLink, 0, 1);
131
132
133 // Output options
134 $theOutput.=$this->pObj->doc->spacer(25);
135 $theOutput.=$this->pObj->doc->divider(0);
136 $theOutput.=$this->pObj->doc->section($GLOBALS['LANG']->getLL('displayOptions', true), '', 1, 1);
137 $addParams = t3lib_div::_GET('template') ? '&template=' . t3lib_div::_GET('template') : '';
138 $theOutput .= '<div class="tst-analyzer-options">' .
139 t3lib_BEfunc::getFuncCheck($this->pObj->id, "SET[ts_analyzer_checkLinenum]", $this->pObj->MOD_SETTINGS["ts_analyzer_checkLinenum"], '', $addParams, 'id="checkTs_analyzer_checkLinenum"') .
140 '<label for="checkTs_analyzer_checkLinenum">' . $GLOBALS['LANG']->getLL('lineNumbers', true) . '</label> ' .
141 t3lib_BEfunc::getFuncCheck($this->pObj->id, "SET[ts_analyzer_checkSyntax]", $this->pObj->MOD_SETTINGS["ts_analyzer_checkSyntax"], '', $addParams, 'id="checkTs_analyzer_checkSyntax"') .
142 '<label for="checkTs_analyzer_checkSyntax">' . $GLOBALS['LANG']->getLL('syntaxHighlight', true) . '</label> ' .
143 (!$this->pObj->MOD_SETTINGS["ts_analyzer_checkSyntax"] ?
144 t3lib_BEfunc::getFuncCheck($this->pObj->id, "SET[ts_analyzer_checkComments]", $this->pObj->MOD_SETTINGS["ts_analyzer_checkComments"], '', $addParams, 'id="checkTs_analyzer_checkComments"') .
145 '<label for="checkTs_analyzer_checkComments">' . $GLOBALS['LANG']->getLL('comments', true) . '</label> ' .
146 t3lib_BEfunc::getFuncCheck($this->pObj->id, "SET[ts_analyzer_checkCrop]", $this->pObj->MOD_SETTINGS["ts_analyzer_checkCrop"], '', $addParams, 'id="checkTs_analyzer_checkCrop"') .
147 '<label for="checkTs_analyzer_checkCrop">' . $GLOBALS['LANG']->getLL('cropLines', true) . '</label> '
148 :
149 t3lib_BEfunc::getFuncCheck($this->pObj->id, "SET[ts_analyzer_checkSyntaxBlockmode]", $this->pObj->MOD_SETTINGS["ts_analyzer_checkSyntaxBlockmode"], '', $addParams, 'id="checkTs_analyzer_checkSyntaxBlockmode"') .
150 '<label for="checkTs_analyzer_checkSyntaxBlockmode">' . $GLOBALS['LANG']->getLL('blockMode', true) . '</label> '
151 ) . '</div>';
152
153
154
155 // Output Constants
156 if (t3lib_div::_GET('template')) {
157 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('constants', true), "", 0, 1);
158 $theOutput .= $this->pObj->doc->sectionEnd();
159 $theOutput .= '
160 <table border=0 cellpadding=1 cellspacing=0>
161 ';
162 $tmpl->ext_lineNumberOffset = -2; // Don't know why -2 and not 0... :-) But works.
163 $tmpl->ext_lineNumberOffset_mode = "const";
164 $tmpl->ext_lineNumberOffset += count(explode(LF, t3lib_TSparser::checkIncludeLines("" . $GLOBALS["TYPO3_CONF_VARS"]["FE"]["defaultTypoScript_constants"]))) + 1;
165
166 reset($tmpl->clearList_const);
167 foreach ($tmpl->constants as $key => $val) {
168 $cVal = current($tmpl->clearList_const);
169 if ($cVal == t3lib_div::_GET('template') || t3lib_div::_GET('template') == "all") {
170 $theOutput .= '
171 <tr>
172 <td><img src="clear.gif" width="3" height="1" /></td><td class="bgColor2"><b>' . $tmpl->templateTitles[$cVal] . '</b></td></tr>
173 <tr>
174 <td><img src="clear.gif" width="3" height="1" /></td>
175 <td class="bgColor2"><table border=0 cellpadding=0 cellspacing=0 class="bgColor0" width="100%"><tr><td nowrap>' .
176 $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"]) .
177 '</td></tr></table>
178 </td>
179 </tr>
180 ';
181 if (t3lib_div::_GET('template') != "all") {
182 break;
183 }
184 }
185 $tmpl->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
186 next($tmpl->clearList_const);
187 }
188 $theOutput .= '
189 </table>
190 ';
191 }
192
193 // Output setup
194 if (t3lib_div::_GET('template')) {
195 $theOutput .= $this->pObj->doc->spacer(15);
196 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('setup', true), "", 0, 1);
197 $theOutput .= $this->pObj->doc->sectionEnd();
198 $theOutput .= '
199 <table border=0 cellpadding=1 cellspacing=0>
200 ';
201 $tmpl->ext_lineNumberOffset = 0;
202 $tmpl->ext_lineNumberOffset_mode = "setup";
203 $tmpl->ext_lineNumberOffset += count(explode(LF, t3lib_TSparser::checkIncludeLines("" . $GLOBALS["TYPO3_CONF_VARS"]["FE"]["defaultTypoScript_setup"]))) + 1;
204
205 reset($tmpl->clearList_setup);
206 foreach ($tmpl->config as $key => $val) {
207 if (current($tmpl->clearList_setup) == t3lib_div::_GET('template') || t3lib_div::_GET('template') == "all") {
208 $theOutput .= '
209 <tr>
210 <td><img src="clear.gif" width="3" height="1" /></td><td class="bgColor2"><b>' . $tmpl->templateTitles[current($tmpl->clearList_setup)] . '</b></td></tr>
211 <tr>
212 <td><img src="clear.gif" width="3" height="1" /></td>
213 <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>
214 </td>
215 </tr>
216 ';
217 if (t3lib_div::_GET('template') != "all") {
218 break;
219 }
220 }
221 $tmpl->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
222 next($tmpl->clearList_setup);
223 }
224 $theOutput .= '
225 </table>
226 ';
227 }
228
229 return $theOutput;
230 }
231 }
232
233 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_analyzer/class.tx_tstemplateanalyzer.php"]) {
234 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_analyzer/class.tx_tstemplateanalyzer.php"]);
235 }
236
237 ?>