The following script can be used for Links SQL v.1.11. It may work in other versions, but it has only been tested with Links SQL 1.11.
#!/usr/local/bin/perl
# ==============================================================
# Script Title : Site of the Day Mod
# Script Name : siteday.cgi
# Description : Extracts a Random Link and Prints it in any page
# Author : Anthro TECH, L.L.C, Copyright 2000
# Web Site : http://www.anthrotech.com/
#
# Disclaimer : This script is freeware and will work with LINKS
# SQL v.1.11. This script is to be used at your
# own risk. Anthro TECH does not assume any
# liability of corruption of your Links database
# or web site.
###############################################################
# Load required modules.
# ---------------------------------------------------
use strict;
use vars qw/%in/;
use CGI ();
use CGI::Carp qw/fatalsToBrowser/;
use lib '/absolute/path/to/admindirectory';
use Links::Links;
use Links::DB_Utils;
use Links::HTML_Templates;
use Links::DBSQL;
$|++;
&main();
sub main {
#-----------------------------------------------------------
# Main subroutine of script.
my $in = new CGI;
my $dynamic = $in->param('d') ? $in : undef;
%in = %{&cgi_to_hash ($in)};
my ($id, $category, $getcat, $name, $offset, $total, $rec, $sth, $LINKDB);
print $in->header('text/html');
# Connect to Database
$LINKDB = new Links::DBSQL "$LINKS{admin_root_path}/defs/Links.def";
# Get the random line in the database
$total = $LINKDB->total();
$offset = int rand $total;
$sth = $LINKDB->prepare ( " SELECT * FROM Links LIMIT $offset, 1 ");
$sth->execute() or die $DBI::errstr;
$rec = $sth->fetchrow_hashref;
$id = $rec->{'ID'};
# Get Record to display
$rec = $LINKDB->get_record ($id, 'HASH');
$getcat = $rec->{'CategoryID'};
$name = &get_category_name ($getcat);
$category = &build_clean_name ($name);
$rec or &site_html_error ({error => "Can't Find Random Link."}, $in, $dynamic);
# Prints record to Site of Day file.
open (PAGE, ">$LINKS{db_siteday_file}") or &site_html_error ({error => "Unable to open textfile: $LINKS{db_siteday_file}. Reason: $!"}, $in, $dynamic);
print PAGE &site_html_day ({Category => $category, %$rec});
close PAGE;
# Confirmation message
print qq|Site of the Day Added: ${$rec}{'Title'}|;
}
You will also have to do the following:
1) Create a subroutine in the HTML_Templates.pm file. (Don't forget to add &site_html_day in the @EXPORT array.
sub site_html_day {
# --------------------------------------------------------
# This routine builds special list of links for Last Link
my ($rec, $dynamic) = @_;
my $template = defined $dynamic ? $dynamic->param('t') : undef;
(ref $rec eq 'HASH') or croak "HTML_TEMPLATES: Argument '$rec' must be hash reference";
# Set new and pop and award to either 1 or 0 for templates.
($rec->{'isNew'} eq 'Y') ? ($rec->{'isNew'} = 1) : (delete $rec->{'isNew'});
($rec->{'isChanged'} eq 'Y') ? ($rec->{'isChanged'} = 1) : (delete $rec->{'isChanged'});
($rec->{'isPopular'} eq 'Y') ? ($rec->{'isPopular'} = 1) : (delete $rec->{'isPopular'});
# Figure out how many days old it is if it's a new link.
if ($LINKS{build_days_old}) {
if ($rec->{'isNew'}) {
$rec->{'Days_Old'} = &Links::DBSQL::date_diff (&Links::DBSQL::get_date(), $rec->{'Add_Date'});
}
else {
$rec->{'Days_Old'} = '';
}
}
my $user = {};
defined $dynamic and &load_user ($dynamic, $user, $rec->{CategoryID});
my $output = &load_template ('siteofday.html', {
%$rec,
%$user,
%GLOBALS
}, undef, $template);
# Don't clean output on a single link.
return $output;
}
2) Add a template file in your templates directory called siteofday.html. This file can contain all tags for fields located in the Links table.
Note: I have included codes for linking the Category that the link is located in by using the <%Category%> tag.
Like the following:
<a href="/<%Category%>/"><%Category%></a>
3) You will have to add the following variable to your Links.pm file:
$LINKS{db_siteday_file} = "$LINKS{build_root_path}/siteday.txt";
4) Then create a file called siteday.txt. This should be placed in your $LINKS{build_root_path} directory and the permission of the file should be 666 (rw-rw-rw-).
5) Then use the following tag in any of your template pages:
< !--#include virtual="/siteday.txt"-- >
Note: Don't forget to close the spaces before and after the < and >.
You can execute this script via Cron or Windows Scheduler Program everyday to have a true site of the day.
Hope this helps and works for you.
Regards,
Eliot Lee
Code:
#!/usr/local/bin/perl
# ==============================================================
# Script Title : Site of the Day Mod
# Script Name : siteday.cgi
# Description : Extracts a Random Link and Prints it in any page
# Author : Anthro TECH, L.L.C, Copyright 2000
# Web Site : http://www.anthrotech.com/
#
# Disclaimer : This script is freeware and will work with LINKS
# SQL v.1.11. This script is to be used at your
# own risk. Anthro TECH does not assume any
# liability of corruption of your Links database
# or web site.
###############################################################
# Load required modules.
# ---------------------------------------------------
use strict;
use vars qw/%in/;
use CGI ();
use CGI::Carp qw/fatalsToBrowser/;
use lib '/absolute/path/to/admindirectory';
use Links::Links;
use Links::DB_Utils;
use Links::HTML_Templates;
use Links::DBSQL;
$|++;
&main();
sub main {
#-----------------------------------------------------------
# Main subroutine of script.
my $in = new CGI;
my $dynamic = $in->param('d') ? $in : undef;
%in = %{&cgi_to_hash ($in)};
my ($id, $category, $getcat, $name, $offset, $total, $rec, $sth, $LINKDB);
print $in->header('text/html');
# Connect to Database
$LINKDB = new Links::DBSQL "$LINKS{admin_root_path}/defs/Links.def";
# Get the random line in the database
$total = $LINKDB->total();
$offset = int rand $total;
$sth = $LINKDB->prepare ( " SELECT * FROM Links LIMIT $offset, 1 ");
$sth->execute() or die $DBI::errstr;
$rec = $sth->fetchrow_hashref;
$id = $rec->{'ID'};
# Get Record to display
$rec = $LINKDB->get_record ($id, 'HASH');
$getcat = $rec->{'CategoryID'};
$name = &get_category_name ($getcat);
$category = &build_clean_name ($name);
$rec or &site_html_error ({error => "Can't Find Random Link."}, $in, $dynamic);
# Prints record to Site of Day file.
open (PAGE, ">$LINKS{db_siteday_file}") or &site_html_error ({error => "Unable to open textfile: $LINKS{db_siteday_file}. Reason: $!"}, $in, $dynamic);
print PAGE &site_html_day ({Category => $category, %$rec});
close PAGE;
# Confirmation message
print qq|Site of the Day Added: ${$rec}{'Title'}|;
}
You will also have to do the following:
1) Create a subroutine in the HTML_Templates.pm file. (Don't forget to add &site_html_day in the @EXPORT array.
Code:
sub site_html_day {
# --------------------------------------------------------
# This routine builds special list of links for Last Link
my ($rec, $dynamic) = @_;
my $template = defined $dynamic ? $dynamic->param('t') : undef;
(ref $rec eq 'HASH') or croak "HTML_TEMPLATES: Argument '$rec' must be hash reference";
# Set new and pop and award to either 1 or 0 for templates.
($rec->{'isNew'} eq 'Y') ? ($rec->{'isNew'} = 1) : (delete $rec->{'isNew'});
($rec->{'isChanged'} eq 'Y') ? ($rec->{'isChanged'} = 1) : (delete $rec->{'isChanged'});
($rec->{'isPopular'} eq 'Y') ? ($rec->{'isPopular'} = 1) : (delete $rec->{'isPopular'});
# Figure out how many days old it is if it's a new link.
if ($LINKS{build_days_old}) {
if ($rec->{'isNew'}) {
$rec->{'Days_Old'} = &Links::DBSQL::date_diff (&Links::DBSQL::get_date(), $rec->{'Add_Date'});
}
else {
$rec->{'Days_Old'} = '';
}
}
my $user = {};
defined $dynamic and &load_user ($dynamic, $user, $rec->{CategoryID});
my $output = &load_template ('siteofday.html', {
%$rec,
%$user,
%GLOBALS
}, undef, $template);
# Don't clean output on a single link.
return $output;
}
2) Add a template file in your templates directory called siteofday.html. This file can contain all tags for fields located in the Links table.
Note: I have included codes for linking the Category that the link is located in by using the <%Category%> tag.
Like the following:
Code:
<a href="/<%Category%>/"><%Category%></a>
3) You will have to add the following variable to your Links.pm file:
Code:
$LINKS{db_siteday_file} = "$LINKS{build_root_path}/siteday.txt";
4) Then create a file called siteday.txt. This should be placed in your $LINKS{build_root_path} directory and the permission of the file should be 666 (rw-rw-rw-).
5) Then use the following tag in any of your template pages:
Code:
< !--#include virtual="/siteday.txt"-- >
Note: Don't forget to close the spaces before and after the < and >.
You can execute this script via Cron or Windows Scheduler Program everyday to have a true site of the day.
Hope this helps and works for you.
Regards,
Eliot Lee