← 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 17:10:45 2013
Reported on Tue Oct 15 17:11:39 2013

Filename/usr/share/koha/lib/C4/Templates.pm
StatementsExecuted 10553 statements in 23.4ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
2101112.9ms16.6msC4::Templates::::utf8_hashrefC4::Templates::utf8_hashref (recurses: max depth 1, inclusive time 3.92ms)
1119.66ms12.7msC4::Templates::::BEGIN@6C4::Templates::BEGIN@6
1114.27ms10.3msC4::Templates::::BEGIN@35C4::Templates::BEGIN@35
222212.35ms17.5msC4::Templates::::utf8_arrayrefC4::Templates::utf8_arrayref (recurses: max depth 1, inclusive time 5.39ms)
1111.62ms852msC4::Templates::::outputC4::Templates::output
1111.16ms29.9msC4::Templates::::BEGIN@33C4::Templates::BEGIN@33
45453942µs942µsC4::Templates::::paramC4::Templates::param
111170µs23.9msC4::Templates::::newC4::Templates::new
2511163µs163µsC4::Templates::::_current_languageC4::Templates::_current_language
322134µs5.70msC4::Templates::::getlanguageC4::Templates::getlanguage
111100µs30.7msC4::Templates::::gettemplateC4::Templates::gettemplate
22179µs2.49msC4::Templates::::themelanguageC4::Templates::themelanguage
11135µs2.40msC4::Templates::::_get_template_fileC4::Templates::_get_template_file
21131µs31µsC4::Templates::::CORE:ftisC4::Templates::CORE:ftis (opcode)
11121µs28µsC4::Templates::::BEGIN@3C4::Templates::BEGIN@3
11118µs18µsC4::Templates::::CORE:substC4::Templates::CORE:subst (opcode)
11113µs34µsC4::Templates::::BEGIN@4C4::Templates::BEGIN@4
11113µs73µsC4::Templates::::BEGIN@7C4::Templates::BEGIN@7
11112µs14µsC4::Templates::::BEGIN@37C4::Templates::BEGIN@37
11112µs2.84msC4::Templates::::BEGIN@32C4::Templates::BEGIN@32
11111µs395µsC4::Templates::::BEGIN@34C4::Templates::BEGIN@34
11110µs58µsC4::Templates::::BEGIN@5C4::Templates::BEGIN@5
1114µs4µ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
3332µs235µ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
use strict;
# spent 28µs making 1 call to C4::Templates::BEGIN@3 # spent 7µs making 1 call to strict::import
4329µs254µ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
use warnings;
# spent 34µs making 1 call to C4::Templates::BEGIN@4 # spent 21µs making 1 call to warnings::import
5329µs2105µ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
use Carp;
# spent 58µs making 1 call to C4::Templates::BEGIN@5 # spent 48µs making 1 call to Exporter::import
63161µs212.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
use CGI;
# spent 12.7ms making 1 call to C4::Templates::BEGIN@6 # spent 29µs making 1 call to CGI::import
7349µs2133µ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
use List::MoreUtils qw/any/;
# 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
- -
32347µs25.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
use base qw(Class::Accessor);
# spent 2.84ms making 1 call to C4::Templates::BEGIN@32 # spent 2.82ms making 1 call to base::import
333145µs129.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
use Template;
# spent 29.9ms making 1 call to C4::Templates::BEGIN@33
34342µs2778µ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
use Template::Constants qw( :debug );
# spent 395µs making 1 call to C4::Templates::BEGIN@34 # spent 384µs making 1 call to Exporter::import
353135µs210.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
use C4::Languages qw(getTranslatedLanguages get_bidi regex_lang_subtags language_get_description accept_language );
# spent 10.3ms making 1 call to C4::Templates::BEGIN@35 # spent 83µs making 1 call to Exporter::import
36
3731.68ms216µ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
use C4::Context;
# spent 14µs making 1 call to C4::Templates::BEGIN@37 # spent 2µs making 1 call to C4::Context::import
38
39113µs1323µ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
sub new {
4422126µs my $class = shift;
45 my $interface = shift;
46 my $filename = shift;
47 my $tmplbase = shift;
48 my $query = @_? shift: undef;
49 my $htdocs;
50117µ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 }
561151µ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) {
59416µs push @includes, "$htdocs/$_/$lang/includes";
60 push @includes, "$htdocs/$_/en/includes" unless $lang eq 'en';
61 }
62323.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;
77132µs $self->theme($theme);
# spent 32µs making 1 call to C4::Templates::theme
7819µs $self->lang($lang);
# spent 9µs making 1 call to C4::Templates::lang
7918µs $self->activethemes($activethemes);
# spent 8µ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
8218µs $self->htdocs($htdocs);
# spent 8µ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 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
sub output {
9016294µ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};
9515µs142µ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 }
101116µs $vars->{lang} = $self->lang;
# spent 16µs making 1 call to C4::Templates::lang
102217µ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
10322.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' );
109116µs $vars->{theme} = $self->theme;
# spent 16µs making 1 call to C4::Templates::theme
11018µs $vars->{opaccolorstylesheet} =
# spent 8µs making 1 call to C4::Context::preference
111 C4::Context->preference('opaccolorstylesheet');
11216µs $vars->{opacsmallimage} = C4::Context->preference('opacsmallimage');
# spent 6µs making 1 call to C4::Context::preference
11316µ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} } ) {
119316748µs $vars->{$k} = $self->{VARS}->{$k};
120149683µs917.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 {
127149140µ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" );
1322831ms $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
# spent 17.5ms (2.35+15.2) within C4::Templates::utf8_arrayref which was called 222 times, avg 79µs/call: # 213 times (1.47ms+-1.47ms) by C4::Templates::utf8_hashref at line 156, avg 0s/call # 9 times (884µs+16.6ms) by C4::Templates::output at line 120, avg 1.95ms/call
sub utf8_arrayref {
138444827µs my $arrayref = shift;
139 foreach my $element (@$arrayref){
140420469µs if (ref($element) eq 'ARRAY'){
141 utf8_arrayref($element);
142 next;
143 }
144420835µs if (ref($element) eq 'HASH'){
14521016.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
sub utf8_hashref {
1534202.00ms my $hashref = shift;
154 for my $key (keys %{$hashref}){
155749113.4ms if (ref($hashref->{$key}) eq 'ARRAY'){
1562130s 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 }
16323352.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.
1741500nsmy $_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
sub _current_language {
17725145µ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
sub param {
18390320µs my $self = shift;
184 while (@_) {
185620743µ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.
208111µs118µsmy $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
sub _get_template_file {
214738µs my ($tmplbase, $interface, $query) = @_;
215
216 my $is_intranet = $interface eq 'intranet';
217119µs my $htdocs = C4::Context->config($is_intranet ? 'intrahtdocs' : 'opachtdocs');
# spent 19µs making 1 call to C4::Context::config
21812.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";
22214µ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
sub gettemplate {
2311597µs my ( $tmplbase, $interface, $query, $is_plugin ) = @_;
232 ($query) or warn "no query in gettemplate";
23312.30ms my $path = C4::Context->preference('intranet_includes') || 'includes';
# spent 2.30ms making 1 call to C4::Context::preference
234118µs $tmplbase =~ s/\.tmpl$/.tt/;
# spent 18µs making 1 call to C4::Templates::CORE:subst
23512.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 );
238123.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
25717541µ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
26111.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) {
26456µs foreach my $sublang (@{ $lang->{'sublanguages_loop'} }) {
26576µs $num_languages_enabled++ if $sublang->{enabled};
266 }
267 }
268 $template->param(
269118µ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
# spent 2.49ms (79µs+2.41) within C4::Templates::themelanguage which was called 2 times, avg 1.25ms/call: # once (57µs+2.28ms) by C4::Templates::_get_template_file at line 218 # once (22µs+129µs) by C4::Templates::new at line 56
sub themelanguage {
2811439µ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
2852227µ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';
28922.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) {
295667µs231µ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
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 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
sub getlanguage {
32127101µ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.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
3313518µ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
355111µs1;
 
# spent 4µs within C4::Templates::CORE:ftfile which was called: # once (4µs+0s) by C4::Templates::_get_template_file at line 222
sub C4::Templates::CORE:ftfile; # opcode
# 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
sub C4::Templates::CORE:ftis; # opcode
# spent 18µs within C4::Templates::CORE:subst which was called: # once (18µs+0s) by C4::Templates::gettemplate at line 234
sub C4::Templates::CORE:subst; # opcode