| 1 | package Moxy::Plugin::FlashUseImgTag; |
|---|
| 2 | use strict; |
|---|
| 3 | use warnings; |
|---|
| 4 | use base qw/Moxy::Plugin/; |
|---|
| 5 | use HTTP::MobileAgent; |
|---|
| 6 | use HTML::Parser; |
|---|
| 7 | |
|---|
| 8 | sub register { |
|---|
| 9 | my ($class, $context) = @_; |
|---|
| 10 | |
|---|
| 11 | $context->register_hook( |
|---|
| 12 | response_filter_E => sub { |
|---|
| 13 | my ( $context, $args ) = @_; |
|---|
| 14 | |
|---|
| 15 | # only for html. |
|---|
| 16 | return unless (($args->{response}->header('Content-Type')||'') =~ /html/); |
|---|
| 17 | |
|---|
| 18 | my $output = ''; |
|---|
| 19 | my $parser = HTML::Parser->new( |
|---|
| 20 | api_version => 3, |
|---|
| 21 | start_h => [ sub { |
|---|
| 22 | my ($tagname, $attr, $orig) = @_; |
|---|
| 23 | |
|---|
| 24 | if ($tagname =~ /^img$/i && $attr->{src} =~ /\.swf$/) { |
|---|
| 25 | $output .= qq| |
|---|
| 26 | <object data="@{[$attr->{src}]}" width="@{[$attr->{width}]}" height="@{[$attr->{height}]}" |
|---|
| 27 | type="application/x-shockwave-flash"> |
|---|
| 28 | <param name="bgcolor" value="#ffffff" /> |
|---|
| 29 | <param name="loop" value="off" /> |
|---|
| 30 | <param name="quality" value="high" /> |
|---|
| 31 | <param name="salign" value="t" /> |
|---|
| 32 | </object> |
|---|
| 33 | |; |
|---|
| 34 | } else { |
|---|
| 35 | $output .= $orig; |
|---|
| 36 | return; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | }, "tagname, attr, text" ], |
|---|
| 40 | end_h => [ sub { $output .= shift }, "text"], |
|---|
| 41 | text_h => [ sub { $output .= shift }, "text"], |
|---|
| 42 | ); |
|---|
| 43 | |
|---|
| 44 | $parser->boolean_attribute_value('__BOOLEAN__'); |
|---|
| 45 | $parser->parse(${ $args->{content_ref} }); |
|---|
| 46 | |
|---|
| 47 | ${ $args->{content_ref} } = $output; |
|---|
| 48 | } |
|---|
| 49 | ); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | 1; |
|---|
| 53 | __END__ |
|---|
| 54 | |
|---|
| 55 | =head1 NAME |
|---|
| 56 | |
|---|
| 57 | Moxy::Plugin::FlashUseImgTag - ezweb can use <img src="/boofy.swf"> |
|---|
| 58 | |
|---|
| 59 | =head1 SYNOPSIS |
|---|
| 60 | |
|---|
| 61 | - module: FlashUseImgTag |
|---|
| 62 | |
|---|
| 63 | =head1 DESCRIPTION |
|---|
| 64 | |
|---|
| 65 | EZweb real machine can use <img src="/boofy.swf" /> style. |
|---|
| 66 | This plugin can simulate it. |
|---|
| 67 | |
|---|
| 68 | This plugin replace img tag to object tag. |
|---|
| 69 | |
|---|
| 70 | =head1 AUTHOR |
|---|
| 71 | |
|---|
| 72 | Kan Fushihara |
|---|
| 73 | |
|---|