View | Details | Raw Unified | Return to bug 7804
Collapse All | Expand All

(-)a/C4/Auth.pm (-1 / +3 lines)
Lines 133-139 EOQ Link Here
133
sub get_template_and_user {
133
sub get_template_and_user {
134
    my $in       = shift;
134
    my $in       = shift;
135
    my $template =
135
    my $template =
136
      C4::Templates::gettemplate( $in->{'template_name'}, $in->{'type'}, $in->{'query'} );
136
      C4::Templates::gettemplate( $in->{'template_name'}, $in->{'type'}, $in->{'query'}, $in->{'is_plugin'} );
137
    my ( $user, $cookie, $sessionID, $flags );
137
    my ( $user, $cookie, $sessionID, $flags );
138
    if ( $in->{'template_name'} !~m/maintenance/ ) {
138
    if ( $in->{'template_name'} !~m/maintenance/ ) {
139
        ( $user, $cookie, $sessionID, $flags ) = checkauth(
139
        ( $user, $cookie, $sessionID, $flags ) = checkauth(
Lines 203-208 sub get_template_and_user { Link Here
203
            $template->param( CAN_user_serials          => 1 );
203
            $template->param( CAN_user_serials          => 1 );
204
            $template->param( CAN_user_reports          => 1 );
204
            $template->param( CAN_user_reports          => 1 );
205
            $template->param( CAN_user_staffaccess      => 1 );
205
            $template->param( CAN_user_staffaccess      => 1 );
206
            $template->param( CAN_user_plugins          => 1 );
206
            foreach my $module (keys %$all_perms) {
207
            foreach my $module (keys %$all_perms) {
207
                foreach my $subperm (keys %{ $all_perms->{$module} }) {
208
                foreach my $subperm (keys %{ $all_perms->{$module} }) {
208
                    $template->param( "CAN_user_${module}_${subperm}" => 1 );
209
                    $template->param( "CAN_user_${module}_${subperm}" => 1 );
Lines 368-373 sub get_template_and_user { Link Here
368
            OPACLocalCoverImages        => C4::Context->preference('OPACLocalCoverImages'),
369
            OPACLocalCoverImages        => C4::Context->preference('OPACLocalCoverImages'),
369
            AllowMultipleCovers         => C4::Context->preference('AllowMultipleCovers'),
370
            AllowMultipleCovers         => C4::Context->preference('AllowMultipleCovers'),
370
            EnableBorrowerFiles         => C4::Context->preference('EnableBorrowerFiles'),
371
            EnableBorrowerFiles         => C4::Context->preference('EnableBorrowerFiles'),
372
            UseKohaPlugins              => C4::Context->preference('UseKohaPlugins'),
371
        );
373
        );
372
    }
374
    }
373
    else {
375
    else {
(-)a/C4/Installer/PerlDependencies.pm (+40 lines)
Lines 634-639 our $PERL_DEPS = { Link Here
634
        'required' => '1',
634
        'required' => '1',
635
        'min_ver'  => '0.22',
635
        'min_ver'  => '0.22',
636
    },
636
    },
637
    'File::Temp' => {
638
        'usage'    => 'Plugins',
639
        'required' => '0',
640
        'min_ver'  => '0.22',
641
    },
642
    'File::Copy' => {
643
        'usage'    => 'Plugins',
644
        'required' => '0',
645
        'min_ver'  => '2.08',
646
    },
647
    'File::Path' => {
648
        'usage'    => 'Plugins',
649
        'required' => '0',
650
        'min_ver'  => '2.07',
651
    },
652
    'Archive::Extract' => {
653
        'usage'    => 'Plugins',
654
        'required' => '0',
655
        'min_ver'  => '0.60',
656
    },
657
    'Archive::Zip' => {
658
        'usage'    => 'Plugins',
659
        'required' => '0',
660
        'min_ver'  => '1.30',
661
    },
662
    'Module::Load::Conditional' => {
663
        'usage'    => 'Plugins',
664
        'required' => '0',
665
        'min_ver'  => '0.38',
666
    },
667
    'Module::Bundled::Files' => {
668
        'usage'    => 'Plugins',
669
        'required' => '0',
670
        'min_ver'  => '0.03',
671
    },
672
    'Module::Pluggable' => {
673
        'usage'    => 'Plugins',
674
        'required' => '0',
675
        'min_ver'  => '3.9',
676
    },
637
};
677
};
638
678
639
1;
679
1;
(-)a/C4/Templates.pm (-1 / +3 lines)
Lines 228-240 sub _get_template_file { Link Here
228
228
229
229
230
sub gettemplate {
230
sub gettemplate {
231
    my ( $tmplbase, $interface, $query ) = @_;
231
    my ( $tmplbase, $interface, $query, $is_plugin ) = @_;
232
    ($query) or warn "no query in gettemplate";
232
    ($query) or warn "no query in gettemplate";
233
    my $path = C4::Context->preference('intranet_includes') || 'includes';
233
    my $path = C4::Context->preference('intranet_includes') || 'includes';
234
    $tmplbase =~ s/\.tmpl$/.tt/;
234
    $tmplbase =~ s/\.tmpl$/.tt/;
235
    my ($htdocs, $theme, $lang, $filename)
235
    my ($htdocs, $theme, $lang, $filename)
236
       =  _get_template_file($tmplbase, $interface, $query);
236
       =  _get_template_file($tmplbase, $interface, $query);
237
    $filename = $tmplbase if ( $is_plugin );
237
    my $template = C4::Templates->new($interface, $filename, $tmplbase, $query);
238
    my $template = C4::Templates->new($interface, $filename, $tmplbase, $query);
239
238
# NOTE: Commenting these out rather than deleting them so that those who need
240
# NOTE: Commenting these out rather than deleting them so that those who need
239
# to know how we previously shimmed these directories will be able to understand.
241
# to know how we previously shimmed these directories will be able to understand.
240
#    my $is_intranet = $interface eq 'intranet';
242
#    my $is_intranet = $interface eq 'intranet';
(-)a/Koha/Plugins.pm (+87 lines)
Line 0 Link Here
1
package Koha::Plugins;
2
3
# Copyright 2012 Kyle Hall
4
#
5
# This file is part of Koha.
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 2 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 Module::Load::Conditional qw(can_load);
23
use Module::Pluggable search_path => ['Koha::Plugin'];
24
25
use C4::Context;
26
use C4::Output;
27
28
BEGIN {
29
    die('Plugins not enabled in config') unless ( C4::Context->config("enable_plugins") );
30
31
    push @INC, C4::Context->config("pluginsdir");
32
}
33
34
=head1 NAME
35
36
Koha::Plugins - Module for loading and managing plugins.
37
38
=cut
39
40
sub new {
41
    my ( $class, $args ) = @_;
42
43
    $args->{'pluginsdir'} = C4::Context->config("pluginsdir");
44
45
    return bless( $args, $class );
46
}
47
48
=head2 GetPlugins()
49
50
This will return a list of all the available plugins of the passed type.
51
52
Usage: my @plugins = C4::Plugins::GetPlugins( $method );
53
54
At the moment, the available types are 'report' and 'tool'.
55
=cut
56
57
sub GetPlugins {
58
    my $self   = shift;
59
    my $method = shift;
60
61
    my @plugin_classes = $self->plugins();
62
    my @plugins;
63
64
    foreach my $plugin_class (@plugin_classes) {
65
        if ( can_load( modules => { $plugin_class => undef } ) ) {
66
            my $plugin = $plugin_class->new();
67
68
            if ($method) {
69
                if ( $plugin->can($method) ) {
70
                    push( @plugins, $plugin );
71
                }
72
            } else {
73
                push( @plugins, $plugin );
74
            }
75
        }
76
    }
77
    return @plugins;
78
}
79
80
1;
81
__END__
82
83
=head1 AUTHOR
84
85
Kyle M Hall <kyle.m.hall@gmail.com>
86
87
=cut
(-)a/Koha/Plugins/Base.pm (+190 lines)
Line 0 Link Here
1
package Koha::Plugins::Base;
2
3
# Copyright 2012 Kyle Hall
4
#
5
# This file is part of Koha.
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 2 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 Module::Pluggable require => 1;
23
24
use base qw{Module::Bundled::Files};
25
26
use C4::Context;
27
use C4::Auth;
28
29
BEGIN {
30
    die('Plugins not enabled in config') unless ( C4::Context->config("enable_plugins") );
31
32
    push @INC, C4::Context->config("pluginsdir");
33
}
34
35
=head1 NAME
36
37
C4::Plugins::Base - Base Module for plugins
38
39
=cut
40
41
sub new {
42
    my ( $class, $args ) = @_;
43
44
    $args->{'class'} = $class;
45
    $args->{'template'} = Template->new( { ABSOLUTE => 1 } );
46
47
    my $self = bless( $args, $class );
48
49
    ## Run the installation method if it exists and hasn't been run before
50
    if ( $self->can('install') && !$self->retrieve_data('__INSTALLED__') ) {
51
        if ( $self->install() ) {
52
            $self->store_data( { '__INSTALLED__' => 1 } );
53
        } else {
54
            warn "Plugin $class failed during installation!";
55
        }
56
    }
57
58
    return $self;
59
}
60
61
=head2 store_data
62
63
set_data allows a plugin to store key value pairs in the database for future use.
64
65
usage: $self->set_data({ param1 => 'param1val', param2 => 'param2value' })
66
67
=cut
68
69
sub store_data {
70
    my ( $self, $data ) = @_;
71
72
    my $dbh = C4::Context->dbh;
73
    my $sql = "REPLACE INTO plugin_data SET plugin_class = ?, plugin_key = ?, plugin_value = ?";
74
    my $sth = $dbh->prepare($sql);
75
76
    foreach my $key ( keys %$data ) {
77
        $sth->execute( $self->{'class'}, $key, $data->{$key} );
78
    }
79
}
80
81
=head2 retrieve_data
82
83
retrieve_data allows a plugin to read the values that were previously saved with store_data
84
85
usage: my $value = $self->retrieve_data( $key );
86
87
=cut
88
89
sub retrieve_data {
90
    my ( $self, $key ) = @_;
91
92
    my $dbh = C4::Context->dbh;
93
    my $sql = "SELECT plugin_value FROM plugin_data WHERE plugin_class = ? AND plugin_key = ?";
94
    my $sth = $dbh->prepare($sql);
95
    $sth->execute( $self->{'class'}, $key );
96
    my $row = $sth->fetchrow_hashref();
97
98
    return $row->{'plugin_value'};
99
}
100
101
=head2 get_template
102
103
get_template returns a Template object. Eventually this will probably be calling
104
C4:Template, but at the moment, it does not.
105
106
=cut
107
108
sub get_template {
109
    my ( $self, $args ) = @_;
110
111
    #    my $template =
112
    #      C4::Templates->new( my $interface = 'intranet', my $filename = $self->mbf_path( $args->{'file'} ), my $tmplbase = '', my $query = $self->{'cgi'} );
113
114
    my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
115
        {   template_name   => $self->mbf_path( $args->{'file'} ),
116
            query           => $self->{'cgi'},
117
            type            => "intranet",
118
            authnotrequired => 1,
119
#           flagsrequired   => { tools => '*' },
120
            is_plugin       => 1,
121
        }
122
    );
123
124
    $template->param(
125
        CLASS       => $self->{'class'},
126
        METHOD      => $self->{'cgi'}->param('method'),
127
        PLUGIN_PATH => $self->get_plugin_http_path(),
128
    );
129
130
    return $template;
131
}
132
133
sub get_metadata {
134
    my ( $self, $args ) = @_;
135
136
    return $self->{'metadata'};
137
}
138
139
=head2 get_qualified_table_name
140
141
To avoid naming conflict, each plugins tables should use a fully qualified namespace.
142
To avoid hardcoding and make plugins more flexible, this method will return the proper
143
fully qualified table name.
144
145
usage: my $table = $self->get_qualified_table_name( 'myTable' );
146
147
=cut
148
149
sub get_qualified_table_name {
150
    my ( $self, $table_name ) = @_;
151
152
    return lc( join( '_', split( '::', $self->{'class'} ), $table_name ) );
153
}
154
155
=head2 get_plugin_http_path
156
157
To access a plugin's own resources ( images, js files, css files, etc... )
158
a plugin will need to know what path to use in the template files. This
159
method returns that path.
160
161
usage: my $path = $self->get_plugin_http_path();
162
163
=cut
164
165
sub get_plugin_http_path {
166
    my ($self) = @_;
167
168
    return "/plugin/" . join( '/', split( '::', $self->{'class'} ) );
169
}
170
171
=head2 go_home
172
173
   go_home is a quick redirect to the Koha plugins home page
174
175
=cut
176
177
sub go_home {
178
    my ( $self, $params ) = @_;
179
180
    print $self->{'cgi'}->redirect("/cgi-bin/koha/plugins/plugins-home.pl");
181
}
182
183
1;
184
__END__
185
186
=head1 AUTHOR
187
188
Kyle M Hall <kyle.m.hall@gmail.com>
189
190
=cut
(-)a/Koha/Plugins/Handler.pm (+100 lines)
Line 0 Link Here
1
package Koha::Plugins::Handler;
2
3
# Copyright 2012 Kyle Hall
4
#
5
# This file is part of Koha.
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 2 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 File::Path qw(remove_tree);
23
24
use Module::Load::Conditional qw(can_load);
25
26
use C4::Context;
27
28
BEGIN {
29
    die('Plugins not enabled in config') unless ( C4::Context->config("enable_plugins") );
30
31
    push @INC, C4::Context->config("pluginsdir");
32
}
33
34
=head1 NAME
35
36
C4::Plugins::Handler - Handler Module for running plugins
37
38
=head1 SYNOPSIS
39
40
  Koha::Plugins::Handler->run({ class => $class, method => $method, cgi => $cgi });
41
  $p->run();
42
43
=over 2
44
45
=cut
46
47
=item run
48
49
Runs a plugin
50
51
=cut
52
53
sub run {
54
    my ( $class, $args ) = @_;
55
    my $plugin_class  = $args->{'class'};
56
    my $plugin_method = $args->{'method'};
57
    my $cgi           = $args->{'cgi'};
58
59
    if ( can_load( modules => { $plugin_class => undef } ) ) {
60
        my $plugin = $plugin_class->new( { cgi => $cgi } );
61
        if ( $plugin->can($plugin_method) ) {
62
            $plugin->$plugin_method();
63
        } else {
64
            warn "Plugin does not have method $plugin_method";
65
        }
66
    } else {
67
        warn "Plugin $plugin_class cannot be loaded";
68
    }
69
}
70
71
=item delete
72
73
Deletes a plugin
74
75
=cut
76
77
sub delete {
78
    my ( $class, $args ) = @_;
79
    my $plugin_class = $args->{'class'};
80
    my $plugin_dir   = C4::Context->config("pluginsdir");
81
    my $plugin_path  = "$plugin_dir/" . join( '/', split( '::', $args->{'class'} ) );
82
83
    Koha::Plugins::Handler->run( { class => $plugin_class, method => 'uninstall' } );
84
85
    C4::Context->dbh->do( "DELETE FROM plugin_data WHERE plugin_class = ?", undef, ($plugin_class) );
86
87
    unlink("$plugin_path.pm");
88
    remove_tree($plugin_path);
89
}
90
91
1;
92
__END__
93
94
=back
95
96
=head1 AUTHOR
97
98
Kyle M Hall <kyle.m.hall@gmail.com>
99
100
=cut
(-)a/Makefile.PL (-1 / +9 lines)
Lines 230-235 Directory for Apache and Zebra logs produced by Koha. Link Here
230
230
231
Directory for backup files produced by Koha.
231
Directory for backup files produced by Koha.
232
232
233
=item PLUGINS_DIR
234
235
Directory for external Koha plugins.
236
233
=item PAZPAR2_CONF_DIR
237
=item PAZPAR2_CONF_DIR
234
238
235
Directory for PazPar2 configuration files.
239
Directory for PazPar2 configuration files.
Lines 309-314 my $target_map = { Link Here
309
  './skel/var/lib/koha/zebradb/biblios/register'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
313
  './skel/var/lib/koha/zebradb/biblios/register'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
310
  './skel/var/lib/koha/zebradb/biblios/shadow'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
314
  './skel/var/lib/koha/zebradb/biblios/shadow'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
311
  './skel/var/lib/koha/zebradb/biblios/tmp'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
315
  './skel/var/lib/koha/zebradb/biblios/tmp'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
316
  './skel/var/lib/koha/plugins' => { target => 'PLUGINS_DIR', trimdir => 6 },
312
  './sms'                       => 'INTRANET_CGI_DIR',
317
  './sms'                       => 'INTRANET_CGI_DIR',
313
  './suggestion'                => 'INTRANET_CGI_DIR',
318
  './suggestion'                => 'INTRANET_CGI_DIR',
314
  './svc'                       => 'INTRANET_CGI_DIR',
319
  './svc'                       => 'INTRANET_CGI_DIR',
Lines 1235-1240 sub get_target_directories { Link Here
1235
        $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
1240
        $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
1236
        $dirmap{'LOG_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'log');
1241
        $dirmap{'LOG_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'log');
1237
        $dirmap{'BACKUP_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'spool');
1242
        $dirmap{'BACKUP_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'spool');
1243
        $dirmap{'PLUGINS_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'lib', 'koha', 'plugins');
1238
        $dirmap{'ZEBRA_DATA_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
1244
        $dirmap{'ZEBRA_DATA_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
1239
        $dirmap{'ZEBRA_RUN_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
1245
        $dirmap{'ZEBRA_RUN_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
1240
    } elsif ($mode eq 'dev') {
1246
    } elsif ($mode eq 'dev') {
Lines 1265-1270 sub get_target_directories { Link Here
1265
        $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
1271
        $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
1266
        $dirmap{'LOG_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'log');
1272
        $dirmap{'LOG_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'log');
1267
        $dirmap{'BACKUP_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'spool');
1273
        $dirmap{'BACKUP_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'spool');
1274
        $dirmap{'PLUGINS_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'lib', 'plugins');
1268
        $dirmap{'ZEBRA_DATA_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
1275
        $dirmap{'ZEBRA_DATA_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
1269
        $dirmap{'ZEBRA_RUN_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
1276
        $dirmap{'ZEBRA_RUN_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
1270
    } else {
1277
    } else {
Lines 1287-1292 sub get_target_directories { Link Here
1287
        $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lock', $package, 'zebradb');
1294
        $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lock', $package, 'zebradb');
1288
        $dirmap{'LOG_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'log', $package);
1295
        $dirmap{'LOG_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'log', $package);
1289
        $dirmap{'BACKUP_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'spool', $package);
1296
        $dirmap{'BACKUP_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'spool', $package);
1297
        $dirmap{'PLUGINS_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'plugins');
1290
        $dirmap{'ZEBRA_DATA_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'zebradb');
1298
        $dirmap{'ZEBRA_DATA_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'zebradb');
1291
        $dirmap{'ZEBRA_RUN_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'run', $package, 'zebradb');
1299
        $dirmap{'ZEBRA_RUN_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'run', $package, 'zebradb');
1292
    }
1300
    }
Lines 1560-1566 make_upgrade_backup :: Link Here
1560
\t\$(NOECHO) umask 022; \$(MOD_BACKUP) \\
1568
\t\$(NOECHO) umask 022; \$(MOD_BACKUP) \\
1561
/;
1569
/;
1562
    foreach my $key (qw/KOHA_CONF_DIR INTRANET_TMPL_DIR INTRANET_WWW_DIR OPAC_TMPL_DIR OPAC_WWW_DIR
1570
    foreach my $key (qw/KOHA_CONF_DIR INTRANET_TMPL_DIR INTRANET_WWW_DIR OPAC_TMPL_DIR OPAC_WWW_DIR
1563
                     PAZPAR2_CONF_DIR ZEBRA_CONF_DIR/) {
1571
                     PAZPAR2_CONF_DIR ZEBRA_CONF_DIR PLUGINS_DIR/) {
1564
    	$upgrade .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n"
1572
    	$upgrade .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n"
1565
            unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or
1573
            unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or
1566
                   exists $skip_directories->{$key} or
1574
                   exists $skip_directories->{$key} or
(-)a/debian/templates/koha-conf-site.xml.in (+2 lines)
Lines 257-262 Link Here
257
 <biblioservershadow>1</biblioservershadow>
257
 <biblioservershadow>1</biblioservershadow>
258
 <authorityserver>authorities</authorityserver>
258
 <authorityserver>authorities</authorityserver>
259
 <authorityservershadow>1</authorityservershadow>
259
 <authorityservershadow>1</authorityservershadow>
260
 <pluginsdir>__PLUGINS_DIR__</pluginsdir>
261
 <enable_plugins>0</enable_plugins>
260
 <intranetdir>/usr/share/koha/intranet/cgi-bin</intranetdir>
262
 <intranetdir>/usr/share/koha/intranet/cgi-bin</intranetdir>
261
 <opacdir>/usr/share/koha/opac/cgi-bin/opac</opacdir>
263
 <opacdir>/usr/share/koha/opac/cgi-bin/opac</opacdir>
262
 <opachtdocs>/usr/share/koha/opac/htdocs/opac-tmpl</opachtdocs>
264
 <opachtdocs>/usr/share/koha/opac/htdocs/opac-tmpl</opachtdocs>
(-)a/etc/koha-conf.xml (+1 lines)
Lines 276-281 __PAZPAR2_TOGGLE_XML_POST__ Link Here
276
 <biblioservershadow>1</biblioservershadow>
276
 <biblioservershadow>1</biblioservershadow>
277
 <authorityserver>authorities</authorityserver>
277
 <authorityserver>authorities</authorityserver>
278
 <authorityservershadow>1</authorityservershadow>
278
 <authorityservershadow>1</authorityservershadow>
279
 <pluginsdir>__PLUGINS_DIR__</pluginsdir>
279
 <intranetdir>__INTRANET_CGI_DIR__</intranetdir>
280
 <intranetdir>__INTRANET_CGI_DIR__</intranetdir>
280
 <opacdir>__OPAC_CGI_DIR__/opac</opacdir>
281
 <opacdir>__OPAC_CGI_DIR__/opac</opacdir>
281
 <opachtdocs>__OPAC_TMPL_DIR__</opachtdocs>
282
 <opachtdocs>__OPAC_TMPL_DIR__</opachtdocs>
(-)a/etc/koha-httpd.conf (+1 lines)
Lines 105-110 Link Here
105
   ScriptAlias /cgi-bin/koha/ "__INTRANET_CGI_DIR__/"
105
   ScriptAlias /cgi-bin/koha/ "__INTRANET_CGI_DIR__/"
106
   ScriptAlias /index.html "__INTRANET_CGI_DIR__/mainpage.pl"
106
   ScriptAlias /index.html "__INTRANET_CGI_DIR__/mainpage.pl"
107
   ScriptAlias /search "__INTRANET_CGI_DIR__/search.pl"
107
   ScriptAlias /search "__INTRANET_CGI_DIR__/search.pl"
108
   Alias /plugin/ "__PLUGINS_DIR__/"
108
   ErrorLog __LOG_DIR__/koha-error_log
109
   ErrorLog __LOG_DIR__/koha-error_log
109
#  TransferLog __LOG_DIR__/koha-access.log
110
#  TransferLog __LOG_DIR__/koha-access.log
110
   SetEnv KOHA_CONF "__KOHA_CONF_DIR__/koha-conf.xml"
111
   SetEnv KOHA_CONF "__KOHA_CONF_DIR__/koha-conf.xml"
(-)a/installer/data/mysql/kohastructure.sql (+11 lines)
Lines 3077-3082 CREATE TABLE linktracker ( Link Here
3077
   KEY dateidx (timeclicked)
3077
   KEY dateidx (timeclicked)
3078
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3078
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3079
3079
3080
--
3081
-- Table structure for table 'plugin_data'
3082
--
3083
3084
CREATE TABLE IF NOT EXISTS plugin_data (
3085
  plugin_class varchar(255) NOT NULL,
3086
  plugin_key varchar(255) NOT NULL,
3087
  plugin_value text,
3088
  PRIMARY KEY (plugin_class,plugin_key)
3089
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3090
3080
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
3091
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
3081
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
3092
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
3082
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
3093
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 421-423 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES( Link Here
421
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('PatronSelfRegistrationAdditionalInstructions','','A free text field to display additional instructions to newly self registered patrons.','','free');
421
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('PatronSelfRegistrationAdditionalInstructions','','A free text field to display additional instructions to newly self registered patrons.','','free');
422
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('UseQueryParser', '0', 'If enabled, try to use QueryParser for queries.', NULL, 'YesNo');
422
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('UseQueryParser', '0', 'If enabled, try to use QueryParser for queries.', NULL, 'YesNo');
423
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('FinesIncludeGracePeriod','1','If enabled, fines calculations will include the grace period.',NULL,'YesNo');
423
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('FinesIncludeGracePeriod','1','If enabled, fines calculations will include the grace period.',NULL,'YesNo');
424
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('UseKohaPlugins','1','Enable or disable the ability to use Koha Plugins.','','YesNo');
(-)a/installer/data/mysql/updatedatabase.pl (+24 lines)
Lines 6532-6537 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
6532
    SetVersion ($DBversion);
6532
    SetVersion ($DBversion);
6533
}
6533
}
6534
6534
6535
$DBversion = "3.11.00.XXX";
6536
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
6537
    $dbh->do("INSERT INTO userflags (bit, flag, flagdesc, defaulton) VALUES ('19', 'plugins', 'Koha plugins', '0')");
6538
    $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES
6539
              ('19', 'manage', 'Manage plugins ( install / uninstall )'),
6540
              ('19', 'tool', 'Use tool plugins'),
6541
              ('19', 'report', 'Use report plugins'),
6542
              ('19', 'configure', 'Configure plugins')
6543
            ");
6544
    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('UseKohaPlugins','1','Enable or disable the ability to use Koha Plugins.','','YesNo')");
6545
6546
    $dbh->do("
6547
        CREATE TABLE IF NOT EXISTS plugin_data (
6548
            plugin_class varchar(255) NOT NULL,
6549
            plugin_key varchar(255) NOT NULL,
6550
            plugin_value text,
6551
            PRIMARY KEY (plugin_class,plugin_key)
6552
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
6553
    ");
6554
6555
    print "Upgrade to $DBversion done (Added plugin system.)\n";
6556
    SetVersion($DBversion);
6557
}
6558
6535
=head1 FUNCTIONS
6559
=head1 FUNCTIONS
6536
6560
6537
=head2 TableExists($table)
6561
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc (-1 / +4 lines)
Lines 30-35 Link Here
30
                            [% IF ( CAN_user_tools ) %]
30
                            [% IF ( CAN_user_tools ) %]
31
                            <li><a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a></li>
31
                            <li><a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a></li>
32
                            [% END %]
32
                            [% END %]
33
                            [% IF ( UseKohaPlugins && CAN_user_plugins ) %]
34
                            <li><a href="/cgi-bin/koha/plugins/plugins-home.pl">Plugins</a></li>
35
                            [% END %]
33
                            [% IF ( CAN_user_parameters ) %]
36
                            [% IF ( CAN_user_parameters ) %]
34
                            <li><a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a></li>
37
                            <li><a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a></li>
35
                            [% END %]
38
                            [% END %]
Lines 93-96 Link Here
93
       </div>
96
       </div>
94
   </div>
97
   </div>
95
[% IF ( intranetbookbag ) %]<div id="cartDetails">Your cart is empty.</div>[% END %]
98
[% IF ( intranetbookbag ) %]<div id="cartDetails">Your cart is empty.</div>[% END %]
96
</div>
99
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref (+7 lines)
Lines 319-321 Enhanced Content: Link Here
319
            - pref: HTML5MediaExtensions
319
            - pref: HTML5MediaExtensions
320
              class: multi
320
              class: multi
321
            - (separated with |).
321
            - (separated with |).
322
    Plugins:
323
        -
324
            - pref: UseKohaPlugins
325
              choices:
326
                  yes: Enable
327
                  no: "Don't enable"
328
            - the ability to use Koha Plugins. Note, the plugin system must also be enabled in the Koha configuration file to be fully enabled.
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt (+116 lines)
Line 0 Link Here
1
[% USE KohaDates %]
2
[% INCLUDE 'doc-head-open.inc' %]
3
<title>Koha &rsaquo; Tools &rsaquo; Plugins </title>
4
[% INCLUDE 'doc-head-close.inc' %]
5
[% INCLUDE 'calendar.inc' %]
6
</head>
7
8
<body>
9
[% INCLUDE 'header.inc' %]
10
[% INCLUDE 'circ-search.inc' %]
11
12
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a>
13
&rsaquo; Plugins
14
</div>
15
16
<div id="doc3" class="yui-t1">
17
    <div id="bd">
18
        <div id="yui-main">
19
            <div class="yui-b">
20
                <div class="details">
21
                    <h1>Plugins</h1>
22
23
                    [% UNLESS ( plugins ) %]
24
                        [% UNLESS ( method ) %]
25
                            <h3>No plugins installed</h3>
26
                        [% ELSE %]
27
                            [% IF method == 'tool' %]
28
                                <h3>No plugins that can be used as a tool are installed</h3>
29
                            [% ELSIF method == 'report' %]
30
                                <h3>No plugins that can create a report are installed</h3>
31
                            [% ELSE %]
32
                                <h3>Unknown plugin type <i>[% method %]</i>
33
                            [% END %]
34
                        [% END %]
35
                    [% ELSE %]
36
                        <table>
37
                            <tr>
38
                                <th>Name</th>
39
                                <th>&nbsp;</th>
40
                                <th>Description</th>
41
                                <th>Author</th>
42
                                <th>Plugin Version</th>
43
                                <th>Minimum Koha Version</th>
44
                                <th>Maximum Koha Version</th>
45
                                <th>Last Updated</th>
46
                                [% IF ( CAN_user_plugins_configure ) %]<th>Configure</th>[% END %]
47
                                [% IF ( CAN_user_plugins_manage ) %]<th>Uninstall</th>[% END %]
48
                            </tr>
49
50
                            [% FOREACH plugin IN plugins %]
51
                                <tr>
52
                                    <td><strong>[% plugin.metadata.name %]</strong></td>
53
                                    <td>
54
                                        [% IF ( CAN_user_plugins_report ) %]
55
                                            [% IF plugin.can('report') %]
56
                                                <p style="white-space:nowrap"><a href="/cgi-bin/koha/plugins/run.pl?class=[% plugin.class %]&method=report">Run report</a></p>
57
                                            [% END %]
58
                                        [% END %]
59
60
                                        [% IF ( CAN_user_plugins_tool ) %]
61
                                            [% IF plugin.can('tool') %]
62
                                                <p style="white-space:nowrap"><a href="/cgi-bin/koha/plugins/run.pl?class=[% plugin.class %]&method=tool">Run tool</a></p>
63
                                            [% END %]
64
                                        [% END %]
65
                                    </td>
66
                                    <td>
67
                                        [% plugin.metadata.description %]
68
69
                                        [% IF ( plugin.metadata.minimum_version && koha_version < plugin.metadata.minimum_version ) %]
70
                                            <div class="error">Warning: This report was written for a newer version of Koha. Run at your own risk.</div>
71
                                        [% END %]
72
73
                                        [% IF ( plugin.metadata.maximum_version && koha_version > plugin.metadata.maximum_version ) %]
74
                                            <div class="error">Warning: This report was written for an older version of Koha. Run at your own risk.</div>
75
                                        [% END %]
76
                                    </td>
77
                                    <td>[% plugin.metadata.author %]</td>
78
                                    <td>[% plugin.metadata.version %]</td>
79
                                    <td>[% plugin.metadata.minimum_version %]</td>
80
                                    <td>[% plugin.metadata.maximum_version %]</td>
81
                                    <td>[% plugin.metadata.date_updated | $KohaDates %]</td>
82
                                    [% IF ( CAN_user_plugins_configure ) %]
83
                                        <td>
84
                                            [% IF plugin.can('configure') %]
85
                                                <a href="/cgi-bin/koha/plugins/run.pl?class=[% plugin.class %]&method=configure">Configure</a>
86
                                            [% END %]
87
                                        </td>
88
                                    [% END %]
89
                                    [% IF ( CAN_user_plugins_manage ) %]
90
                                        <td>
91
                                            [% IF plugin.can('uninstall') %]
92
                                                <a href="/cgi-bin/koha/plugins/plugins-uninstall.pl?class=[% plugin.class %]" onclick="return confirm('Are you sure you want to uninstall the plugin [% plugin.metadata.name %]?')">Uninstall</a>
93
                                            [% END %]
94
                                        </td>
95
                                    [% END %]
96
                            [% END %]
97
                        </table>
98
                    [% END %]
99
                </div>
100
            </div>
101
        </div>
102
103
        <div class="yui-b noprint">
104
            <div id="navmenu">
105
                <ul id="navmenulist">
106
                    [% IF ( CAN_user_plugins_manage ) %]
107
                        <li><a href="plugins-upload.pl">Upload a plugin</a></li>
108
                    [% END %]
109
                </ul>
110
            </div>
111
        </div>
112
    </div>
113
</div>
114
115
116
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-upload.tt (+55 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Tools &rsaquo; Plugins &rsaquo; Upload Plugin
3
 </title>
4
[% INCLUDE 'doc-head-close.inc' %]
5
[% INCLUDE 'calendar.inc' %]
6
</head>
7
8
<body>
9
[% INCLUDE 'header.inc' %]
10
[% INCLUDE 'circ-search.inc' %]
11
12
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a>
13
&rsaquo; <a href="/cgi-bin/koha/plugins/plugins-home.pl">Plugins</a>
14
&rsaquo; Upload Plugins
15
</div>
16
17
<div id="doc3" class="yui-t2">
18
    <div id="bd">
19
        <div id="yui-main">
20
    <div class="yui-b">
21
        <div class="yui-g">
22
            <div class="yui-u first">
23
                <h1>Upload Koha Plugin</h1>
24
                [% IF ( ERRORS ) %]
25
                <div class="dialog alert">
26
                    [% FOREACH ERROR IN ERRORS %]
27
                        [% IF ( ERROR.NOTKPZ ) %]<li><b>The upload file does not appear to be a kpz file.  The extention is not '.kpz'.</b></li>
28
                        [% ELSIF ( ERROR.NOWRITETEMP ) %]<li><b>This script is not able to create/write to the necessary temporary directory.</b></li>
29
                        [% ELSIF ( ERROR.EMPTYUPLOAD ) %]<li><b>The upload file appears to be empty.</b></li>
30
                        [% ELSIF ( ERROR.UZIPFAIL ) %]<li><b>[% ERROR.UZIPFAIL %] failed to unpack.<br />Please verify the integrity of the zip file and retry.</b></li>
31
                        [% ELSIF ( ERROR.NOWRITEPLUGINS ) %]<li><b>Cannot unpack file to the plugins directory.<br />Please verify that the Apache user can write to the plugins directory.</b></li>
32
                        [% ELSE %]<li><b>[% ERROR.CORERR %] An unknown error has occurred.<br />Please review the error log for more details.</b></li>[% END %]
33
                    [% END %]
34
                </div>
35
                [% END %]
36
                <form method="post" action="/cgi-bin/koha/plugins/plugins-upload.pl" enctype="multipart/form-data">
37
                    <fieldset class="brief">
38
                         <div class="hint"><b>NOTE:</b> Only KPZ file format is supported.</div>
39
                        <ol>
40
                            <li>
41
                                <label for="uploadfile">Select the file to upload: </label><input type="file" id="uploadfile" name="uploadfile" />
42
                            </li>
43
                        </ol>
44
                    </fieldset>
45
                    <fieldset class="action">
46
                        <input type="hidden" name="op" value="Upload" />
47
                        <input type="submit" value="Upload" class="submit" />
48
                    </fieldset>
49
                </form>
50
51
            </div>
52
        </div>
53
    </div>
54
</div>
55
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt (-1 / +10 lines)
Lines 35-41 Link Here
35
		<li><a href="/cgi-bin/koha/reports/issues_stats.pl">Circulation</a></li>
35
		<li><a href="/cgi-bin/koha/reports/issues_stats.pl">Circulation</a></li>
36
		<li><a href="/cgi-bin/koha/reports/serials_stats.pl">Serials</a></li>
36
		<li><a href="/cgi-bin/koha/reports/serials_stats.pl">Serials</a></li>
37
		<li><a href="/cgi-bin/koha/reports/reserves_stats.pl">Holds</a></li>
37
		<li><a href="/cgi-bin/koha/reports/reserves_stats.pl">Holds</a></li>
38
	</ul></div>
38
      </ul>
39
40
        [% IF UseKohaPlugins %]
41
        <h2>Report Plugins</h2>
42
        <ul>
43
                <li><a href="/cgi-bin/koha/plugins/plugins-home.pl?method=report">Report Plugins</a></li>
44
        </ul>
45
        [% END %]
46
47
    </div>
39
48
40
    <div class="yui-u"><h2>Top lists</h2>
49
    <div class="yui-u"><h2>Top lists</h2>
41
	<ul>
50
	<ul>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt (+5 lines)
Lines 97-102 Link Here
97
    <dd>Quote editor for Quote-of-the-day feature in OPAC</dd>
97
    <dd>Quote editor for Quote-of-the-day feature in OPAC</dd>
98
    [% END %]
98
    [% END %]
99
99
100
    [% IF ( UseKohaPlugins && CAN_user_plugins_tool ) %]
101
    <dt><a href="/cgi-bin/koha/plugins/plugins-home.pl?method=tool">Tool Plugins</a></dt>
102
    <dd>Use tool plugins</dd>
103
    [% END %]
104
100
</dl>
105
</dl>
101
</div>
106
</div>
102
<div class="yui-u">
107
<div class="yui-u">
(-)a/plugins/plugins-home.pl (+57 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2010 Kyle M Hall <kyle.m.hall@gmail.com>
4
#
5
# This file is part of Koha.
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 2 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 strict;
21
use warnings;
22
23
use CGI;
24
25
use Koha::Plugins;
26
use C4::Auth;
27
use C4::Output;
28
use C4::Dates;
29
use C4::Debug;
30
use C4::Context;
31
32
die("Koha plugins are disabled!")
33
  unless C4::Context->preference('UseKohaPlugins');
34
35
my $input  = new CGI;
36
my $method = $input->param('method');
37
38
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
39
    {   template_name   => "plugins/plugins-home.tmpl",
40
        query           => $input,
41
        type            => "intranet",
42
        authnotrequired => 0,
43
        flagsrequired   => { plugins => '*' },
44
        debug           => 1,
45
    }
46
);
47
48
$template->param(
49
    koha_version => C4::Context->preference("Version"),
50
    method       => $method,
51
);
52
53
my @plugins = Koha::Plugins->new()->GetPlugins($method);
54
55
$template->param( plugins => \@plugins );
56
57
output_html_with_http_headers( $input, $cookie, $template->output );
(-)a/plugins/plugins-uninstall.pl (+52 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
#
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 2 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use strict;
19
use warnings;
20
21
use Archive::Extract;
22
use File::Temp;
23
use File::Copy;
24
use CGI;
25
26
use C4::Context;
27
use C4::Auth;
28
use C4::Output;
29
use C4::Members;
30
use C4::Debug;
31
use Koha::Plugins::Handler;
32
33
die("Koha plugins are disabled!")
34
  unless C4::Context->preference('UseKohaPlugins');
35
36
my $input = new CGI;
37
38
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39
    {   template_name   => "plugins/plugins-upload.tmpl",
40
        query           => $input,
41
        type            => "intranet",
42
        authnotrequired => 0,
43
        flagsrequired   => { plugins => 'manage' },
44
        debug           => 1,
45
    }
46
);
47
48
my $class = $input->param('class');
49
50
Koha::Plugins::Handler->delete( { class => $class } );
51
52
print $input->redirect("/cgi-bin/koha/plugins/plugins-home.pl");
(-)a/plugins/plugins-upload.pl (+98 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
#
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 2 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use strict;
19
use warnings;
20
21
use Archive::Extract;
22
use File::Temp;
23
use File::Copy;
24
use CGI;
25
26
use C4::Context;
27
use C4::Auth;
28
use C4::Output;
29
use C4::Members;
30
use C4::Debug;
31
use Koha::Plugins;
32
33
die("Koha plugins are disabled!")
34
  unless C4::Context->preference('UseKohaPlugins');
35
36
my $input = new CGI;
37
38
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39
    {   template_name   => "plugins/plugins-upload.tmpl",
40
        query           => $input,
41
        type            => "intranet",
42
        authnotrequired => 0,
43
        flagsrequired   => { plugins => 'manage' },
44
        debug           => 1,
45
    }
46
);
47
48
my $uploadfilename = $input->param('uploadfile');
49
my $uploadfile     = $input->upload('uploadfile');
50
my $op             = $input->param('op');
51
52
my ( $total, $handled, @counts, $tempfile, $tfh );
53
54
my %errors;
55
56
if ( ( $op eq 'Upload' ) && $uploadfile ) {
57
    my $plugins_dir = C4::Context->config("pluginsdir");
58
59
    my $dirname = File::Temp::tempdir( CLEANUP => 1 );
60
    $debug and warn "dirname = $dirname";
61
62
    my $filesuffix;
63
    $filesuffix = $1 if $uploadfilename =~ m/(\..+)$/i;
64
    ( $tfh, $tempfile ) = File::Temp::tempfile( SUFFIX => $filesuffix, UNLINK => 1 );
65
66
    $debug and warn "tempfile = $tempfile";
67
68
    $errors{'NOTKPZ'} = 1 if ( $uploadfilename !~ /\.kpz$/i );
69
    $errors{'NOWRITETEMP'}    = 1 unless ( -w $dirname );
70
    $errors{'NOWRITEPLUGINS'} = 1 unless ( -w $plugins_dir );
71
    $errors{'EMPTYUPLOAD'}    = 1 unless ( length($uploadfile) > 0 );
72
73
    if (%errors) {
74
        $template->param( ERRORS => [ \%errors ] );
75
    } else {
76
        while (<$uploadfile>) {
77
            print $tfh $_;
78
        }
79
        close $tfh;
80
81
        my $ae = Archive::Extract->new( archive => $tempfile, type => 'zip' );
82
        unless ( $ae->extract( to => $plugins_dir ) ) {
83
            warn "ERROR: " . $ae->error;
84
            $errors{'UZIPFAIL'} = $uploadfilename;
85
            $template->param( ERRORS => [ \%errors ] );
86
            output_html_with_http_headers $input, $cookie, $template->output;
87
            exit;
88
        }
89
    }
90
} elsif ( ( $op eq 'Upload' ) && !$uploadfile ) {
91
    warn "Problem uploading file or no file uploaded.";
92
}
93
94
if ( $uploadfile && !%errors && !$template->param('ERRORS') ) {
95
    print $input->redirect("/cgi-bin/koha/plugins/plugins-home.pl");
96
} else {
97
    output_html_with_http_headers $input, $cookie, $template->output;
98
}
(-)a/plugins/run.pl (+50 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2010 Kyle M Hall <kyle.m.hall@gmail.com>
4
#
5
# This file is part of Koha.
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 2 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 strict;
21
use warnings;
22
23
use CGI;
24
25
use Koha::Plugins::Handler;
26
use C4::Auth;
27
use C4::Output;
28
use C4::Dates;
29
use C4::Debug;
30
use C4::Context;
31
32
die("Koha plugins are disabled!")
33
  unless C4::Context->preference('UseKohaPlugins');
34
35
my $cgi = new CGI;
36
37
my $class  = $cgi->param('class');
38
my $method = $cgi->param('method');
39
40
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
41
    {   template_name   => "plugins/plugins-home.tmpl",
42
        query           => $cgi,
43
        type            => "intranet",
44
        authnotrequired => 0,
45
        flagsrequired   => { plugins => $method },
46
        debug           => 1,
47
    }
48
);
49
50
my $plugin = Koha::Plugins::Handler->run( { class => $class, method => $method, cgi => $cgi } );
(-)a/rewrite-config.PL (-1 / +2 lines)
Lines 43-49 guesses worked out by the script. Link Here
43
The following configuration keywords are available:
43
The following configuration keywords are available:
44
44
45
PREFIX,
45
PREFIX,
46
BASE_DIR, CGI_DIR, LOG_DIR, INSTALL_BASE,
46
BASE_DIR, CGI_DIR, LOG_DIR, PLUGINS_DIR, INSTALL_BASE,
47
DB_TYPE, DB_HOST, DB_PORT, DB_NAME, DB_PASS, DB_USER, WEBMASTER_EMAIL, WEBSERVER_DOMAIN,
47
DB_TYPE, DB_HOST, DB_PORT, DB_NAME, DB_PASS, DB_USER, WEBMASTER_EMAIL, WEBSERVER_DOMAIN,
48
WEBSERVER_HOST, WEBSERVER_IP, WEBSERVER_PORT, WEBSERVER_PORT_LIBRARIAN, ZEBRA_PASS, ZEBRA_USER
48
WEBSERVER_HOST, WEBSERVER_IP, WEBSERVER_PORT, WEBSERVER_PORT_LIBRARIAN, ZEBRA_PASS, ZEBRA_USER
49
49
Lines 82-87 $prefix = $ENV{'INSTALL_BASE'} || "/usr"; Link Here
82
%configuration = (
82
%configuration = (
83
  "__KOHA_INSTALLED_VERSION__" => "no_version_found",
83
  "__KOHA_INSTALLED_VERSION__" => "no_version_found",
84
  "__LOG_DIR__" => "/var/log",
84
  "__LOG_DIR__" => "/var/log",
85
  "__PLUGINS_DIR__" => "/var/lib/koha/plugins",
85
  "__DB_TYPE__" => "mysql",
86
  "__DB_TYPE__" => "mysql",
86
  "__DB_NAME__" => "koha",
87
  "__DB_NAME__" => "koha",
87
  "__DB_HOST__" => $myhost,
88
  "__DB_HOST__" => $myhost,
(-)a/skel/var/lib/koha/plugins/README (-1 / +1 lines)
Line 0 Link Here
0
- 
1
plugins dir

Return to bug 7804