Lines 4-9
use strict;
Link Here
|
4 |
use warnings; |
4 |
use warnings; |
5 |
use Carp; |
5 |
use Carp; |
6 |
use CGI; |
6 |
use CGI; |
|
|
7 |
use List::Util qw/first/; |
7 |
|
8 |
|
8 |
# Copyright 2009 Chris Cormack and The Koha Dev Team |
9 |
# Copyright 2009 Chris Cormack and The Koha Dev Team |
9 |
# |
10 |
# |
Lines 169-225
sub _current_language {
Link Here
|
169 |
return $_current_language; |
170 |
return $_current_language; |
170 |
} |
171 |
} |
171 |
|
172 |
|
172 |
sub themelanguage_lite { |
|
|
173 |
my ( $htdocs, $tmpl, $interface ) = @_; |
174 |
my $query = new CGI; |
175 |
|
176 |
# Set some defaults for language and theme |
177 |
# First, check the user's preferences |
178 |
my $lang; |
179 |
|
180 |
# But, if there's a cookie set, obey it |
181 |
$lang = $query->cookie('KohaOpacLanguage') |
182 |
if ( defined $query and $query->cookie('KohaOpacLanguage') ); |
183 |
|
184 |
# Fall back to English |
185 |
my @languages; |
186 |
if ( $interface eq 'intranet' ) { |
187 |
@languages = split ",", C4::Context->preference("language"); |
188 |
} |
189 |
else { |
190 |
@languages = split ",", C4::Context->preference("opaclanguages"); |
191 |
} |
192 |
if ($lang) { |
193 |
@languages = ( $lang, @languages ); |
194 |
} |
195 |
else { |
196 |
$lang = $languages[0] || 'en'; |
197 |
} |
198 |
my $theme = 'prog'; # in the event of theme failure default to 'prog' -fbcit |
199 |
my @themes; |
200 |
if ( $interface eq "intranet" ) { |
201 |
@themes = split " ", C4::Context->preference("template"); |
202 |
} |
203 |
else { |
204 |
@themes = split " ", C4::Context->preference("opacthemes"); |
205 |
} |
206 |
|
207 |
# searches through the themes and languages. First template it find it returns. |
208 |
# Priority is for getting the theme right. |
209 |
THEME: |
210 |
foreach my $th (@themes) { |
211 |
foreach my $la (@languages) { |
212 |
if ( -e "$htdocs/$th/$la/modules/$tmpl" ) { |
213 |
$theme = $th; |
214 |
$lang = $la; |
215 |
last THEME; |
216 |
} |
217 |
last unless $la =~ /[-_]/; |
218 |
} |
219 |
} |
220 |
$_current_language = $lang; # FIXME part of bad hack to paper over bug 4403 |
221 |
return ( $theme, $lang ); |
222 |
} |
223 |
|
173 |
|
224 |
# wrapper method to allow easier transition from HTML template pro to Template Toolkit |
174 |
# wrapper method to allow easier transition from HTML template pro to Template Toolkit |
225 |
sub param { |
175 |
sub param { |
Lines 250-258
my $path = C4::Context->config('intrahtdocs') . "/prog/en/includes/";
Link Here
|
250 |
# FIXME - POD |
200 |
# FIXME - POD |
251 |
|
201 |
|
252 |
sub _get_template_file { |
202 |
sub _get_template_file { |
253 |
my ( $tmplbase, $interface, $query ) = @_; |
203 |
my ($tmplbase, $interface, $query) = @_; |
254 |
my $htdocs = C4::Context->config( $interface ne 'intranet' ? 'opachtdocs' : 'intrahtdocs' ); |
204 |
|
255 |
my ( $theme, $lang ) = themelanguage( $htdocs, $tmplbase, $interface, $query ); |
205 |
my $is_intranet = $interface eq 'intranet'; |
|
|
206 |
my $htdocs = C4::Context->config($is_intranet ? 'intrahtdocs' : 'opachtdocs'); |
207 |
my ($theme, $lang) = themelanguage($htdocs, $tmplbase, $interface, $query); |
256 |
my $opacstylesheet = C4::Context->preference('opacstylesheet'); |
208 |
my $opacstylesheet = C4::Context->preference('opacstylesheet'); |
257 |
|
209 |
|
258 |
# if the template doesn't exist, load the English one as a last resort |
210 |
# if the template doesn't exist, load the English one as a last resort |
Lines 261-284
sub _get_template_file {
Link Here
|
261 |
$lang = 'en'; |
213 |
$lang = 'en'; |
262 |
$filename = "$htdocs/$theme/$lang/modules/$tmplbase"; |
214 |
$filename = "$htdocs/$theme/$lang/modules/$tmplbase"; |
263 |
} |
215 |
} |
264 |
|
216 |
return ($htdocs, $theme, $lang, $filename); |
265 |
return ( $htdocs, $theme, $lang, $filename ); |
|
|
266 |
} |
217 |
} |
267 |
|
218 |
|
|
|
219 |
|
268 |
sub gettemplate { |
220 |
sub gettemplate { |
269 |
my ( $tmplbase, $interface, $query ) = @_; |
221 |
my ( $tmplbase, $interface, $query ) = @_; |
270 |
($query) or warn "no query in gettemplate"; |
222 |
($query) or warn "no query in gettemplate"; |
271 |
my $path = C4::Context->preference('intranet_includes') || 'includes'; |
223 |
my $path = C4::Context->preference('intranet_includes') || 'includes'; |
272 |
my $opacstylesheet = C4::Context->preference('opacstylesheet'); |
224 |
my $opacstylesheet = C4::Context->preference('opacstylesheet'); |
273 |
$tmplbase =~ s/\.tmpl$/.tt/; |
225 |
$tmplbase =~ s/\.tmpl$/.tt/; |
274 |
my ( $htdocs, $theme, $lang, $filename ) = _get_template_file( $tmplbase, $interface, $query ); |
226 |
my ($htdocs, $theme, $lang, $filename) |
|
|
227 |
= _get_template_file($tmplbase, $interface, $query); |
275 |
my $template = C4::Templates->new($interface, $filename, $tmplbase, $query); |
228 |
my $template = C4::Templates->new($interface, $filename, $tmplbase, $query); |
276 |
my $themelang=( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' ) |
229 |
my $is_intranet = $interface eq 'intranet'; |
277 |
. "/$theme/$lang"; |
230 |
my $themelang = |
|
|
231 |
($is_intranet ? '/intranet-tmpl' : '/opac-tmpl') . |
232 |
"/$theme/$lang"; |
278 |
$template->param( |
233 |
$template->param( |
279 |
themelang => $themelang, |
234 |
themelang => $themelang, |
280 |
yuipath => (C4::Context->preference("yuipath") eq "local"?"$themelang/lib/yui":C4::Context->preference("yuipath")), |
235 |
yuipath => C4::Context->preference("yuipath") eq "local" |
281 |
interface => ( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' ), |
236 |
? "$themelang/lib/yui" |
|
|
237 |
: C4::Context->preference("yuipath"), |
238 |
interface => $is_intranet ? '/intranet-tmpl' : '/opac-tmpl', |
282 |
theme => $theme, |
239 |
theme => $theme, |
283 |
lang => $lang |
240 |
lang => $lang |
284 |
); |
241 |
); |
Lines 308-374
sub gettemplate {
Link Here
|
308 |
#--------------------------------------------------------------------------------------------------------- |
265 |
#--------------------------------------------------------------------------------------------------------- |
309 |
# FIXME - POD |
266 |
# FIXME - POD |
310 |
sub themelanguage { |
267 |
sub themelanguage { |
311 |
my ( $htdocs, $tmpl, $interface, $query ) = @_; |
268 |
my ($htdocs, $tmpl, $interface, $query) = @_; |
312 |
($query) or warn "no query in themelanguage"; |
269 |
($query) or warn "no query in themelanguage"; |
313 |
|
270 |
|
314 |
# Set some defaults for language and theme |
271 |
# Select a language based on cookie, syspref available languages & browser |
315 |
# First, check the user's preferences |
272 |
my $is_intranet = $interface eq 'intranet'; |
|
|
273 |
my @languages = split(",", C4::Context->preference( |
274 |
$is_intranet ? 'language' : 'opaclanguages')); |
316 |
my $lang; |
275 |
my $lang; |
317 |
my $http_accept_language = $ENV{ HTTP_ACCEPT_LANGUAGE }; |
276 |
$lang = $query->cookie('KohaOpacLanguage') |
318 |
$lang = accept_language( $http_accept_language, |
277 |
if defined $query and $query->cookie('KohaOpacLanguage'); |
319 |
getTranslatedLanguages($interface,'prog') ) |
278 |
unless ($lang) { |
320 |
if $http_accept_language; |
279 |
my $http_accept_language = $ENV{ HTTP_ACCEPT_LANGUAGE }; |
321 |
# But, if there's a cookie set, obey it |
280 |
$lang = accept_language( $http_accept_language, |
322 |
$lang = $query->cookie('KohaOpacLanguage') if (defined $query and $query->cookie('KohaOpacLanguage')); |
281 |
getTranslatedLanguages($interface,'prog') ); |
323 |
# Fall back to English |
|
|
324 |
my @languages; |
325 |
if ($interface eq 'intranet') { |
326 |
@languages = split ",", C4::Context->preference("language"); |
327 |
} else { |
328 |
@languages = split ",", C4::Context->preference("opaclanguages"); |
329 |
} |
330 |
if ($lang){ |
331 |
@languages=($lang,@languages); |
332 |
} else { |
333 |
$lang = $languages[0]; |
334 |
} |
335 |
my $theme = 'prog'; # in the event of theme failure default to 'prog' -fbcit |
336 |
my $dbh = C4::Context->dbh; |
337 |
my @themes; |
338 |
if ( $interface eq "intranet" ) { |
339 |
@themes = split " ", C4::Context->preference("template"); |
340 |
} |
341 |
else { |
342 |
# we are in the opac here, what im trying to do is let the individual user |
343 |
# set the theme they want to use. |
344 |
# and perhaps the them as well. |
345 |
#my $lang = $query->cookie('KohaOpacLanguage'); |
346 |
@themes = split " ", C4::Context->preference("opacthemes"); |
347 |
} |
282 |
} |
348 |
|
283 |
# Ignore a lang not selected in sysprefs |
349 |
# searches through the themes and languages. First template it find it returns. |
284 |
$lang = undef unless first { $_ eq $lang } @languages; |
350 |
# Priority is for getting the theme right. |
285 |
# Fall back to English if necessary |
351 |
THEME: |
286 |
$lang = 'en' unless $lang; |
352 |
foreach my $th (@themes) { |
287 |
|
353 |
foreach my $la (@languages) { |
288 |
my @themes = split(" ", C4::Context->preference( |
354 |
#for ( my $pass = 1 ; $pass <= 2 ; $pass += 1 ) { |
289 |
$is_intranet ? "template" : "opacthemes" )); |
355 |
# warn "$htdocs/$th/$la/modules/$interface-"."tmpl"; |
290 |
push @themes, 'prog'; |
356 |
#$la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2; |
291 |
|
357 |
if ( -e "$htdocs/$th/$la/modules/$tmpl") { |
292 |
# Try to find first theme for the selected language |
358 |
#".($interface eq 'intranet'?"modules":"")."/$tmpl" ) { |
293 |
for my $theme (@themes) { |
359 |
$theme = $th; |
294 |
if ( -e "$htdocs/$theme/$lang/modules/$tmpl" ) { |
360 |
$lang = $la; |
295 |
$_current_language = $lang; |
361 |
last THEME; |
296 |
return ($theme, $lang) |
362 |
} |
|
|
363 |
last unless $la =~ /[-_]/; |
364 |
#} |
365 |
} |
297 |
} |
366 |
} |
298 |
} |
367 |
|
299 |
# Otherwise, return prog theme in English 'en' |
368 |
$_current_language = $lang; # FIXME part of bad hack to paper over bug 4403 |
300 |
return ('prog', 'en'); |
369 |
return ( $theme, $lang ); |
|
|
370 |
} |
301 |
} |
371 |
|
302 |
|
|
|
303 |
|
372 |
sub setlanguagecookie { |
304 |
sub setlanguagecookie { |
373 |
my ( $query, $language, $uri ) = @_; |
305 |
my ( $query, $language, $uri ) = @_; |
374 |
my $cookie = $query->cookie( |
306 |
my $cookie = $query->cookie( |
375 |
- |
|
|