-
Notifications
You must be signed in to change notification settings - Fork 0
/
HtmlElement.class.php
101 lines (84 loc) · 2.19 KB
/
HtmlElement.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
<?php
class HtmlElement
{
private $_attributes,
$_content;
public $_tohtml,
$_toBody = 0,
$_tag;
public function setTag($tag)
{
if (isset($tag))
$this->_tag = $tag;
}
public function getTag()
{
return ($this->_tag);
}
public function addAttribute($key, $value)
{
if (isset($key) && isset($value))
{
$this->_attributes[$key] = $value;
}
}
public function addContent($string)
{
$this->_content = $string;
}
public function prepareTag()
{
if ($this->_tag)
$tag = $this->_tag;
else
$tag = "";
return ($tag);
}
public function prepareAttributes()
{
if ($this->_attributes)
{
$count_attributes = count($this->_attributes);
$i = 0;
$attributes = "";
foreach ($this->_attributes as $key => $value)
{
if ($i == $count_attributes - 1)
$attributes .= ' '.$key.'="'.$value.'"';
else
$attributes .= ' '.$key.'="'.$value.'"';
$i++;
}
}
else
$attributes = "";
return ($attributes);
}
public function prepareContent()
{
if ($this->_content)
$content = $this->_content;
else
$content = "";
return ($content);
}
public function toHtml()
{
$tag = $this->prepareTag();
$attributes = $this->prepareAttributes();
$content = $this->prepareContent();
if ($tag != "")
{
$this->_tohtml = "<".$tag.$attributes.">".$content."</".$tag.">";
if ($tag == "meta" || $tag == "link")
$this->_tohtml = "<".$tag.$attributes." />";
}
else
$this->_tohtml = $content;
return ("\t\t".$this->_tohtml."\n");
}
public function toBody()
{
$this->_toBody = 1;
}
}