Does anyone know were i can find a toplist mod that will count incoming hits??
Mar 12, 2002, 3:11 AM
Veteran / Moderator (1936 posts)
Mar 12, 2002, 3:11 AM
Post #3 of 31
Views: 7792
ewww... sorry, but that feature isn't worth $120... (plus I kind of dislike the guy that's selling Links Extended).
how about if we work this mod out.... here's the hit tracking part:
use CGI qw(:standard);
require "admin/links.cfg";
require "admin/links.def";
my %rec = &get_record(param("ID"));
if (exists $rec{ID}) {
my $old;
if (open (OLD, "admin/data/in/$rec{ID}")) {
chomp ($old = <OLD>);
close OLD;
}
open (NEW, ">admin/data/in/$rec{ID}") or die $!;
flock (NEW, 2);
print NEW ++$old;
close NEW;
}
print redirect($build_root_url);
--Philip
Links 2.0 moderator
how about if we work this mod out.... here's the hit tracking part:
Code:
#!/usr/local/bin/perl use CGI qw(:standard);
require "admin/links.cfg";
require "admin/links.def";
my %rec = &get_record(param("ID"));
if (exists $rec{ID}) {
my $old;
if (open (OLD, "admin/data/in/$rec{ID}")) {
chomp ($old = <OLD>);
close OLD;
}
open (NEW, ">admin/data/in/$rec{ID}") or die $!;
flock (NEW, 2);
print NEW ++$old;
close NEW;
}
print redirect($build_root_url);
--Philip
Links 2.0 moderator
Mar 12, 2002, 3:44 AM
Veteran / Moderator (1936 posts)
Mar 12, 2002, 3:44 AM
Post #4 of 31
Views: 7768
Also untested, but here's a program to update your links.db....
use CGI qw(:standard);
require "admin/links.def";
require "admin/links.cfg";
open (OLD, "admin/data/links.db") or die $!;
open (NEW, ">admin/data/links.db.new") or die $!;
while (<OLD>) {
my @tmp = ();
my $id = $1 if (/^\d+\|/);
my $hits = 0;
if (open (HIT, "admin/data/in/$id")) {
chomp ($hits = <HIT>);
close HIT;
unlink "admin/data/in/$id";
}
if ($hits) {
@tmp = split /\|/;
$tmp[$db_def{inHits}[0]] += $hits;
print NEW join "|", @tmp;
}
else {
print NEW;
}
}
close NEW;
close OLD;
rename("admin/data/links.db.new", "admin/data/links.db") or die $!;
You'll need to create a new field called "inHits" to %db_def and update your database accordingly.
--Philip
Links 2.0 moderator
Code:
#!/usr/local/bin/perl use CGI qw(:standard);
require "admin/links.def";
require "admin/links.cfg";
open (OLD, "admin/data/links.db") or die $!;
open (NEW, ">admin/data/links.db.new") or die $!;
while (<OLD>) {
my @tmp = ();
my $id = $1 if (/^\d+\|/);
my $hits = 0;
if (open (HIT, "admin/data/in/$id")) {
chomp ($hits = <HIT>);
close HIT;
unlink "admin/data/in/$id";
}
if ($hits) {
@tmp = split /\|/;
$tmp[$db_def{inHits}[0]] += $hits;
print NEW join "|", @tmp;
}
else {
print NEW;
}
}
close NEW;
close OLD;
rename("admin/data/links.db.new", "admin/data/links.db") or die $!;
You'll need to create a new field called "inHits" to %db_def and update your database accordingly.
--Philip
Links 2.0 moderator
Last edited by:
King Junko II: Mar 12, 2002, 3:46 AM
Mar 12, 2002, 9:04 AM
Novice (34 posts)
Mar 12, 2002, 9:04 AM
Post #6 of 31
Views: 7754
ok even i got this f***** exams, i've tried.....
I've added inHits fields in my database, created a directory : admin/data/in....
Updated my links.db so there's no corruption inside...
And ran your file which I called top.cgi
When I ran it i've got an 500 Error Message, with perl on telnet here's what I got :
[root@pulsarX links]$ perl top.cgi
Undefined subroutine &main::get_record called at top.cgi line 6.
Any ideas ?
Thx, but I'm a perl sucker....
I've added inHits fields in my database, created a directory : admin/data/in....
Updated my links.db so there's no corruption inside...
And ran your file which I called top.cgi
When I ran it i've got an 500 Error Message, with perl on telnet here's what I got :
[root@pulsarX links]$ perl top.cgi
Undefined subroutine &main::get_record called at top.cgi line 6.
Any ideas ?
Thx, but I'm a perl sucker....
Mar 12, 2002, 10:17 AM
Novice (26 posts)
Mar 12, 2002, 10:17 AM
Post #8 of 31
Views: 7757
sorry i am new at this but i have got all my other mods up and working. Please bear with me......what do i call the hit tracking part or were do i put it. Also dido with the program to update links db, what do i name and or do i add it to a file allready with links?
Thanks a milllion
jamie
Thanks a milllion
jamie
Mar 12, 2002, 10:27 AM
Novice (34 posts)
Mar 12, 2002, 10:27 AM
Post #9 of 31
Views: 7796
ok it works fine now :)
thx you guys
Incrementing is ok, in my data/in directory i've got new files (with id numbers) inside, so the script top.cgi is working....
But what should I put (in the build script i think), to make it work...so the script reads info in data/in like in data/rates....and insert value in inHits so I can make it works out....
thx you guys
Incrementing is ok, in my data/in directory i've got new files (with id numbers) inside, so the script top.cgi is working....
But what should I put (in the build script i think), to make it work...so the script reads info in data/in like in data/rates....and insert value in inHits so I can make it works out....
Mar 12, 2002, 12:22 PM
Novice (34 posts)
Mar 12, 2002, 12:22 PM
Post #11 of 31
Views: 7761
i think my problem is in nph-build.cgi....
I should try something like that
sub build_update_newpop {
# --------------------------------------------------------
# This routines updates the database, and marks new records new,
# old records old, popular records popular, and unpopular records,
# unpopular.
my ($id, %hits, @values, $days, @popular, $cutoff);
# Let's collect how many hits we've gotten.
opendir (HITS, $db_hits_path) or &cgierr ("unable to open hits directory: $db_hits_path. Reason: $!");
while (defined ($id = readdir HITS)) {
next unless ($id =~ /^\d+$/);
open (HIT, "$db_hits_path/$id") or &cgierr ("unable to open hit counter: $db_hits_path/$id. Reason: $!");
$hits{$id} = int <HIT>;
close HIT;
}
closedir HITS;
Something like that but........I'm scared about making an error
I should try something like that
sub build_update_newpop {
# --------------------------------------------------------
# This routines updates the database, and marks new records new,
# old records old, popular records popular, and unpopular records,
# unpopular.
my ($id, %hits, @values, $days, @popular, $cutoff);
# Let's collect how many hits we've gotten.
opendir (HITS, $db_hits_path) or &cgierr ("unable to open hits directory: $db_hits_path. Reason: $!");
while (defined ($id = readdir HITS)) {
next unless ($id =~ /^\d+$/);
open (HIT, "$db_hits_path/$id") or &cgierr ("unable to open hit counter: $db_hits_path/$id. Reason: $!");
$hits{$id} = int <HIT>;
close HIT;
}
closedir HITS;
Something like that but........I'm scared about making an error
Mar 12, 2002, 12:31 PM
Veteran / Moderator (1936 posts)
Mar 12, 2002, 12:31 PM
Post #12 of 31
Views: 7743
Mar 12, 2002, 1:19 PM
Novice (34 posts)
Mar 12, 2002, 1:19 PM
Post #13 of 31
Views: 7722
ok sorry I haven't make the link....
But your script doesn"t seem to work...
If I launch it i got an 500 error, but seems to work under Telnet
[fr@ftp admin]$ perl inhits.cgi
[fr@ftp admin]$
doesn't give any errors...
weird....
But anyway, this doesn"t modify my links.db, it creates a links.db.new file, but this file is neither updated whereas the data/in/ directory / files are working properly
thx for your help :)
But your script doesn"t seem to work...
If I launch it i got an 500 error, but seems to work under Telnet
[fr@ftp admin]$ perl inhits.cgi
[fr@ftp admin]$
doesn't give any errors...
weird....
But anyway, this doesn"t modify my links.db, it creates a links.db.new file, but this file is neither updated whereas the data/in/ directory / files are working properly
thx for your help :)
Mar 12, 2002, 10:21 PM
Novice (34 posts)
Mar 12, 2002, 10:21 PM
Post #16 of 31
Views: 7715
yeah of course I did it but the link
http://dbink.hostingcheck.com/incoming.html
no more exists, I contacted the author, and nothing.....
If you have the original page / zip, I would be pleased :)
http://dbink.hostingcheck.com/incoming.html
no more exists, I contacted the author, and nothing.....
If you have the original page / zip, I would be pleased :)
Mar 13, 2002, 2:24 AM
Veteran / Moderator (1936 posts)
Mar 13, 2002, 2:24 AM
Post #17 of 31
Views: 7701
ah, come on... I'm having fun with this :-) I made a short program to generate a test database of link ID's and hits...
open (DB, ">hit.db");
foreach (1 .. 100) {
print DB "$_|" . $num[rand @num] . "\n";
}
close DB;
Then wrote this to grab the top ten and print it out:
use CGI qw(:standard);
use strict;
my $top = [];
open (DB, "hit.db");
while (<DB>) {
chomp;
my ($id, $hits) = split /\|/;
if (scalar @$top < 10) {
push @$top, [$id, $hits];
}
else {
foreach (@$top) {
if ($hits >= $_->[1]) {
$top->[0] = [$id, $hits];
@$top = sort { $a->[1] <=> $b->[1] } @$top;
last;
}
}
}
}
close DB;
my $i = 1;
print header,
start_html("top ten referers"),
table (
{-border=>1, -cellpadding=>3, -cellspacing=>0},
Tr(
th( [qw(Rank ID Hits)] )
),
map {
Tr(
td( {-width=>20}, [$i++, @$_] )
)
} sort { $b->[1] <=> $a->[1] } @$top,
),
end_html;
Hope you don't mind the CGI.pm HTML syntax :-/ it's the first time I've ever really used it.
--Philip
Links 2.0 moderator
Code:
@num = (0 .. 100); open (DB, ">hit.db");
foreach (1 .. 100) {
print DB "$_|" . $num[rand @num] . "\n";
}
close DB;
Then wrote this to grab the top ten and print it out:
Code:
#!/perl/bin/perl use CGI qw(:standard);
use strict;
my $top = [];
open (DB, "hit.db");
while (<DB>) {
chomp;
my ($id, $hits) = split /\|/;
if (scalar @$top < 10) {
push @$top, [$id, $hits];
}
else {
foreach (@$top) {
if ($hits >= $_->[1]) {
$top->[0] = [$id, $hits];
@$top = sort { $a->[1] <=> $b->[1] } @$top;
last;
}
}
}
}
close DB;
my $i = 1;
print header,
start_html("top ten referers"),
table (
{-border=>1, -cellpadding=>3, -cellspacing=>0},
Tr(
th( [qw(Rank ID Hits)] )
),
map {
Tr(
td( {-width=>20}, [$i++, @$_] )
)
} sort { $b->[1] <=> $a->[1] } @$top,
),
end_html;
Hope you don't mind the CGI.pm HTML syntax :-/ it's the first time I've ever really used it.
--Philip
Links 2.0 moderator
Last edited by:
King Junko II: Mar 13, 2002, 2:34 AM
Mar 13, 2002, 3:55 AM
Veteran / Moderator (1936 posts)
Mar 13, 2002, 3:55 AM
Post #19 of 31
Views: 7704
try changing:
To:
If that doesn't work, replace everything inside $tmp[] with the field position of the inHits field (first part of the array ref...).
Also the script should be run from inside the admin directory, so you need to edit the require lines if you hadn't already. Paul pointed out that db_utils also needs to be required...
this is pretty cool... I was able to tweak the codes to also print out the top 10 worst referers.
--Philip
Links 2.0 moderator
Code:
$tmp[$db_def{inHits}[0]] += $hits;To:
Code:
$tmp[${$db_def{inHits}}[0]] += $hits;If that doesn't work, replace everything inside $tmp[] with the field position of the inHits field (first part of the array ref...).
Also the script should be run from inside the admin directory, so you need to edit the require lines if you hadn't already. Paul pointed out that db_utils also needs to be required...
this is pretty cool... I was able to tweak the codes to also print out the top 10 worst referers.
--Philip
Links 2.0 moderator
Mar 13, 2002, 5:13 AM
Veteran / Moderator (1936 posts)
Mar 13, 2002, 5:13 AM
Post #21 of 31
Views: 7689
What's the problem with that? Everyone knows you need to edit that anyway (I hope).
There's also a slight bug... that unnoticable unless you print out the top 10 worst referers, and there are less than 20 records total. the bug is fixed in the attachement.
--Philip
Links 2.0 moderator
There's also a slight bug... that unnoticable unless you print out the top 10 worst referers, and there are less than 20 records total. the bug is fixed in the attachement.
--Philip
Links 2.0 moderator
Mar 15, 2002, 8:41 AM
Novice (34 posts)
Mar 15, 2002, 8:41 AM
Post #23 of 31
Views: 7662
grrr....2 days i'm on it, and still doesn't work....
here's a copy of my links.def
#
# This script is not freeware! Please read the README for full details
# on registration and terms of use.
# =====================================================================
# Database Definition: LINKS
# --------------------------------------------------------
# Definition of your database file.
%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
Title => [1, 'alpha', 40, 75, 1, '', ''],
URL => [2, 'alpha', 40, 75, 1, 'http://', '^http|news|mailto|ftp'],
Date => [3, 'date', 15, 15, 1, \&get_date, ''],
Category => [4, 'alpha', 0, 150, 1, '', ''],
Description => [5, 'alpha', '40x3', 500, 0, '', ''],
'Contact Name' => [6, 'alpha', 40, 75, 1, '', ''],
'Contact Email' => [7, 'alpha', 40, 75, 1, '', '.+@.+\..+'],
Hits => [8, 'numer', 10, 10, 1, '0', '\d+'],
isNew => [9, 'alpha', 0, 5, 0, 'No', ''],
isPopular => [10, 'alpha', 0, 5, 0, 'No', ''],
Rating => [11, 'numer', 10, 10, 1, 0, '^[\d\.]+$'],
Votes => [12, 'numer', 10, 10, 1, 0, '^\d+$'],
ReceiveMail => [13, 'alpha', 10, 10, 1, 'Yes', 'No|Yes'],
inHits => [14, 'numer', 10, 10, 1, '0', '\d+']
);
# Database file to use -- defined in links.cfg.
$db_file_name = $db_links_name;
# Counter file to use -- defined in links.cfg.
$db_id_file_name = $db_links_id_file_name;
# The column name for the database key.
$db_key = 'ID';
# Database delimeter.
$db_delim = '|';
# Title used in admin output.
$html_title = '123Gratuit';
$html_object = '123Gratuit';
# Field Number of some important fields. The number is from %db_def above
# where the first field equals 0.
$db_category = 4; $db_modified = 3; $db_url = 2;
$db_hits = 8; $db_isnew = 9; $db_ispop = 10;
$db_contact_name = 6; $db_contact_email = 7; $db_title = 1;
$db_votes = 12; $db_rating = 11; $db_mail = 13;
$db_inHits = 14;
# Field number to sort links by:
$db_sort_links = 1;
# Field names you want to allow visitors to search on:
@search_fields = (1,2,5);
# System defaults. When adding new links or modifying links, these fields
# can not be overwritten by a user.
%add_system_fields = (
isNew => 'No',
isPopular => 'No',
Hits => '0',
Rating => 0,
Votes => 0,
ReceiveMail => 'Yes',
inHits => '0'
);
# Hash of column names to possible options. If you want to use a select form
# field, you can use &build_select_field in your HTML page. This routine will
# make a <SELECT> input tag using the following values:
%db_select_fields = (
isNew => 'Yes,No',
isPopular => 'Yes,No',
ReceiveMail => 'Yes,No'
);
# Hash of column names to radio values. If you use &build_radio_field, it will
# make a <INPUT TYPE="RADIO"> tag for you using the options specified in the hash.
%db_radio_fields = ( );
# Maximum number of hits returned in a search. Can be overridden in the search
# options.
$db_max_hits = 10;
# Use the built in key tracker.
$db_key_track = 1;
any errors out there ?
here's a copy of my links.def
#
# This script is not freeware! Please read the README for full details
# on registration and terms of use.
# =====================================================================
# Database Definition: LINKS
# --------------------------------------------------------
# Definition of your database file.
%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
Title => [1, 'alpha', 40, 75, 1, '', ''],
URL => [2, 'alpha', 40, 75, 1, 'http://', '^http|news|mailto|ftp'],
Date => [3, 'date', 15, 15, 1, \&get_date, ''],
Category => [4, 'alpha', 0, 150, 1, '', ''],
Description => [5, 'alpha', '40x3', 500, 0, '', ''],
'Contact Name' => [6, 'alpha', 40, 75, 1, '', ''],
'Contact Email' => [7, 'alpha', 40, 75, 1, '', '.+@.+\..+'],
Hits => [8, 'numer', 10, 10, 1, '0', '\d+'],
isNew => [9, 'alpha', 0, 5, 0, 'No', ''],
isPopular => [10, 'alpha', 0, 5, 0, 'No', ''],
Rating => [11, 'numer', 10, 10, 1, 0, '^[\d\.]+$'],
Votes => [12, 'numer', 10, 10, 1, 0, '^\d+$'],
ReceiveMail => [13, 'alpha', 10, 10, 1, 'Yes', 'No|Yes'],
inHits => [14, 'numer', 10, 10, 1, '0', '\d+']
);
# Database file to use -- defined in links.cfg.
$db_file_name = $db_links_name;
# Counter file to use -- defined in links.cfg.
$db_id_file_name = $db_links_id_file_name;
# The column name for the database key.
$db_key = 'ID';
# Database delimeter.
$db_delim = '|';
# Title used in admin output.
$html_title = '123Gratuit';
$html_object = '123Gratuit';
# Field Number of some important fields. The number is from %db_def above
# where the first field equals 0.
$db_category = 4; $db_modified = 3; $db_url = 2;
$db_hits = 8; $db_isnew = 9; $db_ispop = 10;
$db_contact_name = 6; $db_contact_email = 7; $db_title = 1;
$db_votes = 12; $db_rating = 11; $db_mail = 13;
$db_inHits = 14;
# Field number to sort links by:
$db_sort_links = 1;
# Field names you want to allow visitors to search on:
@search_fields = (1,2,5);
# System defaults. When adding new links or modifying links, these fields
# can not be overwritten by a user.
%add_system_fields = (
isNew => 'No',
isPopular => 'No',
Hits => '0',
Rating => 0,
Votes => 0,
ReceiveMail => 'Yes',
inHits => '0'
);
# Hash of column names to possible options. If you want to use a select form
# field, you can use &build_select_field in your HTML page. This routine will
# make a <SELECT> input tag using the following values:
%db_select_fields = (
isNew => 'Yes,No',
isPopular => 'Yes,No',
ReceiveMail => 'Yes,No'
);
# Hash of column names to radio values. If you use &build_radio_field, it will
# make a <INPUT TYPE="RADIO"> tag for you using the options specified in the hash.
%db_radio_fields = ( );
# Maximum number of hits returned in a search. Can be overridden in the search
# options.
$db_max_hits = 10;
# Use the built in key tracker.
$db_key_track = 1;
any errors out there ?
Mar 15, 2002, 9:25 AM
Novice (34 posts)
Mar 15, 2002, 9:25 AM
Post #24 of 31
Views: 7624
and here's the file corresponding i called inhits.cgi
use CGI qw(:standard);
require "/home/fr/cgi-bin/123gratuit/admin/links.def";
require "/home/fr/cgi-bin/123gratuit/admin/links.cfg";
require "/home/fr/cgi-bin/123gratuit/admin/db_utils.pl";
open (OLD, "/home/fr/cgi-bin/123gratuit/admin/data/links.db") or die $!;
open (NEW, ">/home/fr/cgi-bin/123gratuit/admin/data/links.db.new") or die $!;
while (<OLD>) {
my @tmp = ();
my $id = $1 if (/^\d+\|/);
my $hits = 0;
if (open (HIT, "/home/fr/cgi-bin/123gratuit/admin/data/in/$id")) {
chomp ($hits = <HIT>);
close HIT;
unlink "/home/fr/cgi-bin/123gratuit/admin/data/in/$id";
}
if ($hits) {
@tmp = split /\|/;
$tmp[14] += $hits;
print NEW join "|", @tmp;
}
else {
print NEW;
}
}
close NEW;
close OLD;
rename("/home/fr/cgi-bin/123gratuit/admin/data/links.db.new", "/home/fr/cgi-bin/123gratuit/admin/data/links.db") or die $!;
use CGI qw(:standard);
require "/home/fr/cgi-bin/123gratuit/admin/links.def";
require "/home/fr/cgi-bin/123gratuit/admin/links.cfg";
require "/home/fr/cgi-bin/123gratuit/admin/db_utils.pl";
open (OLD, "/home/fr/cgi-bin/123gratuit/admin/data/links.db") or die $!;
open (NEW, ">/home/fr/cgi-bin/123gratuit/admin/data/links.db.new") or die $!;
while (<OLD>) {
my @tmp = ();
my $id = $1 if (/^\d+\|/);
my $hits = 0;
if (open (HIT, "/home/fr/cgi-bin/123gratuit/admin/data/in/$id")) {
chomp ($hits = <HIT>);
close HIT;
unlink "/home/fr/cgi-bin/123gratuit/admin/data/in/$id";
}
if ($hits) {
@tmp = split /\|/;
$tmp[14] += $hits;
print NEW join "|", @tmp;
}
else {
print NEW;
}
}
close NEW;
close OLD;
rename("/home/fr/cgi-bin/123gratuit/admin/data/links.db.new", "/home/fr/cgi-bin/123gratuit/admin/data/links.db") or die $!;