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