| Filename | /home/vagrant/kohaclone/C4/Templates.pm |
| Statements | Executed 1144 statements in 1.58ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 417 | 31 | 4 | 2.11ms | 2.11ms | C4::Templates::param |
| 1 | 1 | 1 | 1.38ms | 37.4ms | C4::Templates::BEGIN@33 |
| 4 | 2 | 2 | 994µs | 574ms | C4::Templates::output |
| 4 | 1 | 1 | 623µs | 482ms | C4::Templates::gettemplate |
| 8 | 2 | 1 | 509µs | 232ms | C4::Templates::themelanguage |
| 4 | 1 | 1 | 380µs | 135ms | C4::Templates::new |
| 8 | 1 | 1 | 260µs | 260µs | C4::Templates::CORE:ftis (opcode) |
| 4 | 1 | 1 | 109µs | 119ms | C4::Templates::_get_template_file |
| 1 | 1 | 1 | 38µs | 54µs | C4::Templates::BEGIN@3 |
| 1 | 1 | 1 | 36µs | 104µs | C4::Templates::BEGIN@35 |
| 4 | 1 | 1 | 31µs | 31µs | C4::Templates::CORE:binmode (opcode) |
| 8 | 1 | 1 | 30µs | 30µs | C4::Templates::CORE:match (opcode) |
| 1 | 1 | 1 | 17µs | 43µs | C4::Templates::BEGIN@7 |
| 1 | 1 | 1 | 15µs | 18µs | C4::Templates::BEGIN@37 |
| 1 | 1 | 1 | 14µs | 185µs | C4::Templates::BEGIN@34 |
| 1 | 1 | 1 | 12µs | 22µs | C4::Templates::BEGIN@4 |
| 1 | 1 | 1 | 12µs | 80µs | C4::Templates::BEGIN@32 |
| 1 | 1 | 1 | 12µs | 43µs | C4::Templates::BEGIN@6 |
| 1 | 1 | 1 | 10µs | 54µs | C4::Templates::BEGIN@5 |
| 0 | 0 | 0 | 0s | 0s | C4::Templates::GetColumnDefs |
| 0 | 0 | 0 | 0s | 0s | C4::Templates::getlanguagecookie |
| 0 | 0 | 0 | 0s | 0s | C4::Templates::setlanguagecookie |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package C4::Templates; | ||||
| 2 | |||||
| 3 | 2 | 69µ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 # spent 54µs making 1 call to C4::Templates::BEGIN@3
# spent 15µs making 1 call to strict::import | ||
| 4 | 2 | 33µ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 # spent 22µs making 1 call to C4::Templates::BEGIN@4
# spent 10µs making 1 call to warnings::import | ||
| 5 | 2 | 98µ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 # spent 54µs making 1 call to C4::Templates::BEGIN@5
# spent 44µs making 1 call to Exporter::import | ||
| 6 | 2 | 74µ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 # spent 43µs making 1 call to C4::Templates::BEGIN@6
# spent 32µs making 1 call to CGI::import | ||
| 7 | 2 | 69µ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 # 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 | |||||
| 32 | 2 | 148µ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 # spent 80µs making 1 call to C4::Templates::BEGIN@32
# spent 68µs making 1 call to base::import | ||
| 33 | 1 | 37.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 # spent 37.4ms making 1 call to C4::Templates::BEGIN@33 | ||
| 34 | 2 | 355µ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 # spent 185µs making 1 call to C4::Templates::BEGIN@34
# spent 170µs making 1 call to Exporter::import | ||
| 35 | 2 | 170µ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 # spent 104µs making 1 call to C4::Templates::BEGIN@35
# spent 67µs making 1 call to Exporter::import | ||
| 36 | |||||
| 37 | 2 | 21µ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 # spent 18µs making 1 call to C4::Templates::BEGIN@37
# spent 3µs making 1 call to C4::Context::import | ||
| 38 | |||||
| 39 | 1 | 178µ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 | ||||
| 44 | 1 | 600ns | my $class = shift; | ||
| 45 | 1 | 300ns | my $interface = shift; | ||
| 46 | 1 | 200ns | my $filename = shift; | ||
| 47 | 1 | 400ns | my $tmplbase = shift; | ||
| 48 | 1 | 1µs | my $query = @_? shift: undef; | ||
| 49 | 1 | 200ns | my $htdocs; | ||
| 50 | 1 | 1µs | if ( $interface ne "intranet" ) { | ||
| 51 | $htdocs = C4::Context->config('opachtdocs'); | ||||
| 52 | } | ||||
| 53 | else { | ||||
| 54 | 1 | 13µs | 4 | 29µs | $htdocs = C4::Context->config('intrahtdocs'); # spent 29µs making 4 calls to C4::Context::config, avg 7µs/call |
| 55 | } | ||||
| 56 | 1 | 5µs | 4 | 114ms | my ($theme, $lang, $activethemes)= themelanguage( $htdocs, $tmplbase, $interface, $query); # spent 114ms making 4 calls to C4::Templates::themelanguage, avg 28.5ms/call |
| 57 | 1 | 400ns | my @includes; | ||
| 58 | 1 | 1µs | foreach (@$activethemes) { | ||
| 59 | 3 | 7µs | push @includes, "$htdocs/$_/$lang/includes"; | ||
| 60 | 3 | 2µs | push @includes, "$htdocs/$_/en/includes" unless $lang eq 'en'; | ||
| 61 | } | ||||
| 62 | # Do not use template cache if script is called from commandline | ||||
| 63 | 1 | 18µs | 4 | 34µ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 |
| 64 | 1 | 20µs | 4 | 20.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(); | ||||
| 75 | 1 | 4µs | my $self = { | ||
| 76 | TEMPLATE => $template, | ||||
| 77 | VARS => {}, | ||||
| 78 | }; | ||||
| 79 | 1 | 4µs | bless $self, $class; | ||
| 80 | 1 | 17µs | 4 | 64µs | $self->theme($theme); # spent 64µs making 4 calls to C4::Templates::theme, avg 16µs/call |
| 81 | 1 | 10µs | 4 | 19µs | $self->lang($lang); # spent 19µs making 4 calls to C4::Templates::lang, avg 5µs/call |
| 82 | 1 | 8µs | 4 | 20µs | $self->activethemes($activethemes); # spent 20µs making 4 calls to C4::Templates::activethemes, avg 5µs/call |
| 83 | 1 | 8µs | 4 | 16µs | $self->preferredtheme($activethemes->[0]); # spent 16µs making 4 calls to C4::Templates::preferredtheme, avg 4µs/call |
| 84 | 1 | 9µs | 4 | 20µs | $self->filename($filename); # spent 20µs making 4 calls to C4::Templates::filename, avg 5µs/call |
| 85 | 1 | 8µs | 4 | 19µs | $self->htdocs($htdocs); # spent 19µs making 4 calls to C4::Templates::htdocs, avg 5µs/call |
| 86 | 1 | 9µs | 4 | 21µs | $self->interface($interface); # spent 21µs making 4 calls to C4::Templates::interface, avg 5µs/call |
| 87 | 1 | 3µs | $self->{VARS}->{"test"} = "value"; | ||
| 88 | 1 | 4µ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 | ||||
| 93 | 1 | 300ns | my $self = shift; | ||
| 94 | 1 | 300ns | my $vars = shift; | ||
| 95 | |||||
| 96 | # my $file = $self->htdocs . '/' . $self->theme .'/'.$self->lang.'/'.$self->filename; | ||||
| 97 | 1 | 2µs | my $template = $self->{TEMPLATE}; | ||
| 98 | 1 | 15µs | 4 | 35µ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 | } | ||||
| 104 | 1 | 7µs | 4 | 12µs | $vars->{lang} = $self->lang; # spent 12µs making 4 calls to C4::Templates::lang, avg 3µs/call |
| 105 | 1 | 12µs | 8 | 17µ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 |
| 106 | 1 | 2µs | $vars->{interface} = | ||
| 107 | ( $self->{interface} ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' ); | ||||
| 108 | 1 | 8µs | 4 | 13µs | $vars->{theme} = $self->theme; # spent 13µs making 4 calls to C4::Templates::theme, avg 3µs/call |
| 109 | 1 | 15µs | 4 | 9.72ms | $vars->{OpacAdditionalStylesheet} = # spent 9.72ms making 4 calls to C4::Context::preference, avg 2.43ms/call |
| 110 | C4::Context->preference('OpacAdditionalStylesheet'); | ||||
| 111 | 1 | 10µs | 4 | 16.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 | ||||
| 115 | 1 | 68µs | for my $k ( keys %{ $self->{VARS} } ) { | ||
| 116 | 160 | 114µs | $vars->{$k} = $self->{VARS}->{$k}; | ||
| 117 | } | ||||
| 118 | |||||
| 119 | 1 | 300ns | my $data; | ||
| 120 | 1 | 10µs | 4 | 31µs | binmode( STDOUT, ":utf8" ); # spent 31µs making 4 calls to C4::Templates::CORE:binmode, avg 8µs/call |
| 121 | 1 | 17µs | 8 | 547ms | $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(); | ||||
| 123 | 1 | 30µ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 | ||||
| 128 | 105 | 17µs | my $self = shift; | ||
| 129 | 105 | 183µs | while (@_) { | ||
| 130 | 160 | 42µs | my $key = shift; | ||
| 131 | 160 | 25µs | my $val = shift; | ||
| 132 | 160 | 41µs | if ( ref($val) eq 'ARRAY' && !scalar @$val ) { $val = undef; } | ||
| 133 | elsif ( ref($val) eq 'HASH' && !scalar %$val ) { $val = undef; } | ||||
| 134 | 160 | 252µ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 | |||||
| 145 | C4::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. | ||||
| 153 | 1 | 17µs | my $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 | ||||
| 159 | 1 | 2µs | my ($tmplbase, $interface, $query) = @_; | ||
| 160 | |||||
| 161 | 1 | 900ns | my $is_intranet = $interface eq 'intranet'; | ||
| 162 | 1 | 18µs | 4 | 52µs | my $htdocs = C4::Context->config($is_intranet ? 'intrahtdocs' : 'opachtdocs'); # spent 52µs making 4 calls to C4::Context::config, avg 13µs/call |
| 163 | 1 | 6µs | 4 | 119ms | my ($theme, $lang, $availablethemes) = themelanguage($htdocs, $tmplbase, $interface, $query); # spent 119ms making 4 calls to C4::Templates::themelanguage, avg 29.6ms/call |
| 164 | 1 | 300ns | $lang //= 'en'; | ||
| 165 | 1 | 3µs | my $filename = "$htdocs/$theme/$lang/modules/$tmplbase"; | ||
| 166 | |||||
| 167 | 1 | 4µ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 | ||||
| 172 | 1 | 2µs | my ( $tmplbase, $interface, $query, $is_plugin ) = @_; | ||
| 173 | 1 | 400ns | ($query) or warn "no query in gettemplate"; | ||
| 174 | 1 | 18µs | 4 | 20.8ms | my $path = C4::Context->preference('intranet_includes') || 'includes'; # spent 20.8ms making 4 calls to C4::Context::preference, avg 5.20ms/call |
| 175 | 1 | 7µs | 4 | 119ms | 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); | ||||
| 177 | 1 | 200ns | $filename = $tmplbase if ( $is_plugin ); | ||
| 178 | 1 | 11µs | 4 | 135ms | 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 | ||||
| 194 | 1 | 95µs | 4 | 607µs | my $current_lang = regex_lang_subtags($lang); # spent 607µs making 4 calls to C4::Languages::regex_lang_subtags, avg 152µs/call |
| 195 | 1 | 200ns | my $bidi; | ||
| 196 | 1 | 600ns | $bidi = get_bidi($current_lang->{script}) if $current_lang->{script}; | ||
| 197 | 1 | 3µs | 4 | 36µs | $template->param( # spent 36µs making 4 calls to C4::Templates::param, avg 9µs/call |
| 198 | bidi => $bidi, | ||||
| 199 | ); | ||||
| 200 | # Languages | ||||
| 201 | 1 | 23µs | 4 | 206ms | my $languages_loop = getTranslatedLanguages($interface,$theme,$lang); # spent 206ms making 4 calls to C4::Languages::getTranslatedLanguages, avg 51.4ms/call |
| 202 | 1 | 900ns | my $num_languages_enabled = 0; | ||
| 203 | 1 | 5µs | foreach my $lang (@$languages_loop) { | ||
| 204 | 19 | 23µs | foreach my $sublang (@{ $lang->{'sublanguages_loop'} }) { | ||
| 205 | 21 | 19µs | $num_languages_enabled++ if $sublang->{enabled}; | ||
| 206 | } | ||||
| 207 | } | ||||
| 208 | 1 | 900ns | my $one_language_enabled = ($num_languages_enabled <= 1) ? 1 : 0; # deal with zero enabled langs as well | ||
| 209 | 1 | 300ns | $template->param( | ||
| 210 | languages_loop => $languages_loop, | ||||
| 211 | one_language_enabled => $one_language_enabled, | ||||
| 212 | ) unless $one_language_enabled; | ||||
| 213 | |||||
| 214 | 1 | 77µs | return $template; | ||
| 215 | } | ||||
| 216 | |||||
| 217 | |||||
| 218 | =head2 themelanguage | ||||
| 219 | |||||
| 220 | my ($theme,$lang,\@themes) = themelanguage($htdocs,$tmpl,$interface,query); | ||||
| 221 | |||||
| 222 | This function returns the theme and language to be used for rendering the UI. | ||||
| 223 | It also returns the list of themes that should be applied as a fallback. This is | ||||
| 224 | used for the theme overlay feature (i.e. if a file doesn't exist on the requested | ||||
| 225 | theme, fallback to the configured fallback). | ||||
| 226 | |||||
| 227 | Important: this function is used on the webinstaller too, so always consider | ||||
| 228 | the use case where the DB is not populated already when rewriting/fixing. | ||||
| 229 | |||||
| 230 | =cut | ||||
| 231 | |||||
| 232 | sub themelanguage { | ||||
| 233 | 2 | 1µs | my ($htdocs, $tmpl, $interface, $query) = @_; | ||
| 234 | 2 | 1µs | ($query) or warn "no query in themelanguage"; | ||
| 235 | |||||
| 236 | # Select a language based on cookie, syspref available languages & browser | ||||
| 237 | 2 | 40µs | 8 | 70.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 | ||||
| 240 | 2 | 400ns | my @themes; | ||
| 241 | 2 | 3µs | my $theme_syspref = ($interface eq 'intranet') ? 'template' : 'opacthemes'; | ||
| 242 | 2 | 2µs | my $fallback_syspref = ($interface eq 'intranet') ? 'template' : 'OPACFallback'; | ||
| 243 | # Yeah, hardcoded, last resort if the DB is not populated | ||||
| 244 | 2 | 2µs | my $hardcoded_theme = ($interface eq 'intranet') ? 'prog' : 'bootstrap'; | ||
| 245 | |||||
| 246 | # Configured theme is the first one | ||||
| 247 | 2 | 29µs | 16 | 71.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 | ||||
| 250 | 2 | 29µs | 16 | 89.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 | ||||
| 253 | 2 | 1µs | push @themes, $hardcoded_theme; | ||
| 254 | |||||
| 255 | # Try to find first theme for the selected theme/lang, then for fallback/lang | ||||
| 256 | 2 | 18µs | 8 | 30µs | my $where = $tmpl =~ /xsl$/ ? 'xslt' : 'modules'; # spent 30µs making 8 calls to C4::Templates::CORE:match, avg 4µs/call |
| 257 | 2 | 2µs | for my $theme (@themes) { | ||
| 258 | 2 | 114µs | 16 | 318µ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 | |||||
| 275 | sub 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 | |||||
| 294 | Returns a cookie object containing the calculated language to be used. | ||||
| 295 | |||||
| 296 | =cut | ||||
| 297 | |||||
| 298 | sub 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 | |||||
| 314 | It is passed a CGI object and returns a hash of hashes containing | ||||
| 315 | the column names and descriptions for each table defined in the | ||||
| 316 | columns.def file corresponding to the CGI object. | ||||
| 317 | |||||
| 318 | =cut | ||||
| 319 | |||||
| 320 | sub 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 | |||||
| 357 | 1; | ||||
# 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 | |||||
# 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 | |||||
# 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 |