]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/googlecalendar.pm
* Only try postsignin if no other action matched. Fixes a bug where the
[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 => "preprocess", id => "googlecalendar",
10                 call => \&preprocess);
11         hook(type => "format", id => "googlecalendar",
12                 call => \&format);
13 } # }}}
15 sub preprocess (@) { #{{{
16         my %params=@_;
18         # Parse the html, looking for the url to embed for the calendar.
19         # Avoid XSS attacks..
20         my ($url)=$params{html}=~m#iframe\s+src="http://www\.google\.com/calendar/embed\?([^"<>]+)"#;
21         if (! defined $url || ! length $url) {
22                 return "[[googlecalendar ".gettext("failed to find url in html")."]]";
23         }
24         my ($height)=$params{html}=~m#height="(\d+)"#;
25         my ($width)=$params{html}=~m#width="(\d+)"#;
27         return "<div class=\"googlecalendar\" src=\"$url\" height=\"$height\" width=\"$width\"></div>";
28 } # }}}
30 sub format (@) { #{{{
31         my %params=@_;
33         $params{content}=~s/<div class=\"googlecalendar" src="([^"]+)" height="([^"]+)" width="([^"]+)"><\/div>/gencal($1,$2,$3)/eg;
35         return $params{content};
36 } # }}}
38 sub gencal ($$$) { #{{{
39         my $url=shift;
40         my $height=shift;
41         my $width=shift;
42         return qq{<iframe src="http://www.google.com/calendar/embed?$url" style=" border-width:0 " width="$width" frameborder="0" height="$height"></iframe>};
43 } #}}}
45 1