2006-09-09 09:11:51 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
package IkiWiki::Plugin::googlecalendar;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2008-12-23 22:34:19 +01:00
|
|
|
use IkiWiki 3.00;
|
2006-09-09 09:11:51 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub import {
|
2008-08-03 22:40:12 +02:00
|
|
|
hook(type => "getsetup", id => "googlecalendar",
|
|
|
|
call => \&getsetup);
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "preprocess", id => "googlecalendar",
|
2006-09-09 09:11:51 +02:00
|
|
|
call => \&preprocess);
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "format", id => "googlecalendar",
|
2006-09-09 09:11:51 +02:00
|
|
|
call => \&format);
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-09-09 09:11:51 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub getsetup () {
|
2008-08-03 22:40:12 +02:00
|
|
|
return
|
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => undef,
|
|
|
|
},
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-08-03 22:40:12 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub preprocess (@) {
|
2006-09-09 09:11:51 +02:00
|
|
|
my %params=@_;
|
|
|
|
|
|
|
|
# Parse the html, looking for the url to embed for the calendar.
|
|
|
|
# Avoid XSS attacks..
|
|
|
|
my ($url)=$params{html}=~m#iframe\s+src="http://www\.google\.com/calendar/embed\?([^"<>]+)"#;
|
|
|
|
if (! defined $url || ! length $url) {
|
2008-07-13 21:05:34 +02:00
|
|
|
error gettext("failed to find url in html")
|
2006-09-09 09:11:51 +02:00
|
|
|
}
|
|
|
|
my ($height)=$params{html}=~m#height="(\d+)"#;
|
|
|
|
my ($width)=$params{html}=~m#width="(\d+)"#;
|
|
|
|
|
|
|
|
return "<div class=\"googlecalendar\" src=\"$url\" height=\"$height\" width=\"$width\"></div>";
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-09-09 09:11:51 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub format (@) {
|
2006-09-09 09:11:51 +02:00
|
|
|
my %params=@_;
|
|
|
|
|
|
|
|
$params{content}=~s/<div class=\"googlecalendar" src="([^"]+)" height="([^"]+)" width="([^"]+)"><\/div>/gencal($1,$2,$3)/eg;
|
|
|
|
|
|
|
|
return $params{content};
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-09-09 09:11:51 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub gencal ($$$) {
|
2006-09-09 09:11:51 +02:00
|
|
|
my $url=shift;
|
|
|
|
my $height=shift;
|
|
|
|
my $width=shift;
|
|
|
|
return qq{<iframe src="http://www.google.com/calendar/embed?$url" style=" border-width:0 " width="$width" frameborder="0" height="$height"></iframe>};
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-09-09 09:11:51 +02:00
|
|
|
|
|
|
|
1
|