This is the CGI code
#!/usr/bin/perl -wT
use strict;
use CGI qw/:header/;
use Template;
use XML::Simple;
use LWP::Simple qw(get);
use Data::Dumper;
# Template initialisation
my $template = Template->new({INCLUDE_PATH => './'}) || die "template error\n";
my ($vars, @items);
my %blogs = ('blech' => { rdf => 'http://husk.org/blog/index.rdf',
root => 'http://husk.org/blog/',
},
'yoz' => { rdf => 'http://cheerleader.yoz.com/index.rdf',
root => 'http://cheerleader.yoz.com/',
},
'aevil' => { rdf => 'http://www.axis-of-aevil.net/axis.rdf',
root => 'http://www.axis-of-aevil.net/'
},
'davorg' => { rdf => 'http://ician.co.uk/index.rdf',
root => 'http://ician.co.uk/',
},
);
print header;
my $iso_time = iso_time();
foreach my $blog (sort keys %blogs) {
my $xml = get $blogs{$blog}->{'rdf'};
print STDERR "Processing ${blog}'s RDF\n";
my $data = XMLin($xml);
foreach my $item (sort { $b->{'dc:date'} cmp $a->{'dc:date'} } @{ $data->{'item'} }) {
next if ($item->{'dc:date'} gt $iso_time); # skip post-dated items
push @items, { 'title' => $item->{'title'},
'root' => $blogs{$blog}->{'root'},
'nick' => $blog,
'time' => $item->{'dc:date'},
'link' => $item->{'link'},
};
last;
}
}
# process and exit
@items = sort { $b->{'time'} cmp $a->{'time'} } @items;
my $template_file = 'friends.tt';
$vars->{'items'} = \@items;
$template->process($template_file, $vars) || die $template->error(), "\n";
exit;
sub iso_time {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $iso_time = sprintf("%04d-%02d-%02d%01s%02d:%02d:%02d+00:00", # bug
$year+1900,$mon+1,$mday,'T',$hour,$min,$sec);
return $iso_time;
}
This is a simplified TT template.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Friends</title>
</head>
<body>
<table cellpadding="1" cellspacing="0" border="0">
[% FOREACH item = items %]
<tr><td><a href="[% item.root %]">[% item.nick %]</a></td>
<td><a href="[% item.link %]">[% item.title %]</td>
<td>[% item.time %]</td></tr>
[% END %]
</table>
</body>
</html>