-
Notifications
You must be signed in to change notification settings - Fork 0
/
wcHtml5.php
executable file
·207 lines (197 loc) · 5.04 KB
/
wcHtml5.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
<?php
//! HTML5 helper class
/*!
this class holds functions to help you render HTML5 web code
*/
class wcHtml5 //implements iHtml
{
/// encode line break
static function lineBreak()
{
return '<br>';
}
/// encode any text with the specified symbol, you can also add options
static function encode($text,$symbol,$option='')
{
return "<{$symbol} {$option}>{$text}</{$symbol}>";
}
/// encode text as source code, you can also add options
static function encodeCode($text, $option='')
{
return "<pre $option>$text</pre>";
}
/// encode a CSS link (for HTML head)
static function encodeCss($filename)
{
return sprintf("<link type=\"text/css\" href=\"%s\" rel=\"stylesheet\" />\n", $filename);
}
/// encode a Javascript link (for HTML head)
static function encodeJs($filename)
{
return sprintf("<script type=\"text/javascript\" src=\"%s\"></script>\n", $filename);
}
/// encode a hyperlink
static function encodeLink($text,$link,$option='')
{
return sprintf('<a href="%s" %s>%s</a>',$link,$option,$text);
}
/// encode title with the specified size
static function encodeHeader($text,$size=1)
{
return "<h{$size}>{$text}</h{$size}>";
}
/// encode a list
static function encodeNavList($labelnav,$items,$optionsNAV,$optionsUL='',$optionsLI='')
{
$kc=count($items);
$d="<nav {$optionsNAV}><h5>{$labelnav}</h5><ul {$optionsUL}>";
for ($k=0;$k<$kc;$k++)
{
$d.="<li {$optionsLI}>".$items[$k].'</li>';
}
$d.='</ul></nav>';
return $d;
}
/// encode a navigation list
static function encodeList($items,$options='',$optionsli='')
{
$kc=count($items);
$d="<ul {$options}>";
for ($k=0;$k<$kc;$k++)
{
$d.="<li {$optionsli}>".$items[$k].'</li>';
}
$d.='</ul>';
return $d;
}
/// encode a form with time
static function encodeFormTime($fieldname,$timestamp=0,$inc_min=1)
{
if ($timestamp==0)
$timestamp=time();
$hour=date('H',$timestamp);
$min=date('i',$timestamp);
$code="<select name=\"{$fieldname}_hour\"";
for ($k=1;$k<25;$k++)
{
if ($k==$hour)
$code.="<option value=\"{$k}\" selected=\"selected\">{$k}</option>";
else
$code.="<option value=\"{$k}\">{$k}</option>";
}
$code.="</select>";
$code.="<select name=\"{$fieldname}_minute\"";
for ($k=0;$k<60;$k+=$inc_min)
{
if ($k==$min)
$code.="<option value=\"{$k}\" selected=\"selected\">{$k}</option>";
else
$code.="<option value=\"{$k}\">{$k}</option>";
}
$code.="</select>";
return $code;
}
/// encode a form with date
static function encodeFormDate($fieldname,$timestamp=0,$inc_min=10)
{
if ($timestamp==0)
$timestamp=time();
$year=date('Y',$timestamp);
$month=date('n',$timestamp);
$day=date('j',$timestamp);
$code="<select name=\"{$fieldname}_month\"";
for ($k=1;$k<13;$k++)
{
if ($k==$month)
$code.="<option value=\"{$k}\" selected=\"selected\">{$k}</option>";
else
$code.="<option value=\"{$k}\">{$k}</option>";
}
$code.="</select>";
$code.="<select name=\"{$fieldname}_day\"";
for ($k=1;$k<32;$k++)
{
if ($k==$day)
$code.="<option value=\"{$k}\" selected=\"selected\">{$k}</option>";
else
$code.="<option value=\"{$k}\">{$k}</option>";
}
$code.="</select>";
$code.="<select name=\"{$fieldname}_year\"";
for ($k=$year;$k<$year+$inc_min;$k++)
{
if ($k==$year)
$code.="<option value=\"{$k}\" selected=\"selected\">{$k}</option>";
else
$code.="<option value=\"{$k}\">{$k}</option>";
}
$code.="</select>";
return $code;
}
// encode a label with supplied text
static function encodeLabel($id,$text,$options='')
{
return sprintf("<label for=\"%s\" %s>%s</label>", $id, $options, $text);
}
/// encode radio button
static function encodeRadio($name,$value,$default='',$options='')
{
if ($value==$default)
$checked=" checked=\"checked\"";
else
$checked='';
$code=sprintf("<input type=\"radio\" name=\"%s\" value=\"%s\" %s %s/>", $name, $value , $checked, $options);
return $code;
}
/// encode input box
static function encodeInputbox($name,$value,$options='')
{
$code=sprintf("<input type=\"text\" name=\"%s\" value=\"%s\" %s />", $name, $value, $options);
return $code;
}
/// encode a table list
static function encodeTable($items,$options='',$optionstr='', $optionstd='')
{
$kc=count($items);
$d="<table {$options}>";
for ($k=0;$k<$kc;$k++)
{
$d.="<tr {$optionstr}>";
if (is_array($items[$k]))
{
$ks=count($items[$k]);
foreach ($items[$k] as $i => $value)
{
$d.="<td {$optionstd}>{$value}</td>";
}
$d.="<tr />";
}
}
$d.='</table>';
return $d;
}
///make sure than an URL is standardized, will be prefixed with http://
static function enforceUrl($link)
{
$link = trim(strtolower( $link ));
if (substr($link,0,7) != 'http://' )
$link = 'http://'. $link;
return $link;
}
/// enforce a mailto hyperlink with supplied value
static function enforceMailto($link)
{
$link = trim(strtolower($link));
if ( ($link == '-') || ($link==''))
{
$link = '';
}
else
{
if (substr($link,0,7) != 'mailto:' )
$link = 'mailto:'. $link;
}
return $link;
}
}
?>