Skip to content

Commit

Permalink
Start to add spam filtering to feedback form
Browse files Browse the repository at this point in the history
Toward #371
  • Loading branch information
waldoj committed Jan 11, 2020
1 parent da45435 commit 6647a22
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@
"components/jqueryui": "~1.8",
"simplepie/simplepie": "1.5",
"romainneutron/sphinx-search-api-php-client": "2.0.8.1",
"tijsverkoyen/akismet": "~1"
},
"autoload": {
"psr-4": {
"TijsVerkoyen\\": "htdocs/includes/vendor/tijsverkoyen/"
},
"classmap": [
"htdocs/includes/vendor/"
],
Expand Down
26 changes: 25 additions & 1 deletion htdocs/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# page to function.
include_once 'includes/settings.inc.php';
include_once 'vendor/autoload.php';
use TijsVerkoyen\Akismet;

# DECLARATIVE FUNCTIONS
# Run those functions that are necessary prior to loading this specific
Expand Down Expand Up @@ -149,6 +150,28 @@ function show_form($form_data)
}
else
{

/*
* Query Akismet to see if this is spam.
*/
$akismet = new Akismet();
$akismet->apiKey = KISMET_KEY;
$akismet->url = 'https://www.richmondsunlight.com/';

$is_spam = $akismet->isSpam(
$form_data['comments'],
$form_data['name'],
$form_data['email']
);

/*
* This is spam. End silently.
*/
if ($is_spam)
{
die();
}

$form_data['comments'] = 'From: "' . $form_data['name'] . '" <' . $form_data['email'] . '>'
. "\n\n" . $form_data['comments'];

Expand All @@ -162,6 +185,7 @@ function show_form($form_data)
'X-Originating-URL: ' . $_SERVER['REQUEST_URI']
);
$page_body .= '<p>E-mail sent. Thanks for writing!</p>';

}
}
else
Expand All @@ -183,7 +207,7 @@ function show_form($form_data)
}

$page_body = '<p>Found a mistake? Have some extra information? Just want to call to say “I love
you”? Bring it on. <em>Completing this form will send an e-mail to Richmond Sunlight,
you”? Bring it on. <em>Completing this form will send an email to Richmond Sunlight,
not to any member of the General Assembly</em>.</p>';
$page_body .= @show_form($form_data);
}
Expand Down

0 comments on commit 6647a22

Please sign in to comment.