Changeset 9664 for lang/perl/Moxy/branches
- Timestamp:
- 04/18/08 08:33:07 (5 years ago)
- Location:
- lang/perl/Moxy/branches/CC
- Files:
-
- 4 modified
-
config.yaml (modified) (1 diff)
-
lib/Moxy/Plugin/Filter/Pictogram.pm (modified) (1 diff)
-
lib/Moxy/Plugin/Server.pm (modified) (3 diffs)
-
lib/Moxy/Util.pm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Moxy/branches/CC/config.yaml
r9654 r9664 16 16 - module: Filter::XMLisHTML 17 17 - module: Filter::UserAgentSwitcher 18 #- module: Filter::Pictogram18 - module: Filter::Pictogram 19 19 # - module: Filter::HTMLWidth 20 20 # - module: Filter::HTTPEnv -
lang/perl/Moxy/branches/CC/lib/Moxy/Plugin/Filter/Pictogram.pm
r9648 r9664 2 2 use strict; 3 3 use warnings; 4 use base qw/ Class::Component::Plugin/;4 use base qw/Moxy::Plugin/; 5 5 use Moxy::Util; 6 6 use Path::Class; 7 7 use HTML::ReplacePictogramMobileJp; 8 use HTTP::MobileAttribute; 8 9 9 sub register { 10 my ($class, $context) = @_; 10 sub response_filter :Hook('response_filter') { 11 my ( $self, $context, $args, ) = @_; 12 return unless ( ( $args->{response}->header('Content-Type') || '' ) =~ /html/ ); 13 return if $args->{mobile_attribute}->is_non_mobile; 11 14 12 # registering pictogram replacer. 13 for my $carrier (qw/I E V H/) { 14 $context->register_hook( "response_filter_$carrier" => sub { 15 my ($context, $args, ) = @_; 16 return unless (($args->{response}->header('Content-Type')||'') =~ /html/); 15 my $carrier = $args->{mobile_attribute}->carrier; 17 16 18 my $charset = Moxy::Util->detect_charset($args->{response}, $args->{content_ref}); 19 $charset = ($charset =~ /utf-?8/i) ? 'utf8' : 'sjis'; 17 my $charset = 18 Moxy::Util->detect_charset( $args->{response}, $args->{content_ref} ); 19 $charset = ( $charset =~ /utf-?8/i ) ? 'utf8' : 'sjis'; 20 20 21 ${ $args->{content_ref} } = HTML::ReplacePictogramMobileJp->replace( 22 html => ${ $args->{content_ref} }, 23 carrier => $carrier, 24 charset => $charset, 25 callback => sub { 26 my ( $unicode, $carrier ) = @_; 21 $args->{response}->content( 22 HTML::ReplacePictogramMobileJp->replace( 23 html => $args->{response}->content, 24 carrier => $carrier, 25 charset => $charset, 26 callback => sub { 27 my ( $unicode, $carrier ) = @_; 27 28 28 my $pict_html = $class->render_template( $context, 'pict.tmpl' ); 29 return sprintf( $pict_html, $carrier, $unicode, $unicode ); 30 } 31 ); 32 ${ $args->{content_ref} }; 33 }); 29 my $pict_html = 30 $self->render_template( $context, 'pict.tmpl' ); 31 return sprintf( $pict_html, $carrier, $unicode, $unicode ); 32 } 33 ) 34 ); 35 } 36 37 sub deliver_pictogram :Hook('request_filter') { 38 my ($self, $context, $args) = @_; 39 die "request missing" unless $args->{request}; 40 41 if ($args->{request}->uri =~ m{http://pictogram\.moxy/([IEV])/([0-9A-F]{4}).gif}) { 42 my $content = file($self->assets_path($context), 'image', $1, "$2.gif")->slurp; 43 44 my $response = HTTP::Response->new( 200, 'ok' ); 45 $response->header( 'Expires' => 'Thu, 15 Apr 2030 20:00:00 GMT' ); 46 $response->content_type("image/gif"); 47 $response->content($content); 48 $response; 34 49 } 35 36 # deliver pictogram37 $context->register_hook(request_filter => sub {38 my ($context, $args) = @_;39 die "request missing" unless $args->{request};40 41 if ($args->{request}->uri =~ m{http://pictogram\.moxy/([IEV])/([0-9A-F]{4}).gif}) {42 my $content = file($class->assets_path($context), 'image', $1, "$2.gif")->slurp;43 44 my $response = HTTP::Response->new( 200, 'ok' );45 $response->header( 'Expires' => 'Thu, 15 Apr 2030 20:00:00 GMT' );46 $response->content_type("image/gif");47 $response->content($content);48 $response;49 }50 });51 50 } 52 51 -
lang/perl/Moxy/branches/CC/lib/Moxy/Plugin/Server.pm
r9654 r9664 15 15 use URI::Heuristic qw(uf_uristr); 16 16 use HTTP::MobileAttribute plugins => [ 17 qw/CarrierLetter /17 qw/CarrierLetter IS/ 18 18 ]; 19 19 our @EXPORT = qw/rewrite handle_request render_control_panel/; … … 216 216 } 217 217 ); 218 my $mobile_attribute = HTTP::MobileAttribute->new($req->header('User-Agent')); 218 219 my $agent = $context->get_ua_info($req->header('User-Agent')); 219 my $carrier = $ agent->{agent} ? HTTP::MobileAttribute->new($agent->{agent})->carrier : 'N';220 my $carrier = $mobile_attribute->carrier; 220 221 for my $hook ('request_filter', "request_filter_$carrier") { 221 222 my $response = $context->run_hook_and_get_response( 222 223 $hook, 223 224 +{ 224 request => $req,# HTTP::Request object225 agent => $agent,226 user => $args{user_id},225 request => $req, # HTTP::Request object 226 mobile_attribute => $mobile_attribute, 227 user => $args{user_id}, 227 228 } 228 229 ); … … 239 240 ); 240 241 my $response = $ua->request($req); 241 for my $hook ( 'response_filter', "response_filter_$carrier") {242 for my $hook ( 'response_filter', "response_filter_$carrier" ) { 242 243 $context->run_hook( 243 244 $hook, 244 { response => $response, # HTTP::Response object 245 agent => $agent, 246 user => $args{user_id}, 245 { 246 response => $response, # HTTP::Response object 247 mobile_attribute => $mobile_attribute, 248 user => $args{user_id}, 247 249 } 248 250 ); -
lang/perl/Moxy/branches/CC/lib/Moxy/Util.pm
r3964 r9664 23 23 24 24 sub detect_charset { 25 my ($class, $response , $body) = @_;25 my ($class, $response) = @_; 26 26 27 27 my $charset; … … 29 29 $charset = $1; 30 30 } 31 $charset ||= ( $ body=~ /<\?xml version="1.0" encoding="([\w\-]+)"\?>/ )[0];32 $charset ||= ( $ body=~ m!<meta http-equiv="Content-Type" content=".*charset=([\w\-]+)"!i )[0];33 $charset ||= $Detector->($ body);31 $charset ||= ( $response->content() =~ /<\?xml version="1.0" encoding="([\w\-]+)"\?>/ )[0]; 32 $charset ||= ( $response->content() =~ m!<meta http-equiv="Content-Type" content=".*charset=([\w\-]+)"!i )[0]; 33 $charset ||= $Detector->($response->content()); 34 34 $charset ||= 'utf-8'; 35 35
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)