|
Lines 65-70
sub new {
Link Here
|
| 65 |
"$htdocs/$theme/en/includes" |
65 |
"$htdocs/$theme/en/includes" |
| 66 |
], |
66 |
], |
| 67 |
FILTERS => {}, |
67 |
FILTERS => {}, |
|
|
68 |
ENCODING => 'utf8', # templates don't have BOM, see Template::FAQ |
| 68 |
} |
69 |
} |
| 69 |
) or die Template->error(); |
70 |
) or die Template->error(); |
| 70 |
my $self = { |
71 |
my $self = { |
|
Lines 109-165
sub output {
Link Here
|
| 109 |
$vars->{opacstylesheet} = C4::Context->preference('opacstylesheet'); |
110 |
$vars->{opacstylesheet} = C4::Context->preference('opacstylesheet'); |
| 110 |
|
111 |
|
| 111 |
# add variables set via param to $vars for processing |
112 |
# add variables set via param to $vars for processing |
| 112 |
# and clean any utf8 mess |
|
|
| 113 |
for my $k ( keys %{ $self->{VARS} } ) { |
113 |
for my $k ( keys %{ $self->{VARS} } ) { |
| 114 |
$vars->{$k} = $self->{VARS}->{$k}; |
114 |
$vars->{$k} = $self->{VARS}->{$k}; |
| 115 |
if (ref($vars->{$k}) eq 'ARRAY'){ |
|
|
| 116 |
utf8_arrayref($vars->{$k}); |
| 117 |
} |
| 118 |
elsif (ref($vars->{$k}) eq 'HASH'){ |
| 119 |
utf8_hashref($vars->{$k}); |
| 120 |
} |
| 121 |
else { |
| 122 |
utf8::encode($vars->{$k}) if utf8::is_utf8($vars->{$k}); |
| 123 |
} |
| 124 |
} |
115 |
} |
| 125 |
my $data; |
116 |
my $data; |
| 126 |
# binmode( STDOUT, ":utf8" ); |
|
|
| 127 |
$template->process( $self->filename, $vars, \$data ) |
117 |
$template->process( $self->filename, $vars, \$data ) |
| 128 |
|| die "Template process failed: ", $template->error(); |
118 |
|| die "Template process failed: ", $template->error(); |
| 129 |
return $data; |
119 |
return $data; |
| 130 |
} |
120 |
} |
| 131 |
|
121 |
|
| 132 |
sub utf8_arrayref { |
122 |
|
| 133 |
my $arrayref = shift; |
|
|
| 134 |
foreach my $element (@$arrayref){ |
| 135 |
if (ref($element) eq 'ARRAY'){ |
| 136 |
utf8_arrayref($element); |
| 137 |
next; |
| 138 |
} |
| 139 |
if (ref($element) eq 'HASH'){ |
| 140 |
utf8_hashref($element); |
| 141 |
next; |
| 142 |
} |
| 143 |
utf8::encode($element) if utf8::is_utf8($element); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
sub utf8_hashref { |
| 148 |
my $hashref = shift; |
| 149 |
for my $key (keys %{$hashref}){ |
| 150 |
if (ref($hashref->{$key}) eq 'ARRAY'){ |
| 151 |
utf8_arrayref($hashref->{$key}); |
| 152 |
next; |
| 153 |
} |
| 154 |
if (ref($hashref->{$key}) eq 'HASH'){ |
| 155 |
utf8_hashref($hashref->{$key}); |
| 156 |
next; |
| 157 |
} |
| 158 |
utf8::encode($hashref->{$key}) if utf8::is_utf8($hashref->{$key}); |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
# FIXME - this is a horrible hack to cache |
123 |
# FIXME - this is a horrible hack to cache |
| 164 |
# the current known-good language, temporarily |
124 |
# the current known-good language, temporarily |
| 165 |
# put in place to resolve bug 4403. It is |
125 |
# put in place to resolve bug 4403. It is |