TYPO3 CMS  TYPO3_7-6
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('sections', $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  if (isset($GLOBALS['TYPO3_CONF_VARS_extensionAdded'][$sectionName][$key])) {
92  // Don't allow editing stuff which is added by extensions
93  // Make sure we fix potentially duplicated entries from older setups
94  $potentialValue = str_replace(['\' . LF . \'', '\' . LF . \''], [LF, LF], $value);
95  while (preg_match('/' . preg_quote($GLOBALS['TYPO3_CONF_VARS_extensionAdded'][$sectionName][$key], '/') . '$/', $potentialValue)) {
96  $potentialValue = preg_replace('/' . preg_quote($GLOBALS['TYPO3_CONF_VARS_extensionAdded'][$sectionName][$key], '/') . '$/', '', $potentialValue);
97  }
98  $value = $potentialValue;
99  }
100 
101  $description = trim($commentArray[$sectionName][$key]);
102  $isTextarea = (bool)preg_match('/^(<.*?>)?string \\(textarea\\)/i', $description);
103  $doNotRender = (bool)preg_match('/^(<.*?>)?string \\(exclude\\)/i', $description);
104 
105  if (!is_array($value) && !$doNotRender && (!preg_match('/[' . LF . CR . ']/', $value) || $isTextarea)) {
106  $itemData = [];
107  $itemData['key'] = $key;
108  $itemData['description'] = $description;
109  if ($isTextarea) {
110  $itemData['type'] = 'textarea';
111  $itemData['value'] = str_replace(['\' . LF . \'', '\' . LF . \''], [LF, LF], $value);
112  } elseif (preg_match('/^(<.*?>)?boolean/i', $description)) {
113  $itemData['type'] = 'checkbox';
114  $itemData['value'] = $value ? '1' : '0';
115  $itemData['checked'] = (bool)$value;
116  } else {
117  $itemData['type'] = 'input';
118  $itemData['value'] = $value;
119  }
120 
121  // Check if the setting is a PHP error code, will trigger a view helper in fluid
122  if ($sectionName === 'SYS' && in_array($key, $this->phpErrorCodesSettings)) {
123  $itemData['phpErrorCode'] = true;
124  }
125 
126  $data[$sectionName][] = $itemData;
127  }
128  }
129  }
130  return $data;
131  }
132 
138  protected function updateLocalConfigurationValues()
139  {
140  $statusObjects = [];
141  if (isset($this->postValues['values']) && is_array($this->postValues['values'])) {
142  $configurationPathValuePairs = [];
143  $commentArray = $this->getDefaultConfigArrayComments();
144  $formValues = $this->postValues['values'];
145  foreach ($formValues as $section => $valueArray) {
146  if (is_array($GLOBALS['TYPO3_CONF_VARS'][$section])) {
147  foreach ($valueArray as $valueKey => $value) {
148  if (isset($GLOBALS['TYPO3_CONF_VARS'][$section][$valueKey])) {
149  $description = trim($commentArray[$section][$valueKey]);
150  if (preg_match('/^string \\(textarea\\)/i', $description)) {
151  // Force Unix linebreaks in textareas
152  $value = str_replace(CR, '', $value);
153  // Preserve linebreaks
154  $value = str_replace(LF, '\' . LF . \'', $value);
155  }
156  if (preg_match('/^boolean/i', $description)) {
157  // When submitting settings in the Install Tool, values that default to "FALSE" or "TRUE"
158  // in EXT:core/Configuration/DefaultConfiguration.php will be sent as "0" resp. "1".
159  // Therefore, reset the values to their boolean equivalent.
160  if ($GLOBALS['TYPO3_CONF_VARS'][$section][$valueKey] === false && $value === '0') {
161  $value = false;
162  } elseif ($GLOBALS['TYPO3_CONF_VARS'][$section][$valueKey] === true && $value === '1') {
163  $value = true;
164  }
165  }
166  // Save if value changed
167  if ((string)$GLOBALS['TYPO3_CONF_VARS'][$section][$valueKey] !== (string)$value) {
168  $configurationPathValuePairs[$section . '/' . $valueKey] = $value;
170  $status = $this->objectManager->get(\TYPO3\CMS\Install\Status\OkStatus::class);
171  $status->setTitle('$GLOBALS[\'TYPO3_CONF_VARS\'][\'' . $section . '\'][\'' . $valueKey . '\']');
172  $status->setMessage('New value = ' . $value);
173  $statusObjects[] = $status;
174  }
175  }
176  }
177  }
178  }
179  if (!empty($statusObjects)) {
181  $configurationManager = $this->objectManager->get(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class);
182  $configurationManager->setLocalConfigurationValuesByPathValuePairs($configurationPathValuePairs);
183  }
184  }
185  return $statusObjects;
186  }
187 
193  protected function getDefaultConfigArrayComments()
194  {
196  $configurationManager = $this->objectManager->get(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class);
197  $string = GeneralUtility::getUrl($configurationManager->getDefaultConfigurationFileLocation());
198 
199  $commentArray = [];
200  $lines = explode(LF, $string);
201  $inConfiguration = false;
202  $mainKey = '';
203  foreach ($lines as $lc) {
204  $lc = trim($lc);
205  if ($inConfiguration) {
206  if ($lc === '];') {
207  break;
208  }
209  if (preg_match('#["\']([\\w_-]*)["\']\\s*=>\\s*(?:(\\[).*|(?:(?!//).)*//\\s*(.*))#i', $lc, $reg)) {
210  if ($reg[2] === '[' && $reg[1] === strtoupper($reg[1])) {
211  $mainKey = $reg[1];
212  } elseif ($mainKey) {
213  $commentArray[$mainKey][$reg[1]] = $reg[3];
214  }
215  }
216  }
217  if ($lc === 'return [') {
218  $inConfiguration = true;
219  }
220  }
221  return $commentArray;
222  }
223 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']