From 4c4780f4772acb5abcc57b03d114c5e1364af63a Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Wed, 14 Aug 2002 22:54:20 +0000 Subject: Create .meta files with the expiry date of pages. Also put the expiry date in HTML meta headers. Make indexfilebasename a configure option. Code cleanup: renamed some functions. --- Echolot/Tools.pm | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) (limited to 'Echolot/Tools.pm') diff --git a/Echolot/Tools.pm b/Echolot/Tools.pm index e4bed61..dcdbab4 100644 --- a/Echolot/Tools.pm +++ b/Echolot/Tools.pm @@ -1,7 +1,7 @@ package Echolot::Tools; # (c) 2002 Peter Palfrader -# $Id: Tools.pm,v 1.7 2002/07/17 17:06:44 weasel Exp $ +# $Id: Tools.pm,v 1.8 2002/08/14 22:54:20 weasel Exp $ # =pod @@ -17,6 +17,7 @@ Echolot::Tools - Tools for echolot use strict; use Carp qw{cluck}; +use HTML::Template; use Digest::MD5 qw{}; sub hash($) { @@ -141,6 +142,86 @@ sub send_message(%) { return 1; }; +sub make_monthname($) { + my ($month) = @_; + my @MON = qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec}; + return $MON[$month]; +}; + +sub make_dayname($) { + my ($day) = @_; + my @WDAY = qw{Sun Mon Tue Wed Thu Fri Sat}; + return $WDAY[$day]; +}; + +sub date822($) { + my ($date) = @_; + + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime($date); + # 14 Aug 2002 17:11:12 +0100 + return sprintf("%s, %02d %s %d %02d:%02d:%02d +0000", + make_dayname($wday), + $mday, + make_monthname($mon), + $year + 1900, + $hour, + $min, + $sec); +}; + +sub write_meta_information($%) { + my ($file, %data) = @_; + + return 1 unless Echolot::Config::get()->{'write_meta_files'}; + + $file .= Echolot::Config::get()->{'meta_extension'}; + open (F, ">$file") or + cluck ("Cannot open $file: $!"), + return 0; + if (defined $data{'Expires'}) { + my $date = date822($data{'Expires'}); + print F "Expires: $date\n"; + }; + close(F); + return 1; +}; + +sub write_HTML_file($$;$%) { + my ($file, $template_file, $expire, %templateparams) = @_; + + my $template = HTML::Template->new( + filename => $template_file, + strict => 0, + die_on_bad_params => 0, + global_vars => 1 ); + $template->param ( %templateparams ); + $template->param ( CURRENT_TIMESTAMP => scalar gmtime() ); + $template->param ( SITE_NAME => Echolot::Config::get()->{'sitename'} ); + $template->param ( seperate_rlist => Echolot::Config::get()->{'seperate_rlists'} ); + $template->param ( combined_list => Echolot::Config::get()->{'combined_list'} ); + $template->param ( thesaurus => Echolot::Config::get()->{'thesaurus'} ); + $template->param ( version => Echolot::Globals::get()->{'version'} ); + $template->param ( expires => date822( time + $expire )); + + open(F, '>'.$file) or + cluck("Cannot open $file: $!\n"), + return 0; + print F $template->output() or + cluck("Cannot print to $file: $!\n"), + return 0; + close (F) or + cluck("Cannot close $file: $!\n"), + return 0; + + if (defined $expire) { + write_meta_information($file, + Expires => time + $expire) or + cluck ("Error while writing meta information for $file"), + return 0; + }; + + return 1; +}; 1; # vim: set ts=4 shiftwidth=4: -- cgit v1.2.3