message
This commit is contained in:
63
system/modules/gzip.php
Normal file
63
system/modules/gzip.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
if(!defined('DATALIFEENGINE'))
|
||||
{
|
||||
die("Hacking attempt!");
|
||||
}
|
||||
|
||||
function CheckCanGzip(){
|
||||
|
||||
if (headers_sent() || connection_aborted() || !function_exists('ob_gzhandler') || ini_get('zlib.output_compression')) 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;
|
||||
}
|
||||
|
||||
|
||||
function GzipOut($debug=0){
|
||||
global $config, $Timer, $db, $tpl, $_DOCUMENT_DATE;
|
||||
|
||||
$s = "
|
||||
<!-- Âðåìÿ âûïîëíåíèÿ ñêðèïòà ".$Timer->stop()." ñåêóíä -->
|
||||
<!-- Âðåìÿ çàòðà÷åííîå íà êîìïèëÿöèþ øàáëîíîâ ".round($tpl->template_parse_time, 5)." ñåêóíä -->
|
||||
<!-- Âðåìÿ çàòðà÷åííîå íà âûïîëíåíèå MySQL çàïðîñîâ: ".round($db->MySQL_time_taken, 5)." ñåêóíä -->
|
||||
<!-- Îáùåå êîëè÷åñòâî MySQL çàïðîñîâ ".$db->query_num." -->";
|
||||
|
||||
if($_DOCUMENT_DATE)
|
||||
{
|
||||
@header ("Last-Modified: " . date('r', $_DOCUMENT_DATE) ." GMT");
|
||||
|
||||
}
|
||||
|
||||
if ($config['allow_gzip'] != "yes") {if ($debug) echo $s; ob_end_flush(); return;}
|
||||
|
||||
$ENCODING = CheckCanGzip();
|
||||
|
||||
if ($ENCODING){
|
||||
$s .= "\n<!-- Äëÿ âûâîäà èñïîëüçîâàëîñü ñæàòèå $ENCODING -->\n";
|
||||
$Contents = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
if ($debug){
|
||||
$s .= "<!-- Îáùèé ðàçìåð ôàéëà: ".strlen($Contents)." áàéò ";
|
||||
$s .= "Ïîñëå ñæàòèÿ: ".
|
||||
strlen(gzencode($Contents, 1, FORCE_GZIP)).
|
||||
" áàéò -->";
|
||||
$Contents .= $s;
|
||||
}
|
||||
|
||||
header("Content-Encoding: $ENCODING");
|
||||
|
||||
$Contents = gzencode($Contents, 1, FORCE_GZIP);
|
||||
echo $Contents;
|
||||
exit;
|
||||
|
||||
}else{
|
||||
|
||||
ob_end_flush();
|
||||
exit;
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user