-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe107HelperStaticTagObj_class.php
317 lines (283 loc) · 7.85 KB
/
e107HelperStaticTagObj_class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php
// To Do : See e107HelperForm_class.php
/**
* e107 Static Tag Object Helper class
* <b>CVS Details:</b>
* <ul>
* <li>$Source: e:\_repository\e107_plugins/e107helpers/e107HelperStaticTagObj_class.php,v $</li>
* <li>$Date: 2007/08/01 23:36:32 $</li>
* </ul>
* @author $Author: Neil $
* @version $Revision: 1.4 $
* @copyright Released under the terms and conditions of the GNU General Public License (http://gnu.org).
* @package e107HelperForm
*/
/**
* A private Helper class for the e107 CMS system.
* Used by the e107HelperForm class.
* A static tag is one which cannot submit data to the mid tier (e.g. headers, spans, divs)
* Each static tag object holds enough information to render the tag on the screen.
* Note: this class is normally instansiated by the e107HelperForm class.
*
* @package e107HelperForm
*/
class e107HelperStaticTagObj {
/**#@+
* @access private
*/
var $_tagType; // The type of the tag
var $_ix; // Index of current instance of this tag (when batch forms are bing used
var $_name; // Tag name
var $_class; // CSS class(es) for the tag
var $_text; // The text for
var $_paragraphText; // The paragraph text for
var $_values; // Array holding value for the tag
var $_attributes; // Array of attributes for this tag
var $_styles; // Array of style attributes for this tag
/**#@-*/
/**
* Constructor
*/
function __construct($name, $tagType) {
$this->_name = $name;
$this->_ix = 0;
$this->_tagType = $tagType;
$this->_class = "";
$this->_text = "";
$this->_paragraphText= array();
$this->_attributes = array();
$this->_styles = array();
$this->_values = array();
$this->_batchTag = false;
}
// *********************************************************************************************
// Public setter methods
// *********************************************************************************************
/*
* Add a value to the tag
*/
function addValue($value, $text="") {
if ("" != $text) {
$value = array($value, $text);
}
$this->_values[] = $value;
}
/*
* Add CSS class(es).
* @param $new the CSS class(es) (if more than one, separate by spaces)
*/
function addCSSClass($new) {
$this->_class = $new;
}
/*
* Add text
* @param $new the text
*/
function addText($new) {
$this->_text = $new;
}
/*
* Add paragraph text
* @param $new the text
*/
function addParagraphText($new) {
array_push($this->_paragraphText, $new);
}
/*
* Add an attribute to the tag
*/
function addAttribute($att, $value) {
$tempArray = array($att => $value);
$this->_attributes = array_merge($this->_attributes, $tempArray);
}
/*
* Add a style attribute to the tag
*/
function addStyle($att, $value) {
$tempArray = array($att => $value);
$this->_styles = array_merge($this->_styles, $tempArray);
}
/*
* Set a flag to indicate that this field is part of a repeating group
*/
function setBatchTag($new) {
$this->_batchTag = $new;
}
/*
* Set the index for the current item (in batch mode)
* @param $ix the index value
*/
function setIX($ix) {
$this->_ix = $ix;
}
// *********************************************************************************************
// Public getter methods
// *********************************************************************************************
/*
* Get the current value of this tag (looks for user input before returning current value)
* @param bool to indicate if return value should be decorated with HTML value attibute (true, the default) or not (false)
* @return string the value of this tag
*/
function getValue($asAtt=true) {
$value = "";
if ($asAtt) {
$value = " value='".$this->_values[0]."'";
} else {
$value = $this->_values[0];
}
return $value;
}
/*
*
* @param
* @return
*/
function getText($ix=false) {
return $this->_text;
}
/*
*
* @param
* @return
*/
function _getParagraphText($ix=false) {
if ($ix === false) {
return $this->_paragraphText;
} else {
return $this->_paragraphText($ix);
}
}
function getParagraphTextCount() {
return count($this->_text);
}
// *********************************************************************************************
// HTML generation methods
// *********************************************************************************************
/*
*
* @param
* @return
*/
function getTag() {
$text = "";
switch ($this->_tagType) {
case "notelist" : {
$text = "<div";
$text .= $this->_getClass();
$text .= $this->_getAttributes();
$text .= $this->_getStyles();
$text .= ">";
$text .= $this->_getText();
$text .= "<ul>";
foreach($this->_getParagraphText() as $txt) {
$text .= "<li>$txt</li>";
}
$text .= "</ul>";
$text .= "</div>";
break;
}
default : {
$text = "<".$this->_tagType;
$text .= $this->_getClass();
$text .= $this->_getAttributes();
$text .= $this->_getStyles();
$text .= ">";
$text .= $this->_getText();
$text .= "</".$this->_tagType.">";
break;
}
}
return $text;
}
/*
* Get the current index
* @return the current index
*/
function _getIX() {
return $this->_ix;
}
// *********************************************************************************************
// Public helper methods
// *********************************************************************************************
/*
* Check to see if this tag is part of a repeating group
* @return true if tag is part of a repeating group
*/
function isBatchTag() {
global $pref;
return varset($pref[$this->_attributes["id"]."_pref"], $this->_batchTag);
}
// *********************************************************************************************
// Private helper methods
// *********************************************************************************************
/*
*
* @param
* @return
* @access private
*/
function _getClass() {
if (strlen($this->_class) > 0) {
return " class='".$this->_class."'";
}
return "";
}
/*
*
* @param
* @return
* @access private
*/
function getName() {
return " name='".$this->_name."'";
}
/*
*
* @param
* @return
* @access private
*/
function _getText() {
return $this->_text;
}
function _getAttributeSet() {
$text .= $this->_getClass();
$text .= $this->_getAttributes();
$text .= $this->_getStyles();
return $text;
}
/*
*
* @param
* @return
* @access private
*/
function _getAttributes() {
$text = "";
$keys = array_keys($this->_attributes);
foreach ($keys as $key) {
$text .= " $key='".$this->_attributes[$key]."'";
}
return $text;
}
/*
*
* @param
* @return
* @access private
*/
function _getStyles() {
if (count($this->_styles) == 0) {
// No style attributes, return empty string
return "";
}
$text = " style='";
$keys = array_keys($this->_styles);
foreach ($keys as $key) {
$text .= "$key:".$this->_styles[$key].";";
}
$text .= "'";
return $text;
}
}
?>