Changeset 948 for trunk/Defensio

Show
Ignore:
Timestamp:
08/11/08 16:47:50 (16 months ago)
Author:
breese
Message:

added Community Template Override - a plugin that allows you to specify the template id of the template you want to render results for any community template

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/Defensio/plugins/Defensio/Defensio.pl

    r782 r948  
    4242                handle_spam => \&handle_junk, 
    4343                handle_ham => \&handle_not_junk, 
    44                 'MT::Comment::pre_save' => \&pre_save_obj, 
    45                 'MT::TBPing::pre_save' => \&pre_save_obj, 
     44                'MT::Entry::post_save' => \&post_save_obj, 
     45                'MT::Comment::pre_save' => \&pre_save_feedback_obj, 
     46                'MT::TBPing::pre_save' => \&pre_save_feedback_obj, 
    4647            }, 
    4748            junk_filters => { 
     
    109110} 
    110111 
    111 sub pre_save_obj { 
    112     my ($cb, $obj) = @_; 
    113     if (!$obj->id && $obj->is_junk && ($obj->junk_log =~ m/Defensio says spam/)) { 
    114         # this was junked due in part to Defensio 
    115 #        if (my $blog = $obj->blog) { 
    116 #            $plugin->blocked( $blog, $plugin->blocked($blog) + 1 ); 
    117 #        } 
    118 #        $plugin->blocked( undef, $plugin->blocked() + 1 ); 
    119     } 
     112sub pre_save_feedback_obj { 
     113    my ($cb, $obj, $orig) = @_; 
     114    1; 
     115} 
     116 
     117# This callback handler reports new entries to Defensio 
     118sub post_save_obj { 
     119    my ($cb, $obj, $orig) = @_; 
     120    my $key    = get_apikey() or return; 
     121    my $cli    = Net::Defensio->new( api_key => $key );  
     122    my $url = $app->base . $app->mt_uri; 
     123    my $res = $cli->announce_article(  
     124        owner_url => $url, 
     125        article_author => $obj->author->name, 
     126        article_author_email => $obj->author->email, 
     127        article_title => $obj->title, 
     128        article_content => $obj->text, 
     129        permalink => $obj->permalink, 
     130        );  
     131    if ( !$res || !$res->success ) { 
     132        MT->log("Communications failure with Defensio"); 
     133    } elsif ( $res->status eq 'fail' ) { 
     134        MT->log("Defensio error: " . $res->message); 
     135    } 
     136    1; 
    120137} 
    121138 
     
    124141sub handle_junk { 
    125142    my ($cb, $app, $thing) = @_; 
    126     print STDERR "Report false negative through Defensio\n"; 
    127143    my $key    = get_apikey() or return; 
    128144    require Net::Defensio; 
    129145    if (!$thing->defensio_sig) { # comment has NOT been rated by Defensio before 
    130         print STDERR "Never seen this comment before in Defensio - auditing...\n"; 
    131146        my ($score,$grade) = defensio_score($thing); 
    132147    } 
     
    140155            );  
    141156        if ( !$res || !$res->success ) { 
    142             print STDERR "Communications failure with Defensio\n"; 
    143157            MT->log("Communications failure with Defensio"); 
    144158        } elsif ( $res->status eq 'fail' ) { 
    145             print STDERR "Defensio error: " . $res->message . "\n"; 
    146159            MT->log("Defensio error: " . $res->message); 
    147160        } 
    148         print STDERR "Done.\n"; 
    149161    } 
    150162} 
     
    155167    my ($cb, $app, $thing) = @_; 
    156168 
    157     print STDERR "Report false positive through Defensio\n"; 
    158169    my $key    = get_apikey()  or return; 
    159170    require Net::Defensio; 
    160171    if (!$thing->defensio_sig) { # comment has NOT been rated by Defensio before 
    161         print STDERR "Never seen this comment before in Defensio - auditing...\n"; 
    162172        my ($score,$grade) = defensio_score($thing); 
    163173    } 
     
    171181            );  
    172182        if ( !$res || !$res->success ) { 
    173             print STDERR "Communications failure with Defensio\n"; 
    174183            MT->log("Communications failure with Defensio"); 
    175184        } elsif ( $res->status eq 'fail' ) { 
    176             print STDERR "Defensio error: " . $res->message . "\n"; 
    177185            MT->log("Defensio error: " . $res->message); 
    178186        } 
    179         print STDERR "Done.\n"; 
    180187    } 
    181188} 
     
    186193    my $key    = get_apikey() or return MT::JunkFilter::ABSTAIN(); 
    187194 
    188     print STDERR "Routing comment through Defensio...\n"; 
    189195    my $cli    = Net::Defensio->new( api_key => $key );  
    190196    my $params = _build_audit_params($thing);