[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / Action / Tool / AllConfiguration.php
1 <?php
2 namespace TYPO3\CMS\Install\Controller\Action\Tool;
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\Install\Controller\Action;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Show system environment check results
22 */
23 class AllConfiguration extends Action\AbstractAction {
24
25 /**
26 * Error handlers are a bit mask in PHP. This register hints the View to
27 * add a fluid view helper resolving the bit mask to its representation
28 * as constants again for the specified items in ['SYS'].
29 *
30 * @var array
31 */
32 protected $phpErrorCodesSettings = array(
33 'errorHandlerErrors',
34 'exceptionalErrors',
35 'syslogErrorReporting',
36 'belogErrorReporting',
37 );
38
39 /**
40 * Executes the tool
41 *
42 * @return string Rendered content
43 */
44 protected function executeAction() {
45 if (isset($this->postValues['set']['write'])) {
46 $this->view->assign('configurationValuesSaved', TRUE);
47 $this->view->assign('savedConfigurationValueMessages', $this->updateLocalConfigurationValues());
48 } else {
49 $this->view->assign('data', $this->setUpConfigurationData());
50 }
51
52 return $this->view->render();
53 }
54
55 /**
56 * Set up configuration data
57 *
58 * @return array Configuration data
59 */
60 protected function setUpConfigurationData() {
61 $data = array();
62 $typo3ConfVars = array_keys($GLOBALS['TYPO3_CONF_VARS']);
63 sort($typo3ConfVars);
64 $commentArray = $this->getDefaultConfigArrayComments();
65 foreach ($typo3ConfVars as $sectionName) {
66 $data[$sectionName] = array();
67
68 foreach ($GLOBALS['TYPO3_CONF_VARS'][$sectionName] as $key => $value) {
69 if (isset($GLOBALS['TYPO3_CONF_VARS_extensionAdded'][$sectionName][$key])) {
70 // Don't allow editing stuff which is added by extensions
71 // Make sure we fix potentially duplicated entries from older setups
72 $potentialValue = str_replace(array('\'.chr(10).\'', '\' . LF . \''), array(LF, LF), $value);
73 while (preg_match('/' . preg_quote($GLOBALS['TYPO3_CONF_VARS_extensionAdded'][$sectionName][$key], '/') . '$/', '', $potentialValue)) {
74 $potentialValue = preg_replace('/' . preg_quote($GLOBALS['TYPO3_CONF_VARS_extensionAdded'][$sectionName][$key], '/') . '$/', '', $potentialValue);
75 }
76 $value = $potentialValue;
77 }
78
79 $description = trim($commentArray[$sectionName][$key]);
80 $isTextarea = preg_match('/^(<.*?>)?string \\(textarea\\)/i', $description) ? TRUE : FALSE;
81 $doNotRender = preg_match('/^(<.*?>)?string \\(exclude\\)/i', $description) ? TRUE : FALSE;
82
83 if (!is_array($value) && !$doNotRender && (!preg_match('/[' . LF . CR . ']/', $value) || $isTextarea)) {
84 $itemData = array();
85 $itemData['key'] = $key;
86 $itemData['description'] = $description;
87 if ($isTextarea) {
88 $itemData['type'] = 'textarea';
89 $itemData['value'] = str_replace(array('\'.chr(10).\'', '\' . LF . \''), array(LF, LF), $value);
90 } elseif (preg_match('/^(<.*?>)?boolean/i', $description)) {
91 $itemData['type'] = 'checkbox';
92 $itemData['value'] = $value ? '1' : '0';
93 $itemData['checked'] = (boolean)$value;
94 } else {
95 $itemData['type'] = 'input';
96 $itemData['value'] = $value;
97 }
98
99 // Check if the setting is a PHP error code, will trigger a view helper in fluid
100 if ($sectionName === 'SYS' && in_array($key, $this->phpErrorCodesSettings)) {
101 $itemData['phpErrorCode'] = TRUE;
102 }
103
104 $data[$sectionName][] = $itemData;
105 }
106 }
107 }
108 return $data;
109 }
110
111 /**
112 * Store changed values in LocalConfiguration
113 *
114 * @return string Status messages of changed values
115 */
116 protected function updateLocalConfigurationValues() {
117 $statusObjects = array();
118 if (isset($this->postValues['values']) && is_array($this->postValues['values'])) {
119 $configurationPathValuePairs = array();
120 $commentArray = $this->getDefaultConfigArrayComments();
121 $formValues = $this->postValues['values'];
122 foreach ($formValues as $section => $valueArray) {
123 if (is_array($GLOBALS['TYPO3_CONF_VARS'][$section])) {
124 foreach ($valueArray as $valueKey => $value) {
125 if (isset($GLOBALS['TYPO3_CONF_VARS'][$section][$valueKey])) {
126 $description = trim($commentArray[$section][$valueKey]);
127 if (preg_match('/^string \\(textarea\\)/i', $description)) {
128 // Force Unix linebreaks in textareas
129 $value = str_replace(CR, '', $value);
130 // Preserve linebreaks
131 $value = str_replace(LF, '\' . LF . \'', $value);
132 }
133 if (preg_match('/^boolean/i', $description)) {
134 // When submitting settings in the Install Tool, values that default to "FALSE" or "TRUE"
135 // in EXT:core/Configuration/DefaultConfiguration.php will be sent as "0" resp. "1".
136 // Therefore, reset the values to their boolean equivalent.
137 if ($GLOBALS['TYPO3_CONF_VARS'][$section][$valueKey] === FALSE && $value === '0') {
138 $value = FALSE;
139 } elseif ($GLOBALS['TYPO3_CONF_VARS'][$section][$valueKey] === TRUE && $value === '1') {
140 $value = TRUE;
141 }
142 }
143 // Save if value changed
144 if ((string)$GLOBALS['TYPO3_CONF_VARS'][$section][$valueKey] !== (string)$value) {
145 $configurationPathValuePairs[$section . '/' . $valueKey] = $value;
146 /** @var $message \TYPO3\CMS\Install\Status\StatusInterface */
147 $status = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\OkStatus');
148 $status->setTitle('$TYPO3_CONF_VARS[\'' . $section . '\'][\'' . $valueKey . '\']');
149 $status->setMessage('New value = ' . $value);
150 $statusObjects[] = $status;
151 }
152 }
153 }
154 }
155 }
156 if (count($statusObjects)) {
157 /** @var \TYPO3\CMS\Core\Configuration\ConfigurationManager $configurationManager */
158 $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
159 $configurationManager->setLocalConfigurationValuesByPathValuePairs($configurationPathValuePairs);
160 }
161 }
162 return $statusObjects;
163 }
164
165 /**
166 * Make an array of the comments in the EXT:core/Configuration/DefaultConfiguration.php file
167 *
168 * @return array
169 */
170 protected function getDefaultConfigArrayComments() {
171 /** @var \TYPO3\CMS\Core\Configuration\ConfigurationManager $configurationManager */
172 $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
173 $string = GeneralUtility::getUrl($configurationManager->getDefaultConfigurationFileLocation());
174
175 $commentArray = array();
176 $lines = explode(LF, $string);
177 $in = 0;
178 $mainKey = '';
179 foreach ($lines as $lc) {
180 $lc = trim($lc);
181 if ($in) {
182 if ($lc === ');') {
183 $in = 0;
184 } else {
185 if (preg_match('/["\']([[:alnum:]_-]*)["\'][[:space:]]*=>(.*)/i', $lc, $reg)) {
186 preg_match('/,[\\t\\s]*\\/\\/(.*)/i', $reg[2], $creg);
187 $theComment = trim($creg[1]);
188 if (substr(strtolower(trim($reg[2])), 0, 5) == 'array' && $reg[1] === strtoupper($reg[1])) {
189 $mainKey = trim($reg[1]);
190 } elseif ($mainKey) {
191 $commentArray[$mainKey][$reg[1]] = $theComment;
192 }
193 }
194 }
195 }
196 if ($lc === 'return array(') {
197 $in = 1;
198 }
199 }
200 return $commentArray;
201 }
202 }