Bug 22847: Correctly displayed circ rule values for max_holds and maxissue*
[koha.git] / Koha / Template / Plugin / KohaPlugins.pm
1 package Koha::Template::Plugin::KohaPlugins;
2
3 # This file is part of Koha.
4 #
5 # Copyright ByWater Solutions 2018
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use Modern::Perl;
21
22 use base qw( Template::Plugin );
23
24 use Koha::Plugins;
25
26 =head1 NAME
27
28 Koha::Template::Plugin::KohaPlugins - A module for adding hooks into Koha for plugins
29
30 =head1 DESCRIPTION
31
32 This plugin contains functions related to adding plugin hooks into various parts
33 of Koha.
34
35 To use, include the line '[% USE KohaPlugins %]' at the top of the template
36 to enable the plugin
37
38 =head2 Methods
39
40 =head3 get_plugins_opac_head
41
42 [% KohaPlugins.get_plugins_opac_head %]
43
44 This method collects the output of all plugins with an opac_head method
45 to output to the head section of opac pages.
46
47 =cut
48
49 sub get_plugins_opac_head {
50     return q{}
51       unless C4::Context->preference('UseKohaPlugins');
52
53     my $p = Koha::Plugins->new();
54
55     return q{} unless $p;
56
57     my @plugins = $p->GetPlugins(
58         {
59             method => 'opac_head',
60         }
61     );
62
63     my @data = map { $_->opac_head || q{} } @plugins;
64
65     return join( "\n", @data );
66 }
67
68 =head3 get_plugins_opac_js
69
70 [% KohaPlugins.get_plugins_opac_js %]
71
72 This method collects the output of all plugins with an opac_js method
73 to output to the javascript section of at the bottom of opac pages.
74
75 =cut
76
77 sub get_plugins_opac_js {
78     return q{}
79       unless C4::Context->preference('UseKohaPlugins');
80
81     my $p = Koha::Plugins->new();
82
83     return q{} unless $p;
84
85     my @plugins = $p->GetPlugins(
86         {
87             method => 'opac_js',
88         }
89     );
90
91     my @data = map { $_->opac_js || q{} } @plugins;
92
93     return join( "\n", @data );
94 }
95
96 =head3 get_plugins_intranet_head
97
98 [% KohaPlugins.get_plugins_intranet_head %]
99
100 This method collects the output of all plugins with an intranet_head method
101 to output to the head section of intranet pages.
102
103 =cut
104
105 sub get_plugins_intranet_head {
106     return q{}
107       unless C4::Context->preference('UseKohaPlugins');
108
109     my $p = Koha::Plugins->new();
110
111     return q{} unless $p;
112
113     my @plugins = $p->GetPlugins(
114         {
115             method => 'intranet_head',
116         }
117     );
118
119     my @data = map { $_->intranet_head || q{} } @plugins;
120
121     return join( "\n", @data );
122 }
123
124 =head3 get_plugins_intranet_js
125
126 [% KohaPlugins.get_plugins_intranet_js %]
127
128 This method collects the output of all plugins with an intranet_js method
129 to output to the javascript section of at the bottom of intranet pages.
130
131 =cut
132
133 sub get_plugins_intranet_js {
134     return q{}
135       unless C4::Context->preference('UseKohaPlugins');
136
137     my $p = Koha::Plugins->new();
138
139     return q{} unless $p;
140
141     my @plugins = $p->GetPlugins(
142         {
143             method => 'intranet_js',
144         }
145     );
146
147     my @data = map { $_->intranet_js || q{} } @plugins;
148
149     return join( "\n", @data );
150 }
151
152 1;