Lines 34-39
use Template;
Link Here
|
34 |
use Template::Constants qw( :debug ); |
34 |
use Template::Constants qw( :debug ); |
35 |
use C4::Languages qw(getTranslatedLanguages get_bidi regex_lang_subtags language_get_description accept_language ); |
35 |
use C4::Languages qw(getTranslatedLanguages get_bidi regex_lang_subtags language_get_description accept_language ); |
36 |
|
36 |
|
|
|
37 |
use Encode; |
37 |
use C4::Context; |
38 |
use C4::Context; |
38 |
|
39 |
|
39 |
__PACKAGE__->mk_accessors(qw( theme activethemes preferredtheme lang filename htdocs interface vars)); |
40 |
__PACKAGE__->mk_accessors(qw( theme activethemes preferredtheme lang filename htdocs interface vars)); |
Lines 117-131
sub output {
Link Here
|
117 |
# and clean any utf8 mess |
118 |
# and clean any utf8 mess |
118 |
for my $k ( keys %{ $self->{VARS} } ) { |
119 |
for my $k ( keys %{ $self->{VARS} } ) { |
119 |
$vars->{$k} = $self->{VARS}->{$k}; |
120 |
$vars->{$k} = $self->{VARS}->{$k}; |
120 |
if (ref($vars->{$k}) eq 'ARRAY'){ |
121 |
utf8_struct( $vars->{$k} ); |
121 |
utf8_arrayref($vars->{$k}); |
|
|
122 |
} |
123 |
elsif (ref($vars->{$k}) eq 'HASH'){ |
124 |
utf8_hashref($vars->{$k}); |
125 |
} |
126 |
else { |
127 |
utf8::encode($vars->{$k}) if utf8::is_utf8($vars->{$k}); |
128 |
} |
129 |
} |
122 |
} |
130 |
my $data; |
123 |
my $data; |
131 |
# binmode( STDOUT, ":utf8" ); |
124 |
# binmode( STDOUT, ":utf8" ); |
Lines 134-170
sub output {
Link Here
|
134 |
return $data; |
127 |
return $data; |
135 |
} |
128 |
} |
136 |
|
129 |
|
137 |
sub utf8_arrayref { |
130 |
sub utf8_struct { |
138 |
my $arrayref = shift; |
131 |
my $element = shift; |
139 |
foreach my $element (@$arrayref){ |
132 |
my $ref = ref $element; |
140 |
if (ref($element) eq 'ARRAY'){ |
133 |
if ( $ref and $ref eq 'ARRAY' ) { |
141 |
utf8_arrayref($element); |
134 |
foreach my $elt ( @$element ) { |
142 |
next; |
135 |
$elt = utf8_struct( $elt ); |
143 |
} |
136 |
} |
144 |
if (ref($element) eq 'HASH'){ |
137 |
return $element; |
145 |
utf8_hashref($element); |
138 |
} elsif ( $ref and $ref eq 'HASH' ) { |
146 |
next; |
139 |
while ( my ($k, $val) = each %{$element} ) { |
|
|
140 |
$element->{$k} = utf8_struct( $val ); |
147 |
} |
141 |
} |
148 |
utf8::encode($element) if utf8::is_utf8($element); |
142 |
return $element; |
149 |
} |
143 |
} else { |
150 |
} |
144 |
if ( not ref ( $element ) or not UNIVERSAL::can($element, 'can') ) { |
151 |
|
145 |
return Encode::is_utf8($element) |
152 |
sub utf8_hashref { |
146 |
? Encode::encode_utf8($element) |
153 |
my $hashref = shift; |
147 |
: $element; |
154 |
for my $key (keys %{$hashref}){ |
148 |
} else { |
155 |
if (ref($hashref->{$key}) eq 'ARRAY'){ |
149 |
# FIXME It is not the best to create a whitelist or a blacklist here... |
156 |
utf8_arrayref($hashref->{$key}); |
150 |
return $element if ref($element) =~ /^Date/; |
157 |
next; |
151 |
return $element if ref($element) =~ /^Koha::Schema/; |
158 |
} |
152 |
while ( my ( $member, $value ) = each %$element ) { |
159 |
if (ref($hashref->{$key}) eq 'HASH'){ |
153 |
$value = utf8_struct( $value ); |
160 |
utf8_hashref($hashref->{$key}); |
154 |
$element->{$member} = $value; |
161 |
next; |
155 |
} |
|
|
156 |
return $element; |
162 |
} |
157 |
} |
163 |
utf8::encode($hashref->{$key}) if utf8::is_utf8($hashref->{$key}); |
|
|
164 |
} |
158 |
} |
165 |
} |
159 |
} |
166 |
|
160 |
|
167 |
|
|
|
168 |
# FIXME - this is a horrible hack to cache |
161 |
# FIXME - this is a horrible hack to cache |
169 |
# the current known-good language, temporarily |
162 |
# the current known-good language, temporarily |
170 |
# put in place to resolve bug 4403. It is |
163 |
# put in place to resolve bug 4403. It is |