Filename | /usr/share/koha/lib/C4/Templates.pm |
Statements | Executed 10553 statements in 23.4ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
210 | 1 | 1 | 12.9ms | 16.6ms | utf8_hashref (recurses: max depth 1, inclusive time 3.92ms) | C4::Templates::
1 | 1 | 1 | 9.66ms | 12.7ms | BEGIN@6 | C4::Templates::
1 | 1 | 1 | 4.27ms | 10.3ms | BEGIN@35 | C4::Templates::
222 | 2 | 1 | 2.35ms | 17.5ms | utf8_arrayref (recurses: max depth 1, inclusive time 5.39ms) | C4::Templates::
1 | 1 | 1 | 1.62ms | 852ms | output | C4::Templates::
1 | 1 | 1 | 1.16ms | 29.9ms | BEGIN@33 | C4::Templates::
45 | 45 | 3 | 942µs | 942µs | param | C4::Templates::
1 | 1 | 1 | 170µs | 23.9ms | new | C4::Templates::
25 | 1 | 1 | 163µs | 163µs | _current_language | C4::Templates::
3 | 2 | 2 | 134µs | 5.70ms | getlanguage | C4::Templates::
1 | 1 | 1 | 100µs | 30.7ms | gettemplate | C4::Templates::
2 | 2 | 1 | 79µs | 2.49ms | themelanguage | C4::Templates::
1 | 1 | 1 | 35µs | 2.40ms | _get_template_file | C4::Templates::
2 | 1 | 1 | 31µs | 31µs | CORE:ftis (opcode) | C4::Templates::
1 | 1 | 1 | 21µs | 28µs | BEGIN@3 | C4::Templates::
1 | 1 | 1 | 18µs | 18µs | CORE:subst (opcode) | C4::Templates::
1 | 1 | 1 | 13µs | 34µs | BEGIN@4 | C4::Templates::
1 | 1 | 1 | 13µs | 73µs | BEGIN@7 | C4::Templates::
1 | 1 | 1 | 12µs | 14µs | BEGIN@37 | C4::Templates::
1 | 1 | 1 | 12µs | 2.84ms | BEGIN@32 | C4::Templates::
1 | 1 | 1 | 11µs | 395µs | BEGIN@34 | C4::Templates::
1 | 1 | 1 | 10µs | 58µs | BEGIN@5 | C4::Templates::
1 | 1 | 1 | 4µs | 4µ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 | 32µs | 2 | 35µs | # spent 28µs (21+7) within C4::Templates::BEGIN@3 which was called:
# once (21µs+7µs) by C4::Output::BEGIN@36 at line 3 # spent 28µs making 1 call to C4::Templates::BEGIN@3
# spent 7µs making 1 call to strict::import |
4 | 3 | 29µs | 2 | 54µs | # spent 34µs (13+21) within C4::Templates::BEGIN@4 which was called:
# once (13µs+21µs) by C4::Output::BEGIN@36 at line 4 # spent 34µs making 1 call to C4::Templates::BEGIN@4
# spent 21µs making 1 call to warnings::import |
5 | 3 | 29µs | 2 | 105µs | # spent 58µs (10+48) within C4::Templates::BEGIN@5 which was called:
# once (10µs+48µs) by C4::Output::BEGIN@36 at line 5 # spent 58µs making 1 call to C4::Templates::BEGIN@5
# spent 48µs making 1 call to Exporter::import |
6 | 3 | 161µs | 2 | 12.8ms | # spent 12.7ms (9.66+3.07) within C4::Templates::BEGIN@6 which was called:
# once (9.66ms+3.07ms) by C4::Output::BEGIN@36 at line 6 # spent 12.7ms making 1 call to C4::Templates::BEGIN@6
# spent 29µs making 1 call to CGI::import |
7 | 3 | 49µs | 2 | 133µs | # spent 73µs (13+60) within C4::Templates::BEGIN@7 which was called:
# once (13µs+60µs) by C4::Output::BEGIN@36 at line 7 # spent 73µs making 1 call to C4::Templates::BEGIN@7
# spent 60µ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 | 47µs | 2 | 5.66ms | # spent 2.84ms (12µs+2.82) within C4::Templates::BEGIN@32 which was called:
# once (12µs+2.82ms) by C4::Output::BEGIN@36 at line 32 # spent 2.84ms making 1 call to C4::Templates::BEGIN@32
# spent 2.82ms making 1 call to base::import |
33 | 3 | 145µs | 1 | 29.9ms | # spent 29.9ms (1.16+28.8) within C4::Templates::BEGIN@33 which was called:
# once (1.16ms+28.8ms) by C4::Output::BEGIN@36 at line 33 # spent 29.9ms making 1 call to C4::Templates::BEGIN@33 |
34 | 3 | 42µs | 2 | 778µs | # spent 395µs (11+383) within C4::Templates::BEGIN@34 which was called:
# once (11µs+383µs) by C4::Output::BEGIN@36 at line 34 # spent 395µs making 1 call to C4::Templates::BEGIN@34
# spent 384µs making 1 call to Exporter::import |
35 | 3 | 135µs | 2 | 10.4ms | # spent 10.3ms (4.27+6.03) within C4::Templates::BEGIN@35 which was called:
# once (4.27ms+6.03ms) by C4::Output::BEGIN@36 at line 35 # spent 10.3ms making 1 call to C4::Templates::BEGIN@35
# spent 83µs making 1 call to Exporter::import |
36 | |||||
37 | 3 | 1.68ms | 2 | 16µs | # spent 14µs (12+2) within C4::Templates::BEGIN@37 which was called:
# once (12µs+2µs) by C4::Output::BEGIN@36 at line 37 # spent 14µs making 1 call to C4::Templates::BEGIN@37
# spent 2µs making 1 call to C4::Context::import |
38 | |||||
39 | 1 | 13µs | 1 | 323µs | __PACKAGE__->mk_accessors(qw( theme activethemes preferredtheme lang filename htdocs interface vars)); # spent 323µs making 1 call to Class::Accessor::mk_accessors |
40 | |||||
- - | |||||
43 | # spent 23.9ms (170µs+23.7) within C4::Templates::new which was called:
# once (170µs+23.7ms) by C4::Templates::gettemplate at line 238 | ||||
44 | 22 | 126µs | my $class = shift; | ||
45 | my $interface = shift; | ||||
46 | my $filename = shift; | ||||
47 | my $tmplbase = shift; | ||||
48 | my $query = @_? shift: undef; | ||||
49 | my $htdocs; | ||||
50 | 1 | 17µs | if ( $interface ne "intranet" ) { # spent 17µ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 | 151µs | my ($theme, $lang, $activethemes)= themelanguage( $htdocs, $tmplbase, $interface, $query); # spent 151µs making 1 call to C4::Templates::themelanguage | ||
57 | my @includes; | ||||
58 | foreach (@$activethemes) { | ||||
59 | 4 | 16µs | push @includes, "$htdocs/$_/$lang/includes"; | ||
60 | push @includes, "$htdocs/$_/en/includes" unless $lang eq 'en'; | ||||
61 | } | ||||
62 | 3 | 23.5ms | my $template = Template->new( # spent 23.5ms making 1 call to Template::Base::new
# spent 25µs making 2 calls to C4::Context::config, avg 13µ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 | my $self = { | ||||
73 | TEMPLATE => $template, | ||||
74 | VARS => {}, | ||||
75 | }; | ||||
76 | bless $self, $class; | ||||
77 | 1 | 32µs | $self->theme($theme); # spent 32µs making 1 call to C4::Templates::theme | ||
78 | 1 | 9µs | $self->lang($lang); # spent 9µs making 1 call to C4::Templates::lang | ||
79 | 1 | 8µs | $self->activethemes($activethemes); # spent 8µs making 1 call to C4::Templates::activethemes | ||
80 | 1 | 8µs | $self->preferredtheme($activethemes->[0]); # spent 8µs making 1 call to C4::Templates::preferredtheme | ||
81 | 1 | 8µs | $self->filename($filename); # spent 8µs making 1 call to C4::Templates::filename | ||
82 | 1 | 8µs | $self->htdocs($htdocs); # spent 8µs making 1 call to C4::Templates::htdocs | ||
83 | 1 | 8µs | $self->interface($interface); # spent 8µs making 1 call to C4::Templates::interface | ||
84 | $self->{VARS}->{"test"} = "value"; | ||||
85 | return $self; | ||||
86 | |||||
87 | } | ||||
88 | |||||
89 | # spent 852ms (1.62+850) within C4::Templates::output which was called:
# once (1.62ms+850ms) by main::RUNTIME at line 898 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl | ||||
90 | 16 | 294µs | my $self = shift; | ||
91 | my $vars = shift; | ||||
92 | |||||
93 | # my $file = $self->htdocs . '/' . $self->theme .'/'.$self->lang.'/'.$self->filename; | ||||
94 | my $template = $self->{TEMPLATE}; | ||||
95 | 1 | 5µs | 1 | 42µs | if ( $self->interface eq 'intranet' ) { # spent 42µs making 1 call to C4::Templates::interface |
96 | $vars->{themelang} = '/intranet-tmpl'; | ||||
97 | } | ||||
98 | else { | ||||
99 | $vars->{themelang} = '/opac-tmpl'; | ||||
100 | } | ||||
101 | 1 | 16µs | $vars->{lang} = $self->lang; # spent 16µs making 1 call to C4::Templates::lang | ||
102 | 2 | 17µs | $vars->{themelang} .= '/' . $self->preferredtheme . '/' . $self->lang; # spent 11µs making 1 call to C4::Templates::preferredtheme
# spent 6µs making 1 call to C4::Templates::lang | ||
103 | 2 | 2.13ms | $vars->{yuipath} = # spent 2.12ms making 1 call to C4::Context::preference
# spent 12µ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 | $vars->{interface} = | ||||
108 | ( $self->{interface} ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' ); | ||||
109 | 1 | 16µs | $vars->{theme} = $self->theme; # spent 16µs making 1 call to C4::Templates::theme | ||
110 | 1 | 8µs | $vars->{opaccolorstylesheet} = # spent 8µs making 1 call to C4::Context::preference | ||
111 | C4::Context->preference('opaccolorstylesheet'); | ||||
112 | 1 | 6µs | $vars->{opacsmallimage} = C4::Context->preference('opacsmallimage'); # spent 6µs making 1 call to C4::Context::preference | ||
113 | 1 | 6µs | $vars->{opaclayoutstylesheet} = # spent 6µ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 | for my $k ( keys %{ $self->{VARS} } ) { | ||||
119 | 316 | 748µs | $vars->{$k} = $self->{VARS}->{$k}; | ||
120 | 149 | 683µs | 9 | 17.5ms | if (ref($vars->{$k}) eq 'ARRAY'){ # spent 17.5ms making 9 calls to C4::Templates::utf8_arrayref, avg 1.95ms/call |
121 | utf8_arrayref($vars->{$k}); | ||||
122 | } | ||||
123 | elsif (ref($vars->{$k}) eq 'HASH'){ | ||||
124 | utf8_hashref($vars->{$k}); | ||||
125 | } | ||||
126 | else { | ||||
127 | 149 | 140µs | utf8::encode($vars->{$k}) if utf8::is_utf8($vars->{$k}); # spent 140µs making 149 calls to utf8::is_utf8, avg 943ns/call | ||
128 | } | ||||
129 | } | ||||
130 | my $data; | ||||
131 | # binmode( STDOUT, ":utf8" ); | ||||
132 | 2 | 831ms | $template->process( $self->filename, $vars, \$data ) # spent 830ms making 1 call to Template::process
# spent 24µs making 1 call to C4::Templates::filename | ||
133 | || die "Template process failed: ", $template->error(); | ||||
134 | return $data; | ||||
135 | } | ||||
136 | |||||
137 | sub utf8_arrayref { | ||||
138 | 444 | 827µs | my $arrayref = shift; | ||
139 | foreach my $element (@$arrayref){ | ||||
140 | 420 | 469µs | if (ref($element) eq 'ARRAY'){ | ||
141 | utf8_arrayref($element); | ||||
142 | next; | ||||
143 | } | ||||
144 | 420 | 835µs | if (ref($element) eq 'HASH'){ | ||
145 | 210 | 16.6ms | utf8_hashref($element); # spent 20.6ms making 210 calls to C4::Templates::utf8_hashref, avg 98µs/call, recursion: max depth 1, sum of overlapping time 3.92ms | ||
146 | next; | ||||
147 | } | ||||
148 | utf8::encode($element) if utf8::is_utf8($element); | ||||
149 | } | ||||
150 | } | ||||
151 | |||||
152 | # spent 16.6ms (12.9+3.78) within C4::Templates::utf8_hashref which was called 210 times, avg 79µs/call:
# 210 times (12.9ms+3.78ms) by C4::Templates::utf8_arrayref at line 145, avg 79µs/call | ||||
153 | 420 | 2.00ms | my $hashref = shift; | ||
154 | for my $key (keys %{$hashref}){ | ||||
155 | 7491 | 13.4ms | if (ref($hashref->{$key}) eq 'ARRAY'){ | ||
156 | 213 | 0s | utf8_arrayref($hashref->{$key}); # spent 5.39ms making 213 calls to C4::Templates::utf8_arrayref, avg 25µs/call, recursion: max depth 1, sum of overlapping time 5.39ms | ||
157 | next; | ||||
158 | } | ||||
159 | if (ref($hashref->{$key}) eq 'HASH'){ | ||||
160 | utf8_hashref($hashref->{$key}); | ||||
161 | next; | ||||
162 | } | ||||
163 | 2335 | 2.31ms | utf8::encode($hashref->{$key}) if utf8::is_utf8($hashref->{$key}); # spent 2.26ms making 2284 calls to utf8::is_utf8, avg 988ns/call
# spent 57µ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 | 500ns | my $_current_language = 'en'; | ||
175 | |||||
176 | # spent 163µs within C4::Templates::_current_language which was called 25 times, avg 7µs/call:
# 25 times (163µs+0s) by C4::XSLT::XSLTParse4Display at line 165 of /usr/share/koha/lib/C4/XSLT.pm, avg 7µs/call | ||||
177 | 25 | 145µs | return $_current_language; | ||
178 | } | ||||
179 | |||||
180 | |||||
181 | # wrapper method to allow easier transition from HTML template pro to Template Toolkit | ||||
182 | # spent 942µs within C4::Templates::param which was called 45 times, avg 21µs/call:
# once (359µs+0s) by C4::Auth::get_template_and_user at line 381 of /usr/share/koha/lib/C4/Auth.pm
# once (83µs+0s) by C4::Auth::get_template_and_user at line 303 of /usr/share/koha/lib/C4/Auth.pm
# once (27µs+0s) by main::RUNTIME at line 857 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (25µs+0s) by main::RUNTIME at line 248 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (22µs+0s) by main::RUNTIME at line 467 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (21µs+0s) by main::RUNTIME at line 751 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (20µs+0s) by main::RUNTIME at line 202 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (20µs+0s) by main::RUNTIME at line 701 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (19µs+0s) by main::RUNTIME at line 494 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (19µs+0s) by main::RUNTIME at line 196 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (18µs+0s) by C4::Templates::gettemplate at line 269
# once (17µs+0s) by main::RUNTIME at line 875 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (17µs+0s) by main::RUNTIME at line 163 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (17µs+0s) by main::RUNTIME at line 897 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (14µs+0s) by main::RUNTIME at line 696 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (13µs+0s) by main::RUNTIME at line 643 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (12µs+0s) by main::RUNTIME at line 368 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (12µs+0s) by main::RUNTIME at line 812 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (12µs+0s) by main::RUNTIME at line 757 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (12µs+0s) by C4::Auth::get_template_and_user at line 280 of /usr/share/koha/lib/C4/Auth.pm
# once (12µs+0s) by main::RUNTIME at line 123 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (12µs+0s) by main::RUNTIME at line 493 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (12µs+0s) by main::RUNTIME at line 147 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (11µs+0s) by C4::Auth::get_template_and_user at line 283 of /usr/share/koha/lib/C4/Auth.pm
# once (11µs+0s) by main::RUNTIME at line 165 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (11µs+0s) by main::RUNTIME at line 148 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (11µs+0s) by main::RUNTIME at line 150 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (9µs+0s) by C4::Auth::get_template_and_user at line 297 of /usr/share/koha/lib/C4/Auth.pm
# once (8µs+0s) by main::RUNTIME at line 141 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (8µs+0s) by C4::Auth::get_template_and_user at line 461 of /usr/share/koha/lib/C4/Auth.pm
# once (7µs+0s) by main::RUNTIME at line 702 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (6µs+0s) by main::RUNTIME at line 853 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 (6µs+0s) by main::RUNTIME at line 402 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (5µs+0s) by main::RUNTIME at line 756 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (5µs+0s) by main::RUNTIME at line 867 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (5µs+0s) by main::RUNTIME at line 706 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (5µs+0s) by main::RUNTIME at line 699 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (5µs+0s) by main::RUNTIME at line 704 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (5µs+0s) by main::RUNTIME at line 814 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (5µs+0s) by main::RUNTIME at line 705 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (5µs+0s) by main::RUNTIME at line 703 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (5µs+0s) by main::RUNTIME at line 711 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (4µs+0s) by main::RUNTIME at line 707 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (4µs+0s) by main::RUNTIME at line 700 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl | ||||
183 | 90 | 320µs | my $self = shift; | ||
184 | while (@_) { | ||||
185 | 620 | 743µs | my $key = shift; | ||
186 | my $val = shift; | ||||
187 | if ( ref($val) eq 'ARRAY' && !scalar @$val ) { $val = undef; } | ||||
188 | elsif ( ref($val) eq 'HASH' && !scalar %$val ) { $val = undef; } | ||||
189 | 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 | 11µs | 1 | 18µs | my $path = C4::Context->config('intrahtdocs') . "/prog/en/includes/"; # spent 18µs making 1 call to C4::Context::config |
209 | |||||
210 | #--------------------------------------------------------------------------------------------------------- | ||||
211 | # FIXME - POD | ||||
212 | |||||
213 | # spent 2.40ms (35µs+2.37) within C4::Templates::_get_template_file which was called:
# once (35µs+2.37ms) by C4::Templates::gettemplate at line 235 | ||||
214 | 7 | 38µs | my ($tmplbase, $interface, $query) = @_; | ||
215 | |||||
216 | my $is_intranet = $interface eq 'intranet'; | ||||
217 | 1 | 19µs | my $htdocs = C4::Context->config($is_intranet ? 'intrahtdocs' : 'opachtdocs'); # spent 19µs making 1 call to C4::Context::config | ||
218 | 1 | 2.34ms | my ($theme, $lang, $availablethemes) = themelanguage($htdocs, $tmplbase, $interface, $query); # spent 2.34ms making 1 call to C4::Templates::themelanguage | ||
219 | |||||
220 | # if the template doesn't exist, load the English one as a last resort | ||||
221 | my $filename = "$htdocs/$theme/$lang/modules/$tmplbase"; | ||||
222 | 1 | 4µs | unless (-f $filename) { # spent 4µs making 1 call to C4::Templates::CORE:ftfile | ||
223 | $lang = 'en'; | ||||
224 | $filename = "$htdocs/$theme/$lang/modules/$tmplbase"; | ||||
225 | } | ||||
226 | return ($htdocs, $theme, $lang, $filename); | ||||
227 | } | ||||
228 | |||||
229 | |||||
230 | # spent 30.7ms (100µs+30.6) within C4::Templates::gettemplate which was called:
# once (100µs+30.6ms) by C4::Auth::get_template_and_user at line 137 of /usr/share/koha/lib/C4/Auth.pm | ||||
231 | 15 | 97µs | my ( $tmplbase, $interface, $query, $is_plugin ) = @_; | ||
232 | ($query) or warn "no query in gettemplate"; | ||||
233 | 1 | 2.30ms | my $path = C4::Context->preference('intranet_includes') || 'includes'; # spent 2.30ms making 1 call to C4::Context::preference | ||
234 | 1 | 18µs | $tmplbase =~ s/\.tmpl$/.tt/; # spent 18µs making 1 call to C4::Templates::CORE:subst | ||
235 | 1 | 2.40ms | my ($htdocs, $theme, $lang, $filename) # spent 2.40ms making 1 call to C4::Templates::_get_template_file | ||
236 | = _get_template_file($tmplbase, $interface, $query); | ||||
237 | $filename = $tmplbase if ( $is_plugin ); | ||||
238 | 1 | 23.9ms | my $template = C4::Templates->new($interface, $filename, $tmplbase, $query); # spent 23.9ms 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 | 17 | 541µs | my $current_lang = regex_lang_subtags($lang); # spent 530µs making 1 call to C4::Languages::regex_lang_subtags
# spent 11µs making 16 calls to Regexp::DESTROY, avg 669ns/call | ||
258 | my $bidi; | ||||
259 | $bidi = get_bidi($current_lang->{script}) if $current_lang->{script}; | ||||
260 | # Languages | ||||
261 | 1 | 1.39ms | my $languages_loop = getTranslatedLanguages($interface,$theme,$lang); # spent 1.39ms making 1 call to Memoize::__ANON__[(eval 1015)[Memoize.pm:73]:1] | ||
262 | my $num_languages_enabled = 0; | ||||
263 | foreach my $lang (@$languages_loop) { | ||||
264 | 5 | 6µs | foreach my $sublang (@{ $lang->{'sublanguages_loop'} }) { | ||
265 | 7 | 6µs | $num_languages_enabled++ if $sublang->{enabled}; | ||
266 | } | ||||
267 | } | ||||
268 | $template->param( | ||||
269 | 1 | 18µs | languages_loop => $languages_loop, # spent 18µ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 | return $template; | ||||
275 | } | ||||
276 | |||||
277 | |||||
278 | #--------------------------------------------------------------------------------------------------------- | ||||
279 | # FIXME - POD | ||||
280 | sub themelanguage { | ||||
281 | 14 | 39µs | my ($htdocs, $tmpl, $interface, $query) = @_; | ||
282 | ($query) or warn "no query in themelanguage"; | ||||
283 | |||||
284 | # Select a language based on cookie, syspref available languages & browser | ||||
285 | 2 | 227µs | my $lang = getlanguage($query, $interface); # spent 227µs making 2 calls to C4::Templates::getlanguage, avg 113µs/call | ||
286 | |||||
287 | # Select theme | ||||
288 | my $is_intranet = $interface eq 'intranet'; | ||||
289 | 2 | 2.16ms | my @themes = split(" ", C4::Context->preference( # spent 2.16ms making 2 calls to C4::Context::preference, avg 1.08ms/call | ||
290 | $is_intranet ? "template" : "opacthemes" )); | ||||
291 | push @themes, 'prog'; | ||||
292 | |||||
293 | # Try to find first theme for the selected language | ||||
294 | for my $theme (@themes) { | ||||
295 | 6 | 67µs | 2 | 31µs | if ( -e "$htdocs/$theme/$lang/modules/$tmpl" ) { # spent 31µs making 2 calls to C4::Templates::CORE:ftis, avg 15µs/call |
296 | $_current_language = $lang; | ||||
297 | 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 5.70ms (134µs+5.57) within C4::Templates::getlanguage which was called 3 times, avg 1.90ms/call:
# 2 times (72µs+154µs) by C4::Templates::themelanguage at line 285, avg 113µs/call
# once (62µs+5.41ms) by main::RUNTIME at line 93 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl | ||||
321 | 27 | 101µs | my ($query, $interface) = @_; | ||
322 | |||||
323 | # Select a language based on cookie, syspref available languages & browser | ||||
324 | my $preference_to_check = | ||||
325 | $interface eq 'intranet' ? 'language' : 'opaclanguages'; | ||||
326 | 3 | 2.17ms | my @languages = split /,/, C4::Context->preference($preference_to_check); # spent 2.17ms making 3 calls to C4::Context::preference, avg 722µs/call | ||
327 | |||||
328 | my $lang; | ||||
329 | |||||
330 | # cookie | ||||
331 | 3 | 518µs | if ( $query->cookie('KohaOpacLanguage') ) { # spent 379µs making 1 call to CGI::AUTOLOAD
# spent 139µs making 2 calls to CGI::cookie, avg 70µs/call | ||
332 | $lang = $query->cookie('KohaOpacLanguage'); | ||||
333 | $lang =~ s/[^a-zA-Z_-]*//; # sanitize cookie | ||||
334 | } | ||||
335 | |||||
336 | # HTTP_ACCEPT_LANGUAGE | ||||
337 | 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 | if ( $lang && any { $_ eq $lang } @languages ) { | ||||
344 | return $lang; | ||||
345 | } | ||||
346 | |||||
347 | # Pick the first selected syspref language | ||||
348 | $lang = shift @languages; | ||||
349 | return $lang if $lang; | ||||
350 | |||||
351 | # Fall back to English if necessary | ||||
352 | return 'en'; | ||||
353 | } | ||||
354 | |||||
355 | 1 | 11µs | 1; | ||
# spent 4µs within C4::Templates::CORE:ftfile which was called:
# once (4µs+0s) by C4::Templates::_get_template_file at line 222 | |||||
# spent 31µs within C4::Templates::CORE:ftis which was called 2 times, avg 15µs/call:
# 2 times (31µs+0s) by C4::Templates::themelanguage at line 295, avg 15µs/call | |||||
# spent 18µs within C4::Templates::CORE:subst which was called:
# once (18µs+0s) by C4::Templates::gettemplate at line 234 |