Bugzilla – Attachment 146695 Details for
Bug 32680
Add hooks to allow cover images to be provided by plugins
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 32680: (follow-up) Add new plugin hook and reformat data structures
Bug-32680-follow-up-Add-new-plugin-hook-and-reform.patch (text/plain), 17.78 KB, created by
Matt Blenkinsop
on 2023-02-15 15:58:16 UTC
(
hide
)
Description:
Bug 32680: (follow-up) Add new plugin hook and reformat data structures
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2023-02-15 15:58:16 UTC
Size:
17.78 KB
patch
obsolete
>From 5052e0ff3b3a979bb742c6de32ab995a2d0863c8 Mon Sep 17 00:00:00 2001 >From: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >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 > >Sponsored-by: PTFS Europe >--- > 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 @@ > <span class="Z3988" title="[% ocoins | html %]"></span> > [% 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')) ) %] > <div id="catalogue_detail_biblio" class="col-xs-9"> > [% ELSE %] > <div id="catalogue_detail_biblio" class="col-xs-12"> >@@ -204,10 +204,10 @@ > [% END %] > </div> [%# .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')) ) %] > </div> > <div class="col-xs-3 bookcoverimg"> >- <div id="biblio-cover-slider" class="cover-slider cover_images_required"> >+ <div id="biblio-cover-slider" class="cover-slider cover_images_required" data-isbn="[% normalized_isbn | html %]"> > [% 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 ) %] >- <script> >- var normalized_isbn = "[% normalized_isbn %]"; >- </script> >- [% END %] > <script> > var interface = "[% interface | html %]"; > var theme = "[% theme | html %]"; >@@ -2220,5 +2215,8 @@ Note that permanent location is a code, and location may be an authval. > }); > [% END %] > </script> >+ [% 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 @@ > <table> > <thead> > <tr> >- [% IF ( Cover_Images_Required || AmazonCoverImages || LocalCoverImages || ( SyndeticsCovers ) || (Koha.Preference('CustomCoverImages') && Koha.Preference('CustomCoverImagesURL')) ) %] >+ [% IF ( CoverImagesRequired || AmazonCoverImages || LocalCoverImages || ( SyndeticsCovers ) || (Koha.Preference('CustomCoverImages') && Koha.Preference('CustomCoverImagesURL')) ) %] > <th> </th> > [% END %] > <th colspan="2">Results</th> >@@ -461,9 +463,9 @@ > <tbody> > [% FOREACH SEARCH_RESULT IN SEARCH_RESULTS %] > <tr id="row[% SEARCH_RESULT.biblionumber | html %]"> >- [% 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')) ) %] > <td class="bookcoverimg"> >- <div id="cover-slides-[% SEARCH_RESULT.biblionumber | html %]" class="cover-slides search_cover_images_required" data-biblionumber="[% SEARCH_RESULT.biblionumber | html %]"> >+ <div id="cover-slides-[% SEARCH_RESULT.biblionumber | html %]" class="cover-slides cover_images_required" data-biblionumber="[% SEARCH_RESULT.biblionumber | html %]" data-isbn="[% To.json(SEARCH_RESULT.normalized_isbn) | $raw %]" data-processedbiblio="[% PROCESS biblio_a_href biblionumber => SEARCH_RESULT.biblionumber | $raw %]"> > [% IF ( LocalCoverImages ) %][% SEARCH_RESULT.localimage | html %] > <div id="local-coverimg-[% SEARCH_RESULT.biblionumber | html %]" class="cover-image local-coverimg"> > <a href="[% PROCESS biblio_a_href biblionumber => SEARCH_RESULT.biblionumber %]"> >@@ -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 ) %] > <script> > const search_results = {}; > [% FOREACH SEARCH_RESULT IN SEARCH_RESULTS %] >@@ -926,6 +928,7 @@ > [% END %] > </script> > [% 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 @@ > > <div class="bookcover"> > >- <div id="biblio-cover-slider" class="cover-slider cover_images_required"> >+ <div id="biblio-cover-slider" class="cover-slider cover_images_required" data-isbn="[% normalized_isbn | html %]"> > [% IF ( OPACLocalCoverImages ) %] > [% IF localimages.count %] > [% FOREACH image IN localimages %] >@@ -1447,10 +1448,8 @@ > [% Asset.js("js/ratings.js") | $raw %] > [% END %] > >- [% IF ( Cover_Images_Required ) %] >- <script> >- var normalized_isbn = "[% normalized_isbn %]"; >- </script> >+ [% 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 %] > <td class="bibliocol"> >- <div class="coverimages search_cover_images_required itemtype_[% SEARCH_RESULT.itemtype | html %]"> >+ [% IF ( SEARCH_RESULT.title ) %] >+ [% img_title = SEARCH_RESULT.title %] >+ [% ELSE %] >+ [% img_title = SEARCH_RESULT.biblionumber %] >+ [% END %] >+ <div class="coverimages cover_images_required itemtype_[% SEARCH_RESULT.itemtype | html %]" data-isbn="[% To.json(SEARCH_RESULT.normalized_isbn) | $raw %]" data-imgtitle="[% img_title | html %]"> > <a class="p1" href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% SEARCH_RESULT.biblionumber | uri %]"> >- [% IF ( SEARCH_RESULT.title ) %] >- [% img_title = SEARCH_RESULT.title %] >- [% ELSE %] >- [% img_title = SEARCH_RESULT.biblionumber %] >- [% END %] >+ > [% IF ( OPACLocalCoverImages ) %] > <span title="[% img_title | html %]" class="[% SEARCH_RESULT.biblionumber | html %]" id="local-thumbnail[% loop.count | html %]"></span> > [% END %] >@@ -587,20 +590,8 @@ > [% IF OpenLibraryCovers || OpenLibrarySearch %] > [% Asset.js("js/openlibrary.js") | $raw %] > [% END %] >- [% IF ( Cover_Images_Required ) %] >- <script> >- const search_results = {}; >- [% FOREACH SEARCH_RESULT IN SEARCH_RESULTS %] >- var cover_index = "[% loop.count %]"; >- search_results[cover_index] = {}; >- search_results[cover_index].isbn = "[% SEARCH_RESULT.normalized_isbn | html %]"; >- [% IF SEARCH_RESULT.img_title %] >- search_results[cover_index].img_title = "[% SEARCH_RESULT.img_title | html %]"; >- [% ELSE %] >- search_results[cover_index].img_title = "[% SEARCH_RESULT.biblionumber | html %]"; >- [% END %] >- [% END %] >- </script> >+ [% IF ( CoverImagesRequired ) %] >+ [% KohaPlugins.get_plugins_opac_cover_images | $raw %] > [% END %] > <script> > [% IF ( Koha.Preference( 'opacuserlogin' ) == 1 ) && ( Koha.Preference( 'OPACHoldRequests' ) == 1 ) %] >diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl >index 3ff5b91def3..44abb22ccd3 100755 >--- a/opac/opac-detail.pl >+++ b/opac/opac-detail.pl >@@ -83,6 +83,7 @@ use Koha::Serial::Items; > use Koha::SearchEngine::Search; > use Koha::SearchEngine::QueryBuilder; > use Koha::Util::MARC; >+use Koha::Template::Plugin::KohaPlugins; > > use JSON qw( decode_json ); > >@@ -1242,9 +1243,9 @@ if ( C4::Context->preference('OPACAuthorIdentifiers') ) { > $template->param( author_identifiers => \@author_identifiers ); > } > >-my $opac_js_plugins = Koha::Template::Plugin::KohaPlugins->get_plugins_opac_js; >-if(index($opac_js_plugins, "Cover Image Plugin") != -1){ >- $template->param( Cover_Images_Required => 1 ) >+my $opac_cover_images_plugins = Koha::Template::Plugin::KohaPlugins->get_plugins_opac_cover_images; >+if($opac_cover_images_plugins){ >+ $template->param( CoverImagesRequired => 1 ) > } > > output_html_with_http_headers $query, $cookie, $template->output; >diff --git a/opac/opac-search.pl b/opac/opac-search.pl >index 4feba0ad496..7a38fb7a9fc 100755 >--- a/opac/opac-search.pl >+++ b/opac/opac-search.pl >@@ -64,6 +64,7 @@ use Koha::Library::Groups; > use Koha::Patrons; > use Koha::Plugins; > use Koha::SearchFields; >+use Koha::Template::Plugin::KohaPlugins; > > use POSIX qw(ceil floor strftime); > use URI::Escape; >@@ -915,9 +916,9 @@ if ($offset == 0) { > $template->param(firstPage => 1); > } > >-my $opac_js_plugins = Koha::Template::Plugin::KohaPlugins->get_plugins_opac_js; >-if(index($opac_js_plugins, "Cover Image Plugin") != -1){ >- $template->param( Cover_Images_Required => 1 ) >+my $opac_cover_images_plugins = Koha::Template::Plugin::KohaPlugins->get_plugins_opac_cover_images; >+if($opac_cover_images_plugins){ >+ $template->param( CoverImagesRequired => 1 ) > } > > $template->param( borrowernumber => $borrowernumber); >-- >2.37.1 (Apple Git-137.1)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 32680
:
145457
|
145458
|
145459
|
145474
|
145475
|
145898
|
145899
|
146695
|
147992
|
147993
|
147996
|
147997
|
148129
|
148158
|
148159
|
149868
|
149869
|
149886
|
149887
|
149888
|
149889
|
151191
|
151192
|
151193