Lines 29-35
use strict;
Link Here
|
29 |
#use warnings; FIXME - Bug 2505 |
29 |
#use warnings; FIXME - Bug 2505 |
30 |
|
30 |
|
31 |
use C4::Context; |
31 |
use C4::Context; |
32 |
use C4::Languages qw(getTranslatedLanguages get_bidi regex_lang_subtags language_get_description accept_language ); |
|
|
33 |
use C4::Dates qw(format_date); |
32 |
use C4::Dates qw(format_date); |
34 |
use C4::Budgets qw(GetCurrency); |
33 |
use C4::Budgets qw(GetCurrency); |
35 |
use C4::Templates; |
34 |
use C4::Templates; |
Lines 43-234
BEGIN {
Link Here
|
43 |
require Exporter; |
42 |
require Exporter; |
44 |
@ISA = qw(Exporter); |
43 |
@ISA = qw(Exporter); |
45 |
@EXPORT_OK = qw(&is_ajax ajax_fail); # More stuff should go here instead |
44 |
@EXPORT_OK = qw(&is_ajax ajax_fail); # More stuff should go here instead |
46 |
%EXPORT_TAGS = ( all =>[qw(&themelanguage &gettemplate setlanguagecookie pagination_bar |
45 |
%EXPORT_TAGS = ( all =>[qw(&pagination_bar |
47 |
&output_with_http_headers &output_html_with_http_headers)], |
46 |
&output_with_http_headers &output_html_with_http_headers)], |
48 |
ajax =>[qw(&output_with_http_headers is_ajax)], |
47 |
ajax =>[qw(&output_with_http_headers is_ajax)], |
49 |
html =>[qw(&output_with_http_headers &output_html_with_http_headers)] |
48 |
html =>[qw(&output_with_http_headers &output_html_with_http_headers)] |
50 |
); |
49 |
); |
51 |
push @EXPORT, qw( |
50 |
push @EXPORT, qw( |
52 |
&themelanguage &gettemplate setlanguagecookie getlanguagecookie pagination_bar |
51 |
&output_html_with_http_headers &output_with_http_headers FormatData FormatNumber pagination_bar |
53 |
); |
|
|
54 |
push @EXPORT, qw( |
55 |
&output_html_with_http_headers &output_with_http_headers FormatData FormatNumber |
56 |
); |
57 |
} |
58 |
|
59 |
=head1 NAME |
60 |
|
61 |
C4::Output - Functions for managing templates |
62 |
|
63 |
=head1 FUNCTIONS |
64 |
|
65 |
=over 2 |
66 |
|
67 |
=cut |
68 |
|
69 |
#FIXME: this is a quick fix to stop rc1 installing broken |
70 |
#Still trying to figure out the correct fix. |
71 |
my $path = C4::Context->config('intrahtdocs') . "/prog/en/includes/"; |
72 |
|
73 |
#--------------------------------------------------------------------------------------------------------- |
74 |
# FIXME - POD |
75 |
|
76 |
sub _get_template_file { |
77 |
my ( $tmplbase, $interface, $query ) = @_; |
78 |
my $htdocs = C4::Context->config( $interface ne 'intranet' ? 'opachtdocs' : 'intrahtdocs' ); |
79 |
my ( $theme, $lang ) = themelanguage( $htdocs, $tmplbase, $interface, $query ); |
80 |
my $opacstylesheet = C4::Context->preference('opacstylesheet'); |
81 |
|
82 |
# if the template doesn't exist, load the English one as a last resort |
83 |
my $filename = "$htdocs/$theme/$lang/modules/$tmplbase"; |
84 |
unless (-f $filename) { |
85 |
$lang = 'en'; |
86 |
$filename = "$htdocs/$theme/$lang/modules/$tmplbase"; |
87 |
} |
88 |
|
89 |
return ( $htdocs, $theme, $lang, $filename ); |
90 |
} |
91 |
|
92 |
sub gettemplate { |
93 |
my ( $tmplbase, $interface, $query ) = @_; |
94 |
($query) or warn "no query in gettemplate"; |
95 |
my $path = C4::Context->preference('intranet_includes') || 'includes'; |
96 |
my $opacstylesheet = C4::Context->preference('opacstylesheet'); |
97 |
$tmplbase =~ s/\.tmpl$/.tt/; |
98 |
my ( $htdocs, $theme, $lang, $filename ) = _get_template_file( $tmplbase, $interface, $query ); |
99 |
my $template = C4::Templates->new( $interface, $filename, $tmplbase); |
100 |
my $themelang=( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' ) |
101 |
. "/$theme/$lang"; |
102 |
$template->param( |
103 |
themelang => $themelang, |
104 |
yuipath => (C4::Context->preference("yuipath") eq "local"?"$themelang/lib/yui":C4::Context->preference("yuipath")), |
105 |
interface => ( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' ), |
106 |
theme => $theme, |
107 |
lang => $lang |
108 |
); |
109 |
|
110 |
# Bidirectionality |
111 |
my $current_lang = regex_lang_subtags($lang); |
112 |
my $bidi; |
113 |
$bidi = get_bidi($current_lang->{script}) if $current_lang->{script}; |
114 |
# Languages |
115 |
my $languages_loop = getTranslatedLanguages($interface,$theme,$lang); |
116 |
my $num_languages_enabled = 0; |
117 |
foreach my $lang (@$languages_loop) { |
118 |
foreach my $sublang (@{ $lang->{'sublanguages_loop'} }) { |
119 |
$num_languages_enabled++ if $sublang->{enabled}; |
120 |
} |
121 |
} |
122 |
$template->param( |
123 |
languages_loop => $languages_loop, |
124 |
bidi => $bidi, |
125 |
one_language_enabled => ($num_languages_enabled <= 1) ? 1 : 0, # deal with zero enabled langs as well |
126 |
) unless @$languages_loop<2; |
127 |
|
128 |
return $template; |
129 |
} |
130 |
|
131 |
# FIXME - this is a horrible hack to cache |
132 |
# the current known-good language, temporarily |
133 |
# put in place to resolve bug 4403. It is |
134 |
# used only by C4::XSLT::XSLTParse4Display; |
135 |
# the language is set via the usual call |
136 |
# to themelanguage. |
137 |
my $_current_language = 'en'; |
138 |
sub _current_language { |
139 |
return $_current_language; |
140 |
} |
141 |
|
142 |
#--------------------------------------------------------------------------------------------------------- |
143 |
# FIXME - POD |
144 |
sub themelanguage { |
145 |
my ( $htdocs, $tmpl, $interface, $query ) = @_; |
146 |
($query) or warn "no query in themelanguage"; |
147 |
|
148 |
# Set some defaults for language and theme |
149 |
# First, check the user's preferences |
150 |
my $lang; |
151 |
my $http_accept_language = $ENV{ HTTP_ACCEPT_LANGUAGE }; |
152 |
$lang = accept_language( $http_accept_language, |
153 |
getTranslatedLanguages($interface,'prog') ) |
154 |
if $http_accept_language; |
155 |
# But, if there's a cookie set, obey it |
156 |
$lang = $query->cookie('KohaOpacLanguage') if (defined $query and $query->cookie('KohaOpacLanguage')); |
157 |
# Fall back to English |
158 |
my @languages; |
159 |
if ($interface eq 'intranet') { |
160 |
@languages = split ",", C4::Context->preference("language"); |
161 |
} else { |
162 |
@languages = split ",", C4::Context->preference("opaclanguages"); |
163 |
} |
164 |
if ($lang){ |
165 |
@languages=($lang,@languages); |
166 |
} else { |
167 |
$lang = $languages[0]; |
168 |
} |
169 |
my $theme = 'prog'; # in the event of theme failure default to 'prog' -fbcit |
170 |
my $dbh = C4::Context->dbh; |
171 |
my @themes; |
172 |
if ( $interface eq "intranet" ) { |
173 |
@themes = split " ", C4::Context->preference("template"); |
174 |
} |
175 |
else { |
176 |
# we are in the opac here, what im trying to do is let the individual user |
177 |
# set the theme they want to use. |
178 |
# and perhaps the them as well. |
179 |
#my $lang = $query->cookie('KohaOpacLanguage'); |
180 |
@themes = split " ", C4::Context->preference("opacthemes"); |
181 |
} |
182 |
|
183 |
# searches through the themes and languages. First template it find it returns. |
184 |
# Priority is for getting the theme right. |
185 |
THEME: |
186 |
foreach my $th (@themes) { |
187 |
foreach my $la (@languages) { |
188 |
#for ( my $pass = 1 ; $pass <= 2 ; $pass += 1 ) { |
189 |
# warn "$htdocs/$th/$la/modules/$interface-"."tmpl"; |
190 |
#$la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2; |
191 |
if ( -e "$htdocs/$th/$la/modules/$tmpl") { |
192 |
#".($interface eq 'intranet'?"modules":"")."/$tmpl" ) { |
193 |
$theme = $th; |
194 |
$lang = $la; |
195 |
last THEME; |
196 |
} |
197 |
last unless $la =~ /[-_]/; |
198 |
#} |
199 |
} |
200 |
} |
201 |
|
202 |
$_current_language = $lang; # FIXME part of bad hack to paper over bug 4403 |
203 |
return ( $theme, $lang ); |
204 |
} |
205 |
|
206 |
sub setlanguagecookie { |
207 |
my ( $query, $language, $uri ) = @_; |
208 |
my $cookie = $query->cookie( |
209 |
-name => 'KohaOpacLanguage', |
210 |
-value => $language, |
211 |
-expires => '' |
212 |
); |
213 |
print $query->redirect( |
214 |
-uri => $uri, |
215 |
-cookie => $cookie |
216 |
); |
52 |
); |
217 |
} |
53 |
} |
218 |
|
54 |
|
219 |
sub getlanguagecookie { |
|
|
220 |
my ($query) = @_; |
221 |
my $lang; |
222 |
if ($query->cookie('KohaOpacLanguage')){ |
223 |
$lang = $query->cookie('KohaOpacLanguage') ; |
224 |
}else{ |
225 |
$lang = $ENV{HTTP_ACCEPT_LANGUAGE}; |
226 |
|
227 |
} |
228 |
$lang = substr($lang, 0, 2); |
229 |
|
230 |
return $lang; |
231 |
} |
232 |
|
55 |
|
233 |
=item FormatNumber |
56 |
=item FormatNumber |
234 |
=cut |
57 |
=cut |