2008-10-10 00:13:19 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
package IkiWiki::Plugin::google;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2008-12-23 22:34:19 +01:00
|
|
|
use IkiWiki 3.00;
|
2008-10-10 00:13:19 +02:00
|
|
|
use URI;
|
|
|
|
|
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,
|
2010-02-12 10:22:15 +01:00
|
|
|
section => "web",
|
2008-10-10 00:13:19 +02:00
|
|
|
},
|
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}) {
|
2009-01-26 19:08:25 +01:00
|
|
|
error(sprintf(gettext("Must specify %s when using the %s plugin"), "url", 'google'));
|
2008-10-10 23:09:33 +02:00
|
|
|
}
|
2010-04-25 02:22:20 +02:00
|
|
|
|
|
|
|
# This is a mass dependency, so if the search form template
|
|
|
|
# changes, every page is rebuilt.
|
2010-04-25 02:41:35 +02:00
|
|
|
add_depends("", "templates/googleform.tmpl");
|
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) {
|
2010-04-25 02:22:20 +02:00
|
|
|
my $searchform = template("googleform.tmpl", blind_cache => 1);
|
2009-10-29 23:05:58 +01:00
|
|
|
$searchform->param(url => $config{url});
|
2010-05-02 19:49:56 +02:00
|
|
|
$searchform->param(html5 => $config{html5});
|
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
|