-
Notifications
You must be signed in to change notification settings - Fork 0
/
html.php
291 lines (234 loc) · 7 KB
/
html.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
<?php
require_once(dirname(__FILE__).'/purlencode.php');
define('br', "<br />\n");
define('hr', "<hr />\n");
function tabular($d) {
print("<tr><td>". str_replace("\t", "</td><td>", $d). "</td></tr>\n");
}
function div($class, $contents) {
return("\n<div class='$class'>" . $contents . "\n</div>");
}
function heading($level = 1, $data) {
return("\n<h$level>" . $data . "\n</h$level>");
}
function preformat($s) {
return("<pre>$s</pre>");
}
function checkbox($name, $value) {
return("<input type='checkbox' name='$name' value='TRUE' " . ($value ? "checked='checked'" : '') . " />");
}
function radiogroup($name, $values, $default = NULL, $separator = '<br />') {
if(count($values) == 0) return '';
$value = array_shift($values);
return "<input name='$name' type='radio' value='$value'".
($value == $default ? " checked='checked'" : "").
" />$value$separator".radiogroup($name,$values,$default,$separator);
}
function p($s) {
return "<p>$s</p>";
}
function fieldset($name, $s) {
return "<fieldset><legend>$name</legend>$s</fieldset>";
}
function button($name, $text, $value = NULL) {
if(is_null($value)) $value = $text;
return("<button name='$name' value='$value' type='submit'>$text</button>");
}
function doctype($s) {
static $types = array(
"XHTML/1.0" => "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">",
"XHTML/1.0 Frameset" => "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
return $types[$s];
}
function form($action, $content, $enctype = '') {
$method = 'POST';
$action = pqurlencode($action);
if($enctype) {
$enctype = "enctype='$enctype'";
}
return("\n<form action='$action' accept-charset='UTF-8' method='$method' $enctype>"
. $content . "\n</form>");
}
function javascript($s) {
return "<script language='JavaScript'> $s </script>";
}
function body($s) {
return '<body>'.$s.'</body>';
}
function html($s) {
return '<html>'.$s.'</html>';
}
function head($s) {
return '<head>'.$s.'</head>';
}
function title($s) {
return '<title>'.$s.'</title>';
}
function stylesheet($filename) {
if(is_file($filename)) {
return "<link rel='StyleSheet' href='$filename' type='text/css' />";
} else {
// return "Stylesheet not found!";
}
}
function hyperlink($destination, $content, $encode = true) {
if($encode) $destination = htmlspecialchars(pqurlencode($destination));
$content = htmlspecialchars(trim($content));
return("<a href='$destination'>$content</a>");
}
function popup_hyperlink($destination = '', $content, $attribs = array()) {
global $PHP_SELF;
if(!$destination) {
$destination = $PHP_SELF;
}
if(count($attribs) > 0) {
foreach($attribs as $k => $a) {
$attribs[$k] = "$k=$a";
}
$features = ',"'.join(",",$attribs).'"';
} else {
$features = '';
}
return("\n<a href='$destination' ".
"onClick='window.open(\"$destination\",null$features); return false;' ".
"target='_new'>$content</a>");
}
function textarea($key, $value = '', $cols = 60, $rows = 10) {
return("\n<textarea name='$key' cols='$cols' rows='$rows' wrap='virtual'>".htmlspecialchars($value, NULL, "UTF-8")."</textarea>");
}
function fileupload($name) {
return "<input name='$name' type='file' />";
}
function addresstextarea($key, $value='') {
return textarea($key, $value, 3, 40);
}
function address($address) {
return "<address>".$address."</address>";
}
function field($key, $value = '', $type='text') {
if($type == 'textarea') {
return(textarea($key, $value));
} else {
return(
"\n<input type='$type' class='$type' name='$key' ".
"value='$value' />"
);
}
}
function hidden($key, $value) {
return(field($key, $value, 'hidden'));
}
function textinput($key, $value, $size = 8) {
return("<input type='text' name='$key' value='$value' size='$size' />");
}
function password_field($key, $value = '') {
return(field($key, $value, 'password'));
}
function staticfield($key, $value) {
return($value. field($key, $value, 'hidden'));
}
function image($file, $alt = "") {
return("<img src='".pqurlencode($file)."' alt='$alt' />");
}
/* function hoverimagelink($url, $lowfile, $hifile, $alt = '') {
return("<a href='$url' id='".($id=html_id())."'>".
"<img src='$lowfile' alt='$alt' /></a>".
"<script type='text/javascript'></script>"));
} */
function html_id() {
global $_HTML_CURRENT_ID;
return ++$_HTML_CURRENT_ID;
}
function table($contents) {
return("\n<table border='0'>" . $contents . "\n</table>");
}
# "Alignment" table -- no space between cells, so it's good for aligning stuff transparently, such as sidebars (or so Rick says)
function atable($contents) {
return("\n<table border='0' cellspacing='0' cellpadding='0'>" . $contents . "\n</table>");
}
function table_spaced($contents, $cellspacing = 4, $cellpadding = 4) {
return("\n<table border='0' cellspacing='$cellspacing' cellpadding='$cellpadding'>" . $contents . "\n</table>");
}
function tr($contents) {
return("\n<tr>" . $contents . "\n</tr>");
}
function tgroup($contents) {
return("\n<span class='tgroup'>" . $contents . "\n</span>");
}
function td($contents) {
if(is_int($contents) or is_float($contents) or ($contents[0] == '$')) {
$class=" class='numeric'";
} else {
$class='';
}
return("\n<td valign='top'$class>" . $contents . "\n</td>");
}
function spantd($span = 1, $contents) {
return("\n<td valign='top' colspan='$span'>" . $contents . "\n</td>");
}
function rtd($contents) {
return("<td valign='top' align='right'>$contents</td>");
}
function th($contents, $align='center') {
return("\n<th align='$align'>" . $contents . "\n</th>");
}
function ul($data) {
return('<ul>' . $data . '</ul>');
}
function ol($data) {
return('<ol>' . $data . '</ol>');
}
function li($data) {
if($data) {
return('<li>' . $data . '</li>');
} else {
return '';
}
}
function html_dl($s) {
return('<dl>'.$s.'</dl>');
}
function dt($s) {
return('<dt>'.$s.'</dt>');
}
function dd($s) {
return('<dd>'.$s.'</dd>');
}
function comment($str) {
return("<!-- $str -->\n");
}
function tableheaders() {
$args = func_get_args();
foreach($args as $heading) {
$o .= th($heading);
}
return $o;
}
function row2($c1, $c2) {
return tr(td($c1).td($c2));
}
function row1($c1) {
return tr(td($c1));
}
function hrow2($c1, $c2) {
return tr(th($c1, 'left').td($c2));
}
function select($name, $options = array(), $default = NULL) {
$s = array();
foreach($options as $value => $option) {
if(!$option) $option = $value;
if($option == $default) {
$s[] = "<option value='$value' selected='selected'>$option</option>";
} else {
$s[] = "<option value='$value'>$option</option>";
}
}
return "<select name='$name'>".join('', $s)."</select>";
}
function submit($value = 'Submit', $name = NULL) {
return("<input type='submit' value='$value' ".(
is_null($name) ? "" : "name='$name'"
)." />");
}
?>