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