aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/googlecalendar.pm
blob: 81a3ad677fa9d1d2b7ab66d6b2792e3130f158f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl
package IkiWiki::Plugin::googlecalendar;

use warnings;
use strict;
use IkiWiki 2.00;

sub import { #{{{
	hook(type => "getsetup", id => "googlecalendar",
		call => \&getsetup);
	hook(type => "preprocess", id => "googlecalendar",
		call => \&preprocess);
	hook(type => "format", id => "googlecalendar",
		call => \&format);
} # }}}

sub getsetup () { #{{{
	return
		plugin => {
			safe => 1,
			rebuild => undef,
		},
} #}}}

sub preprocess (@) { #{{{
	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) {
		error gettext("failed to find url in html")
	}
	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>";
} # }}}

sub format (@) { #{{{
        my %params=@_;

	$params{content}=~s/<div class=\"googlecalendar" src="([^"]+)" height="([^"]+)" width="([^"]+)"><\/div>/gencal($1,$2,$3)/eg;

        return $params{content};
} # }}}

sub gencal ($$$) { #{{{
	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>};
} #}}}

1