============================================================================================================================
Modification Name: Captcha Registration Image

Version: 1.8

Last modified: 05/16/2010

Description: This modification will add antispam captcha image support to your forums.
                   The captcha images can be used for new registrations and/or anonymous posting.
                   The captcha images uses the same background colors as the theme being used to make it blend in with the page.
                   The captcha images can be created using your own images as the background if preferred.
                   The captcha image can use any font you want (Provided the font '.ttf' file is uploaded to the included 'fonts' directory).
                   There are a few fonts included with the download (Vera, VeraBd, VeraBI, VeraIt, VeraMoBd, VeraMoBI, VeraMoIt, VeraMono, VeraSe, VeraSeBd)  2003 by Bitstream, Inc.

Compatibility: XMB 1.9.5 SP1

Developed By: Adam Clarke (http://www.xmbservices.com)

Captcha Class Developed By: Edward Eliot (http://www.ejeliot.com/pages/2)

History: V1.0 (03/06/2007 @ 18:37) - Initial Release.
         V1.1 (24/06/2007 @ 14:12) - Rectified code error in post.php, and added important code to misc.php that actually generates the image.
         V1.2 (02/07/2007 @ 01:00) - Rectified a few typo errors that would prevent the hack from working.
         V1.3 (09/07/2007 @ 21:10) - It appears that some of the error's I rectified in V1.2, never got rectified in the install instructions.
         V1.4 (09/07/2007 @ 21:35) - Fixed minor issue in misc.php and added additional sanity checks to cp.php ~ Thanks John Briggs.
         V1.5 (09/07/2007 @ 23:15) - Fixed minor issue in captcha templates, and rectified captchaimages SQL table structure ~ Thanks John Briggs.
         V1.6 (10/07/2007 @ 00:25) - Fixed major coding error in post.php.
         V1.7 (13/07/2007 @ 18:00) - Added missing code to $tables array in header.php. Added captcha image to quickreply.
         V1.8 (14/07/2007 @ 10:40) - Relocated code in viewthread.php so it loads before the quickreply template.

License Note: This modification is released under the GPL License v3. A copy is provided with this software package.

Note: Backup all affected files, templates & databases.

Affected Files (7): lang/English.lang.php, cp.php, header.php, member.php, misc.php, post.php, viewthread.php

Affected Templates (5): member_profile_reg, post_newpoll, post_newthread, post_reply, viewthread_quickreply

New Templates (3): member_reg_captcha, post_captcha, viewthread_quickreply_captcha
============================================================================================================================
========
STEP 1:
========
====================================
Go To Administration Panel --> Insert Raw SQL
====================================

Upload provided file named "SQL.txt" and "Submit Changes".

============================================================================================================================
========
STEP 2:
========
=======================
Edit File: lang/English.lang.php
=======================
=============================
Add Code To End Of File ABOVE  ?>
=============================

// CAPTCHA Registration Image Mod Begin
$lang['admin_main_settings7'] = 'Captcha Image Settings';
$lang['captchastatus'] = 'Main Status:';
$lang['captcharegstatus'] = 'Registration Status:';
$lang['captchapoststatus'] = 'Anonymous Posting Status:';
$lang['captchacharset'] = 'Code Characters:';
$lang['captchacodelength'] = 'Code Length:';
$lang['captchacodecase'] = 'Case Sensitive Code:';
$lang['captchacodeshadow'] = 'Code Shadow:';
$lang['captchaimagetype'] = 'Image Type:';
$lang['captchaimagewidth'] = 'Image Width:';
$lang['captchaimageheight'] = 'Image Height:';
$lang['captchaimagebg'] = 'Image Background(s):';
$lang['captchaimagedots'] = 'Number of Random Dots:';
$lang['captchaimagelines'] = 'Number of Random Lines:';
$lang['captchaimagefonts'] = 'Image Font(s):';
$lang['captchaimageminfont'] = 'Min Font Size:';
$lang['captchaimagemaxfont'] = 'Max Font Size:';
$lang['captchaimagecolor'] = 'Use Full Color:';
$lang['captchaimageinvalid'] = "The image verification code that you entered was incorrect. Please enter the code exactly how it appears in the image.";
$lang['captchaverification'] = "Captcha Image Verification";
$lang['verificationnote'] = "Please enter the text contained within the image into the textbox below it. This process is used to prevent automated bots.";
// CAPTCHA Registration Image Mod End

============================================================================================================================
========
STEP 3:
========
==============
Edit File: cp.php
==============
==========
Find Code:
==========

        $resetSigOn = $resetSigOff = '';
        if($SETTINGS['resetsigs'] == 'on') {
            $resetSigOn = $selHTML;
        } else {
            $resetSigOff = $selHTML;
        }

===============
Add Code Below:
===============

        // CAPTCHA Registration Image Mod Begin
        $captchaOn = $captchaOff = '';
        switch ($SETTINGS['captcha_status']) {
            case 'on':
                $captchaOn = $selHTML;
                break;
            default:
                $captchaOff = $selHTML;
                break;
        }

        $captcharegOn = $captcharegOff = '';
        switch ($SETTINGS['captcha_reg_status']) {
            case 'on':
                $captcharegOn = $selHTML;
                break;
            default:
                $captcharegOff = $selHTML;
                break;
        }

        $captchapostOn = $captchapostOff = '';
        switch ($SETTINGS['captcha_post_status']) {
            case 'on':
                $captchapostOn = $selHTML;
                break;
            default:
                $captchapostOff = $selHTML;
                break;
        }

        $captchacodecaseOn = $captchacodecaseOff = '';
        switch ($SETTINGS['captcha_code_casesensitive']) {
            case 'on':
                $captchacodecaseOn = $selHTML;
                break;
            default:
                $captchacodecaseOff = $selHTML;
                break;
        }

        $captchacodeshadowOn = $captchacodeshadowOff = '';
        switch ($SETTINGS['captcha_code_shadow']) {
            case 'on':
                $captchacodeshadowOn = $selHTML;
                break;
            default:
                $captchacodeshadowOff = $selHTML;
                break;
        }

        $captchaimagecolorOn = $captchaimagecolorOff = '';
        switch ($SETTINGS['captcha_image_color']) {
            case 'on':
                $captchaimagecolorOn = $selHTML;
                break;
            default:
                $captchaimagecolorOff = $selHTML;
                break;
        }
        // CAPTCHA Registration Image Mod End

==========
Find Code:
==========

        <tr>
        <td class="ctrtablerow" bgcolor="<?php echo $altbg2?>" colspan="2"><input class="submit" type="submit" name="settingsubmit" value="<?php echo $lang['textsubmitchanges']?>" /></td>
        </tr>

===============
Add Code Above:
===============

        <!-- CAPTCHA Registration Image Mod Begin -->
        <tr>
        <td class="tablerow" bgcolor="<?php echo $altbg2?>" colspan="2">&nbsp;</td>
        </tr>
        <tr>
        <td colspan="2" class="category"><strong><font style="color: <?php echo $THEME['cattext']?>">&raquo;&nbsp;<?php echo $lang['admin_main_settings7']?></font></strong></td>
        </tr>
        <?php
        printsetting1($lang['captchastatus'], 'captchanew', $captchaOn, $captchaOff);
        printsetting1($lang['captcharegstatus'], 'captcharegnew', $captcharegOn, $captcharegOff);
        printsetting1($lang['captchapoststatus'], 'captchapostnew', $captchapostOn, $captchapostOff);
        printsetting2($lang['captchacharset'], "captchacharsetnew", $SETTINGS['captcha_code_charset'], "50");
        printsetting2($lang['captchacodelength'], "captchacodenew", $SETTINGS['captcha_code_length'], 3);
        printsetting1($lang['captchacodecase'], 'captchacodecasenew', $captchacodecaseOn, $captchacodecaseOff);
        printsetting1($lang['captchacodeshadow'], 'captchacodeshadownew', $captchacodeshadowOn, $captchacodeshadowOff);
        printsetting2($lang['captchaimagetype'], "captchaimagetypenew", $SETTINGS['captcha_image_type'], 5);
        printsetting2($lang['captchaimagewidth'], "captchaimagewidthnew", $SETTINGS['captcha_image_width'], 5);
        printsetting2($lang['captchaimageheight'], "captchaimageheightnew", $SETTINGS['captcha_image_height'], 5);
        printsetting2($lang['captchaimagebg'], "captchaimagebgnew", $SETTINGS['captcha_image_bg'], "50");
        printsetting2($lang['captchaimagedots'], "captchaimagedotsnew", $SETTINGS['captcha_image_dots'], 3);
        printsetting2($lang['captchaimagelines'], "captchaimagelinesnew", $SETTINGS['captcha_image_lines'], 3);
        printsetting2($lang['captchaimagefonts'], "captchaimagefontsnew", $SETTINGS['captcha_image_fonts'], "50");
        printsetting2($lang['captchaimageminfont'], "captchaimageminfontnew", $SETTINGS['captcha_image_minfont'], 3);
        printsetting2($lang['captchaimagemaxfont'], "captchaimagemaxfontnew", $SETTINGS['captcha_image_maxfont'], 3);
        printsetting1($lang['captchaimagecolor'], 'captchaimagecolornew', $captchaimagecolorOn, $captchaimagecolorOff);
        ?>
        <!-- CAPTCHA Registration Image Mod End -->

==========
Find Code:
==========

        $resetSigNew = ($resetSigNew == 'on') ? 'on' : 'off';

===============
Add Code Below:
===============

        // CAPTCHA Registration Image Mod Begin
        $captchanew = ($_POST['captchanew'] == 'on' ? 'on' : 'off');
        $captcharegnew = ($_POST['captcharegnew'] == 'on' ? 'on' : 'off');
        $captchapostnew = ($_POST['captchapostnew'] == 'on' ? 'on' : 'off');
        $captchacharsetnew = $_POST['captchacharsetnew'];
        $captchacodenew = (int) $_POST['captchacodenew'];
        $captchacodecasenew = ($_POST['captchacodecasenew'] == 'on' ? 'on' : 'off');
        $captchacodeshadownew = ($_POST['captchacodeshadownew'] == 'on' ? 'on' : 'off');
        $captchaimagetypenew = $_POST['captchaimagetypenew'];
        $captchaimagewidthnew = (int) $_POST['captchaimagewidthnew'];
        $captchaimageheightnew = (int) $_POST['captchaimageheightnew'];
        $captchaimagebgnew = $_POST['captchaimagebgnew'];
        $captchaimagedotsnew = (int) $_POST['captchaimagedotsnew'];
        $captchaimagelinesnew = (int) $_POST['captchaimagelinesnew'];
        $captchaimagefontsnew = $_POST['captchaimagefontsnew'];
        $captchaimageminfontnew = (int) $_POST['captchaimageminfontnew'];
        $captchaimagemaxfontnew = (int) $_POST['captchaimagemaxfontnew'];
        $captchaimagecolornew = ($_POST['captchaimagecolornew'] == 'on' ? 'on' : 'off');
        // CAPTCHA Registration Image Mod End

==========
Find Code:
==========

$db->query("UPDATE $table_settings SET 

==============================
Add To End Of Statement BEFORE  ");
==============================

, captcha_status = '$captchanew', captcha_reg_status = '$captcharegnew', captcha_post_status = '$captchapostnew', captcha_code_charset = '$captchacharsetnew', captcha_code_length = '$captchacodenew', captcha_code_casesensitive = '$captchacodecasenew', captcha_code_shadow = '$captchacodeshadownew', captcha_image_type = '$captchaimagetypenew', captcha_image_width = '$captchaimagewidthnew', captcha_image_height = '$captchaimageheightnew', captcha_image_bg = '$captchaimagebgnew', captcha_image_dots = '$captchaimagedotsnew', captcha_image_lines = '$captchaimagelinesnew', captcha_image_fonts = '$captchaimagefontsnew', captcha_image_minfont = '$captchaimageminfontnew', captcha_image_maxfont = '$captchaimagemaxfontnew', captcha_image_color = '$captchaimagecolornew'

============================================================================================================================
========
STEP 4:
========
=================
Edit File: header.php
=================
==========
Find Code:
==========

'buddys',

================
Replace Code With:
================

'buddys','captchaimages',

==========
Find Code:
==========

if (X_GUEST && $action != 'reg' && $action != 'login' && $action != 'lostpw' && $action != 'coppa'

================
Replace Code With:
================

if (X_GUEST && $action != 'reg' && $action != 'login' && $action != 'lostpw' && $action != 'coppa' && $action != 'captchaimage'

============================================================================================================================
========
STEP 5:
========
==================
Edit File: member.php
==================
==========
Find Code:
==========

loadtemplates(

================
Replace Code With:
================

loadtemplates(
'member_reg_captcha',

==========
Find Code:
==========

            eval('echo stripslashes("'.template('member_reg').'");');

===============
Add Code Above:
===============

            // CAPTCHA Registration Image Mod Begin
            $captcharegcheck = '';
            if ($SETTINGS['captcha_status'] == 'on' && $SETTINGS['captcha_reg_status'] == 'on' && !DEBUG) {
                require('./include/captcha.inc.php');
                $Captcha = new Captcha(250, 50);
                if ($Captcha->bCompatible !== false) {
                    $imghash = $Captcha->GenerateCode();
                    eval('$captcharegcheck = "'.template('member_reg_captcha').'";');
                }
            }
            // CAPTCHA Registration Image Mod End

==========
Find Code:
==========

        if (trim($username) == '') {
            error($lang['textnousername']);
        }

===============
Add Code Below:
===============

        // CAPTCHA Registration Image Mod Begin
        if ($SETTINGS['captcha_status'] == 'on' && $SETTINGS['captcha_reg_status'] == 'on' && !DEBUG) {
            require('./include/captcha.inc.php');
            $Captcha = new Captcha(250, 50);
            if ($Captcha->bCompatible !== false) {
                $imghash = addslashes($imghash);
                $imgcode = addslashes($imgcode);

                if ($Captcha->ValidateCode($imgcode, $imghash) !== true) {
                    error($lang['captchaimageinvalid']);
                }
            }
        }
        // CAPTCHA Registration Image Mod End

============================================================================================================================
========
STEP 6:
========
===============
Edit File: misc.php
===============
==========
Find Code:
==========

        } elseif (false !== strpos($url, 'list')) {
            $location = $lang['onlinememlist'];

===============
Add Code Below:
===============

        // CAPTCHA Registration Image Mod Begin
        } elseif (false !== strpos($url, 'captchaimage')) {
            $location = $lang['onlinereg'];
        // CAPTCHA Registration Image Mod End

==========
Find Code:
==========

    default:
        error($lang['textnoaction']);
        break;

===============
Add Code Above:
===============

    // CAPTCHA Registration Image Mod Begin
    case 'captchaimage':
        require('./include/captcha.inc.php');
        $oPhpCaptcha = new Captcha(250, 50);
        $oPhpCaptcha->Create($imagehash);
        exit();
        break;
    // CAPTCHA Registration Image Mod End

============================================================================================================================
========
STEP 7:
========
===============
Edit File: post.php
===============
==========
Find Code:
==========

loadtemplates(

================
Replace Code With:
================

loadtemplates(
'post_captcha', 

==========
Find Code:
==========

if ($action != 'edit') {

===============
Add Code Below:
===============

    // CAPTCHA Registration Image Mod Begin
    $captchapostcheck = '';
    if (X_GUEST && $SETTINGS['captcha_status'] == 'on' && $SETTINGS['captcha_post_status'] == 'on' && !DEBUG) {
        require('./include/captcha.inc.php');
        $Captcha = new Captcha(250, 50);
    }
    // CAPTCHA Registration Image Mod End

==========
Find Code:
==========

    if (!isset($topicsubmit) || !$topicsubmit) {

===============
Add Code Below:
===============

        // CAPTCHA Registration Image Mod Begin
        if (X_GUEST && $SETTINGS['captcha_status'] == 'on' && $SETTINGS['captcha_post_status'] == 'on' && !DEBUG) {
            if ($Captcha->bCompatible !== false) {
                $imghash = $Captcha->GenerateCode();
                eval('$captchapostcheck = "'.template('post_captcha').'";');
            }
        }
        // CAPTCHA Registration Image Mod End

==========
Find Code:
==========

    if (!isset($replysubmit) || !$replysubmit) {

===============
Add Code Below:
===============

        // CAPTCHA Registration Image Mod Begin
        if (X_GUEST && $SETTINGS['captcha_status'] == 'on' && $SETTINGS['captcha_post_status'] == 'on' && !DEBUG) {
            if ($Captcha->bCompatible !== false) {
                $imghash = $Captcha->GenerateCode();
                eval('$captchapostcheck = "'.template('post_captcha').'";');
            }
        }
        // CAPTCHA Registration Image Mod End

===================
Find Code (2 Instances):
===================

        if ( $forums['guestposting'] != "on" && $username == "Anonymous") {

========================
Add Code Above (2 Instances:
========================

        // CAPTCHA Registration Image Mod Begin
        if ($username == 'Anonymous' && $SETTINGS['captcha_status'] == 'on' && $SETTINGS['captcha_post_status'] == 'on' && !DEBUG) {
            if ($Captcha->bCompatible !== false) {
                $imghash = addslashes($imghash);
                $imgcode = addslashes($imgcode);

                if ($Captcha->ValidateCode($imgcode, $imghash) !== true) {
                    error($lang['captchaimageinvalid']);
                }
            }
        }
        // CAPTCHA Registration Image Mod End

============================================================================================================================
========
STEP 8:
========
===================
Edit File: viewthread.php
===================
==========
Find Code:
==========

loadtemplates(

================
Replace Code With:
================

loadtemplates(
'viewthread_quickreply_captcha',

==========
Find Code:
==========

    $smileoffcheck = (isset($smileyoff) && $smileyoff == 'yes') ? 'checked="checked"' : '';

===============
Add Code Below:
===============

    // CAPTCHA Registration Image Mod Begin
    $captchapostcheck = '';
    if (X_GUEST && $SETTINGS['captcha_status'] == 'on' && $SETTINGS['captcha_post_status'] == 'on' && !DEBUG) {
        require('./include/captcha.inc.php');
        $Captcha = new Captcha(250, 50);
        if ($Captcha->bCompatible !== false) {
            $imghash = $Captcha->GenerateCode();
            eval('$captchapostcheck = "'.template('viewthread_quickreply_captcha').'";');
        }
    }
    // CAPTCHA Registration Image Mod End

============================================================================================================================
========
STEP 8:
========
===============================
Go To Administration Panel --> Templates
===============================
=====================
Edit Template: member_reg
=====================
==========
Find Code:
==========

<tr>
<td colspan="2" class="tablerow" bgcolor="$THEME[altbg2]" align="center"><input type="submit" class="submit" name="regsubmit" value="$lang[textregister]" /></td>
</tr>

===============
Add Code Above:
===============

$captcharegcheck

============================================================================================================================
========
STEP 9:
========
===============================
Go To Administration Panel --> Templates
===============================
======================
Edit Template: post_newpoll
======================
==========
Find Code:
==========

$attachfile

===============
Add Code Below:
===============

$captchapostcheck

============================================================================================================================
=========
STEP 10:
=========
===============================
Go To Administration Panel --> Templates
===============================
========================
Edit Template: post_newthread
========================
==========
Find Code:
==========

$attachfile

===============
Add Code Below:
===============

$captchapostcheck

============================================================================================================================
=========
STEP 11:
=========
===============================
Go To Administration Panel --> Templates
===============================
====================
Edit Template: post_reply
====================
==========
Find Code:
==========

$attachfile

===============
Add Code Below:
===============

$captchapostcheck

============================================================================================================================
=========
STEP 12:
=========
===============================
Go To Administration Panel --> Templates
===============================
============================
Edit Template: viewthread_quickreply
============================
==========
Find Code:
==========

<tr>
<td colspan="3" class="category"><div align="left"><font color="$THEME[cattext]"><strong>&nbsp;&raquo;&nbsp;$lang[quickreply]</strong>&nbsp;- [$lang[loggedin] <strong>$xmbuser</strong>]</font></div></td>
</tr>

===============
Add Code Below:
===============

$captchapostcheck

============================================================================================================================
=========
STEP 13:
=========
===============================
Go To Administration Panel --> Templates
===============================
=================================
Create New Template: member_reg_captcha
=================================
========================
Add Code and Submit Changes
========================

<tr>
<td colspan="2" class="category"><font color="$THEME[cattext]"><strong>$lang[captchaverification] - $lang[required]</strong></font></td>
</tr>
<tr class="tablerow">
<td bgcolor="$THEME[altbg1]">$lang[verificationnote]</td>
<td bgcolor="$THEME[altbg2]"><img src="misc.php?action=captchaimage&amp;imagehash=$imghash" alt="$lang[captchaverification]" title="$lang[captchaverification]" /><br /><br /><input type="text" name="imgcode" value="" /><input type="hidden" name="imghash" value="$imghash" /></td>
</tr>

============================================================================================================================
=========
STEP 14:
=========
===============================
Go To Administration Panel --> Templates
===============================
============================
Create New Template: post_captcha
============================
========================
Add Code and Submit Changes
========================

<tr class="tablerow">
<td bgcolor="$THEME[altbg1]">$lang[verificationnote]</td>
<td bgcolor="$THEME[altbg2]"><img src="misc.php?action=captchaimage&amp;imagehash=$imghash" alt="$lang[captchaverification]" title="$lang[captchaverification]" /><br /><br /><input type="text" name="imgcode" value="" /><input type="hidden" name="imghash" value="$imghash" /></td>
</tr>

============================================================================================================================
=========
STEP 15:
=========
===============================
Go To Administration Panel --> Templates
===============================
========================================
Create New Template: viewthread_quickreply_captcha
========================================
========================
Add Code and Submit Changes
========================

<tr>
<td colspan="3" class="ctrtablerow" bgcolor="$THEME[altbg1]">
$lang[verificationnote]<br /><br />
<img src="misc.php?action=captchaimage&amp;imagehash=$imghash" alt="$lang[captchaverification]" title="$lang[captchaverification]" /><br /><br />
<input type="text" name="imgcode" value="" /><input type="hidden" name="imghash" value="$imghash" />
</td>
</tr>

============================================================================================================================
=========
STEP 16:
=========

Upload included 'fonts', 'images', 'include' directories to your forum directory.

============================================================================================================================
=========
STEP 17:
=========

Upload additional font files to the 'fonts' directory.
The file(s) must have a '.ttf' extension.

============================================================================================================================
=========
STEP 18:
=========

Upload additional background image files to the 'images/captchaimages' directory.
The file(s) must have a '.png', '.gif', or '.jpg' extension.

============================================================================================================================
Enjoy!