From 3bfe9c04243254f24eefacb2f7dff6c877f0dd86 Mon Sep 17 00:00:00 2001 From: MJ Ray Date: Sun, 10 Jun 2012 15:18:42 +0100 Subject: [PATCH] Bug 6554 - added session CGI queries and all ZebraPAR utf8_decode Rebased from added-session-CGI-queries-and-all-ZebraPAR-utf8-de-O_t1Z2.patch Original-Author: Dobrica Pavlinusic --- C4/Context.pm | 4 ++- C4/ItemType.pm | 2 +- C4/Output.pm | 1 + C4/Search.pm | 4 +++ C4/Templates.pm | 44 +----------------------------------------- C4/XSLT.pm | 1 + admin/preferences.pl | 1 + admin/z3950servers.pl | 2 +- catalogue/search.pl | 2 +- cataloguing/z3950_search.pl | 2 +- members/member.pl | 2 +- opac/opac-search.pl | 2 +- 12 files changed, 18 insertions(+), 49 deletions(-) diff --git a/C4/Context.pm b/C4/Context.pm index 67d31ee..ddf63e6 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -1008,7 +1008,9 @@ set_userenv is called in Auth.pm #' sub set_userenv { - my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter)= @_; + my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter)= + map { utf8::decode($_); $_ } # CGI::Session doesn't handle utf-8, so we decode it here + @_; my $var=$context->{"activeuser"}; my $cell = { "number" => $usernum, diff --git a/C4/ItemType.pm b/C4/ItemType.pm index 70d2690..d7c0615 100644 --- a/C4/ItemType.pm +++ b/C4/ItemType.pm @@ -78,7 +78,7 @@ sub all { for ( @{$dbh->selectall_arrayref( "SELECT * FROM itemtypes ORDER BY description", { Slice => {} })} ) { - utf8::encode($_->{description}); +# utf8::encode($_->{description}); push @itypes, $class->new($_); } return @itypes; diff --git a/C4/Output.pm b/C4/Output.pm index 9087075..ac14e8a 100644 --- a/C4/Output.pm +++ b/C4/Output.pm @@ -301,6 +301,7 @@ sub output_with_http_headers($$$$;$) { print $query->header($options), $data; } + binmode( STDOUT, ":utf8" ); sub output_html_with_http_headers ($$$;$) { my ( $query, $cookie, $data, $status ) = @_; output_with_http_headers( $query, $cookie, $data, 'html', $status ); diff --git a/C4/Search.pm b/C4/Search.pm index 56468b5..fac90a2 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -267,6 +267,7 @@ sub SimpleSearch { for my $j ( $first_record..$last_record ) { my $record = $tmpresults[ $i - 1 ]->record( $j-1 )->raw(); # 0 indexed + utf8::decode( $record ); push @{$results}, $record; } } @@ -458,6 +459,7 @@ sub getRecords { # not an index scan else { $record = $results[ $i - 1 ]->record($j)->raw(); + utf8::decode( $record ); # warn "RECORD $j:".$record; $results_hash->{'RECORDS'}[$j] = $record; @@ -473,6 +475,7 @@ sub getRecords { for my $facet ( @$facets ) { for ( my $j = 0 ; $j < $jmax ; $j++ ) { my $render_record = $results[ $i - 1 ]->record($j)->render(); + utf8::decode($render_record); my @used_datas = (); foreach my $tag ( @{$facet->{tags}} ) { # avoid first line @@ -635,6 +638,7 @@ sub pazGetRecords { for (my $i = 0; $i < $count; $i++) { # FIXME -- may need to worry about diacritics here my $rec = $paz->record($recid, $i); + utf8::decode( $rec ); push @{ $result_group->{'RECORDS'} }, $rec; } diff --git a/C4/Templates.pm b/C4/Templates.pm index 0741040..10b31b3 100644 --- a/C4/Templates.pm +++ b/C4/Templates.pm @@ -65,6 +65,7 @@ sub new { "$htdocs/$theme/en/includes" ], FILTERS => {}, + ENCODING => 'utf8', # templates don't have BOM, see Template::FAQ } ) or die Template->error(); my $self = { @@ -109,57 +110,16 @@ sub output { $vars->{opacstylesheet} = C4::Context->preference('opacstylesheet'); # add variables set via param to $vars for processing - # and clean any utf8 mess for my $k ( keys %{ $self->{VARS} } ) { $vars->{$k} = $self->{VARS}->{$k}; - if (ref($vars->{$k}) eq 'ARRAY'){ - utf8_arrayref($vars->{$k}); - } - elsif (ref($vars->{$k}) eq 'HASH'){ - utf8_hashref($vars->{$k}); - } - else { - utf8::encode($vars->{$k}) if utf8::is_utf8($vars->{$k}); - } } my $data; -# binmode( STDOUT, ":utf8" ); $template->process( $self->filename, $vars, \$data ) || die "Template process failed: ", $template->error(); return $data; } -sub utf8_arrayref { - my $arrayref = shift; - foreach my $element (@$arrayref){ - if (ref($element) eq 'ARRAY'){ - utf8_arrayref($element); - next; - } - if (ref($element) eq 'HASH'){ - utf8_hashref($element); - next; - } - utf8::encode($element) if utf8::is_utf8($element); - } -} - -sub utf8_hashref { - my $hashref = shift; - for my $key (keys %{$hashref}){ - if (ref($hashref->{$key}) eq 'ARRAY'){ - utf8_arrayref($hashref->{$key}); - next; - } - if (ref($hashref->{$key}) eq 'HASH'){ - utf8_hashref($hashref->{$key}); - next; - } - utf8::encode($hashref->{$key}) if utf8::is_utf8($hashref->{$key}); - } -} - - + # FIXME - this is a horrible hack to cache # the current known-good language, temporarily # put in place to resolve bug 4403. It is diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 56ba544..d5f8f8d 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -220,6 +220,7 @@ sub XSLTParse4Display { } my $results = $stylesheet->{$xslfilename}->transform($source); my $newxmlrecord = $stylesheet->{$xslfilename}->output_string($results); + utf8::decode( $newxmlrecord ); return $newxmlrecord; } diff --git a/admin/preferences.pl b/admin/preferences.pl index 0dcec19..804d85b 100755 --- a/admin/preferences.pl +++ b/admin/preferences.pl @@ -34,6 +34,7 @@ use File::Spec; use IO::File; use YAML::Syck qw(); $YAML::Syck::ImplicitTyping = 1; +$YAML::Syck::ImplicitUnicode = 1; # force utf-8 for preference encoding our $lang; # use Smart::Comments; diff --git a/admin/z3950servers.pl b/admin/z3950servers.pl index 14603f6..fc8ed64 100755 --- a/admin/z3950servers.pl +++ b/admin/z3950servers.pl @@ -21,7 +21,7 @@ use strict; use warnings; -use CGI; +use CGI qw( -utf8 ); use C4::Context; use C4::Auth; use C4::Output; diff --git a/catalogue/search.pl b/catalogue/search.pl index 0052f66..1428fc4 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -154,7 +154,7 @@ use C4::Branch; # GetBranches my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold"); # create a new CGI object # FIXME: no_undef_params needs to be tested -use CGI qw('-no_undef_params'); +use CGI qw( -no_undef_params -utf8 ); my $cgi = new CGI; my ($template,$borrowernumber,$cookie); diff --git a/cataloguing/z3950_search.pl b/cataloguing/z3950_search.pl index 6e6b417..b4abd59 100755 --- a/cataloguing/z3950_search.pl +++ b/cataloguing/z3950_search.pl @@ -20,7 +20,7 @@ use strict; #use warnings; FIXME - Bug 2505 -use CGI; +use CGI qw( -utf8 ); use C4::Auth; use C4::Output; diff --git a/members/member.pl b/members/member.pl index 9b793f4..fadb47d 100755 --- a/members/member.pl +++ b/members/member.pl @@ -27,7 +27,7 @@ use strict; #use warnings; FIXME - Bug 2505 use C4::Auth; use C4::Output; -use CGI; +use CGI qw( -utf8 ); use C4::Members; use C4::Branch; use C4::Category; diff --git a/opac/opac-search.pl b/opac/opac-search.pl index ea0cb98..654a3cf 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -46,7 +46,7 @@ use Business::ISBN; my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold"); # create a new CGI object # FIXME: no_undef_params needs to be tested -use CGI qw('-no_undef_params'); +use CGI qw( -no_undef_params -utf8 ); my $cgi = new CGI; BEGIN { -- 1.7.2.5