1
|
|
|
<?php |
2
|
|
|
namespace Roesch; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* TagType class |
6
|
|
|
*/ |
7
|
|
|
class TagType |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @return bool |
11
|
|
|
*/ |
12
|
9 |
|
public function end_tag($position, $input) |
13
|
|
|
{ |
14
|
9 |
|
for ($i = $position; $i < strlen($input); $i++) { |
15
|
9 |
|
if ($input[$i] == '<' && $input[$i + 1] == '/') { |
16
|
4 |
|
return true; |
17
|
8 |
|
} elseif ($input[$i] == '<' && $input[$i + 1] == '!') { |
18
|
2 |
|
return true; |
19
|
7 |
|
} elseif ($input[$i] == '>') { |
20
|
7 |
|
return false; |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
|
24
|
1 |
|
return false; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return bool |
29
|
|
|
*/ |
30
|
9 |
|
public function comment($position, $input) |
31
|
|
|
{ |
32
|
|
|
return ( |
33
|
9 |
|
$input[$position] == '<' && |
34
|
9 |
|
$input[$position + 1] == '!' && |
35
|
9 |
|
$input[$position + 2] == '-' && |
36
|
9 |
|
$input[$position + 3] == '-' |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return bool |
42
|
|
|
*/ |
43
|
3 |
|
public function end_comment($position, $input) |
44
|
|
|
{ |
45
|
|
|
return ( |
46
|
3 |
|
$input[$position] == '-' && |
47
|
3 |
|
$input[$position + 1] == '-' && |
48
|
3 |
|
$input[$position + 2] == '>' |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return bool |
54
|
|
|
*/ |
55
|
6 |
|
public function empty_line($position, $input) |
56
|
|
|
{ |
57
|
6 |
|
$tag = $this->get_current_tag($position + 2, $input); |
58
|
|
|
|
59
|
6 |
|
$in_tag = false; |
60
|
|
|
|
61
|
6 |
|
for ($i = $position - 1; $i >= 0; $i--) { |
62
|
6 |
|
if (!$in_tag) { |
63
|
6 |
|
if ($input[$i] == '>') { |
64
|
4 |
|
$in_tag = true; |
65
|
4 |
|
} elseif (!preg_match('/\s/', $input[$i])) { |
66
|
6 |
|
return false; |
67
|
|
|
} |
68
|
|
|
} else { |
69
|
4 |
|
if ($input[$i] == '<') { |
70
|
4 |
|
return ($tag == $this->get_current_tag($i + 1, $input)); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
1 |
|
return true; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return bool |
80
|
|
|
*/ |
81
|
8 |
|
public function closed_tag($position, $input) |
82
|
|
|
{ |
83
|
|
|
$tags = array( |
84
|
8 |
|
'meta', 'link', 'img', 'hr', 'br', 'input', |
85
|
|
|
); |
86
|
|
|
|
87
|
8 |
|
$tag = ''; |
88
|
|
|
|
89
|
8 |
|
for ($i = $position; $i < strlen($input); $i++) { |
90
|
8 |
|
if ($input[$i] == '<') { |
91
|
6 |
|
continue; |
92
|
8 |
|
} elseif (preg_match('/\s/', $input[$i])) { |
93
|
7 |
|
break; |
94
|
|
|
} else { |
95
|
8 |
|
$tag .= $input[$i]; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
8 |
|
return (in_array(rtrim($tag, '/'), $tags)); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return bool |
104
|
|
|
*/ |
105
|
9 |
|
public function inline_tag($position, $input) |
106
|
|
|
{ |
107
|
|
|
$tags = array( |
108
|
9 |
|
'title', 'span', 'abbr', 'acronym', 'b', 'basefont', 'bdo', 'big', |
109
|
|
|
'cite', 'code', 'dfn', 'em', 'font', 'i', 'kbd', 'q', 's', 'samp', |
110
|
|
|
'small', 'strike', 'sub', 'sup', 'textarea', 'tt', 'u', 'var', |
111
|
|
|
'del', 'pre', |
112
|
|
|
// 'strong', |
113
|
|
|
); |
114
|
|
|
|
115
|
9 |
|
$tag = null; |
116
|
9 |
|
for ($i = $position; $i < strlen($input); $i++) { |
117
|
9 |
|
if ($input[$i] == '<' || $input[$i] == '/') { |
118
|
9 |
|
continue; |
119
|
9 |
|
} elseif (preg_match('/\s/', $input[$i]) || $input[$i] == '>') { |
120
|
9 |
|
break; |
121
|
|
|
} else { |
122
|
9 |
|
$tag .= $input[$i]; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
9 |
|
return (in_array(rtrim($tag, '/'), $tags)); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param int $position String index of input |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
7 |
|
public function get_current_tag($position, $input) |
134
|
|
|
{ |
135
|
7 |
|
$i = $position; |
136
|
7 |
|
$tag = ''; |
137
|
7 |
|
for ($i; $i < strlen($input); $i++) { |
138
|
5 |
|
if ($input[$i] == '<') { |
139
|
1 |
|
continue; |
140
|
5 |
|
} elseif ($input[$i] == '>' || preg_match('/\s/', $input[$i])) { |
141
|
5 |
|
return $tag; |
142
|
|
|
} else { |
143
|
5 |
|
$tag .= $input[$i]; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
147
|
3 |
|
return $tag; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|