OSDN Git Service

fix web_charset handling (ticket: #18509)
authorishikawa <ishikawa@180c8125-5b33-4295-ad04-72a68a15b4cc>
Thu, 24 Sep 2009 14:48:21 +0000 (14:48 +0000)
committerishikawa <ishikawa@180c8125-5b33-4295-ad04-72a68a15b4cc>
Thu, 24 Sep 2009 14:48:21 +0000 (14:48 +0000)
31 files changed:
ChangeLog
lib/Keitairc/Config.pm
lib/Keitairc/View.pm
lib/templates/default/404.html
lib/templates/default/address.html
lib/templates/default/all.html
lib/templates/default/index.html
lib/templates/default/location.html
lib/templates/default/location_receiver.html
lib/templates/default/login_icc.html
lib/templates/default/login_imodeid.html
lib/templates/default/logout.html
lib/templates/default/mail.html
lib/templates/default/nick.html
lib/templates/default/phone.html
lib/templates/default/postme.html
lib/templates/default/recent.html
lib/templates/default/root.html
lib/templates/default/topic.html
lib/templates/default/unread.html
lib/templates/default/url.html
lib/templates/default/url_session.html
lib/templates/ipod-sjis/404.html
lib/templates/ipod-sjis/all.html
lib/templates/ipod-sjis/index.html
lib/templates/ipod-sjis/location_receiver.html
lib/templates/ipod-sjis/logout.html
lib/templates/ipod-sjis/nick.html
lib/templates/ipod-sjis/recent.html
lib/templates/ipod-sjis/root.html
lib/templates/ipod-sjis/topic.html

index 7d97edd..d77963a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-09-24  ISHIKAWA Mutsumi <ishikawa@hanzubon.jp>
+
+       * lib/Keitairc/Config.pm, lib/Keitairc/View.pm,
+         lib/templates/{default,ipod-sjis}/*:
+         web_charset \e$B$r;XDj$7$?$H$-$K$A$c$s$H;XDj$I$*$j$K$J$k$h$&$K\e(B
+         \e$B%G%#%U%)%k%H$N\e(Bcharset\e$B%O%s%I%j%s%0%k!<%A%s!"%F%s%W%l!<%H$N\e(B
+         \e$B%(%s%3!<%G%#%s%0$NJQ49=hM}$rDI2C!#\e(Bmeta \e$B%X%C%@$N\e(Bcharset\e$B$r\e(B
+         \e$B30It$+$i%;%C%H$G$-$k$h$&$K%F%s%W%l!<%H$r99?7\e(B(ticket: #18509)
+
 2009-07-16  ISHIKAWA Mutsumi <ishikawa@hanzubon.jp>
 
        * lib/templates/ipod-sjis/index.html: add irc command input
index 6b1cc79..080bc3e 100644 (file)
@@ -1,6 +1,6 @@
 # -*- mode: perl; coding: utf-8 -*-
 # Keitairc::Config
-# $Id: Config.pm,v 1.33 2009-09-24 14:18:23 morimoto Exp $
+# $Id: Config.pm,v 1.34 2009-09-24 14:48:21 ishikawa Exp $
 # $Source: /home/ishikawa/work/keitairc/tmp/keitairc/lib/Keitairc/Config.pm,v $
 #
 # Copyright (c) 2008 Jun Morimoto <morimoto@mrmt.net>
@@ -9,6 +9,7 @@
 package Keitairc::Config;
 use AppConfig qw(:argcount);
 use Cwd;
+use Encode::MIME::Name;
 use strict;
 use warnings;
 our @ISA = qw(AppConfig);
@@ -164,4 +165,10 @@ sub file{
        Keitairc::Log::log("$file does not exist");
 }
 
+################################################################
+sub content_charset{
+       my $me = shift;
+       Encode::MIME::Name::get_mime_name(Encode::resolve_alias($me->web_charset()));
+}
+
 1;
index 9be0475..8b4111b 100644 (file)
@@ -1,6 +1,6 @@
 # -*- mode: perl; coding: utf-8 -*-
 # Keitairc::View
-# $Id: View.pm,v 1.25 2009-07-15 13:47:01 ishikawa Exp $
+# $Id: View.pm,v 1.26 2009-09-24 14:48:21 ishikawa Exp $
 # $Source: /home/ishikawa/work/keitairc/tmp/keitairc/lib/Keitairc/View.pm,v $
 #
 # Copyright (c) 2008 Jun Morimoto <morimoto@mrmt.net>
@@ -81,6 +81,7 @@ sub template{
        $p->{version} = $me->{Config}->version();
        $p->{common_header} = $me->{Config}->common_header();
        $p->{extra_header} = $me->{Config}->extra_header();
+       $p->{content_charset} = $me->{Config}->content_charset();
 
        if($me->{ClientInfo}->is_mobile){
                $p->{fontsize} = $me->{Config}->mobile_fontsize();
@@ -109,10 +110,19 @@ sub template{
                $arch = 'ipod-sjis';
        }
 
+       # Note: ishikawa
+       # 現状、varsの中は既にencodeされた文字列が入ってきているはずだけど
+       # 内部コードのままで、最後の output を encode するのが本来はいい
+       # のではないかと思う。
+       # が、今いじるとあちこち影響でそうなので 2.0 出てから直す。
        if (my $filename = $me->template_path("$arch/$template")) {
                my $t = new HTML::Template(
                        filename => $filename,
                        die_on_bad_params => 0,
+                       filter => sub {
+                               my $text_ref = shift;
+                               Encode::from_to($$text_ref, 'shift_jis', $me->{Config}->web_charset());
+                       },
                        cache => 1);
                $t->param($p);
 
@@ -155,7 +165,7 @@ sub public{
 
        # not found
        my $response = HTTP::Response->new(404);
-       $response->push_header('Content-type', 'text/html; charset=Shift_JIS');
+       $response->push_header('Content-type', 'text/html; charset=' . $me->{Config}->content_charset());
        $response->content($me->template('404.html', { action => $file }));
        return $response;
 }
@@ -166,7 +176,7 @@ sub render{
        my $template = shift;
        my $vars = shift || {};
        my $response = HTTP::Response->new(200);
-       $vars->{content_type} |= 'text/html; charset=Shift_JIS';
+       $vars->{content_type} |= 'text/html; charset=' . $me->{Config}->content_charset();
        $response->push_header('Content-type', $vars->{content_type});
        $response->content($me->template($template, $vars));
        $response;
index 4958652..73b5417 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <!-- tmpl_var extra_header -->
     <title><!-- tmpl_var title --></title>
index 41364d9..f6ea1d3 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <!-- tmpl_var extra_header -->
     <title><!-- tmpl_var title -->: \92n\90}\95\\8e¦</title>
index d4c78d0..1fd3fe8 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <!-- tmpl_var extra_header -->
     <title><!-- tmpl_var title -->: <!-- tmpl_var channel_compact --></title>
index 36e57dd..3a5ad2b 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <!-- tmpl_var extra_header -->
     <title><!-- tmpl_var title --></title>
index 66aa01f..7d3a54f 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <!-- tmpl_var extra_header -->
     <title><!-- tmpl_var title -->: <!-- tmpl_var channel_compact --></title>
index 4088df4..8a1f8ad 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <!-- tmpl_var extra_header -->
     <title><!-- tmpl_var title -->: <!-- tmpl_var channel_compact --></title>
index 8787ca8..d0d45f5 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <!-- tmpl_var extra_header -->
     <title><!-- tmpl_var title -->: icc\95\\8e¦</title>
index 592b53d..a8ffa0c 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <!-- tmpl_var extra_header -->
     <title><!-- tmpl_var title -->: icc\95\\8e¦</title>
index 7808440..8e6415e 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <!-- tmpl_var extra_header -->
     <title><!-- tmpl_var title -->: \83\8d\83O\83A\83E\83g</title>
index b17cc0d..995c2b3 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <!-- tmpl_var extra_header -->
     <title><!-- tmpl_var title -->: mail <!-- tmpl_var mail --></title>
index 1c54b6e..99f55d7 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <!-- tmpl_var extra_header -->
     <title><!-- tmpl_var title --></title>
index a443a15..789519c 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <!-- tmpl_var extra_header -->
     <title><!-- tmpl_var title -->: phone <!-- tmpl_var phone --></title>
index 633bcdf..a85808f 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <!-- tmpl_var extra_header -->
     <title><!-- tmpl_var title -->: postme</title>
index 9dd22d9..4bc49ca 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <!-- tmpl_var extra_header -->
     <title><!-- tmpl_var title --></title>
index 01918f7..b5bf8de 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <!-- tmpl_var extra_header -->
     <title><!-- tmpl_var title --></title>
index f47d4b5..891291a 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <!-- tmpl_var extra_header -->
     <title><!-- tmpl_var title --></title>
index 39a11db..b19ec2c 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <!-- tmpl_var extra_header -->
     <title><!-- tmpl_var title -->: <!-- tmpl_var channel_compact --></title>
index a35d736..57f9017 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <!-- tmpl_var extra_header -->
     <title><!-- tmpl_var title -->: URL <!-- tmpl_var url --></title>
index ae07b02..93387b4 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <!-- tmpl_var extra_header -->
     <title><!-- tmpl_var title -->: URL <!-- tmpl_var url --></title>
index 6eb69f4..5071acd 100644 (file)
@@ -2,7 +2,7 @@
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
     <style type="text/css" media="screen">
index b9c8609..7f1910c 100644 (file)
@@ -2,7 +2,7 @@
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
     <style type="text/css" media="screen">
index b30801e..8ce3ea5 100644 (file)
@@ -2,7 +2,7 @@
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
     <style type="text/css" media="screen">
index 8b8edc7..65e163f 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
     <style type="text/css" media="screen">
index f02da20..02e102e 100644 (file)
@@ -2,7 +2,7 @@
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
     <style type="text/css" media="screen">
index 7ac23ff..3a5a58c 100644 (file)
@@ -2,7 +2,7 @@
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
     <style type="text/css" media="screen">
index ccefd75..e6558d0 100644 (file)
@@ -2,7 +2,7 @@
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
     <style type="text/css" media="screen">
index 5617265..4d76149 100644 (file)
@@ -2,7 +2,7 @@
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
     <style type="text/css" media="screen">
index d06822f..cafc72a 100644 (file)
@@ -2,7 +2,7 @@
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
   <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
+    <meta http-equiv="Content-Type" content="text/html; charset=<!-- tmpl_var content_charset -->" />
     <!-- tmpl_var common_header -->
     <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
     <style type="text/css" media="screen">