23 $this->_iExpirationOffset = 3600 * 24 * 10;
25 $this->_sInFile = CH_DIRECTORY_PATH_CACHE_PUBLIC .
$sFile;
26 $this->_sOutFile = CH_DIRECTORY_PATH_CACHE_PUBLIC .
$sFile .
'.gz';
29 if(!preg_match(
"/^([a-z0-9_-]+)\.(js|css)$/",
$sFile, $aMatches))
32 switch($aMatches[2]) {
34 $this->_sType =
'css';
37 $this->_sType =
'javascript';
41 $this->_sOutContent =
"";
42 $this->_sOutContentZipped =
"";
56 header(
"Content-type: text/" . $this->_sType);
57 header(
"Vary: Accept-Encoding");
58 header(
"Expires: " . gmdate(
"D, d M Y H:i:s",
time() + $this->_iExpirationOffset) .
" GMT");
60 $encodings = array ();
61 if (isset($_SERVER[
'HTTP_ACCEPT_ENCODING']))
62 $encodings = explode(
',', strtolower(preg_replace(
"/\s+/",
"", $_SERVER[
'HTTP_ACCEPT_ENCODING'])));
64 if ((in_array(
'gzip', $encodings) || in_array(
'x-gzip', $encodings) || isset($_SERVER[
'---------------'])) && function_exists(
'ob_gzhandler') && !ini_get(
'zlib.output_compression')) {
65 $this->_sEncoding = in_array(
'x-gzip', $encodings) ?
"x-gzip" :
"gzip";
72 if($this->_bGzip && file_exists($this->_sOutFile))
84 header(
"Content-Encoding: " . $this->_sEncoding);
85 if(!
empty($this->_sOutContentZipped)) {
90 if (!$this->_sOutContent)
93 $this->_sOutContentZipped = gzencode($this->_sOutContent, 9, FORCE_GZIP);
100 $sPath = realpath($sPath);
102 if(!$sPath || !@is_file($sPath))
105 if(function_exists(
"file_get_contents"))
106 return @file_get_contents($sPath);
109 if(!($rHandler = @fopen($sPath,
"r")))
112 while(!feof($rHandler))
122 if (function_exists(
"file_put_contents"))
123 return @file_put_contents($sPath,
$sContent);
125 if(!($rHandler = @fopen($sPath,
"wb")))
128 $iResult = (int)fwrite($rHandler,
$sContent);