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