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