Gossamer Forum
Home : Products : Links 2.0 : Customization :

Top Rated Links

Quote Reply
Top Rated Links
Hi

Im looking for a solution, to show links in the category sorted by
new - top rated - popular - and the rest alphabetical

I can not find something like that :-(

A small gif like the pop gif on popular links for the top rated links would be nice too ;-)

Thanks
Matthias

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] Top Rated Links first In reply to
After searching and experimenting for hours I found a solution

I changed in links.def
$db_sort_links = 1;
to
$db_sort_links = 11; (11=rating field)

and here are the changes (red) in sub_build_sorthit in db_utils.pl
Code:

my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %isnew, $hit, $i, @sorted);
for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
($unsorted[$db_isnew + ($i * ($#db_cols+1))] eq "Ja") and ($isnew{$i} = 1);
($unsorted[$db_ispop + ($i * ($#db_cols+1))] eq "Ja") and ($iscool{$i} = 1);
}
foreach $hit (sort {
($isnew{$b} and !$isnew{$a}) and return 1;
($isnew{$a} and !$isnew{$b}) and return -1;
($iscool{$b} and !$iscool{$a}) and return 1;
($iscool{$a} and !$iscool{$b}) and return -1;
($isnew{$a} and $isnew{$b}) and return lc($sortby{$b}) <=> lc($sortby{$a});
($iscool{$a} and $iscool{$b}) and return lc($sortby{$b}) <=> lc($sortby{$a});
return lc($sortby{$b}) <=> lc($sortby{$a});
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}




Now the links are sorted
1. new links
2. rated links (10 first - 1 last)

Example: http://www.gpaed.de/...blaetter/Mathematik/

BUT and that's my question
unrated links are in random order ???
Is there a way to sort unrated links by ID oder date or hits????

Thanks in advance
Matthias

Matthias
gpaed.de

Last edited by:

Matthias70: Nov 26, 2006, 9:36 AM
Quote Reply
Re: [Matthias70] Top Rated Links first In reply to
Some more hours and the code below is working.
It shows
1. new links
2. rated links from 10 to 1

Only the bold part below with the red extension to prevent unfair rating does not seem to work.

Any suggestions, whats wrong with the extension...???




Code:
sub build_sorthit {
# --------------------------------------------------------
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %isnew, $sortbyvotes, %iscool, $hit, $i, @sorted, $column, $type);
foreach $column (@db_cols) {
if ($db_sort_links == $db_def{$column}[0]) {
$type = $db_def{$column}[1];
last;
}
}
for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
($unsorted[$db_isnew + ($i * ($#db_cols+1))] eq "Ja") and ($isnew{$i} = 1);
($unsorted[$db_ispop + ($i * ($#db_cols+1))] eq "Ja") and ($iscool{$i} = 1);
}
if ($type eq "date") {
foreach $hit (sort {
&date_to_unix ($sortby{$b}) <=> &date_to_unix ($sortby{$a});
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
}
elsif ($type eq "numer") {
foreach $hit (sort {
($isnew{$b} and !$isnew{$a}) and return 1;
($isnew{$a} and !$isnew{$b}) and return -1;
if (($sortbyvotes{$a} >= 5) and ($sortbyvotes{$b} < 5)) {return -1;}
elsif (($sortbyvotes{$a} < 5) and ($sortbyvotes{$b} >= 5)) {return 1;}
else { $sortby{$b} <=> $sortby{$a};}
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
}
else {
foreach $hit (sort {
($isnew{$b} and !$isnew{$a}) and return 1;
($isnew{$a} and !$isnew{$b}) and return -1;
($iscool{$b} and !$iscool{$a}) and return 1;
($iscool{$a} and !$iscool{$b}) and return -1;
($isnew{$a} and $isnew{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
($iscool{$a} and $iscool{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
return lc($sortby{$a}) cmp lc($sortby{$b});
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
}
return @sorted;

Matthias
gpaed.de

Last edited by:

Matthias70: Nov 26, 2006, 2:30 PM
Quote Reply
Re: [Matthias70] Top Rated Links first In reply to
Try adding this to site_html_templates.pl:

sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look like.
my %rec = @_;
if ($rec{'Votes'} < 5) { $rec{'Rating'} = 0 }


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Top Rated Links first In reply to
Thanks for your suggestion PerlFlunkie,
but it does not change anything :-(

That's my actual code in db_utils.pl
Code:

sub build_sorthit {
# --------------------------------------------------------
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %isnew, $sortbyvotes, %iscool, $hit, $i, @sorted, $column, $type);
foreach $column (@db_cols) {
if ($db_sort_links == $db_def{$column}[0]) {
$type = $db_def{$column}[1];
last;
}
}
for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
($unsorted[$db_isnew + ($i * ($#db_cols+1))] eq "Ja") and ($isnew{$i} = 1);
($unsorted[$db_ispop + ($i * ($#db_cols+1))] eq "Ja") and ($iscool{$i} = 1);
}
if ($type eq "date") {
foreach $hit (sort {
&date_to_unix ($sortby{$b}) <=> &date_to_unix ($sortby{$a});
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
}
elsif ($type eq "numer") {
foreach $hit (sort {
($isnew{$b} and !$isnew{$a}) and return 1;
($isnew{$a} and !$isnew{$b}) and return -1;
if (($Votes{$a} >= 5) and ($Votes{$b} < 5)) {return -1;}
elsif (($Votes{$a} < 5) and ($Votes{$b} >= 5)) {return 1;}
else { $sortby{$b} <=> $sortby{$a};}
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
}
else {
foreach $hit (sort {
($isnew{$b} and !$isnew{$a}) and return 1;
($isnew{$a} and !$isnew{$b}) and return -1;
($iscool{$b} and !$iscool{$a}) and return 1;
($iscool{$a} and !$iscool{$b}) and return -1;
($isnew{$a} and $isnew{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
($iscool{$a} and $iscool{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
return lc($sortby{$a}) cmp lc($sortby{$b});
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
}
return @sorted;



Thats my actual code in db_utils.pl
Code:

sub site_html_link {
# --------------------------------------------------------

sub site_html_lastlinkpage {
# --------------------------------------------------------
return &load_template ('lastlinkpage.html', {
category => $category,
grand_total => $grand_total,
lastlink2 => $lastlink2,
%globals
});
}

my %rec = @_;
if ($rec{'Votes'} < 5) { $rec{'Rating'} = 0 }
# -----------------------------------------------
# Banner-MOD by Martin Bujara
#
www.linkdb.de
# -----------------------------------------------
if ($rec{'Banner'} ne "") {
$Banner = qq|<img src="$rec{'Banner'}" border="0" width="$rec{'Width'}" height="$rec{'Height'}">|;
}
elsif ($rec{'Width'} eq "") {
$Banner = qq||;
}
elsif ($rec{'Height'} eq "") {
$Banner = qq||;
}
else {
$Banner = qq||;
}
$db_images = "
www.gpaed.de/images/sterne";
$nr = int($rec{'Bewertung'});
$rate_img = qq|<IMG SRC="$db_images/rate$nr.gif" ALT="Bewertung = $rec{'Bewertung'}">|;

($rec{'istNeu'} eq 'Ja') ? ($rec{'istNeu'} = 1) : (delete $rec{'istNeu'});
($rec{'istPopulaer'} eq 'Ja') ? ($rec{'istPopulaer'} = 1) : (delete $rec{'istPopulaer'});
return &load_template ('link.html', {
banner => $Banner,
rate_img => $rate_img,
detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
%rec,
%globals
});
}




Do you have another idea
Matthias

Matthias
gpaed.de