]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/google.pm
minor refactor/optimisation
[git.ikiwiki.info.git] / IkiWiki / Plugin / google.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::google;
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
7 use URI;
9 sub import {
10         hook(type => "getsetup", id => "google", call => \&getsetup);
11         hook(type => "checkconfig", id => "google", call => \&checkconfig);
12         hook(type => "pagetemplate", id => "google", call => \&pagetemplate);
13 }
15 sub getsetup () {
16         return
17                 plugin => {
18                         safe => 1,
19                         rebuild => 1,
20                         section => "web",
21                 },
22 }
24 sub checkconfig () {
25         if (! length $config{url}) {
26                 error(sprintf(gettext("Must specify %s when using the %s plugin"), "url", 'google'));
27         }
28 }
30 my $form;
31 sub pagetemplate (@) {
32         my %params=@_;
33         my $page=$params{page};
34         my $template=$params{template};
36         # Add search box to page header.
37         if ($template->query(name => "searchform")) {
38                 if (! defined $form) {
39                         my $searchform = template("googleform.tmpl", blind_cache => 1);
40                         $searchform->param(url => $config{url});
41                         $form=$searchform->output;
42                 }
44                 $template->param(searchform => $form);
45         }
46 }
48 1