3d1b53bcbd01d83424a24f6a9e2098eebd791e26
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / TypoScript / ConfigurationForm.php
1 <?php
2 namespace TYPO3\CMS\Core\TypoScript;
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\IconUtility;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Core\Utility\ArrayUtility;
20
21 /**
22 * Provides a simplified layer for making Constant Editor style configuration forms
23 *
24 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
25 */
26 class ConfigurationForm extends ExtendedTemplateService {
27
28 /**
29 * @var array
30 */
31 public $categories = array();
32
33 /**
34 * @var bool
35 */
36 public $ext_dontCheckIssetValues = 1;
37
38 /**
39 * @var string
40 */
41 public $ext_CEformName = 'tsStyleConfigForm';
42
43 /**
44 * @var bool
45 */
46 public $ext_printAll = TRUE;
47
48 /**
49 * @var array
50 */
51 public $ext_incomingValues = array();
52
53 /**
54 * @var array
55 */
56 protected $ext_realValues = array();
57
58 /**
59 * @var string
60 */
61 protected $ext_backPath = '';
62
63 /**
64 * @param string $configTemplate
65 * @param string $pathRel PathRel is the path relative to the typo3/ directory
66 * @param string $pathAbs PathAbs is the absolute path from root
67 * @param string $backPath BackPath is the backReference from current position to typo3/ dir
68 * @return array
69 */
70 public function ext_initTSstyleConfig($configTemplate, $pathRel, $pathAbs, $backPath) {
71 // Do not log time-performance information
72 $this->tt_track = 0;
73 $this->constants = array($configTemplate, '');
74 // The editable constants are returned in an array.
75 $theConstants = $this->generateConfig_constants();
76 $this->ext_localGfxPrefix = $pathAbs;
77 $this->ext_localWebGfxPrefix = $backPath . $pathRel;
78 $this->ext_backPath = $backPath;
79 return $theConstants;
80 }
81
82 /**
83 * Ext set value array
84 *
85 * @param array $theConstants
86 * @param array $valueArray
87 * @return array
88 */
89 public function ext_setValueArray($theConstants, $valueArray) {
90 $temp = $this->flatSetup;
91 $this->flatSetup = array();
92 $this->flattenSetup($valueArray, '', '');
93 $this->objReg = $this->ext_realValues = $this->flatSetup;
94 $this->flatSetup = $temp;
95 foreach ($theConstants as $k => $p) {
96 if (isset($this->objReg[$k])) {
97 $theConstants[$k]['value'] = $this->ext_realValues[$k];
98 }
99 }
100 // Reset the default pool of categories.
101 $this->categories = array();
102 // The returned constants are sorted in categories, that goes into the $this->categories array
103 $this->ext_categorizeEditableConstants($theConstants);
104 return $theConstants;
105 }
106
107 /**
108 * @return array
109 */
110 public function ext_getCategoriesForModMenu() {
111 return $this->ext_getCategoryLabelArray();
112 }
113
114 /**
115 * @param string $cat
116 * @return void
117 */
118 public function ext_makeHelpInformationForCategory($cat) {
119 $this->ext_getTSCE_config($cat);
120 }
121
122 /**
123 * Get the form for extension configuration
124 *
125 * @param string $cat
126 * @param array $theConstants
127 * @param string $script
128 * @param string $addFields
129 * @param string $extKey
130 * @param bool $addFormTag Adds opening <form> tag to the output, if TRUE
131 * @return string The form
132 */
133 public function ext_getForm($cat, $theConstants, $script = '', $addFields = '', $extKey = '', $addFormTag = TRUE) {
134 $this->ext_makeHelpInformationForCategory($cat);
135 $printFields = trim($this->ext_printFields($theConstants, $cat));
136 $content = '';
137 $content .= GeneralUtility::wrapJS('
138 function uFormUrl(aname) {
139 document.' . $this->ext_CEformName . '.action = ' . GeneralUtility::quoteJSvalue(GeneralUtility::linkThisScript() . '#') . '+aname;
140 }
141 ');
142 if ($addFormTag) {
143 $content .= '<form action="' . htmlspecialchars(($script ?: GeneralUtility::linkThisScript())) . '" name="' . $this->ext_CEformName . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">';
144 }
145 $content .= $addFields;
146 $content .= $printFields;
147 $content .= '<input class="btn btn-default" type="submit" name="submit" value="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_tsfe.xlf:update', TRUE) . '" id="configuration-submit-' . htmlspecialchars($extKey) . '" />';
148 $example = $this->ext_displayExample();
149 $content .= $example ? '<hr/>' . $example : '';
150 return $content;
151 }
152
153 /**
154 * Display example
155 *
156 * @return string
157 */
158 public function ext_displayExample() {
159 $out = '';
160 if ($this->helpConfig['imagetag'] || $this->helpConfig['description'] || $this->helpConfig['header']) {
161 $out = '<div align="center">' . $this->helpConfig['imagetag'] . '</div><br />'
162 . ($this->helpConfig['description'] ? implode(explode('//', $this->helpConfig['description']), '<br />') . '<br />' : '')
163 . ($this->helpConfig['bulletlist'] ? '<ul><li>' . implode(explode('//', $this->helpConfig['bulletlist']), '<li>') . '</ul>' : '<BR>');
164 }
165 return $out;
166 }
167
168 /**
169 * Merge incoming with existing
170 *
171 * @param array $arr
172 * @return array
173 */
174 public function ext_mergeIncomingWithExisting($arr) {
175 $parseObj = GeneralUtility::makeInstance(Parser\TypoScriptParser::class);
176 $parseObj->parse(implode(LF, $this->ext_incomingValues));
177 $arr2 = $parseObj->setup;
178 ArrayUtility::mergeRecursiveWithOverrule($arr, $arr2);
179 return $arr;
180 }
181
182 /**
183 * @param string $key
184 * @return string
185 * @deprecated since TYPO3 CMS 7, will be removed with TYPO3 CMS 8
186 */
187 public function ext_getKeyImage($key) {
188 GeneralUtility::logDeprecatedFunction();
189 return '<span class="label label-danger">' . $key . '</span>';
190 }
191
192 /**
193 * @param string $imgConf
194 * @return string
195 */
196 public function ext_getTSCE_config_image($imgConf) {
197 $iFile = $this->ext_localGfxPrefix . $imgConf;
198 $tFile = $this->ext_localWebGfxPrefix . $imgConf;
199 $imageInfo = @getImagesize($iFile);
200 return '<img src="' . $tFile . '" ' . $imageInfo[3] . '>';
201 }
202
203 /**
204 * @param array $params
205 * @return array
206 */
207 public function ext_fNandV($params) {
208 $fN = 'data[' . $params['name'] . ']';
209 $idName = str_replace('.', '-', $params['name']);
210 $fV = ($params['value'] = isset($this->ext_realValues[$params['name']]) ? $this->ext_realValues[$params['name']] : $params['default_value']);
211 $reg = array();
212 // Values entered from the constantsedit cannot be constants!
213 if (preg_match('/^\\{[\\$][a-zA-Z0-9\\.]*\\}$/', trim($fV), $reg)) {
214 $fV = '';
215 }
216 $fV = htmlspecialchars($fV);
217 return array($fN, $fV, $params, $idName);
218 }
219
220 /**
221 * @param string $key
222 * @param string $var
223 * @return void
224 */
225 public function ext_putValueInConf($key, $var) {
226 $this->ext_incomingValues[$key] = $key . '=' . $var;
227 }
228
229 /**
230 * @param string $key
231 * @return void
232 */
233 public function ext_removeValueInConf($key) {
234
235 }
236
237 }