1
|
|
|
<?php |
2
|
|
|
/* vim: set expandtab tabstop=4 shiftwidth=4: */ |
3
|
|
|
// |
4
|
|
|
// +----------------------------------------------------------------------+ |
5
|
|
|
// | PHP Version 4 | |
6
|
|
|
// +----------------------------------------------------------------------+ |
7
|
|
|
// | Copyright (c) 1997-2002 The PHP Group | |
8
|
|
|
// +----------------------------------------------------------------------+ |
9
|
|
|
// | This source file is subject to version 2.02 of the PHP license, | |
10
|
|
|
// | that is bundled with this package in the file LICENSE, and is | |
11
|
|
|
// | available at through the world-wide-web at | |
12
|
|
|
// | http://www.php.net/license/3_0.txt. | |
13
|
|
|
// | If you did not receive a copy of the PHP license and are unable to | |
14
|
|
|
// | obtain it through the world-wide-web, please send a note to | |
15
|
|
|
// | [email protected] so we can mail you a copy immediately. | |
16
|
|
|
// +----------------------------------------------------------------------+ |
17
|
|
|
// | Authors: Alexander Zhukov <[email protected]> Original port from Python | |
18
|
|
|
// | Authors: Harry Fuecks <[email protected]> Port to PEAR + more | |
19
|
|
|
// | Authors: Many @ Sitepointforums Advanced PHP Forums | |
20
|
|
|
// +----------------------------------------------------------------------+ |
21
|
|
|
// |
22
|
|
|
// $Id: States.php 3188 2012-07-12 12:13:23Z ctrlaltca $ |
23
|
|
|
// |
24
|
|
|
/** |
25
|
|
|
* Parsing states. |
26
|
|
|
* @package System.Security.SafeHtml |
27
|
|
|
*/ |
28
|
|
|
/** |
29
|
|
|
* Define parser states |
30
|
|
|
*/ |
31
|
|
|
/*define('TSAX3_STATE_STOP', 0); |
32
|
|
|
define('TSAX3_STATE_START', 1); |
33
|
|
|
define('TSAX3_STATE_TAG', 2); |
34
|
|
|
define('TSAX3_STATE_OPENING_TAG', 3); |
35
|
|
|
define('TSAX3_STATE_CLOSING_TAG', 4); |
36
|
|
|
define('TSAX3_STATE_ESCAPE', 6); |
37
|
|
|
define('TSAX3_STATE_JASP', 7); |
38
|
|
|
define('TSAX3_STATE_PI', 8); |
39
|
|
|
*/ |
40
|
|
|
|
41
|
|
|
namespace Prado\Vendor\SafeHtml\HTMLSax3; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* StartingState searches for the start of any XML tag |
45
|
|
|
* @package System.Security.SafeHtml |
46
|
|
|
* @access protected |
47
|
|
|
*/ |
48
|
|
|
class TSax3_StartingState { |
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param TSax3_StateParser subclass |
51
|
|
|
* @return constant TSAX3_STATE_TAG |
52
|
|
|
* @access protected |
53
|
|
|
*/ |
54
|
|
|
function parse(&$context) { |
55
|
|
|
$data = $context->scanUntilString('<'); |
56
|
|
|
if ($data != '') { |
57
|
|
|
$context->handler_object_data-> |
58
|
|
|
{$context->handler_method_data}($context->htmlsax, $data); |
59
|
|
|
} |
60
|
|
|
$context->IgnoreCharacter(); |
61
|
|
|
return TSax3_StateParser::TSAX3_STATE_TAG; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
/** |
65
|
|
|
* Decides which state to move one from after StartingState |
66
|
|
|
* @package System.Security.SafeHtml |
67
|
|
|
* @access protected |
68
|
|
|
*/ |
69
|
|
|
class TSax3_TagState { |
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param TSax3_StateParser subclass |
72
|
|
|
* @return constant the next state to move into |
73
|
|
|
* @access protected |
74
|
|
|
*/ |
75
|
|
|
function parse(&$context) { |
76
|
|
|
switch($context->ScanCharacter()) { |
77
|
|
|
case '/': |
78
|
|
|
return TSax3_StateParser::TSAX3_STATE_CLOSING_TAG; |
79
|
|
|
break; |
|
|
|
|
80
|
|
|
case '?': |
81
|
|
|
return TSax3_StateParser::TSAX3_STATE_PI; |
82
|
|
|
break; |
|
|
|
|
83
|
|
|
case '%': |
84
|
|
|
return TSax3_StateParser::TSAX3_STATE_JASP; |
85
|
|
|
break; |
|
|
|
|
86
|
|
|
case '!': |
87
|
|
|
return TSax3_StateParser::TSAX3_STATE_ESCAPE; |
88
|
|
|
break; |
|
|
|
|
89
|
|
|
default: |
90
|
|
|
$context->unscanCharacter(); |
91
|
|
|
return TSax3_StateParser::TSAX3_STATE_OPENING_TAG; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
/** |
96
|
|
|
* Dealing with closing XML tags |
97
|
|
|
* @package System.Security.SafeHtml |
98
|
|
|
* @access protected |
99
|
|
|
*/ |
100
|
|
|
class TSax3_ClosingTagState { |
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param TSax3_StateParser subclass |
103
|
|
|
* @return constant TSAX3_STATE_START |
104
|
|
|
* @access protected |
105
|
|
|
*/ |
106
|
|
|
function parse(&$context) { |
107
|
|
|
$tag = $context->scanUntilCharacters('/>'); |
108
|
|
|
if ($tag != '') { |
109
|
|
|
$char = $context->scanCharacter(); |
110
|
|
|
if ($char == '/') { |
111
|
|
|
$char = $context->scanCharacter(); |
112
|
|
|
if ($char != '>') { |
113
|
|
|
$context->unscanCharacter(); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
$context->handler_object_element-> |
117
|
|
|
{$context->handler_method_closing}($context->htmlsax, $tag, FALSE); |
118
|
|
|
} |
119
|
|
|
return TSax3_StateParser::TSAX3_STATE_START; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
/** |
123
|
|
|
* Dealing with opening XML tags |
124
|
|
|
* @package System.Security.SafeHtml |
125
|
|
|
* @access protected |
126
|
|
|
*/ |
127
|
|
|
class TSax3_OpeningTagState { |
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Handles attributes |
130
|
|
|
* @param string attribute name |
131
|
|
|
* @param string attribute value |
132
|
|
|
* @return void |
|
|
|
|
133
|
|
|
* @access protected |
134
|
|
|
* @see TSax3_AttributeStartState |
135
|
|
|
*/ |
136
|
|
|
function parseAttributes(&$context) { |
137
|
|
|
$Attributes = array(); |
138
|
|
|
|
139
|
|
|
$context->ignoreWhitespace(); |
140
|
|
|
$attributename = $context->scanUntilCharacters("=/> \n\r\t"); |
141
|
|
|
while ($attributename != '') { |
142
|
|
|
$attributevalue = NULL; |
143
|
|
|
$context->ignoreWhitespace(); |
144
|
|
|
$char = $context->scanCharacter(); |
145
|
|
|
if ($char == '=') { |
146
|
|
|
$context->ignoreWhitespace(); |
147
|
|
|
$char = $context->ScanCharacter(); |
148
|
|
|
if ($char == '"') { |
149
|
|
|
$attributevalue= $context->scanUntilString('"'); |
150
|
|
|
$context->IgnoreCharacter(); |
151
|
|
|
} else if ($char == "'") { |
152
|
|
|
$attributevalue = $context->scanUntilString("'"); |
153
|
|
|
$context->IgnoreCharacter(); |
154
|
|
|
} else { |
155
|
|
|
$context->unscanCharacter(); |
156
|
|
|
$attributevalue = |
157
|
|
|
$context->scanUntilCharacters("> \n\r\t"); |
158
|
|
|
} |
159
|
|
|
} else if ($char !== NULL) { |
160
|
|
|
$attributevalue = NULL; |
161
|
|
|
$context->unscanCharacter(); |
162
|
|
|
} |
163
|
|
|
$Attributes[$attributename] = $attributevalue; |
164
|
|
|
|
165
|
|
|
$context->ignoreWhitespace(); |
166
|
|
|
$attributename = $context->scanUntilCharacters("=/> \n\r\t"); |
167
|
|
|
} |
168
|
|
|
return $Attributes; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @param TSax3_StateParser subclass |
173
|
|
|
* @return constant TSAX3_STATE_START |
174
|
|
|
* @access protected |
175
|
|
|
*/ |
176
|
|
|
function parse(&$context) { |
177
|
|
|
$tag = $context->scanUntilCharacters("/> \n\r\t"); |
178
|
|
|
if ($tag != '') { |
179
|
|
|
$this->attrs = array(); |
|
|
|
|
180
|
|
|
$Attributes = $this->parseAttributes($context); |
181
|
|
|
$char = $context->scanCharacter(); |
182
|
|
|
if ($char == '/') { |
183
|
|
|
$char = $context->scanCharacter(); |
184
|
|
|
if ($char != '>') { |
185
|
|
|
$context->unscanCharacter(); |
186
|
|
|
} |
187
|
|
|
$context->handler_object_element-> |
188
|
|
|
{$context->handler_method_opening}($context->htmlsax, $tag, |
189
|
|
|
$Attributes, TRUE); |
190
|
|
|
$context->handler_object_element-> |
191
|
|
|
{$context->handler_method_closing}($context->htmlsax, $tag, |
192
|
|
|
TRUE); |
193
|
|
|
} else { |
194
|
|
|
$context->handler_object_element-> |
195
|
|
|
{$context->handler_method_opening}($context->htmlsax, $tag, |
196
|
|
|
$Attributes, FALSE); |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
return TSax3_StateParser::TSAX3_STATE_START; |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Deals with XML escapes handling comments and CDATA correctly |
205
|
|
|
* @package System.Security.SafeHtml |
206
|
|
|
* @access protected |
207
|
|
|
*/ |
208
|
|
|
class TSax3_EscapeState { |
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @param TSax3_StateParser subclass |
211
|
|
|
* @return constant TSAX3_STATE_START |
212
|
|
|
* @access protected |
213
|
|
|
*/ |
214
|
|
|
function parse(&$context) { |
215
|
|
|
$char = $context->ScanCharacter(); |
216
|
|
|
if ($char == '-') { |
217
|
|
|
$char = $context->ScanCharacter(); |
218
|
|
|
if ($char == '-') { |
219
|
|
|
$context->unscanCharacter(); |
220
|
|
|
$context->unscanCharacter(); |
221
|
|
|
$text = $context->scanUntilString('-->'); |
222
|
|
|
$text .= $context->scanCharacter(); |
223
|
|
|
$text .= $context->scanCharacter(); |
224
|
|
|
} else { |
225
|
|
|
$context->unscanCharacter(); |
226
|
|
|
$text = $context->scanUntilString('>'); |
227
|
|
|
} |
228
|
|
|
} else if ( $char == '[') { |
229
|
|
|
$context->unscanCharacter(); |
230
|
|
|
$text = $context->scanUntilString(']>'); |
231
|
|
|
$text.= $context->scanCharacter(); |
232
|
|
|
} else { |
233
|
|
|
$context->unscanCharacter(); |
234
|
|
|
$text = $context->scanUntilString('>'); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
$context->IgnoreCharacter(); |
238
|
|
|
if ($text != '') { |
239
|
|
|
$context->handler_object_escape-> |
240
|
|
|
{$context->handler_method_escape}($context->htmlsax, $text); |
241
|
|
|
} |
242
|
|
|
return TSax3_StateParser::TSAX3_STATE_START; |
243
|
|
|
} |
244
|
|
|
} |
245
|
|
|
/** |
246
|
|
|
* Deals with JASP/ASP markup |
247
|
|
|
* @package System.Security.SafeHtml |
248
|
|
|
* @access protected |
249
|
|
|
*/ |
250
|
|
|
class TSax3_JaspState { |
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @param TSax3_StateParser subclass |
253
|
|
|
* @return constant TSAX3_STATE_START |
254
|
|
|
* @access protected |
255
|
|
|
*/ |
256
|
|
|
function parse(&$context) { |
257
|
|
|
$text = $context->scanUntilString('%>'); |
258
|
|
|
if ($text != '') { |
259
|
|
|
$context->handler_object_jasp-> |
260
|
|
|
{$context->handler_method_jasp}($context->htmlsax, $text); |
261
|
|
|
} |
262
|
|
|
$context->IgnoreCharacter(); |
263
|
|
|
$context->IgnoreCharacter(); |
264
|
|
|
return TSax3_StateParser::TSAX3_STATE_START; |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
/** |
268
|
|
|
* Deals with XML processing instructions |
269
|
|
|
* @package System.Security.SafeHtml |
270
|
|
|
* @access protected |
271
|
|
|
*/ |
272
|
|
|
class TSax3_PiState { |
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* @param TSax3_StateParser subclass |
275
|
|
|
* @return constant TSAX3_STATE_START |
276
|
|
|
* @access protected |
277
|
|
|
*/ |
278
|
|
|
function parse(&$context) { |
279
|
|
|
$target = $context->scanUntilCharacters(" \n\r\t"); |
280
|
|
|
$data = $context->scanUntilString('?>'); |
281
|
|
|
if ($data != '') { |
282
|
|
|
$context->handler_object_pi-> |
283
|
|
|
{$context->handler_method_pi}($context->htmlsax, $target, $data); |
284
|
|
|
} |
285
|
|
|
$context->IgnoreCharacter(); |
286
|
|
|
$context->IgnoreCharacter(); |
287
|
|
|
return TSax3_StateParser::TSAX3_STATE_START; |
288
|
|
|
} |
289
|
|
|
} |
290
|
|
|
|
Classes in PHP are usually named in CamelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database provider becomes
DatabaseProvider
.