[TASK] Fix dummy texts in phpDoc
[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 TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Messaging\FlashMessage;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
21
22 /**
23 * Script class for the Config module
24 *
25 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
26 */
27 class ConfigurationView {
28
29 /**
30 * @var \TYPO3\CMS\Fluid\View\StandaloneView
31 */
32 protected $view;
33
34 /**
35 * @var \TYPO3\CMS\Core\Messaging\FlashMessageQueue
36 */
37 protected $flashMessageQueue;
38
39 /**
40 * @var array
41 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
42 */
43 public $MCONF = array();
44
45 /**
46 * @var array
47 */
48 public $MOD_MENU = array();
49
50 /**
51 * @var array
52 */
53 public $MOD_SETTINGS = array();
54
55 /**
56 * Document template object
57 *
58 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
59 */
60 public $doc;
61
62 /**
63 * @var array
64 */
65 public $include_once = array();
66
67 /**
68 * @var string
69 */
70 public $content;
71
72 /**
73 * The name of the module
74 *
75 * @var string
76 */
77 protected $moduleName = 'system_config';
78
79 /**
80 * Constructor
81 */
82 public function __construct() {
83 $this->view = GeneralUtility::makeInstance(\TYPO3\CMS\Fluid\View\StandaloneView::class);
84 $this->view->getRequest()->setControllerExtensionName('lowlevel');
85 }
86
87 /**
88 * Initialization
89 *
90 * @return void
91 */
92 public function init() {
93 $this->menuConfig();
94 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
95 $this->doc->backPath = $GLOBALS['BACK_PATH'];
96 $this->doc->setModuleTemplate('EXT:lowlevel/Resources/Private/Templates/config.html');
97 $this->doc->form = '<form action="" method="post">';
98 $this->doc->addStyleSheet('module', 'sysext/lowlevel/Resources/Public/Styles/styles.css');
99 }
100
101 /**
102 * Menu Configuration
103 *
104 * @return void
105 */
106 public function menuConfig() {
107 // MENU-ITEMS:
108 // If array, then it's a selector box menu
109 // If empty string it's just a variable, that'll be saved.
110 // Values NOT in this array will not be saved in the settings-array for the module.
111 $this->MOD_MENU = array(
112 'function' => array(
113 0 => LocalizationUtility::translate('typo3ConfVars', 'lowlevel'),
114 1 => LocalizationUtility::translate('tca', 'lowlevel'),
115 2 => LocalizationUtility::translate('tcaDescr', 'lowlevel'),
116 3 => LocalizationUtility::translate('loadedExt', 'lowlevel'),
117 4 => LocalizationUtility::translate('t3services', 'lowlevel'),
118 5 => LocalizationUtility::translate('tbemodules', 'lowlevel'),
119 6 => LocalizationUtility::translate('tbemodulesext', 'lowlevel'),
120 7 => LocalizationUtility::translate('tbeStyles', 'lowlevel'),
121 8 => LocalizationUtility::translate('beUser', 'lowlevel'),
122 9 => LocalizationUtility::translate('usersettings', 'lowlevel')
123 ),
124 'regexsearch' => '',
125 'fixedLgd' => ''
126 );
127 // CLEANSE SETTINGS
128 $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->moduleName);
129 }
130
131 /**
132 * Main function
133 *
134 * @return void
135 */
136 public function main() {
137 /** @var \TYPO3\CMS\Lowlevel\Utility\ArrayBrowser $arrayBrowser */
138 $arrayBrowser = GeneralUtility::makeInstance(\TYPO3\CMS\Lowlevel\Utility\ArrayBrowser::class);
139 $label = $this->MOD_MENU['function'][$this->MOD_SETTINGS['function']];
140 $search_field = GeneralUtility::_GP('search_field');
141
142 $templatePathAndFilename = GeneralUtility::getFileAbsFileName('EXT:lowlevel/Resources/Private/Templates/Backend/Configuration.html');
143 $this->view->setTemplatePathAndFilename($templatePathAndFilename);
144 $this->view->assign('label', $label);
145 $this->view->assign('search_field', $search_field);
146 $this->view->assign('checkbox_checkRegexsearch', BackendUtility::getFuncCheck(0, 'SET[regexsearch]', $this->MOD_SETTINGS['regexsearch'], '', '', 'id="checkRegexsearch"'));
147
148 switch ($this->MOD_SETTINGS['function']) {
149 case 0:
150 $theVar = $GLOBALS['TYPO3_CONF_VARS'];
151 GeneralUtility::naturalKeySortRecursive($theVar);
152 $arrayBrowser->varName = '$TYPO3_CONF_VARS';
153 break;
154 case 1:
155 $theVar = $GLOBALS['TCA'];
156 GeneralUtility::naturalKeySortRecursive($theVar);
157 $arrayBrowser->varName = '$TCA';
158 break;
159 case 2:
160 $theVar = $GLOBALS['TCA_DESCR'];
161 GeneralUtility::naturalKeySortRecursive($theVar);
162 $arrayBrowser->varName = '$TCA_DESCR';
163 break;
164 case 3:
165 $theVar = $GLOBALS['TYPO3_LOADED_EXT'];
166 GeneralUtility::naturalKeySortRecursive($theVar);
167 $arrayBrowser->varName = '$TYPO3_LOADED_EXT';
168 break;
169 case 4:
170 $theVar = $GLOBALS['T3_SERVICES'];
171 GeneralUtility::naturalKeySortRecursive($theVar);
172 $arrayBrowser->varName = '$T3_SERVICES';
173 break;
174 case 5:
175 $theVar = $GLOBALS['TBE_MODULES'];
176 GeneralUtility::naturalKeySortRecursive($theVar);
177 $arrayBrowser->varName = '$TBE_MODULES';
178 break;
179 case 6:
180 $theVar = $GLOBALS['TBE_MODULES_EXT'];
181 GeneralUtility::naturalKeySortRecursive($theVar);
182 $arrayBrowser->varName = '$TBE_MODULES_EXT';
183 break;
184 case 7:
185 $theVar = $GLOBALS['TBE_STYLES'];
186 GeneralUtility::naturalKeySortRecursive($theVar);
187 $arrayBrowser->varName = '$TBE_STYLES';
188 break;
189 case 8:
190 $theVar = $GLOBALS['BE_USER']->uc;
191 GeneralUtility::naturalKeySortRecursive($theVar);
192 $arrayBrowser->varName = '$BE_USER->uc';
193 break;
194 case 9:
195 $theVar = $GLOBALS['TYPO3_USER_SETTINGS'];
196 GeneralUtility::naturalKeySortRecursive($theVar);
197 $arrayBrowser->varName = '$TYPO3_USER_SETTINGS';
198 break;
199 default:
200 $theVar = array();
201 }
202 // Update node:
203 $update = 0;
204 $node = GeneralUtility::_GET('node');
205 // If any plus-signs were clicked, it's registred.
206 if (is_array($node)) {
207 $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']] = $arrayBrowser->depthKeys($node, $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']]);
208 $update = 1;
209 }
210 if ($update) {
211 $GLOBALS['BE_USER']->pushModuleData($this->moduleName, $this->MOD_SETTINGS);
212 }
213 $arrayBrowser->depthKeys = $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']];
214 $arrayBrowser->regexMode = $this->MOD_SETTINGS['regexsearch'];
215 $arrayBrowser->fixedLgd = $this->MOD_SETTINGS['fixedLgd'];
216 $arrayBrowser->searchKeysToo = TRUE;
217
218 // If any POST-vars are send, update the condition array
219 if (GeneralUtility::_POST('search') && trim($search_field)) {
220 $arrayBrowser->depthKeys = $arrayBrowser->getSearchKeys($theVar, '', $search_field, array());
221 }
222 // mask the encryption key to not show it as plaintext in the configuration module
223 if ($theVar == $GLOBALS['TYPO3_CONF_VARS']) {
224 $theVar['SYS']['encryptionKey'] = '***** (length: ' . strlen($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']) . ' characters)';
225 }
226 $tree = $arrayBrowser->tree($theVar, '', '');
227 $this->view->assign('tree', $tree);
228 // Variable name:
229 if (GeneralUtility::_GP('varname')) {
230 $this->view->assign('varname', TRUE);
231 $line = GeneralUtility::_GP('_') ? GeneralUtility::_GP('_') : GeneralUtility::_GP('varname');
232 // Write the line to extTables.php
233 if (GeneralUtility::_GP('writetoexttables')) {
234 // change value to $GLOBALS
235 $length = strpos($line, '[');
236 $var = substr($line, 0, $length);
237 $changedLine = '$GLOBALS[\'' . substr($line, 1, ($length - 1)) . '\']' . substr($line, $length);
238 // load current extTables.php
239 $extTables = GeneralUtility::getUrl(PATH_typo3conf . TYPO3_extTableDef_script);
240 if ($var === '$TCA') {
241 // check if we are editing the TCA
242 preg_match_all('/\\[\'([^\']+)\'\\]/', $line, $parts);
243 }
244 // insert line in extTables.php
245 $extTables = preg_replace('/<\\?php|\\?>/is', '', $extTables);
246 $extTables = '<?php' . (empty($extTables) ? LF : '') . $extTables . $changedLine . LF . '?>';
247 $success = GeneralUtility::writeFile(PATH_typo3conf . TYPO3_extTableDef_script, $extTables);
248 if ($success) {
249 // show flash message
250 $flashMessage = GeneralUtility::makeInstance(
251 FlashMessage::class,
252 '',
253 sprintf(
254 LocalizationUtility::translate('writeMessage', 'lowlevel'),
255 TYPO3_extTableDef_script,
256 '<br />',
257 '<strong>' . nl2br(htmlspecialchars($changedLine)) . '</strong>'
258 ),
259 FlashMessage::OK
260 );
261 } else {
262 // Error: show flash message
263 $flashMessage = GeneralUtility::makeInstance(
264 FlashMessage::class,
265 '',
266 sprintf(LocalizationUtility::translate('writeMessageFailed', 'lowlevel'), TYPO3_extTableDef_script),
267 FlashMessage::ERROR
268 );
269 }
270 $this->getFlashMessageQueue()->enqueue($flashMessage);
271 }
272
273 $this->view->assign('line', trim($line));
274
275 if (TYPO3_extTableDef_script !== '' && ($this->MOD_SETTINGS['function'] === '1' || $this->MOD_SETTINGS['function'] === '4')) {
276 // write only for $TCA and TBE_STYLES if TYPO3_extTableDef_script is defined
277 $this->view->assign('showSaveButton', TRUE);
278 } else {
279 $this->view->assign('showSaveButton', FALSE);
280 }
281 } else {
282 $this->view->assign('varname', FALSE);
283 }
284
285 // Setting up the buttons and markers for docheader
286 $docHeaderButtons = $this->getButtons();
287 $markers = array(
288 'CSH' => $docHeaderButtons['csh'],
289 'FUNC_MENU' => $this->getFuncMenu(),
290 'CONTENT' => $this->view->render(),
291 );
292 // Build the <body> for the module
293 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
294 // Renders the module page
295 $this->content = $this->doc->render('Configuration', $this->content);
296 }
297
298 /**
299 * Print output to browser
300 *
301 * @return void
302 */
303 public function printContent() {
304 echo $this->content;
305 }
306
307 /**
308 * Create the panel of buttons for submitting the form or otherwise perform operations.
309 *
310 * @return array All available buttons as an assoc. array
311 */
312 protected function getButtons() {
313 $buttons = array(
314 'csh' => '',
315 'shortcut' => ''
316 );
317 // Shortcut
318 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
319 $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 'function', $this->moduleName);
320 }
321 return $buttons;
322 }
323
324 /**
325 * Create the function menu
326 *
327 * @return string HTML of the function menu
328 */
329 protected function getFuncMenu() {
330 $funcMenu = BackendUtility::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']);
331 return $funcMenu;
332 }
333
334 /**
335 * @return \TYPO3\CMS\Core\Messaging\FlashMessageQueue
336 */
337 protected function getFlashMessageQueue() {
338 if (!$this->flashMessageQueue instanceof \TYPO3\CMS\Core\Messaging\FlashMessageQueue) {
339 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
340 $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
341 $this->flashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
342 }
343
344 return $this->flashMessageQueue;
345 }
346
347 }