#!/usr/bin/perl -w
#
# Main tip harvester page. Displays the search box and weekly lists
# of tips.
#
# Revision History
#
# 2003-MAR-23 DSM Initial revision.
$| = 1;
use strict;
use lib '/store/host/lists.evolt.org/includes';
use DBI;
use Time::Local;
use Date::Calc qw(Monday_of_Week Week_of_Year Add_Delta_Days);
require 'evolt-lib.pl';
require 'evolt-db.pl';
my @months = qw(January February March April May June July August
September October November December);
my $body = ''; # Contains any dynamically generated content.
# Get a database handle for thetips database.
my $dbh = opendb('thetips') || ($body .= "
Couldn't open database!
");
# Get the earliest and latest tip dates.
my ($min_date, $max_date) = get_boundaries($dbh);
$body .= "Failed to get min or max tip date!
"
if (!defined($min_date) || !defined($max_date));
# Done with the database connection.
$dbh->disconnect();
# If we got the min and max date from thetips, we can generate the
# year/week listing of tip links. Count backward from the latest
# Monday that there are tips for.
if (defined($min_date) && defined($max_date)) {
my ($year, $month) = (0, -1);
my ($min_year, $min_month, $min_day) = ($min_date =~ m|(\d+)-(\d+)-(\d+)|);
my $min_epoch = timelocal(0, 0, 0, $min_day, $min_month - 1, $min_year - 1900);
my ($max_year, $max_month, $max_day) = ($max_date =~ m|(\d+)-(\d+)-(\d+)|);
my ($start_year, $start_month, $start_day) =
Monday_of_Week(Week_of_Year($max_year, $max_month, $max_day));
my ($end_year, $end_month, $end_day) =
Add_Delta_Days($start_year, $start_month, $start_day, 7);
my $end_epoch = timelocal(0, 0, 0, $end_day, $end_month - 1, $end_year - 1900);
while ($end_epoch >= $min_epoch) {
# Print out the year.
if ($year != $start_year) {
$year = $start_year;
$body .= "$year
\n\n";
}
# Start new month on the next line.
if ($month != $start_month - 1) {
$month = $start_month - 1;
$body .= "$months[$month]
\n\n";
}
else {
$body .= '|';
}
my $sdate = sprintf "%04d%02d%02d", $start_year, $start_month, $start_day;
$body .=<
END
($start_year, $start_month, $start_day) =
Add_Delta_Days($start_year, $start_month, $start_day, -7);
($end_year, $end_month, $end_day) =
Add_Delta_Days($end_year, $end_month, $end_day, -7);
$end_epoch = timelocal(0, 0, 0, $end_day, $end_month - 1, $end_year - 1900);
}
}
# Create the rest of the HTML that will be displayed.
my $html =<
tip
|
harvester
|
|
The <tip> is how a list subscriber
"pays" for making an off-topic post to the list (see
List Info for more information). Every week, our tip harvester
sweeps through thelist archive and picks up all the tips from the
preceeding seven days, and puts them in here for easy access.
|
|
search |
thetips |
|
|
|
Key |
|
Browse tips individually |
|
|
Browse tips by week |
|
|
$body
|
END
# Display the actual page.
print
header({
'rss' => 1,
'rss_title' => 'thetips RSS',
'rss_href' => 'http://lists.evolt.org/harvest/harvest.xml',
}),
body($html),
footer();
1;
########## Subroutines ##########
# Name : get_boundaries
# Purpose: Return the minimum and maximum tip dates.
# Args : $dbh - database handle to thetips database.
# Returns: $min_date - earliest tip date.
# $max_date - latest tip date.
# Notes : Returns undef for both dates if there was a problem.
sub get_boundaries {
my $dbh = shift;
my ($min_date, $max_date);
my $sql = 'SELECT min(tip_date), max(tip_date) FROM thetips';
my $sth = $dbh->prepare($sql) || return (undef, undef);
my $rev = $sth->execute() || return (undef, undef);
($min_date, $max_date) = $sth->fetchrow();
$sth->finish();
return ($min_date, $max_date);
}