017139564894b9582ec4525216539e11448750d7
[Packages/TYPO3.CMS.git] / typo3 / sysext / lowlevel / Classes / View / ConfigurationView.php
1 <?php
2 namespace TYPO3\CMS\Lowlevel\View;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Script class for the Config module
22 *
23 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
24 */
25 class ConfigurationView {
26
27 /**
28 * @todo Define visibility
29 */
30 public $MCONF = array();
31
32 /**
33 * @todo Define visibility
34 */
35 public $MOD_MENU = array();
36
37 /**
38 * @todo Define visibility
39 */
40 public $MOD_SETTINGS = array();
41
42 /**
43 * Document template object
44 *
45 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
46 * @todo Define visibility
47 */
48 public $doc;
49
50 /**
51 * @todo Define visibility
52 */
53 public $include_once = array();
54
55 /**
56 * @todo Define visibility
57 */
58 public $content;
59
60 /**
61 * Constructor
62 */
63 public function __construct() {
64 $GLOBALS['LANG']->includeLLFile('EXT:lowlevel/config/locallang.xlf');
65 $GLOBALS['BE_USER']->modAccess($GLOBALS['MCONF'], 1);
66 }
67
68 /**
69 * Initialization
70 *
71 * @return void
72 * @todo Define visibility
73 */
74 public function init() {
75 global $BACK_PATH;
76 $this->MCONF = $GLOBALS['MCONF'];
77 $this->menuConfig();
78 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
79 $this->doc->backPath = $BACK_PATH;
80 $this->doc->setModuleTemplate('EXT:lowlevel/Resources/Private/Templates/config.html');
81 $this->doc->form = '<form action="" method="post">';
82 }
83
84 /**
85 * Menu Configuration
86 *
87 * @return void
88 * @todo Define visibility
89 */
90 public function menuConfig() {
91 global $TYPO3_CONF_VARS;
92 // MENU-ITEMS:
93 // If array, then it's a selector box menu
94 // If empty string it's just a variable, that'll be saved.
95 // Values NOT in this array will not be saved in the settings-array for the module.
96 $this->MOD_MENU = array(
97 'function' => array(
98 0 => $GLOBALS['LANG']->getLL('typo3ConfVars', TRUE),
99 1 => $GLOBALS['LANG']->getLL('tca', TRUE),
100 2 => $GLOBALS['LANG']->getLL('tcaDescr', TRUE),
101 3 => $GLOBALS['LANG']->getLL('loadedExt', TRUE),
102 4 => $GLOBALS['LANG']->getLL('t3services', TRUE),
103 5 => $GLOBALS['LANG']->getLL('tbemodules', TRUE),
104 6 => $GLOBALS['LANG']->getLL('tbemodulesext', TRUE),
105 7 => $GLOBALS['LANG']->getLL('tbeStyles', TRUE),
106 8 => $GLOBALS['LANG']->getLL('beUser', TRUE),
107 9 => $GLOBALS['LANG']->getLL('usersettings', TRUE)
108 ),
109 'regexsearch' => '',
110 'fixedLgd' => ''
111 );
112 // CLEANSE SETTINGS
113 $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->MCONF['name']);
114 }
115
116 /**
117 * [Describe function...]
118 *
119 * @return void
120 * @todo Define visibility
121 */
122 public function main() {
123 $arrayBrowser = GeneralUtility::makeInstance('TYPO3\\CMS\\Lowlevel\\Utility\\ArrayBrowser');
124 $label = $this->MOD_MENU['function'][$this->MOD_SETTINGS['function']];
125 $search_field = GeneralUtility::_GP('search_field');
126 $this->content = $this->doc->header($GLOBALS['LANG']->getLL('configuration', TRUE));
127 $this->content .= '<h2>' . $label . '</h2>';
128
129 $this->content .= '<div id="lowlevel-config">
130 <label for="search_field">' . $GLOBALS['LANG']->getLL('enterSearchPhrase', TRUE) . '</label>
131 <input type="text" id="search_field" name="search_field" value="' . htmlspecialchars($search_field) . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . ' />
132 <input type="submit" name="search" id="search" value="' . $GLOBALS['LANG']->getLL('search', TRUE) . '" />';
133
134 $this->content .= '<div class="checkbox">' .
135 '<label for="checkRegexsearch">' .
136 BackendUtility::getFuncCheck(0, 'SET[regexsearch]', $this->MOD_SETTINGS['regexsearch'], '', '', 'id="checkRegexsearch"') .
137 $GLOBALS['LANG']->getLL('useRegExp', TRUE) .
138 '</label>' .
139 '</div>';
140
141 $this->content .= '<div class="checkbox">' .
142 '<label for="checkFixedLgd">' .
143 BackendUtility::getFuncCheck(0, 'SET[fixedLgd]', $this->MOD_SETTINGS['fixedLgd'], '', '', 'id="checkFixedLgd"') .
144 $GLOBALS['LANG']->getLL('cropLines', TRUE) .
145 '</label>' .
146 '</div>';
147
148 $this->content .= '</div>';
149
150 $this->content .= $this->doc->spacer(5);
151 switch ($this->MOD_SETTINGS['function']) {
152 case 0:
153 $theVar = $GLOBALS['TYPO3_CONF_VARS'];
154 GeneralUtility::naturalKeySortRecursive($theVar);
155 $arrayBrowser->varName = '$TYPO3_CONF_VARS';
156 break;
157 case 1:
158 $theVar = $GLOBALS['TCA'];
159 GeneralUtility::naturalKeySortRecursive($theVar);
160 $arrayBrowser->varName = '$TCA';
161 break;
162 case 2:
163 $theVar = $GLOBALS['TCA_DESCR'];
164 GeneralUtility::naturalKeySortRecursive($theVar);
165 $arrayBrowser->varName = '$TCA_DESCR';
166 break;
167 case 3:
168 $theVar = $GLOBALS['TYPO3_LOADED_EXT'];
169 GeneralUtility::naturalKeySortRecursive($theVar);
170 $arrayBrowser->varName = '$TYPO3_LOADED_EXT';
171 break;
172 case 4:
173 $theVar = $GLOBALS['T3_SERVICES'];
174 GeneralUtility::naturalKeySortRecursive($theVar);
175 $arrayBrowser->varName = '$T3_SERVICES';
176 break;
177 case 5:
178 $theVar = $GLOBALS['TBE_MODULES'];
179 GeneralUtility::naturalKeySortRecursive($theVar);
180 $arrayBrowser->varName = '$TBE_MODULES';
181 break;
182 case 6:
183 $theVar = $GLOBALS['TBE_MODULES_EXT'];
184 GeneralUtility::naturalKeySortRecursive($theVar);
185 $arrayBrowser->varName = '$TBE_MODULES_EXT';
186 break;
187 case 7:
188 $theVar = $GLOBALS['TBE_STYLES'];
189 GeneralUtility::naturalKeySortRecursive($theVar);
190 $arrayBrowser->varName = '$TBE_STYLES';
191 break;
192 case 8:
193 $theVar = $GLOBALS['BE_USER']->uc;
194 GeneralUtility::naturalKeySortRecursive($theVar);
195 $arrayBrowser->varName = '$BE_USER->uc';
196 break;
197 case 9:
198 $theVar = $GLOBALS['TYPO3_USER_SETTINGS'];
199 GeneralUtility::naturalKeySortRecursive($theVar);
200 $arrayBrowser->varName = '$TYPO3_USER_SETTINGS';
201 break;
202 default:
203 $theVar = array();
204 }
205 // Update node:
206 $update = 0;
207 $node = GeneralUtility::_GET('node');
208 // If any plus-signs were clicked, it's registred.
209 if (is_array($node)) {
210 $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']] = $arrayBrowser->depthKeys($node, $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']]);
211 $update = 1;
212 }
213 if ($update) {
214 $GLOBALS['BE_USER']->pushModuleData($this->MCONF['name'], $this->MOD_SETTINGS);
215 }
216 $arrayBrowser->depthKeys = $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']];
217 $arrayBrowser->regexMode = $this->MOD_SETTINGS['regexsearch'];
218 $arrayBrowser->fixedLgd = $this->MOD_SETTINGS['fixedLgd'];
219 $arrayBrowser->searchKeysToo = TRUE;
220
221 // If any POST-vars are send, update the condition array
222 if (GeneralUtility::_POST('search') && trim($search_field)) {
223 $arrayBrowser->depthKeys = $arrayBrowser->getSearchKeys($theVar, '', $search_field, array());
224 }
225 // mask the encryption key to not show it as plaintext in the configuration module
226 if ($theVar == $GLOBALS['TYPO3_CONF_VARS']) {
227 $theVar['SYS']['encryptionKey'] = '***** (length: ' . strlen($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']) . ' characters)';
228 }
229 $tree = $arrayBrowser->tree($theVar, '', '');
230 $this->content .= $this->doc->sectionEnd();
231 // Variable name:
232 if (GeneralUtility::_GP('varname')) {
233 $line = GeneralUtility::_GP('_') ? GeneralUtility::_GP('_') : GeneralUtility::_GP('varname');
234 // Write the line to extTables.php
235 if (GeneralUtility::_GP('writetoexttables')) {
236 // change value to $GLOBALS
237 $length = strpos($line, '[');
238 $var = substr($line, 0, $length);
239 $changedLine = '$GLOBALS[\'' . substr($line, 1, ($length - 1)) . '\']' . substr($line, $length);
240 // load current extTables.php
241 $extTables = GeneralUtility::getUrl(PATH_typo3conf . TYPO3_extTableDef_script);
242 if ($var === '$TCA') {
243 // check if we are editing the TCA
244 preg_match_all('/\\[\'([^\']+)\'\\]/', $line, $parts);
245 }
246 // insert line in extTables.php
247 $extTables = preg_replace('/<\\?php|\\?>/is', '', $extTables);
248 $extTables = '<?php' . (empty($extTables) ? LF : '') . $extTables . $changedLine . LF . '?>';
249 $success = GeneralUtility::writeFile(PATH_typo3conf . TYPO3_extTableDef_script, $extTables);
250 if ($success) {
251 // show flash message
252 $flashMessage = GeneralUtility::makeInstance(
253 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
254 '',
255 sprintf(
256 $GLOBALS['LANG']->getLL('writeMessage', TRUE),
257 TYPO3_extTableDef_script,
258 '<br />',
259 '<strong>' . nl2br(htmlspecialchars($changedLine)) . '</strong>'
260 ),
261 \TYPO3\CMS\Core\Messaging\FlashMessage::OK
262 );
263 } else {
264 // Error: show flash message
265 $flashMessage = GeneralUtility::makeInstance(
266 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
267 '',
268 sprintf($GLOBALS['LANG']->getLL('writeMessageFailed', TRUE), TYPO3_extTableDef_script),
269 \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
270 );
271 }
272 $this->content .= $flashMessage->render();
273 }
274 $this->content .= '<div id="lowlevel-config-var">
275 <strong>' . $GLOBALS['LANG']->getLL('variable', TRUE) . '</strong><br />
276 <input type="text" name="_" value="' . trim(htmlspecialchars($line)) . '" size="120" /><br/>';
277 if (TYPO3_extTableDef_script !== '' && ($this->MOD_SETTINGS['function'] === '1' || $this->MOD_SETTINGS['function'] === '4')) {
278 // write only for $TCA and TBE_STYLES if TYPO3_extTableDef_script is defined
279 $this->content .= '<br /><input type="submit" name="writetoexttables" value="' . $GLOBALS['LANG']->getLL('writeValue', TRUE) . '" /></div>';
280 } else {
281 $this->content .= $GLOBALS['LANG']->getLL('copyPaste', TRUE) . LF . '</div>';
282 }
283 }
284 $this->content .= '<div class="nowrap">' . $tree . '</div>';
285
286 // Setting up the buttons and markers for docheader
287 $docHeaderButtons = $this->getButtons();
288 $markers = array(
289 'CSH' => $docHeaderButtons['csh'],
290 'FUNC_MENU' => $this->getFuncMenu(),
291 'CONTENT' => $this->content
292 );
293 // Build the <body> for the module
294 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
295 // Renders the module page
296 $this->content = $this->doc->render('Configuration', $this->content);
297 }
298
299 /**
300 * Print output to browser
301 *
302 * @return void
303 * @todo Define visibility
304 */
305 public function printContent() {
306 echo $this->content;
307 }
308
309 /**
310 * Create the panel of buttons for submitting the form or otherwise perform operations.
311 *
312 * @return array All available buttons as an assoc. array
313 */
314 protected function getButtons() {
315 $buttons = array(
316 'csh' => '',
317 'shortcut' => ''
318 );
319 // Shortcut
320 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
321 $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
322 }
323 return $buttons;
324 }
325
326 /**
327 * Create the function menu
328 *
329 * @return string HTML of the function menu
330 */
331 protected function getFuncMenu() {
332 $funcMenu = BackendUtility::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']);
333 return $funcMenu;
334 }
335
336 }