[ Index ]

PHP Cross Reference of Web Application Component Toolkit

title

Body

[close]

/framework/template/compiler/saxfilters/ -> whitespacesaxfilter.inc.php (source)

   1  <?php
   2  //--------------------------------------------------------------------------------
   3  // Copyright 2003 Procata, Inc.
   4  // Released under the LGPL license (http://www.gnu.org/copyleft/lesser.html)
   5  //--------------------------------------------------------------------------------
   6  /**
   7  * @package WACT_TEMPLATE
   8  * @version $Id: whitespacesaxfilter.inc.php,v 1.7 2004/11/12 21:25:07 jeffmoore Exp $
   9  */
  10  //--------------------------------------------------------------------------------
  11  /**
  12  * Includes
  13  */
  14  require_once WACT_ROOT . 'template/compiler/saxfilters/basesaxfilter.inc.php';
  15  /**
  16  * SaxFilter for whitespace compression in template. Removes all whitespace
  17  * except that inside a pre tag
  18  * @see http://wact.sourceforge.net/index.php/WhitespaceSaxFilter
  19  * @access public
  20  * @package WACT_TEMPLATE
  21  * @abstract
  22  */
  23  class WhitespaceSaxFilter extends BaseSaxFilter {
  24  
  25      /**
  26      * Whether we're inside an HTML page
  27      * @var boolean (default = FALSE)
  28      * @access private
  29      */
  30      var $inHtml = FALSE;
  31  
  32      /**
  33      * Whether we're inside an HTML where the contents
  34      * are preformatted e.g. pre or script
  35      * @var boolean (default = FALSE)
  36      * @access private
  37      */
  38      var $inPre = FALSE;
  39      
  40      /**
  41      * @param string tag name
  42      * @param array attributes
  43      * @return void
  44      * @access private
  45      */
  46  	function startElement($tag, $attrs) {
  47          switch ( strtolower($tag) ) {
  48              case 'textarea':
  49              case 'script':
  50              case 'pre':
  51                  $this->inPre = TRUE;
  52              break;
  53              case 'html':
  54                  $this->inHtml = TRUE;
  55              break;
  56          }
  57          parent::startElement($tag, $attrs);
  58      }
  59  
  60      /**
  61      * @param string tag name
  62      * @return void
  63      * @access private
  64      */
  65  	function endElement($tag) {
  66          switch ( strtolower($tag) ) {
  67              case 'textarea':
  68              case 'script':
  69              case 'pre':
  70                  $this->inPre = FALSE;
  71              break;
  72              case 'html':
  73                  $this->inHtml = FALSE;
  74              break;
  75          }
  76          parent::endElement($Parser, $tag, $empty);
  77      }
  78  
  79      /**
  80      * @param string text content in tag
  81      * @return void
  82      * @access private
  83      */
  84  	function characters($text) {
  85          if ( !$this->inPre && $this->inHtml ) {
  86              $text = trim($text);
  87              $text = preg_replace('/\s+/', ' ', $text);
  88          }
  89          parent::characters($Parser, $text);
  90      }
  91  }
  92  ?>


Generated: Sun Nov 28 19:36:09 2004 Cross-referenced by PHPXref 0.5