From 53c98f4e592fe68bc0a4c0e062d5617b5339b4f5 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Mon, 30 Jan 2023 17:18:29 +0000 Subject: [PATCH] Bug 32680: (follow-up) Add new plugin hook and reformat data structures This patch adds two new plugin hooks to add cover images and adds data tags to the templates to provide the isbn numbers for this Test plan: 1) Apply patch 2) Go to https://github.com/PTFS-Europe/koha-plugin-addBDSCovers 3) In the releases section, download the .kpz file 4) Upload this in the plugins section and enable the plugin 5) In either the OPAC or staff client, search the catalog 6) The results should have cover art from BDS covers 7) Click on a result and the detail page should also have the cover art --- Koha/Template/Plugin/KohaPlugins.pm | 52 +++++++++++++++++++ catalogue/detail.pl | 7 +-- catalogue/search.pl | 7 +-- .../prog/en/modules/catalogue/detail.tt | 14 +++-- .../prog/en/modules/catalogue/results.tt | 11 ++-- .../bootstrap/en/modules/opac-detail.tt | 9 ++-- .../bootstrap/en/modules/opac-results.tt | 31 ++++------- opac/opac-detail.pl | 7 +-- opac/opac-search.pl | 7 +-- 9 files changed, 96 insertions(+), 49 deletions(-) diff --git a/Koha/Template/Plugin/KohaPlugins.pm b/Koha/Template/Plugin/KohaPlugins.pm index d313f731266..db13621651e 100644 --- a/Koha/Template/Plugin/KohaPlugins.pm +++ b/Koha/Template/Plugin/KohaPlugins.pm @@ -194,4 +194,56 @@ sub get_plugins_intranet_catalog_biblio_tab { return $tabs; } +=head3 get_plugins_intranet_cover_images + +[% KohaPlugins. get_plugins_intranet_cover_images %] + +This method collects the output of all plugins for injecting cover images into the intranet template and appends it to the javascript at the bottom of the page. + +=cut + +sub get_plugins_intranet_cover_images { + return q{} unless C4::Context->config("enable_plugins"); + + my $p = Koha::Plugins->new(); + + return q{} unless $p; + + my @plugins = $p->GetPlugins( + { + method => 'intranet_cover_images', + } + ); + + my @data = map { $_->intranet_cover_images || q{} } @plugins; + + return join( "\n", @data ); +} + +=head3 get_plugins_opac_cover_images + +[% KohaPlugins. get_plugins_opac_cover_images %] + +This method collects the output of all plugins for injecting cover images into the opac template and appends it to the javascript at the bottom of the page. + +=cut + +sub get_plugins_opac_cover_images { + return q{} unless C4::Context->config("enable_plugins"); + + my $p = Koha::Plugins->new(); + + return q{} unless $p; + + my @plugins = $p->GetPlugins( + { + method => 'opac_cover_images', + } + ); + + my @data = map { $_->opac_cover_images || q{} } @plugins; + + return join( "\n", @data ); +} + 1; diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 99bfc5779c6..422e59d2677 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -60,6 +60,7 @@ use Koha::Recalls; use Koha::SearchEngine::Search; use Koha::SearchEngine::QueryBuilder; use Koha::Serial::Items; +use Koha::Template::Plugin::KohaPlugins; my $query = CGI->new(); @@ -684,9 +685,9 @@ $template->param(found1 => scalar $query->param('found1') ); $template->param(biblio => $biblio); -my $intranet_js_plugins = Koha::Template::Plugin::KohaPlugins->get_plugins_intranet_js; -if(index($intranet_js_plugins, "Cover Image Plugin") != -1){ - $template->param( Cover_Images_Required => 1 ) +my $intranet_cover_images_plugins = Koha::Template::Plugin::KohaPlugins->get_plugins_intranet_cover_images; +if($intranet_cover_images_plugins){ + $template->param( CoverImagesRequired => 1 ) } output_html_with_http_headers $query, $cookie, $template->output; diff --git a/catalogue/search.pl b/catalogue/search.pl index 68e75eba490..d288de78108 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -158,6 +158,7 @@ use Koha::SearchEngine::QueryBuilder; use Koha::Virtualshelves; use Koha::SearchFields; use Koha::SearchFilters; +use Koha::Template::Plugin::KohaPlugins; use URI::Escape; use JSON qw( decode_json encode_json ); @@ -779,9 +780,9 @@ my $some_public_shelves = Koha::Virtualshelves->get_some_shelves( } ); -my $intranet_js_plugins = Koha::Template::Plugin::KohaPlugins->get_plugins_intranet_js; -if(index($intranet_js_plugins, "Cover Image Plugin") != -1){ - $template->param( Cover_Images_Required => 1 ) +my $intranet_cover_images_plugins = Koha::Template::Plugin::KohaPlugins->get_plugins_intranet_cover_images; +if($intranet_cover_images_plugins){ + $template->param( CoverImagesRequired => 1 ) } 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 971cda0a478..336ffb692e4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -114,7 +114,7 @@ [% END %] - [% IF ( Cover_Images_Required || AmazonCoverImages || LocalCoverImages || IntranetCoce || ( SyndeticsCovers ) || (Koha.Preference('CustomCoverImages') && Koha.Preference('CustomCoverImagesURL')) ) %] + [% IF ( CoverImagesRequired || AmazonCoverImages || LocalCoverImages || IntranetCoce || ( SyndeticsCovers ) || (Koha.Preference('CustomCoverImages') && Koha.Preference('CustomCoverImagesURL')) ) %]
[% ELSE %]
@@ -204,10 +204,10 @@ [% END %]
[%# .page-section %] - [% IF ( Cover_Images_Required || AmazonCoverImages || LocalCoverImages || IntranetCoce || ( SyndeticsCovers ) || (Koha.Preference('CustomCoverImages') && Koha.Preference('CustomCoverImagesURL')) ) %] + [% IF ( CoverImagesRequired || AmazonCoverImages || LocalCoverImages || IntranetCoce || ( SyndeticsCovers ) || (Koha.Preference('CustomCoverImages') && Koha.Preference('CustomCoverImagesURL')) ) %]
-
+
[% IF ( LocalCoverImages ) %] [% IF localimages.count %] [% FOREACH image IN localimages %] @@ -1310,11 +1310,6 @@ Note that permanent location is a code, and location may be an authval. [% Asset.js("js/recalls.js") | $raw %] [% Asset.js("js/coce.js") | $raw %] [% Asset.js("lib/Chocolat/js/chocolat.js") | $raw %] - [% IF ( Cover_Images_Required ) %] - - [% END %] + [% IF ( CoverImagesRequired ) %] + [% KohaPlugins.get_plugins_intranet_cover_images | $raw %] + [% END %] [% END %] [% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt index eb61a12dcd1..93c008aa6c6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt @@ -4,6 +4,8 @@ [% USE Koha %] [% USE Biblio %] [% USE KohaDates %] +[% USE KohaPlugins %] +[% USE To %] [% PROCESS 'i18n.inc' %] [% SET footerjs = 1 %] [% USE AuthorisedValues %] @@ -449,7 +451,7 @@ - [% IF ( Cover_Images_Required || AmazonCoverImages || LocalCoverImages || ( SyndeticsCovers ) || (Koha.Preference('CustomCoverImages') && Koha.Preference('CustomCoverImagesURL')) ) %] + [% IF ( CoverImagesRequired || AmazonCoverImages || LocalCoverImages || ( SyndeticsCovers ) || (Koha.Preference('CustomCoverImages') && Koha.Preference('CustomCoverImagesURL')) ) %] [% END %] @@ -461,9 +463,9 @@ [% FOREACH SEARCH_RESULT IN SEARCH_RESULTS %] - [% IF ( Cover_Images_Required || AmazonCoverImages || LocalCoverImages || IntranetCoce || ( SyndeticsCovers ) || (Koha.Preference('CustomCoverImages') && Koha.Preference('CustomCoverImagesURL')) ) %] + [% IF ( CoverImagesRequired || AmazonCoverImages || LocalCoverImages || IntranetCoce || ( SyndeticsCovers ) || (Koha.Preference('CustomCoverImages') && Koha.Preference('CustomCoverImagesURL')) ) %]
 Results
-
+
[% IF ( LocalCoverImages ) %][% SEARCH_RESULT.localimage | html %]
@@ -781,7 +783,7 @@ [% Asset.css("css/humanmsg.css") | $raw %] [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %] [% INCLUDE 'select2.inc' %] - [% IF ( Cover_Images_Required ) %] + [% IF ( CoverImagesRequired ) %] [% Asset.js("js/pages/results.js") | $raw %] + [% KohaPlugins.get_plugins_intranet_cover_images | $raw %] [% END %] [% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt index 055037a4e6d..da4e5cbecb4 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt @@ -6,6 +6,7 @@ [% USE Branches %] [% USE TablesSettings %] [% USE AuthorisedValues %] +[% USE KohaPlugins %] [% SET TagsShowEnabled = ( ( Koha.Preference( 'TagsEnabled' ) == 1 ) && TagsShowOnDetail ) %] [% SET TagsInputEnabled = ( ( Koha.Preference( 'opacuserlogin' ) == 1 ) && ( Koha.Preference( 'TagsEnabled' ) == 1 ) && TagsInputOnDetail ) %] [% IF Koha.Preference('AmazonAssocTag') %] @@ -59,7 +60,7 @@
-
+
[% IF ( OPACLocalCoverImages ) %] [% IF localimages.count %] [% FOREACH image IN localimages %] @@ -1447,10 +1448,8 @@ [% Asset.js("js/ratings.js") | $raw %] [% END %] - [% IF ( Cover_Images_Required ) %] - + [% IF ( CoverImagesRequired ) %] + [% KohaPlugins.get_plugins_opac_cover_images | $raw %] [% END %] [% IF ( OpacHighlightedWords ) %][% Asset.js("lib/jquery/plugins/jquery.highlight-3.js") | $raw %][% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt index da5284f5ccb..1f74ca18432 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt @@ -1,6 +1,8 @@ [% USE raw %] [% USE Asset %] [% USE Koha %] +[% USE KohaPlugins %] +[% USE To %] [% SET TagsShowEnabled = ( ( Koha.Preference( 'TagsEnabled' ) == 1 ) && TagsShowOnList ) %] [% SET TagsInputEnabled = ( ( Koha.Preference( 'opacuserlogin' ) == 1 ) && ( Koha.Preference( 'TagsEnabled' ) == 1 ) && TagsInputOnList ) %] @@ -341,13 +343,14 @@ [% # Cell 4: Search result details and controls %]
-
+ [% IF ( SEARCH_RESULT.title ) %] + [% img_title = SEARCH_RESULT.title %] + [% ELSE %] + [% img_title = SEARCH_RESULT.biblionumber %] + [% END %] +
- [% IF ( SEARCH_RESULT.title ) %] - [% img_title = SEARCH_RESULT.title %] - [% ELSE %] - [% img_title = SEARCH_RESULT.biblionumber %] - [% END %] + [% IF ( OPACLocalCoverImages ) %] [% END %] @@ -587,20 +590,8 @@ [% IF OpenLibraryCovers || OpenLibrarySearch %] [% Asset.js("js/openlibrary.js") | $raw %] [% END %] - [% IF ( Cover_Images_Required ) %] - + [% IF ( CoverImagesRequired ) %] + [% KohaPlugins.get_plugins_opac_cover_images | $raw %] [% END %]