]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/google.pm
Merge commit 'intrigeri/po'
[ikiwiki.git] / IkiWiki / Plugin / google.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::google;
3
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
7 use URI;
8
9 my $host;
10
11 sub import {
12         hook(type => "getsetup", id => "google", call => \&getsetup);
13         hook(type => "checkconfig", id => "google", call => \&checkconfig);
14         hook(type => "pagetemplate", id => "google", call => \&pagetemplate);
15 }
16
17 sub getsetup () {
18         return
19                 plugin => {
20                         safe => 1,
21                         rebuild => 1,
22                 },
23 }
24
25 sub checkconfig () {
26         if (! length $config{url}) {
27                 error(sprintf(gettext("Must specify %s when using the %s plugin"), "url", 'google'));
28         }
29         my $uri=URI->new($config{url});
30         if (! $uri || ! defined $uri->host) {
31                 error(gettext("Failed to parse url, cannot determine domain name"));
32         }
33         $host=$uri->host;
34 }
35
36 my $form;
37 sub pagetemplate (@) {
38         my %params=@_;
39         my $page=$params{page};
40         my $template=$params{template};
41
42         # Add search box to page header.
43         if ($template->query(name => "searchform")) {
44                 if (! defined $form) {
45                         my $searchform = template("googleform.tmpl", blind_cache => 1);
46                         $searchform->param(sitefqdn => $host);
47                         $form=$searchform->output;
48                 }
49
50                 $template->param(searchform => $form);
51         }
52 }
53
54 1