[ Index ]
 

Code source de SPIP Agora 1.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Agora1-4/safehtml-1.3.7/classes/HTMLSax3/ -> Decorators.php (source)

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


Généré le : Sat Feb 24 14:40:03 2007 par Balluche grâce à PHPXref 0.7