1 package Koha::Template::Plugin::KohaPlugins;
3 # This file is part of Koha.
5 # Copyright ByWater Solutions 2018
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use base qw( Template::Plugin );
30 Koha::Template::Plugin::KohaPlugins - A module for adding hooks into Koha for plugins
34 This plugin contains functions related to adding plugin hooks into various parts
37 To use, include the line '[% USE KohaPlugins %]' at the top of the template
42 =head3 get_plugins_opac_head
44 [% KohaPlugins.get_plugins_opac_head %]
46 This method collects the output of all plugins with an opac_head method
47 to output to the head section of opac pages.
51 sub get_plugins_opac_head {
52 return q{} unless C4::Context->config("enable_plugins");
54 my $p = Koha::Plugins->new();
58 my @plugins = $p->GetPlugins(
60 method => 'opac_head',
64 my @data = map { $_->opac_head || q{} } @plugins;
66 return join( "\n", @data );
69 =head3 get_plugins_opac_js
71 [% KohaPlugins.get_plugins_opac_js %]
73 This method collects the output of all plugins with an opac_js method
74 to output to the javascript section of at the bottom of opac pages.
78 sub get_plugins_opac_js {
79 return q{} unless C4::Context->config("enable_plugins");
81 my $p = Koha::Plugins->new();
85 my @plugins = $p->GetPlugins(
91 my @data = map { $_->opac_js || q{} } @plugins;
93 return join( "\n", @data );
96 =head3 get_plugins_intranet_head
98 [% KohaPlugins.get_plugins_intranet_head %]
100 This method collects the output of all plugins with an intranet_head method
101 to output to the head section of intranet pages.
105 sub get_plugins_intranet_head {
106 return q{} unless C4::Context->config("enable_plugins");
108 my $p = Koha::Plugins->new();
110 return q{} unless $p;
112 my @plugins = $p->GetPlugins(
114 method => 'intranet_head',
118 my @data = map { $_->intranet_head || q{} } @plugins;
120 return join( "\n", @data );
123 =head3 get_plugins_intranet_js
125 [% KohaPlugins.get_plugins_intranet_js %]
127 This method collects the output of all plugins with an intranet_js method
128 to output to the javascript section of at the bottom of intranet pages.
132 sub get_plugins_intranet_js {
133 return q{} unless C4::Context->config("enable_plugins");
135 my $p = Koha::Plugins->new();
137 return q{} unless $p;
139 my @plugins = $p->GetPlugins(
141 method => 'intranet_js',
145 my @data = map { $_->intranet_js || q{} } @plugins;
147 return join( "\n", @data );
150 =head3 get_plugins_intranet_catalog_biblio_tab
152 [% SET plugins_intranet_catalog_biblio_tabs = KohaPlugins.get_plugins_intranet_catalog_biblio_tab %]
153 [% FOREACH plugins_intranet_catalog_biblio_tab IN plugins_intranet_catalog_biblio_tabs %]
154 <li><a href="#[% plugins_intranet_catalog_biblio_tab.id | uri %]">[% plugins_intranet_catalog_biblio_tab.title | html %]</a></li>
157 This method collects the output of all plugins with a intranet_catalog_biblio_tab
158 method to output to the list of extra cataloguing tabs on intranet pages.
162 sub get_plugins_intranet_catalog_biblio_tab {
166 return $tabs unless C4::Context->config("enable_plugins");
168 my $p = Koha::Plugins->new();
169 return $tabs unless $p;
171 my @plugins = $p->GetPlugins(
173 method => 'intranet_catalog_biblio_tab',
177 foreach my $plugin (@plugins) {
179 my @newtabs = $plugin->intranet_catalog_biblio_tab();
180 foreach my $newtab (@newtabs) {
181 # Add a unique HTML id
182 my $html_id = 'tab-'. $plugin->{class} . '-' . $newtab->title;
183 # Using characters except ASCII letters, digits, '_', '-' and '.' may cause compatibility problems
184 $html_id =~ s/[^0-9A-Za-z]+/-/g;
185 $newtab->id($html_id);
187 push @$tabs, @newtabs;
190 warn "Error calling 'intranet_catalog_biblio_tab' on the " . $plugin->{class} . "plugin ($_)";