Main Koha release repository https://koha-community.org
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

134 рядки
5.0 KiB

  1. #!/usr/bin/perl
  2. # Copyright 2010 Kyle M Hall <kyle.m.hall@gmail.com>
  3. #
  4. # This file is part of Koha.
  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 CGI qw ( -utf8 );
  20. use JSON qw(from_json);
  21. use LWP::Simple qw(get);
  22. use Koha::Plugins;
  23. use C4::Auth;
  24. use C4::Output;
  25. use C4::Debug;
  26. use C4::Context;
  27. my $plugins_enabled = C4::Context->config("enable_plugins");
  28. my $input = CGI->new;
  29. my $method = $input->param('method');
  30. my $plugin_search = $input->param('plugin-search');
  31. my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
  32. { template_name => ($plugins_enabled) ? "plugins/plugins-home.tt" : "plugins/plugins-disabled.tt",
  33. query => $input,
  34. type => "intranet",
  35. flagsrequired => { plugins => '*' },
  36. debug => 1,
  37. }
  38. );
  39. if ($plugins_enabled) {
  40. $template->param(
  41. koha_version => C4::Context->preference("Version"),
  42. method => $method,
  43. );
  44. my @plugins = Koha::Plugins->new()->GetPlugins(
  45. {
  46. method => $method,
  47. all => 1,
  48. errors => 1
  49. }
  50. );
  51. $template->param( plugins => \@plugins, );
  52. $template->param( can_search => C4::Context->config('plugin_repos') ? 1 : 0 );
  53. my @results;
  54. if ($plugin_search) {
  55. my $repos = C4::Context->config('plugin_repos');
  56. # Fix data structure if only one repo defined
  57. if ( ref($repos->{repo}) eq 'HASH' ) {
  58. $repos = { repo => [ $repos->{repo} ] };
  59. }
  60. foreach my $r ( @{ $repos->{repo} } ) {
  61. if ( $r->{service} eq 'github' ) {
  62. my $url = "https://api.github.com/search/repositories?q=$plugin_search+user:$r->{org_name}+in:name,description";
  63. my $response = from_json( get($url) );
  64. foreach my $result ( @{ $response->{items} } ) {
  65. next unless $result->{name} =~ /^koha-plugin-/;
  66. my $releases = $result->{url} . "/releases/latest";
  67. my $release = from_json( get($releases) );
  68. for my $asset ( @{$release->{assets}} ) {
  69. if ($asset->{browser_download_url} =~ m/\.kpz$/) {
  70. $result->{install_name} = $asset->{name};
  71. $result->{install_url} = $asset->{browser_download_url};
  72. }
  73. }
  74. push( @results, { repo => $r, result => $result } );
  75. }
  76. }
  77. elsif ( $r->{service} eq 'gitlab' ) {
  78. my $org_name = $r->{org_name};
  79. my $url = "https://gitlab.com/api/v4/groups/$org_name/projects?with_issues_enabled=no\&with_merge_requests_enabled=no\&with_shared=no\&include_subgroups=yes\&search=koha-plugin+$plugin_search";
  80. my $response = from_json( get($url) );
  81. foreach my $result ( @{ $response } ) {
  82. next unless $result->{name} =~ /^koha-plugin-/;
  83. my $project_id = $result->{id};
  84. my $description = $result->{description} // '';
  85. my $web_url = $result->{web_url};
  86. my $releases_url = "https://gitlab.com/api/v4/projects/$project_id/releases";
  87. my @releases = @{ from_json( get($releases_url) ) };
  88. if ( scalar @releases > 0 ) {
  89. # Pick the first one, the latest release
  90. my $latest = $releases[0];
  91. my $name = $latest->{name};
  92. my @links = @{$latest->{assets}->{links}};
  93. my $url = $links[0]->{direct_asset_url};
  94. my @parts = split( '/', $url);
  95. my $filename = $parts[-1];
  96. next unless $url =~ m/\.kpz$/;
  97. my $result = {
  98. description => $description,
  99. install_name => $filename,
  100. install_url => $url,
  101. html_url => $web_url,
  102. name => $name,
  103. };
  104. push @results, { repo => $r, result => $result };
  105. }
  106. }
  107. }
  108. }
  109. $template->param(
  110. search_results => \@results,
  111. search_term => $plugin_search,
  112. );
  113. }
  114. }
  115. output_html_with_http_headers( $input, $cookie, $template->output );