Просмотр файла includes/counters.php

Размер файла: 5.34Kb
<?php
#-----------------------------------------------------#
#          ********* ROTORCMS *********               #
#             Made by   :  VANTUZ                     #
#               E-mail  :  [email protected]         #
#                 Site  :  http://pizdec.ru           #
#             WAP-Site  :  http://visavi.net          #
#                  ICQ  :  36-44-66                   #
#  Вы не имеете право вносить изменения в код скрипта #
#        для его дальнейшего распространения          #
#-----------------------------------------------------#	
if (!defined('BASEDIR')) {
  header('Location:../index.php');
  exit;
} 

$days = floor((gmmktime(0, 0, 0, date("m"), date("d"), date("Y")) - gmmktime(0, 0, 0, 1, 1, 1970)) / 86400);
$hours = floor((gmmktime(date("H"), 0, 0, date("m"), date("d"), date("Y")) - gmmktime(4, 0, 0, 1, 1, 1970)) / 3600);

DB :: $dbh -> query("DELETE FROM `online` WHERE `online_time`<?;", array(SITETIME-600));
$newhost = 0;

if (is_user()) {
  $queryonline = DB :: $dbh -> querySingle("SELECT `online_id` FROM `online` WHERE `online_ip`=? OR `online_user`=? LIMIT 1;", array($ip, $log));
  if (empty($queryonline)) {
    DB :: $dbh -> query("INSERT DELAYED INTO `online` (`online_ip`, `online_brow`, `online_time`, `online_user`) VALUES (?, ?, ?, ?);", array($ip, $brow, SITETIME, $log));
    $newhost = 1;
  } else {
    DB :: $dbh -> query("UPDATE `online` SET `online_ip`=?, `online_brow`=?, `online_time`=?, `online_user`=? WHERE `online_id`=?;", array($ip, $brow, SITETIME, $log, $queryonline));
  } 
} else {
  $queryonline = DB :: $dbh -> querySingle("SELECT `online_id` FROM `online` WHERE `online_ip`=? LIMIT 1;", array($ip));
  if (empty($queryonline)) {
    DB :: $dbh -> query("INSERT DELAYED INTO `online` (`online_ip`, `online_brow`, `online_time`) VALUES (?, ?, ?);", array($ip, $brow, SITETIME));
    $newhost = 1;
  } else {
    DB :: $dbh -> query("UPDATE `online` SET `online_brow`=?, `online_time`=?, `online_user`=? WHERE `online_id`=?;", array($brow, SITETIME, '', $queryonline));
  } 
} 
// -----------------------------------------------------------//
$counts = DB :: $dbh -> queryFetch("SELECT * FROM `counter`;");

if ($counts['count_hours'] != $hours) {
  $queryhours = DB :: $dbh -> querySingle("SELECT `count_id` FROM `counter24` WHERE `count_hour`=? LIMIT 1;", array($hours));
  if (empty($queryhours)) {
    DB :: $dbh -> query("INSERT INTO `counter24` (`count_hour`, `count_hosts`, `count_hits`) VALUES (?, ?, ?);", array($hours, $counts['count_hosts24'], $counts['count_hits24']));
    DB :: $dbh -> query("UPDATE `counter` SET `count_hours`=?, `count_hosts24`=?, `count_hits24`=?;", array($hours, 0, 0));
    DB :: $dbh -> query("DELETE FROM `counter24` WHERE `count_hour` < (SELECT MIN(`count_hour`) FROM (SELECT `count_hour` FROM `counter24` ORDER BY `count_hour` DESC LIMIT 24) AS del);");
  } 
} 

if ($counts['count_days'] != $days) {
  $querydays = DB :: $dbh -> querySingle("SELECT `count_id` FROM `counter31` WHERE `count_days`=? LIMIT 1;", array($days));
  if (empty($querydays)) {
    DB :: $dbh -> query("INSERT INTO `counter31` (`count_days`, `count_hosts`, `count_hits`) VALUES (?, ?, ?);", array($days, $counts['count_dayhosts'], $counts['count_dayhits']));
    DB :: $dbh -> query("UPDATE `counter` SET `count_days`=?, `count_dayhosts`=?, `count_dayhits`=?;", array($days, 0, 0));
    DB :: $dbh -> query("DELETE FROM `counter31` WHERE `count_days` < (SELECT MIN(`count_days`) FROM (SELECT `count_days` FROM `counter31` ORDER BY `count_days` DESC LIMIT 31) AS del);");
  } 
} 
// -----------------------------------------------------------//
if (!empty($newhost)) {
  DB :: $dbh -> query("UPDATE `counter` SET `count_allhosts`=`count_allhosts`+1, `count_allhits`=`count_allhits`+1, `count_dayhosts`=`count_dayhosts`+1, `count_dayhits`=`count_dayhits`+1, `count_hosts24`=`count_hosts24`+1, `count_hits24`=`count_hits24`+1;");
} else {
  DB :: $dbh -> query("UPDATE `counter` SET `count_allhits`=`count_allhits`+1, `count_dayhits`=`count_dayhits`+1, `count_hits24`=`count_hits24`+1;");
} 
// -------------------------- Онлайн ------------------------------//
if ($config['onlines'] == 1) {
  $online = stats_online();
  echo '<a href="' . BASEDIR . 'pages/online.php?' . SID . '">На сайте: ' . $online[0] . '/' . $online[1] . '</a><br />';
} 
// ----------------------- Статистика ----------------------------//
if ($config['incount'] > 0) {
  $count = stats_counter();

  if ($config['incount'] == 1) {
    echo '<a href="' . BASEDIR . 'pages/counter.php?' . SID . '">' . $count['count_dayhosts'] . ' | ' . $count['count_allhosts'] . '</a><br />';
  } 
  if ($config['incount'] == 2) {
    echo '<a href="' . BASEDIR . 'pages/counter.php?' . SID . '">' . $count['count_dayhits'] . ' | ' . $count['count_allhits'] . '</a><br />';
  } 
  if ($config['incount'] == 3) {
    echo '<a href="' . BASEDIR . 'pages/counter.php?' . SID . '">' . $count['count_dayhosts'] . ' | ' . $count['count_dayhits'] . '</a><br />';
  } 
  if ($config['incount'] == 4) {
    echo '<a href="' . BASEDIR . 'pages/counter.php?' . SID . '">' . $count['count_allhosts'] . ' | ' . $count['count_allhits'] . '</a><br />';
  } 
  if ($config['incount'] == 5) {
    echo '<a href="' . BASEDIR . 'pages/counter.php?' . SID . '"><img src="' . BASEDIR . 'gallery/count.php" alt="image" /></a><br />';
  } 
} 

?>