Gossamer Forum
Home : Products : Links 2.0 : Discussions :

Newsletter: can i SORT??

Quote Reply
Newsletter: can i SORT??
Hello, this is my first post. I try to sort the links in my newsletter, but i canīt! I want to sort by date, firts the new one... somebody can help me?

Thanks a lot!

this is the code on my db_utils.pl

sub build_new_links {
# --------------------------------------------------------
# Returns a text string used in the email newsletter of all
# new links.
#
my $output = '';
my (@data, %rec);

open (DB, "<$db_file_name") or &cgierr("unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB>) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
chomp;
@data = &split_decode($_);
if ($data[$db_isnew] eq 'm5m') {
%rec = &array_to_hash(0, @data);
my $des_q = &linewrap ($rec{'Pie'});
$output .= qq~
---------------------------------------------------------
$rec{'Title'}
$rec{'URL'}
$des_q

~;
}
}
close DB;
return $output;
}



Quote Reply
Re: Newsletter: can i SORT?? In reply to
Welp, you will have to use sub build_sorthit for your links in the Newsletter (if you have kept the stock codes for this sub, which sorts first by new links).

Try adding the following codes:

Code:

@data = &build_sorthit ($_);


AFTER the following codes:

Code:

@data = &split_decode($_);


BTW: This question is more appropriate for the Customization Forum.

Regards,

Regards,

Eliot Lee
Quote Reply
Re: Newsletter: can i SORT?? In reply to
Okey Eliot
I put this line in my code:

@data = &build_sorthit ($_);


AFTER the following codes:



@data = &split_decode($_);

but donīt work!

This is the subrutine for sort...

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, %isnew, %iscool, $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 "m5m") and ($isnew{$i} = 1);
($unsorted[$db_ispop + ($i * ($#db_cols+1))] eq "Yes") and ($iscool{$i} = 1);
}
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]);
}
return @sorted;
}





i will post a new one message in Customization Forum.

Thanks!

jav