<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
package IkiWiki::Plugin::googlecalendar;

use warnings;
use strict;
use IkiWiki 2.00;

sub import { #{{{
	hook(type =&gt; "preprocess", id =&gt; "googlecalendar",
		call =&gt; \&amp;preprocess);
	hook(type =&gt; "format", id =&gt; "googlecalendar",
		call =&gt; \&amp;format);
} # }}}

sub preprocess (@) { #{{{
	my %params=@_;

	# Parse the html, looking for the url to embed for the calendar.
	# Avoid XSS attacks..
	my ($url)=$params{html}=~m#iframe\s+src="http://www\.google\.com/calendar/embed\?([^"&lt;&gt;]+)"#;
	if (! defined $url || ! length $url) {
		error gettext("failed to find url in html")
	}
	my ($height)=$params{html}=~m#height="(\d+)"#;
	my ($width)=$params{html}=~m#width="(\d+)"#;

	return "&lt;div class=\"googlecalendar\" src=\"$url\" height=\"$height\" width=\"$width\"&gt;&lt;/div&gt;";
} # }}}

sub format (@) { #{{{
        my %params=@_;

	$params{content}=~s/&lt;div class=\"googlecalendar" src="([^"]+)" height="([^"]+)" width="([^"]+)"&gt;&lt;\/div&gt;/gencal($1,$2,$3)/eg;

        return $params{content};
} # }}}

sub gencal ($$$) { #{{{
	my $url=shift;
	my $height=shift;
	my $width=shift;
	return qq{&lt;iframe src="http://www.google.com/calendar/embed?$url" style=" border-width:0 " width="$width" frameborder="0" height="$height"&gt;&lt;/iframe&gt;};
} #}}}

1
</pre></body></html>