[Koha-patches] [PATCH] C4::Output adding getlanguagecookie + other enhancements

Henri-Damien LAURENT henridamien.laurent at biblibre.com
Tue Aug 25 23:56:18 CEST 2009


required for language stemming management
Adding also some filters for NSB NSE characters
Now, get_template can be used even when query->cookie not set
---
 C4/Output.pm |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/C4/Output.pm b/C4/Output.pm
index 5bebf6c..731cb7e 100644
--- a/C4/Output.pm
+++ b/C4/Output.pm
@@ -26,7 +26,6 @@ package C4::Output;
 # templates.
 
 use strict;
-use warnings;
 
 use C4::Context;
 use C4::Languages qw(getTranslatedLanguages get_bidi regex_lang_subtags language_get_description accept_language );
@@ -46,7 +45,7 @@ BEGIN {
 					html =>[qw(&output_with_http_headers &output_html_with_http_headers)]
 				);
     push @EXPORT, qw(
-        &themelanguage &gettemplate setlanguagecookie pagination_bar
+        &themelanguage &gettemplate setlanguagecookie getlanguagecookie pagination_bar
     );
     push @EXPORT, qw(
         &output_html_with_http_headers &output_with_http_headers
@@ -81,6 +80,7 @@ sub gettemplate {
     }
     my $path = C4::Context->preference('intranet_includes') || 'includes';
     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/modules/$tmplbase";
@@ -141,7 +141,7 @@ sub themelanguage {
               getTranslatedLanguages($interface,'prog') )
       if $http_accept_language;
     # But, if there's a cookie set, obey it
-    $lang = $query->cookie('KohaOpacLanguage') if $query->cookie('KohaOpacLanguage');
+    $lang = $query->cookie('KohaOpacLanguage') if (defined $query and $query->cookie('KohaOpacLanguage'));
     # Fall back to English
     my @languages;
     if ($interface eq 'intranet') {
@@ -202,6 +202,20 @@ sub setlanguagecookie {
     );
 }
 
+sub getlanguagecookie {
+    my ($query) = @_;
+    my $lang;
+    if ($query->cookie('KohaOpacLanguage')){
+        $lang = $query->cookie('KohaOpacLanguage') ;
+    }else{
+        $lang = $ENV{HTTP_ACCEPT_LANGUAGE};
+        
+    }
+    $lang = substr($lang, 0, 2);
+
+    return $lang;
+}
+
 =item pagination_bar
 
    pagination_bar($base_url, $nb_pages, $current_page, $startfrom_name)
@@ -392,6 +406,9 @@ sub output_with_http_headers($$$$;$) {
         $options->{'Content-Style-Type' } = 'text/css';
         $options->{'Content-Script-Type'} = 'text/javascript';
     }
+    # remove SUDOC specific NSB NSE
+    $data =~ s/\x{C2}\x{98}|\x{C2}\x{9C}/ /g;
+    $data =~ s/\x{C2}\x{88}|\x{C2}\x{89}/ /g;
     print $query->header($options), $data;
 }
 
-- 
1.6.0.4




More information about the Koha-patches mailing list