summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/googlecalendar.pm
blob: 81a3ad677fa9d1d2b7ab66d6b2792e3130f158f1 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::googlecalendar;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 2.00;
  6. sub import { #{{{
  7. hook(type => "getsetup", id => "googlecalendar",
  8. call => \&getsetup);
  9. hook(type => "preprocess", id => "googlecalendar",
  10. call => \&preprocess);
  11. hook(type => "format", id => "googlecalendar",
  12. call => \&format);
  13. } # }}}
  14. sub getsetup () { #{{{
  15. return
  16. plugin => {
  17. safe => 1,
  18. rebuild => undef,
  19. },
  20. } #}}}
  21. sub preprocess (@) { #{{{
  22. my %params=@_;
  23. # Parse the html, looking for the url to embed for the calendar.
  24. # Avoid XSS attacks..
  25. my ($url)=$params{html}=~m#iframe\s+src="http://www\.google\.com/calendar/embed\?([^"<>]+)"#;
  26. if (! defined $url || ! length $url) {
  27. error gettext("failed to find url in html")
  28. }
  29. my ($height)=$params{html}=~m#height="(\d+)"#;
  30. my ($width)=$params{html}=~m#width="(\d+)"#;
  31. return "<div class=\"googlecalendar\" src=\"$url\" height=\"$height\" width=\"$width\"></div>";
  32. } # }}}
  33. sub format (@) { #{{{
  34. my %params=@_;
  35. $params{content}=~s/<div class=\"googlecalendar" src="([^"]+)" height="([^"]+)" width="([^"]+)"><\/div>/gencal($1,$2,$3)/eg;
  36. return $params{content};
  37. } # }}}
  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. } #}}}
  44. 1