CyberSlug Labs Software Projects

CyberSlug Labs » Software » Loudblog ReCAPTCHA plugin and patch for 0.6.1

<lb:recaptcha />

To install this plugin:
  • Go to the ReCAPTCHA site.
    • Install recaptchalib.php to your plugins folder.
    • Sign up for your free account keys.
  • Install lb_recaptcha.php to your plugins folder.
  • Edit lb_recaptcha.php with your account keys.
  • Edit loudblog/inc/loudblogtags.php as follows.

    In function area_comments (hint: find for "preventspam"),
    replace the section that looks like:

    if ($settings['preventspam'] == "1") {

        if (isset($_POST['commentspam'])) {
            $givenanswer = trim(strtolower($_POST['commentspam']));
            $rightanswer = trim(strtolower($settings['spamanswer']));
            if ($givenanswer != $rightanswer) {
                $commentingokay = false;
                echo "<p style=\"font-size: 20px;\">Possible spam attack! Don't do this again!</p>\n";
            }            
        } else {
            $commentingokay = false;
            echo "<p style=\"font-size: 20px;\">Possible spam attack! (The administrator of this podcast has to deactivate anti spam or add an appropriate input field to the template.)</p>\n";

    }

    with:

    Download lbtag_after.txt

    if ($settings['preventspam'] == "1") {

        $recaptcha = recaptcha();
        if($recaptcha != "OK") {
            $commentingokay = false;
            $return .= "<div id=\"recaptchaerror\">$recaptcha</div>\n";
        }

    }

  • Edit your template as follows.

    Replace the section that looks like:

    <lb:if_preventspam>
    <div id="spamquestion" class="input">
        <label for="commentspam"><lb:spamquestion /></label>
        <lb:inputspam />
    </div>
    </lb:if_preventspam>

    with:

    Download recaptcha_template.txt

    <lb:if_preventspam>
    <div id="spamquestion" class="input">
        <lb:recaptcha />
    </div>
    </lb:if_preventspam>

Download lb_recaptcha.php.txt

<?php
/******************************************
lb_recaptcha v0.2 (2007.06.26)
< cyber slug labs at g mail dot com >
http://cyberslug.net

This plugin adds support for ReCAPTCHA to
Loudblog. A small hack to loudblogtags.php
is required to replace the built-in anti-spam
check with the CAPTCHA check.

URL: http://cyberslug.net/software/recaptcha.php

About:
ReCAPTCHA is a free service that protects
against spam while helping proofread OCR
scans done by the Internet Archive.

You will need to download recaptchalib.php
to your plugins directory and sign up for
your free account keys to use this plugin.

URL: http://recaptcha.net/plugins/php/
******************************************/

require_once('recaptchalib.php');

function recaptcha () {
    global $settings;

    $publickey = "";
    $privatekey = "";

    $return = "";
    $error = null;

    if (isset($_POST['commentpreview'])) {
        $return = recaptcha_get_html($publickey, $error);
    }

    if (isset($_POST['commentsubmit'])) {
        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) {
                 $return = "OK";
            } else {
                 $return = "Anti-Spam Error! (".$resp->error.") - Please try again.";
            }
        } else {
            $return = "Please make certain to answer the anti-spam question.";
        }
    }

    return $return;
}

?>

Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License.

 
©2007 CyberSlug Labs