Gossamer Forum
Home : Products : Links 2.0 : Customization :

Re: Ordering the Links RECIP, COOL, NEW, ALPHA

Quote Reply
Re: Ordering the Links RECIP, COOL, NEW, ALPHA In reply to
Try the following: -

sub build_sorthit {
# --------------------------------------------------------
# This function sorts a list of links. It has been modified to sort
# new links first, then cool links, then the rest alphabetically. By modifying
# the sort function below, you can sort the links however you like (by date,
# or random, etc.).
#
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %priority, %isnew, %iscool, $hit, $i, @sorted);
for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
($unsorted[$db_priority + ($i * ($#db_cols+1))] eq "Yes") and ($priority{$i} = 1);
($unsorted[$db_isnew + ($i * ($#db_cols+1))] eq "Yes") and ($isnew{$i} = 1);
($unsorted[$db_ispop + ($i * ($#db_cols+1))] eq "Yes") and ($iscool{$i} = 1);
}
foreach $hit (sort {
($priority{$b} and !$priority{$a}) and return 1;
($priority{$a} and !$priority{$b}) and return -1;
($isnew{$b} and !$isnew{$a} and !$priority{$a} and !$priority{$b}) and return 1;
($isnew{$a} and !$isnew{$b} and !$priority{$a} and !$priority{$b}) and return -1;
($iscool{$b} and !$iscool{$a} and !$priority{$a} and !$priority{$b}) and return 1;
($iscool{$a} and !$iscool{$b} and !$priority{$a} and !$priority{$b}) and return -1;
($priority{$a} and $priority{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
($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;
}


http://www.humorlinks.com
Subject Author Views Date
Thread Ordering the Links RECIP, COOL, NEW, ALPHA sportscapper 2470 Feb 7, 2001, 6:49 PM
Thread Re: Ordering the Links RECIP, COOL, NEW, ALPHA
sportscapper 2400 Feb 10, 2001, 2:16 PM
Thread Re: Ordering the Links RECIP, COOL, NEW, ALPHA
Stealth 2412 Feb 10, 2001, 2:37 PM
Thread Re: Ordering the Links RECIP, COOL, NEW, ALPHA
sportscapper 2382 Feb 10, 2001, 7:49 PM
Thread Re: Ordering the Links RECIP, COOL, NEW, ALPHA
glennu 2363 Feb 10, 2001, 8:14 PM
Thread Re: Ordering the Links RECIP, COOL, NEW, ALPHA
sportscapper 2357 Feb 10, 2001, 10:04 PM
Thread Re: Ordering the Links RECIP, COOL, NEW, ALPHA
glennu 2355 Feb 11, 2001, 7:43 AM
Thread Re: Ordering the Links RECIP, COOL, NEW, ALPHA
sportscapper 2354 Feb 11, 2001, 1:17 PM
Thread Re: Ordering the Links RECIP, COOL, NEW, ALPHA
glennu 2362 Feb 11, 2001, 1:47 PM
Thread Re: Ordering the Links RECIP, COOL, NEW, ALPHA
sportscapper 2322 Feb 11, 2001, 5:16 PM
Thread Re: Ordering the Links RECIP, COOL, NEW, ALPHA
humorlinks 2308 Feb 11, 2001, 7:57 PM
Post Re: Ordering the Links RECIP, COOL, NEW, ALPHA
sportscapper 2318 Feb 11, 2001, 8:28 PM