← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
  Run on Tue Oct 15 11:58:52 2013
Reported on Tue Oct 15 12:01:03 2013

Filename/usr/share/koha/lib/C4/Templates.pm
StatementsExecuted 10553 statements in 22.0ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
2101112.2ms15.4msC4::Templates::::utf8_hashrefC4::Templates::utf8_hashref (recurses: max depth 1, inclusive time 3.75ms)
1118.14ms10.9msC4::Templates::::BEGIN@6C4::Templates::BEGIN@6
1112.57ms3.01msC4::Templates::::BEGIN@35C4::Templates::BEGIN@35
222212.08ms16.2msC4::Templates::::utf8_arrayrefC4::Templates::utf8_arrayref (recurses: max depth 1, inclusive time 5.03ms)
1111.36ms720msC4::Templates::::outputC4::Templates::output
454531.32ms1.32msC4::Templates::::paramC4::Templates::param
1111.18ms24.6msC4::Templates::::BEGIN@33C4::Templates::BEGIN@33
2511162µs162µsC4::Templates::::_current_languageC4::Templates::_current_language
111142µs20.2msC4::Templates::::newC4::Templates::new
111114µs129msC4::Templates::::gettemplateC4::Templates::gettemplate
32263µs4.36msC4::Templates::::getlanguageC4::Templates::getlanguage
22154µs2.34msC4::Templates::::themelanguageC4::Templates::themelanguage
11133µs2.31msC4::Templates::::_get_template_fileC4::Templates::_get_template_file
21120µs20µsC4::Templates::::CORE:ftisC4::Templates::CORE:ftis (opcode)
11120µs27µsC4::Templates::::BEGIN@3C4::Templates::BEGIN@3
11114µs2.47msC4::Templates::::BEGIN@32C4::Templates::BEGIN@32
11114µs17µsC4::Templates::::BEGIN@37C4::Templates::BEGIN@37
11113µs76µsC4::Templates::::BEGIN@7C4::Templates::BEGIN@7
11113µs369µsC4::Templates::::BEGIN@34C4::Templates::BEGIN@34
11112µs34µsC4::Templates::::BEGIN@4C4::Templates::BEGIN@4
11110µs63µsC4::Templates::::BEGIN@5C4::Templates::BEGIN@5
1115µs5µsC4::Templates::::CORE:substC4::Templates::CORE:subst (opcode)
1113µs3µsC4::Templates::::CORE:ftfileC4::Templates::CORE:ftfile (opcode)
0000s0sC4::Templates::::__ANON__[:343]C4::Templates::__ANON__[:343]
0000s0sC4::Templates::::setlanguagecookieC4::Templates::setlanguagecookie
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package C4::Templates;
2
3330µs234µ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
use strict;
# spent 27µs making 1 call to C4::Templates::BEGIN@3 # spent 7µs making 1 call to strict::import
4327µs255µ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
use warnings;
# spent 34µs making 1 call to C4::Templates::BEGIN@4 # spent 22µs making 1 call to warnings::import
5330µs2116µ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
use Carp;
# spent 63µs making 1 call to C4::Templates::BEGIN@5 # spent 53µs making 1 call to Exporter::import
63198µs210.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
use CGI;
# spent 10.9ms making 1 call to C4::Templates::BEGIN@6 # spent 30µs making 1 call to CGI::import
7349µs2138µ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
use List::MoreUtils qw/any/;
# 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
- -
32393µs24.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
use base qw(Class::Accessor);
# spent 2.47ms making 1 call to C4::Templates::BEGIN@32 # spent 2.45ms making 1 call to base::import
333149µs124.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
use Template;
# spent 24.6ms making 1 call to C4::Templates::BEGIN@33
34342µs2725µ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
use Template::Constants qw( :debug );
# spent 369µs making 1 call to C4::Templates::BEGIN@34 # spent 356µs making 1 call to Exporter::import
353176µs23.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
use C4::Languages qw(getTranslatedLanguages get_bidi regex_lang_subtags language_get_description accept_language );
# spent 3.01ms making 1 call to C4::Templates::BEGIN@35 # spent 109µs making 1 call to Exporter::import
36
3731.49ms220µ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
use C4::Context;
# spent 17µs making 1 call to C4::Templates::BEGIN@37 # spent 3µs making 1 call to C4::Context::import
38
39113µs1369µ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
sub new {
4426117µs my $class = shift;
45 my $interface = shift;
46 my $filename = shift;
47 my $tmplbase = shift;
48 my $query = @_? shift: undef;
49 my $htdocs;
50114µ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 }
56185µs my ($theme, $lang, $activethemes)= themelanguage( $htdocs, $tmplbase, $interface, $query);
# spent 85µs making 1 call to C4::Templates::themelanguage
57 my @includes;
58 foreach (@$activethemes) {
59 push @includes, "$htdocs/$_/$lang/includes";
60 push @includes, "$htdocs/$_/en/includes" unless $lang eq 'en';
61 }
62319.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 my $self = {
73 TEMPLATE => $template,
74 VARS => {},
75 };
76 bless $self, $class;
77128µs $self->theme($theme);
# spent 28µs making 1 call to C4::Templates::theme
7819µs $self->lang($lang);
# spent 9µs making 1 call to C4::Templates::lang
7919µs $self->activethemes($activethemes);
# spent 9µs making 1 call to C4::Templates::activethemes
8018µs $self->preferredtheme($activethemes->[0]);
# spent 8µs making 1 call to C4::Templates::preferredtheme
8118µs $self->filename($filename);
# spent 8µs making 1 call to C4::Templates::filename
8217µs $self->htdocs($htdocs);
# spent 7µs making 1 call to C4::Templates::htdocs
8318µ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 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
sub output {
904821.43ms my $self = shift;
91 my $vars = shift;
92
93# my $file = $self->htdocs . '/' . $self->theme .'/'.$self->lang.'/'.$self->filename;
94 my $template = $self->{TEMPLATE};
95141µ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 $vars->{themelang} = '/opac-tmpl';
100 }
101118µs $vars->{lang} = $self->lang;
# spent 18µs making 1 call to C4::Templates::lang
102233µ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
10321.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 $vars->{interface} =
108 ( $self->{interface} ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' );
109110µs $vars->{theme} = $self->theme;
# spent 10µs making 1 call to C4::Templates::theme
11017µs $vars->{opaccolorstylesheet} =
# spent 7µs making 1 call to C4::Context::preference
111 C4::Context->preference('opaccolorstylesheet');
11213µs $vars->{opacsmallimage} = C4::Context->preference('opacsmallimage');
# spent 3µs making 1 call to C4::Context::preference
11313µ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 for my $k ( keys %{ $self->{VARS} } ) {
119 $vars->{$k} = $self->{VARS}->{$k};
120916.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 {
127149100µ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 my $data;
131# binmode( STDOUT, ":utf8" );
1322701ms $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 return $data;
135}
136
137
# spent 16.2ms (2.08+14.1) within C4::Templates::utf8_arrayref which was called 222 times, avg 73µs/call: # 213 times (1.28ms+-1.28ms) by C4::Templates::utf8_hashref at line 156, avg 0s/call # 9 times (798µs+15.4ms) by C4::Templates::output at line 120, avg 1.80ms/call
sub utf8_arrayref {
13812842.13ms my $arrayref = shift;
139 foreach my $element (@$arrayref){
140 if (ref($element) eq 'ARRAY'){
141 utf8_arrayref($element);
142 next;
143 }
144 if (ref($element) eq 'HASH'){
14521015.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 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
sub utf8_hashref {
153791114.1ms my $hashref = shift;
154 for my $key (keys %{$hashref}){
155 if (ref($hashref->{$key}) eq 'ARRAY'){
1562130s 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 next;
158 }
159 if (ref($hashref->{$key}) eq 'HASH'){
160 utf8_hashref($hashref->{$key});
161 next;
162 }
16323351.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.
1741400nsmy $_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
sub _current_language {
17725124µ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
sub param {
1837101.47ms my $self = shift;
184 while (@_) {
185 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.
20816µs119µsmy $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
sub _get_template_file {
214732µs my ($tmplbase, $interface, $query) = @_;
215
216 my $is_intranet = $interface eq 'intranet';
217120µs my $htdocs = C4::Context->config($is_intranet ? 'intrahtdocs' : 'opachtdocs');
# spent 20µs making 1 call to C4::Context::config
21812.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 my $filename = "$htdocs/$theme/$lang/modules/$tmplbase";
22213µ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 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
sub gettemplate {
23127109µs my ( $tmplbase, $interface, $query, $is_plugin ) = @_;
232 ($query) or warn "no query in gettemplate";
23312.17ms my $path = C4::Context->preference('intranet_includes') || 'includes';
# spent 2.17ms making 1 call to C4::Context::preference
23415µs $tmplbase =~ s/\.tmpl$/.tt/;
# spent 5µs making 1 call to C4::Templates::CORE:subst
23512.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 $filename = $tmplbase if ( $is_plugin );
238120.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
25717421µ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 my $bidi;
259 $bidi = get_bidi($current_lang->{script}) if $current_lang->{script};
260 # Languages
2611104ms my $languages_loop = getTranslatedLanguages($interface,$theme,$lang);
# spent 104ms making 1 call to C4::Languages::getTranslatedLanguages
262 my $num_languages_enabled = 0;
263 foreach my $lang (@$languages_loop) {
264 foreach my $sublang (@{ $lang->{'sublanguages_loop'} }) {
265 $num_languages_enabled++ if $sublang->{enabled};
266 }
267 }
268 $template->param(
269130µ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 return $template;
275}
276
277
278#---------------------------------------------------------------------------------------------------------
279# FIXME - POD
280
# spent 2.34ms (54µs+2.28) within C4::Templates::themelanguage which was called 2 times, avg 1.17ms/call: # once (37µs+2.22ms) by C4::Templates::_get_template_file at line 218 # once (17µs+68µs) by C4::Templates::new at line 56
sub themelanguage {
2812072µ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
2852130µ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 my $is_intranet = $interface eq 'intranet';
28922.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 push @themes, 'prog';
292
293 # Try to find first theme for the selected language
294 for my $theme (@themes) {
295220µs if ( -e "$htdocs/$theme/$lang/modules/$tmpl" ) {
# spent 20µs making 2 calls to C4::Templates::CORE:ftis, avg 10µ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
305sub 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
sub getlanguage {
3212753µ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';
32632.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 my $lang;
329
330 # cookie
3313310µ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 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
35518µs1;
 
# spent 3µs within C4::Templates::CORE:ftfile which was called: # once (3µs+0s) by C4::Templates::_get_template_file at line 222
sub C4::Templates::CORE:ftfile; # opcode
# 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
sub C4::Templates::CORE:ftis; # opcode
# spent 5µs within C4::Templates::CORE:subst which was called: # once (5µs+0s) by C4::Templates::gettemplate at line 234
sub C4::Templates::CORE:subst; # opcode