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