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