3 use Squirrel::Template;
7 my ($class, $template, $cfg, $acts, $base_template, $rsets) = @_;
9 my @conf_dirs = $class->template_dirs($cfg);
10 my $file = $cfg->entry('templates', $template) || $template;
11 $file =~ /\.\w+$/ or $file .= ".tmpl";
13 if ($rsets && @$rsets) {
14 for my $set (@$rsets) {
15 push @dirs, map "$_/$set", @conf_dirs;
17 push @dirs, @conf_dirs;
23 my $obj = Squirrel::Template->new(template_dir => \@dirs);
28 $out = $obj->show_page(undef, $file, $acts);
31 if ($@ =~ /Cannot find template/) {
32 print STDERR "Could not find requested template $file, trying $base_template\n";
33 $file = $cfg->entry('templates', $base_template) || $base_template;
34 $file =~ /\.\w+$/ or $file .= ".tmpl";
35 $out = $obj->show_page(undef, $file, $acts);
38 print STDERR "** Eval error: $@\n";
39 $out = "<html><body>There was an error producing this page - please contect the webmaster.</body></html>\n";
44 $out = $obj->show_page(undef, $file, $acts);
52 my ($class, $source, $cfg, $acts) = @_;
54 my @dirs = $class->template_dirs($cfg);
55 my $obj = Squirrel::Template->new(template_dir => \@dirs);
57 $obj->replace_template($source, $acts);
61 my ($class, $cfg) = @_;
63 my $type = "text/html";
64 my $charset = $cfg->entry('html', 'charset');
65 $charset = 'iso-8859-1' unless defined $charset;
66 return $type . "; charset=$charset";
70 my ($class, $cfg, $template) = @_;
72 return $cfg->entry("template types", $template)
73 || $class->html_type($cfg);
77 my ($class, $template, $cfg, $acts, $base_template) = @_;
79 $class->show_literal($class->get_page($template, $cfg, $acts, $base_template), $cfg);
83 my ($class, $source, $cfg, $acts) = @_;
85 $class->show_literal($class->replace($source, $cfg, $acts), $cfg);
89 my ($class, $text, $cfg) = @_;
91 my $type = $class->html_type($cfg);
93 print "Content-Type: $type\n\n";
98 my ($class, $template, $cfg, $acts, $base_template, $rsets) = @_;
102 type => $class->get_type($cfg, $template),
103 content => scalar($class->get_page($template, $cfg, $acts,
104 $base_template, $rsets)),
106 push @{$result->{headers}}, "Content-Length: ".length($result->{content});
112 my ($class, $url, $cfg) = @_;
124 # the commented out headers were meant to help Opera, but they didn't
127 type=>$class->html_type($cfg),
128 content=>"<html></html>",
129 headers=>[ qq/Refresh: 0; url=$url/,
130 #qq/Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0/,
131 #qq/Pragma: no-cache/,
132 #qq/Expires: Thu, 01 Jan 1970 00:00:00 GMT/
138 my ($class, $cfg) = @_;
140 ref($cfg) eq 'BSE::Cfg'
141 or confess "Invalid cfg $cfg supplied\n";
143 my $base = $cfg->entryVar('paths', 'templates');
144 my $local = $cfg->entry('paths', 'local_templates');
145 my @dirs = ( $base );
146 unshift @dirs, $local if $local;
152 my ($class, $template, $cfg) = @_;
154 my @dirs = $class->template_dirs($cfg);
156 my $file = $cfg->entry('templates', $template) || $template;
157 $file =~ /\.\w+$/ or $file .= ".tmpl";
159 for my $dir (@dirs) {
160 return "$dir/$file" if -f "$dir/$file";
167 my ($class, $template, $cfg) = @_;
169 my $path = $class->find_source($template, $cfg)
170 or confess "Cannot find template $template";
171 open SOURCE, "< $path"
172 or confess "Cannot open template $path: $!";
174 my $html = do { local $/; <SOURCE> };
181 my ($class, $req, $result) = @_;
188 push @{$result->{headers}}, "Content-Type: $result->{type}"
190 push @{$result->{headers}}, $req->extra_headers;
191 my $add_cache_control = 1;
192 for my $header (@{$result->{headers}}) {
193 if ($header =~ /^cache-control:/i) {
194 $add_cache_control = 0;
198 if ($add_cache_control) {
199 push @{$result->{headers}}, "Cache-Control: no-cache";
201 if (exists $ENV{GATEWAY_INTERFACE}
202 && $ENV{GATEWAY_INTERFACE} =~ /^CGI-Perl\//) {
204 my $r = Apache->request or die;
205 $r->send_cgi_header(join("\n", @{$result->{headers}})."\n\n");
208 print "$_\n" for @{$result->{headers}};
211 print $result->{content};