[BUGFIX] Configuration Tool creates invalid extTables.php file
[Packages/TYPO3.CMS.git] / typo3 / sysext / lowlevel / config / index.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 * Module: Config
29 *
30 * This module lets you view the config variables around TYPO3.
31 *
32 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
33 */
34 /**
35 * [CLASS/FUNCTION INDEX of SCRIPT]
36 *
37 *
38 *
39 * 72: class SC_mod_tools_config_index
40 * 89: function init()
41 * 103: function jumpToUrl(URL)
42 * 117: function menuConfig()
43 * 144: function main()
44 * 268: function printContent()
45 *
46 * TOTAL FUNCTIONS: 5
47 * (This index is automatically created/updated by the extension "extdeveval")
48 *
49 */
50
51 unset($MCONF);
52 require ('conf.php');
53 require ($BACK_PATH.'init.php');
54 require ($BACK_PATH.'template.php');
55 $GLOBALS['LANG']->includeLLFile('EXT:lowlevel/config/locallang.xml');
56
57 $BE_USER->modAccess($MCONF,1);
58
59
60
61
62
63
64
65 /**
66 * Script class for the Config module
67 *
68 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
69 * @package TYPO3
70 * @subpackage tx_lowlevel
71 */
72 class SC_mod_tools_config_index {
73
74 var $MCONF = array();
75 var $MOD_MENU = array();
76 var $MOD_SETTINGS = array();
77
78 /**
79 * document template object
80 *
81 * @var noDoc
82 */
83 var $doc;
84
85 var $include_once = array();
86 var $content;
87
88
89
90 /**
91 * Initialization
92 *
93 * @return void
94 */
95 function init() {
96 global $BACK_PATH;
97
98 $this->MCONF = $GLOBALS['MCONF'];
99
100 $this->menuConfig();
101
102 $this->doc = t3lib_div::makeInstance('template');
103 $this->doc->backPath = $BACK_PATH;
104 $this->doc->setModuleTemplate('templates/config.html');
105
106 // JavaScript
107 $this->doc->JScode = '
108 <script language="javascript" type="text/javascript">
109 script_ended = 0;
110 function jumpToUrl(URL) {
111 window.location.href = URL;
112 }
113 </script>
114 ';
115
116 $this->doc->form = '<form action="" method="post">';
117 }
118
119 /**
120 * Menu Configuration
121 *
122 * @return void
123 */
124 function menuConfig() {
125 global $TYPO3_CONF_VARS;
126
127 // MENU-ITEMS:
128 // If array, then it's a selector box menu
129 // If empty string it's just a variable, that'll be saved.
130 // Values NOT in this array will not be saved in the settings-array for the module.
131 $this->MOD_MENU = array(
132 'function' => array(
133 0 => $GLOBALS['LANG']->getLL('typo3ConfVars', true),
134 1 => $GLOBALS['LANG']->getLL('tca', true),
135 2 => $GLOBALS['LANG']->getLL('tcaDescr', true),
136 3 => $GLOBALS['LANG']->getLL('loadedExt', true),
137 4 => $GLOBALS['LANG']->getLL('t3services', true),
138 5 => $GLOBALS['LANG']->getLL('tbemodules', true),
139 6 => $GLOBALS['LANG']->getLL('tbemodulesext', true),
140 7 => $GLOBALS['LANG']->getLL('tbeStyles', true),
141 8 => $GLOBALS['LANG']->getLL('beUser', true),
142 9 => $GLOBALS['LANG']->getLL('usersettings', true),
143 ),
144 'regexsearch' => '',
145 'fixedLgd' => ''
146 );
147
148 // CLEANSE SETTINGS
149 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
150 }
151
152 /**
153 * [Describe function...]
154 *
155 * @return [type] ...
156 */
157 function main() {
158
159 $arrayBrowser = t3lib_div::makeInstance('t3lib_arrayBrowser');
160
161 $this->content= $this->doc->header($GLOBALS['LANG']->getLL('configuration', true));
162 $this->content.= $this->doc->spacer(5);
163
164 $this->content .= '<div id="lowlevel-config">
165 <label for="search_field">' . $GLOBALS['LANG']->getLL('enterSearchPhrase', true) . '</label>
166 <input type="text" id="search_field" name="search_field" value="' . htmlspecialchars($search_field) . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . ' />
167 <input type="submit" name="search" id="search" value="' . $GLOBALS['LANG']->getLL('search', true) . '" />';
168 $this->content .= t3lib_BEfunc::getFuncCheck(0,'SET[regexsearch]',$this->MOD_SETTINGS['regexsearch'],'','','id="checkRegexsearch"') .
169 '<label for="checkRegexsearch">' . $GLOBALS['LANG']->getLL('useRegExp', true) . '</label>';
170
171 $this->content.= t3lib_BEfunc::getFuncCheck(0, 'SET[fixedLgd]', $this->MOD_SETTINGS['fixedLgd'], '', '', 'id="checkFixedLgd"') .
172 '<label for="checkFixedLgd">' . $GLOBALS['LANG']->getLL('cropLines', true) . '</label>
173 </div>';
174
175 $this->content.= $this->doc->spacer(5);
176
177 switch($this->MOD_SETTINGS['function']) {
178 case 0:
179 $theVar = $GLOBALS['TYPO3_CONF_VARS'];
180 t3lib_div::naturalKeySortRecursive($theVar);
181 $arrayBrowser->varName = '$TYPO3_CONF_VARS';
182 break;
183 case 1:
184 foreach ($GLOBALS['TCA'] as $table => $config) {
185 t3lib_div::loadTCA($table);
186 }
187 $theVar = $GLOBALS['TCA'];
188 t3lib_div::naturalKeySortRecursive($theVar);
189 $arrayBrowser->varName = '$TCA';
190 break;
191 case 2:
192 $theVar = $GLOBALS['TCA_DESCR'];
193 t3lib_div::naturalKeySortRecursive($theVar);
194 $arrayBrowser->varName = '$TCA_DESCR';
195 break;
196 case 3:
197 $theVar = $GLOBALS['TYPO3_LOADED_EXT'];
198 t3lib_div::naturalKeySortRecursive($theVar);
199 $arrayBrowser->varName = '$TYPO3_LOADED_EXT';
200 break;
201 case 4:
202 $theVar = $GLOBALS['T3_SERVICES'];
203 t3lib_div::naturalKeySortRecursive($theVar);
204 $arrayBrowser->varName = '$T3_SERVICES';
205 break;
206 case 5:
207 $theVar = $GLOBALS['TBE_MODULES'];
208 t3lib_div::naturalKeySortRecursive($theVar);
209 $arrayBrowser->varName = '$TBE_MODULES';
210 break;
211 case 6:
212 $theVar = $GLOBALS['TBE_MODULES_EXT'];
213 t3lib_div::naturalKeySortRecursive($theVar);
214 $arrayBrowser->varName = '$TBE_MODULES_EXT';
215 break;
216 case 7:
217 $theVar = $GLOBALS['TBE_STYLES'];
218 t3lib_div::naturalKeySortRecursive($theVar);
219 $arrayBrowser->varName = '$TBE_STYLES';
220 break;
221 case 8:
222 $theVar = $GLOBALS['BE_USER']->uc;
223 t3lib_div::naturalKeySortRecursive($theVar);
224 $arrayBrowser->varName = '$BE_USER->uc';
225 break;
226 case 9:
227 $theVar = $GLOBALS['TYPO3_USER_SETTINGS'];
228 t3lib_div::naturalKeySortRecursive($theVar);
229 $arrayBrowser->varName = '$TYPO3_USER_SETTINGS';
230 break;
231 default:
232 $theVar = array();
233 break;
234 }
235
236
237 // Update node:
238 $update = 0;
239 $node = t3lib_div::_GET('node');
240 if (is_array($node)) { // If any plus-signs were clicked, it's registred.
241 $this->MOD_SETTINGS['node_'.$this->MOD_SETTINGS['function']] = $arrayBrowser->depthKeys($node, $this->MOD_SETTINGS['node_'.$this->MOD_SETTINGS['function']]);
242 $update = 1;
243 }
244 if ($update) {
245 $GLOBALS['BE_USER']->pushModuleData($this->MCONF['name'],$this->MOD_SETTINGS);
246 }
247
248 $arrayBrowser->depthKeys = $this->MOD_SETTINGS['node_'.$this->MOD_SETTINGS['function']];
249 $arrayBrowser->regexMode = $this->MOD_SETTINGS['regexsearch'];
250 $arrayBrowser->fixedLgd = $this->MOD_SETTINGS['fixedLgd'];
251 $arrayBrowser->searchKeysToo = TRUE;
252
253
254 $search_field = t3lib_div::_GP('search_field');
255 if (t3lib_div::_POST('search') && trim($search_field)) { // If any POST-vars are send, update the condition array
256 $arrayBrowser->depthKeys=$arrayBrowser->getSearchKeys($theVar, '', $search_field, array());
257 }
258
259 $tree = $arrayBrowser->tree($theVar, '', '');
260
261 $label = $this->MOD_MENU['function'][$this->MOD_SETTINGS['function']];
262 $this->content.= $this->doc->sectionEnd();
263
264 // Variable name:
265 if (t3lib_div::_GP('varname')) {
266 $line = t3lib_div::_GP('_') ? t3lib_div::_GP('_') : t3lib_div::_GP('varname');
267 if (t3lib_div::_GP('writetoexttables')) { // Write the line to extTables.php
268 // change value to $GLOBALS
269 $length = strpos($line, '[');
270 $var = substr($line, 0, $length);
271 $changedLine = '$GLOBALS[\'' . substr($line, 1, $length - 1) . '\']' . substr($line, $length);
272 // load current extTables.php
273 $extTables = t3lib_div::getURL(PATH_typo3conf . TYPO3_extTableDef_script);
274 if ($var === '$TCA') {
275 // check if we are editing the TCA
276 preg_match_all('/\[\'([^\']+)\'\]/', $line, $parts);
277 if ($parts[1][1] !== 'ctrl') {
278 // anything else than ctrl section requires to load TCA
279 $loadTCA = 't3lib_div::loadTCA(\'' . $parts[1][0] . '\');';
280 if (strpos($extTables, $loadTCA) === FALSE) {
281 // check if the loadTCA statement is not already present in the file
282 $changedLine = $loadTCA . LF . $changedLine;
283 }
284 }
285 }
286
287 // insert line in extTables.php
288 $extTables = preg_replace('/<\?php|\?>/is', '', $extTables);
289 $extTables = '<?php' . (empty($extTables) ? LF : '') . $extTables . $changedLine . LF . '?>';
290 $success = t3lib_div::writeFile(PATH_typo3conf . TYPO3_extTableDef_script, $extTables);
291 if ($success) {
292 // show flash message
293 $flashMessage = t3lib_div::makeInstance(
294 't3lib_FlashMessage',
295 '',
296 sprintf($GLOBALS['LANG']->getLL('writeMessage', TRUE), TYPO3_extTableDef_script, '<br />', '<strong>' . nl2br($changedLine) . '</strong>'),
297 t3lib_FlashMessage::OK
298 );
299 } else {
300 // Error: show flash message
301 $flashMessage = t3lib_div::makeInstance(
302 't3lib_FlashMessage',
303 '',
304 sprintf($GLOBALS['LANG']->getLL('writeMessageFailed', TRUE), TYPO3_extTableDef_script),
305 t3lib_FlashMessage::ERROR
306 );
307 }
308 $this->content .= $flashMessage->render();
309 }
310 $this->content .= '<div id="lowlevel-config-var">
311 <strong>' . $GLOBALS['LANG']->getLL('variable', TRUE) . '</strong><br />
312 <input type="text" name="_" value="'.trim(htmlspecialchars($line)).'" size="120" /><br/>';
313
314 if (TYPO3_extTableDef_script !== '' && ($this->MOD_SETTINGS['function'] === '1' || $this->MOD_SETTINGS['function'] === '4')) {
315 // write only for $TCA and TBE_STYLES if TYPO3_extTableDef_script is defined
316 $this->content .= '<br /><input type="submit" name="writetoexttables" value="' .
317 $GLOBALS['LANG']->getLL('writeValue', TRUE) . '" /></div>';
318 } else {
319 $this->content .= $GLOBALS['LANG']->getLL('copyPaste', TRUE) . LF . '</div>';
320 }
321
322 }
323
324 $this->content.= '<br /><table border="0" cellpadding="0" cellspacing="0" class="t3-tree t3-tree-config">';
325 $this->content.= '<tr>
326 <th class="t3-row-header t3-tree-config-header">' . $label . '</th>
327 </tr>
328 <tr>
329 <td>' . $tree . '</td>
330 </tr>
331 </table>
332 ';
333
334
335 // Setting up the buttons and markers for docheader
336 $docHeaderButtons = $this->getButtons();
337 $markers = array(
338 'CSH' => $docHeaderButtons['csh'],
339 'FUNC_MENU' => $this->getFuncMenu(),
340 'CONTENT' => $this->content
341 );
342
343 // Build the <body> for the module
344 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
345 // Renders the module page
346 $this->content = $this->doc->render(
347 'Configuration',
348 $this->content
349 );
350 }
351
352 /**
353 * Print output to browser
354 *
355 * @return void
356 */
357 function printContent() {
358 echo $this->content;
359 }
360
361 /**
362 * Create the panel of buttons for submitting the form or otherwise perform operations.
363 *
364 * @return array all available buttons as an assoc. array
365 */
366 protected function getButtons() {
367
368 $buttons = array(
369 'csh' => '',
370 'shortcut' => ''
371 );
372 // CSH
373 //$buttons['csh'] = t3lib_BEfunc::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']);
374
375 // Shortcut
376 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
377 $buttons['shortcut'] = $this->doc->makeShortcutIcon('','function',$this->MCONF['name']);
378 }
379 return $buttons;
380 }
381
382 /**
383 * Create the function menu
384 *
385 * @return string HTML of the function menu
386 */
387 protected function getFuncMenu() {
388 $funcMenu = t3lib_BEfunc::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']);
389 return $funcMenu;
390 }
391 }
392
393
394 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/lowlevel/config/index.php'])) {
395 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/lowlevel/config/index.php']);
396 }
397
398
399
400
401 // Make instance:
402 $SOBE = t3lib_div::makeInstance('SC_mod_tools_config_index');
403 $SOBE->init();
404 $SOBE->main();
405 $SOBE->printContent();
406 ?>