From 6cbae9c3cb0cb3675dc2620e149eace979a78e01 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Fri, 19 Feb 2016 11:02:59 -0500 Subject: [PATCH] Bug 11592: Applying filtering to opac interface. Applying the filtering and then... Debugging opac/opac-detail.pl filtering Debugging opac/opac-ISBDdetail.pl more Debugging opac/opac-export.pl Tweak opac/opac-export.pl fix variable declarations, conditional assignments Debugging opac/opac-showmarc.pl https://bugs.koha-community.org/show_bug.cgi?id=11592 Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall --- opac/opac-ISBDdetail.pl | 11 ++++++++--- opac/opac-detail.pl | 16 +++++++++++++--- opac/opac-export.pl | 28 +++++++++++++++++++++------- opac/opac-showmarc.pl | 21 +++++++++++++++++---- 4 files changed, 59 insertions(+), 17 deletions(-) diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index f325fd3586..d956af284f 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -54,6 +54,7 @@ use C4::Review; use C4::Serials; # uses getsubscriptionfrom biblionumber use C4::Koha; use C4::Members; # GetMember +use Koha::RecordProcessor; my $query = CGI->new(); my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -91,11 +92,15 @@ if (scalar @items >= 1) { } } -my $record = GetMarcBiblio($biblionumber); -if ( ! $record ) { +my $record_unfiltered = GetMarcBiblio($biblionumber); +if ( ! $record_unfiltered ) { print $query->redirect("/cgi-bin/koha/errors/404.pl"); exit; } +my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' }); +my $record_filtered = $record_unfiltered->clone(); +my $record = $record_processor->process($record_filtered); + # some useful variables for enhanced content; # in each case, we're grabbing the first value we find in # the record and normalizing it @@ -112,7 +117,7 @@ $template->param( normalized_ean => $ean, normalized_oclc => $oclc, normalized_isbn => $isbn, - content_identifier_exists => $content_identifier_exists, + content_identifier_exists => $content_identifier_exists, ); #coping with subscriptions diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 98afe3e9f0..b2046a810e 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -50,7 +50,7 @@ use C4::Images; use Koha::DateUtils; use C4::HTML5Media; use C4::CourseReserves qw(GetItemCourseReservesInfo); - +use Koha::RecordProcessor; use Koha::Virtualshelves; BEGIN { @@ -84,11 +84,14 @@ if (scalar @all_items >= 1) { } } -my $record = GetMarcBiblio($biblionumber); -if ( ! $record ) { +my $record_unfiltered = GetMarcBiblio($biblionumber); +if ( ! $record_unfiltered ) { print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early exit; } +my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' }); +my $record_filtered = $record_unfiltered->clone(); +my $record = $record_processor->process($record_filtered); # redirect if opacsuppression is enabled and biblio is suppressed if (C4::Context->preference('OpacSuppression')) { @@ -524,6 +527,11 @@ if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) { } my $dat = &GetBiblioData($biblionumber); +my $HideMARC = $record_processor->filters->[0]->should_hide_marc( + { + frameworkcode => $dat->{'frameworkcode'}, + interface => 'opac', + } ); my $itemtypes = GetItemTypes(); # imageurl: @@ -762,7 +770,9 @@ if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) { ); } +# FIXME: The template uses this hash directly. Need to filter. foreach ( keys %{$dat} ) { + next if ( $HideMARC->{$_} ); $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' ); } diff --git a/opac/opac-export.pl b/opac/opac-export.pl index 3f32d1a8a3..c732e2e6d4 100755 --- a/opac/opac-export.pl +++ b/opac/opac-export.pl @@ -26,20 +26,33 @@ use C4::Biblio; use CGI qw ( -utf8 ); use C4::Auth; use C4::Ris; +use Koha::RecordProcessor; -my $query = new CGI; +my $query = CGI->new; my $op=$query->param("op")||''; #op=export is currently the only use my $format=$query->param("format")||'utf8'; my $biblionumber = $query->param("bib")||0; $biblionumber = int($biblionumber); -my ($marc, $error)= ('',''); +my $error = q{}; -$marc = GetMarcBiblio($biblionumber, 1) if $biblionumber; -if(!$marc) { +my $marc_unfiltered; +$marc_unfiltered = GetMarcBiblio($biblionumber, 1) if $biblionumber; +if(!$marc_unfiltered) { print $query->redirect("/cgi-bin/koha/errors/404.pl"); exit; } -elsif ($format =~ /endnote/) { + +# ASSERT: There is a biblionumber, because GetMarcBiblio returned something. + +my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' }); +my $marc_filtered = $marc_unfiltered->clone(); +my $marc = $record_processor->process($marc_filtered); + +my $marc_noitems_unfiltered = GetMarcBiblio($biblionumber); +my $marc_noitems_filtered = $marc_noitems_unfiltered->clone(); +my $marc_noitems = $record_processor->process($marc_noitems_filtered); + +if ($format =~ /endnote/) { $marc = marc2endnote($marc); $format = 'endnote'; } @@ -56,11 +69,12 @@ elsif ($format =~ /ris/) { $format = 'ris'; } elsif ($format =~ /bibtex/) { - $marc = marc2bibtex(C4::Biblio::GetMarcBiblio($biblionumber),$biblionumber); + $marc = marc2bibtex($marc_noitems,$biblionumber); $format = 'bibtex'; } elsif ($format =~ /dc$/) { - $marc = marc2dcxml(undef, undef, $biblionumber, $format); + # TODO: Dublin Core leaks fields marked hidden by framework. + $marc = marc2dcxml($marc, undef, $biblionumber, $format); $format = "dublin-core.xml"; } elsif ($format =~ /marc8/) { diff --git a/opac/opac-showmarc.pl b/opac/opac-showmarc.pl index c3377277d8..f02ab7cf69 100755 --- a/opac/opac-showmarc.pl +++ b/opac/opac-showmarc.pl @@ -31,6 +31,7 @@ use C4::Biblio; use C4::ImportBatch; use C4::XSLT (); use C4::Templates; +use Koha::RecordProcessor; my $input = new CGI; my $biblionumber = $input->param('id'); @@ -38,21 +39,33 @@ $biblionumber = int($biblionumber); my $importid= $input->param('importid'); my $view= $input->param('viewas') || 'marc'; -my $record; +my $record_unfiltered; if ($importid) { my ($marc) = GetImportRecordMarc($importid); - $record = MARC::Record->new_from_usmarc($marc); + $record_unfiltered = MARC::Record->new_from_usmarc($marc); } else { - $record =GetMarcBiblio($biblionumber); + $record_unfiltered = GetMarcBiblio($biblionumber); } -if(!ref $record) { +if(!ref $record_unfiltered) { print $input->redirect("/cgi-bin/koha/errors/404.pl"); exit; } +my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' }); +my $record_filtered = $record_unfiltered->clone(); +my $record = $record_processor->process($record_filtered); + if ($view eq 'card' || $view eq 'html') { + # FIXME: GetXmlBiblio needs filtering later. my $xml = $importid ? $record->as_xml(): GetXmlBiblio($biblionumber); + if (!$importid && $view eq 'html') { + my $unfiltered_record = MARC::Record->new_from_xml($xml); + my $frameworkcode = GetFrameworkCode($biblionumber); + $record_processor->options({ frameworkcode => $frameworkcode}); + my $filtered_record = $record_processor->process($unfiltered_record); + $xml = $filtered_record->as_xml(); + } my $xsl = $view eq 'card' ? 'compact.xsl' : 'plainMARC.xsl'; my $htdocs = C4::Context->config('opachtdocs'); my ($theme, $lang) = C4::Templates::themelanguage($htdocs, $xsl, 'opac', $input); -- 2.39.5