From 99521c37fa443d52478f9e059c68dd014fea0c2d 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 Signed-off-by: Dobrica Pavlinusic Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi --- 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 +- 11 files changed, 21 insertions(+), 16 deletions(-) diff --git a/C4/Charset.pm b/C4/Charset.pm index 4521262..6bfd935 100644 --- a/C4/Charset.pm +++ b/C4/Charset.pm @@ -624,7 +624,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 7456c7f..73f37f5 100644 --- a/C4/Templates.pm +++ b/C4/Templates.pm @@ -125,7 +125,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 ff43a38..781cd21 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 645a30a..fe7e1fd 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 6ae7a2c..1a612b6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -99,8 +99,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 f67f64c..35720df 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 @@