-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhtml.class.php
More file actions
executable file
·184 lines (170 loc) · 5.08 KB
/
html.class.php
File metadata and controls
executable file
·184 lines (170 loc) · 5.08 KB
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
<?php
/**
* html.class.php
*
* This contains functions needed to generate html output.
*
* @copyright 2003-2021 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: html.class.php 14885 2021-02-05 19:19:32Z pdontthink $
* @package squirrelmail
*/
/**
* Undocumented class
* @package squirrelmail
*/
class html {
var $tag, $text, $style, $class,
$id, $html_el = array(), $javascript, $xtr_prop;
/**
* Constructor (PHP5 style, required in some future version of PHP)
*/
function __construct($tag='', $text='', $style ='', $class='', $id='',
$xtr_prop = '', $javascript = '') {
$this->tag = $tag;
$this->text = $text;
$this->style = $style;
$this->class = $class;
$this->id = $id;
$this->xtr_prop = $xtr_prop;
$this->javascript = $javascript;
}
/**
* Constructor (PHP4 style, kept for compatibility reasons)
*/
function html($tag='', $text='', $style ='', $class='', $id='',
$xtr_prop = '', $javascript = '') {
self::__construct($tag, $text, $style, $class, $id, $xtr_prop, $javascript);
}
function htmlAdd($el, $last=true) {
if ($last) {
$this->html_el[] = $el;
} else {
$new_html_el = array();
$new_html_el[] = $el;
foreach ($this->html_el as $html_el) {
$new_html_el[] = $html_el;
}
$this->html_el = $new_html_el;
}
}
function AddChild($tag='', $text='', $style ='', $class='', $id='',
$xtr_prop = '', $javascript = '') {
$el = new html ($tag, $text, $style, $class, $id, $xtr_prop, $javascript);
$this->htmlAdd($el);
}
function FindId($id) {
$cnt = count($this->html_el);
$el = false;
if ($cnt) {
for ($i = 0 ; $i < $cnt; $i++) {
if ($this->html_el[$i]->id == $id) {
$ret = $this->html_el[$i];
return $ret;
} else if (count($this->html_el[$i]->html_el)) {
$el = $this->html_el[$i]->FindId($id);
}
if ($el) return $el;
}
}
return $el;
}
function InsToId( $el, $id, $last=true) {
$html_el = &$this->FindId($id);
if ($html_el) {
$html_el->htmlAdd($el, $last);
}
}
function scriptAdd($script) {
$s = "\n".'<!--'."\n".
$script .
"\n".'// -->'."\n";
$el = new html ('script',$s,'','','',array('language' => 'JavaScript',
'type' => 'text/javascript'));
$this->htmlAdd($el);
}
function echoHtml( $usecss=false, $indent='x') {
if ($indent == 'x') {
$indent = ''; $indentmore = '';
} else {
$indentmore = $indent . ' ';
}
$tag = $this->tag;
$text = $this->text;
$class = $this->class;
$id = $this->id;
$style = $this->style;
$javascript = $this->javascript;
$xtr_prop = $this->xtr_prop;
if ($xtr_prop) {
$prop = '';
foreach ($xtr_prop as $k => $v) {
if (is_string($k)) {
$prop.=' '.$k.'="'.$v.'"';
} else {
$prop.=' '.$v;
}
}
}
if ($javascript) {
$js = '';
foreach ($javascript as $k => $v) { /* here we put the onclick, onmouseover etc entries */
$js.=' '.$k.'="'.$v.'";';
}
}
if ($tag) {
echo $indent . '<' . $tag;
} else {
echo $indent;
}
if ($class) {
echo ' class="'.$class.'"';
}
if ($id) {
echo ' id="'.$id.'"';
}
if ($xtr_prop) {
echo ' '.$prop;
}
if ($style && !$usecss && !is_array($style)) {
/* last premisse is to prevent 'style="Array"' in the output */
echo ' style="'.$style.'"';
}
if ($javascript) {
echo ' '.$js;
}
if ($tag) echo '>';
$openstyles = '';
$closestyles = '';
if ($style && !$usecss) {
foreach ($style as $k => $v) {
$openstyles .= '<'.$k.'>';
}
foreach ($style as $k => $v) {
/* if value of key value = true close the tag */
if ($v) {
$closestyles .= '</'.$k.'>';
}
}
}
echo $openstyles;
if ($text) {
echo $text;
}
$cnt = count($this->html_el);
if ($cnt) {
echo "\n";
for($i = 0;$i<$cnt;$i++) {
$el = $this->html_el[$i];
$el->echoHtml($usecss,$indentmore);
}
echo $indent;
}
echo $closestyles;
if ($tag) {
echo '</'.$tag.'>'."\n";
} else {
echo "\n";
}
}
}