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