/*
* History (admun):
* 0.90 initial version
* 0.91 Added the possibility to call pop,10 to show the most populair pages
* Minor bugfixes for htmlspecialchars
* Added substr to trim the line. Internet Explorer makes long lines instead of braking them
* 0.92 Added timeoffset functionality to refWhen ...
* 0.93 Added three display options (needs reinstallation!)
* Bugfixes and another calling option; lastall
* Added "-" on each refer
* 0.94 use sql_table, add supportFeature
* 0.95 add rel="nofollow"
* 0.96 trim the line to other display mode
*
* Start of Referer2 by pdreker: 04.03.2004
* History: 0.10 initial version based on referer 0.93 by -=Xiffy=-
* Main Differences:
* - uses textarea for list options, because this is a lot more readable and has no length
* restrictions. List are not comma separated any more, but newline separated (i.e. one
* entry per line)
* - minor grammar and speling fixes. Clarified how the options have to be entered.
* - uses sql_table() instead of hardcoded table name.
* - IP banning supports CIDR notation (e.g. 192.168.1.0/24 to block all IPs in 192.168.1.0-255)
* - different defaults for
insertion and display of referer time (exactly the other way
* around).
* - added on option to automagically clean the referer DB table. This means, after you save the
* options the domain bans will be applied to the database. This comes in handy, if a new
* d*ckhead came along sprinkling p0rn links on your site: just add the domain to the ban
* list, and if the option is checked the entries will be removed from the DB, so they don't
* show up any more. WARNING: it is rather easy to shoot yourself in the foot, if you enter a
* too wide ban (e.g. entering "x" as a ban will remove all referers with "x" in their domain
* name... NO FURTHER QUESTIONS ASKED!
* 0.11 small maintenance release
* - changed the "lastall" target to look like all others (no table anymore). The old target
* was moved to "lastalltable"
* 0.12 bugfix release (a.k.a. getting quick release)
* - fixed a warning with empty blocklist or search engine list.
* - fixed a typo in search engine handling which prevented search engines from being
* recognized properly
* 0.13 bugfix release (a.k.a. "Dont kill the referrer table")
* - fixed a stupid oversight, which might delete all referrers from the DB table
* if you had an empty entry there (yielded DELETE FROM .... WHERE ... LIKE "%%", which matches
* every entry...)
*/
// to make this plugin works on Nucleus versions <=2.0 as well
if (!function_exists('sql_table'))
{
function sql_table($name) { return 'nucleus_' . $name; }
}
class NP_Referer2 extends NucleusPlugin {
function cidrCheck($ip_address, $cidr_address) {
$first = substr($cidr_address, 0, strpos($cidr_address, "/"));
$netmask = substr(strstr($cidr_address, "/"), 1);
$first_bin = str_pad(decbin(ip2long($first)), 32, "0", STR_PAD_LEFT);
$ip_bin = str_pad(decbin(ip2long($ip_address)), 32, "0", STR_PAD_LEFT);
$netmask_bin = str_pad(str_repeat("1", (integer)$netmask), 32, "0", STR_PAD_RIGHT);
// check: if (ip & mask) == first -> match
// "compute" the "&"
for($i = 0; $i<32; $i++) {
if ($netmask_bin[$i] == "1") {
$check_bin .= $ip_bin[$i];
} else {
$check_bin .= "0";
}
}
$result = (strcmp($check_bin, $first_bin) == 0);
return $result;
}
function supportsFeature($feature) {
switch($feature) {
case 'SqlTablePrefix':
return 1;
default:
return 0;
}
}
function getEventList() { return array('PostPluginOptionsUpdate'); }
function event_PostPluginOptionsUpdate($data) {
if ($data['context'] != 'global') return;
if ($data['plugid'] != $this->GetID()) return;
// if we get here we have just saved our own options
$cleanDB = $this->getOption('cleanDB');
if($cleanDB == 'yes') {
$query = "DELETE FROM " . sql_table('plug_referer2') . " WHERE ";
$filterlist = explode("\n",$this->getOption(blockDomain));
$gotone = false;
foreach($filterlist as $block) {
$block = rtrim($block);
if($block != "") {
$query .= "ref_from LIKE '%$block%' OR ";
$gotone = true;
}
}
// remove last "OR "
$query = substr($query, 0, -4);
// echo $query; // chicken ;-)
if($gotone) mysql_query($query); // only do query if we really found something to clean
// clear the option again
if($this->getOption('autoResetCleanDB') == 'yes') {
$this->setOption('cleanDB', 'no');
}
}
}
function doSkinVar($skintype, $what='last', $amount=10) {
global $manager;
global $blog;
global $CONF;
global $HTTP_REFERER;
global $HTTP_HOST;
$table_name = sql_table("plug_referer2");
$logtime = time();
$refer = $_SERVER['HTTP_REFERER']; //ED$ $HTTP_REFERER;
$parsed = parse_url($refer);
$refParts = explode("/", $refer);
if ($_SERVER['QUERY_STRING']) {
$pageRef = $_SERVER['PHP_SELF']."_".$_SERVER['QUERY_STRING'];
} else {
$pageRef = $_SERVER['PHP_SELF'];
}
// see if we need to block this referer
if ($parsed[scheme] != "http") { $refer = ""; }
// not local please ...
// ED$ if ($parsed[host] == $HTTP_HOST ) { $refer = ""; }
if ($parsed[host] == $_SERVER['HTTP_HOST'] ) { $refer = ""; }
$filterip = explode("\n",$this->getOption(blockIp));
$filterlist = explode("\n",$this->getOption(blockDomain));
$searchengines = explode("\n",$this->getOption(searchengines));
$addbreaks = $this->getOption(addBR);
$maxlength = $this->getOption(maxlength);
$showtime = $this->getOption(showDateTime);
// ignore filtered domains
foreach($filterip as $block) {
if(strstr($block, "/")) {
// CIDR notation
$block = rtrim($block);
if($this->cidrCheck($_SERVER['REMOTE_ADDR'], $block)) {
$refer = "";
}
} else {
// Single IP Address
$block = rtrim($block);
if ($block != "" && strstr($_SERVER['REMOTE_ADDR'], $block)) {
$refer = "";
}
}
}
foreach($filterlist as $block) {
$block = rtrim($block);
if ($block != "" && strstr($parsed[host],$block)) {
$refer = "";
}
}
// searxch engine ??
foreach($searchengines as $engine ) {
$engine = rtrim($engine);
if ($engine != "" && strstr($parsed[host],$engine)) {
$extra = $parsed[query]; // searchwords used ....
}
}
// if we didn't block this, let's put it in the db ....
// and if this is the first time we were called then ...
if ($refer && !$this->count == 1) {
if (! $extra) {
// find the page title ...
$fp = @fopen ($refer, "r");
if ($fp){
$ref_str = fread($fp, 4096);
if (eregi("
"; echo "- refFrom)."\" rel=\"nofollow\">".strftime("%e/%m/%g - %R",$ref->refWhen + (0 * 3600))." ".stripslashes($ref->refShow).""; //echo " | "; $linktxt = substr($ref->refTo,strpos($ref->refTo,"?") + 1); if( strpos($linktxt,"temid") > 0 ) { $citemid = substr($linktxt,strpos($linktxt,"itemid=") + 7); if ( strpos($citemid,"&") > 0) { $citemid = substr($citemid,0, strpos($citemid,"&")); } $titleq = "SELECT ititle FROM ".sql_table('item')." WHERE inumber = ". $citemid; $result = mysql_query($titleq); $row = mysql_fetch_object($result); if (! $row->ititle == "") { $linktxt = $row->ititle; } else { $linktxt = $citemid . "-" .$linktxt; } } echo "refTo)."\" rel=\"nofollow\"> -> ".$linktxt.""; echo " |