Changeset 1101

Show
Ignore:
Timestamp:
07/17/06 17:11:40
Author:
typester
Message:

Filter::HTMLScrubber:

  • fixed config parser
  • added default config parameters (from Publish::Planet)
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/feature-server/plagger/lib/Plagger/Plugin/Filter/HTMLScrubber.pm

    r735 r1101  
    44 
    55use HTML::Scrubber; 
     6 
     7sub rules { 
     8    return( 
     9        img => { 
     10            src => qr{^http://},    # only URL with http:// 
     11            alt => 1,               # alt attributes allowed 
     12            '*' => 0,               # deny all others 
     13        }, 
     14        style  => 0, 
     15        script => 0, 
     16    ); 
     17} 
     18 
     19sub default { 
     20    return( 
     21        '*'    => 1,                        # default rule, allow all attributes 
     22        'href' => qr{^(?!(?:java)?script)}i, 
     23        'src'  => qr{^(?!(?:java)?script)}i, 
     24        'cite'     => '(?i-xsm:^(?!(?:java)?script))', 
     25        'language' => 0, 
     26        'name'        => 1,                 # could be sneaky, but hey ;) 
     27        'onblur'      => 0, 
     28        'onchange'    => 0, 
     29        'onclick'     => 0, 
     30        'ondblclick'  => 0, 
     31        'onerror'     => 0, 
     32        'onfocus'     => 0, 
     33        'onkeydown'   => 0, 
     34        'onkeypress'  => 0, 
     35        'onkeyup'     => 0, 
     36        'onload'      => 0, 
     37        'onmousedown' => 0, 
     38        'onmousemove' => 0, 
     39        'onmouseout'  => 0, 
     40        'onmouseover' => 0, 
     41        'onmouseup'   => 0, 
     42        'onreset'     => 0, 
     43        'onselect'    => 0, 
     44        'onsubmit'    => 0, 
     45        'onunload'    => 0, 
     46        'src'         => 0, 
     47        'type'        => 0, 
     48        'style'       => 0, 
     49    ); 
     50} 
    651 
    752sub register { 
     
    1459        my $config   = $self->conf; 
    1560 
     61        my ( %rules, %default ); 
     62        unless ( delete $config->{no_default_configs} ) { 
     63            %rules   = $self->rules; 
     64            %default = $self->default; 
     65        } 
     66        $scrubber->rules( %rules, %{ delete $config->{rules} || {} } ); 
     67        $scrubber->default( %default, %{ delete $config->{default} || {} } ); 
     68 
    1669        while ( my ( $method, $arg ) = each %$config ) { 
    17             eval { $scrubber->$method( ref $arg eq 'ARRAY' ? @$arg : $arg ) }; 
     70            eval { 
     71                $scrubber->$method( 
     72                      ref $arg eq 'ARRAY' ? @$arg 
     73                    : ref $arg eq 'HASH'  ? %$arg 
     74                    : $arg ); 
     75            }; 
    1876            $context->error(qq/Invalid method call "$method": $@/) if $@; 
    1977        } 
     
    3290=head1 NAME 
    3391 
    34 Plagger::Plugin::Filter::HTMLScrubber - Scrubb feed content 
     92Plagger::Plugin::Filter::HTMLScrubber - Scrub feed content 
    3593 
    3694=head1 SYNOPSIS 
     
    3896  - module: Filter::HTMLScrubber 
    3997    config: 
    40       default: 1 
    41       deny: [ 'script', 'iframe' ] 
     98      rules: 
     99        style: 0 
     100        script: 0 
    42101 
    43102=head1 DESCRIPTION 
    44103 
    45 This plugin scrubb feed content by L<HTML::Scrubber>. 
     104This plugin scrub feed content by L<HTML::Scrubber>. 
    46105 
    47 All config parameters are implemented as HTML::Scrubber's method: value. 
     106All config parameters (except 'no_default_configs') are implemented as HTML::Scrubber's method: value. 
    48107For example, if you write in config. 
    49108 
     
    58117So please see L<HTML::Scrubber> document for detail. 
    59118 
     119=head1 DEFAULT_CONFIGS 
     120 
     121some rules and default config parameters are setted by default. 
     122see rules and default functions in this module. 
     123 
     124and if you doen't need these settings, use no_default_configs: 
     125 
     126   config: 
     127     no_detault_configs: 1 
     128 
    60129=head1 AUTHOR 
    61130