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: Decorators.php 3188 2012-07-12 12:13:23Z ctrlaltca $ |
23
|
|
|
// |
24
|
|
|
/** |
25
|
|
|
* Decorators for dealing with parser options |
26
|
|
|
* @package System.Security.SafeHtml |
27
|
|
|
* @see TSax3::set_option |
28
|
|
|
*/ |
29
|
|
|
|
30
|
|
|
namespace Prado\Vendor\SafeHtml\HTMLSax3; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Trims the contents of element data from whitespace at start and end |
34
|
|
|
* @package System.Security.SafeHtml |
35
|
|
|
* @access protected |
36
|
|
|
*/ |
37
|
|
|
class TSax3_Trim { |
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Original handler object |
40
|
|
|
* @var object |
41
|
|
|
* @access private |
42
|
|
|
*/ |
43
|
|
|
private $orig_obj; |
44
|
|
|
/** |
45
|
|
|
* Original handler method |
46
|
|
|
* @var string |
47
|
|
|
* @access private |
48
|
|
|
*/ |
49
|
|
|
private $orig_method; |
50
|
|
|
/** |
51
|
|
|
* Constructs TSax3_Trim |
52
|
|
|
* @param object handler object being decorated |
53
|
|
|
* @param string original handler method |
54
|
|
|
* @access protected |
55
|
|
|
*/ |
56
|
|
|
function __construct(&$orig_obj, $orig_method) { |
|
|
|
|
57
|
|
|
$this->orig_obj =& $orig_obj; |
58
|
|
|
$this->orig_method = $orig_method; |
59
|
|
|
} |
60
|
|
|
/** |
61
|
|
|
* Trims the data |
62
|
|
|
* @param TSax3 |
63
|
|
|
* @param string element data |
64
|
|
|
* @access protected |
65
|
|
|
*/ |
66
|
|
|
function trimData(&$parser, $data) { |
67
|
|
|
$data = trim($data); |
68
|
|
|
if ($data != '') { |
69
|
|
|
$this->orig_obj->{$this->orig_method}($parser, $data); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
/** |
74
|
|
|
* Coverts tag names to upper case |
75
|
|
|
* @package System.Security.SafeHtml |
76
|
|
|
* @access protected |
77
|
|
|
*/ |
78
|
|
|
class TSax3_CaseFolding { |
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Original handler object |
81
|
|
|
* @var object |
82
|
|
|
* @access private |
83
|
|
|
*/ |
84
|
|
|
private $orig_obj; |
85
|
|
|
/** |
86
|
|
|
* Original open handler method |
87
|
|
|
* @var string |
88
|
|
|
* @access private |
89
|
|
|
*/ |
90
|
|
|
private $orig_open_method; |
91
|
|
|
/** |
92
|
|
|
* Original close handler method |
93
|
|
|
* @var string |
94
|
|
|
* @access private |
95
|
|
|
*/ |
96
|
|
|
private $orig_close_method; |
97
|
|
|
/** |
98
|
|
|
* Constructs TSax3_CaseFolding |
99
|
|
|
* @param object handler object being decorated |
100
|
|
|
* @param string original open handler method |
101
|
|
|
* @param string original close handler method |
102
|
|
|
* @access protected |
103
|
|
|
*/ |
104
|
|
|
function __construct(&$orig_obj, $orig_open_method, $orig_close_method) { |
|
|
|
|
105
|
|
|
$this->orig_obj =& $orig_obj; |
106
|
|
|
$this->orig_open_method = $orig_open_method; |
107
|
|
|
$this->orig_close_method = $orig_close_method; |
108
|
|
|
} |
109
|
|
|
/** |
110
|
|
|
* Folds up open tag callbacks |
111
|
|
|
* @param TSax3 |
112
|
|
|
* @param string tag name |
113
|
|
|
* @param array tag attributes |
114
|
|
|
* @access protected |
115
|
|
|
*/ |
116
|
|
|
function foldOpen(&$parser, $tag, $attrs=array(), $empty = FALSE) { |
117
|
|
|
$this->orig_obj->{$this->orig_open_method}($parser, strtoupper($tag), $attrs, $empty); |
118
|
|
|
} |
119
|
|
|
/** |
120
|
|
|
* Folds up close tag callbacks |
121
|
|
|
* @param TSax3 |
122
|
|
|
* @param string tag name |
123
|
|
|
* @access protected |
124
|
|
|
*/ |
125
|
|
|
function foldClose(&$parser, $tag, $empty = FALSE) { |
126
|
|
|
$this->orig_obj->{$this->orig_close_method}($parser, strtoupper($tag), $empty); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
/** |
130
|
|
|
* Breaks up data by linefeed characters, resulting in additional |
131
|
|
|
* calls to the data handler |
132
|
|
|
* @package System.Security.SafeHtml |
133
|
|
|
* @access protected |
134
|
|
|
*/ |
135
|
|
|
class TSax3_Linefeed { |
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Original handler object |
138
|
|
|
* @var object |
139
|
|
|
* @access private |
140
|
|
|
*/ |
141
|
|
|
private $orig_obj; |
142
|
|
|
/** |
143
|
|
|
* Original handler method |
144
|
|
|
* @var string |
145
|
|
|
* @access private |
146
|
|
|
*/ |
147
|
|
|
private $orig_method; |
148
|
|
|
/** |
149
|
|
|
* Constructs TSax3_LineFeed |
150
|
|
|
* @param object handler object being decorated |
151
|
|
|
* @param string original handler method |
152
|
|
|
* @access protected |
153
|
|
|
*/ |
154
|
|
|
function __construct(&$orig_obj, $orig_method) { |
|
|
|
|
155
|
|
|
$this->orig_obj =& $orig_obj; |
156
|
|
|
$this->orig_method = $orig_method; |
157
|
|
|
} |
158
|
|
|
/** |
159
|
|
|
* Breaks the data up by linefeeds |
160
|
|
|
* @param TSax3 |
161
|
|
|
* @param string element data |
162
|
|
|
* @access protected |
163
|
|
|
*/ |
164
|
|
|
function breakData(&$parser, $data) { |
165
|
|
|
$data = explode("\n",$data); |
166
|
|
|
foreach ( $data as $chunk ) { |
167
|
|
|
$this->orig_obj->{$this->orig_method}($parser, $chunk); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
/** |
172
|
|
|
* Breaks up data by tab characters, resulting in additional |
173
|
|
|
* calls to the data handler |
174
|
|
|
* @package System.Security.SafeHtml |
175
|
|
|
* @access protected |
176
|
|
|
*/ |
177
|
|
|
class TSax3_Tab { |
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Original handler object |
180
|
|
|
* @var object |
181
|
|
|
* @access private |
182
|
|
|
*/ |
183
|
|
|
private $orig_obj; |
184
|
|
|
/** |
185
|
|
|
* Original handler method |
186
|
|
|
* @var string |
187
|
|
|
* @access private |
188
|
|
|
*/ |
189
|
|
|
private $orig_method; |
190
|
|
|
/** |
191
|
|
|
* Constructs TSax3_Tab |
192
|
|
|
* @param object handler object being decorated |
193
|
|
|
* @param string original handler method |
194
|
|
|
* @access protected |
195
|
|
|
*/ |
196
|
|
|
function __construct(&$orig_obj, $orig_method) { |
|
|
|
|
197
|
|
|
$this->orig_obj =& $orig_obj; |
198
|
|
|
$this->orig_method = $orig_method; |
199
|
|
|
} |
200
|
|
|
/** |
201
|
|
|
* Breaks the data up by linefeeds |
202
|
|
|
* @param TSax3 |
203
|
|
|
* @param string element data |
204
|
|
|
* @access protected |
205
|
|
|
*/ |
206
|
|
|
function breakData(&$parser, $data) { |
207
|
|
|
$data = explode("\t",$data); |
208
|
|
|
foreach ( $data as $chunk ) { |
209
|
|
|
$this->orig_obj->{$this->orig_method}($this, $chunk); |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
/** |
214
|
|
|
* Breaks up data by XML entities and parses them with html_entity_decode(), |
215
|
|
|
* resulting in additional calls to the data handler<br /> |
216
|
|
|
* Requires PHP 4.3.0+ |
217
|
|
|
* @package System.Security.SafeHtml |
218
|
|
|
* @access protected |
219
|
|
|
*/ |
220
|
|
|
class TSax3_Entities_Parsed { |
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Original handler object |
223
|
|
|
* @var object |
224
|
|
|
* @access private |
225
|
|
|
*/ |
226
|
|
|
private $orig_obj; |
227
|
|
|
/** |
228
|
|
|
* Original handler method |
229
|
|
|
* @var string |
230
|
|
|
* @access private |
231
|
|
|
*/ |
232
|
|
|
private $orig_method; |
233
|
|
|
/** |
234
|
|
|
* Constructs TSax3_Entities_Parsed |
235
|
|
|
* @param object handler object being decorated |
236
|
|
|
* @param string original handler method |
237
|
|
|
* @access protected |
238
|
|
|
*/ |
239
|
|
|
function __construct(&$orig_obj, $orig_method) { |
|
|
|
|
240
|
|
|
$this->orig_obj =& $orig_obj; |
241
|
|
|
$this->orig_method = $orig_method; |
242
|
|
|
} |
243
|
|
|
/** |
244
|
|
|
* Breaks the data up by XML entities |
245
|
|
|
* @param TSax3 |
246
|
|
|
* @param string element data |
247
|
|
|
* @access protected |
248
|
|
|
*/ |
249
|
|
|
function breakData(&$parser, $data) { |
250
|
|
|
$data = preg_split('/(&.+?;)/',$data,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
251
|
|
|
foreach ( $data as $chunk ) { |
252
|
|
|
$chunk = html_entity_decode($chunk,ENT_NOQUOTES); |
253
|
|
|
$this->orig_obj->{$this->orig_method}($this, $chunk); |
254
|
|
|
} |
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
/** |
258
|
|
|
* Compatibility with older PHP versions |
259
|
|
|
*/ |
260
|
|
|
if (version_compare(phpversion(), '4.3', '<') && !function_exists('html_entity_decode') ) { |
261
|
|
|
function html_entity_decode($str, $style=ENT_NOQUOTES) { |
262
|
|
|
return strtr($str, |
263
|
|
|
array_flip(get_html_translation_table(HTML_ENTITIES,$style))); |
264
|
|
|
} |
265
|
|
|
} |
266
|
|
|
/** |
267
|
|
|
* Breaks up data by XML entities but leaves them unparsed, |
268
|
|
|
* resulting in additional calls to the data handler<br /> |
269
|
|
|
* @package System.Security.SafeHtml |
270
|
|
|
* @access protected |
271
|
|
|
*/ |
272
|
|
|
class TSax3_Entities_Unparsed { |
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Original handler object |
275
|
|
|
* @var object |
276
|
|
|
* @access private |
277
|
|
|
*/ |
278
|
|
|
private $orig_obj; |
279
|
|
|
/** |
280
|
|
|
* Original handler method |
281
|
|
|
* @var string |
282
|
|
|
* @access private |
283
|
|
|
*/ |
284
|
|
|
private $orig_method; |
285
|
|
|
/** |
286
|
|
|
* Constructs TSax3_Entities_Unparsed |
287
|
|
|
* @param object handler object being decorated |
288
|
|
|
* @param string original handler method |
289
|
|
|
* @access protected |
290
|
|
|
*/ |
291
|
|
|
function __construct(&$orig_obj, $orig_method) { |
|
|
|
|
292
|
|
|
$this->orig_obj =& $orig_obj; |
293
|
|
|
$this->orig_method = $orig_method; |
294
|
|
|
} |
295
|
|
|
/** |
296
|
|
|
* Breaks the data up by XML entities |
297
|
|
|
* @param TSax3 |
298
|
|
|
* @param string element data |
299
|
|
|
* @access protected |
300
|
|
|
*/ |
301
|
|
|
function breakData(&$parser, $data) { |
302
|
|
|
$data = preg_split('/(&.+?;)/',$data,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
303
|
|
|
foreach ( $data as $chunk ) { |
304
|
|
|
$this->orig_obj->{$this->orig_method}($this, $chunk); |
305
|
|
|
} |
306
|
|
|
} |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* Strips the HTML comment markers or CDATA sections from an escape. |
311
|
|
|
* If XML_OPTIONS_FULL_ESCAPES is on, this decorator is not used.<br /> |
312
|
|
|
* @package System.Security.SafeHtml |
313
|
|
|
* @access protected |
314
|
|
|
*/ |
315
|
|
|
class TSax3_Escape_Stripper { |
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* Original handler object |
318
|
|
|
* @var object |
319
|
|
|
* @access private |
320
|
|
|
*/ |
321
|
|
|
private $orig_obj; |
322
|
|
|
/** |
323
|
|
|
* Original handler method |
324
|
|
|
* @var string |
325
|
|
|
* @access private |
326
|
|
|
*/ |
327
|
|
|
private $orig_method; |
328
|
|
|
/** |
329
|
|
|
* Constructs TSax3_Entities_Unparsed |
330
|
|
|
* @param object handler object being decorated |
331
|
|
|
* @param string original handler method |
332
|
|
|
* @access protected |
333
|
|
|
*/ |
334
|
|
|
function __construct(&$orig_obj, $orig_method) { |
|
|
|
|
335
|
|
|
$this->orig_obj =& $orig_obj; |
336
|
|
|
$this->orig_method = $orig_method; |
337
|
|
|
} |
338
|
|
|
/** |
339
|
|
|
* Breaks the data up by XML entities |
340
|
|
|
* @param TSax3 |
341
|
|
|
* @param string element data |
342
|
|
|
* @access protected |
343
|
|
|
*/ |
344
|
|
|
function strip(&$parser, $data) { |
345
|
|
|
// Check for HTML comments first |
346
|
|
|
if ( substr($data,0,2) == '--' ) { |
347
|
|
|
$patterns = array( |
348
|
|
|
'/^\-\-/', // Opening comment: -- |
349
|
|
|
'/\-\-$/', // Closing comment: -- |
350
|
|
|
); |
351
|
|
|
$data = preg_replace($patterns,'',$data); |
352
|
|
|
|
353
|
|
|
// Check for XML CDATA sections (note: don't do both!) |
354
|
|
|
} else if ( substr($data,0,1) == '[' ) { |
355
|
|
|
$patterns = array( |
356
|
|
|
'/^\[.*CDATA.*\[/s', // Opening CDATA |
357
|
|
|
'/\].*\]$/s', // Closing CDATA |
358
|
|
|
); |
359
|
|
|
$data = preg_replace($patterns,'',$data); |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
$this->orig_obj->{$this->orig_method}($this, $data); |
363
|
|
|
} |
364
|
|
|
} |
365
|
|
|
|
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
.