Gossamer Forum
Home : Products : Links 2.0 : Customization :

NEW! How to put the Top10 sites on homepage, but BY NUMBER OF VISITS!

Quote Reply
NEW! How to put the Top10 sites on homepage, but BY NUMBER OF VISITS!
Hi!

As said, the most visited sites get on the Top 10 List to appear on the home page.

That is, make a list of the top 10 sites where Hits are the highest.

For example:

1 people site
(43 hits)
2 john site
(32 hits)
3 peter site
(20 hits)
4 johnny site
(2 hits)
5 leto site
(1 hit)
6 atreides site
(1 hit)

Hard, huh?

Any ideas for this NEW challenge?


------------------
Alex Tutusaus
Atyc WebDesigns
http://www.webcamworld.com/
Quote Reply
Re: NEW! How to put the Top10 sites on homepage, but BY NUMBER OF VISITS! In reply to
This would essentially be the cool page just modified a bit and pulled into the front page like we did with the top 10 (rates) page.

Just copy the build_cool_page stuff in nph-build and do like we did for the top 10 rates.
Quote Reply
Re: NEW! How to put the Top10 sites on homepage, but BY NUMBER OF VISITS! In reply to
I am working with links now for couple days, got the top 10 rates mod with ssi in my index.shtml up and running.
i tried to do the same for top 10 hits, but never got it running. i know it has to be done similar to the top 10 rate mod, but how?
iŽd need some step-by-step, sorry
Quote Reply
Re: NEW! How to put the Top10 sites on homepage, but BY NUMBER OF VISITS! In reply to
You can look at the LastLink Mod in the Resource Center as a starting point/model for putting the Top Ten Sites on your home page.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: NEW! How to put the Top10 sites on homepage, but BY NUMBER OF VISITS! In reply to
thanks eliot,
i got the lastlinks running, modified it to display the results as link, just a list of links eg.
got no clue how to go on to the topten cool/hits from that.
do i have to
Open COOL?
any help is appreciated, i am pretty new here

thx
volker
Quote Reply
Re: NEW! How to put the Top10 sites on homepage, but BY NUMBER OF VISITS! In reply to
Yes.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: NEW! How to put the Top10 sites on homepage, but BY NUMBER OF VISITS! In reply to
Eliot:
i know i am bothering you, sorry..
what has to follow open COOL to get this thing running.
i am sorry but i am really new here, i registered the software a week ago...

hope you can help

tc
volker
Quote Reply
Re: NEW! How to put the Top10 sites on homepage, but BY NUMBER OF VISITS! In reply to
i'll give you a hint..

Code:
sub build_top_5 {
my ($category) = @_;
my (@values, $top_cat, @top5, $top5html, $count);

open (DB, "<$db_file_name") or &cgierr("unable to open database: $db_file_name.\nReason: $!");
LINE: while (<DB> ) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp; # Remove trailing new line.
@values = &split_decode($_);
$top_cat = $values[$db_category];
next unless ($top_cat =~ /^$category/);
push (@top5, @values);
}

$db_sort_links = "14";
@top5 = &build_sorthit (@top5);
$db_sort_links = "1";
close DB;

$top5html = qq~<table cellpadding="0" cellspacing="0" border="0">\n~;
my $display = 5;
(($#top5+1) / ($#db_cols+1) >= 5) or $display = ($#top5+1)/($#db_cols+1);
for ($i = 0; $i < $display; $i++) {
%tmp = &array_to_hash ($i, @top5);
$count = $i+1;
$top5html .= qq~<tr><td valign="top"><$font><b>$count.</b></font> </td><td valign="top"><$font>~;
if ($tmp{'isDetailed'} eq "Yes") { $top5html .= qq~<a href="$build_detail_url/$tmp{$db_key}$build_extension"><b>$tmp{'Title'}</b></a>~; }
else { $top5html .= qq~<a href="$build_jump_url?$db_key=$tmp{$db_key}"><b>$tmp{'Title'}</b></a>~; }
$top5html .= qq~</font><br><$font_small>($tmp{'Hits'} Downloads)</font></td></tr>\n~;
}

$top5html .= qq~</table>~;

return $top5html;
}

change the first db sort links to the field number of hits.. then the second one to what it usually is.. (in links.def)

ok.. and just put that into nph-build.cgi at the bottom..

then.. you put something like this into the homepage sub..

$top5html = &build_top_5 ("Software");

which gets the top5 in the software category.. figure out the rest yourself please.. it's easy..

jerry
Quote Reply
Re: NEW! How to put the Top10 sites on homepage, but BY NUMBER OF VISITS! In reply to
Links has most of the code done.

I made a "basic" link template instead of link.html .. Then made a build routine to use that link that creates a "top ten" file based on the exsisting build top_rated subroutine.

Check the results at http://www.lit.org .. I use SSi To include it.

------------------
The Crowe crowe@charter.net
www.lit.org Links Engine for Writing on the net!



Quote Reply
Re: NEW! How to put the Top10 sites on homepage, but BY NUMBER OF VISITS! In reply to
ahh see.. i hate ssi.. that's why i don't use it Wink

heh.. also.. this mod you can get the top x of any category..

jerry
Quote Reply
Re: NEW! How to put the Top10 sites on homepage, but BY NUMBER OF VISITS! In reply to
Hey Widgets and Elliot. Where does links use the variable $build_span_pages other than in links.cfg? I'd like to have a new variable for cool pages so that cool pages won't build by date but still span if there are more than the maxhits per page.

------------------
www.webgotcha.com
[b]admin@webgotcha.com[/b]
Quote Reply
Re: NEW! How to put the Top10 sites on homepage, but BY NUMBER OF VISITS! In reply to
build span pages is used in build_category_pages and search.cgi.. i think search.cgi uses it as maxhits though..

when i started using links i did try modding the new page to span.. i got close but no cigar.. Smile soon i am going to change the new page completely so i will make it span.. plus the cool page..

jerry
Quote Reply
Re: NEW! How to put the Top10 sites on homepage, but BY NUMBER OF VISITS! In reply to
Jerry, Eliot, thanks a lot for your help.
I needed some startup-help, you provided it.
take acre
volkman
Quote Reply
Re: NEW! How to put the Top10 sites on homepage, but BY NUMBER OF VISITS! In reply to
I've gotten a couple of e-mails asking for how I did mine, so I'm posting it here.. Its VERY rough, and I can't help you with it, I just don't have the time! I'm in the middle of moving and planning my wedding ( yeah me! ) .. But I'm happy to post it and help point you in the right direction, although I like jerry's method alot as well!

This should point you guys in the right direction, and this info is posted as an aid,not a mod. I'm sure I can clean it up and stream line it.. this is DEF the long way of doing it.

Here is
one for site_html_templates.pl

Code:
sub site_html_link_cool {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.

my %rec = @_;

return &load_template ('mini_link.html', {
detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
rate_img => $rate_img,
%rec,
%globals });
}

here is the mini link template
Code:
<a class="main" href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>"><%Title%></a> <%Hits%><br>

Here is the votes template
Code:
<%top_votes_include%>

Here is the rated template
Code:
<%top_rated_include%>
Here is my build_rate_page sub in nph_build.cgi. You'll have to see
whats different, cause I don't remember what
all I changed.
Code:
sub build_rate_page {
# --------------------------------------------------------
# Creates a Top 10 ratings page.

my (@values, $id, $votes, $rate, @top_votes, %top_votes, @top_rate, %top_rate);
local ($top_rated, $top_votes);

if ($build_ratings_path =~ m,^$build_root_path/(.*)$,) {
&build_dir ($1);
}

$total = 0;

open (LINKS, $db_links_name) or &cgierr ("unable to open links database: $db_links_name. Reason: $!");
LINE: while (<LINKS> ) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp;
@values = &split_decode ($_);
$id = $values[$db_key_pos];
$votes = $values[$db_votes];
$rate = $values[$db_rating];
next if ($votes < 10);
if (($#top_votes < 9) or ($votes > $top_votes[$#top_votes])) {
push (@{$top_votes{$votes}}, @values);
if ($#top_votes <= 10) {
push (@top_votes, $votes);
@top_votes = sort { $b <=> $a } @top_votes;
}
else {
splice (@{$top_votes{$#top_votes}}, 0, $#db_cols);
$#{$top_votes{$#top_votes}} or delete $top_votes{$#top_votes};
delete $top_votes{$top_votes[$#top_votes]-$id};
$top_votes[$#top_votes] = $votes;
@top_votes = sort { $b <=> $a } @top_votes;
}
}
if (($#top_rate < 9) or ($rate > $top_rate[$#top_rate])) {
push (@{$top_rate{$rate}}, @values);
if ($#top_rate <= 10) {
push (@top_rate, $rate);
@top_rate = sort { $b <=> $a } @top_rate;
}
else {
splice (@{$top_rate{$#top_rate}}, 0, $#db_cols);
$#{$top_rate{$#top_rate}} or delete $top_rate{$#top_rate};
delete $top_rate{$top_rate[$#top_rate]-$id};
$top_rate[$#top_rate] = $rate;
@top_rate = sort { $b <=> $a } @top_rate;
}
}
}
close LINKS;

$top_rated = ''; $top_votes = '';

#rate include
$top_rated_include = ''; $top_votes_include = '';


foreach (sort { $b <=> $a } @top_votes) {
$seen{$_}++;
%link = &array_to_hash ($seen{$_} - 1, @{$top_votes{$_}});
$top_votes .= qq~<tr><td align=center>$link{'Rating'}</td><td align=center>$link{'Votes'}</td><td><a href="$link{'URL'}">$link{'Title'}</a></td></tr>\n~;

#rate include
$top_votes_include .= qq~<a class=main href="$link{'URL'}">$link{'Title'}</a> $link{'Votes'} <br> \n~;
}
foreach (sort { $b <=> $a } @top_rate) {
$seen{$_}++;
%link = &array_to_hash ($seen{$_} - 1, @{$top_rate{$_}});
$top_rated .= qq~<tr><td align=center>$link{'Rating'}</td><td align=center>$link{'Votes'}</td><td><a href="$link{'URL'}">$link{'Title'}</a></td></tr>\n~;

#rate include
$top_rated_include .= qq~<a class=main href="$link{'URL'}">$link{'Title'}</a> $link{'Rating'} <br> \n~;
}
open (RATE, ">$build_ratings_path/$build_index") or &cgierr ("unable to open top rated page: $build_ratings_path/$build_index. Reason: $!");
print "\tVote Range: $top_votes[0] .. $top_votes[$#top_votes]\n";
print "\tRate Range: $top_rate[0] .. $top_rate[$#top_rate]\n";
print RATE &site_html_ratings;
close RATE;

#rate include
open (RATE_INCLUDE, ">$build_ratings_path/rated_mini$build_extension") or &cgierr ("unable to open top rated page: $build_ratings_path/rated_mini$build_extension. Reason: $!");
print "\tRate Range: $top_rate[0] .. $top_rate[$#top_rate]\n";
print RATE_INCLUDE &site_html_ratings_include; close RATE_INCLUDE;


#vote include
open (VOTE_INCLUDE, ">$build_ratings_path/vote_mini$build_extension") or &cgierr ("unable to open top rated page: $build_ratings_path/vote_mini$build_extension. Reason: $!"); print "\tVote Range: $top_votes[0] .. $top_votes[$#top_votes]\n";
print VOTE_INCLUDE &site_html_votes_include; close VOTE_INCLUDE;
}


Add these 2 to nph_build.cgi
Code:
#Build rate mini include
sub site_html_ratings_include {
# --------------------------------------------------------
# This routine determines how the top rated page will look like.
return &load_template ( 'rated_mini.html', {
top_rated_include => $top_rated_include,
%globals
});
}


#Build vote mini include
sub site_html_votes_include {
# --------------------------------------------------------
# This routine determines how the top rated page will look like.
return &load_template ( 'vote_mini.html', {
top_votes_include => $top_votes_include,
%globals
});
}



------------------
The Crowe crowe@charter.net
www.lit.org Links Engine for Writing on the net!



Quote Reply
Re: NEW! How to put the Top10 sites on homepage, but BY NUMBER OF VISITS! In reply to
Jerry:
Your solution looks very smart and seemed to work. i integrated the sub in nph_build.cgi at the bottom. i got confused with the two $db_sort_links. as far as i understood: the first refers to a database-field to be created. i my term i defined in links.def
Counthits => [15, 'numer', 10, 10, 0, '0', '\d+']
and added
$db_counthits = 15;
and ran a little script that copies content of field 8 (hits) to 15

so the part in the sub lokks like
$db_sort_links = "15";
@top5 = &build_sorthit (@top5);
$db_sort_links = "8";

i put
$top5html = &build_top_5;
under sub build_home_page in nph_build.cgi without the category cause i want the overall top hits
and i put the correct ...=>... in site_html_templates.pl

what i get in my homepage is
Top-Links
1.
FavorStrip 1.3.1
(3 Hits)
2.
Apple Click 1.0.1
(3 Hits)
3.
Guru 2.8
(4 Hits)
4.
FileDispenser 2.0.0
(3 Hits)
5.
URLstory 1.7.1
(3 Hits)
it does not sort by hits, the listed links are in sub categories of my top-cat shareware.
i do have another top-cat tips that also has subcats with one lint that has 5 hits, this one is not even listed.
the whats cool page is listing correct.

any idea? sorry, my english is soso, hope you got the point

thanks
volker

Quote Reply
Re: NEW! How to put the Top10 sites on homepage, but BY NUMBER OF VISITS! In reply to
either you didn't do the two db_sort_links right or you need my sub build_sorthit (which is modified alot)

ok.. for the first one.. but the field number to the Hits field.. and the second one.. put the field number to the original build_sort_links.. which is in links.def

jerry
Quote Reply
Re: NEW! How to put the Top10 sites on homepage, but BY NUMBER OF VISITS! In reply to
jerry,
thanks, it is up and running now. you directed me to the point. i defined the sub as a global to have it available in all pages

thanks a lot
volkman
Quote Reply
Re: NEW! How to put the Top10 sites on homepage, but BY NUMBER OF VISITS! In reply to
when I use jerry's mod I get 503 error (server did not respond...)