]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/googlecalendar.pm
move use
[ikiwiki.git] / IkiWiki / Plugin / googlecalendar.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::googlecalendar;
3
4 use warnings;
5 use strict;
6 use IkiWiki;
7 use IPC::Open2;
8
9 sub import { #{{{
10         hook(type => "preprocess", id => "googlecalendar",
11                 call => \&preprocess);
12         hook(type => "format", id => "googlecalendar",
13                 call => \&format);
14 } # }}}
15
16 sub preprocess (@) { #{{{
17         my %params=@_;
18
19         # Parse the html, looking for the url to embed for the calendar.
20         # Avoid XSS attacks..
21         my ($url)=$params{html}=~m#iframe\s+src="http://www\.google\.com/calendar/embed\?([^"<>]+)"#;
22         if (! defined $url || ! length $url) {
23                 return "[[googlecalendar failed to find url in html]]";
24         }
25         my ($height)=$params{html}=~m#height="(\d+)"#;
26         my ($width)=$params{html}=~m#width="(\d+)"#;
27
28         return "<div class=\"googlecalendar\" src=\"$url\" height=\"$height\" width=\"$width\"></div>";
29 } # }}}
30
31 sub format (@) { #{{{
32         my %params=@_;
33
34         $params{content}=~s/<div class=\"googlecalendar" src="([^"]+)" height="([^"]+)" width="([^"]+)"><\/div>/gencal($1,$2,$3)/eg;
35
36         return $params{content};
37 } # }}}
38
39 sub gencal ($$$) { #{{{
40         my $url=shift;
41         my $height=shift;
42         my $width=shift;
43         return qq{<iframe src="http://www.google.com/calendar/embed?$url" style=" border-width:0 " width="$width" frameborder="0" height="$height"></iframe>};
44 } #}}}
45
46 1