Revert "[RELEASE] Release of TYPO3 4.6.0alpha1"
[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 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
31 */
32 /**
33 * [CLASS/FUNCTION INDEX of SCRIPT]
34 *
35 *
36 *
37 * 79: class t3lib_tsStyleConfig extends t3lib_tsparser_ext
38 * 98: function ext_initTSstyleConfig($configTemplate,$pathRel,$pathAbs,$backPath)
39 * 118: function ext_setValueArray($theConstants,$valueArray)
40 * 145: function ext_getCategoriesForModMenu()
41 * 155: function ext_makeHelpInformationForCategory($cat)
42 * 168: function ext_getForm($cat,$theConstants,$script="",$addFields="")
43 * 175: function uFormUrl(aname)
44 * 197: function ext_displayExample()
45 * 213: function ext_mergeIncomingWithExisting($arr)
46 * 221: function ext_getKeyImage($key)
47 * 231: function ext_getTSCE_config_image($imgConf)
48 * 244: function ext_fNandV($params)
49 * 262: function ext_loadResources($absPath)
50 * 278: function ext_putValueInConf($key, $var)
51 * 288: function ext_removeValueInConf($key)
52 *
53 * TOTAL FUNCTIONS: 14
54 * (This index is automatically created/updated by the extension "extdeveval")
55 *
56 */
57
58
59 /**
60 * Provides a simplified layer for making Constant Editor style configuration forms
61 *
62 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
63 * @package TYPO3
64 * @subpackage t3lib
65 */
66 class t3lib_tsStyleConfig extends t3lib_tsparser_ext {
67 // internal
68 var $categories = array();
69 var $ext_dontCheckIssetValues = 1;
70 var $ext_CEformName = "tsStyleConfigForm";
71 var $ext_noCEUploadAndCopying = 1;
72 var $ext_printAll = 1;
73 var $ext_defaultOnlineResourceFlag = 1;
74
75 var $ext_incomingValues = array();
76
77
78 /**
79 * @param string pathRel is the path relative to the typo3/ directory
80 * @param string pathAbs is the absolute path from root
81 * @param string backPath is the backReference from current position to typo3/ dir
82 * @param [type] $backPath: ...
83 * @return [type] ...
84 */
85 function ext_initTSstyleConfig($configTemplate, $pathRel, $pathAbs, $backPath) {
86 $this->tt_track = 0; // Do not log time-performance information
87 $this->constants = array($configTemplate, "");
88
89 $theConstants = $this->generateConfig_constants(); // The editable constants are returned in an array.
90
91 $this->ext_localGfxPrefix = $pathAbs;
92 $this->ext_localWebGfxPrefix = $backPath . $pathRel;
93 $this->ext_backPath = $backPath;
94
95 return $theConstants;
96 }
97
98 /**
99 * [Describe function...]
100 *
101 * @param [type] $theConstants: ...
102 * @param [type] $valueArray: ...
103 * @return [type] ...
104 */
105 function ext_setValueArray($theConstants, $valueArray) {
106
107 $temp = $this->flatSetup;
108 $this->flatSetup = array();
109 $this->flattenSetup($valueArray, "", "");
110 $this->objReg = $this->ext_realValues = $this->flatSetup;
111 $this->flatSetup = $temp;
112
113
114 foreach ($theConstants as $k => $p) {
115 if (isset($this->objReg[$k])) {
116 $theConstants[$k]["value"] = $this->ext_realValues[$k];
117 }
118 }
119
120 $this->categories = array(); // Reset the default pool of categories.
121 $this->ext_categorizeEditableConstants($theConstants); // The returned constants are sorted in categories, that goes into the $this->categories array
122
123 return $theConstants;
124 }
125
126 /**
127 * [Describe function...]
128 *
129 * @return [type] ...
130 */
131 function ext_getCategoriesForModMenu() {
132 return $this->ext_getCategoryLabelArray();
133 }
134
135 /**
136 * [Describe function...]
137 *
138 * @param [type] $cat: ...
139 * @return [type] ...
140 */
141 function ext_makeHelpInformationForCategory($cat) {
142 return $this->ext_getTSCE_config($cat);
143 }
144
145 /**
146 * Get the form for extension configuration
147 *
148 * @param string $cat
149 * @param array $theConstants
150 * @param string $script
151 * @param string $addFields
152 * @param string $extKey
153 * @param bool Adds opening <form> tag to the ouput, if TRUE
154 * @return string the form
155 */
156 function ext_getForm($cat, $theConstants, $script = "", $addFields = "", $extKey = "", $addFormTag = TRUE) {
157 $this->ext_makeHelpInformationForCategory($cat);
158 $printFields = trim($this->ext_printFields($theConstants, $cat));
159
160 $content = '';
161 $content .= t3lib_div::wrapJS('
162 function uFormUrl(aname) {
163 document.' . $this->ext_CEformName . '.action = "' . t3lib_div::linkThisScript() . '#"+aname;
164 }
165 ');
166
167 if ($addFormTag) {
168 $content .= '<form action="' . htmlspecialchars($script ? $script : t3lib_div::linkThisScript()) . '" name="' . $this->ext_CEformName . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">';
169 }
170 $content .= $addFields;
171 $content .= $printFields;
172 $content .= '<input type="submit" name="submit" value="' .
173 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_tsfe.xml:update', TRUE) . '" id="configuration-submit-' . htmlspecialchars($extKey) . '" />';
174
175 $example = $this->ext_displayExample();
176 $content .= $example ? '<hr/>' . $example : "";
177
178 return $content;
179 }
180
181 /**
182 * [Describe function...]
183 *
184 * @return [type] ...
185 */
186 function ext_displayExample() {
187 global $SOBE, $tmpl;
188 if ($this->helpConfig["imagetag"] || $this->helpConfig["description"] || $this->helpConfig["header"]) {
189 $out = '<div align="center">' . $this->helpConfig["imagetag"] . '</div><BR>' .
190 ($this->helpConfig["description"] ? implode(explode("//", $this->helpConfig["description"]), "<BR>") . "<BR>" : "") .
191 ($this->helpConfig["bulletlist"] ? "<ul><li>" . implode(explode("//", $this->helpConfig["bulletlist"]), "<li>") . "</ul>" : "<BR>");
192 }
193 return $out;
194 }
195
196 /**
197 * [Describe function...]
198 *
199 * @param [type] $arr: ...
200 * @return [type] ...
201 */
202 function ext_mergeIncomingWithExisting($arr) {
203 $parseObj = t3lib_div::makeInstance("t3lib_TSparser");
204 $parseObj->parse(implode(LF, $this->ext_incomingValues));
205 $arr2 = $parseObj->setup;
206 return t3lib_div::array_merge_recursive_overrule($arr, $arr2);
207 }
208
209 // extends:
210 function ext_getKeyImage($key) {
211 return '<img' . t3lib_iconWorks::skinImg($this->ext_backPath, 'gfx/rednumbers/' . $key . '.gif', '') . ' hspace="2" align="top" alt="" />';
212 }
213
214 /**
215 * [Describe function...]
216 *
217 * @param [type] $imgConf: ...
218 * @return [type] ...
219 */
220 function ext_getTSCE_config_image($imgConf) {
221 $iFile = $this->ext_localGfxPrefix . $imgConf;
222 $tFile = $this->ext_localWebGfxPrefix . $imgConf;
223 $imageInfo = @getImagesize($iFile);
224 return '<img src="' . $tFile . '" ' . $imageInfo[3] . '>';
225 }
226
227 /**
228 * [Describe function...]
229 *
230 * @param [type] $params: ...
231 * @return [type] ...
232 */
233 function ext_fNandV($params) {
234 $fN = 'data[' . $params["name"] . ']';
235 $fV = $params["value"] = isset($this->ext_realValues[$params["name"]]) ? $this->ext_realValues[$params["name"]] : $params["default_value"];
236 $reg = array();
237 if (preg_match('/^\{[\$][a-zA-Z0-9\.]*\}$/', trim($fV), $reg)) { // Values entered from the constantsedit cannot be constants!
238 $fV = "";
239 }
240 $fV = htmlspecialchars($fV);
241
242 return array($fN, $fV, $params);
243 }
244
245 /**
246 * [Describe function...]
247 *
248 * @param [type] $absPath: ...
249 * @return [type] ...
250 */
251 function ext_loadResources($absPath) {
252 $this->ext_readDirResources($GLOBALS["TYPO3_CONF_VARS"]["MODS"]["web_ts"]["onlineResourceDir"]);
253 if (is_dir($absPath)) {
254 $absPath = rtrim($absPath, '/');
255 $this->readDirectory($absPath);
256 }
257 $this->ext_resourceDims();
258 }
259
260 /**
261 * [Describe function...]
262 *
263 * @param [type] $key: ...
264 * @param [type] $var: ...
265 * @return [type] ...
266 */
267 function ext_putValueInConf($key, $var) {
268 $this->ext_incomingValues[$key] = $key . "=" . $var;
269 }
270
271 /**
272 * [Describe function...]
273 *
274 * @param [type] $key: ...
275 * @return [type] ...
276 */
277 function ext_removeValueInConf($key) {
278 // Nothing...
279 }
280 }
281
282
283 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsstyleconfig.php'])) {
284 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsstyleconfig.php']);
285 }
286 ?>