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