a673562329d363402b7455f072dbfba2ad256da3
[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 $this->content = $this->doc->header($GLOBALS['LANG']->getLL('configuration', TRUE));
144 $this->content .= '<div id="lowlevel-config">
145 <label for="search_field">' . $GLOBALS['LANG']->getLL('enterSearchPhrase', TRUE) . '</label>
146 <input type="text" id="search_field" name="search_field" value="' . htmlspecialchars($search_field) . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . ' />
147 <input type="submit" name="search" id="search" value="' . $GLOBALS['LANG']->getLL('search', TRUE) . '" />';
148 $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>';
149 $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>
150 </div>';
151 $this->content .= $this->doc->spacer(5);
152 switch ($this->MOD_SETTINGS['function']) {
153 case 0:
154 $theVar = $GLOBALS['TYPO3_CONF_VARS'];
155 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
156 $arrayBrowser->varName = '$TYPO3_CONF_VARS';
157 break;
158 case 1:
159 $theVar = $GLOBALS['TCA'];
160 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
161 $arrayBrowser->varName = '$TCA';
162 break;
163 case 2:
164 $theVar = $GLOBALS['TCA_DESCR'];
165 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
166 $arrayBrowser->varName = '$TCA_DESCR';
167 break;
168 case 3:
169 $theVar = $GLOBALS['TYPO3_LOADED_EXT'];
170 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
171 $arrayBrowser->varName = '$TYPO3_LOADED_EXT';
172 break;
173 case 4:
174 $theVar = $GLOBALS['T3_SERVICES'];
175 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
176 $arrayBrowser->varName = '$T3_SERVICES';
177 break;
178 case 5:
179 $theVar = $GLOBALS['TBE_MODULES'];
180 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
181 $arrayBrowser->varName = '$TBE_MODULES';
182 break;
183 case 6:
184 $theVar = $GLOBALS['TBE_MODULES_EXT'];
185 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
186 $arrayBrowser->varName = '$TBE_MODULES_EXT';
187 break;
188 case 7:
189 $theVar = $GLOBALS['TBE_STYLES'];
190 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
191 $arrayBrowser->varName = '$TBE_STYLES';
192 break;
193 case 8:
194 $theVar = $GLOBALS['BE_USER']->uc;
195 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
196 $arrayBrowser->varName = '$BE_USER->uc';
197 break;
198 case 9:
199 $theVar = $GLOBALS['TYPO3_USER_SETTINGS'];
200 \TYPO3\CMS\Core\Utility\GeneralUtility::naturalKeySortRecursive($theVar);
201 $arrayBrowser->varName = '$TYPO3_USER_SETTINGS';
202 break;
203 default:
204 $theVar = array();
205 }
206 // Update node:
207 $update = 0;
208 $node = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('node');
209 // If any plus-signs were clicked, it's registred.
210 if (is_array($node)) {
211 $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']] = $arrayBrowser->depthKeys($node, $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']]);
212 $update = 1;
213 }
214 if ($update) {
215 $GLOBALS['BE_USER']->pushModuleData($this->MCONF['name'], $this->MOD_SETTINGS);
216 }
217 $arrayBrowser->depthKeys = $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']];
218 $arrayBrowser->regexMode = $this->MOD_SETTINGS['regexsearch'];
219 $arrayBrowser->fixedLgd = $this->MOD_SETTINGS['fixedLgd'];
220 $arrayBrowser->searchKeysToo = TRUE;
221 $search_field = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('search_field');
222 // If any POST-vars are send, update the condition array
223 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_POST('search') && trim($search_field)) {
224 $arrayBrowser->depthKeys = $arrayBrowser->getSearchKeys($theVar, '', $search_field, array());
225 }
226 // mask the encryption key to not show it as plaintext in the configuration module
227 if ($theVar == $GLOBALS['TYPO3_CONF_VARS']) {
228 $theVar['SYS']['encryptionKey'] = '***** (length: ' . strlen($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']) . ' characters)';
229 }
230 $tree = $arrayBrowser->tree($theVar, '', '');
231 $label = $this->MOD_MENU['function'][$this->MOD_SETTINGS['function']];
232 $this->content .= $this->doc->sectionEnd();
233 // Variable name:
234 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('varname')) {
235 $line = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('_') ? \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('_') : \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('varname');
236 // Write the line to extTables.php
237 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('writetoexttables')) {
238 // change value to $GLOBALS
239 $length = strpos($line, '[');
240 $var = substr($line, 0, $length);
241 $changedLine = '$GLOBALS[\'' . substr($line, 1, ($length - 1)) . '\']' . substr($line, $length);
242 // load current extTables.php
243 $extTables = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl(PATH_typo3conf . TYPO3_extTableDef_script);
244 if ($var === '$TCA') {
245 // check if we are editing the TCA
246 preg_match_all('/\\[\'([^\']+)\'\\]/', $line, $parts);
247 }
248 // insert line in extTables.php
249 $extTables = preg_replace('/<\\?php|\\?>/is', '', $extTables);
250 $extTables = '<?php' . (empty($extTables) ? LF : '') . $extTables . $changedLine . LF . '?>';
251 $success = \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile(PATH_typo3conf . TYPO3_extTableDef_script, $extTables);
252 if ($success) {
253 // show flash message
254 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
255 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
256 '',
257 sprintf(
258 $GLOBALS['LANG']->getLL('writeMessage', TRUE),
259 TYPO3_extTableDef_script,
260 '<br />',
261 '<strong>' . nl2br(htmlspecialchars($changedLine)) . '</strong>'
262 ),
263 \TYPO3\CMS\Core\Messaging\FlashMessage::OK
264 );
265 } else {
266 // Error: show flash message
267 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
268 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
269 '',
270 sprintf($GLOBALS['LANG']->getLL('writeMessageFailed', TRUE), TYPO3_extTableDef_script),
271 \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
272 );
273 }
274 $this->content .= $flashMessage->render();
275 }
276 $this->content .= '<div id="lowlevel-config-var">
277 <strong>' . $GLOBALS['LANG']->getLL('variable', TRUE) . '</strong><br />
278 <input type="text" name="_" value="' . trim(htmlspecialchars($line)) . '" size="120" /><br/>';
279 if (TYPO3_extTableDef_script !== '' && ($this->MOD_SETTINGS['function'] === '1' || $this->MOD_SETTINGS['function'] === '4')) {
280 // write only for $TCA and TBE_STYLES if TYPO3_extTableDef_script is defined
281 $this->content .= '<br /><input type="submit" name="writetoexttables" value="' . $GLOBALS['LANG']->getLL('writeValue', TRUE) . '" /></div>';
282 } else {
283 $this->content .= $GLOBALS['LANG']->getLL('copyPaste', TRUE) . LF . '</div>';
284 }
285 }
286 $this->content .= '<br /><table border="0" cellpadding="0" cellspacing="0" class="t3-tree t3-tree-config">';
287 $this->content .= '<tr>
288 <th class="t3-row-header t3-tree-config-header">' . $label . '</th>
289 </tr>
290 <tr>
291 <td>' . $tree . '</td>
292 </tr>
293 </table>
294 ';
295 // Setting up the buttons and markers for docheader
296 $docHeaderButtons = $this->getButtons();
297 $markers = array(
298 'CSH' => $docHeaderButtons['csh'],
299 'FUNC_MENU' => $this->getFuncMenu(),
300 'CONTENT' => $this->content
301 );
302 // Build the <body> for the module
303 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
304 // Renders the module page
305 $this->content = $this->doc->render('Configuration', $this->content);
306 }
307
308 /**
309 * Print output to browser
310 *
311 * @return void
312 * @todo Define visibility
313 */
314 public function printContent() {
315 echo $this->content;
316 }
317
318 /**
319 * Create the panel of buttons for submitting the form or otherwise perform operations.
320 *
321 * @return array All available buttons as an assoc. array
322 */
323 protected function getButtons() {
324 $buttons = array(
325 'csh' => '',
326 'shortcut' => ''
327 );
328 // Shortcut
329 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
330 $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
331 }
332 return $buttons;
333 }
334
335 /**
336 * Create the function menu
337 *
338 * @return string HTML of the function menu
339 */
340 protected function getFuncMenu() {
341 $funcMenu = \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']);
342 return $funcMenu;
343 }
344
345 }
346
347
348 ?>