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