root/lang/perl/Moxy/trunk/lib/Moxy/Plugin/FlashUseImgTag.pm @ 2891

Revision 2891, 2.0 kB (checked in by tokuhirom, 5 years ago)

lang/perl/Moxy: import Moxy.

Line 
1package Moxy::Plugin::FlashUseImgTag;
2use strict;
3use warnings;
4use base qw/Moxy::Plugin/;
5use HTTP::MobileAgent;
6use HTML::Parser;
7
8sub 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
521;
53__END__
54
55=head1 NAME
56
57Moxy::Plugin::FlashUseImgTag - ezweb can use <img src="/boofy.swf">
58
59=head1 SYNOPSIS
60
61  - module: FlashUseImgTag
62
63=head1 DESCRIPTION
64
65EZweb real machine can use <img src="/boofy.swf" /> style.
66This plugin can simulate it.
67
68This plugin replace img tag to object tag.
69
70=head1 AUTHOR
71
72Kan Fushihara
73
Note: See TracBrowser for help on using the browser.