<?php
/*
======================================================
 created by ko1yan... icq: 380119
------------------------------------------------------
 email: konohoff@gmail.com
 site:  www.dangels.net.ru
------------------------------------------------------
 Сopyright (c) ko1yan
======================================================
 Данный код защищен авторскими правами
======================================================
 Файл: refermod.php
------------------------------------------------------
 Назначение: Определение и добавление в базу рефералов
             Вывод последних рефералов для блока.
======================================================
*/
if(!defined('DATALIFEENGINE')) {
  die("Hacking attempt! created by ko1yan");
 }
include ROOT_DIR.'/engine/data/refer.txt';
$myurl = "";
if($func_myurl != 0){
$myurl = $_SERVER['REQUEST_URI'];
}
$ttime = time();
if ($_SERVER['REMOTE_ADDR']) $ip = $_SERVER['REMOTE_ADDR'];
 else $ip = "0";
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : getenv("http_referer");
$hurl = str_replace("http://", "", $config['http_home_url']);
$hurl = str_replace("www.", "", $hurl);
$hurl = explode("/", $hurl);
$hurl = reset($hurl);
$refurl = str_replace("www.", "", $referer);
$dom = parse_url("$refurl");
$host = $dom['host'];
if ($host == "google.") { $host = "google"; }
if (!eregi($hurl, $referer) and trim( $referer ) != "" ) {
    $refexist = $db->super_query("SELECT COUNT(*) as count FROM ".PREFIX."_referer WHERE url='".htmlspecialchars(mysql_escape_string($refurl))."'");
    if ($refexist['count'] > 0)
    {
      $db->query("UPDATE ".PREFIX."_referer SET hits=hits+1, date='$ttime', myurl='$myurl', lastip='$ip', host='$host' WHERE url='".htmlspecialchars(mysql_escape_string($refurl))."'");
    }
    else
    {
      $db->query("INSERT INTO ".PREFIX."_referer (url, date, hits, lastip, host, myurl) VALUES ('".htmlspecialchars(mysql_escape_string($refurl))."', '$ttime', '1', '$ip', '$host', '$myurl')");
    }
}
$referscount = $db->super_query("SELECT COUNT(*) as count FROM ".PREFIX."_referer");
    if ($referscount['count'] >= $max_ref)
    {
      $db->query("TRUNCATE TABLE ".PREFIX."_referer");
    }
$result = $db->query("SELECT * FROM ".PREFIX."_referer ORDER BY date DESC LIMIT 0,$block_ref"); 
 while ($row = $db->get_row($result)) {

   $url = $row['url'];
   $hits = $row['hits'];
   $name = str_replace("http://", "", $url);
   $mini = substr($name, 0, $block_link);
		    	if (strlen($mini) == $block_link)
		    	{
		    		$mini .= '...';
	   	} 
 $refer .= "<li><a href='$url' target='_blank' title='Переходов: $hits'>$mini</a>";
}
?>