File: | C4/Scrubber.pm |
Coverage: | 95.7% |
line | stmt | bran | cond | sub | time | code |
---|---|---|---|---|---|---|
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 | 2 2 2 | 593 8 47 | use strict; | |||
18 | 2 2 2 | 13 28 71 | use warnings; | |||
19 | 2 2 2 | 13 6 136 | use Carp; | |||
20 | 2 2 2 | 101677 24793 71 | use HTML::Scrubber; | |||
21 | ||||||
22 | 2 2 2 | 207 3 21 | use C4::Context; | |||
23 | 2 2 2 | 12 2 697 | use C4::Debug; | |||
24 | ||||||
25 | our $VERSION = 0.02; | |||||
26 | ||||||
27 | ||||||
28 | my %scrubbertypes = ( | |||||
29 | default => {}, # place holder, default settings are below as fallbacks in call to constructor | |||||
30 | tag => {}, # uses defaults | |||||
31 | comment => { allow => [qw( br b i em big small strong )], }, | |||||
32 | staff => { | |||||
33 | default => [ 1 => { '*' => 1 } ], | |||||
34 | comment => 1, | |||||
35 | }, | |||||
36 | ); | |||||
37 | ||||||
38 | ||||||
39 | sub new { | |||||
40 | 7 | 64 | shift; # ignore our class we are wrapper | |||
41 | 7 | 80 | my $type = (@_) ? shift : 'default'; | |||
42 | 7 | 74 | if ( !exists $scrubbertypes{$type} ) { | |||
43 | 2 | 239 | croak "New called with unrecognized type '$type'"; | |||
44 | } | |||||
45 | 5 | 55 | $debug and carp "Building new Scrubber of type '$type'"; | |||
46 | 5 | 55 | my $settings = $scrubbertypes{$type}; | |||
47 | 5 | 137 | my $scrubber = HTML::Scrubber->new( | |||
48 | allow => exists $settings->{allow} ? $settings->{allow} : [], | |||||
49 | rules => exists $settings->{rules} ? $settings->{rules} : [], | |||||
50 | default => exists $settings->{default} ? $settings->{default} : [ 0 => { '*' => 0 } ], | |||||
51 | comment => exists $settings->{comment} ? $settings->{comment} : 0, | |||||
52 | process => 0, | |||||
53 | ); | |||||
54 | 5 | 927 | return $scrubber; | |||
55 | } | |||||
56 | ||||||
57 | ||||||
58 | 1; |