Topic: reCaptcha extension 0.4

Here's my second extension that adds a reCaptcha box when guests are registering or posting (No reCaptcha's for registered users).

File is here : http://tinyurl.com/n7kj7d

1 problems remaining :
There's something wrong with the css that displays the reCaptcha badly.
I had to set a fixed height to the container so it's working allright, but maybe is there a cleaner solution

.sf-set.recaptcha{
    height:150px;
}

Last edited by gordie.lachance (2009-07-20 12:31:26)

Re: reCaptcha extension 0.4

gordie.lachance wrote:

I do add css, but it outputs before everything :

        <hook id="hd_head" priority="5">
        <![CDATA[
        if ($forum_user['is_guest']) {
            echo '<link rel="stylesheet" type="text/css" media="screen" href="'.$ext_info['url'].'/recaptcha.css" />';
        }
        ]]>

<link rel="stylesheet" type="text/css" media="screen" href="http://www.mysite.com/fluxBB/extensions/recaptcha/recaptcha.css" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">


instead of echoing it directly, add it to the $forum_head, something like:

$forum_head['recaptchacss'] = '<link rel="stylesheet" type="text/css" media="screen" href="'.$ext_info['url'].'/recaptcha.css" />';

Re: reCaptcha extension 0.4

Ok, thanks.
I updated it, it's working !

Re: reCaptcha extension 0.4

You should realy make it so that people do not have to edit manifest.xml to get it working.

make some fields in the config table and an little admin area where people can enter their keys.

I have edited your manifest.xml to do just that, please check it if everything works ok.
I also found that you had entered maby your own private and publickey in the manifest. Not sure if they are used!
You should also make it translatable but that is up to you.

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<!--
/***********************************************************************

    @author        : Gordie Lachance
    @copyright     : (c) Copyright by Gordie Lachance
    @license       : http://www.gnu.org/licenses/gpl-2.0.html

************************************************************************/
-->
<extension engine="1.0">
    <id>recaptcha</id>
    <title>reCaptcha</title>
    <version>0.2</version>
    <description>This adds reCaptcha Spam Protection to your fluxBB installation, only when a guest registers or posts.</description>
    <author>Gordie Lachance</author>
    <minversion>1.3 Beta</minversion>
    <maxtestedon>1.3 Beta</maxtestedon>
    <note type="install">Don't forget to edit the reCaptcha's public and private keys in the config.php file.</note>
    <note type="install">You can get it here : http://recaptcha.net/whyrecaptcha.html.</note>

    <install>
        <![CDATA[
            if (defined('EXT_CUR_VERSION'))
            {
                // you can make special update code for each previous extension version
            }
            else
            { // it's a fresh install
                $forum_db->query('INSERT INTO '.$forum_db->prefix.'config VALUES (\'recaptcha_privatekey\', \'\')') or error(__FILE__, __LINE__);
                $forum_db->query('INSERT INTO '.$forum_db->prefix.'config VALUES (\'recaptcha_publickey\', \'\')') or error(__FILE__, __LINE__);
            }
        ]]>
    </install>

    <uninstall>
        <![CDATA[
            $sql = array(
                'DELETE'        =>    'config',
                'WHERE'        =>    'conf_name IN (\'recaptcha_privatekey\', \'recaptcha_publickey\')'
            );
            $forum_db->query_build($sql) or error(__FILE__, __LINE__);
        ]]>
    </uninstall>

    <hooks>
        <hook id="hd_head" priority="5">
        <![CDATA[
        if ($forum_user['is_guest'])
        {
            $forum_head['recaptchacss'] = '<link rel="stylesheet" type="text/css" media="screen" href="'.$ext_info['url'].'/recaptcha.css" />';
        }
        ]]>
        </hook>
        <hook id="po_start" priority="5">
            <![CDATA[
                if ($forum_user['is_guest'])
                {
                    if (file_exists($ext_info['path'].'/recaptchalib.php'))
                        require_once($ext_info['path'].'/recaptchalib.php');

                    if (file_exists($ext_info['path'].'/recaptchalib.php'))
                        require_once($ext_info['path'].'/config.php');
                }
            ]]>
        </hook>
        <hook id="po_form_submitted" priority="5">
            <![CDATA[
                if ($forum_user['is_guest'])
                {
                    $resp = recaptcha_check_answer ($privatekey,
                    $_SERVER["REMOTE_ADDR"],
                    $_POST["recaptcha_challenge_field"],
                    $_POST["recaptcha_response_field"]);

                    if (!$resp->is_valid)
                        $errors[] ="The <b>reCAPTCHA</b> wasn't entered correctly. Go back and try it again.";
                }
            ]]>
        </hook>
        <hook id="po_req_info_fieldset_end" priority="5">
            <![CDATA[
                if ($forum_user['is_guest']) {
                        ?>
                    <div class="frm-group">
                        <div class="sf-set recaptcha">
                            <div class="sf-box text required">
                                <label for="fld1"><span>reCaptcha: <em>(Are you human ?)</em></span></label><br/>
                                <span class="fld-input">
                                    <?php
                                        echo recaptcha_get_html($publickey);
                                    ?>
                                </span>
                            </div>
                        </div>
                    </div>
                        <?php
                }
            ]]>
        </hook>
        <hook id="rg_start" priority="5">
            <![CDATA[
                if (file_exists($ext_info['path'].'/recaptchalib.php')) {
                    require_once($ext_info['path'].'/recaptchalib.php');
                }
                $publickey = $forum_config['recaptcha_publickey'];
                $privatekey = $forum_config['recaptcha_privatekey'];
            ]]>
        </hook>
        <hook id="rg_register_form_submitted" priority="5">
            <![CDATA[
                $resp = recaptcha_check_answer ($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],$_POST["recaptcha_response_field"]);
                echo $resp;
            ]]>
        </hook>
        <hook id="rg_register_end_validation" priority="5">
            <![CDATA[
                if (!$resp->is_valid) {
                    $errors[] ="The <b>reCAPTCHA</b> wasn't entered correctly. Go back and try it again.";
                }
            ]]>
        </hook>
        <hook id="rg_register_group_end" priority="5">
            <![CDATA[
                ?>
                <div class="frm-group">
                    <div class="sf-set recaptcha">
                        <div class="sf-box text required">
                            <label for="fld1"><span>reCaptcha: <em>(Are you human ?)</em></span></label><br/>
                            <span class="fld-input">
                                <?php
                                    echo recaptcha_get_html($publickey);
                                ?>
                            </span>
                        </div>
                    </div>
                </div>
                <?php
            ]]>
        </hook>

        <hook id="aop_features_general_fieldset_end">
            <![CDATA[
?>
    <div class="content-head">
        <h2 class="hn"><span>ReCaptcha</span></h2>
    </div>
    <fieldset class="sf-set group-item<?php echo ++$forum_page['group_count'] ?>">
        <legend><span>ReCaptcha:</span></legend>
            <div class="sf-box text">
                <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span>Public key</span></label>
                <span class="fld-input"><input size="25" type="text" id="fld<?php echo $forum_page['fld_count'] ?>" name="form[recaptcha_publickey]" value="<?php echo $forum_config['recaptcha_publickey'];?>" /></span>
            </div>
            <div class="sf-box text">
                <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span>Private key</span></label>
                <span class="fld-input"><input size="25" type="text" id="fld<?php echo $forum_page['fld_count'] ?>" name="form[recaptcha_privatekey]" value="<?php echo $forum_config['recaptcha_privatekey'];?>" /></span>
            </div>
    </fieldset>
<?php

            ]]>
        </hook>
        <hook id="aop_features_validation">
            <![CDATA[
                if (!isset($form['recaptcha_publickey']) || empty($form['recaptcha_publickey']))
                    $form['recaptcha_publickey'] = '';
                if (!isset($form['recaptcha_privatekey']) || empty($form['recaptcha_privatekey']))
                    $form['recaptcha_privatekey'] = '';
            ]]>
        </hook>
        <hook id="aop_pre_update_configuration">
            <![CDATA[
                if (isset($form['recaptcha_publickey']))
                {
                    if ($form['recaptcha_publickey'] != $forum_config['recaptcha_publickey'])
                        $forum_db->query('UPDATE '.$forum_db->prefix.'config SET conf_value = \''.$forum_db->escape($form['recaptcha_publickey']).'\' WHERE conf_name = \'recaptcha_publickey\'', true) or error(__FILE__, __LINE__);
                }
                if (isset($form['recaptcha_privatekey']))
                {
                    if ($form['recaptcha_privatekey'] != $forum_config['recaptcha_privatekey'])
                        $forum_db->query('UPDATE '.$forum_db->prefix.'config SET conf_value = \''.$forum_db->escape($form['recaptcha_privatekey']).'\' WHERE conf_name = \'recaptcha_privatekey\'', true) or error(__FILE__, __LINE__);
                }
            ]]>
        </hook>
    </hooks>
</extension>

Last edited by kierownik (2009-02-25 16:18:34)

Re: reCaptcha extension 0.4

Hi kierownik !
Nice work !!! Thanks !
Seems ok (admin part) but there is an error to retrieve the values :

Undefined variable: publickey

Seems there is no function to call them.  I don't know how this works...

Re: reCaptcha extension 0.4

Ok I found how.  Version updated to 0.3.
Thanks again !

Re: reCaptcha extension 0.4

No problem, hope that it helps you build more extensions smile

Are you also going to make it translatable?!?

Last edited by kierownik (2009-02-25 18:42:11)

Re: reCaptcha extension 0.4

I don't know how that works...
I'm new to fluxBB extensions !

Re: reCaptcha extension 0.4

Create a language folder with files for each language holding all the strings in an array

Then load the appropiate language file at the beginning like this:

if (file_exists('my_extension/lang/'.$forum_user['language'].'.php'))
   include 'my_extension/lang/'.$forum_user['language'].'.php';
else
   include 'my_extension/lang/English.php';

http://www.fluxbb.de - Deutschsprachiges FluxBB-Supportforum

Re: reCaptcha extension 0.4

Here you are ! (same URL than first post)

Re: reCaptcha extension 0.4

Nice work wink

http://www.fluxbb.de - Deutschsprachiges FluxBB-Supportforum

Re: reCaptcha extension 0.4

Nice work but roll you should also make that css file only load when it is needed, now it loads every time a user comes to the forum.
It should only be loaded when they register or not?

And but I am not sure, it is better to use the $ext_info['url'] for the css file and not the path...
Do not know why but that is what I think someone told me.

Last edited by kierownik (2009-02-26 15:59:32)

Re: reCaptcha extension 0.4

Hi Kierownik, I am using $ext_info['url'] for the css.
I would like to load it only for posting and registering but don't know how to achieve it.
Just by moving

 $forum_head['recaptchacss'] = '<link rel="stylesheet" type="text/css" media="screen" href="'.$ext_info['url'].'/recaptcha.css" />';

from  <hook id="hd_head"> to <hook id="po_start,rg_start"> ?

Re: reCaptcha extension 0.4

also, what is the goal of the "priority" parameter?
Is it optional ?
I put them to 5, but don't know why wink

Re: reCaptcha extension 0.4

Thanks a lot for great extension! Works great on r718 smile

Re: reCaptcha extension 0.4

You don't need to use priority, if it doesn't matter. And it doesn't in this case.

Use the hook 'hd_head' and check for the value of the constant FORUM_PAGE. It is defined in each file, e.g. register.php is probably 'register'. Just check it tongue

http://www.fluxbb.de - Deutschsprachiges FluxBB-Supportforum

Re: reCaptcha extension 0.4

@gordie: please can you post a new link of your plugin. I have a 404 error when I tried to access the URL you've provided.

Re: reCaptcha extension 0.4

ok mathieu, i did it ! same url than in first post.

Re: reCaptcha extension 0.4

Merci wink

Re: reCaptcha extension 0.4

I'm really stupid at this... someone point me to where I can learn how to install this please? Thanks!

Re: reCaptcha extension 0.4

doesn't seem to work for me..
where is the settings ?

My English isn't perfect, so don't beat me !
www.FluxBBHeb.co.cc - Hebrew Support site for FluxBB... FluxBB אתר התמיכה הישראלי ל
Vexover Foundation - Software and media creation company.

Re: reCaptcha extension 0.4

Administration » Settings » Features

Re: reCaptcha extension 0.4

I've inserted the recaptcha keys, but when I post as a Guest, it says "Could not open socket"

Re: reCaptcha extension 0.4

Looks like the download link is dead again.

Re: reCaptcha extension 0.4

http://tinyurl.com/n7kj7d