Main Koha release repository https://koha-community.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

149 lines
3.3 KiB

  1. package Koha::Template::Plugin::KohaPlugins;
  2. # This file is part of Koha.
  3. #
  4. # Copyright ByWater Solutions 2018
  5. #
  6. # Koha is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # Koha is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Koha; if not, see <http://www.gnu.org/licenses>.
  18. use Modern::Perl;
  19. use base qw( Template::Plugin );
  20. use Koha::Plugins;
  21. =head1 NAME
  22. Koha::Template::Plugin::KohaPlugins - A module for adding hooks into Koha for plugins
  23. =head1 DESCRIPTION
  24. This plugin contains functions related to adding plugin hooks into various parts
  25. of Koha.
  26. To use, include the line '[% USE KohaPlugins %]' at the top of the template
  27. to enable the plugin
  28. =head2 Methods
  29. =head3 get_plugins_opac_head
  30. [% KohaPlugins.get_plugins_opac_head %]
  31. This method collects the output of all plugins with an opac_head method
  32. to output to the head section of opac pages.
  33. =cut
  34. sub get_plugins_opac_head {
  35. return q{} unless C4::Context->config("enable_plugins");
  36. my $p = Koha::Plugins->new();
  37. return q{} unless $p;
  38. my @plugins = $p->GetPlugins(
  39. {
  40. method => 'opac_head',
  41. }
  42. );
  43. my @data = map { $_->opac_head || q{} } @plugins;
  44. return join( "\n", @data );
  45. }
  46. =head3 get_plugins_opac_js
  47. [% KohaPlugins.get_plugins_opac_js %]
  48. This method collects the output of all plugins with an opac_js method
  49. to output to the javascript section of at the bottom of opac pages.
  50. =cut
  51. sub get_plugins_opac_js {
  52. return q{} unless C4::Context->config("enable_plugins");
  53. my $p = Koha::Plugins->new();
  54. return q{} unless $p;
  55. my @plugins = $p->GetPlugins(
  56. {
  57. method => 'opac_js',
  58. }
  59. );
  60. my @data = map { $_->opac_js || q{} } @plugins;
  61. return join( "\n", @data );
  62. }
  63. =head3 get_plugins_intranet_head
  64. [% KohaPlugins.get_plugins_intranet_head %]
  65. This method collects the output of all plugins with an intranet_head method
  66. to output to the head section of intranet pages.
  67. =cut
  68. sub get_plugins_intranet_head {
  69. return q{} unless C4::Context->config("enable_plugins");
  70. my $p = Koha::Plugins->new();
  71. return q{} unless $p;
  72. my @plugins = $p->GetPlugins(
  73. {
  74. method => 'intranet_head',
  75. }
  76. );
  77. my @data = map { $_->intranet_head || q{} } @plugins;
  78. return join( "\n", @data );
  79. }
  80. =head3 get_plugins_intranet_js
  81. [% KohaPlugins.get_plugins_intranet_js %]
  82. This method collects the output of all plugins with an intranet_js method
  83. to output to the javascript section of at the bottom of intranet pages.
  84. =cut
  85. sub get_plugins_intranet_js {
  86. return q{} unless C4::Context->config("enable_plugins");
  87. my $p = Koha::Plugins->new();
  88. return q{} unless $p;
  89. my @plugins = $p->GetPlugins(
  90. {
  91. method => 'intranet_js',
  92. }
  93. );
  94. my @data = map { $_->intranet_js || q{} } @plugins;
  95. return join( "\n", @data );
  96. }
  97. 1;