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