Filename | /home/vagrant/kohaclone/C4/Templates.pm |
Statements | Executed 1167 statements in 5.48ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.43ms | 18.7ms | BEGIN@33 | C4::Templates::
2 | 1 | 1 | 932µs | 932µs | CORE:ftis (opcode) | C4::Templates::
105 | 30 | 3 | 417µs | 417µs | param | C4::Templates::
1 | 1 | 1 | 218µs | 167ms | output | C4::Templates::
2 | 2 | 1 | 120µs | 39.8ms | themelanguage | C4::Templates::
1 | 1 | 1 | 108µs | 96.3ms | gettemplate | C4::Templates::
1 | 1 | 1 | 100µs | 33.8ms | new | C4::Templates::
1 | 1 | 1 | 28µs | 42µs | BEGIN@3 | C4::Templates::
1 | 1 | 1 | 26µs | 23.5ms | _get_template_file | C4::Templates::
1 | 1 | 1 | 17µs | 84µs | BEGIN@35 | C4::Templates::
1 | 1 | 1 | 17µs | 112µs | BEGIN@32 | C4::Templates::
1 | 1 | 1 | 16µs | 26µs | BEGIN@4 | C4::Templates::
1 | 1 | 1 | 15µs | 47µs | BEGIN@7 | C4::Templates::
1 | 1 | 1 | 14µs | 45µs | BEGIN@6 | C4::Templates::
1 | 1 | 1 | 13µs | 207µs | BEGIN@34 | C4::Templates::
1 | 1 | 1 | 13µs | 16µs | BEGIN@37 | C4::Templates::
1 | 1 | 1 | 11µs | 68µs | BEGIN@5 | C4::Templates::
1 | 1 | 1 | 10µs | 10µs | CORE:binmode (opcode) | C4::Templates::
2 | 1 | 1 | 3µs | 3µs | CORE:match (opcode) | C4::Templates::
0 | 0 | 0 | 0s | 0s | GetColumnDefs | C4::Templates::
0 | 0 | 0 | 0s | 0s | getlanguagecookie | C4::Templates::
0 | 0 | 0 | 0s | 0s | setlanguagecookie | C4::Templates::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package C4::Templates; | ||||
2 | |||||
3 | 2 | 54µs | 2 | 55µs | # spent 42µs (28+13) within C4::Templates::BEGIN@3 which was called:
# once (28µs+13µs) by C4::Output::BEGIN@34 at line 3 # spent 42µs making 1 call to C4::Templates::BEGIN@3
# spent 13µs making 1 call to strict::import |
4 | 2 | 44µs | 2 | 37µs | # spent 26µs (16+11) within C4::Templates::BEGIN@4 which was called:
# once (16µs+11µs) by C4::Output::BEGIN@34 at line 4 # spent 26µs making 1 call to C4::Templates::BEGIN@4
# spent 11µs making 1 call to warnings::import |
5 | 2 | 98µs | 2 | 125µs | # spent 68µs (11+57) within C4::Templates::BEGIN@5 which was called:
# once (11µs+57µs) by C4::Output::BEGIN@34 at line 5 # spent 68µs making 1 call to C4::Templates::BEGIN@5
# spent 57µs making 1 call to Exporter::import |
6 | 2 | 79µs | 2 | 77µs | # spent 45µs (14+32) within C4::Templates::BEGIN@6 which was called:
# once (14µs+32µs) by C4::Output::BEGIN@34 at line 6 # spent 45µs making 1 call to C4::Templates::BEGIN@6
# spent 32µs making 1 call to CGI::import |
7 | 2 | 90µs | 2 | 79µs | # spent 47µs (15+32) within C4::Templates::BEGIN@7 which was called:
# once (15µs+32µs) by C4::Output::BEGIN@34 at line 7 # spent 47µs making 1 call to C4::Templates::BEGIN@7
# spent 32µs making 1 call to Exporter::import |
8 | |||||
9 | # Copyright 2009 Chris Cormack and The Koha Dev Team | ||||
10 | # | ||||
11 | # This file is part of Koha. | ||||
12 | # | ||||
13 | # Koha is free software; you can redistribute it and/or modify it | ||||
14 | # under the terms of the GNU General Public License as published by | ||||
15 | # the Free Software Foundation; either version 3 of the License, or | ||||
16 | # (at your option) any later version. | ||||
17 | # | ||||
18 | # Koha is distributed in the hope that it will be useful, but | ||||
19 | # WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
21 | # GNU General Public License for more details. | ||||
22 | # | ||||
23 | # You should have received a copy of the GNU General Public License | ||||
24 | # along with Koha; if not, see <http://www.gnu.org/licenses>. | ||||
25 | |||||
26 | =head1 NAME | ||||
27 | |||||
28 | Koha::Templates - Object for manipulating templates for use with Koha | ||||
29 | |||||
30 | =cut | ||||
31 | |||||
32 | 2 | 148µs | 2 | 208µs | # spent 112µs (17+95) within C4::Templates::BEGIN@32 which was called:
# once (17µs+95µs) by C4::Output::BEGIN@34 at line 32 # spent 112µs making 1 call to C4::Templates::BEGIN@32
# spent 95µs making 1 call to base::import |
33 | 2 | 237µs | 1 | 18.7ms | # spent 18.7ms (1.43+17.3) within C4::Templates::BEGIN@33 which was called:
# once (1.43ms+17.3ms) by C4::Output::BEGIN@34 at line 33 # spent 18.7ms making 1 call to C4::Templates::BEGIN@33 |
34 | 2 | 237µs | 2 | 400µs | # spent 207µs (13+194) within C4::Templates::BEGIN@34 which was called:
# once (13µs+194µs) by C4::Output::BEGIN@34 at line 34 # spent 207µs making 1 call to C4::Templates::BEGIN@34
# spent 194µs making 1 call to Exporter::import |
35 | 2 | 107µs | 2 | 150µs | # spent 84µs (17+66) within C4::Templates::BEGIN@35 which was called:
# once (17µs+66µs) by C4::Output::BEGIN@34 at line 35 # spent 84µs making 1 call to C4::Templates::BEGIN@35
# spent 66µs making 1 call to Exporter::import |
36 | |||||
37 | 2 | 1.60ms | 2 | 20µs | # spent 16µs (13+4) within C4::Templates::BEGIN@37 which was called:
# once (13µs+4µs) by C4::Output::BEGIN@34 at line 37 # spent 16µs making 1 call to C4::Templates::BEGIN@37
# spent 4µs making 1 call to C4::Context::import |
38 | |||||
39 | 1 | 222µs | 1 | 208µs | __PACKAGE__->mk_accessors(qw( theme activethemes preferredtheme lang filename htdocs interface vars)); # spent 208µs making 1 call to Class::Accessor::mk_accessors |
40 | |||||
- - | |||||
43 | # spent 33.8ms (100µs+33.7) within C4::Templates::new which was called:
# once (100µs+33.7ms) by C4::Templates::gettemplate at line 178 | ||||
44 | 1 | 700ns | my $class = shift; | ||
45 | 1 | 400ns | my $interface = shift; | ||
46 | 1 | 300ns | my $filename = shift; | ||
47 | 1 | 400ns | my $tmplbase = shift; | ||
48 | 1 | 1µs | my $query = @_? shift: undef; | ||
49 | 1 | 300ns | my $htdocs; | ||
50 | 1 | 1µs | if ( $interface ne "intranet" ) { | ||
51 | $htdocs = C4::Context->config('opachtdocs'); | ||||
52 | } | ||||
53 | else { | ||||
54 | 1 | 13µs | 1 | 6µs | $htdocs = C4::Context->config('intrahtdocs'); # spent 6µs making 1 call to C4::Context::config |
55 | } | ||||
56 | 1 | 4µs | 1 | 16.3ms | my ($theme, $lang, $activethemes)= themelanguage( $htdocs, $tmplbase, $interface, $query); # spent 16.3ms making 1 call to C4::Templates::themelanguage |
57 | 1 | 400ns | my @includes; | ||
58 | 1 | 2µs | foreach (@$activethemes) { | ||
59 | 3 | 6µs | push @includes, "$htdocs/$_/$lang/includes"; | ||
60 | 3 | 1µs | push @includes, "$htdocs/$_/en/includes" unless $lang eq 'en'; | ||
61 | } | ||||
62 | # Do not use template cache if script is called from commandline | ||||
63 | 1 | 12µs | 1 | 6µs | my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE}; # spent 6µs making 1 call to C4::Context::config |
64 | 1 | 21µs | 1 | 17.4ms | my $template = Template->new( # spent 17.4ms making 1 call to Template::Base::new |
65 | { EVAL_PERL => 1, | ||||
66 | ABSOLUTE => 1, | ||||
67 | PLUGIN_BASE => 'Koha::Template::Plugin', | ||||
68 | COMPILE_EXT => $use_template_cache ? '.ttc' : '', | ||||
69 | COMPILE_DIR => $use_template_cache ? C4::Context->config('template_cache_dir') : '', | ||||
70 | INCLUDE_PATH => \@includes, | ||||
71 | FILTERS => {}, | ||||
72 | ENCODING => 'UTF-8', | ||||
73 | } | ||||
74 | ) or die Template->error(); | ||||
75 | 1 | 2µs | my $self = { | ||
76 | TEMPLATE => $template, | ||||
77 | VARS => {}, | ||||
78 | }; | ||||
79 | 1 | 4µs | bless $self, $class; | ||
80 | 1 | 25µs | 1 | 18µs | $self->theme($theme); # spent 18µs making 1 call to C4::Templates::theme |
81 | 1 | 8µs | 1 | 4µs | $self->lang($lang); # spent 4µs making 1 call to C4::Templates::lang |
82 | 1 | 8µs | 1 | 3µs | $self->activethemes($activethemes); # spent 3µs making 1 call to C4::Templates::activethemes |
83 | 1 | 7µs | 1 | 3µs | $self->preferredtheme($activethemes->[0]); # spent 3µs making 1 call to C4::Templates::preferredtheme |
84 | 1 | 8µs | 1 | 4µs | $self->filename($filename); # spent 4µs making 1 call to C4::Templates::filename |
85 | 1 | 8µs | 1 | 4µs | $self->htdocs($htdocs); # spent 4µs making 1 call to C4::Templates::htdocs |
86 | 1 | 6µs | 1 | 3µs | $self->interface($interface); # spent 3µs making 1 call to C4::Templates::interface |
87 | 1 | 2µs | $self->{VARS}->{"test"} = "value"; | ||
88 | 1 | 5µs | return $self; | ||
89 | |||||
90 | } | ||||
91 | |||||
92 | # spent 167ms (218µs+167) within C4::Templates::output which was called:
# once (218µs+167ms) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::__ANON__[/home/vagrant/kohaclone/mainpage.pl:107] at line 87 of mainpage.pl | ||||
93 | 1 | 400ns | my $self = shift; | ||
94 | 1 | 300ns | my $vars = shift; | ||
95 | |||||
96 | # my $file = $self->htdocs . '/' . $self->theme .'/'.$self->lang.'/'.$self->filename; | ||||
97 | 1 | 800ns | my $template = $self->{TEMPLATE}; | ||
98 | 1 | 14µs | 1 | 10µs | if ( $self->interface eq 'intranet' ) { # spent 10µs making 1 call to C4::Templates::interface |
99 | $vars->{themelang} = '/intranet-tmpl'; | ||||
100 | } | ||||
101 | else { | ||||
102 | $vars->{themelang} = '/opac-tmpl'; | ||||
103 | } | ||||
104 | 1 | 7µs | 1 | 3µs | $vars->{lang} = $self->lang; # spent 3µs making 1 call to C4::Templates::lang |
105 | 1 | 11µs | 2 | 4µs | $vars->{themelang} .= '/' . $self->preferredtheme . '/' . $self->lang; # spent 3µs making 1 call to C4::Templates::preferredtheme
# spent 1µs making 1 call to C4::Templates::lang |
106 | 1 | 2µs | $vars->{interface} = | ||
107 | ( $self->{interface} ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' ); | ||||
108 | 1 | 7µs | 1 | 3µs | $vars->{theme} = $self->theme; # spent 3µs making 1 call to C4::Templates::theme |
109 | 1 | 14µs | 1 | 2.41ms | $vars->{OpacAdditionalStylesheet} = # spent 2.41ms making 1 call to C4::Context::preference |
110 | C4::Context->preference('OpacAdditionalStylesheet'); | ||||
111 | 1 | 10µs | 1 | 2.07ms | $vars->{opaclayoutstylesheet} = # spent 2.07ms making 1 call to C4::Context::preference |
112 | C4::Context->preference('opaclayoutstylesheet'); | ||||
113 | |||||
114 | # add variables set via param to $vars for processing | ||||
115 | 1 | 41µs | for my $k ( keys %{ $self->{VARS} } ) { | ||
116 | 160 | 98µs | $vars->{$k} = $self->{VARS}->{$k}; | ||
117 | } | ||||
118 | |||||
119 | 1 | 200ns | my $data; | ||
120 | 1 | 16µs | 1 | 10µs | binmode( STDOUT, ":utf8" ); # spent 10µs making 1 call to C4::Templates::CORE:binmode |
121 | 1 | 16µs | 2 | 163ms | $template->process( $self->filename, $vars, \$data ) # spent 163ms making 1 call to Template::process
# spent 7µs making 1 call to C4::Templates::filename |
122 | || die "Template process failed: ", $template->error(); | ||||
123 | 1 | 26µs | return $data; | ||
124 | } | ||||
125 | |||||
126 | # wrapper method to allow easier transition from HTML template pro to Template Toolkit | ||||
127 | # spent 417µs within C4::Templates::param which was called 105 times, avg 4µs/call:
# 76 times (195µs+0s) by C4::Auth::get_template_and_user at line 282 of C4/Auth.pm, avg 3µs/call
# once (58µs+0s) by C4::Auth::get_template_and_user at line 433 of C4/Auth.pm
# once (42µs+0s) by C4::Auth::get_template_and_user at line 409 of C4/Auth.pm
# once (17µs+0s) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::__ANON__[/home/vagrant/kohaclone/mainpage.pl:107] at line 72 of mainpage.pl
# once (14µs+0s) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::__ANON__[/home/vagrant/kohaclone/mainpage.pl:107] at line 53 of mainpage.pl
# once (10µs+0s) by C4::Auth::get_template_and_user at line 228 of C4/Auth.pm
# once (9µs+0s) by C4::Auth::get_template_and_user at line 396 of C4/Auth.pm
# once (8µs+0s) by C4::Templates::gettemplate at line 197
# once (5µs+0s) by C4::Auth::get_template_and_user at line 400 of C4/Auth.pm
# once (5µs+0s) by C4::Auth::get_template_and_user at line 262 of C4/Auth.pm
# once (4µs+0s) by C4::Auth::get_template_and_user at line 251 of C4/Auth.pm
# once (4µs+0s) by C4::Auth::get_template_and_user at line 263 of C4/Auth.pm
# once (3µs+0s) by C4::Auth::get_template_and_user at line 269 of C4/Auth.pm
# once (3µs+0s) by C4::Auth::get_template_and_user at line 265 of C4/Auth.pm
# once (3µs+0s) by C4::Auth::get_template_and_user at line 304 of C4/Auth.pm
# once (3µs+0s) by C4::Auth::get_template_and_user at line 273 of C4/Auth.pm
# once (3µs+0s) by C4::Auth::get_template_and_user at line 271 of C4/Auth.pm
# once (3µs+0s) by C4::Auth::get_template_and_user at line 229 of C4/Auth.pm
# once (3µs+0s) by C4::Auth::get_template_and_user at line 268 of C4/Auth.pm
# once (3µs+0s) by C4::Auth::get_template_and_user at line 278 of C4/Auth.pm
# once (3µs+0s) by C4::Auth::get_template_and_user at line 230 of C4/Auth.pm
# once (2µs+0s) by C4::Auth::get_template_and_user at line 275 of C4/Auth.pm
# once (2µs+0s) by C4::Auth::get_template_and_user at line 266 of C4/Auth.pm
# once (2µs+0s) by C4::Auth::get_template_and_user at line 270 of C4/Auth.pm
# once (2µs+0s) by C4::Auth::get_template_and_user at line 276 of C4/Auth.pm
# once (2µs+0s) by C4::Auth::get_template_and_user at line 264 of C4/Auth.pm
# once (2µs+0s) by C4::Auth::get_template_and_user at line 272 of C4/Auth.pm
# once (2µs+0s) by C4::Auth::get_template_and_user at line 277 of C4/Auth.pm
# once (2µs+0s) by C4::Auth::get_template_and_user at line 274 of C4/Auth.pm
# once (2µs+0s) by C4::Auth::get_template_and_user at line 267 of C4/Auth.pm | ||||
128 | 105 | 17µs | my $self = shift; | ||
129 | 105 | 197µs | while (@_) { | ||
130 | 160 | 29µs | my $key = shift; | ||
131 | 160 | 21µs | my $val = shift; | ||
132 | 160 | 42µs | if ( ref($val) eq 'ARRAY' && !scalar @$val ) { $val = undef; } | ||
133 | elsif ( ref($val) eq 'HASH' && !scalar %$val ) { $val = undef; } | ||||
134 | 160 | 208µs | if ( $key ) { | ||
135 | $self->{VARS}->{$key} = $val; | ||||
136 | } else { | ||||
137 | warn "Problem = a value of $val has been passed to param without key"; | ||||
138 | } | ||||
139 | } | ||||
140 | } | ||||
141 | |||||
142 | |||||
143 | =head1 NAME | ||||
144 | |||||
145 | C4::Templates - Functions for managing templates | ||||
146 | |||||
147 | =head1 FUNCTIONS | ||||
148 | |||||
149 | =cut | ||||
150 | |||||
151 | # FIXME: this is a quick fix to stop rc1 installing broken | ||||
152 | # Still trying to figure out the correct fix. | ||||
153 | 1 | 22µs | 1 | 16µs | my $path = C4::Context->config('intrahtdocs') . "/prog/en/includes/"; # spent 16µs making 1 call to C4::Context::config |
154 | |||||
155 | #--------------------------------------------------------------------------------------------------------- | ||||
156 | # FIXME - POD | ||||
157 | |||||
158 | # spent 23.5ms (26µs+23.5) within C4::Templates::_get_template_file which was called:
# once (26µs+23.5ms) by C4::Templates::gettemplate at line 175 | ||||
159 | 1 | 1µs | my ($tmplbase, $interface, $query) = @_; | ||
160 | |||||
161 | 1 | 800ns | my $is_intranet = $interface eq 'intranet'; | ||
162 | 1 | 12µs | 1 | 6µs | my $htdocs = C4::Context->config($is_intranet ? 'intrahtdocs' : 'opachtdocs'); # spent 6µs making 1 call to C4::Context::config |
163 | 1 | 6µs | 1 | 23.5ms | my ($theme, $lang, $availablethemes) = themelanguage($htdocs, $tmplbase, $interface, $query); # spent 23.5ms making 1 call to C4::Templates::themelanguage |
164 | 1 | 300ns | $lang //= 'en'; | ||
165 | 1 | 4µs | my $filename = "$htdocs/$theme/$lang/modules/$tmplbase"; | ||
166 | |||||
167 | 1 | 5µs | return ($htdocs, $theme, $lang, $filename); | ||
168 | } | ||||
169 | |||||
170 | |||||
171 | # spent 96.3ms (108µs+96.2) within C4::Templates::gettemplate which was called:
# once (108µs+96.2ms) by C4::Auth::get_template_and_user at line 166 of C4/Auth.pm | ||||
172 | 1 | 2µs | my ( $tmplbase, $interface, $query, $is_plugin ) = @_; | ||
173 | 1 | 1µs | ($query) or warn "no query in gettemplate"; | ||
174 | 1 | 23µs | 1 | 3.54ms | my $path = C4::Context->preference('intranet_includes') || 'includes'; # spent 3.54ms making 1 call to C4::Context::preference |
175 | 1 | 4µs | 1 | 23.5ms | my ($htdocs, $theme, $lang, $filename) # spent 23.5ms making 1 call to C4::Templates::_get_template_file |
176 | = _get_template_file($tmplbase, $interface, $query); | ||||
177 | 1 | 400ns | $filename = $tmplbase if ( $is_plugin ); | ||
178 | 1 | 9µs | 1 | 33.8ms | my $template = C4::Templates->new($interface, $filename, $tmplbase, $query); # spent 33.8ms making 1 call to C4::Templates::new |
179 | |||||
180 | # NOTE: Commenting these out rather than deleting them so that those who need | ||||
181 | # to know how we previously shimmed these directories will be able to understand. | ||||
182 | # my $is_intranet = $interface eq 'intranet'; | ||||
183 | # my $themelang = | ||||
184 | # ($is_intranet ? '/intranet-tmpl' : '/opac-tmpl') . | ||||
185 | # "/$theme/$lang"; | ||||
186 | # $template->param( | ||||
187 | # themelang => $themelang, | ||||
188 | # interface => $is_intranet ? '/intranet-tmpl' : '/opac-tmpl', | ||||
189 | # theme => $theme, | ||||
190 | # lang => $lang | ||||
191 | # ); | ||||
192 | |||||
193 | # Bidirectionality, must be sent even if is the only language | ||||
194 | 1 | 344µs | 1 | 336µs | my $current_lang = regex_lang_subtags($lang); # spent 336µs making 1 call to C4::Languages::regex_lang_subtags |
195 | 1 | 300ns | my $bidi; | ||
196 | 1 | 900ns | $bidi = get_bidi($current_lang->{script}) if $current_lang->{script}; | ||
197 | 1 | 3µs | 1 | 8µs | $template->param( # spent 8µs making 1 call to C4::Templates::param |
198 | bidi => $bidi, | ||||
199 | ); | ||||
200 | # Languages | ||||
201 | 1 | 23µs | 1 | 35.0ms | my $languages_loop = getTranslatedLanguages($interface,$theme,$lang); # spent 35.0ms making 1 call to C4::Languages::getTranslatedLanguages |
202 | 1 | 500ns | my $num_languages_enabled = 0; | ||
203 | 1 | 2µs | foreach my $lang (@$languages_loop) { | ||
204 | 19 | 12µs | foreach my $sublang (@{ $lang->{'sublanguages_loop'} }) { | ||
205 | 21 | 11µs | $num_languages_enabled++ if $sublang->{enabled}; | ||
206 | } | ||||
207 | } | ||||
208 | 1 | 900ns | my $one_language_enabled = ($num_languages_enabled <= 1) ? 1 : 0; # deal with zero enabled langs as well | ||
209 | 1 | 300ns | $template->param( | ||
210 | languages_loop => $languages_loop, | ||||
211 | one_language_enabled => $one_language_enabled, | ||||
212 | ) unless $one_language_enabled; | ||||
213 | |||||
214 | 1 | 35µs | return $template; | ||
215 | } | ||||
216 | |||||
217 | |||||
218 | =head2 themelanguage | ||||
219 | |||||
220 | my ($theme,$lang,\@themes) = themelanguage($htdocs,$tmpl,$interface,query); | ||||
221 | |||||
222 | This function returns the theme and language to be used for rendering the UI. | ||||
223 | It also returns the list of themes that should be applied as a fallback. This is | ||||
224 | used for the theme overlay feature (i.e. if a file doesn't exist on the requested | ||||
225 | theme, fallback to the configured fallback). | ||||
226 | |||||
227 | Important: this function is used on the webinstaller too, so always consider | ||||
228 | the use case where the DB is not populated already when rewriting/fixing. | ||||
229 | |||||
230 | =cut | ||||
231 | |||||
232 | sub themelanguage { | ||||
233 | 2 | 1µs | my ($htdocs, $tmpl, $interface, $query) = @_; | ||
234 | 2 | 1µs | ($query) or warn "no query in themelanguage"; | ||
235 | |||||
236 | # Select a language based on cookie, syspref available languages & browser | ||||
237 | 2 | 46µs | 2 | 12.2ms | my $lang = C4::Languages::getlanguage($query); # spent 12.2ms making 2 calls to C4::Languages::getlanguage, avg 6.12ms/call |
238 | |||||
239 | # Get theme | ||||
240 | 2 | 300ns | my @themes; | ||
241 | 2 | 2µs | my $theme_syspref = ($interface eq 'intranet') ? 'template' : 'opacthemes'; | ||
242 | 2 | 900ns | my $fallback_syspref = ($interface eq 'intranet') ? 'template' : 'OPACFallback'; | ||
243 | # Yeah, hardcoded, last resort if the DB is not populated | ||||
244 | 2 | 1µs | my $hardcoded_theme = ($interface eq 'intranet') ? 'prog' : 'bootstrap'; | ||
245 | |||||
246 | # Configured theme is the first one | ||||
247 | 2 | 25µs | 4 | 9.16ms | push @themes, C4::Context->preference( $theme_syspref ) # spent 9.16ms making 4 calls to C4::Context::preference, avg 2.29ms/call |
248 | if C4::Context->preference( $theme_syspref ); | ||||
249 | # Configured fallback next | ||||
250 | 2 | 18µs | 4 | 17.3ms | push @themes, C4::Context->preference( $fallback_syspref ) # spent 17.3ms making 4 calls to C4::Context::preference, avg 4.33ms/call |
251 | if C4::Context->preference( $fallback_syspref ); | ||||
252 | # The hardcoded fallback theme is the last one | ||||
253 | 2 | 1µs | push @themes, $hardcoded_theme; | ||
254 | |||||
255 | # Try to find first theme for the selected theme/lang, then for fallback/lang | ||||
256 | 2 | 13µs | 2 | 3µs | my $where = $tmpl =~ /xsl$/ ? 'xslt' : 'modules'; # spent 3µs making 2 calls to C4::Templates::CORE:match, avg 2µs/call |
257 | 2 | 1µs | for my $theme (@themes) { | ||
258 | 2 | 999µs | 4 | 951µs | if ( -e "$htdocs/$theme/$lang/$where/$tmpl" ) { # spent 932µs making 2 calls to C4::Templates::CORE:ftis, avg 466µs/call
# spent 19µs making 2 calls to List::MoreUtils::uniq, avg 10µs/call |
259 | return ( $theme, $lang, uniq( \@themes ) ); | ||||
260 | } | ||||
261 | } | ||||
262 | # Otherwise return theme/'en', last resort fallback/'en' | ||||
263 | for my $theme (@themes) { | ||||
264 | if ( -e "$htdocs/$theme/en/$where/$tmpl" ) { | ||||
265 | return ( $theme, 'en', uniq( \@themes ) ); | ||||
266 | } | ||||
267 | } | ||||
268 | # tmpl is a full path, so this is a template for a plugin | ||||
269 | if ( $tmpl =~ /^\// && -e $tmpl ) { | ||||
270 | return ( $themes[0], $lang, uniq( \@themes ) ); | ||||
271 | } | ||||
272 | } | ||||
273 | |||||
274 | |||||
275 | sub setlanguagecookie { | ||||
276 | my ( $query, $language, $uri ) = @_; | ||||
277 | |||||
278 | my $cookie = $query->cookie( | ||||
279 | -name => 'KohaOpacLanguage', | ||||
280 | -value => $language, | ||||
281 | -HttpOnly => 1, | ||||
282 | -expires => '+3y' | ||||
283 | ); | ||||
284 | print $query->redirect( | ||||
285 | -uri => $uri, | ||||
286 | -cookie => $cookie | ||||
287 | ); | ||||
288 | } | ||||
289 | |||||
290 | =head2 getlanguagecookie | ||||
291 | |||||
292 | my $cookie = getlanguagecookie($query,$language); | ||||
293 | |||||
294 | Returns a cookie object containing the calculated language to be used. | ||||
295 | |||||
296 | =cut | ||||
297 | |||||
298 | sub getlanguagecookie { | ||||
299 | my ( $query, $language ) = @_; | ||||
300 | my $cookie = $query->cookie( | ||||
301 | -name => 'KohaOpacLanguage', | ||||
302 | -value => $language, | ||||
303 | -HttpOnly => 1, | ||||
304 | -expires => '+3y' | ||||
305 | ); | ||||
306 | |||||
307 | return $cookie; | ||||
308 | } | ||||
309 | |||||
310 | =head2 GetColumnDefs | ||||
311 | |||||
312 | my $columns = GetColumnDefs( $cgi ) | ||||
313 | |||||
314 | It is passed a CGI object and returns a hash of hashes containing | ||||
315 | the column names and descriptions for each table defined in the | ||||
316 | columns.def file corresponding to the CGI object. | ||||
317 | |||||
318 | =cut | ||||
319 | |||||
320 | sub GetColumnDefs { | ||||
321 | |||||
322 | my $query = shift; | ||||
323 | |||||
324 | my $columns = {}; | ||||
325 | |||||
326 | my $htdocs = C4::Context->config('intrahtdocs'); | ||||
327 | my $columns_file = 'columns.def'; | ||||
328 | |||||
329 | # Get theme and language to build the path to columns.def | ||||
330 | my ($theme, $lang, $availablethemes) = | ||||
331 | themelanguage($htdocs, 'about.tt', 'intranet', $query); | ||||
332 | # Build columns.def path | ||||
333 | my $path = "$htdocs/$theme/$lang/$columns_file"; | ||||
334 | my $fh; | ||||
335 | if ( ! open ( $fh, q{<:encoding(utf-8)}, $path ) ) { | ||||
336 | carp "Error opening $path. Check your templates."; | ||||
337 | return; | ||||
338 | } | ||||
339 | # Loop through the columns.def file | ||||
340 | while ( my $input = <$fh> ){ | ||||
341 | chomp $input; | ||||
342 | if ( $input =~ m|<field name="(.*)">(.*)</field>| ) { | ||||
343 | my ( $table, $column ) = split( '\.', $1); | ||||
344 | my $description = $2; | ||||
345 | # Initialize the table array if needed. | ||||
346 | @{$columns->{ $table }} = () if ! defined $columns->{ $table }; | ||||
347 | # Push field and description | ||||
348 | push @{$columns->{ $table }}, | ||||
349 | { field => $column, description => $description }; | ||||
350 | } | ||||
351 | } | ||||
352 | close $fh; | ||||
353 | |||||
354 | return $columns; | ||||
355 | } | ||||
356 | |||||
357 | 1 | 5µs | 1; | ||
# spent 10µs within C4::Templates::CORE:binmode which was called:
# once (10µs+0s) by C4::Templates::output at line 120 | |||||
# spent 932µs within C4::Templates::CORE:ftis which was called 2 times, avg 466µs/call:
# 2 times (932µs+0s) by C4::Templates::themelanguage at line 258, avg 466µs/call | |||||
# spent 3µs within C4::Templates::CORE:match which was called 2 times, avg 2µs/call:
# 2 times (3µs+0s) by C4::Templates::themelanguage at line 256, avg 2µs/call |