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