Description:
records the referer for referer_view to display - helps you track who's linking in
Box Code:
## START referer_catch ##
# This box collects referer information but
# doesn't actually output anything visible. Place
# on every page template if you want to find out
# who's linking to any page. If the referer is
# from within the site, it is ignored
# To use this box, you must create a table in the
# database named "referer"
# with the following SQL command:
#
# CREATE TABLE referer (
# url varchar(255),
# hits int(10) DEFAULT 0,
# INDEX (url)
# );
#
my $sitename = $S->{UI}->{VARS}->{site_url};
my $raw_referer = $S->{REFERER};
unless ( $raw_referer ) {
$raw_referer = "-";
}
# keep things clean; we only want referers you
# *don't* know about
return if ( $raw_referer =~ /$sitename/i );
my $referer = $S->{DBH}->quote($raw_referer);
# check if that URL is already in the db
my ($rv, $sth) = $S->db_select({
WHAT => 'count(url) AS num',
FROM => 'referer',
WHERE => "url = $referer"
});
my $dbresponse = $sth->fetchrow_hashref();
my $url_exists = $dbresponse->{num};
# count the URL
if ( $url_exists ) {
($rv, $sth) = $S->db_update({
WHAT => 'referer',
SET => 'hits = hits + 1',
WHERE => "url = $referer"
});
} else {
$S->db_insert({ INTO => 'referer',
COLS => 'url, hits',
VALUES => "$referer, 1"
});
}
return;
## END referer_catch ##
|