[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/libraries/pattemplate/patTemplate/OutputFilter/ -> Gzip.php (source)

   1  <?PHP
   2  /**
   3   * patTemplate GZip output filter
   4   *
   5   * $Id: Gzip.php 10381 2008-06-01 03:35:53Z pasamio $
   6   *
   7   * Checks the accept encoding of the browser and
   8   * compresses the data before sending it to the client.
   9   *
  10   * @package        patTemplate
  11   * @subpackage    Filters
  12   * @author        Stephan Schmidt <schst@php.net>
  13   */
  14  
  15  // Check to ensure this file is within the rest of the framework
  16  defined('JPATH_BASE') or die();
  17  
  18  /**
  19   * patTemplate GZip output filter
  20   *
  21   * $Id: Gzip.php 10381 2008-06-01 03:35:53Z pasamio $
  22   *
  23   * Checks the accept encoding of the browser and
  24   * compresses the data before sending it to the client.
  25   *
  26   * @package        patTemplate
  27   * @subpackage    Filters
  28   * @author        Stephan Schmidt <schst@php.net>
  29   */
  30  class patTemplate_OutputFilter_Gzip extends patTemplate_OutputFilter
  31  {
  32      /**
  33      * filter name
  34      *
  35      * This has to be set in the final
  36      * filter classes.
  37      *
  38      * @access    protected
  39      * @abstract
  40      * @var    string
  41      */
  42      var    $_name    =    'Gzip';
  43  
  44      /**
  45      * compress the data
  46      *
  47      * @access    public
  48      * @param    string        data
  49      * @return    string        compressed data
  50      */
  51  	function apply( $data )
  52      {
  53          if (!$this->_clientSupportsGzip()) {
  54              return $data;
  55          }
  56  
  57          $size = strlen( $data );
  58          $crc  = crc32( $data );
  59  
  60          $data = gzcompress( $data, 9 );
  61          $data = substr( $data, 0, strlen( $data ) - 4 );
  62  
  63          $data .= $this->_gfc( $crc );
  64          $data .= $this->_gfc( $size );
  65  
  66          header( 'Content-Encoding: gzip' );
  67          $data = "\x1f\x8b\x08\x00\x00\x00\x00\x00" . $data;
  68          return $data;
  69      }
  70  
  71      /**
  72      * check, whether client supports compressed data
  73      *
  74      * @access    private
  75      * @return    boolean
  76      */
  77  	function _clientSupportsGzip()
  78      {
  79          if (!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
  80              return false;
  81          }
  82  
  83          if (false !== strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
  84              return  true;
  85          }
  86          return  false;
  87      }
  88  
  89      /**
  90      * get value as hex-string
  91      *
  92      * @access      public
  93      * @param       integer $value  value to convert
  94      * @return      string  $string converted string
  95      */
  96  	function _gfc( $value )
  97      {
  98          $str = '';
  99          for ($i = 0; $i < 4; $i ++) {
 100              $str  .= chr( $value % 256 );
 101              $value = floor( $value / 256 );
 102          }
 103          return  $str;
 104      }
 105  }
 106  ?>


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1