4 use lib "$FindBin::Bin/modules";
6 use Carp; # 'verbose'; # remove the 'verbose' in production
12 my $cfg = BSE::Cfg->new;
16 defined $id or $id = 1;
17 # the reason to avoid creating an articles object is that this
18 # loads all of the articles into memory
19 # hopefully a print template won't include too many references to
20 # other articles anyway
21 #my $articles = BSE::TB::Articles->new;
23 my $article = BSE::TB::Articles->getByPkey($id)
24 or error_page("No article with id $id found");
26 eval "use $article->{generator}";
28 my $generator = $article->{generator}->new(articles=>'BSE::TB::Articles', cfg => $cfg,
31 my $template = param('template');
33 # make sure they don't try to work outside the
37 if ($template =~ m!^/! || $template =~ /\.\./ || $template !~ /\.tmpl$/i) {
38 error_page("Invalid template name '$template'");
41 $file = file_from_template($template);
43 or error_page("Cannot find template '$template'");
45 $type = $cfg->entry('printable types', $template)
46 || BSE::Template->html_type($cfg);
49 for my $work ($article->{template}, 'printable.tmpl') {
50 next unless $work =~ /\S/;
52 $file = file_from_template($work);
53 last if $file && -e $file;
55 -e $file or error_page("No template available for this page");
56 $type = BSE::Template->html_type($cfg);
60 or error_page("Cannot open template '$template'");
61 my $text = do { local $/; <TMPLT> };
64 $text =~ s/<:\s*embed\s+(?:start|end)\s*:>//g;
66 print "Content-Type: $type\n\n";
67 print $generator->generate_low($text, $article, 'BSE::TB::Articles');
72 $error ||= "Unknown error";
75 my @cols = BSE::TB::Article->columns;
76 @article{@cols} = ('') x @cols;
78 $article{title} = "Error";
79 $article{parentid} = -1;
81 require BSE::Generate::Article;
82 my $gen = BSE::Generate::Article->new(cfg=>$cfg, top => \%article);
86 $gen->baseActs('BSE::TB::Articles', \%acts, \%article),
87 error => sub { CGI::escapeHTML($error) },
90 BSE::Template->show_page('error', $cfg, \%acts);
94 sub file_from_template {
97 return BSE::Template->find_source("printable/$template", $cfg);