summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2007-08-23 20:14:08 +0000
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2007-08-23 20:14:08 +0000
commit27d029113faf479464db289a71b98cbf5e672793 (patch)
tree72c9dd9fc03c6fb4cede32a2415ac38837175251 /IkiWiki
parent1c033e5d14be9b1002acd7a8a363cf5c97bbabb2 (diff)
* Add embed plugin, which allows embedding content from google maps, video,
calendar, and youtube. Normally, the htmlsanitiser eats these since they use unsafe tags, the embed plugin overrides it for trusted sites. * The googlecalendar plugin is now deprecated, and will be removed eventually. Please switch to using the embed plugin.
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/embed.pm68
1 files changed, 68 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/embed.pm b/IkiWiki/Plugin/embed.pm
new file mode 100644
index 000000000..4fc91d978
--- /dev/null
+++ b/IkiWiki/Plugin/embed.pm
@@ -0,0 +1,68 @@
+#!/usr/bin/perl
+package IkiWiki::Plugin::embed;
+
+use warnings;
+use strict;
+use IkiWiki 2.00;
+
+my $attribr=qr/[^<>"]+/;
+
+# regexp matching known-safe html
+my $safehtml=qr{(
+ # google maps
+ <\s*iframe\s+width="\d+"\s+height="\d+"\s+frameborder="$attribr"\s+
+ scrolling="$attribr"\s+marginheight="\d+"\s+marginwidth="\d+"\s+
+ src="http://maps.google.com/\?$attribr"\s*>\s*</iframe>
+
+ |
+
+ # youtube
+ <\s*object\s+width="\d+"\s+height="\d+"\s*>\s*
+ <\s*param\s+name="movie"\s+value="http://www.youtube.com/v/$attribr"\s*>\s*
+ </param>\s*
+ <\s*param\s+name="wmode"\s+value="transparent"\s*>\s*</param>\s*
+ <embed\s+src="http://www.youtube.com/v/$attribr"\s+
+ type="application/x-shockwave-flash"\s+wmode="transparent"\s+
+ width="\d+"\s+height="\d+"\s*>\s*</embed>\s*</object>
+
+ |
+
+ # google video
+ <\s*embed\s+style="\s*width:\d+px;\s+height:\d+px;\s*"\s+id="$attribr"\s+
+ type="application/x-shockwave-flash"\s+
+ src="http://video.google.com/googleplayer.swf\?$attribr"\s+
+ flashvars=""\s*>\s*</embed>
+
+ |
+
+ # google calendar
+ <\s*iframe\s+src="http://www.google.com/calendar/embed\?src=$attribr"\s+
+ style="\s*border-width:\d+\s*"\s+width="\d+"\s+frameborder="\d+"\s*
+ height="\d+"\s*>\s*</iframe>
+)}sx;
+
+my @embedded;
+
+sub import { #{{{
+ hook(type => "filter", id => "embed", call => \&filter);
+} # }}}
+
+sub embed ($) { #{{{
+ hook(type => "format", id => "embed", call => \&format) unless @embedded;
+ push @embedded, shift;
+ return "<div class=\"embed$#embedded\"></div>";
+} #}}}
+
+sub filter (@) { #{{{
+ my %params=@_;
+ $params{content} =~ s/$safehtml/embed($1)/eg;
+ return $params{content};
+} # }}}
+
+sub format (@) { #{{{
+ my %params=@_;
+ $params{content} =~ s/<div class="embed(\d+)"><\/div>/$embedded[$1]/eg;
+ return $params{content};
+} # }}}
+
+1