From c1d429c3f8683489661249a2d60d3e83ec2e4324 Mon Sep 17 00:00:00 2001 From: senator Date: Mon, 7 Mar 2011 13:15:03 -0500 Subject: [PATCH] Subclass CGI (and create TT plugin wrapper for the subclass) to get utf8 params The CGI module configuration option -utf8 just doesn't seem to do the trick. I could have missed something, but this works and isn't too awful. --- Open-ILS/src/perlmods/lib/OpenILS/WWW/CGIUTF8.pm | 20 ++++++++++++++++++++ .../src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 4 ++-- Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm | 5 ++++- .../src/perlmods/lib/OpenILS/WWW/EGWeb/CGIUTF8.pm | 17 +++++++++++++++++ .../web/templates/default/opac/parts/header.tt2 | 2 +- .../templates/default/opac/parts/place_hold.tt2 | 3 +-- 6 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 Open-ILS/src/perlmods/lib/OpenILS/WWW/CGIUTF8.pm create mode 100644 Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb/CGIUTF8.pm diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/CGIUTF8.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/CGIUTF8.pm new file mode 100644 index 0000000..baa43eb --- /dev/null +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/CGIUTF8.pm @@ -0,0 +1,20 @@ +package OpenILS::WWW::CGIUTF8; +use strict; +use warnings; +use base qw(CGI); +use Encode; + +sub param { + my ($self, $k) = @_; + + return map { Encode::decode_utf8($_) } CGI::param($k) if wantarray; + return Encode::decode_utf8(CGI::param($k)); +} + +sub param_bin { + my $self = shift; + + return CGI::param(@_); +} + +1; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index bb1371b..597bf96 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -1,6 +1,5 @@ package OpenILS::WWW::EGCatLoader; use strict; use warnings; -use CGI; use XML::LibXML; use URI::Escape; use Digest::MD5 qw(md5_hex); @@ -14,6 +13,7 @@ use OpenILS::Application::AppUtils; use OpenILS::Utils::CStoreEditor qw/:funcs/; use OpenILS::Utils::Fieldmapper; use DateTime::Format::ISO8601; +use OpenILS::WWW::CGIUTF8; # EGCatLoader sub-modules use OpenILS::WWW::EGCatLoader::Util; @@ -33,7 +33,7 @@ sub new { $self->apache($apache); $self->ctx($ctx); - $self->cgi(CGI->new); + $self->cgi(new OpenILS::WWW::CGIUTF8); OpenILS::Utils::CStoreEditor->init; # just in case $self->editor(new_editor()); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm index 4064ec2..6a7f49a 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm @@ -51,7 +51,10 @@ sub handler { OUTPUT => ($as_xml) ? sub { parse_as_xml($r, $ctx, @_); } : $r, INCLUDE_PATH => $ctx->{template_paths}, DEBUG => $ctx->{debug_template}, - PLUGINS => {EGI18N => 'OpenILS::WWW::EGWeb::I18NFilter'} + PLUGINS => { + EGI18N => 'OpenILS::WWW::EGWeb::I18NFilter', + CGIUTF8 => 'OpenILS::WWW::EGWeb::CGIUTF8' + } }); unless($tt->process($template, {ctx => $ctx, l => set_text_handler($ctx, $r)})) { diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb/CGIUTF8.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb/CGIUTF8.pm new file mode 100644 index 0000000..e90d5d9 --- /dev/null +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb/CGIUTF8.pm @@ -0,0 +1,17 @@ +package OpenILS::WWW::EGWeb::CGIUTF8; + +# This is just a wrapper for TT around the real package, +# which is OpenILS::WWW::CGIUTF8 + +use strict; +use warnings; +use base 'Template::Plugin'; +use OpenILS::WWW::CGIUTF8; + +sub new { + my $class = shift; + my $context = shift; + new OpenILS::WWW::CGIUTF8(@_); +} + +1; diff --git a/Open-ILS/web/templates/default/opac/parts/header.tt2 b/Open-ILS/web/templates/default/opac/parts/header.tt2 index 866ce2d..7b8eec4 100644 --- a/Open-ILS/web/templates/default/opac/parts/header.tt2 +++ b/Open-ILS/web/templates/default/opac/parts/header.tt2 @@ -1,6 +1,6 @@ [%- USE money = format(l('$%.2f')); USE date; - USE CGI; + USE CGI = CGIUTF8; USE EGI18N; SET DATE_FORMAT = l('%m/%d/%Y'); diff --git a/Open-ILS/web/templates/default/opac/parts/place_hold.tt2 b/Open-ILS/web/templates/default/opac/parts/place_hold.tt2 index 84d8e71..f3d8ef3 100644 --- a/Open-ILS/web/templates/default/opac/parts/place_hold.tt2 +++ b/Open-ILS/web/templates/default/opac/parts/place_hold.tt2 @@ -1,5 +1,4 @@ -[% USE CGI; - PROCESS "default/opac/parts/marc_misc.tt2"; +[% PROCESS "default/opac/parts/marc_misc.tt2"; attrs = {marc_xml => ctx.marc_xml}; PROCESS get_marc_attrs args=attrs; %] -- 1.7.2.5