Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Create a Recommended Programs Listing

Quote Reply
Create a Recommended Programs Listing
Okay, here is one for all you guru's there. People who formerly used Links 2.0 will remember a couple of mods called 'Pick' and 'Top Ten'. I used both these mods previously, as I recommend certain programs and also keep a Top Ten List of Programs. These were setup with a simple 'Yes/No' field (default being No).

I've tried implementing this in LinksSQL - the nph-build.cgi runs okay - no errors - actually got it to create a Top Ten page, but it didn't have any links on it!

Firstly, in Links.pm I added the following:-

Code:
# The path and URL for the TOP TEN Programs page.
$LINKS{build_topten_path} = "$LINKS{build_root_path}/My_Top_Ten_Affiliate_Programs";
$LINKS{build_topten_url} = "$LINKS{build_root_url}/My_Top_Ten_Affiliate_Programs";

I then in nph-build.cgi added the following in sub_build_all
---------------------
Code:
&build_topten_page();

AND also in nph-build.cgi:

Code:
sub build_topten_page {
# --------------------------------------------------------
# Creates a "TopTen" page.
#
my ($s, $e, $f, $sth, $link, $category, $category_clean, %link_output);
my ($total, $link_results, $title_linked, $percent);

$USE_HTML ?
print "Building <a href='$LINKS{build_topten_url}/$LINKS{build_index}' target='_blank'>Top Ten Programs</a> ... \n" :
print "Building Top Ten Programs Page ... \n";
$s = time();

# Build the directory.
($LINKS{build_topten_path} =~ m,^$LINKS{build_root_path}/(.*)$,) and &build_dir ($1);

# Get all the topten links.
$sth = $LINKDB->prepare (qq!
SELECT Links.*, Category.Name
FROM Links, Category
WHERE Links.isTop = 'Yes' AND Links.CategoryID = Category.ID
ORDER BY $LINKS{build_sort_order_topten}
LIMIT 1000
!);
$sth->execute();

# Create the HTML for the individual links.
$total = 0;
while ($link = $sth->fetchrow_hashref) {
$total++;
$link_output{$link->{'Name'}} .= &site_html_link ($link);
}

# Create the HTML for the category headers, and join it all together into link_results.
foreach $category (sort keys %link_output) {
$category_clean = &build_clean_name ($category);
$link_results .= qq|<P><A HREF="$LINKS{build_root_url}/$category_clean/$LINKS{build_index}">$category</A>\n|;
$link_results .= $link_output{$category};
}

# Write it out to the file.
$title_linked = &build_linked_title ("Top Ten Affiliate Programs");
open (TOPTEN, ">$LINKS{build_topten_path}/$LINKS{build_index}") or die ("unable to open top ten page: $LINKS{build_topten_path}/$LINKS{build_index}. Reason: $!");
print "\tTop Ten Affiliate Programs: $total\n";
print TOPTEN &site_html_topten ( { grand_total => $GRAND_TOTAL, total => $total, link_results => $link_results, title_linked => $title_linked, percent => $percent } );
close TOPTEN;

# All done.
$f = time();
$e = $f - $s;
print "Done ($e s)\n\n";
}

Now you clever codester's out there (one of which I am not) will notice that what I basically did was cut/paste the contents of sub_build_cool_page, however I also removed from that area a couple of lines: -

Code:
($sth->rows > 1000) and print "\tWarning: Max Cool links limit of 1,000 exceeded!\n";
Because I thought this was irrelevant as it was going the check of New Links.

The key area where I think I made an error was in the following area: -

Code:
# Write it out to the file.
$title_linked = &build_linked_title ("Top Ten Affiliate Programs");
open (TOPTEN, ">$LINKS{build_topten_path}/$LINKS{build_index}") or die ("unable to open top ten page: $LINKS{build_topten_path}/$LINKS{build_index}. Reason: $!");
print "\tTop Ten Affiliate Programs: $total\n";
print TOPTEN &site_html_topten ( { grand_total => $GRAND_TOTAL, total => $total, link_results => $link_results, title_linked => $title_linked, percent => $percent } );
close TOPTEN;

The corresponding code in the what's cool area is: -

Code:
# Write it out to the file.
$title_linked = &build_linked_title ("Cool");
open (COOL, ">$LINKS{build_cool_path}/$LINKS{build_index}") or die ("unable to open what's cool page: $LINKS{build_cool_path}/$LINKS{build_index}. Reason: $!");
print "\tCool Links: $total\n";
($LINKS{build_pop_cutoff} < 1) ? ($percent = $LINKS{build_pop_cutoff} * 100 . "%") : ($percent = $LINKS{build_pop_cutoff});
print COOL &site_html_cool ( { grand_total => $GRAND_TOTAL, total => $total, link_results => $link_results, title_linked => $title_linked, percent => $percent } );
close COOL;

I believe the changes in this area is what is causing me not to display any links.

In HTML_Templates.pm I also added the following:-

Code:
&site_html_topten
in the @EXPORT... area.

and also the following subroutine:-

Code:
sub site_html_topten {
# --------------------------------------------------------
# This routine determines how the top rated page will look like.
#
my ($tags, $dynamic) = @_;
my $template = defined $dynamic ? $dynamic->param('t') : undef;
(ref $tags eq 'HASH') or croak "HTML_TEMPLATES: Argument '$tags' must be hash reference";

defined $dynamic and &load_user ($dynamic, $tags, $tags->{ID});
my $output = &load_template ( 'category.html', {
%$tags,
%GLOBALS
}, undef, $template);
defined $dynamic and &clean_output($dynamic, \$output);
return $output;
}

I hope someone can follow these changes and work out what I am trying to do. I believe the area where I am principally having the problem is in the #write it out to a file area above.

Anyone have any ideas? If I can work this out, then I'll be able to also amend it for my Recommended Programs.

These fields are current in my database, and is defined as 'isTop'.

Regards,

Clint.








------------------
Clint
----------------------------------
www.AffiliatesDirectory.com
Proud Supporter of Links SQL
----------------------------------