From f0e1b7ea60dcdc91693957d820db86573935b5c0 Mon Sep 17 00:00:00 2001 From: David Bourgault Date: Tue, 26 Sep 2017 10:17:06 -0400 Subject: [PATCH] Bug 17385: Add custom export XSLT Rebase Signed-off-by: David Nind --- C4/XSLT.pm | 23 ++++++- basket/basket.pl | 4 ++ basket/downloadcart.pl | 8 ++- catalogue/detail.pl | 3 + catalogue/export.pl | 16 +++++ .../prog/en/includes/cat-toolbar.inc | 3 + .../en/includes/virtualshelves-toolbar.inc | 3 + .../en/modules/admin/preferences/opac.pref | 1 + .../prog/en/modules/basket/basket.tt | 3 + .../prog/en/modules/catalogue/detail.tt | 3 + .../modules/virtualshelves/downloadshelf.tt | 3 + .../biblioexport/MARC21_simple_export.xsl | 62 +++++++++++++++++++ .../en/includes/opac-detail-sidebar.inc | 17 +++-- .../bootstrap/en/modules/opac-downloadcart.tt | 3 + .../en/modules/opac-downloadshelf.tt | 3 + .../biblioexport/MARC21_simple_export.xsl | 62 +++++++++++++++++++ opac/opac-detail.pl | 3 + opac/opac-downloadcart.pl | 10 ++- opac/opac-downloadshelf.pl | 12 +++- opac/opac-export.pl | 10 +++ virtualshelves/downloadshelf.pl | 9 ++- virtualshelves/shelves.pl | 1 + 22 files changed, 247 insertions(+), 15 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/xslt/biblioexport/MARC21_simple_export.xsl create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/xslt/biblioexport/MARC21_simple_export.xsl diff --git a/C4/XSLT.pm b/C4/XSLT.pm index a2d212fe138..de4a3b43de1 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -36,6 +36,10 @@ use Koha::TemplateUtils qw( process_tt ); use Koha::AdditionalContents; use C4::Scrubber; use C4::Languages; +use XML::LibXML; +use Encode; +use vars qw(@ISA @EXPORT); + my $engine; #XSLT Handler object @@ -47,6 +51,7 @@ BEGIN { @EXPORT_OK = qw( buildKohaItemsNamespace XSLTParse4Display + &CustomXSLTExportList ); $engine = Koha::XSLT::Base->new( { do_not_return_source => 1 } ); } @@ -91,7 +96,7 @@ sub _get_best_default_xslt_filename { =head2 get_xslt_sysprefs -Missing POD for get_xslt_sysprefs. + returns XML xslt sysprefs. =cut @@ -141,7 +146,21 @@ sub get_xsl_filename { my $xslfilename = C4::Context->preference($xslsyspref) || "default"; - if ( $xslfilename =~ /^\s*"?default"?\s*$/i ) { + if ($xslsyspref eq "XSLTCustomExport") { + my $dir; + $dir = C4::Context->config('intrahtdocs') . + '/' . C4::Context->preference("template") . + '/' . C4::Languages::getlanguage() . + '/xslt/biblioexport'; + $xslfilename = $dir . "/" . $xslfilename; + } elsif ($xslsyspref eq "OPACXSLTCustomExport") { + my $dir; + $dir = C4::Context->config('opachtdocs') . + '/' . C4::Context->preference("opacthemes") . + '/' . C4::Languages::getlanguage() . + '/xslt/biblioexport'; + $xslfilename = $dir . "/" . $xslfilename; + } elsif ( $xslfilename =~ /^\s*"?default"?\s*$/i ) { my ( $htdocs, $theme, $xslfile ); diff --git a/basket/basket.pl b/basket/basket.pl index 49d98371f4c..48c1ac7a7d0 100755 --- a/basket/basket.pl +++ b/basket/basket.pl @@ -18,6 +18,7 @@ use Modern::Perl; use CGI qw ( -utf8 ); use C4::Koha; + use C4::Biblio qw( GetMarcSeries GetMarcSubjects @@ -25,6 +26,8 @@ use C4::Biblio qw( ); use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); +use C4::XSLT; + use Koha::AuthorisedValues; use Koha::Biblios; @@ -109,6 +112,7 @@ my $resultsarray = \@results; $template->param( BIBLIO_RESULTS => $resultsarray, csv_profiles => Koha::CsvProfiles->search( { type => 'marc', used_for => 'export_records' } ), + xsl_exports => CustomXSLTExportList(), bib_list => $bib_list, ); diff --git a/basket/downloadcart.pl b/basket/downloadcart.pl index 900a5d8b999..1d97271fbc6 100755 --- a/basket/downloadcart.pl +++ b/basket/downloadcart.pl @@ -26,6 +26,7 @@ use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); use C4::Record; use C4::Ris qw( marc2ris ); +use C4::XSLT; use Koha::CsvProfiles; use Koha::Biblios; @@ -77,11 +78,15 @@ if ( $bib_list && $format ) { } elsif ( $format eq 'bibtex' ) { $output .= marc2bibtex( $record, $biblionumber ); } + elsif ($format =~ /^xsl\.(.*)$/) { + $output .= XSLTParse4Display($biblio, $record, 'XSLTCustomExport', 1, undef, , '', $1, ''); + } } } # If it was a CSV export we change the format after the export so the file extension is fine - $format = "csv" if ( $format =~ m/^\d+$/ ); + $format = "csv" if ( $format =~ m/^\d+$/ ); + $format = "html" if ( $format =~ /^xsl\./ ); print $query->header( -type => 'application/octet-stream', @@ -92,6 +97,7 @@ if ( $bib_list && $format ) { } else { $template->param( csv_profiles => Koha::CsvProfiles->search( { type => 'marc', used_for => 'export_records' } ) ); + $template->param( xsl_exports => CustomXSLTExportList() ); $template->param( bib_list => $bib_list ); output_html_with_http_headers $query, $cookie, $template->output; } diff --git a/catalogue/detail.pl b/catalogue/detail.pl index f8a1fe447ec..702a8bf7ccf 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -86,6 +86,9 @@ if ( C4::Context->config('enable_plugins') ) { } my $activetab = $query->param('activetab'); +##### ADD CUSTOM XSLT +$template->param(filesOptions => CustomXSLTExportList(0)); + my $biblionumber = $query->param('biblionumber'); $biblionumber = HTML::Entities::encode($biblionumber); my $biblio = Koha::Biblios->find($biblionumber); diff --git a/catalogue/export.pl b/catalogue/export.pl index a7c77c62f1f..543fdcc07e8 100755 --- a/catalogue/export.pl +++ b/catalogue/export.pl @@ -6,6 +6,8 @@ use C4::Auth qw( get_template_and_user ); use C4::Output; use CGI qw ( -utf8 ); use C4::Ris qw( marc2ris ); +use C4::XSLT; + my $query = CGI->new; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -79,4 +81,18 @@ if ( $op eq "export" ) { ); print $marc; } +} elsif ( $op eq "exportxsl" ) { + my $biblionumber = $query->param("bib"); + if ($biblionumber){ + my $xslFile = $query->param("file"); + my $marc = GetMarcBiblio( { biblionumber => $biblionumber, embed_items => 1 } ); + my $format=$query->param("format")||'txt'; + my @hiddenitems; + + $marc = XSLTParse4Display($biblionumber, $marc, 'XSLTCustomExport', 1, \@hiddenitems, '', $xslFile,''); + print $query->header( + -type => 'application/octet-stream', + -attachment=>"bib-$biblionumber.$format"); + print $marc; + } } diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc index 7b4ac6920fb..02f9a9c21c3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc @@ -189,6 +189,9 @@
  • MARC (Unicode/UTF-8, Standard)
  • MODS (XML)
  • RIS
  • + [% FOREACH filesOption IN filesOptions %] +
  • XSL - [% filesOption.filename | html %]
  • + [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/virtualshelves-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/virtualshelves-toolbar.inc index f50f614dd67..4466f4a48b3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/virtualshelves-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/virtualshelves-toolbar.inc @@ -41,6 +41,9 @@ [% FOREACH csv_profile IN csv_profiles %]
  • CSV - [% csv_profile.profile | html %]
  • [% END %] + [% FOREACH xsl_export IN xsl_exports %] +
  • XSL - [% xsl_export.filename | html %]
  • + [% END %]
    CSV - [% csv_profile.profile | html %] [% END %] + [% FOREACH xsl_export IN xsl_exports %] +
  • XSL - [% xsl_export.filename | html %]
  • + [% END %]
    Print diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index 061b5d39a11..19f93aafbf8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -984,6 +984,9 @@ + [% FOREACH filesOption IN filesOptions %] + + [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/downloadshelf.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/downloadshelf.tt index d0f95844921..b967803b2ab 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/downloadshelf.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/downloadshelf.tt @@ -42,6 +42,9 @@ [% FOREACH csv_profile IN csv_profiles %] [% END %] + [% FOREACH xsl_export IN xsl_exports %] + + [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/xslt/biblioexport/MARC21_simple_export.xsl b/koha-tmpl/intranet-tmpl/prog/en/xslt/biblioexport/MARC21_simple_export.xsl new file mode 100644 index 00000000000..faad19d5215 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/xslt/biblioexport/MARC21_simple_export.xsl @@ -0,0 +1,62 @@ + + + + + + + + + +

    + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + +
    + +
    + + + + + + + + + + + + + +
    +

    +
    + +
    diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc index 03e74f148cf..82e824a827c 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc @@ -94,12 +94,12 @@
    diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadcart.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadcart.tt index 162e2b1be41..3662f18a191 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadcart.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadcart.tt @@ -28,6 +28,9 @@ [% FOREACH csv_profile IN csv_profiles %] [% END %] + [% FOREACH xsl_export IN xsl_exports %] + + [% END %]
    diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt index 2add33da39a..4377d791fd8 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt @@ -71,6 +71,9 @@ [% FOREACH csv_profile IN csv_profiles %] [% END %] + [% FOREACH xsl_export IN xsl_exports %] + + [% END %] Required
    diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/xslt/biblioexport/MARC21_simple_export.xsl b/koha-tmpl/opac-tmpl/bootstrap/en/xslt/biblioexport/MARC21_simple_export.xsl new file mode 100644 index 00000000000..faad19d5215 --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/en/xslt/biblioexport/MARC21_simple_export.xsl @@ -0,0 +1,62 @@ + + + + + + + + + +

    + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + +
    + +
    + + + + + + + + + + + + + +
    +

    +
    + +
    diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 211dac36ea1..fc03382ee0c 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -102,6 +102,9 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( } ); +#### ADD CUSTOM XSLT +$template->param(filesOptions => CustomXSLTExportList(1)); + my $patron = Koha::Patrons->find($borrowernumber); my $biblio = Koha::Biblios->find($biblionumber); diff --git a/opac/opac-downloadcart.pl b/opac/opac-downloadcart.pl index e46dbd99932..446ac5e52ed 100755 --- a/opac/opac-downloadcart.pl +++ b/opac/opac-downloadcart.pl @@ -28,6 +28,8 @@ use C4::Output qw( output_html_with_http_headers ); use C4::Record; use C4::Ris qw( marc2ris ); use Koha::Biblios; +use C4::XSLT; + use Koha::CsvProfiles; use Koha::RecordProcessor; @@ -114,11 +116,15 @@ if ( $bib_list && $format ) { $extension = "txt"; $type = "text/plain"; } + elsif ($format =~ /^xsl\.(.*)$/) { + $output .= XSLTParse4Display($biblio, $record, 'OPACXSLTCustomExport', 1, undef, undef, $1, ''); + } } } # If it was a CSV export we change the format after the export so the file extension is fine - $format = "csv" if ( $format =~ m/^\d+$/ ); + $format = "csv" if ( $format =~ m/^\d+$/ ); + $format = "html" if ( $format =~ /^xsl\./ ); print $query->header( -type => ($type) ? $type : 'application/octet-stream', @@ -138,5 +144,7 @@ if ( $bib_list && $format ) { ), bib_list => $bib_list, ); + $template->param(bib_list => $bib_list); + $template->param(xsl_exports => CustomXSLTExportList()); output_html_with_http_headers $query, $cookie, $template->output; } diff --git a/opac/opac-downloadshelf.pl b/opac/opac-downloadshelf.pl index 0c369381f49..899b84d124a 100755 --- a/opac/opac-downloadshelf.pl +++ b/opac/opac-downloadshelf.pl @@ -27,6 +27,8 @@ use C4::Output qw( output_html_with_http_headers ); use C4::Record; use C4::Ris qw( marc2ris ); use Koha::Biblios; +use C4::XSLT; + use Koha::CsvProfiles; use Koha::RecordProcessor; use Koha::Virtualshelves; @@ -121,13 +123,15 @@ 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); + } } } # If it was a CSV export we change the format after the export so the file extension is fine - $format = "csv" if ( $format =~ m/^\d+$/ ); - + $format = "csv" if ( $format =~ m/^\d+$/ ); + $format = "html" if ( $format =~ /^xsl\./ ); print $query->header( -type => ($type) ? $type : 'application/octet-stream', -'Content-Transfer-Encoding' => 'binary', @@ -153,6 +157,8 @@ if ( $shelf and $shelf->can_be_viewed($borrowernumber) ) { ), shelf => $shelf, ); + $template->param(xsl_exports => CustomXSLTExportList()); + $template->param( shelf => $shelf ); output_html_with_http_headers $query, $cookie, $template->output; } diff --git a/opac/opac-export.pl b/opac/opac-export.pl index e8ef025b5e5..2ed5058b161 100755 --- a/opac/opac-export.pl +++ b/opac/opac-export.pl @@ -30,6 +30,8 @@ use CGI qw ( -utf8 ); use C4::Auth; use C4::Ris qw( marc2ris ); use Koha::Biblios; +use C4::XSLT; + use Koha::RecordProcessor; use List::MoreUtils qw(none any); @@ -151,6 +153,14 @@ if ( $format =~ /endnote/ ) { } ); $format = 'isbd'; +} elsif ($format =~ /html/ ) { + if ($biblionumber){ + my $xslFile = $query->param("file"); + $marc = C4::Biblio::GetMarcBiblio({biblionumber => $biblionumber}); + my @hiddenitems; + + $marc = XSLTParse4Display($biblionumber, $marc, 'OPACXSLTCustomExport', 1, \@hiddenitems, undef, $xslFile, undef); + } } else { $error = "Format $format is not supported."; } diff --git a/virtualshelves/downloadshelf.pl b/virtualshelves/downloadshelf.pl index fbf7ff74996..5fda06b14e6 100755 --- a/virtualshelves/downloadshelf.pl +++ b/virtualshelves/downloadshelf.pl @@ -25,6 +25,8 @@ use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); use C4::Record; use C4::Ris qw( marc2ris ); +use C4::XSLT; + use Koha::Biblios; use Koha::CsvProfiles; @@ -77,12 +79,15 @@ if ( $shelfid && $format ) { } elsif ( $format eq 'bibtex' ) { $output .= marc2bibtex( $record, $biblionumber ); } + elsif ($format =~ /^xsl\.(.*)$/){ + $output .= XSLTParse4Display($biblionumber, $record, 'XSLTCustomExport', 1, undef, ,'',$1,''); + } } } # If it was a CSV export we change the format after the export so the file extension is fine - $format = "csv" if ( $format =~ m/^\d+$/ ); - + $format = "csv" if ( $format =~ m/^\d+$/ ); + $format = "html" if ( $format =~ /^xsl\./ ); print $query->header( -type => 'application/octet-stream', -'Content-Transfer-Encoding' => 'binary', diff --git a/virtualshelves/shelves.pl b/virtualshelves/shelves.pl index f64caf75428..a05e93e5f26 100755 --- a/virtualshelves/shelves.pl +++ b/virtualshelves/shelves.pl @@ -434,6 +434,7 @@ $template->param( csv_profiles => [ Koha::CsvProfiles->search( { type => 'marc', used_for => 'export_records' } )->as_list ], allow_transfer => $allow_transfer, allow_create_public_lists => $allow_create_public_lists, + xsl_exports => CustomXSLTExportList() ); output_html_with_http_headers $query, $cookie, $template->output; -- 2.43.0