2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
4 // +----------------------------------------------------------------------+
6 // +----------------------------------------------------------------------+
7 // | Copyright (c) 1997-2002 The PHP Group |
8 // +----------------------------------------------------------------------+
9 // | This source file is subject toversion 3.0 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 // | license@php.net so we can mail you a copy immediately. |
16 // +----------------------------------------------------------------------+
17 // | Authors: Alexander Zhukov <alex@veresk.ru> Original port from Python |
18 // | Authors: Harry Fuecks <hfuecks@phppatterns.com> Port to PEAR + more |
19 // | Authors: Many @ Sitepointforums Advanced PHP Forums |
20 // +----------------------------------------------------------------------+
22 // $Id: Decorators.php,v 1.2 2007/10/29 21:41:35 hfuecks Exp $
25 * Decorators for dealing with parser options
26 * @package XML_HTMLSax3
27 * @version $Id: Decorators.php,v 1.2 2007/10/29 21:41:35 hfuecks Exp $
28 * @see XML_HTMLSax3::set_option
31 * Trims the contents of element data from whitespace at start and end
32 * @package XML_HTMLSax3
35 class XML_HTMLSax3_Trim
{
37 * Original handler object
43 * Original handler method
49 * Constructs XML_HTMLSax3_Trim
50 * @param object handler object being decorated
51 * @param string original handler method
54 function __construct(&$orig_obj, $orig_method) {
55 $this->orig_obj
=& $orig_obj;
56 $this->orig_method
= $orig_method;
61 * @param string element data
64 function trimData(&$parser, $data) {
67 $this->orig_obj
->{$this->orig_method
}($parser, $data);
72 * Coverts tag names to upper case
73 * @package XML_HTMLSax3
76 class XML_HTMLSax3_CaseFolding
{
78 * Original handler object
84 * Original open handler method
88 var $orig_open_method;
90 * Original close handler method
94 var $orig_close_method;
96 * Constructs XML_HTMLSax3_CaseFolding
97 * @param object handler object being decorated
98 * @param string original open handler method
99 * @param string original close handler method
102 function __construct(&$orig_obj, $orig_open_method, $orig_close_method) {
103 $this->orig_obj
=& $orig_obj;
104 $this->orig_open_method
= $orig_open_method;
105 $this->orig_close_method
= $orig_close_method;
108 * Folds up open tag callbacks
109 * @param XML_HTMLSax3
110 * @param string tag name
111 * @param array tag attributes
114 function foldOpen(&$parser, $tag, $attrs=array(), $empty = FALSE) {
115 $this->orig_obj
->{$this->orig_open_method
}($parser, strtoupper($tag), $attrs, $empty);
118 * Folds up close tag callbacks
119 * @param XML_HTMLSax3
120 * @param string tag name
123 function foldClose(&$parser, $tag, $empty = FALSE) {
124 $this->orig_obj
->{$this->orig_close_method
}($parser, strtoupper($tag), $empty);
128 * Breaks up data by linefeed characters, resulting in additional
129 * calls to the data handler
130 * @package XML_HTMLSax3
133 class XML_HTMLSax3_Linefeed
{
135 * Original handler object
141 * Original handler method
147 * Constructs XML_HTMLSax3_LineFeed
148 * @param object handler object being decorated
149 * @param string original handler method
152 function __construct(&$orig_obj, $orig_method) {
153 $this->orig_obj
=& $orig_obj;
154 $this->orig_method
= $orig_method;
157 * Breaks the data up by linefeeds
158 * @param XML_HTMLSax3
159 * @param string element data
162 function breakData(&$parser, $data) {
163 $data = explode("\n",$data);
164 foreach ( $data as $chunk ) {
165 $this->orig_obj
->{$this->orig_method
}($parser, $chunk);
170 * Breaks up data by tab characters, resulting in additional
171 * calls to the data handler
172 * @package XML_HTMLSax3
175 class XML_HTMLSax3_Tab
{
177 * Original handler object
183 * Original handler method
189 * Constructs XML_HTMLSax3_Tab
190 * @param object handler object being decorated
191 * @param string original handler method
194 function __construct(&$orig_obj, $orig_method) {
195 $this->orig_obj
=& $orig_obj;
196 $this->orig_method
= $orig_method;
199 * Breaks the data up by linefeeds
200 * @param XML_HTMLSax3
201 * @param string element data
204 function breakData(&$parser, $data) {
205 $data = explode("\t",$data);
206 foreach ( $data as $chunk ) {
207 $this->orig_obj
->{$this->orig_method
}($this, $chunk);
212 * Breaks up data by XML entities and parses them with html_entity_decode(),
213 * resulting in additional calls to the data handler<br />
214 * Requires PHP 4.3.0+
215 * @package XML_HTMLSax3
218 class XML_HTMLSax3_Entities_Parsed
{
220 * Original handler object
226 * Original handler method
232 * Constructs XML_HTMLSax3_Entities_Parsed
233 * @param object handler object being decorated
234 * @param string original handler method
237 function __construct(&$orig_obj, $orig_method) {
238 $this->orig_obj
=& $orig_obj;
239 $this->orig_method
= $orig_method;
242 * Breaks the data up by XML entities
243 * @param XML_HTMLSax3
244 * @param string element data
247 function breakData(&$parser, $data) {
248 $data = preg_split('/(&.+?;)/',$data,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
);
249 foreach ( $data as $chunk ) {
250 $chunk = html_entity_decode($chunk, ENT_NOQUOTES
, HTML_ENTITIES_CHARSET
);
251 $this->orig_obj
->{$this->orig_method
}($this, $chunk);
256 * Breaks up data by XML entities but leaves them unparsed,
257 * resulting in additional calls to the data handler<br />
258 * @package XML_HTMLSax3
261 class XML_HTMLSax3_Entities_Unparsed
{
263 * Original handler object
269 * Original handler method
275 * Constructs XML_HTMLSax3_Entities_Unparsed
276 * @param object handler object being decorated
277 * @param string original handler method
280 function __construct(&$orig_obj, $orig_method) {
281 $this->orig_obj
=& $orig_obj;
282 $this->orig_method
= $orig_method;
285 * Breaks the data up by XML entities
286 * @param XML_HTMLSax3
287 * @param string element data
290 function breakData(&$parser, $data) {
291 $data = preg_split('/(&.+?;)/',$data,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
);
292 foreach ( $data as $chunk ) {
293 $this->orig_obj
->{$this->orig_method
}($this, $chunk);
299 * Strips the HTML comment markers or CDATA sections from an escape.
300 * If XML_OPTIONS_FULL_ESCAPES is on, this decorator is not used.<br />
301 * @package XML_HTMLSax3
304 class XML_HTMLSax3_Escape_Stripper
{
306 * Original handler object
312 * Original handler method
318 * Constructs XML_HTMLSax3_Entities_Unparsed
319 * @param object handler object being decorated
320 * @param string original handler method
323 function __construct(&$orig_obj, $orig_method) {
324 $this->orig_obj
=& $orig_obj;
325 $this->orig_method
= $orig_method;
328 * Breaks the data up by XML entities
329 * @param XML_HTMLSax3
330 * @param string element data
333 function strip(&$parser, $data) {
334 // Check for HTML comments first
335 if ( substr($data,0,2) == '--' ) {
337 '/^\-\-/', // Opening comment: --
338 '/\-\-$/', // Closing comment: --
340 $data = preg_replace($patterns,'',$data);
342 // Check for XML CDATA sections (note: don't do both!)
343 } else if ( substr($data,0,1) == '[' ) {
345 '/^\[.*CDATA.*\[/s', // Opening CDATA
346 '/\].*\]$/s', // Closing CDATA
348 $data = preg_replace($patterns,'',$data);
351 $this->orig_obj
->{$this->orig_method
}($this, $data);