Cleanup: Updated copyright comments
[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 * [Describe function...]
149 *
150 * @param [type] $cat: ...
151 * @param [type] $theConstants: ...
152 * @param [type] $script: ...
153 * @param [type] $addFields: ...
154 * @return [type] ...
155 */
156 function ext_getForm($cat, $theConstants, $script = "", $addFields = "") {
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 $content .= '<form action="' . htmlspecialchars($script ? $script : t3lib_div::linkThisScript()) . '" name="' . $this->ext_CEformName . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">';
167 $content .= $addFields;
168 $content .= $printFields;
169 $content .= '<input type="Submit" name="submit" value="Update" />';
170
171 $example = $this->ext_displayExample();
172 $content .= $example ? '<hr/>' . $example : "";
173
174 return $content;
175 }
176
177 /**
178 * [Describe function...]
179 *
180 * @return [type] ...
181 */
182 function ext_displayExample() {
183 global $SOBE, $tmpl;
184 if ($this->helpConfig["imagetag"] || $this->helpConfig["description"] || $this->helpConfig["header"]) {
185 $out = '<div align="center">' . $this->helpConfig["imagetag"] . '</div><BR>' .
186 ($this->helpConfig["description"] ? implode(explode("//", $this->helpConfig["description"]), "<BR>") . "<BR>" : "") .
187 ($this->helpConfig["bulletlist"] ? "<ul><li>" . implode(explode("//", $this->helpConfig["bulletlist"]), "<li>") . "</ul>" : "<BR>");
188 }
189 return $out;
190 }
191
192 /**
193 * [Describe function...]
194 *
195 * @param [type] $arr: ...
196 * @return [type] ...
197 */
198 function ext_mergeIncomingWithExisting($arr) {
199 $parseObj = t3lib_div::makeInstance("t3lib_TSparser");
200 $parseObj->parse(implode(LF, $this->ext_incomingValues));
201 $arr2 = $parseObj->setup;
202 return t3lib_div::array_merge_recursive_overrule($arr, $arr2);
203 }
204
205 // extends:
206 function ext_getKeyImage($key) {
207 return '<img' . t3lib_iconWorks::skinImg($this->ext_backPath, 'gfx/rednumbers/' . $key . '.gif', '') . ' hspace="2" align="top" alt="" />';
208 }
209
210 /**
211 * [Describe function...]
212 *
213 * @param [type] $imgConf: ...
214 * @return [type] ...
215 */
216 function ext_getTSCE_config_image($imgConf) {
217 $iFile = $this->ext_localGfxPrefix . $imgConf;
218 $tFile = $this->ext_localWebGfxPrefix . $imgConf;
219 $imageInfo = @getImagesize($iFile);
220 return '<img src="' . $tFile . '" ' . $imageInfo[3] . '>';
221 }
222
223 /**
224 * [Describe function...]
225 *
226 * @param [type] $params: ...
227 * @return [type] ...
228 */
229 function ext_fNandV($params) {
230 $fN = 'data[' . $params["name"] . ']';
231 $fV = $params["value"] = isset($this->ext_realValues[$params["name"]]) ? $this->ext_realValues[$params["name"]] : $params["default_value"];
232 $reg = array();
233 if (preg_match('/^\{[\$][a-zA-Z0-9\.]*\}$/', trim($fV), $reg)) { // Values entered from the constantsedit cannot be constants!
234 $fV = "";
235 }
236 $fV = htmlspecialchars($fV);
237
238 return array($fN, $fV, $params);
239 }
240
241 /**
242 * [Describe function...]
243 *
244 * @param [type] $absPath: ...
245 * @return [type] ...
246 */
247 function ext_loadResources($absPath) {
248 $this->ext_readDirResources($GLOBALS["TYPO3_CONF_VARS"]["MODS"]["web_ts"]["onlineResourceDir"]);
249 if (is_dir($absPath)) {
250 $absPath = rtrim($absPath, '/');
251 $this->readDirectory($absPath);
252 }
253 $this->ext_resourceDims();
254 }
255
256 /**
257 * [Describe function...]
258 *
259 * @param [type] $key: ...
260 * @param [type] $var: ...
261 * @return [type] ...
262 */
263 function ext_putValueInConf($key, $var) {
264 $this->ext_incomingValues[$key] = $key . "=" . $var;
265 }
266
267 /**
268 * [Describe function...]
269 *
270 * @param [type] $key: ...
271 * @return [type] ...
272 */
273 function ext_removeValueInConf($key) {
274 // Nothing...
275 }
276 }
277
278
279 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsstyleconfig.php'])) {
280 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsstyleconfig.php']);
281 }
282 ?>