Gossamer Forum
Home : Products : Links 2.0 : Customization :

Re: [allthingsfree] priority links mod

Quote Reply
Re: [allthingsfree] priority links mod In reply to
here are some sort_hit routines. The ones with "good" in the name actually worked. I'm not sure if they all work or not.

You will need to be careful about the type ( alpha or numeric ) you use with Priority. If you set Priority as alpha, you need to use the string operators (eq, ne, lt, gt, cmp, etc). If you set Priority as numeric, you need to use the numeric operators (==, !=, <, >, etc).

I never was very good with Perl, which I why I have switched to a completely PHP-based/mySQL system...

Code:
sub build_sorthity {
# --------------------------------------------------------
# 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, %ispick, $hit, $i, @sorted); for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
$priority{$i} = $unsorted[$db_priority + ($i * ($#db_cols+1))];
($unsorted[$db_ispick + ($i * ($#db_cols+1))] eq "Yes") and ($ispick{$i} = 1);
}
foreach $hit (sort {
($priority{$b} and !$priority{$a}) and return 1;
($priority{$a} and !$priority{$b}) and return -1;
($ispick{$b} and !$ispick{$a}) and return 1;
($ispick{$a} and !$ispick{$b}) and return -1;
($priority{$a} and $priority{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
($ispick{$a} and $ispick{$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;
}



sub build_sorthitgoodaa {
# --------------------------------------------------------
# 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, %ispriority, %ispick, %ispaid, $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))]) and ($priority{$i} = 1);
($unsorted[$db_isPriority + ($i * ($#db_cols+1))] eq "Yes") and ($ispriority{$i} = 1);
($unsorted[$db_isPick + ($i * ($#db_cols+1))] eq "Yes") and ($ispick{$i} = 1);
($unsorted[$db_isPaid + ($i * ($#db_cols+1))] eq "Yes") and ($ispaid{$i} = 1);
}
foreach $hit (sort {
($priority{$b} and !$priority{$a}) and return 1;
($priority{$a} and !$priority{$b}) and return -1;
($ispriority{$b} and !$ispriority{$a}) and return 1;
($ispriority{$a} and !$ispriority{$b}) and return -1;
($ispick{$b} and !$ispick{$a}) and return 1;
($ispick{$a} and !$ispick{$b}) and return -1;
($ispaid{$b} and !$ispaid{$a}) and return 1;
($ispaid{$a} and !$ispaid{$b}) and return -1;



($priority{$a} and $priority{$b}) and return lc($sortby{$b}) cmp lc($sortby{$a});
($ispriority{$a} and $ispriority{$b}) and return lc($sortby{$b}) cmp lc($sortby{$b});
($ispick{$a} and $ispick{$b}) and return lc($sortby{$b}) cmp lc($sortby{$a});
($ispaid{$a} and $ispaid{$b}) and return lc($sortby{$b}) cmp lc($sortby{$a});



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;
}





sub build_sorthit {
# just priority
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, $hit, $i, @sorted, $column, $type);
for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
}
foreach $hit ( sort {
$sortby{$b} cmp $sortby{$a};
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}



sub build_sorthitr {
# just priority
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, $hit, $i, @sorted, $column, $type);
for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
}
foreach $hit (reverse sort {
$sortby{$b} cmp $sortby{$a};
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}




sub build_sorthitgood {
# --------------------------------------------------------
# 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, %isPriority, %isPaid, %isPick, $hit, $i, @sorted);
for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
$Priority{$i} = $unsorted[$db_priority + ($i * ($#db_cols+1))];
($unsorted[$db_priority + ($i * ($#db_cols+1))] eq "Yes") and ($isPriority{$i} = 1);
($unsorted[$db_isPaid + ($i * ($#db_cols+1))] eq "Yes") and ($isPaid{$i} = 1);
($unsorted[$db_isPick + ($i * ($#db_cols+1))] eq "Yes") and ($isPick{$i} = 1);
}



foreach $hit (sort {
($isPriority{$b} and !$isPriority{$a}) and return 1;
($isPriority{$a} and !$isPriority{$b}) and return -1;
($isPaid{$b} and !$isPaid{$a} and !$isPriority{$a} and !$isPriority{$b}) and return 1;
($isPaid{$a} and !$isPaid{$b} and !$isPriority{$a} and !$isPriority{$b}) and return -1;
($isPick{$b} and !$isPick{$a} and !$isPriority{$a} and !$isPriority{$b}) and return 1;
($isPick{$a} and !$isPick{$b} and !$isPriority{$a} and !$isPriority{$b}) and return -1;
($isPriority{$a} and $isPriority{$b}) and return $Priority{$a} cmp $Priority{$b};
($isPaid{$a} and $isPaid{$b}) and return $sortby{$a} cmp $sortby{$b};
($isPick{$a} and $isPick{$b}) and return $sortby{$a} cmp $sortby{$b};
$sortby{$b} <=> $sortby{$a};
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}




sub build_sorthitf {
# --------------------------------------------------------
# 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, %isPriority, %isPaid, %isPick, $hit, $i, @sorted);



for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
$Priority{$i} = $unsorted[$db_priority + ($i * ($#db_cols+1))];
($unsorted[$db_priority + ($i * ($#db_cols+1))] eq "Yes") and ($isPriority{$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 {
($isPriority{$a} and !$isPriority{$b}) and return -1;
($isPriority{$b} and !$isPriority{$a}) and return 1;
($isPaid{$b} and !$isPaid{$a} and !$isPriority{$a} and !$isPriority{$b}) and return 1;
($isPaid{$a} and !$isPaid{$b} and !$isPriority{$a} and !$isPriority{$b}) and return -1;
($isPick{$b} and !$isPick{$a} and !$isPriority{$a} and !$isPriority{$b}) and return 1;
($isPick{$a} and !$isPick{$b} and !$isPriority{$a} and !$isPriority{$b}) and return -1;
($isPriority{$a} and $isPriority{$b}) and return lc($Priority{$a}) cmp lc($Priority{$b});
($isPaid{$a} and $isPaid{$b}) and return lc($sortby{$a}) cmp lc($sortby{$b});
($isPick{$a} and $isPick{$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;
}





sub build_sorthitx {
# --------------------------------------------------------
# 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, $hit, $i, @sorted);
for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
$priority{$i} = $unsorted[$db_priority + ($i * ($#db_cols+1))];
($unsorted[$db_ispick + ($i * ($#db_cols+1))] eq "Yes") and ($ispick{$i} = 1);



}
foreach $hit (sort {
($priority{$b} and !$priority{$a}) and return 1;
($priority{$a} and !$priority{$b}) and return -1;
($ispick{$b} and !$ispick{$a}) and return 1;
($ispick{$a} and !$ispick{$b}) and return -1;
($priority{$a} and $priority{$b}) and return $priority{$b} <=> $priority{$a};
($ispick{$a} and $ispick{$b}) and return $sortby{$b} <=> $sortby{$a};
$sortby{$b} <=> $sortby{$a};
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}


You now know more than I do!


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Subject Author Views Date
Thread priority links mod allthingsfree 5062 Oct 27, 2003, 6:46 AM
Post Re: [allthingsfree] priority links mod
PerlFlunkie 4981 Oct 27, 2003, 10:08 AM
Thread Re: [allthingsfree] priority links mod
esm 4986 Oct 27, 2003, 11:02 AM
Thread Re: [esm] priority links mod
allthingsfree 4973 Oct 29, 2003, 11:12 AM
Thread Re: [allthingsfree] priority links mod
esm 4998 Oct 29, 2003, 12:07 PM
Thread Re: [esm] priority links mod
allthingsfree 4959 Oct 31, 2003, 2:10 PM
Post Re: [allthingsfree] priority links mod
esm 4948 Oct 31, 2003, 2:44 PM
Post Re: [allthingsfree] priority links mod
MadridMan 4810 Feb 26, 2004, 4:24 PM