TYPO3 CMS  TYPO3_8-7
AllConfiguration.php
Go to the documentation of this file.
1 <?php
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 
19 
24 {
32  protected $phpErrorCodesSettings = [
33  'errorHandlerErrors',
34  'exceptionalErrors',
35  'syslogErrorReporting',
36  'belogErrorReporting',
37  ];
38 
44  protected function executeAction()
45  {
46  if (isset($this->postValues['set']['write'])) {
47  $this->view->assign('configurationValuesSaved', true);
48  $this->view->assign('savedConfigurationValueMessages', $this->updateLocalConfigurationValues());
49  } else {
50  $this->view->assign('sectionNames', $this->getSpeakingSectionNames());
51  $this->view->assign('data', $this->setUpConfigurationData());
52  }
53 
54  return $this->view->render();
55  }
56 
62  protected function getSpeakingSectionNames()
63  {
64  return [
65  'BE' => 'Backend',
66  'DB' => 'Database',
67  'EXT' => 'Extension Installation',
68  'FE' => 'Frontend',
69  'GFX' => 'Image Processing',
70  'HTTP' => 'Connection',
71  'MAIL' => 'Mail',
72  'SYS' => 'System'
73  ];
74  }
75 
81  protected function setUpConfigurationData()
82  {
83  $data = [];
84  $typo3ConfVars = array_keys($GLOBALS['TYPO3_CONF_VARS']);
85  sort($typo3ConfVars);
86  $commentArray = $this->getDefaultConfigArrayComments();
87  foreach ($typo3ConfVars as $sectionName) {
88  $data[$sectionName] = [];
89 
90  foreach ($GLOBALS['TYPO3_CONF_VARS'][$sectionName] as $key => $value) {
91  // @deprecated since TYPO3 v8, will be removed in TYPO3 v9. The array TYPO3_CONF_VARS_extensionAdded will be removed in v9.
92  if (isset($GLOBALS['TYPO3_CONF_VARS_extensionAdded'][$sectionName][$key])) {
93  // Don't allow editing stuff which is added by extensions
94  // Make sure we fix potentially duplicated entries from older setups
95  $potentialValue = str_replace(['\' . LF . \'', '\' . LF . \''], [LF, LF], $value);
96  while (preg_match('/' . preg_quote($GLOBALS['TYPO3_CONF_VARS_extensionAdded'][$sectionName][$key], '/') . '$/', $potentialValue)) {
97  $potentialValue = preg_replace('/' . preg_quote($GLOBALS['TYPO3_CONF_VARS_extensionAdded'][$sectionName][$key], '/') . '$/', '', $potentialValue);
98  }
99  $value = $potentialValue;
100  }
101 
102  $description = trim($commentArray[$sectionName][$key]);
103  $isTextarea = (bool)preg_match('/^(<.*?>)?string \\(textarea\\)/i', $description);
104  $doNotRender = (bool)preg_match('/^(<.*?>)?string \\(exclude\\)/i', $description);
105 
106  if (!is_array($value) && !$doNotRender && (!preg_match('/[' . LF . CR . ']/', $value) || $isTextarea)) {
107  $itemData = [];
108  $itemData['key'] = $key;
109  $itemData['description'] = $description;
110  if ($isTextarea) {
111  $itemData['type'] = 'textarea';
112  $itemData['value'] = str_replace(['\' . LF . \'', '\' . LF . \''], [LF, LF], $value);
113  } elseif (preg_match('/^(<.*?>)?boolean/i', $description)) {
114  $itemData['type'] = 'checkbox';
115  $itemData['value'] = $value ? '1' : '0';
116  $itemData['checked'] = (bool)$value;
117  } elseif (preg_match('/^(<.*?>)?integer/i', $description)) {
118  $itemData['type'] = 'number';
119  $itemData['value'] = (int)$value;
120  } else {
121  $itemData['type'] = 'input';
122  $itemData['value'] = $value;
123  }
124 
125  // Check if the setting is a PHP error code, will trigger a view helper in fluid
126  if ($sectionName === 'SYS' && in_array($key, $this->phpErrorCodesSettings)) {
127  $itemData['phpErrorCode'] = true;
128  }
129 
130  $data[$sectionName][] = $itemData;
131  }
132  }
133  }
134  return $data;
135  }
136 
142  protected function updateLocalConfigurationValues()
143  {
144  $statusObjects = [];
145  if (isset($this->postValues['values']) && is_array($this->postValues['values'])) {
146  $configurationPathValuePairs = [];
147  $commentArray = $this->getDefaultConfigArrayComments();
148  $formValues = $this->postValues['values'];
149  foreach ($formValues as $section => $valueArray) {
150  if (is_array($GLOBALS['TYPO3_CONF_VARS'][$section])) {
151  foreach ($valueArray as $valueKey => $value) {
152  if (isset($GLOBALS['TYPO3_CONF_VARS'][$section][$valueKey])) {
153  $oldValue = $GLOBALS['TYPO3_CONF_VARS'][$section][$valueKey];
154  $description = trim($commentArray[$section][$valueKey]);
155 
156  if (preg_match('/^string \\(textarea\\)/i', $description)) {
157  // Force Unix linebreaks in textareas
158  $value = str_replace(CR, '', $value);
159  // Preserve linebreaks
160  $value = str_replace(LF, '\' . LF . \'', $value);
161  }
162 
163  if (preg_match('/^(<.*?>)?boolean/i', $description)) {
164  // When submitting settings in the Install Tool, values that default to "FALSE" or "TRUE"
165  // in EXT:core/Configuration/DefaultConfiguration.php will be sent as "0" resp. "1".
166  $value = $value === '1';
167  $valueHasChanged = (bool)$oldValue !== $value;
168  } elseif (preg_match('/^(<.*?>)?integer/i', $description)) {
169  // Cast integer values to integers (but only for values that can not contain a string as well)
170  $value = (int)$value;
171  $valueHasChanged = (int)$oldValue !== $value;
172  } else {
173  $valueHasChanged = (string)$oldValue !== (string)$value;
174  }
175 
176  // Save if value changed
177  if ($valueHasChanged) {
178  $configurationPathValuePairs[$section . '/' . $valueKey] = $value;
180  $status = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Status\OkStatus::class);
181  $status->setTitle('$GLOBALS[\'TYPO3_CONF_VARS\'][\'' . $section . '\'][\'' . $valueKey . '\']');
182  if (is_bool($value)) {
183  $status->setMessage('New value = ' . ($value ? 'true' : 'false'));
184  } else {
185  $status->setMessage('New value = ' . $value);
186  }
187  $statusObjects[] = $status;
188  }
189  }
190  }
191  }
192  }
193  if (!empty($statusObjects)) {
195  $configurationManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class);
196  $configurationManager->setLocalConfigurationValuesByPathValuePairs($configurationPathValuePairs);
197  }
198  }
199  return $statusObjects;
200  }
201 
205  protected function getDefaultConfigArrayComments(): array
206  {
208  $configurationManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class);
209  return require $configurationManager->getDefaultConfigurationDescriptionFileLocation();
210  }
211 }
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']