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