Bug 5611 INIT block causes failure with mod perl
[koha.git] / C4 / Scrubber.pm
1 package C4::Scrubber;
2 # This file is part of Koha.
3 #
4 # Koha is free software; you can redistribute it and/or modify it under the
5 # terms of the GNU General Public License as published by the Free Software
6 # Foundation; either version 2 of the License, or (at your option) any later
7 # version.
8 #
9 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License along with
14 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
15 # Suite 330, Boston, MA  02111-1307 USA
16
17 use strict;
18 use warnings;
19 use Carp;
20 use HTML::Scrubber;
21
22 use C4::Context;
23 use C4::Debug;
24
25 use vars qw($VERSION @ISA);
26 use vars qw(%scrubbertypes $scrubbertype);
27
28 BEGIN {
29         $VERSION = 0.02;
30         # @ISA = qw(HTML::Scrubber);
31 }
32
33
34 my %scrubbertypes = (
35         default => {},  # place holder, default settings are below as fallbacks in call to constructor
36             tag => {},  # uses defaults
37         comment => {
38         allow   => [qw( br b i em big small strong )],
39         },
40         staff   => {
41         default => [ 1 =>{'*'=>1} ],
42         comment => 1,
43         },
44 );
45
46
47 sub new {
48         my $fakeself = shift;   # not really OO, we return an HTML::Scrubber object.
49         my $type  = (@_) ? shift : 'default';
50         exists $scrubbertypes{$type} or croak "New called with unrecognized type '$type'";
51         $debug and print STDERR "Building new Scrubber of type '$type'\n";
52         my $settings = $scrubbertypes{$type};
53         my $scrubber = HTML::Scrubber->new(
54                 allow   => exists $settings->{allow}   ? $settings->{allow}   : [],
55                 rules   => exists $settings->{rules}   ? $settings->{rules}   : [],
56                 default => exists $settings->{default} ? $settings->{default} : [ 0 =>{'*'=>0} ],
57                 comment => exists $settings->{comment} ? $settings->{comment} : 0,
58                 process => 0,
59         );
60         return $scrubber;
61 }
62
63
64 1;
65 __END__
66
67 =head1 C4::Sanitize
68
69 Standardized wrapper with settings for building HTML::Scrubber tailored to various koha inputs.
70 More verbose debugging messages are sent in the presence of non-zero $ENV{"DEBUG"}.
71
72 The default is to scrub everything, leaving no markup at all.  This is compatible with the expectations
73 for Tags.
74
75 =head2 TODO: Add real perldoc
76
77 =cut
78