View file www/rating2.php

File size: 5.34Kb
<?php
error_reporting(15);
$rootpath="/home/kmx/includes/";
$site=$_SERVER['QUERY_STRING'];
include($rootpath."function.inc");

define("DBName","kmx");
define("HostName","localhost");
define("UserName","kmx");
define("Password","kmx-hosting");

$connectserv=@mysql_connect(HostName, UserName, Password);
$selectDB=@mysql_select_db(DBName);
$connect_bd=(($connectserv!=0)&&($selectDB!=0));

if (!$connect_bd) include($rootpath."mysqlerror.php");

$f=fopen('/home/kmx/includes/sluzhebnye/counter.timestamp','r');$tmp=fread($f,10);fclose($f);

if ($tmp<time())
	{
	# Обновляем счетчики
	$f=fopen('/home/kmx/includes/sluzhebnye/counter.timestamp','w');fwrite($f,time()+180);fclose($f);
	$q=@mysql(DBName,"SELECT `login` FROM `counter` WHERE `flag` = '1'");
	$s=mysql_num_rows($q);
	for ($i=0;$i<$s;$i++)
		{
	    $data=@mysql_fetch_array($q);
		$counterfile="/home/kmx/www/sites/".$data['login']."/counter.dat";
	    if     ($data['login']=='top')     $counterfile="/home/kmx/includes/sluzhebnye/top.counter";
	    elseif ($data['login']=='wap')     $counterfile="/home/kmx/includes/sluzhebnye/wap.counter";
	    elseif ($data['login']=='catalog') $counterfile="/home/kmx/includes/sluzhebnye/catalog.counter";
	    elseif ($data['login']=='forum')   $counterfile="/home/kmx/includes/sluzhebnye/forum.counter";

	    if ($f=@fopen($counterfile,"r+"))
	        {
	        fseek($f,0,SEEK_SET);

	        // Время сейчас
	        $hour=date('G');
	        $day=date('w');
	        $timestamp=time();

	        // Время на счетчике
	        fseek($f,198,SEEK_SET); $timestamp_=fread($f,10);
	        $hour_=date('G',$timestamp_);
	        $day_=date('w',$timestamp_);

	        # Счетчик за час
	        if ($hour_==$hour)
	            {
	            fseek($f,342+$hour*30,SEEK_SET);
	            $hit_hour=trim(fread($f,9));
	            $host_hour=trim(fread($f,7));
	            }
	        else
	            {
	            $hit_hour=0;
	            $host_hour=0;
	            }

	        # Счетчик за день
	        if ($day_==$day)
	            {
	            fseek($f,1142+$day*30,SEEK_SET);
	            $hit_day=trim(fread($f,9));
	            $host_day=trim(fread($f,7));
	            }
	        else
	            {
	            $hit_day=0;
	            $host_day=0;
	            }

	        # Общее хитов
	        fseek($f,247,SEEK_SET);
	        $hit_all=trim(fread($f,9));

			# Хосты за последние 24 часа
	        $host24=0;
	        for ($_hour=0;$_hour<24;$_hour++)
	            {
	            fseek($f,351+$_hour*30,SEEK_SET);
	            $host24=$host24+trim(fread($f,7));
	            }

			# Хосты и хиты по дням недели
	        for ($_day=0;$_day<7;$_day++)
	            {
	            fseek($f,1142+$_day*30,SEEK_SET);
	            $hit_week[]=trim(fread($f,9));
	            $host_week[]=trim(fread($f,7));
	            }

	        fclose($f);
	        }

	    # Обновление данных в каталоге
	    $summ_host=0;
	    $query_cat='';
	    for ($_day=0;$_day<7;$_day++)
	        {
	        $query_cat.="`d".$_day."` = '".$host_week[$_day]."', ";
	        $summ_host=$summ_host+$host_week[$_day];
	        }
	    $query_cat.=" `da` = '".$summ_host."'";
	    @mysql(DBName,"UPDATE `sites` SET ".$query_cat." WHERE `login` = '".addslashes($data['login'])."' LIMIT 1");

	    # Обновление данных в таблице счетчиков
	    @mysql(DBName,"UPDATE `counter` SET `host24` = '".$host24."' , `host` = '".$host_day."' , `hit` = '".$hit_day."' , `all` = '".$all."' , `day` = '".date('j')."' WHERE `login` = '".addslashes($data['login'])."' LIMIT 1");
		}
	}

$q=@mysql(DBName,"SELECT * FROM `counter` WHERE `flag` = '1' AND `login` != 'wap' AND `login` != 'catalog' AND `login` != 'top' AND `day` = '".date('j')."' AND `hit` > 0 ORDER BY `host` DESC LIMIT 0, 25");
$s=@mysql_num_rows($q);

Header("Content-type:text/vnd.wap.wml; charset=Utf-8");
Header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
Header("Cache-Control: no-cache, must-relative");
$head='<?xml version="1.0" encoding="Utf-8"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.xml"><wml>';
print $head.cyr2utf('<card id="main" title="TOP-KMX.Ru"><p align="center"><b>25 самых посещаемых</b></p><p><small>');

for ($i=0;$i<$s;$i++)
	{
	$data=@mysql_fetch_array($q);
	print cyr2utf('<br/><b>'.($i+1).'. <a href="http://'.$data['login'].'.kmx.ru">'.$data['login'].'.kmx.ru</a></b><br/>Посещений: '.$data['hit'].'<br/>Уникальных: '.$data['host'].'<br/>');
	}

print '- - - - -';

$q=@mysql(DBName,"SELECT * FROM `counter` WHERE `login` = 'top' LIMIT 0, 1");
$data=@mysql_fetch_array($q);
print cyr2utf('<br/><b><a href="http://top.kmx.ru">TOP-KMX.Ru</a></b><br/>Посещений: '.$data['hit'].'<br/>Уникальных: '.$data['host']);

$q=@mysql(DBName,"SELECT * FROM `counter` WHERE `login` = 'catalog' LIMIT 0, 1");
$data=@mysql_fetch_array($q);
print cyr2utf('<br/><b><a href="http://catalog.kmx.ru">Каталог-KMX.Ru</a></b><br/>Посещений: '.$data['hit'].'<br/>Уникальных: '.$data['host']);

$q=@mysql(DBName,"SELECT * FROM `counter` WHERE `login` = 'wap' LIMIT 0, 1");
$data=@mysql_fetch_array($q);
print cyr2utf('<br/><b><a href="http://kmx.ru">KMX.Ru</a></b><br/>Посещений: '.$data['hit'].'<br/>Уникальных: '.$data['host']);

print '<br/></small><img src="http://cnt.kmx.ru/top" alt="TOP-KMX.Ru"/></p></card></wml>';

?>