From 977774f0959dfd5e523f222df81f76b2e3be0cff Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 18 Jun 2021 16:05:34 +0200 Subject: [PATCH] Bug 12561: Change prototype of XSLTParse4Display Use a hash for better readability and reusability. Signed-off-by: Owen Leonard Signed-off-by: Tomas Cohen Arazi Signed-off-by: Nick Clemens Signed-off-by: Jonathan Druart --- C4/Search.pm | 22 ++++++++++++++++------ C4/XSLT.pm | 33 +++++++++++++++++++++++++-------- catalogue/detail.pl | 17 +++++++++-------- opac/opac-detail.pl | 20 ++++++++++---------- opac/opac-shelves.pl | 19 +++++++++---------- opac/opac-tags.pl | 17 ++++++++--------- virtualshelves/shelves.pl | 14 ++++++++------ 7 files changed, 85 insertions(+), 57 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 529f83428d..72c81ec06c 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1655,10 +1655,6 @@ sub searchResults { my ($bibliotag,$bibliosubf)=GetMarcFromKohaField( 'biblio.biblionumber' ); # set stuff for XSLT processing here once, not later again for every record we retrieved - my $xslsyspref = $is_opac ? 'OPACXSLTResultsDisplay' : 'XSLTResultsDisplay'; - my $xslfile = C4::Context->preference( $xslsyspref ) || "default"; - my $lang = C4::Languages::getlanguage(); - my $sysxml = C4::XSLT::get_xslt_sysprefs(); my $userenv = C4::Context->userenv; my $logged_in_user @@ -1955,14 +1951,28 @@ sub searchResults { # XSLT processing of some stuff # we fetched the sysprefs already before the loop through all retrieved record! - if (!$scan && $xslfile) { + if (!$scan) { $record_processor->options({ frameworkcode => $fw, interface => $search_context->{'interface'} }); $record_processor->process($marcrecord); - $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $xslsyspref, 1, \@hiddenitems, $sysxml, $xslfile, $lang, $xslt_variables); + + $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display( + { + biblionumber => $oldbiblio->{biblionumber}, + record => $marcrecord, + xsl_syspref => ( + $is_opac + ? 'OPACXSLTResultsDisplay' + : 'XSLTResultsDisplay' + ), + fix_amps => 1, + hidden_items => \@hiddenitems, + xslt_variables => $xslt_variables + } + ); } # if biblio level itypes are used and itemtype is notforloan, it can't be reserved either diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 245d76b74f..2de14b89a5 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -188,17 +188,17 @@ sub get_xslt_sysprefs { return $sysxml; } -sub XSLTParse4Display { - my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items, $sysxml, $xslfilename, $lang, $variables, $items_rs ) = @_; +sub get_xsl_filename { + my ( $xslsyspref ) = @_; + + my $lang = C4::Languages::getlanguage(); - $sysxml ||= C4::Context->preference($xslsyspref); - $xslfilename ||= C4::Context->preference($xslsyspref); - $lang ||= C4::Languages::getlanguage(); + my $xslfilename = C4::Context->preference($xslsyspref) || "default"; if ( $xslfilename =~ /^\s*"?default"?\s*$/i ) { - my $htdocs; - my $theme; - my $xslfile; + + my ( $htdocs, $theme, $xslfile ); + if ($xslsyspref eq "XSLTDetailsDisplay") { $htdocs = C4::Context->config('intrahtdocs'); $theme = C4::Context->preference("template"); @@ -239,6 +239,22 @@ sub XSLTParse4Display { $xslfilename =~ s/\{langcode\}/$lang/; } + return $xslfilename; +} + +sub XSLTParse4Display { + my ( $params ) = @_; + + my $biblionumber = $params->{biblionumber}; + my $orig_record = $params->{record}; + my $xslsyspref = $params->{xsl_syspref}; + my $fixamps = $params->{fix_amps}; + my $hidden_items = $params->{hidden_items} || []; + my $variables = $params->{xslt_variables}; + my $items_rs = $params->{items_rs}; + + my $xslfilename = get_xsl_filename( $xslsyspref); + # grab the XML, run it through our stylesheet, push it out to the browser my $record = transformMARCXML4XSLT($biblionumber, $orig_record); my $itemsxml; @@ -271,6 +287,7 @@ sub XSLTParse4Display { } $varxml .= "\n"; + my $sysxml = get_xslt_sysprefs(); $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml$varxml\<\/record\>/; if ($fixamps) { # We need to correct the ampersand entities that Zebra outputs $xmlrecord =~ s/\&amp;/\&/g; diff --git a/catalogue/detail.pl b/catalogue/detail.pl index f70803a029..0cb204ced9 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -124,9 +124,6 @@ my $marcflavour = C4::Context->preference("marcflavour"); { # XSLT processing of some stuff - my $xslfile = C4::Context->preference('XSLTDetailsDisplay') || "default"; - my $lang = C4::Languages::getlanguage(); - my $sysxml = C4::XSLT::get_xslt_sysprefs(); my $searcher = Koha::SearchEngine::Search->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } @@ -148,11 +145,15 @@ my $marcflavour = C4::Context->preference("marcflavour"); $template->param( XSLTDetailsDisplay => '1', - XSLTBloc => XSLTParse4Display( - $biblionumber, $record, "XSLTDetailsDisplay", 1, - undef, $sysxml, $xslfile, $lang, - $variables - ) + XSLTBloc => XSLTParse4Display( + { + biblionumber => $biblionumber, + record => $record, + xsl_syspref => "XSLTDetailsDisplay", + fix_amps => 1, + xslt_variables => $variables + } + ), ); } diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 97f8f0c2a9..55a326fe37 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -194,12 +194,6 @@ my $marcflavour = C4::Context->preference("marcflavour"); my $ean = GetNormalizedEAN( $record, $marcflavour ); { - - # XSLT processing of some stuff - my $xslfile = C4::Context->preference('OPACXSLTDetailsDisplay') || "default"; - my $lang = C4::Languages::getlanguage(); - my $sysxml = C4::XSLT::get_xslt_sysprefs(); - my $searcher = Koha::SearchEngine::Search->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); @@ -212,13 +206,14 @@ my $ean = GetNormalizedEAN( $record, $marcflavour ); my ( $err, $result, $count ) = $searcher->simple_search_compat( $query, 0, 0 ); warn "Warning from simple_search_compat: $err" - if $err; + if $err; my $variables = { anonymous_session => ($borrowernumber) ? 0 : 1, show_analytics_link => $count > 0 ? 1 : 0 }; + my $lang = C4::Languages::getlanguage(); my @plugin_responses = Koha::Plugins->call( 'opac_detail_xslt_variables', { @@ -234,9 +229,14 @@ my $ean = GetNormalizedEAN( $record, $marcflavour ); $template->param( XSLTBloc => XSLTParse4Display( - $biblionumber, $record, "OPACXSLTDetailsDisplay", 1, undef, - $sysxml, $xslfile, $lang, $variables - ) + { + biblionumber => $biblionumber, + record => $record, + xsl_syspref => 'OPACXSLTDetailsDisplay', + fix_amps => 1, + xslt_variables => $variables + } + ), ); } diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index 90ec38cc40..611baecb02 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -303,11 +303,6 @@ if ( $op eq 'view' ) { $categorycode = $patron ? $patron->categorycode : undef; } - # Lists display falls back to search results configuration - my $xslfile = C4::Context->preference('OPACXSLTListsDisplay') || "default"; - my $lang = C4::Languages::getlanguage(); - my $sysxml = C4::XSLT::get_xslt_sysprefs(); - my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' }); my $art_req_itypes; @@ -374,13 +369,17 @@ if ( $op eq 'view' ) { anonymous_session => ($loggedinuser) ? 0 : 1 }; $this_item->{XSLTBloc} = XSLTParse4Display( - $biblionumber, $record, - "OPACXSLTListsDisplay", 1, - undef, $sysxml, - $xslfile, $lang, - $variables, $items->reset + { + biblionumber => $biblionumber, + record => $record, + xsl_syspref => "OPACXSLTListsDisplay", + fix_amps => 1, + xslt_variables => $variables, + items_rs => $items->reset, + } ); + if ( grep {$_ eq $biblionumber} @cart_list) { $this_item->{incart} = 1; } diff --git a/opac/opac-tags.pl b/opac/opac-tags.pl index e420bee5d6..01479967ba 100755 --- a/opac/opac-tags.pl +++ b/opac/opac-tags.pl @@ -285,19 +285,18 @@ if ($loggedinuser) { # BZ17530: 'Intelligent' guess if result can be article requested $tag->{artreqpossible} = ( $art_req_itypes->{ $tag->{itemtype} // q{} } || $art_req_itypes->{ '*' } ) ? 1 : q{}; - my $xslfile = C4::Context->preference('OPACXSLTResultsDisplay') || "default"; - my $lang = C4::Languages::getlanguage(); - my $sysxml = C4::XSLT::get_xslt_sysprefs(); - my $variables = { anonymous_session => ($loggedinuser) ? 0 : 1 }; $tag->{XSLTBloc} = XSLTParse4Display( - $tag->{biblionumber}, $record, - "OPACXSLTResultsDisplay", 1, - $hidden_items, $sysxml, - $xslfile, $lang, - $variables + { + biblionumber => $tag->{biblionumber}, + record => $record, + xsl_filename => 'OPACXSLTResultsDisplay', + fix_amps => 1, + hidden_items => $hidden_items, + xslt_variables => $variables + } ); my $date = $tag->{date_created} || ''; diff --git a/virtualshelves/shelves.pl b/virtualshelves/shelves.pl index 91f219d105..25f2127b1c 100755 --- a/virtualshelves/shelves.pl +++ b/virtualshelves/shelves.pl @@ -258,18 +258,20 @@ if ( $op eq 'view' ) { } ); - my $xslfile = C4::Context->preference('XSLTListsDisplay'); - my $lang = C4::Languages::getlanguage(); - my $sysxml = C4::XSLT::get_xslt_sysprefs(); - my @items; while ( my $content = $contents->next ) { my $this_item; my $biblionumber = $content->biblionumber; my $record = GetMarcBiblio({ biblionumber => $biblionumber }); - $this_item->{XSLTBloc} = XSLTParse4Display( $biblionumber, $record, "XSLTListsDisplay", - 1, undef, $sysxml, $xslfile, $lang); + $this_item->{XSLTBloc} = XSLTParse4Display( + { + biblionumber => $biblionumber, + record => $record, + xsl_filename => "XSLTListsDisplay", + fix_amps => 1, + } + ); my $marcflavour = C4::Context->preference("marcflavour"); my $itemtype = Koha::Biblioitems->search({ biblionumber => $content->biblionumber })->next->itemtype; -- 2.39.5