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

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

fix last bit of hardcoding

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