c9f3001d657bd715cd07aac1389e997be7e83c2c
[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 Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Module\BaseScriptClass;
20 use TYPO3\CMS\Backend\Template\ModuleTemplate;
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
22 use TYPO3\CMS\Core\Utility\ArrayUtility;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
25 use TYPO3\CMS\Fluid\View\StandaloneView;
26 use TYPO3\CMS\Lowlevel\Utility\ArrayBrowser;
27
28 /**
29 * Script class for the Config module
30 */
31 class ConfigurationView extends BaseScriptClass
32 {
33 /**
34 * @var StandaloneView
35 */
36 protected $view;
37
38 /**
39 * The name of the module
40 *
41 * @var string
42 */
43 protected $moduleName = 'system_config';
44
45 /**
46 * ModuleTemplate Container
47 *
48 * @var ModuleTemplate
49 */
50 protected $moduleTemplate;
51
52 /**
53 * Blind configurations which should not be visible
54 *
55 * @var array
56 */
57 protected $blindedConfigurationOptions = [
58 'TYPO3_CONF_VARS' => [
59 'DB' => [
60 'database' => '******',
61 'host' => '******',
62 'password' => '******',
63 'port' => '******',
64 'socket' => '******',
65 'username' => '******'
66 ],
67 'SYS' => [
68 'encryptionKey' => '******'
69 ]
70 ]
71 ];
72
73 /**
74 * Constructor
75 */
76 public function __construct()
77 {
78 $this->view = GeneralUtility::makeInstance(StandaloneView::class);
79 $this->view->getRequest()->setControllerExtensionName('lowlevel');
80 }
81
82 /**
83 * Initialization
84 *
85 * @return void
86 */
87 public function init()
88 {
89 $this->menuConfig();
90 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
91 $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Lowlevel/ConfigurationView');
92 }
93
94 /**
95 * Menu Configuration
96 *
97 * @return void
98 */
99 public function menuConfig()
100 {
101 // MENU-ITEMS:
102 // If array, then it's a selector box menu
103 // If empty string it's just a variable, that'll be saved.
104 // Values NOT in this array will not be saved in the settings-array for the module.
105 $this->MOD_MENU = array(
106 'function' => array(
107 0 => LocalizationUtility::translate('typo3ConfVars', 'lowlevel'),
108 1 => LocalizationUtility::translate('tca', 'lowlevel'),
109 2 => LocalizationUtility::translate('tcaDescr', 'lowlevel'),
110 3 => LocalizationUtility::translate('loadedExt', 'lowlevel'),
111 4 => LocalizationUtility::translate('t3services', 'lowlevel'),
112 5 => LocalizationUtility::translate('tbemodules', 'lowlevel'),
113 6 => LocalizationUtility::translate('tbemodulesext', 'lowlevel'),
114 7 => LocalizationUtility::translate('tbeStyles', 'lowlevel'),
115 8 => LocalizationUtility::translate('beUser', 'lowlevel'),
116 9 => LocalizationUtility::translate('usersettings', 'lowlevel')
117 ),
118 'regexsearch' => '',
119 'fixedLgd' => ''
120 );
121 // CLEANSE SETTINGS
122 $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->moduleName);
123 }
124
125 /**
126 * Main function
127 *
128 * @return void
129 */
130 public function main()
131 {
132 /** @var ArrayBrowser $arrayBrowser */
133 $arrayBrowser = GeneralUtility::makeInstance(ArrayBrowser::class);
134 $label = $this->MOD_MENU['function'][$this->MOD_SETTINGS['function']];
135 $search_field = GeneralUtility::_GP('search_field');
136
137 $templatePathAndFilename = GeneralUtility::getFileAbsFileName('EXT:lowlevel/Resources/Private/Templates/Backend/Configuration.html');
138 $this->view->setTemplatePathAndFilename($templatePathAndFilename);
139 $this->view->assign('label', $label);
140 $this->view->assign('search_field', $search_field);
141 $this->view->assign('checkbox_checkRegexsearch', BackendUtility::getFuncCheck(0, 'SET[regexsearch]', $this->MOD_SETTINGS['regexsearch'], '', '', 'id="checkRegexsearch"'));
142
143 switch ($this->MOD_SETTINGS['function']) {
144 case 0:
145 $theVar = $GLOBALS['TYPO3_CONF_VARS'];
146 ArrayUtility::naturalKeySortRecursive($theVar);
147 $arrayBrowser->varName = '$TYPO3_CONF_VARS';
148 break;
149 case 1:
150 $theVar = $GLOBALS['TCA'];
151 ArrayUtility::naturalKeySortRecursive($theVar);
152 $arrayBrowser->varName = '$TCA';
153 break;
154 case 2:
155 $theVar = $GLOBALS['TCA_DESCR'];
156 ArrayUtility::naturalKeySortRecursive($theVar);
157 $arrayBrowser->varName = '$TCA_DESCR';
158 break;
159 case 3:
160 $theVar = $GLOBALS['TYPO3_LOADED_EXT'];
161 ArrayUtility::naturalKeySortRecursive($theVar);
162 $arrayBrowser->varName = '$TYPO3_LOADED_EXT';
163 break;
164 case 4:
165 $theVar = $GLOBALS['T3_SERVICES'];
166 ArrayUtility::naturalKeySortRecursive($theVar);
167 $arrayBrowser->varName = '$T3_SERVICES';
168 break;
169 case 5:
170 $theVar = $GLOBALS['TBE_MODULES'];
171 ArrayUtility::naturalKeySortRecursive($theVar);
172 $arrayBrowser->varName = '$TBE_MODULES';
173 break;
174 case 6:
175 $theVar = $GLOBALS['TBE_MODULES_EXT'];
176 ArrayUtility::naturalKeySortRecursive($theVar);
177 $arrayBrowser->varName = '$TBE_MODULES_EXT';
178 break;
179 case 7:
180 $theVar = $GLOBALS['TBE_STYLES'];
181 ArrayUtility::naturalKeySortRecursive($theVar);
182 $arrayBrowser->varName = '$TBE_STYLES';
183 break;
184 case 8:
185 $theVar = $GLOBALS['BE_USER']->uc;
186 ArrayUtility::naturalKeySortRecursive($theVar);
187 $arrayBrowser->varName = '$BE_USER->uc';
188 break;
189 case 9:
190 $theVar = $GLOBALS['TYPO3_USER_SETTINGS'];
191 ArrayUtility::naturalKeySortRecursive($theVar);
192 $arrayBrowser->varName = '$TYPO3_USER_SETTINGS';
193 break;
194 default:
195 $theVar = array();
196 }
197 // Update node:
198 $update = 0;
199 $node = GeneralUtility::_GET('node');
200 // If any plus-signs were clicked, it's registered.
201 if (is_array($node)) {
202 $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']] = $arrayBrowser->depthKeys($node, $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']]);
203 $update = 1;
204 }
205 if ($update) {
206 $this->getBackendUser()->pushModuleData($this->moduleName, $this->MOD_SETTINGS);
207 }
208 $arrayBrowser->dontLinkVar = true;
209 $arrayBrowser->depthKeys = $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']];
210 $arrayBrowser->regexMode = $this->MOD_SETTINGS['regexsearch'];
211 $arrayBrowser->fixedLgd = $this->MOD_SETTINGS['fixedLgd'];
212 $arrayBrowser->searchKeysToo = true;
213
214 // If any POST-vars are send, update the condition array
215 if (GeneralUtility::_POST('search') && trim($search_field)) {
216 $arrayBrowser->depthKeys = $arrayBrowser->getSearchKeys($theVar, '', $search_field, array());
217 }
218
219 // mask sensitive information
220 $varName = trim($arrayBrowser->varName, '$');
221 if (isset($this->blindedConfigurationOptions[$varName])) {
222 ArrayUtility::mergeRecursiveWithOverrule($theVar, $this->blindedConfigurationOptions[$varName]);
223 }
224 $tree = $arrayBrowser->tree($theVar, '', '');
225 $this->view->assign('tree', $tree);
226
227 // Setting up the shortcut button for docheader
228 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
229 // Shortcut
230 $shortcutButton = $buttonBar->makeShortcutButton()
231 ->setModuleName($this->moduleName)
232 ->setDisplayName($this->MOD_MENU['function'][$this->MOD_SETTINGS['function']])
233 ->setSetVariables(['function']);
234 $buttonBar->addButton($shortcutButton);
235
236 $this->getModuleMenu();
237
238 $this->content = '<form action="" id="ConfigurationView" method="post">';
239 $this->content .= $this->view->render();
240 $this->content .= '</form>';
241 }
242
243 /**
244 * Injects the request object for the current request or subrequest
245 * Simply calls main() and init() and outputs the content
246 *
247 * @param ServerRequestInterface $request the current request
248 * @param ResponseInterface $response
249 * @return ResponseInterface the response with the content
250 */
251 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
252 {
253 $GLOBALS['SOBE'] = $this;
254 $this->init();
255 $this->main();
256
257 $this->moduleTemplate->setContent($this->content);
258 $response->getBody()->write($this->moduleTemplate->renderContent());
259 return $response;
260 }
261
262 /**
263 * Print output to browser
264 *
265 * @return void
266 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
267 */
268 public function printContent()
269 {
270 GeneralUtility::logDeprecatedFunction();
271 echo $this->content;
272 }
273
274 /**
275 * Generates the action menu
276 */
277 protected function getModuleMenu()
278 {
279 $menu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
280 $menu->setIdentifier('ConfigurationJumpMenu');
281
282 foreach ($this->MOD_MENU['function'] as $controller => $title) {
283 $item = $menu
284 ->makeMenuItem()
285 ->setHref(
286 BackendUtility::getModuleUrl(
287 $this->moduleName,
288 [
289 'id' => $this->id,
290 'SET' => [
291 'function' => $controller
292 ]
293 ]
294 )
295 )
296 ->setTitle($title);
297 if ($controller === (int)$this->MOD_SETTINGS['function']) {
298 $item->setActive(true);
299 }
300 $menu->addMenuItem($item);
301 }
302 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
303 }
304 }