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