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