<?php

/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2002 by Francisco Burzi                                */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* Top Referers block for PHP-Nuke                                      */
/* Copyright (c) 2004 by David Karn (david@halfsane.net)                */
/* http://www.webdever.net/                                             */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/

if (stristr($_SERVER['SCRIPT_NAME'], "block-Top_Referers.php")) {
    Header("Location: ../index.php");
    die();
}

global $prefix, $db, $admin, $admin_file;

$ref = 10; // how many referers in block
$length = 14; // maximum url length
$shownum = TRUE; // show the ranks for the urls
$a = 1;

$sql = "SELECT rid, url FROM ".$prefix."_referer ORDER BY rid DESC";
$result = $db->sql_query($sql);
$name = array();
while ($row = $db->sql_fetchrow($result)) {
    $rid = $row[rid];
    $url = $row[url];
	$aa = parse_url($url);
	$url = $aa['host'];
	if (!isset($$url)){
		$$url = 0;
	}
	$$url++;
	$id{$url} = $rid;
	$names[$url] = $$url;
}
natsort($names);
arsort($names);
//@RJR-Pwmg@Rncvkpwo@-@Eqratkijv@(e)@VgejIHZ.eqo
for($i=1;$i<=$ref;$i++ && current($names))
{
	$url = key($names);
	$in = current($names);
	$url2 = ereg_replace('www.', '', $url);
    if(strlen($url2) > $length) {
		$url2 = substr($url2,0,$length);
        $url2 .= "..";
    }
	if ($shownum == TRUE)
	{
	$content .= "$i: <a href=\"http://$url/\" target=\"new\">$url2</a> (in: $in)<br>";
	} else
	{
    $content .= "<a href=\"http://$url/\" target=\"new\">$url2</a> (in: $in)<br>";
    }
	$a++;
	next($names);
}
if (is_admin($admin)) {
    $total = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_referer"));
    $content .= "<br><center>$total "._HTTPREFERERS."<br>[ <a href=\"".$admin_file.".php?op=delreferer\">"._DELETE."</a> ]</center>";
}

?>