From 3c30f8b69e2eed22463e48e479a3594813f15c5c Mon Sep 17 00:00:00 2001 From: tipaul Date: Wed, 2 Oct 2002 16:26:14 +0000 Subject: [PATCH] templating modifications to rspect finlay structure --- C4/Database.pm | 21 ++++++++- C4/Output.pm | 116 +++++++++++++++++++++++++------------------------ 2 files changed, 79 insertions(+), 58 deletions(-) diff --git a/C4/Database.pm b/C4/Database.pm index 63d828dcd2..d0a9192c36 100755 --- a/C4/Database.pm +++ b/C4/Database.pm @@ -29,9 +29,28 @@ $VERSION = 0.01; @ISA = qw(Exporter); @EXPORT = qw( - &C4Connect &requireDBI + &C4Connect &requireDBI &configfile ); +sub configfile { + my $configfile; + open (KC, "/etc/koha.conf"); + while () { + chomp; + (next) if (/^\s*#/); + if (/(.*)\s*=\s*(.*)/) { + my $variable=$1; + my $value=$2; + # Clean up white space at beginning and end + $variable=~s/^\s*//g; + $variable=~s/\s*$//g; + $value=~s/^\s*//g; + $value=~s/\s*$//g; + $configfile->{$variable}=$value; + } + } + return $configfile; +} sub C4Connect { my $dbname="c4"; diff --git a/C4/Output.pm b/C4/Output.pm index f00d5004ea..6ed22c5066 100644 --- a/C4/Output.pm +++ b/C4/Output.pm @@ -64,7 +64,8 @@ printable string. &gotopage &mkformnotable &mkform3 &getkeytableselectoptions &pathtotemplate - &picktemplate); + &themelanguage &gettemplate + ); %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], # your exported package globals go here, @@ -97,76 +98,77 @@ my @more = (); # FIXME - Since this is used in several places, it ought to be put # into a separate file. Better yet, put "use C4::Config;" inside the # &import method of any package that requires the config file. -my %configfile; -open (KC, "/etc/koha.conf"); -while () { - chomp; - (next) if (/^\s*#/); - if (/(.*)\s*=\s*(.*)/) { - my $variable=$1; - my $value=$2; - - $variable =~ s/^\s*//g; - $variable =~ s/\s*$//g; - $value =~ s/^\s*//g; - $value =~ s/\s*$//g; - $configfile{$variable}=$value; - } # if -} # while -close(KC); - -my $path=$configfile{'includes'}; + +my $configfile=configfile(); + +my $path=$configfile->{'includes'}; ($path) || ($path="/usr/local/www/hdl/htdocs/includes"); -# make all your functions, whether exported or not; +#--------------------------------------------------------------------------------------------------------- +sub gettemplate { + my ($tmplbase, $opac) = @_; + + my $htdocs; + if ($opac) { + $htdocs = $configfile->{'opachtdocs'}; + } else { + $htdocs = $configfile->{'intrahtdocs'}; + } -=item picktemplate + my ($theme, $lang) = themelanguage($htdocs, $tmplbase); - $template = &picktemplate($includes, $base); + my $template = HTML::Template->new(filename => "$htdocs/$theme/$lang/$tmplbase", + die_on_bad_params => 0, + global_vars => 1, + path => ["$htdocs/$theme/$lang/includes"]); -Returns the preferred template for a given page. C<$base> is the -basename of the script that will generate the page (with the C<.pl> -extension stripped off), and C<$includes> is the directory in which -HTML include files are located. + $template->param(themelang => "/$theme/$lang"); + return $template; +} -The preferred template is given by the C