From 300ea0d68f6aaaad913211b15a10d1391dc40542 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 12 Feb 2018 09:09:20 -0500 Subject: [PATCH] Bug 20181: Allow plugins to add css and javascript to OPAC A number of Koha plugins have been written that enhance Koha's public catalog. These plugins often make due to adding css and javascript to the various opac system preferences. It would be nice if the plugin system had hooks so plugin developers could add code the the head block and the area where we include javascript in the opac template. Test Plan: 1) Apply this patch 2) Download and install the Kitchen Sink plugin ( v2.1.12 or later ) https://github.com/bywatersolutions/koha-plugin-kitchen-sink/releases/download/v2.1.12/koha-plugin-kitchen-sink-v2.1.12.kpz 3) Install the plugin 4) Restart all the things if you can ( restart_all if you are using kohadevbox ) This will ensure the plugin takes effect right away, it should be necessary but it won't hurt anything! 5) Load the opac, notice you get an alert message and the background for your opac is now orange ( assuming you've not customized the opac in any way ) Signed-off-by: Mark Tompsett Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart (cherry picked from commit e8fbe51ff33760b0446339b44047229be9e9f1a8) Signed-off-by: Fridolin Somers --- Koha/Template/Plugin/KohaPlugins.pm | 58 +++++++++++++++++++ .../bootstrap/en/includes/doc-head-close.inc | 2 + .../bootstrap/en/includes/opac-bottom.inc | 2 + 3 files changed, 62 insertions(+) create mode 100644 Koha/Template/Plugin/KohaPlugins.pm diff --git a/Koha/Template/Plugin/KohaPlugins.pm b/Koha/Template/Plugin/KohaPlugins.pm new file mode 100644 index 0000000000..a2b9e2997b --- /dev/null +++ b/Koha/Template/Plugin/KohaPlugins.pm @@ -0,0 +1,58 @@ +package Koha::Template::Plugin::KohaPlugins; + +# This file is part of Koha. +# +# Copyright ByWater Solutions 2018 +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use base qw( Template::Plugin ); + +use Koha::Plugins; + +sub get_plugins_opac_head { + return q{} + unless C4::Context->preference('UseKohaPlugins') + && C4::Context->config("enable_plugins"); + + my @plugins = Koha::Plugins->new()->GetPlugins( + { + method => 'opac_head', + } + ); + + my @data = map { $_->opac_head || q{} } @plugins; + + return join( "\n", @data ); +} + +sub get_plugins_opac_js { + return q{} + unless C4::Context->preference('UseKohaPlugins') + && C4::Context->config("enable_plugins"); + + my @plugins = Koha::Plugins->new()->GetPlugins( + { + method => 'opac_js', + } + ); + + my @data = map { $_->opac_js || q{} } @plugins; + + return join( "\n", @data ); +} + +1; diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/doc-head-close.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/doc-head-close.inc index 111700e63d..2964daeed1 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/doc-head-close.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/doc-head-close.inc @@ -1,3 +1,4 @@ +[%- USE KohaPlugins -%] @@ -53,3 +54,4 @@ [% PROCESS 'html_helpers.inc' %] +[% KohaPlugins.get_plugins_opac_head %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc index e717b391dc..a9e77726a9 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc @@ -1,3 +1,4 @@ +[%- USE KohaPlugins -%] [% UNLESS ( is_popup ) %] [% SET OpacLangSelectorMode = Koha.Preference('OpacLangSelectorMode') %] [% IF ( opaccredits ) %] @@ -271,5 +272,6 @@ $(document).ready(function() { [% END %] [% END %] +[% KohaPlugins.get_plugins_opac_js %] -- 2.39.5