[Koha-patches] [PATCH] [3.0.x](bug #3144) Added antispam filter for anonymous suggestions

Jean-André Santoni jeanandre.santoni at biblibre.com
Mon Jun 22 13:35:29 CEST 2009


This antispam is based on Mollom. You will need to register and get an API key to access it, then set the Mollom* sysprefs.
This patch only use the statistic way to filter spam. A future patch could add a captcha if Mollom can't determinate if content is spam or ham.
---
 installer/data/mysql/en/mandatory/sysprefs.sql     |    4 ++
 installer/data/mysql/updatedatabase.pl             |    9 +++++
 .../prog/en/modules/opac-suggestions.tmpl          |    1 +
 opac/opac-suggestions.pl                           |   33 ++++++++++++++++++--
 4 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/installer/data/mysql/en/mandatory/sysprefs.sql b/installer/data/mysql/en/mandatory/sysprefs.sql
index 7d8016e..2d55548 100644
--- a/installer/data/mysql/en/mandatory/sysprefs.sql
+++ b/installer/data/mysql/en/mandatory/sysprefs.sql
@@ -215,3 +215,7 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('
 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('MergeAuthoritiesOnUpdate', '1', 'if ON, Updating authorities will automatically updates biblios',NULL,'YesNo');
 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowNotForLoanOverride', '0', 'if ON, enables the librarian to choose when they want to check out a notForLoan regular item',NULL,'YesNo');
 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('RenewalPeriodBase', 'date_due', 'Set whether the renewal date should be counted from the date_due or from the moment the Patron asks for renewal ','date_due|now','Choice');
+
+INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('Mollom',0,'Turn ON Mollom antispam for anonimous suggestions - You MUST set MollomPublicKey and MollomPrivateKey if enabled','','YesNo');
+INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('MollomPublicKey','','See:  http://mollom.com','','free');
+INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('MollomPrivateKey','','See:  http://mollom.com','','free');
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index aa3e547..02577c5 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -1965,6 +1965,15 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ILS-DI','0','if ON, ILS-DI server is enabled',NULL,'YesNo');");
     SetVersion ($DBversion);
 }
+
+$DBversion = "3.01.00.039";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('Mollom',0,'Turn ON Mollom antispam for anonimous suggestions - You MUST set MollomPublicKey and MollomPrivateKey if enabled','','YesNo');");
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('MollomPublicKey','','See:  http://mollom.com','','free');");
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('MollomPrivateKey','','See:  http://mollom.com','','free');");
+    SetVersion ($DBversion);
+}
+
 if (C4::Context->preference("Version") =~/3\.00/) {
 	warn "inside 3.00";
         my $perllibdir=C4::Context->config('intranetdir');
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-suggestions.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-suggestions.tmpl
index 56d56fc..0189549 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-suggestions.tmpl
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-suggestions.tmpl
@@ -73,6 +73,7 @@ $.tablesorter.addParser({
 
 <!-- TMPL_IF name="op_else" -->
     <h1><!-- TMPL_UNLESS NAME="OPACViewOthersSuggestions" --><!-- TMPL_IF NAME="loggedinusername" -->My <!-- /TMPL_IF --><!-- /TMPL_UNLESS -->Purchase Suggestions</h1>
+    <!-- TMPL_IF NAME="spam" -->Sorry, your suggestion has been considered as spam. Please login to your account and try again.<!-- /TMPL_IF -->
     <!-- TMPL_IF NAME="suggestions_loop" -->
     <!-- TMPL_IF NAME="OPACViewOthersSuggestions" -->
 	<form action="/cgi-bin/koha/opac-suggestions.pl" method="get">
diff --git a/opac/opac-suggestions.pl b/opac/opac-suggestions.pl
index b739817..218230b 100755
--- a/opac/opac-suggestions.pl
+++ b/opac/opac-suggestions.pl
@@ -23,6 +23,7 @@ use C4::Auth;    # get_template_and_user
 use C4::Branch;
 use C4::Output;
 use C4::Suggestions;
+use Net::Mollom;
 
 my $input           = new CGI;
 my $title           = $input->param('title');
@@ -67,13 +68,12 @@ else {
     );
 }
 
-if ( $op eq "add_confirm" ) {
+sub create_suggestion {
     &NewSuggestion(
         $borrowernumber, $title,         $author,     $publishercode,
         $note,           $copyrightdate, $volumedesc, $publicationyear,
         $place,          $isbn,          ''
     );
-
     # empty fields, to avoid filter in "SearchSuggestion"
     $title           = '';
     $author          = '';
@@ -86,6 +86,33 @@ if ( $op eq "add_confirm" ) {
     $op              = 'else';
 }
 
+if ( $op eq "add_confirm" ) {
+    # If antispam is enabled and user not logged
+    if (C4::Context->preference('Mollom')
+    and $borrowernumber == C4::Context->preference("AnonSuggestions")) {
+        # Instanciates Mollom Antispam
+        my $mollom = Net::Mollom->new(
+                'public_key'  => C4::Context->preference("MollomPublicKey"),
+                'private_key' => C4::Context->preference("MollomPrivateKey"),
+            );
+        # Checks the suggestion content
+        my $check = $mollom->check_content(
+            post_title => $title,
+            post_body  => $author . ' ' . $publishercode . ' ' . $note
+        );
+        # You can add a $check->is_unsure case to display a captcha
+        if ($check->is_ham) {
+            create_suggestion;
+        } else {
+            $template->param(spam => 1);
+            $op = 'else';
+        }
+    # If the user is logged or antispam is turned off, create the suggestion
+    } else {
+        create_suggestion;
+    }
+}
+
 if ( $op eq "delete_confirm" ) {
     my @delete_field = $input->param("delete_field");
     foreach my $delete_field (@delete_field) {
@@ -106,7 +133,7 @@ $template->param(
     status           => $status,
     suggestedbyme    => $suggestedbyme,
     "op_$op"         => 1,
-	suggestionsview => 1
+    suggestionsview  => 1
 );
 
 output_html_with_http_headers $input, $cookie, $template->output;
-- 
1.6.0.4




More information about the Koha-patches mailing list