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