[TASK] Remove <table> in lowlevel configuration
[Packages/TYPO3.CMS.git] / typo3 / sysext / lowlevel / Classes / View / ConfigurationView.php
1 <?php
2 namespace TYPO3\CMS\Lowlevel\View;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Script class for the Config module
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35 class ConfigurationView {
36
37 /**
38 * @todo Define visibility
39 */
40 public $MCONF = array();
41
42 /**
43 * @todo Define visibility
44 */
45 public $MOD_MENU = array();
46
47 /**
48 * @todo Define visibility
49 */
50 public $MOD_SETTINGS = array();
51
52 /**
53 * Document template object
54 *
55 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
56 * @todo Define visibility
57 */
58 public $doc;
59
60 /**
61 * @todo Define visibility
62 */
63 public $include_once = array();
64
65 /**
66 * @todo Define visibility
67 */
68 public $content;
69
70 /**
71 * Constructor
72 */
73 public function __construct() {
74 $GLOBALS['LANG']->includeLLFile('EXT:lowlevel/config/locallang.xml');
75 $GLOBALS['BE_USER']->modAccess($GLOBALS['MCONF'], 1);
76 }
77
78 /**
79 * Initialization
80 *
81 * @return void
82 * @todo Define visibility
83 */
84 public function init() {
85 global $BACK_PATH;
86 $this->MCONF = $GLOBALS['MCONF'];
87 $this->menuConfig();
88 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
89 $this->doc->backPath = $BACK_PATH;
90 $this->doc->setModuleTemplate('EXT:lowlevel/Resources/Private/Templates/config.html');
91 // JavaScript
92 $this->doc->JScode = '
93 <script language="javascript" type="text/javascript">
94 script_ended = 0;
95 function jumpToUrl(URL) {
96 window.location.href = URL;
97 }
98 </script>
99 ';
100 $this->doc->form = '<form action="" method="post">';
101 }
102
103 /**
104 * Menu Configuration
105 *
106 * @return void
107 * @todo Define visibility
108 */
109 public function menuConfig() {
110 global $TYPO3_CONF_VARS;
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 // CLEANSE SETTINGS
132 $this->MOD_SETTINGS = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleData($this->MOD_MENU, \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('SET'), $this->MCONF['name']);
133 }
134
135 /**
136 * [Describe function...]
137 *
138 * @return void
139 * @todo Define visibility
140 */
141 public function main() {
142 $arrayBrowser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Lowlevel\\Utility\\ArrayBrowser');
143 $label = $this->MOD_MENU['function'][$this->MOD_SETTINGS['function']];
144
145 $this->content = $this->doc->header($GLOBALS['LANG']->getLL('configuration', TRUE));
146 $this->content .= '<h2>' . $label . '</h2>';
147
148 $this->content .= '<div id="lowlevel-config">
149 <label for="search_field">' . $GLOBALS['LANG']->getLL('enterSearchPhrase', TRUE) . '</label>
150 <input type="text" id="search_field" name="search_field" value="' . htmlspecialchars($search_field) . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . ' />
151 <input type="submit" name="search" id="search" value="' . $GLOBALS['LANG']->getLL('search', TRUE) . '" />';
152 $this->content .= \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck(0, 'SET[regexsearch]', $this->MOD_SETTINGS['regexsearch'], '', '', 'id="checkRegexsearch"') . '<label for="checkRegexsearch">' . $GLOBALS['LANG']->getLL('useRegExp', TRUE) . '</label>';
153 $this->content .= \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck(0, 'SET[fixedLgd]', $this->MOD_SETTINGS['fixedLgd'], '', '', 'id="checkFixedLgd"') . '<label for="checkFixedLgd">' . $GLOBALS['LANG']->getLL('cropLines', TRUE) . '</label>
154 </div>';
155 $this->content .= $this->doc->spacer(5);
156 switch ($this->MOD_SETTINGS['function']) {
157 case 0:
158 $theVar = $GLOBALS['TYPO3_CONF_VARS'];
159 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
160 $arrayBrowser->varName = '$TYPO3_CONF_VARS';
161 break;
162 case 1:
163 $theVar = $GLOBALS['TCA'];
164 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
165 $arrayBrowser->varName = '$TCA';
166 break;
167 case 2:
168 $theVar = $GLOBALS['TCA_DESCR'];
169 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
170 $arrayBrowser->varName = '$TCA_DESCR';
171 break;
172 case 3:
173 $theVar = $GLOBALS['TYPO3_LOADED_EXT'];
174 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
175 $arrayBrowser->varName = '$TYPO3_LOADED_EXT';
176 break;
177 case 4:
178 $theVar = $GLOBALS['T3_SERVICES'];
179 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
180 $arrayBrowser->varName = '$T3_SERVICES';
181 break;
182 case 5:
183 $theVar = $GLOBALS['TBE_MODULES'];
184 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
185 $arrayBrowser->varName = '$TBE_MODULES';
186 break;
187 case 6:
188 $theVar = $GLOBALS['TBE_MODULES_EXT'];
189 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
190 $arrayBrowser->varName = '$TBE_MODULES_EXT';
191 break;
192 case 7:
193 $theVar = $GLOBALS['TBE_STYLES'];
194 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
195 $arrayBrowser->varName = '$TBE_STYLES';
196 break;
197 case 8:
198 $theVar = $GLOBALS['BE_USER']->uc;
199 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
200 $arrayBrowser->varName = '$BE_USER->uc';
201 break;
202 case 9:
203 $theVar = $GLOBALS['TYPO3_USER_SETTINGS'];
204 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
205 $arrayBrowser->varName = '$TYPO3_USER_SETTINGS';
206 break;
207 default:
208 $theVar = array();
209 }
210 // Update node:
211 $update = 0;
212 $node = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('node');
213 // If any plus-signs were clicked, it's registred.
214 if (is_array($node)) {
215 $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']] = $arrayBrowser->depthKeys($node, $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']]);
216 $update = 1;
217 }
218 if ($update) {
219 $GLOBALS['BE_USER']->pushModuleData($this->MCONF['name'], $this->MOD_SETTINGS);
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 $search_field = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('search_field');
226 // If any POST-vars are send, update the condition array
227 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_POST('search') && trim($search_field)) {
228 $arrayBrowser->depthKeys = $arrayBrowser->getSearchKeys($theVar, '', $search_field, array());
229 }
230 // mask the encryption key to not show it as plaintext in the configuration module
231 if ($theVar == $GLOBALS['TYPO3_CONF_VARS']) {
232 $theVar['SYS']['encryptionKey'] = '***** (length: ' . strlen($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']) . ' characters)';
233 }
234 $tree = $arrayBrowser->tree($theVar, '', '');
235 $this->content .= $this->doc->sectionEnd();
236 // Variable name:
237 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('varname')) {
238 $line = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('_') ? \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('_') : \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('varname');
239 // Write the line to extTables.php
240 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('writetoexttables')) {
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 = \TYPO3\CMS\Core\Utility\GeneralUtility::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 }
251 // insert line in extTables.php
252 $extTables = preg_replace('/<\\?php|\\?>/is', '', $extTables);
253 $extTables = '<?php' . (empty($extTables) ? LF : '') . $extTables . $changedLine . LF . '?>';
254 $success = \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile(PATH_typo3conf . TYPO3_extTableDef_script, $extTables);
255 if ($success) {
256 // show flash message
257 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
258 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
259 '',
260 sprintf(
261 $GLOBALS['LANG']->getLL('writeMessage', TRUE),
262 TYPO3_extTableDef_script,
263 '<br />',
264 '<strong>' . nl2br(htmlspecialchars($changedLine)) . '</strong>'
265 ),
266 \TYPO3\CMS\Core\Messaging\FlashMessage::OK
267 );
268 } else {
269 // Error: show flash message
270 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
271 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
272 '',
273 sprintf($GLOBALS['LANG']->getLL('writeMessageFailed', TRUE), TYPO3_extTableDef_script),
274 \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
275 );
276 }
277 $this->content .= $flashMessage->render();
278 }
279 $this->content .= '<div id="lowlevel-config-var">
280 <strong>' . $GLOBALS['LANG']->getLL('variable', TRUE) . '</strong><br />
281 <input type="text" name="_" value="' . trim(htmlspecialchars($line)) . '" size="120" /><br/>';
282 if (TYPO3_extTableDef_script !== '' && ($this->MOD_SETTINGS['function'] === '1' || $this->MOD_SETTINGS['function'] === '4')) {
283 // write only for $TCA and TBE_STYLES if TYPO3_extTableDef_script is defined
284 $this->content .= '<br /><input type="submit" name="writetoexttables" value="' . $GLOBALS['LANG']->getLL('writeValue', TRUE) . '" /></div>';
285 } else {
286 $this->content .= $GLOBALS['LANG']->getLL('copyPaste', TRUE) . LF . '</div>';
287 }
288 }
289 $this->content .= '<div class="nowrap">' . $tree . '</div>';
290
291 // Setting up the buttons and markers for docheader
292 $docHeaderButtons = $this->getButtons();
293 $markers = array(
294 'CSH' => $docHeaderButtons['csh'],
295 'FUNC_MENU' => $this->getFuncMenu(),
296 'CONTENT' => $this->content
297 );
298 // Build the <body> for the module
299 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
300 // Renders the module page
301 $this->content = $this->doc->render('Configuration', $this->content);
302 }
303
304 /**
305 * Print output to browser
306 *
307 * @return void
308 * @todo Define visibility
309 */
310 public function printContent() {
311 echo $this->content;
312 }
313
314 /**
315 * Create the panel of buttons for submitting the form or otherwise perform operations.
316 *
317 * @return array All available buttons as an assoc. array
318 */
319 protected function getButtons() {
320 $buttons = array(
321 'csh' => '',
322 'shortcut' => ''
323 );
324 // Shortcut
325 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
326 $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
327 }
328 return $buttons;
329 }
330
331 /**
332 * Create the function menu
333 *
334 * @return string HTML of the function menu
335 */
336 protected function getFuncMenu() {
337 $funcMenu = \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']);
338 return $funcMenu;
339 }
340
341 }
342
343
344 ?>