XML_HTMLSax3
[ class tree: XML_HTMLSax3 ] [ index: XML_HTMLSax3 ] [ all elements ]

Source for file Decorators.php

Documentation is available at Decorators.php

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

Documentation generated on Fri, 18 Jul 2008 21:44:54 +0200 by phpDocumentor 1.4.1