X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FOutput.pm;h=4ad79dafccd64b4f9a532c0e2aa7933f6a9dea42;hb=1c0401e867b85ddd5dd5ef211ab8c1ef5b63276f;hp=e73d1b6b3510571c9bd3ae5a63739c4bc2ac3c6d;hpb=fe1b2e488207bf13cf39ba6100af6f14a0fd3c12;p=koha_fer diff --git a/C4/Output.pm b/C4/Output.pm index e73d1b6b35..4ad79dafcc 100644 --- a/C4/Output.pm +++ b/C4/Output.pm @@ -26,16 +26,25 @@ package C4::Output; # templates. use strict; -require Exporter; use C4::Context; -use C4::Languages qw(getTranslatedLanguages get_bidi regex_lang_subtags language_get_description); +use C4::Languages qw(getTranslatedLanguages get_bidi regex_lang_subtags language_get_description accept_language ); use HTML::Template::Pro; use vars qw($VERSION @ISA @EXPORT); -# set the version for version checking -$VERSION = 3.00; +BEGIN { + # set the version for version checking + $VERSION = 3.01; + require Exporter; + @ISA = qw(Exporter); + push @EXPORT, qw( + &themelanguage &gettemplate setlanguagecookie pagination_bar + ); + push @EXPORT, qw( + &output_html_with_http_headers + ); +} =head1 NAME @@ -47,17 +56,6 @@ C4::Output - Functions for managing templates =cut -@ISA = qw(Exporter); -push @EXPORT, qw( - &themelanguage &gettemplate setlanguagecookie pagination_bar -); - -#Output -push @EXPORT, qw( - &output_html_with_http_headers -); - - #FIXME: this is a quick fix to stop rc1 installing broken #Still trying to figure out the correct fix. my $path = C4::Context->config('intrahtdocs') . "/prog/en/includes/"; @@ -66,9 +64,7 @@ my $path = C4::Context->config('intrahtdocs') . "/prog/en/includes/"; # FIXME - POD sub gettemplate { my ( $tmplbase, $interface, $query ) = @_; - if ( !$query ) { - warn "no query in gettemplate"; - } + ($query) or warn "no query in gettemplate"; my $htdocs; if ( $interface ne "intranet" ) { $htdocs = C4::Context->config('opachtdocs'); @@ -78,18 +74,17 @@ sub gettemplate { } my $path = C4::Context->preference('intranet_includes') || 'includes'; - # warn "PATH : $path"; my ( $theme, $lang ) = themelanguage( $htdocs, $tmplbase, $interface, $query ); my $opacstylesheet = C4::Context->preference('opacstylesheet'); - # if the template doesn't exist, load the English one as a last resort - my $filename = "$htdocs/$theme/$lang/".($interface eq 'intranet'?"modules":"")."/$tmplbase"; - unless (-f $filename) { - $lang = 'en'; - $filename = "$htdocs/$theme/$lang/".($interface eq 'intranet'?"modules":"")."/$tmplbase"; - } + # if the template doesn't exist, load the English one as a last resort + my $filename = "$htdocs/$theme/$lang/modules/$tmplbase"; + unless (-f $filename) { + $lang = 'en'; + $filename = "$htdocs/$theme/$lang/modules/$tmplbase"; + } my $template = HTML::Template::Pro->new( - filename => $filename, + filename => $filename, die_on_bad_params => 1, global_vars => 1, case_sensitive => 1, @@ -107,26 +102,16 @@ sub gettemplate { lang => $lang ); - # Language, Script, and Locale - my $language_subtags_hashref = regex_lang_subtags($lang); - my $bidi; - $bidi = get_bidi($language_subtags_hashref->{script}) if $language_subtags_hashref->{script}; - my @template_languages; - my $languages_loop = getTranslatedLanguages($interface,$theme); - for my $language_hashref (@$languages_loop) { - $language_hashref->{'language_script_description'} = language_get_description($language_hashref->{'language_script'},$lang); - $language_hashref->{'language_region_description'} = language_get_description($language_hashref->{'language_region'},$lang); - $language_hashref->{'language_variant_description'} = language_get_description($language_hashref->{'language_variant'},$lang); - - if ($language_hashref->{language_code} eq $language_subtags_hashref->{language}) { - $language_hashref->{current}++; - } - push @template_languages, $language_hashref; - } - # load the languages ( for switching from one template to another ) - $template->param( languages_loop => \@template_languages, - bidi => $bidi - ); + # Bidirectionality + my $current_lang = regex_lang_subtags($lang); + my $bidi; + $bidi = get_bidi($current_lang->{script}) if $current_lang->{script}; + # Languages + my $languages_loop = getTranslatedLanguages($interface,$theme,$lang); + $template->param( + languages_loop => $languages_loop, + bidi => $bidi + ) unless @$languages_loop<2; return $template; } @@ -134,56 +119,55 @@ sub gettemplate { #--------------------------------------------------------------------------------------------------------- # FIXME - POD sub themelanguage { - my ( $htdocs, $tmpl, $section, $query ) = @_; - - # if (!$query) { - # warn "no query"; - # } - - # set some defaults for language and theme - my $lang = $query->cookie('KohaOpacLanguage'); - $lang = 'en' unless $lang; - my $theme = 'prog'; - + my ( $htdocs, $tmpl, $interface, $query ) = @_; + ($query) or warn "no query in themelanguage"; + + # Set some defaults for language and theme + # First, check the user's preferences + my $lang; + my $http_accept_language = regex_lang_subtags($ENV{HTTP_ACCEPT_LANGUAGE})->{language}; + if ($http_accept_language) { + $lang = accept_language($http_accept_language,getTranslatedLanguages($interface,'prog')); + } + # But, if there's a cookie set, obey it + $lang = $query->cookie('KohaOpacLanguage') if $query->cookie('KohaOpacLanguage'); + # Fall back to English + my @languages = split " ", C4::Context->preference("opaclanguages"); + if ($lang){ + @languages=($lang,@languages); + } else { + $lang = $languages[0]; + } + my $theme = 'prog'; # in the event of theme failure default to 'prog' -fbcit my $dbh = C4::Context->dbh; - my @languages; my @themes; - if ( $section eq "intranet" ) { - @languages = split " ", C4::Context->preference("opaclanguages"); + if ( $interface eq "intranet" ) { @themes = split " ", C4::Context->preference("template"); - pop @languages, $lang if $lang; } else { - # we are in the opac here, what im trying to do is let the individual user # set the theme they want to use. # and perhaps the them as well. #my $lang = $query->cookie('KohaOpacLanguage'); - if ($lang) { - - push @languages, $lang; - @themes = split " ", C4::Context->preference("opacthemes"); - } - else { - @languages = split " ", C4::Context->preference("opaclanguages"); - @themes = split " ", C4::Context->preference("opacthemes"); - } + @themes = split " ", C4::Context->preference("opacthemes"); } # searches through the themes and languages. First template it find it returns. # Priority is for getting the theme right. - THEME: + THEME: foreach my $th (@themes) { foreach my $la (@languages) { - for ( my $pass = 1 ; $pass <= 2 ; $pass += 1 ) { - $la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2; - if ( -e "$htdocs/$th/$la/modules/$tmpl" ) { + #for ( my $pass = 1 ; $pass <= 2 ; $pass += 1 ) { + # warn "$htdocs/$th/$la/modules/$interface-"."tmpl"; + #$la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2; + if ( -e "$htdocs/$th/$la/modules/$tmpl") { + #".($interface eq 'intranet'?"modules":"")."/$tmpl" ) { $theme = $th; $lang = $la; last THEME; } last unless $la =~ /[-_]/; - } + #} } } return ( $theme, $lang ); @@ -357,8 +341,8 @@ sub output_html_with_http_headers ($$$) { -type => 'text/html', -charset => 'UTF-8', -cookie => $cookie, - -Pragma => 'no-cache', - -'Cache-Control' => 'no-cache', + -Pragma => 'no-cache', + -'Cache-Control' => 'no-cache', ), $html; }