From 7ea9a3a932118495fb27c7726060c449b6007e52 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 f85017b615..7210f7bcf0 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 b513f7a903..1b3d3ae239 100755 --- a/basket/downloadcart.pl +++ b/basket/downloadcart.pl @@ -81,7 +81,15 @@ if ($bib_list && $format) { $output .= marc2bibtex($record, $biblio); } 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 7dc8e73206..0ca12ea0a8 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 3393d2fc0d..8deb959352 100755 --- a/catalogue/export.pl +++ b/catalogue/export.pl @@ -7,7 +7,7 @@ use C4::Output; use C4::Biblio qw( GetMarcBiblio GetMarcControlnumber ); use CGI qw ( -utf8 ); use C4::Ris qw( marc2ris ); -use C4::XSLT; +use C4::XSLT qw( XSLTParse4Display ); @@ -97,7 +97,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 3b95a6e522..999cfe1396 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -61,7 +61,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 605435e0ef..9912553f85 100755 --- a/opac/opac-downloadcart.pl +++ b/opac/opac-downloadcart.pl @@ -118,7 +118,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 89f2c2dd18..5d04f17a0f 100755 --- a/opac/opac-downloadshelf.pl +++ b/opac/opac-downloadshelf.pl @@ -126,8 +126,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 41bfddceec..a6ae378d5d 100755 --- a/opac/opac-export.pl +++ b/opac/opac-export.pl @@ -144,7 +144,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 4c44bf5661..7ca3c465e1 100755 --- a/virtualshelves/downloadshelf.pl +++ b/virtualshelves/downloadshelf.pl @@ -83,7 +83,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