From c6b2ae2f72b3f546481572971de74859d46b15a7 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 14 Mar 2014 09:16:16 +0100 Subject: [PATCH] Bug 11944: Remove all utf8 filter from templates This patch - removes all html_entity usages in tt file which hide utf8 bugs - removes all encode utf8 in tt plugins because we should get correctly marked data from DBIC and other sources directly (cf plugin EncodeUTF8 used in renew.tt) - adds some cleanup in C4::Templates::output: we now use perl utf8 file handler output so we don't need to decode tt variables manually. Signed-off-by: Paola Rossi Signed-off-by: Bernardo Gonzalez Kriegel --- C4/Charset.pm | 2 +- C4/Templates.pm | 2 +- Koha/Template/Plugin/AuthorisedValues.pm | 8 +++++++- Koha/Template/Plugin/Branches.pm | 4 ++-- Koha/Template/Plugin/EncodeUTF8.pm | 2 +- Koha/Template/Plugin/ItemTypes.pm | 2 +- cataloguing/addbiblio.pl | 2 +- koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc | 4 ++-- koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc | 2 +- koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt | 7 +++---- koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt | 2 +- koha-tmpl/opac-tmpl/prog/en/modules/opac-account.tt | 2 +- 12 files changed, 22 insertions(+), 17 deletions(-) diff --git a/C4/Charset.pm b/C4/Charset.pm index acad92a..1774be6 100644 --- a/C4/Charset.pm +++ b/C4/Charset.pm @@ -560,7 +560,7 @@ sub _marc_marc8_to_utf8 { # occurs, upgrade the string in place. Moral of the story seems to be # that pack("U", ...) is better than chr(...) if you need to guarantee # that the resulting string is UTF-8. - utf8::upgrade($utf8sf); + $utf8sf = Encode::encode('UTF-8', $utf8sf); } push @converted_subfields, $subfield->[0], $utf8sf; } diff --git a/C4/Templates.pm b/C4/Templates.pm index 8d13a49..f6bacdf 100644 --- a/C4/Templates.pm +++ b/C4/Templates.pm @@ -128,7 +128,7 @@ sub output { } } my $data; -# binmode( STDOUT, ":utf8" ); + binmode( STDOUT, ":utf8" ); $template->process( $self->filename, $vars, \$data ) || die "Template process failed: ", $template->error(); return $data; diff --git a/Koha/Template/Plugin/AuthorisedValues.pm b/Koha/Template/Plugin/AuthorisedValues.pm index 65abac7..0198ab4 100644 --- a/Koha/Template/Plugin/AuthorisedValues.pm +++ b/Koha/Template/Plugin/AuthorisedValues.pm @@ -21,7 +21,7 @@ use Modern::Perl; use Template::Plugin; use base qw( Template::Plugin ); -use Encode qw{encode decode}; +use Encode qw{encode is_utf8}; use C4::Koha; @@ -63,6 +63,12 @@ the following TT code: [% AuthorisedValues.GetByCode( 'CATEGORY', 'AUTHORISED_VA The parameters are identical to those used by the subroutine C4::Koha::GetAuthorisedValueByCode. +sub GetByCode { + my ( $self, $category, $code, $opac ) = @_; + my $av = GetAuthorisedValueByCode( $category, $code, $opac ); + return $av; +} + =head2 GetAuthValueDropbox The parameters are identical to those used by the subroutine C4::Koha::GetAuthValueDropbox diff --git a/Koha/Template/Plugin/Branches.pm b/Koha/Template/Plugin/Branches.pm index ddf5f2f..8d6359d 100644 --- a/Koha/Template/Plugin/Branches.pm +++ b/Koha/Template/Plugin/Branches.pm @@ -21,7 +21,7 @@ use Modern::Perl; use Template::Plugin; use base qw( Template::Plugin ); -use Encode qw{encode decode}; +use Encode qw{encode is_utf8}; use C4::Koha; use C4::Context; @@ -33,7 +33,7 @@ sub GetName { my $sth = C4::Context->dbh->prepare($query); $sth->execute($branchcode); my $b = $sth->fetchrow_hashref(); - return $b ? encode( 'UTF-8', $b->{'branchname'} ) : q{}; + return $b->{branchname}; } sub GetLoggedInBranchcode { diff --git a/Koha/Template/Plugin/EncodeUTF8.pm b/Koha/Template/Plugin/EncodeUTF8.pm index 94fa81a..d27ccec 100644 --- a/Koha/Template/Plugin/EncodeUTF8.pm +++ b/Koha/Template/Plugin/EncodeUTF8.pm @@ -25,7 +25,7 @@ use Encode qw{encode}; sub filter { my ( $self, $value ) = @_; - return encode( 'UTF-8', $value ); + return is_utf8( $value ) ? encode( 'UTF-8', $value ) : $value; } 1; diff --git a/Koha/Template/Plugin/ItemTypes.pm b/Koha/Template/Plugin/ItemTypes.pm index f0edbc8..c913189 100644 --- a/Koha/Template/Plugin/ItemTypes.pm +++ b/Koha/Template/Plugin/ItemTypes.pm @@ -32,7 +32,7 @@ sub GetDescription { my $sth = C4::Context->dbh->prepare($query); $sth->execute($itemtype); my $d = $sth->fetchrow_hashref(); - return encode( 'UTF-8', $d->{'description'} ); + return $d->{description} } diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index 118bfc2..fa3e90b 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -21,7 +21,7 @@ use strict; #use warnings; FIXME - Bug 2505 -use CGI; +use CGI q(-utf8); use C4::Output; use C4::Auth; use C4::Biblio; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc index bccd39c..f32451f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -63,8 +63,8 @@

[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc index 8d36da3..c8ff82d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc @@ -4,7 +4,7 @@