Bug 11944: Remove all utf8 filter from templates
authorJonathan Druart <jonathan.druart@biblibre.com>
Fri, 14 Mar 2014 08:16:16 +0000 (09:16 +0100)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Tue, 13 Jan 2015 16:06:42 +0000 (13:06 -0300)
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 <paola.rossi@cineca.it>
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Signed-off-by: Dobrica Pavlinusic <dpavlin@rot13.org>

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>

C4/Charset.pm
C4/Templates.pm
Koha/Template/Plugin/AuthorisedValues.pm
Koha/Template/Plugin/Branches.pm
Koha/Template/Plugin/EncodeUTF8.pm
Koha/Template/Plugin/ItemTypes.pm
cataloguing/addbiblio.pl
koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc
koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc
koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt
koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt

index 4521262..6bfd935 100644 (file)
@@ -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;
             }
index 7456c7f..73f37f5 100644 (file)
@@ -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;
index 65abac7..0198ab4 100644 (file)
@@ -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
index ff43a38..781cd21 100644 (file)
@@ -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 {
index 94fa81a..d27ccec 100644 (file)
@@ -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;
index f0edbc8..c913189 100644 (file)
@@ -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}
 
 }
 
index 645a30a..fe7e1fd 100755 (executable)
@@ -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;
index 6ae7a2c..1a612b6 100644 (file)
@@ -99,8 +99,8 @@
                  <label for="categorycode">Category: </label><select name="categorycode" id="categorycode">
         <option value="">Any</option>[% FOREACH categorie IN categories %]
         [% IF ( categorie.selected ) %]
-        <option value="[% categorie.categorycode %]" selected="selected">[% categorie.description |html_entity %]</option>[% ELSE %]
-        <option value="[% categorie.categorycode %]">[% categorie.description |html_entity %]</option>[% END %]
+        <option value="[% categorie.categorycode %]" selected="selected">[% categorie.description %]</option>[% ELSE %]
+        <option value="[% categorie.categorycode %]">[% categorie.description %]</option>[% END %]
       [% END %]</select>
     </p>
     [% END %]
index f67f64c..35720df 100644 (file)
@@ -4,7 +4,7 @@
         <button class="btn btn-small dropdown-toggle" data-toggle="dropdown"><i class="icon-plus"></i> New patron <span class="caret"></span></button>
             <ul class="dropdown-menu">
                 [% IF Koha.Preference('AddPatronLists') == 'categorycode' %]
-                    [% FOREACH categorie IN categories %]<li><a href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;categorycode=[% categorie.categorycode %]">[% categorie.description | html_entity %]</a></li>[% END %]
+                    [% FOREACH categorie IN categories %]<li><a href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;categorycode=[% categorie.categorycode %]">[% categorie.description %]</a></li>[% END %]
                 [% ELSE %]
                     <li><a href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;category_type=A">Adult patron</a></li>
                     <li><a href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;category_type=C">Child patron</a></li>
index 46a68ea..964704f 100644 (file)
@@ -1,6 +1,5 @@
 [% USE Koha %]
 [% USE KohaDates %]
-[% USE EncodeUTF8 %]
 
 [% INCLUDE 'doc-head-open.inc' %]
 
 
                             [% ELSIF error == "no_checkout" %]
 
-                                <p><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% item.biblionumber %]">[% item.biblio.title | $EncodeUTF8 %] [% item.biblioitem.subtitle | $EncodeUTF8 %]</a> ( <a href="/cgi-bin/koha/catalogue/moredetail.pl?itemnumber=[% item.itemnumber %]&amp;biblionumber=[% item.biblionumber %]&amp;bi=[% item.biblioitemnumber %]#item[% item.itemnumber %]">[% item.barcode %]</a> ) is not checked out to a patron.</p>
+                                <p><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% item.biblionumber %]">[% item.biblio.title %] [% item.biblioitem.subtitle %]</a> ( <a href="/cgi-bin/koha/catalogue/moredetail.pl?itemnumber=[% item.itemnumber %]&amp;biblionumber=[% item.biblionumber %]&amp;bi=[% item.biblioitemnumber %]#item[% item.itemnumber %]">[% item.barcode %]</a> ) is not checked out to a patron.</p>
 
                             [% ELSIF error == "too_many" %]
 
-                                <p>[% item.biblio.title | $EncodeUTF8 %] [% item.biblioitem.subtitle | $EncodeUTF8 %] ( [% item.barcode %] ) has been renewed the maximum number of times by [% borrower.firstname %] [% borrower.surname %] ( <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber %]"> [% borrower.cardnumber %] </a> )</p>
+                                <p>[% item.biblio.title %] [% item.biblioitem.subtitle %] ( [% item.barcode %] ) has been renewed the maximum number of times by [% borrower.firstname %] [% borrower.surname %] ( <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber %]"> [% borrower.cardnumber %] </a> )</p>
 
                                 [% IF Koha.Preference('AllowRenewalLimitOverride') %]
                                     <form method="post" action="/cgi-bin/koha/circ/renew.pl">
                     <div class="dialog message">
                         <h3>Item renewed:</h3>
                         <p>
-                            <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% item.biblionumber %]">[% item.biblio.title | $EncodeUTF8 %] [% item.biblioitem.subtitle | $EncodeUTF8 %]</a>
+                            <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% item.biblionumber %]">[% item.biblio.title %] [% item.biblioitem.subtitle %]</a>
                             ( <a href="/cgi-bin/koha/catalogue/moredetail.pl?itemnumber=[% item.itemnumber %]&amp;biblionumber=[% item.biblionumber %]&amp;bi=[% item.biblioitemnumber %]#item[% item.itemnumber %]">[% item.barcode %]</a> )
                             renewed for
                             [% borrower.firstname %] [% borrower.surname %] ( <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber %]"> [% borrower.cardnumber %] </a> )
index a2882ab..f8bb6fe 100644 (file)
@@ -136,7 +136,7 @@ function enableCheckboxActions(){
           [% CASE %][% line.accounttype %]
         [%- END -%]
         [%- IF line.description %], [% line.description %][% END %]
-        [% IF line.title %]([% line.title |html %])[% END %]
+        [% IF line.title %]([% line.title %])[% END %]
     </td>
     <td><input type="text" name="payment_note_[% line.accountno %]" /></td>
     <td>[% line.accounttype %]</td>