summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/googlecalendar.pm
blob: c6409e5e6db3732e1efd3ea4d5232b5dc66c76be (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 => "preprocess", id => "googlecalendar",
  8. call => \&preprocess);
  9. hook(type => "format", id => "googlecalendar",
  10. call => \&format);
  11. } # }}}
  12. sub preprocess (@) { #{{{
  13. my %params=@_;
  14. # Parse the html, looking for the url to embed for the calendar.
  15. # Avoid XSS attacks..
  16. my ($url)=$params{html}=~m#iframe\s+src="http://www\.google\.com/calendar/embed\?([^"<>]+)"#;
  17. if (! defined $url || ! length $url) {
  18. return "[[googlecalendar ".gettext("failed to find url in html")."]]";
  19. }
  20. my ($height)=$params{html}=~m#height="(\d+)"#;
  21. my ($width)=$params{html}=~m#width="(\d+)"#;
  22. return "<div class=\"googlecalendar\" src=\"$url\" height=\"$height\" width=\"$width\"></div>";
  23. } # }}}
  24. sub format (@) { #{{{
  25. my %params=@_;
  26. $params{content}=~s/<div class=\"googlecalendar" src="([^"]+)" height="([^"]+)" width="([^"]+)"><\/div>/gencal($1,$2,$3)/eg;
  27. return $params{content};
  28. } # }}}
  29. sub gencal ($$$) { #{{{
  30. my $url=shift;
  31. my $height=shift;
  32. my $width=shift;
  33. return qq{<iframe src="http://www.google.com/calendar/embed?$url" style=" border-width:0 " width="$width" frameborder="0" height="$height"></iframe>};
  34. } #}}}
  35. 1