1 package BSE::UI::AdminPregen;
3 use base qw(BSE::UI::AdminDispatch);
4 use BSE::Util::Iterate;
5 use BSE::Util::Tags qw(tag_hash);
7 our $VERSION = "1.000";
16 sub actions { \%actions }
18 sub rights { \%actions }
20 sub default_action { "list" }
23 my ($self, $req) = @_;
25 my %entries = $req->cfg->entries('pregenerate');
27 my @names = sort keys %entries;
31 my ($type, $src) = split /,/, $entries{$_}, 2;
38 my $it = BSE::Util::Iterate->new;
45 plural => "templates",
50 return $req->response("admin/pregen/index", \%acts);
54 my ($self, $req) = @_;
56 my $id = $req->cgi->param("template");
58 or return $self->req_list($req, { template => "No pregen template" });
59 my $entry = $req->cfg->entry("pregenerate", $id)
60 or return $self->req_list($req, { template => "Unknown pregen template $id" });
62 my %template = ( id => $id );
63 @template{qw/type source/} = split /,/, $entry, 2;
68 template => [ \&tag_hash, \%template ],
71 return $req->response("admin/pregen/show", \%acts);
75 my ($self, $req) = @_;
78 my $id = $req->cgi->param("template");
80 or return $self->req_list($req, { template => "No pregen template" });
81 my $entry = $cfg->entry("pregenerate", $id)
82 or return $self->req_list($req, { template => "Unknown pregen template $id" });
84 require Generate::Article;
85 my ($presets, $input) = split ',', $entry, 2;
86 my $section = "$presets settings";
87 my %article = map { $_, '' } Article->columns;
88 $article{displayOrder} = 1;
90 $article{parentid} = -1;
91 $article{link} = $cfg->entryErr('site', 'url');
92 for my $field (Article->columns) {
93 if ($cfg->entry($section, $field)) {
94 $article{$field} = $cfg->entryVar($section, $field);
97 # by default all of these are handled as dynamic, but it can be
98 # overidden, eg. the error template
99 my $is_extras = $presets eq 'extras';
100 my $dynamic = $cfg->entry($section, 'dynamic', !$is_extras);
102 my $gen = Generate::Article->new
106 force_dynamic => $dynamic,
109 articles => "Articles",
111 %acts = $gen->baseActs("Articles", \%acts, \%article);
112 my $oldurl = $acts{url};
115 my $value = $oldurl->(@_);
116 $value =~ /^<:/ and return $value;
117 unless ($value =~ /^\w+:/) {
118 # put in the base site url
119 $value = $cfg->entryErr('site', 'url').$value;
123 my $content = BSE::Template->get_page($input, $cfg, \%acts);
129 type => BSE::Template->html_type($req->cfg),
132 require BSE::Dynamic::Article;
133 my $dyngen = BSE::Dynamic::Article->new($req);
134 return $dyngen->generate(\%article, $content);