Gossamer Forum
Home : Products : Links 2.0 : Customization :

A - Z Listing... My 90% completed solution

Quote Reply
A - Z Listing... My 90% completed solution
G'day
Because none of the other solutions offered for an A - Z listing of links in the database were suitable for myself, I wrote the following script and for me (my links2 is heavily modified... but as far as I know it should work for most installations) it works great.

The only thing I have not completed as yet is spanning the output onto multiple pages. If someone would be kind enough to modify the script to do this (for say 20 links a page...) before I do (will attempt and let you know of outcome) it would be greatly appreciated. Not only by me, but by everyone else who wants this script.

Here is the code, which I have in a file called abc.cgi but it could be in a file of any name. Just execute the script and it should work! (This is definately in beta stage, as it is it doesn't even print correct HTML tags, this is just to show that it can be done)

Code:
#!/usr/local/bin/perl

print "Content-type: text/html\n\n";

require "admin/links.cfg";
require "$db_lib_path/db_utils.pl";
require "$db_lib_path/links.def";
require "$db_lib_path/site_html.pl";

open (DB, "$db_links_name");
flock(DB,1);
LINE: while (<DB>) {
/^\s*$/ and next LINE;
chomp;
push (@values, &split_decode($_));
}
close (DB);

@values = &sorthit (@values);

$count1 = 0;
$count2 = $#db_cols;
$count3 = $#values+1;
while ($count1 < $count3) {
$count4++;
%rec = &array_to_hash(0,@values[$count1 .. $count2]);
$link .= &site_html_link (%rec);
$count1 = $count1 + $#db_cols + 1 ;
$count2 = sprintf ("%.0f", $count2 + $#db_cols + 0.5);
}

print $link;

sub sorthit {
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, $hit, $i, @sorted);

for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
}

foreach $hit ( sort { 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;
}
If anyone has any question about the code or anything else, fire away. And before anyone does ask, I used that sub sorthit and not the build_sorthit in the db_utils.pl file because the links are aplhabetically sorted, rather than how the rest of the site may be arranged. Example, the rest of my links2 site is randomly sorted, and this is alphabetical... cannot use the same code for those two things.

Regards,
Robbo