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