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 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 // | 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: XML_HTMLSax_Decorators.php 2291 2004-11-16 19:35:41Z joel $
25 * Decorators for dealing with parser options
26 * @package XML_HTMLSax
27 * @version $Id: XML_HTMLSax_Decorators.php 2291 2004-11-16 19:35:41Z joel $
28 * @see XML_HTMLSax::set_option
31 * Trims the contents of element data from whitespace at start and end
32 * @package XML_HTMLSax
35 class XML_HTMLSax_Trim {
37 * Original handler object
43 * Original handler method
49 * Constructs XML_HTMLSax_Trim
50 * @param object handler object being decorated
51 * @param string original handler method
54 function XML_HTMLSax_Trim(&$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_HTMLSax
76 class XML_HTMLSax_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_HTMLSax_CaseFolding
97 * @param object handler object being decorated
98 * @param string original open handler method
99 * @param string original close handler method
102 function XML_HTMLSax_CaseFolding(&$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
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
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_HTMLSax
133 class XML_HTMLSax_Linefeed {
135 * Original handler object
141 * Original handler method
147 * Constructs XML_HTMLSax_LineFeed
148 * @param object handler object being decorated
149 * @param string original handler method
152 function XML_HTMLSax_LineFeed(&$orig_obj, $orig_method) {
153 $this->orig_obj =& $orig_obj;
154 $this->orig_method = $orig_method;
157 * Breaks the data up by linefeeds
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_HTMLSax
175 class XML_HTMLSax_Tab {
177 * Original handler object
183 * Original handler method
189 * Constructs XML_HTMLSax_Tab
190 * @param object handler object being decorated
191 * @param string original handler method
194 function XML_HTMLSax_Tab(&$orig_obj, $orig_method) {
195 $this->orig_obj =& $orig_obj;
196 $this->orig_method = $orig_method;
199 * Breaks the data up by linefeeds
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_HTMLSax
218 class XML_HTMLSax_Entities_Parsed {
220 * Original handler object
226 * Original handler method
232 * Constructs XML_HTMLSax_Entities_Parsed
233 * @param object handler object being decorated
234 * @param string original handler method
237 function XML_HTMLSax_Entities_Parsed(&$orig_obj, $orig_method) {
238 $this->orig_obj =& $orig_obj;
239 $this->orig_method = $orig_method;
242 * Breaks the data up by XML entities
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);
251 $this->orig_obj->{$this->orig_method}($this, $chunk);
256 * Compatibility with older PHP versions
258 if (version_compare(phpversion(), '4.3', '<') && !function_exists('html_entity_decode') ) {
259 function html_entity_decode($str, $style=ENT_NOQUOTES) {
261 array_flip(get_html_translation_table(HTML_ENTITIES,$style)));
265 * Breaks up data by XML entities but leaves them unparsed,
266 * resulting in additional calls to the data handler<br />
267 * @package XML_HTMLSax
270 class XML_HTMLSax_Entities_Unparsed {
272 * Original handler object
278 * Original handler method
284 * Constructs XML_HTMLSax_Entities_Unparsed
285 * @param object handler object being decorated
286 * @param string original handler method
289 function XML_HTMLSax_Entities_Unparsed(&$orig_obj, $orig_method) {
290 $this->orig_obj =& $orig_obj;
291 $this->orig_method = $orig_method;
294 * Breaks the data up by XML entities
296 * @param string element data
299 function breakData(&$parser, $data) {
300 $data = preg_split('/(&.+?;)/',$data,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
301 foreach ( $data as $chunk ) {
302 $this->orig_obj->{$this->orig_method}($this, $chunk);