<?
error_reporting(E_ALL & ~E_NOTICE);
include "config.php";
// Эта функция позволяет определить длину строки в пикселях
function width($text) {
$box=imagettfbbox(7, 0, FONT_TAHOMA, $text);
return($box[2]-$box[1]);
}
// Шрифт, который мы используем для вывода счетчика.
// Можно взять из C:\Windows\Fonts
define('FONT_TAHOMA', 'tahoma.ttf');
// Внимание ! Изображение должно быть True-Color (24 бита)
$im=ImageCreateFromPng("button-big.png");
$CONN=@mysql_connect($STATS_CONF["sqlhost"],
$STATS_CONF["sqluser"],
$STATS_CONFs["sqlpassword"]);
if (mysql_errno()==0) {
@mysql_select_db($STATS_CONF["dbname"]);
if (mysql_errno()==0) {
$r=@mysql_query("SELECT t_hits,t_hosts,t_users,hits,hosts,users,u_hits FROM cns_counter");
$res=@mysql_fetch_array($r,MYSQL_ASSOC);
@mysql_free_result($r);
$text = number_format($res["t_hits"],0,","," ");
Imagettftext($im,7, 0, 86-width($text), 11, 0xCCCCCC, FONT_TAHOMA, $text);
Imagettftext($im,7, 0, 85-width($text), 10, 0x03314A, FONT_TAHOMA, $text);
$text = number_format($res["hits"],0,","," ");
Imagettftext($im,7, 0, 86-width($text), 20, 0xCCCCCC, FONT_TAHOMA, $text);
Imagettftext($im,7, 0, 85-width($text), 19, 0x0331FF, FONT_TAHOMA, $text);
$text = number_format($res["t_hosts"],0,","," ");
Imagettftext($im,7, 0, 86-width($text), 31, 0xCCCCCC, FONT_TAHOMA, $text);
Imagettftext($im,7, 0, 85-width($text), 30, 0x03314A, FONT_TAHOMA, $text);
$text = number_format($res["hosts"],0,","," ");
Imagettftext($im,7, 0, 86-width($text), 40, 0xCCCCCC, FONT_TAHOMA, $text);
Imagettftext($im,7, 0, 85-width($text), 39, 0x0331FF, FONT_TAHOMA, $text);
$text = number_format($res["t_users"],0,","," ");
Imagettftext($im,7, 0, 86-width($text), 51, 0xCCCCCC, FONT_TAHOMA, $text);
Imagettftext($im,7, 0, 85-width($text), 50, 0x03314A, FONT_TAHOMA, $text);
$text = number_format($res["users"],0,","," ");
Imagettftext($im,7, 0, 86-width($text), 60, 0xCCCCCC, FONT_TAHOMA, $text);
Imagettftext($im,7, 0, 85-width($text), 59, 0x0331FF, FONT_TAHOMA, $text);
$r=mysql_query("SELECT count(DISTINCT hid) as online
FROM cns_log
WHERE date>NOW() - INTERVAL 3 MINUTE;");
$text = mysql_result($r,0,0);
Imagettftext($im,7, 0, 86-width($text), 70, 0xCCCCCC, FONT_TAHOMA, $text);
Imagettftext($im,7, 0, 85-width($text), 69, 0xC0314A, FONT_TAHOMA, $text);
$text = sprintf("%.2f%%",(1-$res["u_hits"]/$res["hits"])*100);
Imagettftext($im,7, 0, 86-width($text), 82, 0xCCCCCC, FONT_TAHOMA, $text);
Imagettftext($im,7, 0, 85-width($text), 81, 0x03804A, FONT_TAHOMA, $text);
}
}
ImagePng($im);
ImageDestroy($im);
?>