Filename | /usr/share/koha/lib/C4/Templates.pm |
Statements | Executed 10553 statements in 22.0ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
210 | 1 | 1 | 12.2ms | 15.4ms | utf8_hashref (recurses: max depth 1, inclusive time 3.75ms) | C4::Templates::
1 | 1 | 1 | 8.14ms | 10.9ms | BEGIN@6 | C4::Templates::
1 | 1 | 1 | 2.57ms | 3.01ms | BEGIN@35 | C4::Templates::
222 | 2 | 1 | 2.08ms | 16.2ms | utf8_arrayref (recurses: max depth 1, inclusive time 5.03ms) | C4::Templates::
1 | 1 | 1 | 1.36ms | 720ms | output | C4::Templates::
45 | 45 | 3 | 1.32ms | 1.32ms | param | C4::Templates::
1 | 1 | 1 | 1.18ms | 24.6ms | BEGIN@33 | C4::Templates::
25 | 1 | 1 | 162µs | 162µs | _current_language | C4::Templates::
1 | 1 | 1 | 142µs | 20.2ms | new | C4::Templates::
1 | 1 | 1 | 114µs | 129ms | gettemplate | C4::Templates::
3 | 2 | 2 | 63µs | 4.36ms | getlanguage | C4::Templates::
2 | 2 | 1 | 54µs | 2.34ms | themelanguage | C4::Templates::
1 | 1 | 1 | 33µs | 2.31ms | _get_template_file | C4::Templates::
2 | 1 | 1 | 20µs | 20µs | CORE:ftis (opcode) | C4::Templates::
1 | 1 | 1 | 20µs | 27µs | BEGIN@3 | C4::Templates::
1 | 1 | 1 | 14µs | 2.47ms | BEGIN@32 | C4::Templates::
1 | 1 | 1 | 14µs | 17µs | BEGIN@37 | C4::Templates::
1 | 1 | 1 | 13µs | 76µs | BEGIN@7 | C4::Templates::
1 | 1 | 1 | 13µs | 369µs | BEGIN@34 | C4::Templates::
1 | 1 | 1 | 12µs | 34µs | BEGIN@4 | C4::Templates::
1 | 1 | 1 | 10µs | 63µs | BEGIN@5 | C4::Templates::
1 | 1 | 1 | 5µs | 5µs | CORE:subst (opcode) | C4::Templates::
1 | 1 | 1 | 3µs | 3µs | CORE:ftfile (opcode) | C4::Templates::
0 | 0 | 0 | 0s | 0s | __ANON__[:343] | 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 | 3 | 30µs | 2 | 34µs | # spent 27µs (20+7) within C4::Templates::BEGIN@3 which was called:
# once (20µs+7µs) by C4::Output::BEGIN@36 at line 3 # spent 27µs making 1 call to C4::Templates::BEGIN@3
# spent 7µs making 1 call to strict::import |
4 | 3 | 27µs | 2 | 55µs | # spent 34µs (12+22) within C4::Templates::BEGIN@4 which was called:
# once (12µs+22µs) by C4::Output::BEGIN@36 at line 4 # spent 34µs making 1 call to C4::Templates::BEGIN@4
# spent 22µs making 1 call to warnings::import |
5 | 3 | 30µs | 2 | 116µs | # spent 63µs (10+53) within C4::Templates::BEGIN@5 which was called:
# once (10µs+53µs) by C4::Output::BEGIN@36 at line 5 # spent 63µs making 1 call to C4::Templates::BEGIN@5
# spent 53µs making 1 call to Exporter::import |
6 | 3 | 198µs | 2 | 10.9ms | # spent 10.9ms (8.14+2.77) within C4::Templates::BEGIN@6 which was called:
# once (8.14ms+2.77ms) by C4::Output::BEGIN@36 at line 6 # spent 10.9ms making 1 call to C4::Templates::BEGIN@6
# spent 30µs making 1 call to CGI::import |
7 | 3 | 49µs | 2 | 138µs | # spent 76µs (13+63) within C4::Templates::BEGIN@7 which was called:
# once (13µs+63µs) by C4::Output::BEGIN@36 at line 7 # spent 76µs making 1 call to C4::Templates::BEGIN@7
# spent 63µ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 under the | ||||
14 | # terms of the GNU General Public License as published by the Free Software | ||||
15 | # Foundation; either version 2 of the License, or (at your option) any later | ||||
16 | # version. | ||||
17 | # | ||||
18 | # Koha is distributed in the hope that it will be useful, but WITHOUT ANY | ||||
19 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||||
20 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||||
21 | # | ||||
22 | # You should have received a copy of the GNU General Public License along with | ||||
23 | # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, | ||||
24 | # Suite 330, Boston, MA 02111-1307 USA | ||||
25 | |||||
26 | =head1 NAME | ||||
27 | |||||
- - | |||||
32 | 3 | 93µs | 2 | 4.92ms | # spent 2.47ms (14µs+2.45) within C4::Templates::BEGIN@32 which was called:
# once (14µs+2.45ms) by C4::Output::BEGIN@36 at line 32 # spent 2.47ms making 1 call to C4::Templates::BEGIN@32
# spent 2.45ms making 1 call to base::import |
33 | 3 | 149µs | 1 | 24.6ms | # spent 24.6ms (1.18+23.4) within C4::Templates::BEGIN@33 which was called:
# once (1.18ms+23.4ms) by C4::Output::BEGIN@36 at line 33 # spent 24.6ms making 1 call to C4::Templates::BEGIN@33 |
34 | 3 | 42µs | 2 | 725µs | # spent 369µs (13+356) within C4::Templates::BEGIN@34 which was called:
# once (13µs+356µs) by C4::Output::BEGIN@36 at line 34 # spent 369µs making 1 call to C4::Templates::BEGIN@34
# spent 356µs making 1 call to Exporter::import |
35 | 3 | 176µs | 2 | 3.12ms | # spent 3.01ms (2.57+432µs) within C4::Templates::BEGIN@35 which was called:
# once (2.57ms+432µs) by C4::Output::BEGIN@36 at line 35 # spent 3.01ms making 1 call to C4::Templates::BEGIN@35
# spent 109µs making 1 call to Exporter::import |
36 | |||||
37 | 3 | 1.49ms | 2 | 20µs | # spent 17µs (14+3) within C4::Templates::BEGIN@37 which was called:
# once (14µs+3µs) by C4::Output::BEGIN@36 at line 37 # spent 17µs making 1 call to C4::Templates::BEGIN@37
# spent 3µs making 1 call to C4::Context::import |
38 | |||||
39 | 1 | 13µs | 1 | 369µs | __PACKAGE__->mk_accessors(qw( theme activethemes preferredtheme lang filename htdocs interface vars)); # spent 369µs making 1 call to Class::Accessor::mk_accessors |
40 | |||||
- - | |||||
43 | # spent 20.2ms (142µs+20.1) within C4::Templates::new which was called:
# once (142µs+20.1ms) by C4::Templates::gettemplate at line 238 | ||||
44 | 1 | 2µs | my $class = shift; | ||
45 | 1 | 2µs | my $interface = shift; | ||
46 | 1 | 1µs | my $filename = shift; | ||
47 | 1 | 1µs | my $tmplbase = shift; | ||
48 | 1 | 1µs | my $query = @_? shift: undef; | ||
49 | 1 | 400ns | my $htdocs; | ||
50 | 1 | 5µs | 1 | 14µs | if ( $interface ne "intranet" ) { # spent 14µs making 1 call to C4::Context::config |
51 | $htdocs = C4::Context->config('opachtdocs'); | ||||
52 | } | ||||
53 | else { | ||||
54 | $htdocs = C4::Context->config('intrahtdocs'); | ||||
55 | } | ||||
56 | 1 | 4µs | 1 | 85µs | my ($theme, $lang, $activethemes)= themelanguage( $htdocs, $tmplbase, $interface, $query); # spent 85µs making 1 call to C4::Templates::themelanguage |
57 | 1 | 400ns | my @includes; | ||
58 | 1 | 3µs | foreach (@$activethemes) { | ||
59 | 2 | 6µs | push @includes, "$htdocs/$_/$lang/includes"; | ||
60 | 2 | 6µs | push @includes, "$htdocs/$_/en/includes" unless $lang eq 'en'; | ||
61 | } | ||||
62 | 1 | 34µs | 3 | 19.9ms | my $template = Template->new( # spent 19.9ms making 1 call to Template::Base::new
# spent 14µs making 2 calls to C4::Context::config, avg 7µs/call |
63 | { EVAL_PERL => 1, | ||||
64 | ABSOLUTE => 1, | ||||
65 | PLUGIN_BASE => 'Koha::Template::Plugin', | ||||
66 | COMPILE_EXT => C4::Context->config('template_cache_dir')?'.ttc':'', | ||||
67 | COMPILE_DIR => C4::Context->config('template_cache_dir')?C4::Context->config('template_cache_dir'):'',, | ||||
68 | INCLUDE_PATH => \@includes, | ||||
69 | FILTERS => {}, | ||||
70 | } | ||||
71 | ) or die Template->error(); | ||||
72 | 1 | 3µs | my $self = { | ||
73 | TEMPLATE => $template, | ||||
74 | VARS => {}, | ||||
75 | }; | ||||
76 | 1 | 17µs | bless $self, $class; | ||
77 | 1 | 5µs | 1 | 28µs | $self->theme($theme); # spent 28µs making 1 call to C4::Templates::theme |
78 | 1 | 3µs | 1 | 9µs | $self->lang($lang); # spent 9µs making 1 call to C4::Templates::lang |
79 | 1 | 3µs | 1 | 9µs | $self->activethemes($activethemes); # spent 9µs making 1 call to C4::Templates::activethemes |
80 | 1 | 3µs | 1 | 8µs | $self->preferredtheme($activethemes->[0]); # spent 8µs making 1 call to C4::Templates::preferredtheme |
81 | 1 | 3µs | 1 | 8µs | $self->filename($filename); # spent 8µs making 1 call to C4::Templates::filename |
82 | 1 | 3µs | 1 | 7µs | $self->htdocs($htdocs); # spent 7µs making 1 call to C4::Templates::htdocs |
83 | 1 | 3µs | 1 | 8µs | $self->interface($interface); # spent 8µs making 1 call to C4::Templates::interface |
84 | 1 | 2µs | $self->{VARS}->{"test"} = "value"; | ||
85 | 1 | 6µs | return $self; | ||
86 | |||||
87 | } | ||||
88 | |||||
89 | # spent 720ms (1.36+719) within C4::Templates::output which was called:
# once (1.36ms+719ms) by main::RUNTIME at line 898 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl | ||||
90 | 1 | 1µs | my $self = shift; | ||
91 | 1 | 1µs | my $vars = shift; | ||
92 | |||||
93 | # my $file = $self->htdocs . '/' . $self->theme .'/'.$self->lang.'/'.$self->filename; | ||||
94 | 1 | 2µs | my $template = $self->{TEMPLATE}; | ||
95 | 1 | 9µs | 1 | 41µs | if ( $self->interface eq 'intranet' ) { # spent 41µs making 1 call to C4::Templates::interface |
96 | $vars->{themelang} = '/intranet-tmpl'; | ||||
97 | } | ||||
98 | else { | ||||
99 | 1 | 5µs | $vars->{themelang} = '/opac-tmpl'; | ||
100 | } | ||||
101 | 1 | 8µs | 1 | 18µs | $vars->{lang} = $self->lang; # spent 18µs making 1 call to C4::Templates::lang |
102 | 1 | 16µs | 2 | 33µs | $vars->{themelang} .= '/' . $self->preferredtheme . '/' . $self->lang; # spent 17µs making 1 call to C4::Templates::lang
# spent 15µs making 1 call to C4::Templates::preferredtheme |
103 | 1 | 20µs | 2 | 1.88ms | $vars->{yuipath} = # spent 1.85ms making 1 call to C4::Context::preference
# spent 21µs making 1 call to C4::Templates::interface |
104 | ( C4::Context->preference("yuipath") eq "local" | ||||
105 | ? ( $self->interface eq 'intranet' ? $vars->{themelang} . "/lib/yui" : "/opac-tmpl/lib/yui" ) | ||||
106 | : C4::Context->preference("yuipath") ); | ||||
107 | 1 | 3µs | $vars->{interface} = | ||
108 | ( $self->{interface} ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' ); | ||||
109 | 1 | 5µs | 1 | 10µs | $vars->{theme} = $self->theme; # spent 10µs making 1 call to C4::Templates::theme |
110 | 1 | 5µs | 1 | 7µs | $vars->{opaccolorstylesheet} = # spent 7µs making 1 call to C4::Context::preference |
111 | C4::Context->preference('opaccolorstylesheet'); | ||||
112 | 1 | 3µs | 1 | 3µs | $vars->{opacsmallimage} = C4::Context->preference('opacsmallimage'); # spent 3µs making 1 call to C4::Context::preference |
113 | 1 | 3µs | 1 | 3µs | $vars->{opaclayoutstylesheet} = # spent 3µs making 1 call to C4::Context::preference |
114 | C4::Context->preference('opaclayoutstylesheet'); | ||||
115 | |||||
116 | # add variables set via param to $vars for processing | ||||
117 | # and clean any utf8 mess | ||||
118 | 1 | 117µs | for my $k ( keys %{ $self->{VARS} } ) { | ||
119 | 158 | 465µs | $vars->{$k} = $self->{VARS}->{$k}; | ||
120 | 158 | 255µs | 9 | 16.2ms | if (ref($vars->{$k}) eq 'ARRAY'){ # spent 16.2ms making 9 calls to C4::Templates::utf8_arrayref, avg 1.80ms/call |
121 | utf8_arrayref($vars->{$k}); | ||||
122 | } | ||||
123 | elsif (ref($vars->{$k}) eq 'HASH'){ | ||||
124 | utf8_hashref($vars->{$k}); | ||||
125 | } | ||||
126 | else { | ||||
127 | 149 | 401µs | 149 | 100µs | utf8::encode($vars->{$k}) if utf8::is_utf8($vars->{$k}); # spent 100µs making 149 calls to utf8::is_utf8, avg 672ns/call |
128 | } | ||||
129 | } | ||||
130 | 1 | 500ns | my $data; | ||
131 | # binmode( STDOUT, ":utf8" ); | ||||
132 | 1 | 14µs | 2 | 701ms | $template->process( $self->filename, $vars, \$data ) # spent 701ms making 1 call to Template::process
# spent 23µs making 1 call to C4::Templates::filename |
133 | || die "Template process failed: ", $template->error(); | ||||
134 | 1 | 94µs | return $data; | ||
135 | } | ||||
136 | |||||
137 | sub utf8_arrayref { | ||||
138 | 222 | 171µs | my $arrayref = shift; | ||
139 | 222 | 966µs | foreach my $element (@$arrayref){ | ||
140 | 210 | 184µs | if (ref($element) eq 'ARRAY'){ | ||
141 | utf8_arrayref($element); | ||||
142 | next; | ||||
143 | } | ||||
144 | 210 | 87µs | if (ref($element) eq 'HASH'){ | ||
145 | 210 | 572µs | 210 | 15.4ms | utf8_hashref($element); # spent 19.2ms making 210 calls to C4::Templates::utf8_hashref, avg 91µs/call, recursion: max depth 1, sum of overlapping time 3.75ms |
146 | 210 | 147µs | next; | ||
147 | } | ||||
148 | utf8::encode($element) if utf8::is_utf8($element); | ||||
149 | } | ||||
150 | } | ||||
151 | |||||
152 | # spent 15.4ms (12.2+3.23) within C4::Templates::utf8_hashref which was called 210 times, avg 73µs/call:
# 210 times (12.2ms+3.23ms) by C4::Templates::utf8_arrayref at line 145, avg 73µs/call | ||||
153 | 210 | 99µs | my $hashref = shift; | ||
154 | 210 | 1.76ms | for my $key (keys %{$hashref}){ | ||
155 | 2497 | 2.00ms | if (ref($hashref->{$key}) eq 'ARRAY'){ | ||
156 | 213 | 477µs | 213 | 0s | utf8_arrayref($hashref->{$key}); # spent 5.03ms making 213 calls to C4::Templates::utf8_arrayref, avg 24µs/call, recursion: max depth 1, sum of overlapping time 5.03ms |
157 | 213 | 101µs | next; | ||
158 | } | ||||
159 | 2284 | 1.12ms | if (ref($hashref->{$key}) eq 'HASH'){ | ||
160 | utf8_hashref($hashref->{$key}); | ||||
161 | next; | ||||
162 | } | ||||
163 | 2284 | 8.55ms | 2335 | 1.95ms | utf8::encode($hashref->{$key}) if utf8::is_utf8($hashref->{$key}); # spent 1.88ms making 2284 calls to utf8::is_utf8, avg 825ns/call
# spent 64µs making 51 calls to utf8::encode, avg 1µs/call |
164 | } | ||||
165 | } | ||||
166 | |||||
167 | |||||
168 | # FIXME - this is a horrible hack to cache | ||||
169 | # the current known-good language, temporarily | ||||
170 | # put in place to resolve bug 4403. It is | ||||
171 | # used only by C4::XSLT::XSLTParse4Display; | ||||
172 | # the language is set via the usual call | ||||
173 | # to themelanguage. | ||||
174 | 1 | 400ns | my $_current_language = 'en'; | ||
175 | |||||
176 | # spent 162µs within C4::Templates::_current_language which was called 25 times, avg 6µs/call:
# 25 times (162µs+0s) by C4::XSLT::XSLTParse4Display at line 165 of /usr/share/koha/lib/C4/XSLT.pm, avg 6µs/call | ||||
177 | 25 | 124µs | return $_current_language; | ||
178 | } | ||||
179 | |||||
180 | |||||
181 | # wrapper method to allow easier transition from HTML template pro to Template Toolkit | ||||
182 | # spent 1.32ms within C4::Templates::param which was called 45 times, avg 29µs/call:
# once (290µs+0s) by C4::Auth::get_template_and_user at line 381 of /usr/share/koha/lib/C4/Auth.pm
# once (188µs+0s) by main::RUNTIME at line 248 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (126µs+0s) by C4::Auth::get_template_and_user at line 303 of /usr/share/koha/lib/C4/Auth.pm
# once (49µs+0s) by main::RUNTIME at line 148 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (48µs+0s) by main::RUNTIME at line 857 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (37µs+0s) by main::RUNTIME at line 751 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (35µs+0s) by main::RUNTIME at line 696 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (31µs+0s) by main::RUNTIME at line 701 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (30µs+0s) by C4::Templates::gettemplate at line 269
# once (28µs+0s) by main::RUNTIME at line 467 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (27µs+0s) by main::RUNTIME at line 875 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (26µs+0s) by main::RUNTIME at line 196 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (24µs+0s) by main::RUNTIME at line 757 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (21µs+0s) by main::RUNTIME at line 643 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (21µs+0s) by main::RUNTIME at line 812 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (20µs+0s) by main::RUNTIME at line 897 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (19µs+0s) by C4::Auth::get_template_and_user at line 280 of /usr/share/koha/lib/C4/Auth.pm
# once (18µs+0s) by C4::Auth::get_template_and_user at line 297 of /usr/share/koha/lib/C4/Auth.pm
# once (17µs+0s) by C4::Auth::get_template_and_user at line 283 of /usr/share/koha/lib/C4/Auth.pm
# once (16µs+0s) by main::RUNTIME at line 494 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (16µs+0s) by main::RUNTIME at line 150 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (15µs+0s) by main::RUNTIME at line 202 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (14µs+0s) by main::RUNTIME at line 147 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (14µs+0s) by main::RUNTIME at line 368 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (14µs+0s) by main::RUNTIME at line 493 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (13µs+0s) by main::RUNTIME at line 853 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (12µs+0s) by main::RUNTIME at line 165 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (10µs+0s) by main::RUNTIME at line 163 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (10µs+0s) by main::RUNTIME at line 702 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (10µs+0s) by main::RUNTIME at line 699 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (10µs+0s) by main::RUNTIME at line 706 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (10µs+0s) by main::RUNTIME at line 703 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (9µs+0s) by main::RUNTIME at line 711 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (9µs+0s) by main::RUNTIME at line 814 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (9µs+0s) by main::RUNTIME at line 123 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (9µs+0s) by main::RUNTIME at line 867 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (8µs+0s) by main::RUNTIME at line 700 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (8µs+0s) by main::RUNTIME at line 705 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (8µs+0s) by main::RUNTIME at line 704 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (8µs+0s) by main::RUNTIME at line 707 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (8µs+0s) by main::RUNTIME at line 756 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (7µs+0s) by C4::Auth::get_template_and_user at line 461 of /usr/share/koha/lib/C4/Auth.pm
# once (6µs+0s) by main::RUNTIME at line 141 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (6µs+0s) by main::RUNTIME at line 420 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (5µs+0s) by main::RUNTIME at line 402 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl | ||||
183 | 45 | 211µs | my $self = shift; | ||
184 | 45 | 410µs | while (@_) { | ||
185 | 155 | 116µs | my $key = shift; | ||
186 | 155 | 90µs | my $val = shift; | ||
187 | 155 | 135µs | if ( ref($val) eq 'ARRAY' && !scalar @$val ) { $val = undef; } | ||
188 | elsif ( ref($val) eq 'HASH' && !scalar %$val ) { $val = undef; } | ||||
189 | 155 | 513µs | if ( $key ) { | ||
190 | $self->{VARS}->{$key} = $val; | ||||
191 | } else { | ||||
192 | warn "Problem = a value of $val has been passed to param without key"; | ||||
193 | } | ||||
194 | } | ||||
195 | } | ||||
196 | |||||
197 | |||||
198 | =head1 NAME | ||||
199 | |||||
- - | |||||
206 | # FIXME: this is a quick fix to stop rc1 installing broken | ||||
207 | # Still trying to figure out the correct fix. | ||||
208 | 1 | 6µs | 1 | 19µs | my $path = C4::Context->config('intrahtdocs') . "/prog/en/includes/"; # spent 19µs making 1 call to C4::Context::config |
209 | |||||
210 | #--------------------------------------------------------------------------------------------------------- | ||||
211 | # FIXME - POD | ||||
212 | |||||
213 | # spent 2.31ms (33µs+2.28) within C4::Templates::_get_template_file which was called:
# once (33µs+2.28ms) by C4::Templates::gettemplate at line 235 | ||||
214 | 1 | 2µs | my ($tmplbase, $interface, $query) = @_; | ||
215 | |||||
216 | 1 | 1µs | my $is_intranet = $interface eq 'intranet'; | ||
217 | 1 | 4µs | 1 | 20µs | my $htdocs = C4::Context->config($is_intranet ? 'intrahtdocs' : 'opachtdocs'); # spent 20µs making 1 call to C4::Context::config |
218 | 1 | 5µs | 1 | 2.25ms | my ($theme, $lang, $availablethemes) = themelanguage($htdocs, $tmplbase, $interface, $query); # spent 2.25ms making 1 call to C4::Templates::themelanguage |
219 | |||||
220 | # if the template doesn't exist, load the English one as a last resort | ||||
221 | 1 | 4µs | my $filename = "$htdocs/$theme/$lang/modules/$tmplbase"; | ||
222 | 1 | 10µs | 1 | 3µs | unless (-f $filename) { # spent 3µs making 1 call to C4::Templates::CORE:ftfile |
223 | $lang = 'en'; | ||||
224 | $filename = "$htdocs/$theme/$lang/modules/$tmplbase"; | ||||
225 | } | ||||
226 | 1 | 6µs | return ($htdocs, $theme, $lang, $filename); | ||
227 | } | ||||
228 | |||||
229 | |||||
230 | # spent 129ms (114µs+129) within C4::Templates::gettemplate which was called:
# once (114µs+129ms) by C4::Auth::get_template_and_user at line 137 of /usr/share/koha/lib/C4/Auth.pm | ||||
231 | 1 | 4µs | my ( $tmplbase, $interface, $query, $is_plugin ) = @_; | ||
232 | 1 | 600ns | ($query) or warn "no query in gettemplate"; | ||
233 | 1 | 4µs | 1 | 2.17ms | my $path = C4::Context->preference('intranet_includes') || 'includes'; # spent 2.17ms making 1 call to C4::Context::preference |
234 | 1 | 13µs | 1 | 5µs | $tmplbase =~ s/\.tmpl$/.tt/; # spent 5µs making 1 call to C4::Templates::CORE:subst |
235 | 1 | 5µs | 1 | 2.31ms | my ($htdocs, $theme, $lang, $filename) # spent 2.31ms making 1 call to C4::Templates::_get_template_file |
236 | = _get_template_file($tmplbase, $interface, $query); | ||||
237 | 1 | 400ns | $filename = $tmplbase if ( $is_plugin ); | ||
238 | 1 | 12µs | 1 | 20.2ms | my $template = C4::Templates->new($interface, $filename, $tmplbase, $query); # spent 20.2ms making 1 call to C4::Templates::new |
239 | |||||
240 | # NOTE: Commenting these out rather than deleting them so that those who need | ||||
241 | # to know how we previously shimmed these directories will be able to understand. | ||||
242 | # my $is_intranet = $interface eq 'intranet'; | ||||
243 | # my $themelang = | ||||
244 | # ($is_intranet ? '/intranet-tmpl' : '/opac-tmpl') . | ||||
245 | # "/$theme/$lang"; | ||||
246 | # $template->param( | ||||
247 | # themelang => $themelang, | ||||
248 | # yuipath => C4::Context->preference("yuipath") eq "local" | ||||
249 | # ? "$themelang/lib/yui" | ||||
250 | # : C4::Context->preference("yuipath"), | ||||
251 | # interface => $is_intranet ? '/intranet-tmpl' : '/opac-tmpl', | ||||
252 | # theme => $theme, | ||||
253 | # lang => $lang | ||||
254 | # ); | ||||
255 | |||||
256 | # Bidirectionality | ||||
257 | 1 | 6µs | 17 | 421µs | my $current_lang = regex_lang_subtags($lang); # spent 411µs making 1 call to C4::Languages::regex_lang_subtags
# spent 10µs making 16 calls to Regexp::DESTROY, avg 644ns/call |
258 | 1 | 500ns | my $bidi; | ||
259 | 1 | 1µs | $bidi = get_bidi($current_lang->{script}) if $current_lang->{script}; | ||
260 | # Languages | ||||
261 | 1 | 8µs | 1 | 104ms | my $languages_loop = getTranslatedLanguages($interface,$theme,$lang); # spent 104ms making 1 call to C4::Languages::getTranslatedLanguages |
262 | 1 | 1µs | my $num_languages_enabled = 0; | ||
263 | 1 | 3µs | foreach my $lang (@$languages_loop) { | ||
264 | 5 | 13µs | foreach my $sublang (@{ $lang->{'sublanguages_loop'} }) { | ||
265 | 7 | 13µs | $num_languages_enabled++ if $sublang->{enabled}; | ||
266 | } | ||||
267 | } | ||||
268 | $template->param( | ||||
269 | 1 | 12µs | 1 | 30µs | languages_loop => $languages_loop, # spent 30µs making 1 call to C4::Templates::param |
270 | bidi => $bidi, | ||||
271 | one_language_enabled => ($num_languages_enabled <= 1) ? 1 : 0, # deal with zero enabled langs as well | ||||
272 | ) unless @$languages_loop<2; | ||||
273 | |||||
274 | 1 | 14µs | return $template; | ||
275 | } | ||||
276 | |||||
277 | |||||
278 | #--------------------------------------------------------------------------------------------------------- | ||||
279 | # FIXME - POD | ||||
280 | sub themelanguage { | ||||
281 | 2 | 3µs | my ($htdocs, $tmpl, $interface, $query) = @_; | ||
282 | 2 | 900ns | ($query) or warn "no query in themelanguage"; | ||
283 | |||||
284 | # Select a language based on cookie, syspref available languages & browser | ||||
285 | 2 | 4µs | 2 | 130µs | my $lang = getlanguage($query, $interface); # spent 130µs making 2 calls to C4::Templates::getlanguage, avg 65µs/call |
286 | |||||
287 | # Select theme | ||||
288 | 2 | 2µs | my $is_intranet = $interface eq 'intranet'; | ||
289 | 2 | 9µs | 2 | 2.13ms | my @themes = split(" ", C4::Context->preference( # spent 2.13ms making 2 calls to C4::Context::preference, avg 1.07ms/call |
290 | $is_intranet ? "template" : "opacthemes" )); | ||||
291 | 2 | 2µs | push @themes, 'prog'; | ||
292 | |||||
293 | # Try to find first theme for the selected language | ||||
294 | 2 | 2µs | for my $theme (@themes) { | ||
295 | 2 | 35µs | 2 | 20µs | if ( -e "$htdocs/$theme/$lang/modules/$tmpl" ) { # spent 20µs making 2 calls to C4::Templates::CORE:ftis, avg 10µs/call |
296 | 2 | 1µs | $_current_language = $lang; | ||
297 | 2 | 13µs | return ($theme, $lang, \@themes) | ||
298 | } | ||||
299 | } | ||||
300 | # Otherwise, return prog theme in English 'en' | ||||
301 | return ('prog', 'en', \@themes); | ||||
302 | } | ||||
303 | |||||
304 | |||||
305 | sub setlanguagecookie { | ||||
306 | my ( $query, $language, $uri ) = @_; | ||||
307 | my $cookie = $query->cookie( | ||||
308 | -name => 'KohaOpacLanguage', | ||||
309 | -value => $language, | ||||
310 | -HttpOnly => 1, | ||||
311 | -expires => '+3y' | ||||
312 | ); | ||||
313 | print $query->redirect( | ||||
314 | -uri => $uri, | ||||
315 | -cookie => $cookie | ||||
316 | ); | ||||
317 | } | ||||
318 | |||||
319 | |||||
320 | # spent 4.36ms (63µs+4.30) within C4::Templates::getlanguage which was called 3 times, avg 1.45ms/call:
# 2 times (28µs+102µs) by C4::Templates::themelanguage at line 285, avg 65µs/call
# once (35µs+4.20ms) by main::RUNTIME at line 93 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl | ||||
321 | 3 | 4µs | my ($query, $interface) = @_; | ||
322 | |||||
323 | # Select a language based on cookie, syspref available languages & browser | ||||
324 | 3 | 4µs | my $preference_to_check = | ||
325 | $interface eq 'intranet' ? 'language' : 'opaclanguages'; | ||||
326 | 3 | 15µs | 3 | 2.13ms | my @languages = split /,/, C4::Context->preference($preference_to_check); # spent 2.13ms making 3 calls to C4::Context::preference, avg 708µs/call |
327 | |||||
328 | 3 | 900ns | my $lang; | ||
329 | |||||
330 | # cookie | ||||
331 | 3 | 13µs | 3 | 310µs | if ( $query->cookie('KohaOpacLanguage') ) { # spent 215µs making 1 call to CGI::AUTOLOAD
# spent 95µs making 2 calls to CGI::cookie, avg 47µs/call |
332 | $lang = $query->cookie('KohaOpacLanguage'); | ||||
333 | $lang =~ s/[^a-zA-Z_-]*//; # sanitize cookie | ||||
334 | } | ||||
335 | |||||
336 | # HTTP_ACCEPT_LANGUAGE | ||||
337 | 3 | 2µs | if ( !$lang && $ENV{HTTP_ACCEPT_LANGUAGE} ) { | ||
338 | $lang = accept_language( $ENV{HTTP_ACCEPT_LANGUAGE}, | ||||
339 | getTranslatedLanguages( $interface, 'prog' ) ); | ||||
340 | } | ||||
341 | |||||
342 | # Ignore a lang not selected in sysprefs | ||||
343 | 3 | 1µs | if ( $lang && any { $_ eq $lang } @languages ) { | ||
344 | return $lang; | ||||
345 | } | ||||
346 | |||||
347 | # Pick the first selected syspref language | ||||
348 | 3 | 2µs | $lang = shift @languages; | ||
349 | 3 | 12µs | return $lang if $lang; | ||
350 | |||||
351 | # Fall back to English if necessary | ||||
352 | return 'en'; | ||||
353 | } | ||||
354 | |||||
355 | 1 | 8µs | 1; | ||
# spent 3µs within C4::Templates::CORE:ftfile which was called:
# once (3µs+0s) by C4::Templates::_get_template_file at line 222 | |||||
# spent 20µs within C4::Templates::CORE:ftis which was called 2 times, avg 10µs/call:
# 2 times (20µs+0s) by C4::Templates::themelanguage at line 295, avg 10µs/call | |||||
# spent 5µs within C4::Templates::CORE:subst which was called:
# once (5µs+0s) by C4::Templates::gettemplate at line 234 |