use strict;
use warnings;
-use Carp;
+use Carp qw( carp );
use CGI qw ( -utf8 );
-use List::MoreUtils qw/ any uniq /;
+use List::MoreUtils qw( uniq );
# Copyright 2009 Chris Cormack and The Koha Dev Team
#
use base qw(Class::Accessor);
use Template;
-use Template::Constants qw( :debug );
-use C4::Languages qw(getTranslatedLanguages get_bidi regex_lang_subtags language_get_description accept_language );
+use C4::Languages qw( get_bidi getTranslatedLanguages regex_lang_subtags );
use C4::Context;
$vars->{opaclayoutstylesheet} =
C4::Context->preference('opaclayoutstylesheet');
+ if(exists $self->{VARS}{lang}) {
+ warn "Preventing \$template->lang='" . ($self->{vars}{lang}//'-undef-')
+ . "' to be overwritten by template->{VARS}{lang}='" . ($self->{VARS}{lang}//'-undef-') . "'";
+ delete $self->{VARS}{lang};
+ }
+
# add variables set via param to $vars for processing
$vars = { %$vars, %{ $self->{VARS} } };
my $data;
- binmode( STDOUT, ":utf8" );
+ binmode( STDOUT, ":encoding(UTF-8)" );
$template->process( $self->filename, $vars, \$data )
|| die "Template process failed: ", $template->error();
return $data;
# This also includes two dots
Koha::Exceptions::NoPermission->throw( 'bad template path' );
} else {
- # Check allowed dirs
+ # Check allowed dirs - make sure we operate on a copy of the config
my $dirs = C4::Context->config("pluginsdir");
- $dirs = [ $dirs ] if !ref($dirs);
+ if ( !ref($dirs) ) {
+ $dirs = [ $dirs ];
+ }
+ else {
+ $dirs = [ @$dirs ];
+ }
unshift @$dirs, C4::Context->config('opachtdocs'), C4::Context->config('intrahtdocs');
my $found = 0;
foreach my $dir ( @$dirs ) {
sub gettemplate {
my ( $tmplbase, $interface, $query ) = @_;
- ($query) or warn "no query in gettemplate";
my ($htdocs, $theme, $lang, $filename)
= _get_template_file($tmplbase, $interface, $query);
badtemplatecheck( $filename ); # single trip for bad templates
sub themelanguage {
my ($htdocs, $tmpl, $interface, $query) = @_;
- ($query) or warn "no query in themelanguage";
# Select a language based on cookie, syspref available languages & browser
my $lang = C4::Languages::getlanguage($query);
+ return availablethemes($htdocs, $tmpl, $interface, $lang);
+}
+
+sub availablethemes {
+ my ($htdocs, $tmpl, $interface, $lang) = @_;
+
# Get theme
my @themes;
my $theme_syspref = ($interface eq 'intranet') ? 'template' : 'opacthemes';
}
}
-
sub setlanguagecookie {
my ( $query, $language, $uri ) = @_;
-name => 'KohaOpacLanguage',
-value => $language,
-HttpOnly => 1,
- -expires => '+3y'
+ -expires => '+3y',
+ -sameSite => 'Lax',
+ -secure => ( C4::Context->https_enabled() ? 1 : 0 ),
);
return $cookie;
}
-=head2 GetColumnDefs
-
- my $columns = GetColumnDefs( $cgi )
-
-It is passed a CGI object and returns a hash of hashes containing
-the column names and descriptions for each table defined in the
-columns.def file corresponding to the CGI object.
-
-=cut
-
-sub GetColumnDefs {
-
- my $query = shift;
-
- my $columns = {};
-
- my $htdocs = C4::Context->config('intrahtdocs');
- my $columns_file = 'columns.def';
-
- # Get theme and language to build the path to columns.def
- my ($theme, $lang, $availablethemes) =
- themelanguage($htdocs, 'about.tt', 'intranet', $query);
- # Build columns.def path
- my $path = "$htdocs/$theme/$lang/$columns_file";
- my $fh;
- if ( ! open ( $fh, q{<:encoding(utf-8)}, $path ) ) {
- carp "Error opening $path. Check your templates.";
- return;
- }
- # Loop through the columns.def file
- while ( my $input = <$fh> ){
- chomp $input;
- if ( $input =~ m|<field name="(.*)">(.*)</field>| ) {
- my ( $table, $column ) = split( '\.', $1);
- my $description = $2;
- # Initialize the table array if needed.
- @{$columns->{ $table }} = () if ! defined $columns->{ $table };
- # Push field and description
- push @{$columns->{ $table }},
- { field => $column, description => $description };
- }
- }
- close $fh;
-
- return $columns;
-}
-
1;