From a94a8e15ca9789c36f4c97361990787a2c8991cc Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 24 May 2012 17:50:53 +0200 Subject: [PATCH] Bug 8995: Show OpenURL links in OPAC search results This patch use GetCOinS sub to provide an OpenURL link in OPAC search results. It uses 4 new system preferences: - OpenURLinOPACResults: enable or disable this feature - OpenURLResolverURL: url of the openURL resolver - OpenURLText: text of the link - OpenURLImageLocation: image of the link Link is displayed as an image if OpenURLImageLocation is defined, and as text otherwise. It works both with and without XSLT enabled. Changes are made for UNIMARC and MARC21 xslt. Note: this patch also moves the Babeltheque code outside an if statement "if (C4::Context->preference('COinSinOPACResults'))" (was misplaced because Babeltheque don't need COinS) --- C4/Search.pm | 6 +- C4/XSLT.pm | 14 ++++- installer/data/mysql/sysprefs.sql | 4 ++ installer/data/mysql/updatedatabase.pl | 23 ++++++++ .../prog/en/modules/admin/preferences/opac.pref | 22 +++++++ .../opac-tmpl/prog/en/modules/opac-results.tt | 18 ++++++ .../prog/en/xslt/MARC21slim2OPACResults.xsl | 61 ++++++++++++++++++++ .../prog/en/xslt/UNIMARCslim2OPACResults.xsl | 60 +++++++++++++++++++ opac/opac-search.pl | 51 +++++++++------- 9 files changed, 235 insertions(+), 24 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 3a63fcd..fbb40fc 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1909,7 +1909,11 @@ sub searchResults { warn $marcrecord->as_formatted if $DEBUG; my $interface = $search_context eq 'opac' ? 'OPAC' : ''; if (!$scan && C4::Context->preference($interface . "XSLTResultsDisplay")) { - $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $interface."XSLTResultsDisplay", 1, \@hiddenitems); + my $variables = {}; + if (C4::Context->preference('OpenURLinOPACResults')) { + $variables->{COinS} = C4::Biblio::GetCOinSBiblio($marcrecord); + } + $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $interface."XSLTResultsDisplay", 1, \@hiddenitems, $variables); # the last parameter tells Koha to clean up the problematic ampersand entities that Zebra outputs } diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 19ec162..6db5368 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -137,7 +137,7 @@ sub getAuthorisedValues4MARCSubfields { my $stylesheet; sub XSLTParse4Display { - my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items ) = @_; + my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items, $variables ) = @_; my $xslfilename = C4::Context->preference($xslsyspref); if ( $xslfilename =~ /^\s*"?default"?\s*$/i ) { my $htdocs; @@ -189,14 +189,22 @@ sub XSLTParse4Display { Display856uAsImage OPACDisplay856uAsImage UseControlNumber IntranetBiblioDefaultView BiblioDefaultView singleBranchMode - AlternateHoldingsField AlternateHoldingsSeparator / ) + AlternateHoldingsField AlternateHoldingsSeparator + OpenURLinOPACResults OpenURLResolverURL + OpenURLImageLocation OpenURLText + / ) { my $sp = C4::Context->preference( $syspref ); next unless defined($sp); $sysxml .= "$sp\n"; } $sysxml .= "\n"; - $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml\<\/record\>/; + my $varxml = "\n"; + while (my ($key, $value) = each %$variables) { + $varxml .= "$value\n"; + } + $varxml .= "\n"; + $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml$varxml\<\/record\>/; if ($fixamps) { # We need to correct the ampersand entities that Zebra outputs $xmlrecord =~ s/\&amp;/\&/g; } diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index a4e4102..e4f37a7 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -386,3 +386,7 @@ INSERT INTO systempreferences (variable,value,explanation,type) VALUES('OPACdidy INSERT INTO systempreferences (variable,value,explanation,type) VALUES('INTRAdidyoumean',NULL,'Did you mean? configuration for the Intranet. Do not change, as this is controlled by /cgi-bin/koha/admin/didyoumean.pl.','Free'); INSERT INTO systempreferences (variable, value, options, explanation, type) VALUES ('BlockReturnOfWithdrawnItems', '1', '0', 'If enabled, items that are marked as withdrawn cannot be returned.', 'YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('HoldsToPullStartDate','2','Set the default start date for the Holds to pull list to this many days ago',NULL,'Integer'); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpenURLResolverURL', '', 'URL of OpenURL Resolver', NULL, 'Free'); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpenURLText', '', 'Text of OpenURL links (or image title if OpenURLImageLocation is defined)', NULL, 'Free'); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpenURLImageLocation', '', 'Location of image for OpenURL links', NULL, 'Free'); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpenURLinOPACResults', '', 'Enable display of OpenURL links in OPAC search results', NULL, 'YesNo'); diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 7ab48ee..37e5cec 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -6020,6 +6020,29 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = "XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do(" + INSERT INTO systempreferences (variable,value,explanation,options,type) + VALUES('OpenURLResolverURL', '', 'URL of OpenURL Resolver', NULL, 'Free') + "); + $dbh->do(" + INSERT INTO systempreferences (variable,value,explanation,options,type) + VALUES('OpenURLText', '', 'Text of OpenURL links (or image title if OpenURLImageLocation is defined)', NULL, 'Free'); + "); + $dbh->do(" + INSERT INTO systempreferences (variable,value,explanation,options,type) + VALUES('OpenURLImageLocation', '', 'Location of image for OpenURL links', NULL, 'Free'); + "); + $dbh->do(" + INSERT INTO systempreferences (variable,value,explanation,options,type) + VALUES('OpenURLinOPACResults', '', 'Enable display of OpenURL links in OPAC search results', NULL, 'YesNo'); + "); + print "Upgrade to $DBversion done (Add sysprefs for OpenURL)\n"; + SetVersion($DBversion); +} + + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index 1a9fa09..cf3c7f2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -258,6 +258,28 @@ OPAC: - '
Note: Available options are: BIBTEX (bibtex), Dublin Core (dc),' - 'MARCXML (marcxml), MARC-8 encoded MARC (marc8), Unicode/UTF-8 encoded MARC (utf8),' - 'Unicode/UTF-8 encoded MARC without local use -9xx, x9x, xx9- fields and subfields (marcstd), MODS (mods), RIS (ris)' + - + - 'Complete URL of OpenURL resolver (starting with http:// or https://):' + - pref: OpenURLResolverURL + class: url + - + - 'Text of OpenURL links (or image title if OpenURLImageLocation is defined):' + - pref: OpenURLText + - + - 'Location of image for OpenURL links:' + - pref: OpenURLImageLocation + class: url + - '
Can be a complete URL starting with http:// or' + - 'https:// or the name of a file in images directory' + - '
Examples:' + - '
- http://www.example.com/img/openurl.png' + - '
- OpenURL/OpenURL.png (file is in opac-tmpl/<opacthemes>/images/OpenURL/OpenURL.png)' + - + - pref: OpenURLinOPACResults + choices: + yes: Enable + no: Disable + - 'display of OpenURL link in OPAC search results.' Features: - - pref: opacuserlogin diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt index 53e6e4e..3a1a62a 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt @@ -414,6 +414,13 @@ $(document).ready(function(){ + [%# Build OpenURL image location %] + [% IF (OpenURLImageLocation && !OpenURLImageLocation.match('^https?://')) %] + [% openurlimagelocation = "$interface/$theme/images/$OpenURLImageLocation" %] + [% ELSE %] + [% openurlimagelocation = "$OpenURLImageLocation" %] + [% END %] + [% FOREACH SEARCH_RESULT IN SEARCH_RESULTS %] [% UNLESS ( loop.odd ) %] @@ -469,6 +476,17 @@ $(document).ready(function(){ [% IF ( SEARCH_RESULT.author ) %]by [% SEARCH_RESULT.author %] [% ELSE %]  [% END %] + [% IF (OpenURLinOPACResults && OpenURLResolverURL && SEARCH_RESULT.coins) %] + + [% IF openurlimagelocation %] + + [% ELSIF OpenURLText %] + [% OpenURLText %] + [% ELSE %] + OpenURL + [% END %] + + [% END %] Publication: [% IF ( SEARCH_RESULT.place ) %][% SEARCH_RESULT.place %] [% END %][% IF ( SEARCH_RESULT.publishercode ) %][% SEARCH_RESULT.publishercode|html %][% END %][% IF ( SEARCH_RESULT.publicationyear ) %] [% SEARCH_RESULT.publicationyear %] [% ELSE %][% IF ( SEARCH_RESULT.copyrightdate ) %] [% SEARCH_RESULT.copyrightdate %][% END %][% END %] diff --git a/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl b/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl index 4f0acd3..533c460 100644 --- a/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl +++ b/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl @@ -436,6 +436,67 @@ + + + + + + + + + + + + + + + + OpenURL + + + + + + + + + + + /opac-tmpl/prog/images/ + + + + + +   + + + ? + + + + + + + + + text-decoration:none + + + + + + + vertical-align:middle + + + + + + + + +

diff --git a/koha-tmpl/opac-tmpl/prog/en/xslt/UNIMARCslim2OPACResults.xsl b/koha-tmpl/opac-tmpl/prog/en/xslt/UNIMARCslim2OPACResults.xsl index 2b416fb..683a40e 100644 --- a/koha-tmpl/opac-tmpl/prog/en/xslt/UNIMARCslim2OPACResults.xsl +++ b/koha-tmpl/opac-tmpl/prog/en/xslt/UNIMARCslim2OPACResults.xsl @@ -76,6 +76,66 @@ + + + + + + + + + + + + + + OpenURL + + + + + + + + + + + /opac-tmpl/prog/images/ + + + + + +   + + + ? + + + + + + + + + text-decoration:none + + + + + + + vertical-align:middle + + + + + + + + + + 454 Translation of diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 7677d86..2a5b074 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -459,6 +459,16 @@ if (C4::Context->preference('OpacSuppression')) { } } +# OpenURL +if (C4::Context->preference('OpenURLinOPACResults')) { + $template->param( + OpenURLinOPACResults => 1, + OpenURLResolverURL => C4::Context->preference('OpenURLResolverURL'), + OpenURLText => C4::Context->preference('OpenURLText'), + OpenURLImageLocation => C4::Context->preference('OpenURLImageLocation') + ); +} + $template->param ( LIMIT_INPUTS => \@limit_inputs ); $template->param ( OPACResultsSidebar => C4::Context->preference('OPACResultsSidebar')); @@ -543,6 +553,27 @@ for (my $i=0;$i<@servers;$i++) { if ( grep {$_ eq $line->{'biblionumber'}} @cart_list) { $line->{'incart'} = 1; } + + if (C4::Context->preference('COinSinOPACResults') + or C4::Context->preference('OpenURLinOPACResults')) { + my $record = GetMarcBiblio($line->{'biblionumber'}); + $line->{coins} = GetCOinSBiblio($record); + } + + if ( C4::Context->preference( "Babeltheque" ) and $line->{normalized_isbn} ) { + my $isbn = Business::ISBN->new( $line->{normalized_isbn} ); + next if not $isbn; + $isbn = $isbn->as_isbn13->as_string; + $isbn =~ s/-//g; + my $social_datas = C4::SocialData::get_data( $isbn ); + next if not $social_datas; + for my $key ( keys %$social_datas ) { + $line->{$key} = $$social_datas{$key}; + if ( $key eq 'score_avg' ){ + $line->{score_int} = sprintf("%.0f", $$social_datas{score_avg} ); + } + } + } } @@ -557,26 +588,6 @@ for (my $i=0;$i<@servers;$i++) { } } - if (C4::Context->preference('COinSinOPACResults')) { - foreach (@newresults) { - my $record = GetMarcBiblio($_->{'biblionumber'}); - $_->{coins} = GetCOinSBiblio($record); - if ( C4::Context->preference( "Babeltheque" ) and $_->{normalized_isbn} ) { - my $isbn = Business::ISBN->new( $_->{normalized_isbn} ); - next if not $isbn; - $isbn = $isbn->as_isbn13->as_string; - $isbn =~ s/-//g; - my $social_datas = C4::SocialData::get_data( $isbn ); - next if not $social_datas; - for my $key ( keys %$social_datas ) { - $_->{$key} = $$social_datas{$key}; - if ( $key eq 'score_avg' ){ - $_->{score_int} = sprintf("%.0f", $$social_datas{score_avg} ); - } - } - } - } - } if ( C4::Context->preference('OpacStarRatings') eq 'all' ) { -- 1.7.10.4