-sub rsspage ($) { #{{{
- my $page=shift;
-
- return $page.".rss";
-} #}}}
-
-sub preprocess ($$) { #{{{
- my $page=shift;
- my $content=shift;
-
- my %commands=(inline => \&preprocess_inline);
-
- my $handle=sub {
- my $escape=shift;
- my $command=shift;
- my $params=shift;
- if (length $escape) {
- return "[[$command $params]]";
- }
- elsif (exists $commands{$command}) {
- my %params;
- while ($params =~ /(\w+)=\"([^"]+)"(\s+|$)/g) {
- $params{$1}=$2;
- }
- return $commands{$command}->(page => $page, %params);
- }
- else {
- return "[[bad directive $command]]";
- }
- };
-
- $content =~ s{(\\?)$config{wiki_processor_regexp}}{$handle->($1, $2, $3)}eg;
- return $content;
-} #}}}
-
-sub blog_list ($$) { #{{{
- my $globlist=shift;
- my $maxitems=shift;
-
- my @list;
- foreach my $page (keys %pagesources) {
- if (globlist_match($page, $globlist)) {
- push @list, $page;
- }
- }
-
- @list=sort { $pagectime{$b} <=> $pagectime{$a} } @list;
- return @list if ! $maxitems || @list <= $maxitems;
- return @list[0..$maxitems - 1];
-} #}}}
-
-sub get_inline_content ($$) { #{{{
- my $parentpage=shift;
- my $page=shift;
-
- my $file=$pagesources{$page};
- my $type=pagetype($file);
- if ($type ne 'unknown') {
- return htmlize($type, linkify(readfile(srcfile($file)), $parentpage));
- }
- else {
- return "";
- }
-} #}}}
-
-sub preprocess_inline ($@) { #{{{
- my %params=@_;
-
- if (! exists $params{pages}) {
- return "";
- }
- if (! exists $params{archive}) {
- $params{archive}="no";
- }
- if (! exists $params{show} && $params{archive} eq "no") {
- $params{show}=10;
- }
- if (! exists $depends{$params{page}}) {
- $depends{$params{page}}=$params{pages};
- }
- else {
- $depends{$params{page}}.=" ".$params{pages};
- }
-
- my $ret="";
-
- if (exists $params{rootpage}) {
- # Add a blog post form, with a rss link button.
- my $formtemplate=HTML::Template->new(blind_cache => 1,
- filename => "$config{templatedir}/blogpost.tmpl");
- $formtemplate->param(cgiurl => $config{cgiurl});
- $formtemplate->param(rootpage => $params{rootpage});
- if ($config{rss}) {
- $formtemplate->param(rssurl => rsspage(basename($params{page})));
- }
- $ret.=$formtemplate->output;
- }
- elsif ($config{rss}) {
- # Add a rss link button.
- my $linktemplate=HTML::Template->new(blind_cache => 1,
- filename => "$config{templatedir}/rsslink.tmpl");
- $linktemplate->param(rssurl => rsspage(basename($params{page})));
- $ret.=$linktemplate->output;
- }
-
- my $template=HTML::Template->new(blind_cache => 1,
- filename => (($params{archive} eq "no")
- ? "$config{templatedir}/inlinepage.tmpl"
- : "$config{templatedir}/inlinepagetitle.tmpl"));
-
- my @pages;
- foreach my $page (blog_list($params{pages}, $params{show})) {
- next if $page eq $params{page};
- push @pages, $page;
- $template->param(pagelink => htmllink($params{page}, $page));
- $template->param(content => get_inline_content($params{page}, $page))
- if $params{archive} eq "no";
- $template->param(ctime => scalar(gmtime($pagectime{$page})));
- $ret.=$template->output;
- }
-
- # TODO: should really add this to renderedfiles and call
- # check_overwrite, but currently renderedfiles
- # only supports listing one file per page.
- if ($config{rss}) {
- writefile(rsspage($params{page}), $config{destdir},
- genrss($params{page}, @pages));
- }
-
- return $ret;
-} #}}}
-