-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTag.php
More file actions
101 lines (92 loc) · 2.4 KB
/
Copy pathTag.php
File metadata and controls
101 lines (92 loc) · 2.4 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
<?php
/**
* Tag, simple PHP interface for HTML
*
* @license https://github.com/colgatto/RWTFPL/blob/master/RawLicense.txt Recursive Do What The Fuck You Want To Public License
* @version 1.0
* @since 1.0
*/
class Tag{
private $oneLineTag = array('link','br','hr','img','input','meta','base','embed','spacer');
private $name;
private $textContains='';
private $textToTopContains='';
private $content=array();
private $attr=array();
public function __construct($name,$class='',$content=array()){
$this->name = explode(' ',$name);
if($class!='')$this->addClass($class);
if(is_array($content))
forEach($content as $k => $v)
$this->append($v,$k);
}
public function attr($name,$value){
$this->attr[$name]=$value;
return $this;
}
public function addClass($className){
if(isset($this->attr['class']))
$this->attr['class'].=' '.$className;
else
$this->attr['class']=$className;
return $this;
}
public function text($text){
$this->textContains = $text;
return $this;
}
public function textToTop($text){
$this->textToTopContains = $text;
return $this;
}
public function append(&$content,$k=''){
if($k=='') array_push($this->content,$content);
else $this->content[$k]=$content;
return $this;
}
public function appendToTop(&$content,$k=''){
if($k=='')array_unshift($this->content,$content);
else $this->content = array($k => $content) + $this->content;
return $this;
}
public function clearText(){
$this->text='';
return $this;
}
public function clearContent(){
$this->content=array();
return $this;
}
public function clear(){
$this->clearText();
$this->clearContent();
return $this;
}
/*Find*
public function find($tagName,$start=0){
$finded=array();
for($i=$start;$i<count($this->content);$i++)
if($this->content[$i]->name[0]==$tagName)
array_push($finded,$this->content[$i]);
return $finded;
}
/**/
public function f($contentName){
return isset($this->content[$contentName]) ? $this->content[$contentName] : null;
}
public function __toString(){
$str='<'.$this->name[0].' ';
foreach($this->attr as $attName => $value){
$str.=$attName.'="'.$value.'" ';
}
$names=$this->name;
array_shift($names);
$str.= implode(' ',$names)
.(in_array($this->name[0],$this->oneLineTag) ?
"/>\n" : ">\n".$this->textToTopContains
.implode("\n",$this->content).$this->textContains
."\n</".$this->name[0].'>');
return $str;
}
}
?>