Fixed bug #17184: Disable the CSRF protection in ExtDirect calls coming from the...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tsstyleconfig.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Provides a simplified layer for making Constant Editor style configuration forms
29 *
30 * $Id$
31 *
32 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
33 */
34 /**
35 * [CLASS/FUNCTION INDEX of SCRIPT]
36 *
37 *
38 *
39 * 79: class t3lib_tsStyleConfig extends t3lib_tsparser_ext
40 * 98: function ext_initTSstyleConfig($configTemplate,$pathRel,$pathAbs,$backPath)
41 * 118: function ext_setValueArray($theConstants,$valueArray)
42 * 145: function ext_getCategoriesForModMenu()
43 * 155: function ext_makeHelpInformationForCategory($cat)
44 * 168: function ext_getForm($cat,$theConstants,$script="",$addFields="")
45 * 175: function uFormUrl(aname)
46 * 197: function ext_displayExample()
47 * 213: function ext_mergeIncomingWithExisting($arr)
48 * 221: function ext_getKeyImage($key)
49 * 231: function ext_getTSCE_config_image($imgConf)
50 * 244: function ext_fNandV($params)
51 * 262: function ext_loadResources($absPath)
52 * 278: function ext_putValueInConf($key, $var)
53 * 288: function ext_removeValueInConf($key)
54 *
55 * TOTAL FUNCTIONS: 14
56 * (This index is automatically created/updated by the extension "extdeveval")
57 *
58 */
59
60
61 /**
62 * Provides a simplified layer for making Constant Editor style configuration forms
63 *
64 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
65 * @package TYPO3
66 * @subpackage t3lib
67 */
68 class t3lib_tsStyleConfig extends t3lib_tsparser_ext {
69 // internal
70 var $categories = array();
71 var $ext_dontCheckIssetValues = 1;
72 var $ext_CEformName = "tsStyleConfigForm";
73 var $ext_noCEUploadAndCopying = 1;
74 var $ext_printAll = 1;
75 var $ext_defaultOnlineResourceFlag = 1;
76
77 var $ext_incomingValues = array();
78
79
80 /**
81 * @param string pathRel is the path relative to the typo3/ directory
82 * @param string pathAbs is the absolute path from root
83 * @param string backPath is the backReference from current position to typo3/ dir
84 * @param [type] $backPath: ...
85 * @return [type] ...
86 */
87 function ext_initTSstyleConfig($configTemplate, $pathRel, $pathAbs, $backPath) {
88 $this->tt_track = 0; // Do not log time-performance information
89 $this->constants = array($configTemplate, "");
90
91 $theConstants = $this->generateConfig_constants(); // The editable constants are returned in an array.
92
93 $this->ext_localGfxPrefix = $pathAbs;
94 $this->ext_localWebGfxPrefix = $backPath . $pathRel;
95 $this->ext_backPath = $backPath;
96
97 return $theConstants;
98 }
99
100 /**
101 * [Describe function...]
102 *
103 * @param [type] $theConstants: ...
104 * @param [type] $valueArray: ...
105 * @return [type] ...
106 */
107 function ext_setValueArray($theConstants, $valueArray) {
108
109 $temp = $this->flatSetup;
110 $this->flatSetup = array();
111 $this->flattenSetup($valueArray, "", "");
112 $this->objReg = $this->ext_realValues = $this->flatSetup;
113 $this->flatSetup = $temp;
114
115
116 foreach ($theConstants as $k => $p) {
117 if (isset($this->objReg[$k])) {
118 $theConstants[$k]["value"] = $this->ext_realValues[$k];
119 }
120 }
121
122 $this->categories = array(); // Reset the default pool of categories.
123 $this->ext_categorizeEditableConstants($theConstants); // The returned constants are sorted in categories, that goes into the $this->categories array
124
125 return $theConstants;
126 }
127
128 /**
129 * [Describe function...]
130 *
131 * @return [type] ...
132 */
133 function ext_getCategoriesForModMenu() {
134 return $this->ext_getCategoryLabelArray();
135 }
136
137 /**
138 * [Describe function...]
139 *
140 * @param [type] $cat: ...
141 * @return [type] ...
142 */
143 function ext_makeHelpInformationForCategory($cat) {
144 return $this->ext_getTSCE_config($cat);
145 }
146
147 /**
148 * Get the form for extension configuration
149 *
150 * @param string $cat
151 * @param array $theConstants
152 * @param string $script
153 * @param string $addFields
154 * @param string $extKey
155 * @return string the form
156 */
157 function ext_getForm($cat, $theConstants, $script = "", $addFields = "", $extKey = "") {
158 $this->ext_makeHelpInformationForCategory($cat);
159 $printFields = trim($this->ext_printFields($theConstants, $cat));
160
161 $content = '';
162 $content .= t3lib_div::wrapJS('
163 function uFormUrl(aname) {
164 document.' . $this->ext_CEformName . '.action = "' . t3lib_div::linkThisScript() . '#"+aname;
165 }
166 ');
167 $content .= '<form action="' . htmlspecialchars($script ? $script : t3lib_div::linkThisScript()) . '" name="' . $this->ext_CEformName . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">';
168 $content .= $addFields;
169 $content .= $printFields;
170 $content .= '<input type="Submit" name="submit" value="' .
171 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_tsfe.xml:update', TRUE) . '" id="configuration-submit-' . htmlspecialchars($extKey) . '" />';
172
173 $example = $this->ext_displayExample();
174 $content .= $example ? '<hr/>' . $example : "";
175
176 return $content;
177 }
178
179 /**
180 * [Describe function...]
181 *
182 * @return [type] ...
183 */
184 function ext_displayExample() {
185 global $SOBE, $tmpl;
186 if ($this->helpConfig["imagetag"] || $this->helpConfig["description"] || $this->helpConfig["header"]) {
187 $out = '<div align="center">' . $this->helpConfig["imagetag"] . '</div><BR>' .
188 ($this->helpConfig["description"] ? implode(explode("//", $this->helpConfig["description"]), "<BR>") . "<BR>" : "") .
189 ($this->helpConfig["bulletlist"] ? "<ul><li>" . implode(explode("//", $this->helpConfig["bulletlist"]), "<li>") . "</ul>" : "<BR>");
190 }
191 return $out;
192 }
193
194 /**
195 * [Describe function...]
196 *
197 * @param [type] $arr: ...
198 * @return [type] ...
199 */
200 function ext_mergeIncomingWithExisting($arr) {
201 $parseObj = t3lib_div::makeInstance("t3lib_TSparser");
202 $parseObj->parse(implode(LF, $this->ext_incomingValues));
203 $arr2 = $parseObj->setup;
204 return t3lib_div::array_merge_recursive_overrule($arr, $arr2);
205 }
206
207 // extends:
208 function ext_getKeyImage($key) {
209 return '<img' . t3lib_iconWorks::skinImg($this->ext_backPath, 'gfx/rednumbers/' . $key . '.gif', '') . ' hspace="2" align="top" alt="" />';
210 }
211
212 /**
213 * [Describe function...]
214 *
215 * @param [type] $imgConf: ...
216 * @return [type] ...
217 */
218 function ext_getTSCE_config_image($imgConf) {
219 $iFile = $this->ext_localGfxPrefix . $imgConf;
220 $tFile = $this->ext_localWebGfxPrefix . $imgConf;
221 $imageInfo = @getImagesize($iFile);
222 return '<img src="' . $tFile . '" ' . $imageInfo[3] . '>';
223 }
224
225 /**
226 * [Describe function...]
227 *
228 * @param [type] $params: ...
229 * @return [type] ...
230 */
231 function ext_fNandV($params) {
232 $fN = 'data[' . $params["name"] . ']';
233 $fV = $params["value"] = isset($this->ext_realValues[$params["name"]]) ? $this->ext_realValues[$params["name"]] : $params["default_value"];
234 $reg = array();
235 if (preg_match('/^\{[\$][a-zA-Z0-9\.]*\}$/', trim($fV), $reg)) { // Values entered from the constantsedit cannot be constants!
236 $fV = "";
237 }
238 $fV = htmlspecialchars($fV);
239
240 return array($fN, $fV, $params);
241 }
242
243 /**
244 * [Describe function...]
245 *
246 * @param [type] $absPath: ...
247 * @return [type] ...
248 */
249 function ext_loadResources($absPath) {
250 $this->ext_readDirResources($GLOBALS["TYPO3_CONF_VARS"]["MODS"]["web_ts"]["onlineResourceDir"]);
251 if (is_dir($absPath)) {
252 $absPath = rtrim($absPath, '/');
253 $this->readDirectory($absPath);
254 }
255 $this->ext_resourceDims();
256 }
257
258 /**
259 * [Describe function...]
260 *
261 * @param [type] $key: ...
262 * @param [type] $var: ...
263 * @return [type] ...
264 */
265 function ext_putValueInConf($key, $var) {
266 $this->ext_incomingValues[$key] = $key . "=" . $var;
267 }
268
269 /**
270 * [Describe function...]
271 *
272 * @param [type] $key: ...
273 * @return [type] ...
274 */
275 function ext_removeValueInConf($key) {
276 // Nothing...
277 }
278 }
279
280
281 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsstyleconfig.php'])) {
282 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsstyleconfig.php']);
283 }
284 ?>