Файл: includes/rating.php
Строк: 144
<?php
error_reporting(0);
$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 ((strlen($site)<=3)&&($site<=999)&&($site>1)) {$page=($site-1)*10;}
else {$site=1; $page=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 `domain`, `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['domain']."/".$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,342+$_hour*30,SEEK_SET);
$hit_hour=trim(fread($f,9));
$host_hour=trim(fread($f,7));
$host24=$host24+$host_hour;
}
# Хосты и хиты по дням недели
for ($_day=0;$_day<7;$_day++)
{
fseek($f,1142+$_day*30,SEEK_SET);
$hit_week[$_day]=trim(fread($f,9));
$host_week[$_day]=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 `domain` = '".addslashes($data['domain'])."' AND `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 `domain` = '".addslashes($data['domain'])."' AND `login` = '".addslashes($data['login'])."' LIMIT 1");
}
include($rootpath."refresh_reklama_link.php");
}
$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 (`host24`*1000000+`host`*1000+`hit`) DESC LIMIT ".$page.", 11");
$s=@mysql_num_rows($q);
if ($s>10) {$s=10; $npage=true;}
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">'.
'<do name="m" type="options" label="KMX.Ru"><go href="http://wap.kmx.ru"/></do>'.
'<do name="k" type="options" label="Каталог"><go href="http://catalog.kmx.ru"/></do>'.
'<p align="center"><b>Самые посещаемые</b></p><p>');
for ($i=0;$i<$s;$i++)
{
$data=@mysql_fetch_array($q);
$q2=@mysql(DBName,"SELECT * FROM `sites` WHERE `domain` = '".$data['domain']."' AND `login` = '".$data['login']."' LIMIT 1");
$data2=@mysql_fetch_array($q2);
if (($data['rekommend']==1)&&($catalog2!='rekommend')) $rekom='(!)'; else $rekom='';
print '<b>'.($page+$i+1).'.'.$rekom;
if (trim($data2['name'])!='') print cyr2utf(' <a href="http://'.$data['login'].'.'.$data['domain'].'.ru">'.htmlspecialchars($data2['name']).'</a></b><br/>'.$data['login'].'.'.$data['domain'].'.ru<br/><small>');
if (trim($data2['name'])=='') print cyr2utf(' <a href="http://'.$data['login'].'.'.$data['domain'].'.ru">'.$data['login'].'.'.$data['domain'].'.ru</a></b><br/><small>');
if (trim($data2['descr'])!='') print cyr2utf(htmlspecialchars($data2['descr']).'<br/>');
print cyr2utf('Посещений: '.$data['hit'].'<br/>Посетителей: '.$data['host'].'<br/>За 24 часа: '.$data['host24'].'</small> <br/> <br/>');
if ($page<51)
{
$f=@fopen('/home/kmx/www/sites/'.$data['domain'].'/'.$data['login'].'/services.dat','r');
$servicelist=@fread($f,1024);
$servicelist=str_replace(';;', ';', 'chat10;'.str_replace('chat10','',$servicelist));
$f=fopen('/home/kmx/www/sites/'.$data['domain'].'/'.$data['login'].'/services.dat',"w+");
fwrite($f,$servicelist);fclose($f);
}
}
if ($page>0)
if ($page>10) print cyr2utf('<a href="http://top.kmx.ru/'.($site-1).'">Назад</a>');
else print cyr2utf('<a href="http://top.kmx.ru">Назад</a>');
if (($page>0)&&$npage) print ' | ';
if ($npage) print cyr2utf('<a href="http://top.kmx.ru/'.($site+1).'">Далее</a><br/>');
else print '<br/>';
print '- - - - -';
$q=@mysql(DBName,"SELECT * FROM `counter` WHERE `domain` = 'kmx' AND `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/><small>('.$data['host'].'/'.$data['hit'].')</small>');
$q=@mysql(DBName,"SELECT * FROM `counter` WHERE `domain` = 'kmx' AND `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/><small>('.$data['host'].'/'.$data['hit'].')</small>');
#$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/><small>('.$data['host'].'/'.$data['hit'].')</small>');
print '<br/><img src="http://cnt.kmx.ru/top" alt="TOP-KMX.Ru"/></p></card></wml>';
?>