← Index
NYTProf Performance Profile   « line view »
For starman worker -M FindBin --max-requests 50 --workers 2 --user=kohadev-koha --group kohadev-koha --pid /var/run/koha/kohadev/plack.pid --daemonize --access-log /var/log/koha/kohadev/plack.log --error-log /var/log/koha/kohadev/plack-error.log -E deployment --socket /var/run/koha/kohadev/plack.sock /etc/koha/sites/kohadev/plack.psgi
  Run on Fri Jan 8 14:31:06 2016
Reported on Fri Jan 8 14:33:27 2016

Filename/home/vagrant/kohaclone/C4/Templates.pm
StatementsExecuted 1144 statements in 1.58ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
4173142.11ms2.11msC4::Templates::::paramC4::Templates::param
1111.38ms37.4msC4::Templates::::BEGIN@33C4::Templates::BEGIN@33
422994µs574msC4::Templates::::outputC4::Templates::output
411623µs482msC4::Templates::::gettemplateC4::Templates::gettemplate
821509µs232msC4::Templates::::themelanguageC4::Templates::themelanguage
411380µs135msC4::Templates::::newC4::Templates::new
811260µs260µsC4::Templates::::CORE:ftisC4::Templates::CORE:ftis (opcode)
411109µs119msC4::Templates::::_get_template_fileC4::Templates::_get_template_file
11138µs54µsC4::Templates::::BEGIN@3C4::Templates::BEGIN@3
11136µs104µsC4::Templates::::BEGIN@35C4::Templates::BEGIN@35
41131µs31µsC4::Templates::::CORE:binmodeC4::Templates::CORE:binmode (opcode)
81130µs30µsC4::Templates::::CORE:matchC4::Templates::CORE:match (opcode)
11117µs43µsC4::Templates::::BEGIN@7C4::Templates::BEGIN@7
11115µs18µsC4::Templates::::BEGIN@37C4::Templates::BEGIN@37
11114µs185µsC4::Templates::::BEGIN@34C4::Templates::BEGIN@34
11112µs22µsC4::Templates::::BEGIN@4C4::Templates::BEGIN@4
11112µs80µsC4::Templates::::BEGIN@32C4::Templates::BEGIN@32
11112µs43µsC4::Templates::::BEGIN@6C4::Templates::BEGIN@6
11110µs54µsC4::Templates::::BEGIN@5C4::Templates::BEGIN@5
0000s0sC4::Templates::::GetColumnDefsC4::Templates::GetColumnDefs
0000s0sC4::Templates::::getlanguagecookieC4::Templates::getlanguagecookie
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
3269µs
# spent 54µs (38+15) within C4::Templates::BEGIN@3 which was called: # once (38µs+15µs) by C4::Auth::BEGIN@29 at line 3
use strict;
# spent 54µs making 1 call to C4::Templates::BEGIN@3 # spent 15µs making 1 call to strict::import
4233µs
# spent 22µs (12+10) within C4::Templates::BEGIN@4 which was called: # once (12µs+10µs) by C4::Auth::BEGIN@29 at line 4
use warnings;
# spent 22µs making 1 call to C4::Templates::BEGIN@4 # spent 10µs making 1 call to warnings::import
5298µs
# spent 54µs (10+44) within C4::Templates::BEGIN@5 which was called: # once (10µs+44µs) by C4::Auth::BEGIN@29 at line 5
use Carp;
# spent 54µs making 1 call to C4::Templates::BEGIN@5 # spent 44µs making 1 call to Exporter::import
6274µs
# spent 43µs (12+32) within C4::Templates::BEGIN@6 which was called: # once (12µs+32µs) by C4::Auth::BEGIN@29 at line 6
use CGI qw ( -utf8 );
# spent 43µs making 1 call to C4::Templates::BEGIN@6 # spent 32µs making 1 call to CGI::import
7269µs
# spent 43µs (17+26) within C4::Templates::BEGIN@7 which was called: # once (17µs+26µs) by C4::Auth::BEGIN@29 at line 7
use List::MoreUtils qw/ any uniq /;
# spent 43µs making 1 call to C4::Templates::BEGIN@7 # spent 26µs making 1 call to Exporter::import
8
9# Copyright 2009 Chris Cormack and The Koha Dev Team
10#
11# This file is part of Koha.
12#
13# Koha is free software; you can redistribute it and/or modify it
14# under the terms of the GNU General Public License as published by
15# the Free Software Foundation; either version 3 of the License, or
16# (at your option) any later version.
17#
18# Koha is distributed in the hope that it will be useful, but
19# WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21# GNU General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with Koha; if not, see <http://www.gnu.org/licenses>.
25
26=head1 NAME
27
28 Koha::Templates - Object for manipulating templates for use with Koha
29
30=cut
31
322148µs
# spent 80µs (12+68) within C4::Templates::BEGIN@32 which was called: # once (12µs+68µs) by C4::Auth::BEGIN@29 at line 32
use base qw(Class::Accessor);
# spent 80µs making 1 call to C4::Templates::BEGIN@32 # spent 68µs making 1 call to base::import
33137.4ms
# spent 37.4ms (1.38+36.0) within C4::Templates::BEGIN@33 which was called: # once (1.38ms+36.0ms) by C4::Auth::BEGIN@29 at line 33
use Template;
# spent 37.4ms making 1 call to C4::Templates::BEGIN@33
342355µs
# spent 185µs (14+170) within C4::Templates::BEGIN@34 which was called: # once (14µs+170µs) by C4::Auth::BEGIN@29 at line 34
use Template::Constants qw( :debug );
# spent 185µs making 1 call to C4::Templates::BEGIN@34 # spent 170µs making 1 call to Exporter::import
352170µs
# spent 104µs (36+67) within C4::Templates::BEGIN@35 which was called: # once (36µs+67µs) by C4::Auth::BEGIN@29 at line 35
use C4::Languages qw(getTranslatedLanguages get_bidi regex_lang_subtags language_get_description accept_language );
# spent 104µs making 1 call to C4::Templates::BEGIN@35 # spent 67µs making 1 call to Exporter::import
36
37221µs
# spent 18µs (15+3) within C4::Templates::BEGIN@37 which was called: # once (15µs+3µs) by C4::Auth::BEGIN@29 at line 37
use C4::Context;
# spent 18µs making 1 call to C4::Templates::BEGIN@37 # spent 3µs making 1 call to C4::Context::import
38
391178µs__PACKAGE__->mk_accessors(qw( theme activethemes preferredtheme lang filename htdocs interface vars));
# spent 178µs making 1 call to Class::Accessor::mk_accessors
40
- -
43
# spent 135ms (380µs+135) within C4::Templates::new which was called 4 times, avg 33.8ms/call: # 4 times (380µs+135ms) by C4::Templates::gettemplate at line 178, avg 33.8ms/call
sub new {
441600ns my $class = shift;
451300ns my $interface = shift;
461200ns my $filename = shift;
471400ns my $tmplbase = shift;
4811µs my $query = @_? shift: undef;
491200ns my $htdocs;
5011µs if ( $interface ne "intranet" ) {
51 $htdocs = C4::Context->config('opachtdocs');
52 }
53 else {
54113µs429µs $htdocs = C4::Context->config('intrahtdocs');
# spent 29µs making 4 calls to C4::Context::config, avg 7µs/call
55 }
5615µs4114ms my ($theme, $lang, $activethemes)= themelanguage( $htdocs, $tmplbase, $interface, $query);
# spent 114ms making 4 calls to C4::Templates::themelanguage, avg 28.5ms/call
571400ns my @includes;
5811µs foreach (@$activethemes) {
5937µs push @includes, "$htdocs/$_/$lang/includes";
6032µs push @includes, "$htdocs/$_/en/includes" unless $lang eq 'en';
61 }
62 # Do not use template cache if script is called from commandline
63118µs434µs my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE};
# spent 34µs making 4 calls to C4::Context::config, avg 9µs/call
64120µs420.7ms my $template = Template->new(
# spent 20.7ms making 4 calls to Template::Base::new, avg 5.17ms/call
65 { EVAL_PERL => 1,
66 ABSOLUTE => 1,
67 PLUGIN_BASE => 'Koha::Template::Plugin',
68 COMPILE_EXT => $use_template_cache ? '.ttc' : '',
69 COMPILE_DIR => $use_template_cache ? C4::Context->config('template_cache_dir') : '',
70 INCLUDE_PATH => \@includes,
71 FILTERS => {},
72 ENCODING => 'UTF-8',
73 }
74 ) or die Template->error();
7514µs my $self = {
76 TEMPLATE => $template,
77 VARS => {},
78 };
7914µs bless $self, $class;
80117µs464µs $self->theme($theme);
# spent 64µs making 4 calls to C4::Templates::theme, avg 16µs/call
81110µs419µs $self->lang($lang);
# spent 19µs making 4 calls to C4::Templates::lang, avg 5µs/call
8218µs420µs $self->activethemes($activethemes);
# spent 20µs making 4 calls to C4::Templates::activethemes, avg 5µs/call
8318µs416µs $self->preferredtheme($activethemes->[0]);
# spent 16µs making 4 calls to C4::Templates::preferredtheme, avg 4µs/call
8419µs420µs $self->filename($filename);
# spent 20µs making 4 calls to C4::Templates::filename, avg 5µs/call
8518µs419µs $self->htdocs($htdocs);
# spent 19µs making 4 calls to C4::Templates::htdocs, avg 5µs/call
8619µs421µs $self->interface($interface);
# spent 21µs making 4 calls to C4::Templates::interface, avg 5µs/call
8713µs $self->{VARS}->{"test"} = "value";
8814µs return $self;
89
90}
91
92
# spent 574ms (994µs+573) within C4::Templates::output which was called 4 times, avg 144ms/call: # 3 times (729µs+442ms) by CGI::Compile::ROOT::home_vagrant_kohaclone_errors_404_2epl::__ANON__[/home/vagrant/kohaclone/errors/404.pl:58] at line 38 of errors/404.pl, avg 148ms/call # once (265µs+131ms) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::__ANON__[/home/vagrant/kohaclone/mainpage.pl:107] at line 87 of mainpage.pl
sub output {
931300ns my $self = shift;
941300ns my $vars = shift;
95
96# my $file = $self->htdocs . '/' . $self->theme .'/'.$self->lang.'/'.$self->filename;
9712µs my $template = $self->{TEMPLATE};
98115µs435µs if ( $self->interface eq 'intranet' ) {
# spent 35µs making 4 calls to C4::Templates::interface, avg 9µs/call
99 $vars->{themelang} = '/intranet-tmpl';
100 }
101 else {
102 $vars->{themelang} = '/opac-tmpl';
103 }
10417µs412µs $vars->{lang} = $self->lang;
# spent 12µs making 4 calls to C4::Templates::lang, avg 3µs/call
105112µs817µs $vars->{themelang} .= '/' . $self->preferredtheme . '/' . $self->lang;
# spent 12µs making 4 calls to C4::Templates::preferredtheme, avg 3µs/call # spent 5µs making 4 calls to C4::Templates::lang, avg 1µs/call
10612µs $vars->{interface} =
107 ( $self->{interface} ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' );
10818µs413µs $vars->{theme} = $self->theme;
# spent 13µs making 4 calls to C4::Templates::theme, avg 3µs/call
109115µs49.72ms $vars->{OpacAdditionalStylesheet} =
# spent 9.72ms making 4 calls to C4::Context::preference, avg 2.43ms/call
110 C4::Context->preference('OpacAdditionalStylesheet');
111110µs416.8ms $vars->{opaclayoutstylesheet} =
# spent 16.8ms making 4 calls to C4::Context::preference, avg 4.20ms/call
112 C4::Context->preference('opaclayoutstylesheet');
113
114 # add variables set via param to $vars for processing
115168µs for my $k ( keys %{ $self->{VARS} } ) {
116160114µs $vars->{$k} = $self->{VARS}->{$k};
117 }
118
1191300ns my $data;
120110µs431µs binmode( STDOUT, ":utf8" );
# spent 31µs making 4 calls to C4::Templates::CORE:binmode, avg 8µs/call
121117µs8547ms $template->process( $self->filename, $vars, \$data )
# spent 547ms making 4 calls to Template::process, avg 137ms/call # spent 30µs making 4 calls to C4::Templates::filename, avg 7µs/call
122 || die "Template process failed: ", $template->error();
123130µs return $data;
124}
125
126# wrapper method to allow easier transition from HTML template pro to Template Toolkit
127
# spent 2.11ms within C4::Templates::param which was called 417 times, avg 5µs/call: # 304 times (903µs+0s) by C4::Auth::get_template_and_user at line 282 of C4/Auth.pm, avg 3µs/call # 4 times (317µs+0s) by C4::Auth::get_template_and_user at line 433 of C4/Auth.pm, avg 79µs/call # 4 times (214µs+0s) by C4::Auth::get_template_and_user at line 409 of C4/Auth.pm, avg 54µs/call # 4 times (104µs+0s) by C4::Auth::get_template_and_user at line 400 of C4/Auth.pm, avg 26µs/call # 4 times (69µs+0s) by C4::Auth::get_template_and_user at line 396 of C4/Auth.pm, avg 17µs/call # 4 times (46µs+0s) by C4::Auth::get_template_and_user at line 228 of C4/Auth.pm, avg 12µs/call # 4 times (44µs+0s) by C4::Auth::get_template_and_user at line 267 of C4/Auth.pm, avg 11µs/call # 4 times (36µs+0s) by C4::Templates::gettemplate at line 197, avg 9µs/call # 4 times (35µs+0s) by C4::Auth::get_template_and_user at line 262 of C4/Auth.pm, avg 9µs/call # 4 times (27µs+0s) by C4::Auth::get_template_and_user at line 251 of C4/Auth.pm, avg 7µs/call # 4 times (24µs+0s) by C4::Auth::get_template_and_user at line 268 of C4/Auth.pm, avg 6µs/call # 4 times (24µs+0s) by C4::Auth::get_template_and_user at line 263 of C4/Auth.pm, avg 6µs/call # 4 times (21µs+0s) by C4::Auth::get_template_and_user at line 230 of C4/Auth.pm, avg 5µs/call # 4 times (16µs+0s) by C4::Auth::get_template_and_user at line 272 of C4/Auth.pm, avg 4µs/call # 4 times (16µs+0s) by C4::Auth::get_template_and_user at line 275 of C4/Auth.pm, avg 4µs/call # 4 times (16µs+0s) by C4::Auth::get_template_and_user at line 271 of C4/Auth.pm, avg 4µs/call # 4 times (14µs+0s) by C4::Auth::get_template_and_user at line 276 of C4/Auth.pm, avg 4µs/call # 4 times (14µs+0s) by C4::Auth::get_template_and_user at line 304 of C4/Auth.pm, avg 3µs/call # 4 times (13µs+0s) by C4::Auth::get_template_and_user at line 229 of C4/Auth.pm, avg 3µs/call # 4 times (13µs+0s) by C4::Auth::get_template_and_user at line 277 of C4/Auth.pm, avg 3µs/call # 4 times (13µs+0s) by C4::Auth::get_template_and_user at line 266 of C4/Auth.pm, avg 3µs/call # 4 times (13µs+0s) by C4::Auth::get_template_and_user at line 273 of C4/Auth.pm, avg 3µs/call # 4 times (13µs+0s) by C4::Auth::get_template_and_user at line 265 of C4/Auth.pm, avg 3µs/call # 4 times (13µs+0s) by C4::Auth::get_template_and_user at line 269 of C4/Auth.pm, avg 3µs/call # 4 times (12µs+0s) by C4::Auth::get_template_and_user at line 264 of C4/Auth.pm, avg 3µs/call # 4 times (11µs+0s) by C4::Auth::get_template_and_user at line 274 of C4/Auth.pm, avg 3µs/call # 4 times (10µs+0s) by C4::Auth::get_template_and_user at line 270 of C4/Auth.pm, avg 3µs/call # 4 times (10µs+0s) by C4::Auth::get_template_and_user at line 278 of C4/Auth.pm, avg 3µs/call # 3 times (22µs+0s) by CGI::Compile::ROOT::home_vagrant_kohaclone_errors_404_2epl::__ANON__[/home/vagrant/kohaclone/errors/404.pl:58] at line 37 of errors/404.pl, avg 7µs/call # once (18µs+0s) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::__ANON__[/home/vagrant/kohaclone/mainpage.pl:107] at line 72 of mainpage.pl # once (12µs+0s) by CGI::Compile::ROOT::home_vagrant_kohaclone_mainpage_2epl::__ANON__[/home/vagrant/kohaclone/mainpage.pl:107] at line 53 of mainpage.pl
sub param {
12810517µs my $self = shift;
129105183µs while (@_) {
13016042µs my $key = shift;
13116025µs my $val = shift;
13216041µs if ( ref($val) eq 'ARRAY' && !scalar @$val ) { $val = undef; }
133 elsif ( ref($val) eq 'HASH' && !scalar %$val ) { $val = undef; }
134160252µs if ( $key ) {
135 $self->{VARS}->{$key} = $val;
136 } else {
137 warn "Problem = a value of $val has been passed to param without key";
138 }
139 }
140}
141
142
143=head1 NAME
144
145C4::Templates - Functions for managing templates
146
147=head1 FUNCTIONS
148
149=cut
150
151# FIXME: this is a quick fix to stop rc1 installing broken
152# Still trying to figure out the correct fix.
153117µsmy $path = C4::Context->config('intrahtdocs') . "/prog/en/includes/";
# spent 17µs making 1 call to C4::Context::config
154
155#---------------------------------------------------------------------------------------------------------
156# FIXME - POD
157
158
# spent 119ms (109µs+119) within C4::Templates::_get_template_file which was called 4 times, avg 29.7ms/call: # 4 times (109µs+119ms) by C4::Templates::gettemplate at line 175, avg 29.7ms/call
sub _get_template_file {
15912µs my ($tmplbase, $interface, $query) = @_;
160
1611900ns my $is_intranet = $interface eq 'intranet';
162118µs452µs my $htdocs = C4::Context->config($is_intranet ? 'intrahtdocs' : 'opachtdocs');
# spent 52µs making 4 calls to C4::Context::config, avg 13µs/call
16316µs4119ms my ($theme, $lang, $availablethemes) = themelanguage($htdocs, $tmplbase, $interface, $query);
# spent 119ms making 4 calls to C4::Templates::themelanguage, avg 29.6ms/call
1641300ns $lang //= 'en';
16513µs my $filename = "$htdocs/$theme/$lang/modules/$tmplbase";
166
16714µs return ($htdocs, $theme, $lang, $filename);
168}
169
170
171
# spent 482ms (623µs+481) within C4::Templates::gettemplate which was called 4 times, avg 120ms/call: # 4 times (623µs+481ms) by C4::Auth::get_template_and_user at line 166 of C4/Auth.pm, avg 120ms/call
sub gettemplate {
17212µs my ( $tmplbase, $interface, $query, $is_plugin ) = @_;
1731400ns ($query) or warn "no query in gettemplate";
174118µs420.8ms my $path = C4::Context->preference('intranet_includes') || 'includes';
# spent 20.8ms making 4 calls to C4::Context::preference, avg 5.20ms/call
17517µs4119ms my ($htdocs, $theme, $lang, $filename)
# spent 119ms making 4 calls to C4::Templates::_get_template_file, avg 29.7ms/call
176 = _get_template_file($tmplbase, $interface, $query);
1771200ns $filename = $tmplbase if ( $is_plugin );
178111µs4135ms my $template = C4::Templates->new($interface, $filename, $tmplbase, $query);
# spent 135ms making 4 calls to C4::Templates::new, avg 33.8ms/call
179
180# NOTE: Commenting these out rather than deleting them so that those who need
181# to know how we previously shimmed these directories will be able to understand.
182# my $is_intranet = $interface eq 'intranet';
183# my $themelang =
184# ($is_intranet ? '/intranet-tmpl' : '/opac-tmpl') .
185# "/$theme/$lang";
186# $template->param(
187# themelang => $themelang,
188# interface => $is_intranet ? '/intranet-tmpl' : '/opac-tmpl',
189# theme => $theme,
190# lang => $lang
191# );
192
193 # Bidirectionality, must be sent even if is the only language
194195µs4607µs my $current_lang = regex_lang_subtags($lang);
# spent 607µs making 4 calls to C4::Languages::regex_lang_subtags, avg 152µs/call
1951200ns my $bidi;
1961600ns $bidi = get_bidi($current_lang->{script}) if $current_lang->{script};
19713µs436µs $template->param(
# spent 36µs making 4 calls to C4::Templates::param, avg 9µs/call
198 bidi => $bidi,
199 );
200 # Languages
201123µs4206ms my $languages_loop = getTranslatedLanguages($interface,$theme,$lang);
# spent 206ms making 4 calls to C4::Languages::getTranslatedLanguages, avg 51.4ms/call
2021900ns my $num_languages_enabled = 0;
20315µs foreach my $lang (@$languages_loop) {
2041923µs foreach my $sublang (@{ $lang->{'sublanguages_loop'} }) {
2052119µs $num_languages_enabled++ if $sublang->{enabled};
206 }
207 }
2081900ns my $one_language_enabled = ($num_languages_enabled <= 1) ? 1 : 0; # deal with zero enabled langs as well
2091300ns $template->param(
210 languages_loop => $languages_loop,
211 one_language_enabled => $one_language_enabled,
212 ) unless $one_language_enabled;
213
214177µs return $template;
215}
216
217
218=head2 themelanguage
219
220 my ($theme,$lang,\@themes) = themelanguage($htdocs,$tmpl,$interface,query);
221
222This function returns the theme and language to be used for rendering the UI.
223It also returns the list of themes that should be applied as a fallback. This is
224used for the theme overlay feature (i.e. if a file doesn't exist on the requested
225theme, fallback to the configured fallback).
226
227Important: this function is used on the webinstaller too, so always consider
228the use case where the DB is not populated already when rewriting/fixing.
229
230=cut
231
232
# spent 232ms (509µs+232) within C4::Templates::themelanguage which was called 8 times, avg 29.1ms/call: # 4 times (287µs+118ms) by C4::Templates::_get_template_file at line 163, avg 29.6ms/call # 4 times (223µs+114ms) by C4::Templates::new at line 56, avg 28.5ms/call
sub themelanguage {
23321µs my ($htdocs, $tmpl, $interface, $query) = @_;
23421µs ($query) or warn "no query in themelanguage";
235
236 # Select a language based on cookie, syspref available languages & browser
237240µs870.1ms my $lang = C4::Languages::getlanguage($query);
# spent 70.1ms making 8 calls to C4::Languages::getlanguage, avg 8.76ms/call
238
239 # Get theme
2402400ns my @themes;
24123µs my $theme_syspref = ($interface eq 'intranet') ? 'template' : 'opacthemes';
24222µs my $fallback_syspref = ($interface eq 'intranet') ? 'template' : 'OPACFallback';
243 # Yeah, hardcoded, last resort if the DB is not populated
24422µs my $hardcoded_theme = ($interface eq 'intranet') ? 'prog' : 'bootstrap';
245
246 # Configured theme is the first one
247229µs1671.6ms push @themes, C4::Context->preference( $theme_syspref )
# spent 71.6ms making 16 calls to C4::Context::preference, avg 4.48ms/call
248 if C4::Context->preference( $theme_syspref );
249 # Configured fallback next
250229µs1689.9ms push @themes, C4::Context->preference( $fallback_syspref )
# spent 89.9ms making 16 calls to C4::Context::preference, avg 5.62ms/call
251 if C4::Context->preference( $fallback_syspref );
252 # The hardcoded fallback theme is the last one
25321µs push @themes, $hardcoded_theme;
254
255 # Try to find first theme for the selected theme/lang, then for fallback/lang
256218µs830µs my $where = $tmpl =~ /xsl$/ ? 'xslt' : 'modules';
# spent 30µs making 8 calls to C4::Templates::CORE:match, avg 4µs/call
25722µs for my $theme (@themes) {
2582114µs16318µs if ( -e "$htdocs/$theme/$lang/$where/$tmpl" ) {
# spent 260µs making 8 calls to C4::Templates::CORE:ftis, avg 32µs/call # spent 58µs making 8 calls to List::MoreUtils::uniq, avg 7µs/call
259 return ( $theme, $lang, uniq( \@themes ) );
260 }
261 }
262 # Otherwise return theme/'en', last resort fallback/'en'
263 for my $theme (@themes) {
264 if ( -e "$htdocs/$theme/en/$where/$tmpl" ) {
265 return ( $theme, 'en', uniq( \@themes ) );
266 }
267 }
268 # tmpl is a full path, so this is a template for a plugin
269 if ( $tmpl =~ /^\// && -e $tmpl ) {
270 return ( $themes[0], $lang, uniq( \@themes ) );
271 }
272}
273
274
275sub setlanguagecookie {
276 my ( $query, $language, $uri ) = @_;
277
278 my $cookie = $query->cookie(
279 -name => 'KohaOpacLanguage',
280 -value => $language,
281 -HttpOnly => 1,
282 -expires => '+3y'
283 );
284 print $query->redirect(
285 -uri => $uri,
286 -cookie => $cookie
287 );
288}
289
290=head2 getlanguagecookie
291
292 my $cookie = getlanguagecookie($query,$language);
293
294Returns a cookie object containing the calculated language to be used.
295
296=cut
297
298sub getlanguagecookie {
299 my ( $query, $language ) = @_;
300 my $cookie = $query->cookie(
301 -name => 'KohaOpacLanguage',
302 -value => $language,
303 -HttpOnly => 1,
304 -expires => '+3y'
305 );
306
307 return $cookie;
308}
309
310=head2 GetColumnDefs
311
312 my $columns = GetColumnDefs( $cgi )
313
314It is passed a CGI object and returns a hash of hashes containing
315the column names and descriptions for each table defined in the
316columns.def file corresponding to the CGI object.
317
318=cut
319
320sub GetColumnDefs {
321
322 my $query = shift;
323
324 my $columns = {};
325
326 my $htdocs = C4::Context->config('intrahtdocs');
327 my $columns_file = 'columns.def';
328
329 # Get theme and language to build the path to columns.def
330 my ($theme, $lang, $availablethemes) =
331 themelanguage($htdocs, 'about.tt', 'intranet', $query);
332 # Build columns.def path
333 my $path = "$htdocs/$theme/$lang/$columns_file";
334 my $fh;
335 if ( ! open ( $fh, q{<:encoding(utf-8)}, $path ) ) {
336 carp "Error opening $path. Check your templates.";
337 return;
338 }
339 # Loop through the columns.def file
340 while ( my $input = <$fh> ){
341 chomp $input;
342 if ( $input =~ m|<field name="(.*)">(.*)</field>| ) {
343 my ( $table, $column ) = split( '\.', $1);
344 my $description = $2;
345 # Initialize the table array if needed.
346 @{$columns->{ $table }} = () if ! defined $columns->{ $table };
347 # Push field and description
348 push @{$columns->{ $table }},
349 { field => $column, description => $description };
350 }
351 }
352 close $fh;
353
354 return $columns;
355}
356
3571;
 
# spent 31µs within C4::Templates::CORE:binmode which was called 4 times, avg 8µs/call: # 4 times (31µs+0s) by C4::Templates::output at line 120, avg 8µs/call
sub C4::Templates::CORE:binmode; # opcode
# spent 260µs within C4::Templates::CORE:ftis which was called 8 times, avg 32µs/call: # 8 times (260µs+0s) by C4::Templates::themelanguage at line 258, avg 32µs/call
sub C4::Templates::CORE:ftis; # opcode
# spent 30µs within C4::Templates::CORE:match which was called 8 times, avg 4µs/call: # 8 times (30µs+0s) by C4::Templates::themelanguage at line 256, avg 4µs/call
sub C4::Templates::CORE:match; # opcode