Файл: PROFIWM.COM/top/count.php
Строк: 307
<?php
// by -=ШАХТЕР=- (waphp.ru - качай только тут)
error_reporting(0);
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
include "config.php";
//проверка ввода id
$data = $_SERVER['QUERY_STRING'];
list($uid, $size) = explode(",", $data);
$uid = check(intval($uid));
if (empty($uid)) exit;
// проверка существования учетной записи
$result = mysql_query("SELECT link FROM top_users WHERE uid=$uid");
$row=mysql_fetch_row($result);
if (empty($row)) header("Location: img/default.gif");
### Обновление даты пользование топом
$time_stamp = time();
$day_time = 24*60*60;
mysql_query("UPDATE `top_users` SET `date` = $time_stamp WHERE (`date` + $day_time) < $time_stamp AND `uid` = $uid LIMIT 1;
");
### Изменяем статус
$time_s = time();
$day_t = 86400;
mysql_query("UPDATE `top_users` SET `status` = 'user' WHERE (`regdate` + $day_t) < $time_s AND `uid` = $uid AND `status` != 'ban' LIMIT 1;
");
// получаем ip посетителя
$ip = check($_SERVER['REMOTE_ADDR']);
$ua = check($_SERVER['HTTP_USER_AGENT']);
$browser = explode("/",$ua);
$user_browser = (string)$browser[0];
// =================== Определение тела и учет в статистике
include "mod_telinfo.php";
// =================== Определение оператора и учет в статистике
include "mod_operators.php";
// текущий час, день недели и дата
$hour = date("H");
$day = date("d");
$today = date("Ymd");
// ------------------------- обнулялка хостов ----------------------------
// извлекаем время последней записи в счетчик хостов
$result = mysql_query("SELECT time FROM hits_time WHERE uid=$uid");
$row=mysql_fetch_row($result);
// если время отсутствует, запоминаем
if(empty($row)){
@mysql_query("INSERT INTO hits_time VALUES ($uid,$today)");
$reset_time = $today;
} else $reset_time = $row[0];
// удаляем записи ip старее суток
if($today != $reset_time){
@mysql_query("DELETE FROM hits_ip WHERE uid=$uid");
@mysql_query("UPDATE hits_time SET time = $today WHERE uid=$uid");
}
//------------------------------ часовая статистика -------------------------
// данные за текущий час
$result = mysql_query("SELECT count,host FROM count_24 WHERE hour=$hour AND date=$today AND uid=$uid");
$row=mysql_fetch_row($result);
// поверка наличия записи в базе
if (empty($row))
{
$res = mysql_query("SELECT count(*) FROM count_24 WHERE uid=$uid");
$data = mysql_fetch_row($res);
$count_rows = $data[0];
if ($count_rows >= 24) @mysql_query("DELETE FROM count_24 WHERE uid=$uid ORDER BY id ASC LIMIT 1;");
$rrow = mysql_fetch_array(mysql_query("SELECT * FROM top_users WHERE uid=$uid"));
$razd = $rrow['razdel'];
$status = $rrow['status'];
@mysql_query("INSERT INTO count_24 VALUES ('',$uid,$today,$hour,0,0,'$status');");
$hour_count = 0;
$hour_host = 0;
}else
{
$hour_count = $row[0];
$hour_host = $row[1];
}
$hour_count++;
// ---------------------------- посещения за месяц --------------------
$today = date("Ym");
// данные за текущий месяц
$result = mysql_query("SELECT count,host FROM months WHERE date=$today AND uid=$uid");
$row=mysql_fetch_row($result);
// поверка наличия записи в базе
if (empty($row))
{
$rrow = mysql_fetch_array(mysql_query("SELECT * FROM top_users WHERE uid=$uid"));
$razd = $rrow['razdel'];
$status = $rrow['status'];
@mysql_query("INSERT INTO months VALUES ('',$uid,$today,0,0,'$status');");
$this_month_count = 0;
$this_month_host = 0;
}else{
$this_month_count = $row[0];
$this_month_host = $row[1];
}
$this_month_count++;
//-------------------------- недельная статистика----------------
$week_day = date("w");
$today = date("Ymd");
// получаем дату обнуления недельной статистики
$result = mysql_query("SELECT next_mon FROM weeks WHERE uid=$uid ORDER BY id ASC LIMIT 1");
$row=mysql_fetch_row($result);
if (empty($row))
{
// расчитываем дату обнуления
$dayNext =$week_day + 7;
if ($dayNext > 7){
$dayNext-=7;
}
$cntDay=8-$dayNext;
$nextMonday=date("Ymd",mktime(0,0,0,date("m"),date("d")+$cntDay));
}
else $nextMonday = $row[0];
// если сегодня дата обнуления, обнуляем недельную статистику, и расчитываем след дату обнуления
if ($today >= $nextMonday)
{
// расчитываем след дату обнуления
$dayNext =$week_day + 7;
if ($dayNext > 7){
$dayNext-=7;
}
$cntDay=8-$dayNext;
$nextMonday=date("Ymd",mktime(0,0,0,date("m"),date("d")+$cntDay));
// обнуляем посещения за прошедшую неделю
@mysql_query("DELETE FROM `weeks` WHERE uid = $uid");
@mysql_query("DELETE FROM `top_operators_stat` WHERE uid = $uid");
### Удаление неактивных пользователей
$time_stamp = time ();
$week_time = 31*24*60*60;
$sql_result = mysql_query("
SELECT `uid` FROM `top_users`
WHERE ($time_stamp - `top_users`.`date`) > $week_time
");
while ($result = mysql_fetch_assoc($sql_result))
{
$del_uid = $result['uid'];
@mysql_query("DELETE FROM `top_users` WHERE uid = $del_uid");
@mysql_query("DELETE FROM `count_24` WHERE uid = $del_uid");
@mysql_query("DELETE FROM `hits_ip` WHERE uid = $del_uid");
@mysql_query("DELETE FROM `hits_time` WHERE uid = $del_uid");
@mysql_query("DELETE FROM `months` WHERE uid = $del_uid");
@mysql_query("DELETE FROM `online_ip` WHERE uid = $del_uid");
@mysql_query("DELETE FROM `top_operators_stat` WHERE uid = $del_uid");
@mysql_query("DELETE FROM `weeks` WHERE uid = $del_uid");
}
}
// получаем данные за текущий день недели
$result = mysql_query("SELECT count,host FROM weeks WHERE date=$today AND day_week=$week_day AND uid=$uid LIMIT 1");
$row=mysql_fetch_row($result);
if (empty($row))
{
// расчитываем дату обнуления
$dayNext =$week_day + 7;
if ($dayNext > 7)
{
$dayNext-=7;
}
$cntDay=8-$dayNext;
$nextMonday=date("Ymd",mktime(0,0,0,date("m"),date("d")+$cntDay));
$rrow = mysql_fetch_array(mysql_query("SELECT * FROM top_users WHERE uid=$uid"));
$razd = $rrow['razdel'];
$status = $rrow['status'];
@mysql_query("INSERT INTO weeks VALUES ('',$uid,$razd,$nextMonday,$today,$week_day,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'$status')");
$week_day_count = 0;
$week_day_host = 0;
} else{
$week_day_count = $row[0];
$week_day_host = $row[1];
}
$week_day_count++;
// ======================================== хосты (оптимиз код) ===================================
// чтение текущего ip хита из базы
$result = mysql_query("SELECT `ip` FROM `hits_ip` WHERE (`ip`='$ip' AND `ua`='$ua') AND `uid`=$uid");
$row=mysql_fetch_row($result);
// если адрес отсутствует, плюсуем хост
if(empty($row))
{
// защита от накрутки
$result = mysql_query("SELECT `ip` FROM `hits_ip` WHERE `uid`=$uid ORDER BY `time` DESC LIMIT 1;");
$row = mysql_fetch_array($result);
if (empty($row) || ($row['ip'] != $ip))
{
$hour_host++;
$week_day_host++;
$this_month_host++;
mysql_query("INSERT INTO `hits_ip` VALUES ($uid,'$ip','$ua',".time().")");
}
}
// сохранение посещения
$rrow = mysql_fetch_array(mysql_query("SELECT * FROM top_users WHERE uid=$uid"));
$status = $rrow['status'];
@mysql_query("UPDATE count_24 SET count=$hour_count,host=$hour_host, status = '$status' WHERE hour=$hour AND date=$today AND uid=$uid");
@mysql_query("UPDATE weeks SET count=$week_day_count, host=$week_day_host, status = '$status' WHERE date=$today AND day_week=$week_day AND uid=$uid LIMIT 1");
$today = date("Ym");
@mysql_query("UPDATE months SET count=$this_month_count,host=$this_month_host, status = '$status' WHERE date=$today AND uid=$uid");
// за сегодня
$count_today = $week_day_count;
$host_today = $week_day_host;
// ------------------------------- онлайн -----------------------------
$today = date("Ymd");
$now=date("ymdHi");
// удаляем записи ip старее online_time минут
// del_time время позднее которого записи считаются старыми
$del_time = date("ymdHi", mktime(date("H"), date("i")-$online_time));
@mysql_query("DELETE FROM `online_ip` WHERE `uid`=$uid AND `time` <= $del_time");
// --------- онлайн
$result = mysql_query("SELECT ip FROM online_ip WHERE ip='$ip' AND uid=$uid");
$row = mysql_num_rows($result);
// если адрес отсутствует, записываем
if(empty($row)){
mysql_query("INSERT INTO online_ip VALUES ($uid,'$ip',$now,'$user_browser')");
}
$online = mysql_result(mysql_query("SELECT count(ip) FROM online_ip WHERE uid=$uid"),0);
// за 24 часа
$today = date("Ymd");
$hour = date("H");
$result = mysql_query("SELECT sum(count) FROM count_24 WHERE ((date=$today-1 AND hour>$hour) OR (date=$today AND hour<=$hour)) AND uid=$uid");
$row = mysql_fetch_row($result);
$count_24 = (int)$row[0];
// -----------------------Всего---------------------------
$result = mysql_query("SELECT sum(count) FROM months WHERE uid=$uid");
$row=mysql_fetch_row($result);
$all_count = (int)$row[0];
/*---------------
$count_today - хиты
$host_today - хосты
$online - онлайн
$count_24 - за 24 часа
$all_count - всего
-----------------*/
// вывод информации
$result = mysql_query("SELECT type FROM top_users WHERE uid=$uid");
$type=mysql_fetch_row($result);
$result = mysql_query("SELECT typeStat FROM top_users WHERE uid=$uid");
$typeStat=mysql_fetch_row($result);
$image=$type[0];
if($type[0]==1 or $type[0]==3 or $type[0]==4 or $type[0]==5){
$image.=$typeStat[0];
}
if($size == "small")
{
$img = imagecreatefromgif("img/1".$typeStat[0].".gif");
}
else
{
$img = @imageCreateFromGIF("img/".$image.".gif");
$color = imagecolorallocate($img, 255,255,255);
$color2 = imagecolorallocate($img, 0,0,0);
############################################################
// средний 3
if($image==41){
///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$x2 = (ImageSX($img) - 5*strlen("$host_today")-3);
$x3 = (ImageSX($img) - 5*strlen("$count_today")-3);
$y = 3;
///imageString($img, 1, $x1, $y,"$count_today", $color);
imageString($img, 1, $x2-35, $y+12,"$host_today", $color);
imageString($img, 1, $x3+1, $y+12,"$count_today", $color2);
}
// средний 3
if($image==42){
///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$x2 = (ImageSX($img) - 5*strlen("$host_today")-3);
$x3 = (ImageSX($img) - 5*strlen("$count_today")-3);
$y = 3;
///imageString($img, 1, $x1, $y,"$count_today", $color);
imageString($img, 1, $x2-35, $y+12,"$host_today", $color);
imageString($img, 1, $x3+1, $y+12,"$count_today", $color2);
}
// средний 3
if($image==43){
///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$x2 = (ImageSX($img) - 5*strlen("$host_today")-3);
$x3 = (ImageSX($img) - 5*strlen("$count_today")-3);
$y = 3;
///imageString($img, 1, $x1, $y,"$count_today", $color);
imageString($img, 1, $x2-35, $y+12,"$host_today", $color);
imageString($img, 1, $x3+1, $y+12,"$count_today", $color2);
}
// средний 3
if($image==44){
///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$x2 = (ImageSX($img) - 5*strlen("$host_today")-3);
$x3 = (ImageSX($img) - 5*strlen("$count_today")-3);
$y = 3;
///imageString($img, 1, $x1, $y,"$count_today", $color);
imageString($img, 1, $x2-50, $y+12,"$host_today", $color);
imageString($img, 1, $x3-5, $y+12,"$count_today", $color2);
}
// средний 3
if($image==45){
///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$x2 = (ImageSX($img) - 5*strlen("$host_today")-3);
$x3 = (ImageSX($img) - 5*strlen("$count_today")-3);
$y = 3;
///imageString($img, 1, $x1, $y,"$count_today", $color);
imageString($img, 1, $x2-35, $y+12,"$host_today", $color);
imageString($img, 1, $x3+1, $y+12,"$count_today", $color2);
}
// средний 3
if($image==46){
///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$x2 = (ImageSX($img) - 5*strlen("$host_today")-3);
$x3 = (ImageSX($img) - 5*strlen("$count_today")-3);
$y = 3;
///imageString($img, 1, $x1, $y,"$count_today", $color);
imageString($img, 1, $x2-35, $y+12,"$host_today", $color);
imageString($img, 1, $x3+1, $y+12,"$count_today", $color2);
}
############################################################
// полный
if($image==51){
///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$x2 = (ImageSX($img) - 5*strlen("$host_today")-3);
$x3 = (ImageSX($img) - 5*strlen("$online")-3);
$x4 = (ImageSX($img) - 5*strlen("$count_24")-3);
$x5 = (ImageSX($img) - 5*strlen("$all_count")-3);
$y = 3;
/////imageString($img, 1, $x1, $y,"$count_today", $color);
imageString($img, 1, $x2+1, $y+11,"$host_today", $color2);
imageString($img, 1, $x3+1, $y+18,"$online", $color2);
imageString($img, 1, $x4+1, $y+25,"$count_24", $color2);
imageString($img, 1, $x5+1, $y+32,"$all_count", $color2);
}
// полный
if($image==52){
///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$x2 = (ImageSX($img) - 5*strlen("$host_today")-3);
$x3 = (ImageSX($img) - 5*strlen("$online")-3);
$x4 = (ImageSX($img) - 5*strlen("$count_24")-3);
$x5 = (ImageSX($img) - 5*strlen("$all_count")-3);
$y = 3;
/////imageString($img, 1, $x1, $y,"$count_today", $color);
imageString($img, 1, $x2+1, $y+11,"$host_today", $color2);
imageString($img, 1, $x3+1, $y+18,"$online", $color2);
imageString($img, 1, $x4+1, $y+25,"$count_24", $color2);
imageString($img, 1, $x5+1, $y+32,"$all_count", $color2);
}
// полный
if($image==53){
///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$x2 = (ImageSX($img) - 5*strlen("$host_today")-3);
$x3 = (ImageSX($img) - 5*strlen("$online")-3);
$x4 = (ImageSX($img) - 5*strlen("$count_24")-3);
$x5 = (ImageSX($img) - 5*strlen("$all_count")-3);
$y = 3;
/////imageString($img, 1, $x1, $y,"$count_today", $color);
imageString($img, 1, $x2+1, $y+11,"$host_today", $color2);
imageString($img, 1, $x3+1, $y+18,"$online", $color2);
imageString($img, 1, $x4+1, $y+25,"$count_24", $color2);
imageString($img, 1, $x5+1, $y+32,"$all_count", $color2);
}
// полный
if($image==54){
///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$x2 = (ImageSX($img) - 5*strlen("$host_today")-3);
$x3 = (ImageSX($img) - 5*strlen("$online")-3);
$x4 = (ImageSX($img) - 5*strlen("$count_24")-3);
$x5 = (ImageSX($img) - 5*strlen("$all_count")-3);
$y = 3;
/////imageString($img, 1, $x1, $y,"$count_today", $color);
imageString($img, 1, $x2+1, $y+11,"$host_today", $color2);
imageString($img, 1, $x3+1, $y+18,"$online", $color2);
imageString($img, 1, $x4+1, $y+25,"$count_24", $color2);
imageString($img, 1, $x5+1, $y+32,"$all_count", $color2);
}
// полный
if($image==55){
///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$x2 = (ImageSX($img) - 5*strlen("$host_today")-3);
$x3 = (ImageSX($img) - 5*strlen("$online")-3);
$x4 = (ImageSX($img) - 5*strlen("$count_24")-3);
$x5 = (ImageSX($img) - 5*strlen("$all_count")-3);
$y = 3;
/////imageString($img, 1, $x1, $y,"$count_today", $color);
imageString($img, 1, $x2+1, $y+11,"$host_today", $color2);
imageString($img, 1, $x3+1, $y+18,"$online", $color2);
imageString($img, 1, $x4+1, $y+25,"$count_24", $color2);
imageString($img, 1, $x5+1, $y+32,"$all_count", $color2);
}
// полный
if($image==56){
///$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$x2 = (ImageSX($img) - 5*strlen("$host_today")-3);
$x3 = (ImageSX($img) - 5*strlen("$online")-3);
$x4 = (ImageSX($img) - 5*strlen("$count_24")-3);
$x5 = (ImageSX($img) - 5*strlen("$all_count")-3);
$y = 3;
/////imageString($img, 1, $x1, $y,"$count_today", $color);
imageString($img, 1, $x2+1, $y+11,"$host_today", $color2);
imageString($img, 1, $x3+1, $y+18,"$online", $color2);
imageString($img, 1, $x4+1, $y+25,"$count_24", $color2);
imageString($img, 1, $x5+1, $y+32,"$all_count", $color2);
}
############################################################
############################################################
// маленький
if($image==31){
$x = (ImageSX($img) - 5*strlen("$host_today")-3);
$y =0;
imageString($img, 1, $x-1, $y+4,"$host_today", $color2);
}
// маленький
if($image==32){
$x = (ImageSX($img) - 5*strlen("$host_today")-3);
$y =0;
imageString($img, 1, $x-1, $y+4,"$host_today", $color2);
}
// маленький
if($image==33){
$x = (ImageSX($img) - 5*strlen("$host_today")-3);
$y =0;
imageString($img, 1, $x-1, $y+4,"$host_today", $color2);
}
// маленький
if($image==34){
$x = (ImageSX($img) - 5*strlen("$host_today")-3);
$y =0;
imageString($img, 1, $x-1, $y+4,"$host_today", $color2);
}
// маленький
if($image==35){
$x = (ImageSX($img) - 5*strlen("$host_today")-3);
$y =0;
imageString($img, 1, $x-1, $y+4,"$host_today", $color2);
}
// маленький
if($image==36){
$x = (ImageSX($img) - 5*strlen("$host_today")-3);
$y =0;
imageString($img, 1, $x-1, $y+4,"$host_today", $color2);
}
############################################################
/*Header("Content-type: image/gif");
ImageGIF($img);
ImageDestroy($img);*/
}
header("Content-type: ".image_type_to_mime_type(IMAGETYPE_GIF));
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-cache, must-relative");
imagegif($img);
imagedestroy($img);
die();
?>