From 6328a8f55067692cb1c228931a4e2ec101242d8c Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Fri, 19 Feb 2016 11:02:59 -0500 Subject: [PATCH] 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 --- 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 7fb1073..9923206 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -55,6 +55,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( @@ -92,11 +93,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 @@ -113,7 +118,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 6d71bed..1e37621 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -51,7 +51,7 @@ use C4::Images; use Koha::DateUtils; use C4::HTML5Media; use C4::CourseReserves qw(GetItemCourseReservesInfo); - +use Koha::RecordProcessor; use Koha::Virtualshelves; BEGIN { @@ -85,11 +85,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')) { @@ -516,6 +519,11 @@ if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) { } my $dat = &GetBiblioData($biblionumber); +my $HideMARC = $record_processor->filters->[0]->ShouldHideMARC( + { + frameworkcode => $dat->{'frameworkcode'}, + interface => 'opac', + } ); my $itemtypes = GetItemTypes(); # imageurl: @@ -766,7 +774,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 c4ab83a..3f1948b 100755 --- a/opac/opac-export.pl +++ b/opac/opac-export.pl @@ -27,20 +27,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'; } @@ -57,11 +70,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 786693e..bb4030d 100755 --- a/opac/opac-showmarc.pl +++ b/opac/opac-showmarc.pl @@ -32,6 +32,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'); @@ -39,21 +40,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.1.4