if(!defined('DATALIFEENGINE'))
{
die("Hacking attempt!");
}
function CheckCanGzip(){
if (headers_sent() || connection_aborted()){
return 0;
}
if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false) return "x-gzip";
if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) return "gzip";
return 0;
}
/* $level = compression level 0-9, 0=none, 9=max */
function GzipOut($debug=0, $level=5){
global $config, $Timer, $db, $tpl;
$s_bot = '<div align="center" ><font size="1" color="#A0A0A0">' .
"Script time: " . $Timer->stop() . ", templates time: " . round($tpl->template_parse_time, 5) .
"sec, MySQL time: " . round($db->MySQL_time_taken, 5) . " sec, MySQL queries: " . $db->query_num .
"</font></div>";
$Contents = ob_get_contents() . $s_bot;
ob_end_clean();
header ("Last-Modified: " . date('r', time()-60*60*10) ." GMT");
header ("Expires: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
//if (@intval($hour) != "" && @intval($hour) != 0) $hour = $hour - 1;
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
if ($config['allow_gzip'] != "yes") {if ($debug) echo $Contents; return;}
$ENCODING = CheckCanGzip();
if ($ENCODING){
$s = "\n<!-- Для вывода использовалось сжатие $ENCODING -->\n";
//$Contents = ob_get_contents();
//ob_end_clean();
if ($debug){
$s .= "<!-- Общий размер файла: ".strlen($Contents)." байт ";
$s .= "После сжатия: ".
strlen(gzcompress($Contents, $level)).
" байт -->";
$Contents .= $s;
}
header("Content-Encoding: $ENCODING");
print "\x1f\x8b\x08\x00\x00\x00\x00\x00";
$Size = strlen($Contents);
$Crc = crc32($Contents);
$Contents = gzcompress($Contents, $level);
$Contents = substr($Contents, 0, strlen($Contents) - 4);
print $Contents;
print pack('V', $Crc);
print pack('V', $Size);
exit;
}else{
echo $Contents;
exit;
}
}