Hi,
I have tried to extend the existing spamblock plugin by using the recaptcha plugin.
Here is the patch (of recaptcha 1.16 and serendipity 1.1.2)
lang_en.inc.php.diff:
--- lang_en.inc.php 2007-05-29 18:26:17.127768400 +0200
+++ lang_en.inc.php.orig 2007-05-29 12:28:17.279592400 +0200
@@ -5,6 +5,7 @@
* @author Translator Name <
yourmail@example.com>
* EN-Revision: Revision of lang_en.inc.php
*/
+
@define('PLUGIN_EVENT_SPAMBLOCK_TITLE', 'Spam Protector');
@define('PLUGIN_EVENT_SPAMBLOCK_DESC', 'A variety of methods to prevent comment spam');
@define('PLUGIN_EVENT_SPAMBLOCK_ERROR_BODY', 'Spam Prevention: Invalid message.');
@@ -19,12 +20,6 @@
@define('PLUGIN_EVENT_SPAMBLOCK_IPFLOOD_DESC', 'Only allow an IP to submit a comment every n minutes. Useful to prevent comment floods.');
@define('PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS', 'Enable Captchas');
@define('PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_DESC', 'Will force the user to input a random string displayed in a specially crafted image. This will disallow automated submits to your blog. Please remember that people with decreased vision may find it hard to read those captchas.');
-@define('PLUGIN_EVENT_SPAMBLOCK_RECAPTCHA', 'Use Recaptcha');
-@define('PLUGIN_EVENT_SPAMBLOCK_RECAPTCHA_DESC', 'If set, a recaptcha will be generated. This is a special kind of captcha, that will help digitize books. See
http://www.recaptcha.net for more details. As with normal captchas, remember that people with decreased vision may find it hard to read.');
-@define('PLUGIN_EVENT_SPAMBLOCK_RECAPTCHA_PUB', 'Public key for recaptcha');
-@define('PLUGIN_EVENT_SPAMBLOCK_RECAPTCHA_PRIV', 'Private key for recaptcha');
-@define('PLUGIN_EVENT_SPAMBLOCK_RECAPTCHA_PUB_DESC', 'Provide a public key pair for communicating with the recaptcha.net site. You can request a public/private key pair at
http://www.recaptcha.net/api/getkey');
-@define('PLUGIN_EVENT_SPAMBLOCK_RECAPTCHA_PRIV_DESC', 'Provide a private key pair for communicating with the recaptcha.net site. You can request a public/private key pair at
http://www.recaptcha.net/api/getkey');
@define('PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC', 'To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.');
@define('PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC2', 'Enter the string you see here in the input box!');
@define('PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC3', 'Enter the string from the spam-prevention image above: ');
------------------------------------------------------------------------------------
serendipity_event_spamblock.php:
--- serendipity_event_spamblock.php 2007-05-29 18:16:59.770099300 +0200
+++ serendipity_event_spamblock.php.orig 2007-05-29 12:23:20.252671700 +0200
@@ -12,11 +12,6 @@
}
include dirname(__FILE__) . '/lang_en.inc.php';
-require_once dirname(__FILE__) . '/recaptchalib.php';
-$GLOBALS['recaptcha_api_server'] = '
http://api.recaptcha.net';
-$GLOBALS['recaptcha_api_secure_server'] = '
https://api-secure.recaptcha.net';
-$GLOBALS['recaptcha_verify_server'] = 'api-verify.recaptcha.net';
-
/* BC - TODO: Remove for 0.8 final */
if (!function_exists('serendipity_serverOffsetHour')) {
@@ -61,9 +56,6 @@
'ipflood',
'csrf',
'captchas',
- 'recaptcha',
- 'recaptcha_pub',
- 'recaptcha_priv',
'captchas_ttl',
'captcha_color',
'forcemoderation',
@@ -172,31 +164,6 @@
'desc' => array(YES, NO, PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_SCRAMBLE)
));
break;
-
- case 'recaptcha':
- $propbag->add('type', 'radio');
- $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_RECAPTCHA);
- $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_RECAPTCHA_DESC);
- $propbag->add('default', 'no');
- $propbag->add('radio', array(
- 'value' => array('yes', 'no'),
- 'desc' => array(YES, NO)
- ));
- break;
-
- case 'recaptcha_pub':
- $propbag->add('type', 'string');
- $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_RECAPTCHA_PUB);
- $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_RECAPTCHA_PUB_DESC);
- $propbag->add('default', '');
- break;
-
- case 'recaptcha_priv':
- $propbag->add('type', 'string');
- $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_RECAPTCHA_PRIV);
- $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_RECAPTCHA_PRIV_DESC);
- $propbag->add('default', '');
- break;
case 'hide_for_authors':
$_groups =& serendipity_getAllGroups();
@@ -598,13 +565,11 @@
if (isset($hooks[$event])) {
$captchas_ttl = $this->get_config('captchas_ttl', 7);
$_captchas = $this->get_config('captchas', 'yes');
- $_recaptcha = $this->get_config('recaptcha', 'no');
- $captchas = ($_captchas !== 'no' && ($_captchas === 'yes' || $_captchas === 'scramble' || serendipity_db_bool($_captchas)) && ($_recaptcha ==='no'));
- $recaptcha = ($_captchas !== 'no' && ($_captchas === 'yes' || $_captchas === 'scramble' || serendipity_db_bool($_captchas)) && ($_recaptcha ==='yes' || $_recaptcha !== 'no' || serendipity_db_bool($_recaptcha)));
+ $captchas = ($_captchas !== 'no' && ($_captchas === 'yes' || $_captchas === 'scramble' || serendipity_db_bool($_captchas)));
// Check if the entry is older than the allowed amount of time. Enforce kaptchas if that is true
// of if kaptchas are activated for every entry
- $show_captcha = (($captchas || $recaptcha) && isset($eventData['timestamp']) && ($captchas_ttl < 1 || ($eventData['timestamp'] < (time() - ($captchas_ttl*60*60*24)))) ? true : false);
+ $show_captcha = ($captchas && isset($eventData['timestamp']) && ($captchas_ttl < 1 || ($eventData['timestamp'] < (time() - ($captchas_ttl*60*60*24)))) ? true : false);
$forcemoderation = $this->get_config('forcemoderation', 60);
$forcemoderation_treat = $this->get_config('forcemoderation_treat', 'moderate');
@@ -620,7 +585,8 @@
$use_gd = true;
} else {
$max_char = $min_char = 5;
- $use_gd = false; }
+ $use_gd = false;
+ }
switch($event) {
case 'fetchcomments':
@@ -864,38 +830,16 @@
// Captcha checking
if ($show_captcha && $addData['type'] == 'NORMAL') {
- if ($captchas) {
- if (!isset($_SESSION['spamblock']['captcha']) || !isset($serendipity['POST']['captcha']) || strtolower($serendipity['POST']['captcha']) != strtolower($_SESSION['spamblock']['captcha'])) {
- $this->log($logfile, $eventData['id'], 'REJECTED', sprintf(PLUGIN_EVENT_SPAMBLOCK_REASON_CAPTCHAS, $serendipity['POST']['captcha'], $_SESSION['spamblock']['captcha']), $addData);
- $eventData = array('allow_comments' => false);
- $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_CAPTCHAS;
- return false;
- } else {
- // DEBUG
- // $this->log($logfile, $eventData['id'], 'REJECTED', 'Captcha passed: ' . $serendipity['POST']['captcha'] . ' / ' . $_SESSION['spamblock']['captcha'] . ' // Source: ' . $_SERVER['REQUEST_URI'], $addData);
- }
- }
- // check recaptcha
- else {
- $privatekey = $this->get_config('recaptcha_priv');
- if ($_POST["recaptcha_response_field"]) {
- $resp = recaptcha_check_answer ($privatekey,
- $_SERVER["REMOTE_ADDR"],
- $_POST["recaptcha_challenge_field"],
- $_POST["recaptcha_response_field"]);
-
- if (!$resp->is_valid) {
- # set the error code so that we can display it
- $error = $resp->error;
- $this->log($logfile, $eventData['id'], 'REJECTED', $error, $addData);
- $eventData = array('allow_comments' => false);
- $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_CAPTCHAS;
- return false;
- }
+ if (!isset($_SESSION['spamblock']['captcha']) || !isset($serendipity['POST']['captcha']) || strtolower($serendipity['POST']['captcha']) != strtolower($_SESSION['spamblock']['captcha'])) {
+ $this->log($logfile, $eventData['id'], 'REJECTED', sprintf(PLUGIN_EVENT_SPAMBLOCK_REASON_CAPTCHAS, $serendipity['POST']['captcha'], $_SESSION['spamblock']['captcha']), $addData);
+ $eventData = array('allow_comments' => false);
+ $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_CAPTCHAS;
+ return false;
+ } else {
+// DEBUG
+// $this->log($logfile, $eventData['id'], 'REJECTED', 'Captcha passed: ' . $serendipity['POST']['captcha'] . ' / ' . $_SESSION['spamblock']['captcha'] . ' // Source: ' . $_SERVER['REQUEST_URI'], $addData);
}
- }
- }
- else {
+ } else {
// DEBUG
// $this->log($logfile, $eventData['id'], 'REJECTED', 'Captcha not needed: ' . $serendipity['POST']['captcha'] . ' / ' . $_SESSION['spamblock']['captcha'] . ' // Source: ' . $_SERVER['REQUEST_URI'], $addData);
}
@@ -993,45 +937,33 @@
}
if ($show_captcha) {
- if ($captchas) {
- echo '<div class="serendipity_commentDirection serendipity_comment_captcha">';
- if (!isset($serendipity['POST']['preview']) || strtolower($serendipity['POST']['captcha'] != strtolower($_SESSION['spamblock']['captcha']))) {
- echo '<br />' . PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC . '<br />';
- if ($use_gd) {
- printf('<img src="%s" title="%s" alt="CAPTCHA" class="captcha" />',
- $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/captcha_' . md5(time()),
+ echo '<div class="serendipity_commentDirection serendipity_comment_captcha">';
+ if (!isset($serendipity['POST']['preview']) || strtolower($serendipity['POST']['captcha'] != strtolower($_SESSION['spamblock']['captcha']))) {
+ echo '<br />' . PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC . '<br />';
+ if ($use_gd) {
+ printf('<img src="%s" title="%s" alt="CAPTCHA" class="captcha" />',
+ $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/captcha_' . md5(time()),
+ htmlspecialchars(PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC2)
+ );
+ } else {
+ $bgcolors = explode(',', $this->get_config('captcha_color', '255,0,255'));
+ $hexval = '#' . dechex(trim($bgcolors[0])) . dechex(trim($bgcolors[1])) . dechex(trim($bgcolors[2]));
+ $this->random_string($max_char, $min_char);
+ echo '<div style="background-color: ' . $hexval . '">';
+ for ($i = 1; $i <= $max_char; $i++) {
+ printf('<img src="%s" title="%s" alt="CAPTCHA ' . $i . '" class="captcha" />',
+ $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/captcha_' . $i . '_' . md5(time()),
htmlspecialchars(PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC2)
);
- } else {
- $bgcolors = explode(',', $this->get_config('captcha_color', '255,0,255'));
- $hexval = '#' . dechex(trim($bgcolors[0])) . dechex(trim($bgcolors[1])) . dechex(trim($bgcolors[2]));
- $this->random_string($max_char, $min_char);
- echo '<div style="background-color: ' . $hexval . '">';
- for ($i = 1; $i <= $max_char; $i++) {
- printf('<img src="%s" title="%s" alt="CAPTCHA ' . $i . '" class="captcha" />',
- $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/captcha_' . $i . '_' . md5(time()),
- htmlspecialchars(PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC2)
- );
- }
- echo '</div>';
}
- echo '<br />';
- echo '<label for="captcha">'. PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC3 . '</label><br /><input type="text" size="5" name="serendipity[captcha]" value="" id="captcha" />';
- }
- elseif (isset($serendipity['POST']['captcha'])) {
- echo '<input type="hidden" name="serendipity[captcha]" value="' . htmlspecialchars($serendipity['POST']['captcha']) . '" />';
+ echo '</div>';
}
- echo '</div>';
- }
- elseif ($recaptcha){
- $pubkey = $this->get_config('recaptcha_pub');
- $privkey = $this->get_config('recaptcha_priv');
- // The response from recaptcha.net
- $resp = null;
- // The error code from recaptcha.net, if any
- $error = null;
- echo recaptcha_get_html($pubkey);
+ echo '<br />';
+ echo '<label for="captcha">'. PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC3 . '</label><br /><input type="text" size="5" name="serendipity[captcha]" value="" id="captcha" />';
+ } elseif (isset($serendipity['POST']['captcha'])) {
+ echo '<input type="hidden" name="serendipity[captcha]" value="' . htmlspecialchars($serendipity['POST']['captcha']) . '" />';
}
+ echo '</div>';
}
return true;
-----------------------------------------------------------------------------------
This is my first contribution to serendipity and I had a hard time figuring out the plugin_api

. But it works for me.
All you need to do is get a copy of recaptchalib.php from <a href="
http://recaptcha.net/plugins/php/">recaptcha.net</a> and place it in the serendipity_event_spamblock folder. Next you need to apply for your public/private key combination at <a href="
http://recaptcha.net/api/getkey">recaptcha.net</a>.
Now apply the patch and enter the keys into the fields in the configuration dialog for the spamblock plugin.