Код: Выделить всё
#
#---OPEN includes/page_header.php
#
#
#---FIND
#
//
// gzip_compression
//
$do_gzip_compress = FALSE;
if ( $board_config['gzip_compress'] )
{
$phpver = phpversion();
$useragent = (isset($_SERVER["HTTP_USER_AGENT"]) ) ? $_SERVER["HTTP_USER_AGENT"] : $HTTP_USER_AGENT;
if ( $phpver >= '4.0.4pl1' && ( strstr($useragent,'compatible') || strstr($useragent,'Gecko') ) )
{
if ( extension_loaded('zlib') )
{
ob_start('ob_gzhandler');
}
}
else
if ( $phpver > '4.0' )
{
if ( strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') )
{
if ( extension_loaded('zlib') )
{
$do_gzip_compress = TRUE;
ob_start();
ob_implicit_flush(0);
@header('Content-Encoding: gzip');
}
}
}
}
#
#---REPLACE WITH
#
ob_start();
#
#---OPEN includes/page_tail.php
#
#
#---FIND
#
$template->pparse('overall_footer');
#
#---ADD AFTER
#
//
// SAVE QSL QUERIES COUT
//
$page_sql_queries = $db->num_queries;
#
#---FIND
#
/* Un-comment the line below to restrict Admins only to view page generation info */
//if( ($userdata['session_logged_in']) and ($userdata['user_level'] == ADMIN) )
{
$gzip_text = ($board_config['gzip_compress']) ? 'GZIP enabled' : 'GZIP disabled';
$debug_text = (DEBUG == 1) ? 'Debug on' : 'Debug off';
$excuted_queries = $db->num_queries;
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$gentime = round(($endtime - $starttime), 4);
$sql_time = round($db->sql_time, 4);
$sql_part = round($sql_time / $gentime * 100);
$php_part = 100 - $sql_part;
echo '<br /><div class="gensmall" align="center">Page generation time: '. $gentime .'s (PHP: '. $php_part .'% - SQL: '. $sql_part .'%) - SQL queries: '. $excuted_queries .' - '. $gzip_text .' - '. $debug_text .'</div>';
}
//
// Compress buffered output if required and send to browser
//
if ( $do_gzip_compress )
{
//
// Borrowed from php.net!
//
$gzip_contents = ob_get_contents();
ob_end_clean();
$gzip_size = strlen($gzip_contents);
$gzip_crc = crc32($gzip_contents);
$gzip_contents = gzcompress($gzip_contents, 9);
$gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4);
echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
echo $gzip_contents;
echo pack('V', $gzip_crc);
echo pack('V', $gzip_size);
}
#
#---REPLACE WITH
#
function dk_ob_gzhandler($uncompress)
{
global $board_config, $page_gen_time, $page_sql_queries, $page_size;
$len1 = strlen($uncompress);
if ($board_config['gzip_compress'] && strstr(@$_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
{
$compress = ob_gzhandler($uncompress, 9);
}
else
{
$compress = $uncompress;
}
/*
if ($board_config['gzip_compress']) {
if (strstr(@$_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
{
$compress = ob_gzhandler($uncompress, 9);
}
else
{
$compress = $uncompress;
}
} else {
$compress = $uncompress;
}
*/
$len2 = strlen($compress);
@SetCookie('page_gen_time', $page_gen_time, 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
@SetCookie('page_sql_queries', $page_sql_queries, 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
@SetCookie('page_size', "$len1, $len2", 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
return $compress;
}
$html = ob_get_contents();
ob_clean();
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$page_gen_time = round(($endtime - $starttime), 4);
echo dk_ob_gzhandler($html);
#
#---OPEN templates/subSilver/overall_footer.tpl
#
#
#---FIND
#
</td>
</tr>
</table>
</body>
</html>
#
#---BEFORE ADD
#
<table width="100%" align="center" border="0" cellpadding="3">
<tr>
<td width="100"> </td>
<td id="stat" align="center" class="gensmall"></td>
<td width="100" align="right" class="gensmall"> </td>
</tr>
</table>
<script language="JavaScript">
<!--
// The trim-family functions
String.prototype.ltrim = function()
{
return this.replace(/(^\s*)/, "");
}
String.prototype.rtrim = function()
{
return this.replace(/(\s*$)/g, "");
}
String.prototype.trim = function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}
function getCookie(name)
{
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var s = cookies[i].trim().split('=');
if (name == s[0]) return unescape(s[1]);
}
return null;
}
// The code below is modified cosmetically
// Original code has copyright by Dmitry Koteroff http://forum.dklab.ru
var time = getCookie('page_gen_time');
var sql = getCookie('page_sql_queries');
var size = getCookie('page_size');
size = size ? size.split(/,\s*/) : null;
var size_before = getCookie('page_size_before');
var size_after = getCookie('page_size_after');
document.getElementById("stat").innerHTML = ''
+ (time ? '[Generation time: ' + time + ' s] .::. ' : '')
+ (sql ? '[SQL queries: ' + sql + '] .::. ' : '')
+ (size ? '[GZIP compression: ' + (size ? size[1] + '/' + size[0] + ' (' + (100 - Math.round(size[1] / size[0] * 100)) + '
//-->
</script>
написано по мотивам Page Generation Time
немного кода (javascript с небольшими косметическими изменениями) взяты с форума ДК
оригинальный мод Page Generation Time, имхо содержит большую ошибку в определении времени генерации страницы - а именно при включенном гзип-сжатии неучитывается время самого гзипования, а оно не нулевое!!!
хотя это больше похоже модификацию модификации и требует наличия оригинального мода