Gossamer Forum
Home : Products : Links 2.0 : Customization :

Toplist mod??

(Page 1 of 2)
> >
Quote Reply
Toplist mod??
Does anyone know were i can find a toplist mod that will count incoming hits??
Quote Reply
Re: [jamies] Toplist mod?? In reply to
it's been a month since i've been asking this....

grrr....

I'm gonna buy Links Extended but 120$ just for this function.....grrr
Quote Reply
Re: [numeric] Toplist mod?? In reply to
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:

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
Quote Reply
Re: [King Junko II] Toplist mod?? In reply to
Also untested, but here's a program to update your links.db....
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
Quote Reply
Re: [King Junko II] Toplist mod?? In reply to
thx a lot :)

you've saved me 120$ :lol:

i can't test it this day nor tomorrow, because i'm full of EXAMS, right now....

but thx again....Cool

to create a new field it's the only thing i need to do ?
Quote Reply
Re: [numeric] Toplist mod?? In reply to
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....
Quote Reply
Re: [numeric] Toplist mod?? In reply to
Add:

require "admin/db_utils.pl";
Quote Reply
Re: [King Junko II] Toplist mod?? In reply to
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
Quote Reply
Re: [RedRum] Toplist mod?? In reply to
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....
Quote Reply
Re: [jamies] Toplist mod?? In reply to
you have to copy/paste the codes above and name it yourfilename1.cgi yourfilename2.cgi
Quote Reply
Re: [numeric] Toplist mod?? In reply to
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
Quote Reply
Re: [numeric] Toplist mod?? In reply to
That's what the second routine I posted above does, except it gets the value, deletes old hit file, and updates the links record all in one process. The only thing left is to make a routine to build the inHits page.

--Philip
Links 2.0 moderator
Quote Reply
Re: [King Junko II] Toplist mod?? In reply to
ok sorry I haven't make the link....Tongue

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 :) ShockedSly
Quote Reply
Re: [King Junko II] Toplist mod?? In reply to
You want to install this mod for me....i will pay...or does anyone else....
Quote Reply
Re: [jamies] Toplist mod?? In reply to
search for INHITS mod

------------------------------------------
Quote Reply
Re: [DogTags] Toplist mod?? In reply to
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 :)
Quote Reply
Re: [DogTags] Toplist mod?? In reply to
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...

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
Quote Reply
Re: [King Junko II] Toplist mod?? In reply to
ok thats cool thx again, i'll try :)

but i stil have a real problem, which is that the second of the first scripts doesn't work, it doesn't increment my links.db with inHits field, it stays to 0 whereas the data/in/$id file is working....
Quote Reply
Re: [numeric] Toplist mod?? In reply to
try changing:
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
Quote Reply
Re: [King Junko II] Toplist mod?? In reply to
Remeber you left the windows perl path in there :)
Quote Reply
Re: [RedRum] Toplist mod?? In reply to
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
Quote Reply
Re: [King Junko II] Toplist mod?? In reply to
Not a problem, just pointing it out incase anyone didn't notice.

Last edited by:

RedRum: Mar 13, 2002, 5:56 AM
Quote Reply
Re: [Paul] Toplist mod?? In reply to
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 ?

Last edited by:

numeric: Mar 15, 2002, 8:42 AM
Quote Reply
Re: [numeric] Toplist mod?? In reply to
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 $!;

Quote Reply
Re: [numeric] Toplist mod?? In reply to
Did the forum screw that up or...?

'Contact Email' => [7, 'alpha', 40, 75, 1, '', '.+@.+\..+'],

Last edited by:

Paul: Mar 15, 2002, 11:22 AM
> >