diff --git a/composer.json b/composer.json index a6583f2c..ccb68cdd 100644 --- a/composer.json +++ b/composer.json @@ -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/" ], diff --git a/htdocs/contact.php b/htdocs/contact.php index 4be86f73..3d628008 100644 --- a/htdocs/contact.php +++ b/htdocs/contact.php @@ -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 @@ -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']; @@ -162,6 +185,7 @@ function show_form($form_data) 'X-Originating-URL: ' . $_SERVER['REQUEST_URI'] ); $page_body .= '

E-mail sent. Thanks for writing!

'; + } } else @@ -183,7 +207,7 @@ function show_form($form_data) } $page_body = '

Found a mistake? Have some extra information? Just want to call to say “I love - you”? Bring it on. Completing this form will send an e-mail to Richmond Sunlight, + you”? Bring it on. Completing this form will send an email to Richmond Sunlight, not to any member of the General Assembly.

'; $page_body .= @show_form($form_data); }