Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: patTemplate

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /pattemplate/patTemplate/OutputFilter/Gzip.php

Documentation is available at Gzip.php

  1. <?PHP
  2. /**
  3.  * patTemplate GZip output filter
  4.  *
  5.  * $Id: Gzip.php 359 2005-02-18 19:01:54Z schst $
  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 <[email protected]>
  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 359 2005-02-18 19:01:54Z schst $
  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 <[email protected]>
  29.  */
  30. {
  31.    /**
  32.     * filter name
  33.     *
  34.     * This has to be set in the final
  35.     * filter classes.
  36.     *
  37.     * @access    protected
  38.     * @abstract
  39.     * @var    string 
  40.     */
  41.     var    $_name    =    'Gzip';
  42.  
  43.    /**
  44.     * compress the data
  45.     *
  46.     * @access    public
  47.     * @param    string        data
  48.     * @return    string        compressed data
  49.     */
  50.     function apply$data )
  51.     {
  52.         if (!$this->_clientSupportsGzip()) {
  53.             return $data;
  54.         }
  55.  
  56.         $size strlen$data );
  57.         $crc  crc32$data );
  58.  
  59.         $data gzcompress$data);
  60.         $data substr$data0strlen$data );
  61.  
  62.         $data .= $this->_gfc$crc );
  63.         $data .= $this->_gfc$size );
  64.  
  65.         header'Content-Encoding: gzip' );
  66.         $data "\x1f\x8b\x08\x00\x00\x00\x00\x00" $data;
  67.         return $data;
  68.     }
  69.  
  70.    /**
  71.     * check, whether client supports compressed data
  72.     *
  73.     * @access    private
  74.     * @return    boolean 
  75.     */
  76.     function _clientSupportsGzip()
  77.     {
  78.         if (!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
  79.             return false;
  80.         }
  81.  
  82.         if (false !== strpos($_SERVER['HTTP_ACCEPT_ENCODING']'gzip')) {
  83.             return  true;
  84.         }
  85.         return  false;
  86.     }
  87.  
  88.    /**
  89.     * get value as hex-string
  90.     *
  91.     * @access      public
  92.     * @param       integer $value  value to convert
  93.     * @return      string  $string converted string
  94.     */
  95.     function _gfc$value )
  96.     {
  97.         $str '';
  98.         for ($i 0$i 4$i ++{
  99.             $str  .= chr$value 256 );
  100.             $value floor$value 256 );
  101.         }
  102.         return  $str;
  103.     }
  104. }
  105. ?>

Documentation generated on Mon, 05 Mar 2007 21:05:18 +0000 by phpDocumentor 1.3.1