2008-10-10 00:13:19 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
package IkiWiki::Plugin::google;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use IkiWiki 2.00;
|
|
|
|
use URI;
|
|
|
|
|
2008-10-10 23:09:33 +02:00
|
|
|
my $host;
|
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub import {
|
2008-10-10 00:13:19 +02:00
|
|
|
hook(type => "getsetup", id => "google", call => \&getsetup);
|
|
|
|
hook(type => "checkconfig", id => "google", call => \&checkconfig);
|
|
|
|
hook(type => "pagetemplate", id => "google", call => \&pagetemplate);
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-10-10 00:13:19 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub getsetup () {
|
2008-10-10 00:13:19 +02:00
|
|
|
return
|
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => 1,
|
|
|
|
},
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-10-10 00:13:19 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub checkconfig () {
|
2008-10-10 23:09:33 +02:00
|
|
|
if (! length $config{url}) {
|
|
|
|
error(sprintf(gettext("Must specify %s when using the google search plugin"), "url"));
|
|
|
|
}
|
|
|
|
my $uri=URI->new($config{url});
|
|
|
|
if (! $uri || ! defined $uri->host) {
|
|
|
|
error(gettext("Failed to parse url, cannot determine domain name"));
|
2008-10-10 00:13:19 +02:00
|
|
|
}
|
2008-10-10 23:09:33 +02:00
|
|
|
$host=$uri->host;
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-10-10 00:13:19 +02:00
|
|
|
|
|
|
|
my $form;
|
2008-12-17 21:22:16 +01:00
|
|
|
sub pagetemplate (@) {
|
2008-10-10 00:13:19 +02:00
|
|
|
my %params=@_;
|
|
|
|
my $page=$params{page};
|
|
|
|
my $template=$params{template};
|
|
|
|
|
|
|
|
# Add search box to page header.
|
|
|
|
if ($template->query(name => "searchform")) {
|
|
|
|
if (! defined $form) {
|
|
|
|
my $searchform = template("googleform.tmpl", blind_cache => 1);
|
2008-10-10 23:09:33 +02:00
|
|
|
$searchform->param(sitefqdn => $host);
|
2008-10-10 00:13:19 +02:00
|
|
|
$form=$searchform->output;
|
|
|
|
}
|
|
|
|
|
|
|
|
$template->param(searchform => $form);
|
|
|
|
}
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-10-10 00:13:19 +02:00
|
|
|
|
|
|
|
1
|