package MT::Plugin::ResizeYoutube; # ResizeYoutube - Resize Youtube tags written in the entry # Copyright (c) delphinus use strict; use warnings; use base qw! MT::Plugin !; use MT::Template::Context; our $NAME = "ResizeYoutube"; our $VERSION = "1.00"; my $plugin = MT::Plugin::ResizeYoutube->new ( { name => $NAME, version => $VERSION, key => $NAME, id => $NAME, author_name => "delphinus", author_link => "http://blog.remora.cx/", plugin_link => "http://blog.remora.cx/2010/05/xxxx.html", doc_link => "http://blog.remora.cx/2010/05/xxxx.html", description => <add_plugin( $plugin ); sub instance { $plugin } MT::Template::Context->add_global_filter( resize_youtube => sub { my ( $raw_data, $arg, $ctx ) = @_; $arg or return $raw_data; my $max_width = $arg eq "1" ? 300 : $arg; $raw_data =~ s! (<(?:object|embed)[^>]+) width="(\d+)"\s* height="(\d+)" ! my $before = $1; my $w = $2; my $h = $3; if ( $w > $max_width ) { $h = int( $max_width * $h / $w ); $w = $max_width; } qq|${before}width="$w" height="$h"|; !gex; $raw_data; } ); 1;