From 52f781a4e9def4fdb3f4556584b0dac7a98de7d4 Mon Sep 17 00:00:00 2001 From: The Minh Luong Date: Tue, 8 Feb 2022 08:09:15 -0500 Subject: [PATCH] Bug 17385: Add custum export format option when saving a record This patch adds "XSL-Simple Export" when saving a bibliographic record. Previous patches are combined into this one. To test: 1) Search for a record in the intranet. 2) Click on the "Save" button and observe the dropdown menu. 3) Notice that "XSL- Simple Export" is not in the menu. 4) Apply the patch. 5) Repeat the steps 1 and 2. 6) Notice that "XSL - Simple Export" is in the menu. 7) Click on "XSL - Simple Export". A .html file should be downloaded. 8) Open the .html file. You should see the record's informations. --- C4/XSLT.pm | 13 +++++++------ basket/downloadcart.pl | 10 +++++++++- catalogue/detail.pl | 2 +- catalogue/export.pl | 13 +++++++++++-- opac/opac-detail.pl | 2 +- opac/opac-downloadcart.pl | 10 +++++++++- opac/opac-downloadshelf.pl | 12 ++++++++++-- opac/opac-export.pl | 11 ++++++++++- virtualshelves/downloadshelf.pl | 10 +++++++++- 9 files changed, 67 insertions(+), 16 deletions(-) diff --git a/C4/XSLT.pm b/C4/XSLT.pm index c6871002d8..62ad4807fc 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -204,24 +204,24 @@ sub get_xslt_sysprefs { } sub get_xsl_filename { - my ( $xslsyspref ) = @_; + my ( $xslsyspref, $xslfilename ) = @_; my $lang = C4::Languages::getlanguage(); - my $xslfilename = C4::Context->preference($xslsyspref) || "default"; + $xslfilename ||= C4::Context->preference($xslsyspref) || "default"; if ($xslsyspref eq "XSLTCustomExport") { my $dir; $dir = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference("template") . - '/' . C4::Languages::getlanguage() . + '/' . $lang . '/xslt/biblioexport'; $xslfilename = $dir . "/" . $xslfilename; } elsif ($xslsyspref eq "OPACXSLTCustomExport") { my $dir; $dir = C4::Context->config('opachtdocs') . '/' . C4::Context->preference("opacthemes") . - '/' . C4::Languages::getlanguage() . + '/' . $lang . '/xslt/biblioexport'; $xslfilename = $dir . "/" . $xslfilename; } elsif ( $xslfilename =~ /^\s*"?default"?\s*$/i ) { @@ -281,11 +281,12 @@ sub XSLTParse4Display { my $hidden_items = $params->{hidden_items} || []; my $variables = $params->{xslt_variables}; my $items_rs = $params->{items_rs}; + my $xslfilename = $params->{xslfilename}; die "Mandatory \$params->{xsl_syspref} was not provided, called with biblionumber $params->{biblionumber}" if not defined $params->{xsl_syspref}; - my $xslfilename = get_xsl_filename( $xslsyspref); + $xslfilename = get_xsl_filename( $xslsyspref, $xslfilename); # grab the XML, run it through our stylesheet, push it out to the browser my $record = transformMARCXML4XSLT($biblionumber, $orig_record); @@ -298,7 +299,7 @@ sub XSLTParse4Display { my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour')); my $biblio; - my $variables ||= {}; + $variables ||= {}; if (C4::Context->preference('OPACShowOpenURL')) { my @biblio_itemtypes; diff --git a/basket/downloadcart.pl b/basket/downloadcart.pl index 07527e897a..7c0df55bc3 100755 --- a/basket/downloadcart.pl +++ b/basket/downloadcart.pl @@ -80,7 +80,15 @@ if ($bib_list && $format) { $output .= marc2bibtex($record, $biblionumber); } elsif ($format =~ /^xsl\.(.*)$/) { - $output .= XSLTParse4Display($biblio, $record, 'XSLTCustomExport', 1, undef, , '', $1, ''); + $output .= XSLTParse4Display( + { + biblionumber => $biblio, + record => $record, + xsl_syspref => "XSLTCustomExport", + fix_amps => 1, + hidden_items => undef, + } + ); } } } diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 1d050b19ec..bc6bd3889c 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -41,7 +41,7 @@ use C4::XISBN qw( get_xisbns ); use C4::External::Amazon qw( get_amazon_tld ); use C4::Search qw( z3950_search_args enabled_staff_search_views new_record_from_zebra ); use C4::Tags qw( get_tags ); -use C4::XSLT qw( XSLTParse4Display ); +use C4::XSLT qw( XSLTParse4Display CustomXSLTExportList ); use Koha::DateUtils qw( format_sqldatetime ); use C4::HTML5Media; use C4::CourseReserves qw( GetItemCourseReservesInfo ); diff --git a/catalogue/export.pl b/catalogue/export.pl index e023a55e71..541000b037 100755 --- a/catalogue/export.pl +++ b/catalogue/export.pl @@ -7,7 +7,7 @@ use C4::Output; use C4::Biblio qw( GetMarcControlnumber ); use CGI qw ( -utf8 ); use C4::Ris qw( marc2ris ); -use C4::XSLT; +use C4::XSLT qw( XSLTParse4Display ); @@ -96,7 +96,16 @@ if ($op eq "export") { my $format=$query->param("format")||'txt'; my @hiddenitems; - $marc = XSLTParse4Display($biblionumber, $marc, 'XSLTCustomExport', 1, \@hiddenitems, '', $xslFile,''); + $marc = XSLTParse4Display( + { + biblionumber => $biblionumber, + record => $marc, + xsl_syspref => "XSLTCustomExport", + fix_amps => 1, + hidden_items => \@hiddenitems, + xslfilename => $xslFile, + } + ); print $query->header( -type => 'application/octet-stream', -attachment=>"bib-$biblionumber.$format"); diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index f10738b76a..6ea2de54ad 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -60,7 +60,7 @@ use C4::External::Syndetics qw( get_syndetics_toc ); use C4::Members; -use C4::XSLT qw( XSLTParse4Display ); +use C4::XSLT qw( XSLTParse4Display CustomXSLTExportList ); use C4::ShelfBrowser qw( GetNearbyItems ); use C4::Reserves qw( GetReserveStatus ); use C4::Charset qw( SetUTF8Flag ); diff --git a/opac/opac-downloadcart.pl b/opac/opac-downloadcart.pl index e16204c53b..bb6ceece24 100755 --- a/opac/opac-downloadcart.pl +++ b/opac/opac-downloadcart.pl @@ -117,7 +117,15 @@ if ($bib_list && $format) { $type = "text/plain"; } elsif ($format =~ /^xsl\.(.*)$/) { - $output .= XSLTParse4Display($biblio, $record, 'OPACXSLTCustomExport', 1, undef, undef, $1, ''); + $output .= XSLTParse4Display( + { + biblionumber => $biblio, + record => $record, + xsl_syspref => "OPACXSLTCustomExport", + fix_amps => 1, + hidden_items => undef, + } + ); } } } diff --git a/opac/opac-downloadshelf.pl b/opac/opac-downloadshelf.pl index 7090a31734..58b792b4d3 100755 --- a/opac/opac-downloadshelf.pl +++ b/opac/opac-downloadshelf.pl @@ -125,8 +125,16 @@ if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { $extension = "txt"; $type = "text/plain"; }elsif ($format =~ /^xsl\.(.*)$/){ - $output .= XSLTParse4Display($biblionumber, $record, 'XSLTCustomExport', 1, undef, undef, $1, '', 1); - } + $output .= XSLTParse4Display( + { + biblionumber => $biblionumber, + record => $record, + xsl_syspref => "XSLTCustomExport", + fix_amps => 1, + hidden_items => undef, + } + ); + } } } diff --git a/opac/opac-export.pl b/opac/opac-export.pl index 610d5d27e5..f818cd86a4 100755 --- a/opac/opac-export.pl +++ b/opac/opac-export.pl @@ -145,7 +145,16 @@ elsif ($format =~ /html/ ) { $marc = C4::Biblio::GetMarcBiblio({biblionumber => $biblionumber}); my @hiddenitems; - $marc = XSLTParse4Display($biblionumber, $marc, 'OPACXSLTCustomExport', 1, \@hiddenitems, undef, $xslFile, undef); + $marc = XSLTParse4Display( + { + biblionumber => $biblionumber, + record => $marc, + xsl_syspref => "OPACXSLTCustomExport", + fix_amps => 1, + hidden_items => \@hiddenitems, + xslfilename => $xslFile, + } + ); } } else { diff --git a/virtualshelves/downloadshelf.pl b/virtualshelves/downloadshelf.pl index d9939c5cb0..fa2b8b7fc7 100755 --- a/virtualshelves/downloadshelf.pl +++ b/virtualshelves/downloadshelf.pl @@ -82,7 +82,15 @@ if ($shelfid && $format) { $output .= marc2bibtex($record, $biblionumber); } elsif ($format =~ /^xsl\.(.*)$/){ - $output .= XSLTParse4Display($biblionumber, $record, 'XSLTCustomExport', 1, undef, ,'',$1,''); + $output .= XSLTParse4Display( + { + biblionumber => $biblionumber, + record => $record, + xsl_syspref => 'XSLTCustomExport', + fix_amps => 1, + hidden_items => undef, + } + ); } } } -- 2.25.1