]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/googlecalendar.pm
po: actually use pofiles() function, to enhance code clarity
[git.ikiwiki.info.git] / IkiWiki / Plugin / googlecalendar.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::googlecalendar;
4 use warnings;
5 use strict;
6 use IkiWiki 2.00;
8 sub import { #{{{
9         hook(type => "getsetup", id => "googlecalendar",
10                 call => \&getsetup);
11         hook(type => "preprocess", id => "googlecalendar",
12                 call => \&preprocess);
13         hook(type => "format", id => "googlecalendar",
14                 call => \&format);
15 } # }}}
17 sub getsetup () { #{{{
18         return
19                 plugin => {
20                         safe => 1,
21                         rebuild => undef,
22                 },
23 } #}}}
25 sub preprocess (@) { #{{{
26         my %params=@_;
28         # Parse the html, looking for the url to embed for the calendar.
29         # Avoid XSS attacks..
30         my ($url)=$params{html}=~m#iframe\s+src="http://www\.google\.com/calendar/embed\?([^"<>]+)"#;
31         if (! defined $url || ! length $url) {
32                 error gettext("failed to find url in html")
33         }
34         my ($height)=$params{html}=~m#height="(\d+)"#;
35         my ($width)=$params{html}=~m#width="(\d+)"#;
37         return "<div class=\"googlecalendar\" src=\"$url\" height=\"$height\" width=\"$width\"></div>";
38 } # }}}
40 sub format (@) { #{{{
41         my %params=@_;
43         $params{content}=~s/<div class=\"googlecalendar" src="([^"]+)" height="([^"]+)" width="([^"]+)"><\/div>/gencal($1,$2,$3)/eg;
45         return $params{content};
46 } # }}}
48 sub gencal ($$$) { #{{{
49         my $url=shift;
50         my $height=shift;
51         my $width=shift;
52         return qq{<iframe src="http://www.google.com/calendar/embed?$url" style=" border-width:0 " width="$width" frameborder="0" height="$height"></iframe>};
53 } #}}}
55 1