-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml_utils.php
executable file
·94 lines (78 loc) · 3.13 KB
/
html_utils.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
<?
function html_dl($items, $attributes=array()){
$result = array();
foreach($items as $key => $value)
$result[] = "<dt>".$key.'</dt><dd>'.$value.' </dd>';
return "<dl>".implode($result, "\n")."</dl>";
}
function html_input($name, $value, $attributes=array()){
$attributes = array_merge(
array('name' => $name, 'value' => $value), $attributes);
return '<input type="text" '.xml_attributify($attributes).'>';
}
function html_password($name, $attributes=array()){
$attributes = array_merge(array('name' => $name), $attributes);
return '<input type="password" '.xml_attributify($attributes).'>';
}
function html_submit($text=false, $attributes=array()){
if($text) $attributes['value'] = $text;
return '<input type="submit" '.xml_attributify($attributes).'>';
}
function html_select($name, $options, $selected=false, $attributes=array()){
foreach($options as $key=>$value){
$option_attributes = array('value'=>$value);
if($selected && $selected == $key) $option_attributes['selected'] = 'selected';
$result[] = '<option '.xml_attributify($option_attributes).">$value</option>";
}
$attributes = array_merge(array('name' => $name), $attributes);
return '<select '.xml_attributify($attributes).'>'.implode("\n", $result)."</select>";
}
function html_textarea($name, $value, $attributes = array()){
$attributes = array_merge(array(
'rows' => 10, 'cols'=>60, 'name'=> $name), $attributes);
return '<textarea '.xml_attributify($attributes).'>'.$value.'</textarea>';
}
function html_span($content, $attributes=array()){
return '<span '.xml_attributify($attributes).'>'.$content.'</span> ';
}
function html_form_open($url, $method='POST', $attributes=array()){
$attributes = array_merge(
array('action' => $url, 'method' => $method), $attributes);
return '<form '.xml_attributify($attributes).'>';
}
function html_label($for, $text, $attributes = array()){
$attributes = array_merge(
array('for' => $for), $attributes);
return '<label '.xml_attributify($attributes).'>'.$text.'</label> ';
}
function html_js_link($file, $attributes=array()){
if(substr($file, -3) != '.js') $file .= '.js';
$attributes = array_merge(
array('src' => URL_BASE."/public/$file",
'type' => 'text/javascript',
'charset' => 'utf-8'), $attributes);
return '<script '.xml_attributify($attributes).'></script>';
}
function html_css_link($file, $attributes=array()){
if(substr($file, -4) != '.css') $file .= '.css';
$attributes = array_merge(array(
'rel' => "stylesheet",
'href' => URL_BASE."/public/$file",
'type' => "text/css"), $attributes);
return '<link '.xml_attributify($attributes).'/>';
}
function linkify($text, $path, $params = array(), $attributes = array()){
return "<a href=\"".urlify($path, $params)."\" ".xml_attributify($attributes).">$text</a>";
}
function iconify($icon, $attributes=array()){
$path = URL_BASE."/public/icons/$icon.png";
$attributes = array_merge(array('src' => $path), $attributes);
return '<img '.xml_attributify($attributes).'/>';
}
function xml_attributify($attributes){
$result = array();
foreach($attributes as $key=>$value){
$result[] = "$key=\"$value\"";
}
return implode(" ", $result);
}