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