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