source: sites/oxford.openguides.org/lib/OpenGuides/SpamPlugin/Akismet.pm @ 1176

Last change on this file since 1176 was 1176, checked in by Dominic Hargreaves, 13 years ago

no reason here

  • Property svn:keywords set to HeadURL LastChangedRevision LastChangedDate LastChangedBy
File size: 1.6 KB
Line 
1# $HeadURL: sites/oxford.openguides.org/lib/OpenGuides/SpamPlugin/Akismet.pm $
2# $LastChangedRevision: 1176 $
3# $LastChangedDate: 2008-06-22 00:10:02 +0000 (Sun, 22 Jun 2008) $
4# $LastChangedBy: dom $
5
6package OpenGuides::SpamPlugin::Akismet;
7
8use strict;
9use warnings;
10
11use Net::Akismet;
12use Data::Dumper;
13use Config::Tiny;
14use MIME::Lite;
15
16sub notify_admins {
17    my ( $class, %args ) = @_;
18    my $message = MIME::Lite->new(
19        From     => $args{email},
20        To       => $args{email},
21        Subject  => "Attempted spam edit on " . $args{'url'},
22        Data     => "Someone just tried to edit " . $args{'url'} . ", and "
23                    . "Akismet said no.\n\n"
24                    . "Here's a dump of the details:\n"
25                    . Dumper( \%args ),
26    );
27    $message->send;
28}
29
30sub looks_like_spam {
31    my ( $class, %args ) = @_;
32    # http://dev.openguides.org/ticket/253
33    # shouldn't have to fish this out ourselves
34    # hacking core OpenGuides code is for another day
35    my $config = Config::Tiny->read('wiki.conf');
36    my $api_key = $config->{_}->{'spam_detector_akismet_key'};
37    my $url = $config->{_}->{'script_url'};
38    my $email = $config->{_}->{'contact_email'};
39
40    my $akismet = Net::Akismet->new(
41        KEY => $api_key,
42        URL => $url,
43    )
44        or die "Could not verify API key\n";
45    my %check_data = (
46        USER_IP => $ENV{'REMOTE_ADDR'},
47        COMMENT_USER_AGENT => $ENV{'HTTP_USER_AGENT'},
48        COMMENT_CONTENT => $args{content},
49        COMMENT_AUTHOR => $args{metadata}->{username},
50    );
51    my $result = $akismet->check( %check_data );
52
53    if ( $result eq 'true' ) {
54        $class->notify_admins( %args, url => $url, email => $email );
55        return 1;
56    } else {
57        return 0;
58    }
59}
60
611;
Note: See TracBrowser for help on using the repository browser.