test suite cleanup
[srvgit] / C4 / Output.pm
index c96573f..1c12a73 100644 (file)
@@ -26,7 +26,6 @@ package C4::Output;
 # templates.
 
 use strict;
-require Exporter;
 
 use C4::Context;
 use C4::Languages qw(getTranslatedLanguages get_bidi regex_lang_subtags language_get_description accept_language );
@@ -34,8 +33,18 @@ use C4::Languages qw(getTranslatedLanguages get_bidi regex_lang_subtags 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,12 +56,6 @@ C4::Output - Functions for managing templates
 
 =cut
 
-@ISA    = qw(Exporter);
-push @EXPORT, qw(
-  &themelanguage &gettemplate setlanguagecookie pagination_bar &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/";
@@ -61,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');
@@ -77,7 +78,7 @@ sub gettemplate {
     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";
+       my $filename = "$htdocs/$theme/$lang/modules/$tmplbase";
        unless (-f $filename) {
                $lang = 'en';
                $filename = "$htdocs/$theme/$lang/".($interface eq 'intranet'?"modules":"")."/$tmplbase";
@@ -137,12 +138,15 @@ sub gettemplate {
 # FIXME - POD
 sub themelanguage {
     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;
-       $lang = accept_language($ENV{HTTP_ACCEPT_LANGUAGE},getTranslatedLanguages($interface,'prog'));
-
+       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');
 
@@ -156,23 +160,20 @@ sub themelanguage {
     if ( $interface eq "intranet" ) {
         @languages = split " ", C4::Context->preference("opaclanguages");
         @themes    = split " ", C4::Context->preference("template");
-        pop @languages, $lang if $lang;
+        push @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) {
-
+        if ($lang) {                                           # FIXME: if $lang always TRUE!
             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.