1 package Sesse::pr0n::Templates;
5 use Sesse::pr0n::Common qw(error dberror);
9 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
21 my $base = $r->dir_config('TemplateBase');
24 for my $dir (<$base/*>) {
28 warn "Templates exist for '$1'";
36 if (!defined(%dirs)) {
40 my $site = $r->get_server_name();
41 if (defined($dirs{$site})) {
49 my ($r, $template) = @_;
51 my $dir = r_to_dir($r);
52 my $cache = $dirs{$dir}{$template};
53 if (defined($cache) && time - $cache->{'time'} <= 300) {
54 return $cache->{'contents'};
59 my $base = $r->dir_config('TemplateBase');
60 open TEMPLATE, "<$base/$dir/$template"
61 or Sesse::pr0n::Common::error($r, "Couldn't open $dir/$template: $!");
64 $newcache->{'contents'} = <TEMPLATE>;
68 $newcache->{'time'} = time;
69 $dirs{$dir}{$template} = $newcache;
70 return $newcache->{'contents'};
74 my ($r, $template, $args) = @_;
75 my $text = fetch_template($r, $template);
78 while (my ($key, $value) = each (%$args)) {
79 $key = "%" . uc($key) . "%";
80 $text =~ s/$key/$value/g;