Version 3.2.3

This commit is contained in:
Neo committed 2025-12-19 00:34:03 -08:00
1 parent ae5c01cc78
commit 78706903a2
2641 files changed
+228363 -201264

No files matched your search

+183 -285
View File
@@ -1,156 +1,86 @@
<?php
/**
* CAPTCHA CLASS
* Database Table
* <code>
* CREATE TABLE captcha (
* captcha_unique_id VARCHAR(32) NOT NULL default '',
* captcha_string VARCHAR(100) NOT NULL default '',
* captcha_ipaddress VARCHAR(16) NOT NULL default '',
* captcha_date INT(10) NOT NULL default '',
* PRIMARY KEY (captcha_unique_id )
* );
* </code>
* PLUG IN: Default GD image
* <pre>
* Invision Power Services
* IP.Board v3.1.4
* Last Updated: $Date: 2010-09-13 17:11:29 -0400 (Mon, 13 Sep 2010) $
* </pre>
*
* @package IP.Board
* @subpackage Kernel
* @author Matt Mecham
* @copyright Invision Power Services, Inc.
* @version 1.0
* @file default.php Plugin for the default CAPTCHA GD image
*~TERABYTE_DOC_READY~
* $Copyright: (c) 2001 - 2011 Invision Power Services, Inc.$
* $License: This is NULLED!
* $Author: bfarber $
* @since Friday 19th May 2006 17:33
* $LastChangedDate: 2011-08-17 17:49:31 -0400 (Wed, 17 Aug 2011) $
* @version v3.2.3
* $Revision: 9396 $
*/
/**
*
* @class captchaPlugin
* @brief Plugin for the default CAPTCHA GD image
* @note This plugin is automatically loaded by classCaptcha class based on the CAPTCHA setting
*
*/
class captchaPlugin
{
/**
* GD version
* Registry Object Shortcuts
*
* @access public
* @var integer
* @var $registry
* @var $DB
* @var $settings
* @var $member
*/
public $gd_version = 0;
public $registry;
public $DB;
public $settings;
public $member;
/**
* Backgrounds path
* String that stores the backgrounds path
*
* @access public
* @var string
* @var $path_background
*/
public $path_background = '';
/**
* Fonts path
* String that stores the fonts path
*
* @access public
* @var string
* @var $path_fonts
*/
public $path_fonts = '';
/**
* Return an error if GD is not installed?
* My most verbose string name. I'm so proud.
*
* @access public
* @var boolean
*/
public $show_error_gd_img = false;
/**
* Registry object
*
* @access protected
* @var object
*/
public $registry;
/**
* Database object
*
* @access protected
* @var object
*/
public $DB;
/**
* Settings object
*
* @access protected
* @var object
*/
public $settings;
/**
* Request object
*
* @access protected
* @var object
*/
public $request;
/**
* Language object
*
* @access protected
* @var object
*/
public $lang;
/**
* Member object
*
* @access protected
* @var object
*/
public $member;
/**
* Member data object
*
* @access protected
* @var object
*/
public $memberData;
/**
* Captcha key
* String that stores the captcha key
*
* @access public
* @var string
* @var $captchaKey
*/
public $captchaKey = '';
public $captchaKey = '';
/**
* Constructor
*
* @param object Registry Object
* @param object $registry Registry Object
* @return @e void
*/
public function __construct( ipsRegistry $registry )
{
$this->registry = $registry;
$this->DB = $this->registry->DB();
$this->settings =& $this->registry->fetchSettings();
$this->request =& $this->registry->fetchRequest();
$this->lang = $this->registry->getClass('class_localization');
$this->member = $this->registry->member();
$this->memberData =& $this->registry->member()->fetchMemberData();
$this->registry = $registry;
$this->DB = $this->registry->DB();
$this->settings =& $this->registry->fetchSettings();
$this->member = $this->registry->member();
/* Settings */
$this->gd_version = $this->settings['gd_version'];
$this->path_background = DOC_IPS_ROOT_PATH . 'public/style_captcha/captcha_backgrounds';
$this->path_fonts = DOC_IPS_ROOT_PATH . 'public/style_captcha/captcha_fonts';
$this->path_background = DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_captcha/captcha_backgrounds';
$this->path_fonts = DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_captcha/captcha_fonts';
}
/**
* Returns the template bit
* Returns the captcha template
*
* @access public
* @return string
* @return @e string HTML template for captcha GD form
*
* <b>Example Usage:</b>
* @code
* $gdImage = $this->getTemplate();
* @endcode
*/
public function getTemplate()
{
@@ -191,7 +121,7 @@ class captchaPlugin
//-----------------------------------------
// Add to the DB
//-----------------------------------------
$this->DB->insert( 'captcha', array( 'captcha_unique_id' => $captcha_unique_id,
'captcha_string' => $captcha_string,
'captcha_ipaddress' => $this->member->ip_address,
@@ -200,45 +130,35 @@ class captchaPlugin
/* Make available */
$this->captchaKey = $captcha_unique_id;
//-----------------------------------------
// Return Template Bit
//-----------------------------------------
/* Return template */
return $this->registry->output->getTemplate('global_other')->captchaGD( $captcha_unique_id );
}
/**
* Validate the captcha image
* Validates the entered captcha code
*
* @access public
* @return boolean
* @return @e boolean TRUE if the code is valid otherwise FALSE
*
* <b>Example Usage:</b>
* @code
* $isValid = $this->validate();
* @endcode
*/
public function validate()
{
//-----------------------------------------
// INIT
//-----------------------------------------
/* Init vars */
$captcha_unique_id = IPSText::alphanumericalClean( $_REQUEST['captcha_unique_id'] );
$captcha_input_NOT_CLEAN = trim( $_REQUEST['captcha_string'] );
//-----------------------------------------
// Get the info from the DB
//-----------------------------------------
$captcha = $this->DB->buildAndFetch( array( 'select' => '*',
'from' => 'captcha',
'where' => "captcha_unique_id='". addslashes( $captcha_unique_id )."'" ) );
/* Get ID from DB */
$captcha = $this->DB->buildAndFetch( array( 'select' => '*', 'from' => 'captcha', 'where' => "captcha_unique_id='". addslashes( $captcha_unique_id )."'" ) );
if ( ! $captcha['captcha_unique_id'] )
{
return FALSE;
}
//-----------------------------------------
// Check...
//-----------------------------------------
/* Check */
if ( $captcha['captcha_string'] != $captcha_input_NOT_CLEAN )
{
return FALSE;
@@ -251,19 +171,18 @@ class captchaPlugin
}
/**
* Show the captcha bot image
* Generates the captcha image
*
* @access public
* @param string captcha_unique_id Unique captcha db row id
* @return mixed [Boolean on failure],[Output image data/headers]
* @since 1.0
* @param array $captcha_unique_id Key 0 of the array contains the Unique ID
* @return @e mixed Prints image data and headers on success otherwise FALSE on failure
*
* <b>Example Usage:</b>
* @code
* $captchaImage = $this->showImage( $captcha_unique_id );
* @endcode
*/
public function showImage( $captcha_unique_id )
{
//-----------------------------------------
// CHECK
//-----------------------------------------
//-----------------------------------------
// Magic _call method makes an array
//-----------------------------------------
@@ -275,35 +194,30 @@ class captchaPlugin
return false;
}
//-----------------------------------------
// Get the info from the DB
//-----------------------------------------
$captcha = $this->DB->buildAndFetch( array( 'select' => '*',
'from' => 'captcha',
'where' => "captcha_unique_id='" . $captcha_unique_id . "'",
) );
/* Get the info from the DB */
$captcha = $this->DB->buildAndFetch( array( 'select' => '*', 'from' => 'captcha', 'where' => "captcha_unique_id='" . $captcha_unique_id . "'" ) );
if ( ! $captcha['captcha_unique_id'] )
{
return false;
}
//-----------------------------------------
// Show it...
//-----------------------------------------
/* Show it... */
$this->_showGDImage( $captcha['captcha_string'] );
}
/**
* Show anti-spam bot GD image numbers
* Prints captcha image and headers
*
* @param string Number string
* @return void
* @since 1.0
* @param string $content Key to show in the GD image
* @return @e void Prints image data and headers
*
* <b>Example Usage:</b>
* @code
* $this->_showGDImage( $captcha_string );
* @endcode
*/
private function _showGDImage( $content="" )
protected function _showGDImage( $content="" )
{
//-----------------------------------------
// Is GD Available?
@@ -311,16 +225,9 @@ class captchaPlugin
if ( ! extension_loaded('gd') )
{
if ( $this->show_error_gd_img )
{
@header( "Content-Type: image/gif" );
print base64_decode( "R0lGODlhyAA8AJEAAN/f3z8/P8zMzP///yH5BAAAAAAALAAAAADIADwAAAL/nI+py+0Po5y02ouz3rz7D4biSJbmiabqyrbuC8fyTNf2jef6zvf+DwwKh8Si8YhMlgACwEHQXESfzgOzykQAqgMmFMr9Rq+GbHlqAFsFWnFVrfwIAvQAu15P0A14Nn8/ADhXd4dnl2YYCAioGHBgyDbnNzBIV0gYxzEYWdg1iLAnScmFuQdAt2UKZTcl+mip+HoYG+tKOfv3N5l5garnmPt6CwyaFzrranu7i0crObvoaKvMyMhrIQhFuyzcyGwXcOpoLYg7DGsZXk5r6DSN51RNfF0RPU5sy7gpnH5bjLhrk7Y9/RQNisfq2CRJauTR6xUuFyBx/yrWypMMmTlq/9IwQnKWcKG5cvMeShBIMOFIaV9w2eti6SBABAyjvBRFMaZCMaxsqtxl8iShjpj+VfqGCJg4XzOfJCK5DVWliFNXlSIENKjWrVy7ev0KNqzYsWTFwhlFU8waLk+efGF7hi0aSgu3iGmV1cxdoGTinimbiGOeP8SWhps6z3AkeMMWW20mMykqQyuJDbYWdufKBJWc2uWmAJZdO0yOKfTCCqHGiO4E/oKGriTYaBw5g/MDqynNlW9Uhmx66tM2i05dNcM8O6Rg2MHLYKraLTpDcLebTke4APkcduAoku0DWpe24MI96ewZPdiy6Rlx/0Y+XJevlNu/z6vtlHFxZbpv9f9edYkfxgVmjnqSxXYOYPfFVMgXIHGC0ltWDNXYJ6Lsw82AFVpWEk4pEabgbsfBM5FphyDWRh1OLCUgbC06NtNU6UV1T1Jl3YhjjjruyGOPPv4IZJBC6tDXGUDB4UUaK06RhRl/0aWWF3CR4YWESraR1ZCh6dMOiMNIFE2GI/bRJYiIEeULiloyUNSFLzWC3VXcqEJXTBe1qApDpbXUEYxr2tYeQCyyGMuIcxbokHfPvPjHf25mqeWHoLEX0iH0UScmUzSWNxmj20yH6Z+/yNTeM0N1cumkg9E4GHnluLcfeKLm95yLoO5ZKJrhgeaQm4xlFGshcK3pYZ9LradQrmY5nmhVdMm+qqpKYkIqpDyltWkpjJJaaKmd6kXjHUXvDPborOaei2666q7LbrvuvgtvvPLOS2+9YBUAADs=" );
exit();
}
else
{
exit();
}
@header( "Content-Type: image/gif" );
print base64_decode( "R0lGODlhyAA8AJEAAN/f3z8/P8zMzP///yH5BAAAAAAALAAAAADIADwAAAL/nI+py+0Po5y02ouz3rz7D4biSJbmiabqyrbuC8fyTNf2jef6zvf+DwwKh8Si8YhMlgACwEHQXESfzgOzykQAqgMmFMr9Rq+GbHlqAFsFWnFVrfwIAvQAu15P0A14Nn8/ADhXd4dnl2YYCAioGHBgyDbnNzBIV0gYxzEYWdg1iLAnScmFuQdAt2UKZTcl+mip+HoYG+tKOfv3N5l5garnmPt6CwyaFzrranu7i0crObvoaKvMyMhrIQhFuyzcyGwXcOpoLYg7DGsZXk5r6DSN51RNfF0RPU5sy7gpnH5bjLhrk7Y9/RQNisfq2CRJauTR6xUuFyBx/yrWypMMmTlq/9IwQnKWcKG5cvMeShBIMOFIaV9w2eti6SBABAyjvBRFMaZCMaxsqtxl8iShjpj+VfqGCJg4XzOfJCK5DVWliFNXlSIENKjWrVy7ev0KNqzYsWTFwhlFU8waLk+efGF7hi0aSgu3iGmV1cxdoGTinimbiGOeP8SWhps6z3AkeMMWW20mMykqQyuJDbYWdufKBJWc2uWmAJZdO0yOKfTCCqHGiO4E/oKGriTYaBw5g/MDqynNlW9Uhmx66tM2i05dNcM8O6Rg2MHLYKraLTpDcLebTke4APkcduAoku0DWpe24MI96ewZPdiy6Rlx/0Y+XJevlNu/z6vtlHFxZbpv9f9edYkfxgVmjnqSxXYOYPfFVMgXIHGC0ltWDNXYJ6Lsw82AFVpWEk4pEabgbsfBM5FphyDWRh1OLCUgbC06NtNU6UV1T1Jl3YhjjjruyGOPPv4IZJBC6tDXGUDB4UUaK06RhRl/0aWWF3CR4YWESraR1ZCh6dMOiMNIFE2GI/bRJYiIEeULiloyUNSFLzWC3VXcqEJXTBe1qApDpbXUEYxr2tYeQCyyGMuIcxbokHfPvPjHf25mqeWHoLEX0iH0UScmUzSWNxmj20yH6Z+/yNTeM0N1cumkg9E4GHnluLcfeKLm95yLoO5ZKJrhgeaQm4xlFGshcK3pYZ9LradQrmY5nmhVdMm+qqpKYkIqpDyltWkpjJJaaKmd6kXjHUXvDPborOaei2666q7LbrvuvgtvvPLOS2+9YBUAADs=" );
exit();
}
//-----------------------------------------
@@ -328,7 +235,6 @@ class captchaPlugin
//-----------------------------------------
$content = ' '. preg_replace( "/(\w)/", "\\1 ", $content ) .' ';
$allow_fonts = isset( $this->settings['captcha_allow_fonts'] ) ? $this->settings['captcha_allow_fonts'] : 1;
$use_fonts = 0;
$tmp_x = 135;
$tmp_y = 20;
@@ -350,76 +256,73 @@ class captchaPlugin
//-----------------------------------------
$_imgs = array();
if ( $this->gd_version > 1 )
while ( $continue_loop )
{
while ( $continue_loop )
if ( is_array( $backgrounds ) AND count( $backgrounds ) )
{
if ( is_array( $backgrounds ) AND count( $backgrounds ) )
$i = mt_rand(0, count( $backgrounds ) - 1 );
$background = $backgrounds[ $i ];
$_file_extension = preg_replace( "#^.*\.(\w{2,4})$#is", "\\1", strtolower( $background ) );
switch( $_file_extension )
{
$i = mt_rand(0, count( $backgrounds ) - 1 );
$background = $backgrounds[ $i ];
$_file_extension = preg_replace( "#^.*\.(\w{2,4})$#is", "\\1", strtolower( $background ) );
switch( $_file_extension )
{
case 'jpg':
case 'jpe':
case 'jpeg':
if ( ! function_exists('imagecreatefromjpeg') OR ! $im = @imagecreatefromjpeg($background) )
case 'jpg':
case 'jpe':
case 'jpeg':
if ( ! function_exists('imagecreatefromjpeg') OR ! $im = @imagecreatefromjpeg($background) )
{
unset( $backgrounds[ $i ] );
}
else
{
$_imgs[] = $im;
if( count( $_imgs ) > 2 )
{
unset( $backgrounds[ $i ] );
$continue_loop = FALSE;
$_started = TRUE;
}
else
}
break;
case 'gif':
if ( ! function_exists('imagecreatefromgif') OR ! $im = @imagecreatefromgif($background) )
{
unset( $backgrounds[ $i ] );
}
else
{
$_imgs[] = $im;
if( count( $_imgs ) > 2 )
{
$_imgs[] = $im;
if( count( $_imgs ) > 2 )
{
$continue_loop = FALSE;
$_started = TRUE;
}
$continue_loop = FALSE;
$_started = TRUE;
}
break;
case 'gif':
if ( ! function_exists('imagecreatefromgif') OR ! $im = @imagecreatefromgif($background) )
}
break;
case 'png':
if ( ! function_exists('imagecreatefrompng') OR ! $im = @imagecreatefrompng($background) )
{
unset( $backgrounds[ $i ] );
}
else
{
$_imgs[] = $im;
if( count( $_imgs ) > 2 )
{
unset( $backgrounds[ $i ] );
$continue_loop = FALSE;
$_started = TRUE;
}
else
{
$_imgs[] = $im;
if( count( $_imgs ) > 2 )
{
$continue_loop = FALSE;
$_started = TRUE;
}
}
break;
case 'png':
if ( ! function_exists('imagecreatefrompng') OR ! $im = @imagecreatefrompng($background) )
{
unset( $backgrounds[ $i ] );
}
else
{
$_imgs[] = $im;
if( count( $_imgs ) > 2 )
{
$continue_loop = FALSE;
$_started = TRUE;
}
}
break;
}
}
else
{
$continue_loop = FALSE;
}
break;
}
}
else
{
$continue_loop = FALSE;
}
}
/* Create a new background */
@@ -458,16 +361,8 @@ class captchaPlugin
if ( $_started !== TRUE )
{
if ( $this->gd_version == 1 )
{
$im = imagecreate($image_x, $image_y);
$tmp = imagecreate($tmp_x, $tmp_y);
}
else
{
$im = imagecreatetruecolor($image_x, $image_y);
$tmp = imagecreatetruecolor($tmp_x, $tmp_y);
}
$im = imagecreatetruecolor($image_x, $image_y);
$tmp = imagecreatetruecolor($tmp_x, $tmp_y);
$white = ImageColorAllocate($tmp, 255, 255, 255);
$black = ImageColorAllocate($tmp, 0, 0, 0);
@@ -557,7 +452,7 @@ class captchaPlugin
// Can we use fonts?
//-----------------------------------------
if ( $allow_fonts AND function_exists('imagettftext') AND is_array( $fonts ) AND count( $fonts ) )
if ( function_exists('imagettftext') AND is_array( $fonts ) AND count( $fonts ) )
{
if ( function_exists('imageantialias') )
{
@@ -601,7 +496,7 @@ class captchaPlugin
$b = mt_rand(0,100);
$c = $a + 20;
$d = $b + 20;
$e = ( $i == 3 ) ? mt_rand( 280, 320 ) : mt_rand( -280, -320 );
$e = ( $i == 3 ) ? mt_rand( 280, 320 ) : mt_rand( -320, -280 );
imagearc( $im, $a , $b , $c, $d, 0, $e, $color_light );
imagearc( $im, $a+1, $b+1, $c, $d, 0, $e, $color_main );
@@ -721,13 +616,16 @@ class captchaPlugin
/**
* Create wave effect for GD images
*
* @access private
* @param resource Image resource
* @param integer Wave factor
* @return resource Returned image resource
* @since 1.0
* @param resources $im Image resource
* @param integer $wave Wave factor
* @return @e resource Returned image resource
*
* <b>Example Usage:</b>
* @code
* $imageResource = $this->_showGDImageWave( $captcha_string );
* @endcode
*/
private function _showGDImageWave( $im, $wave=10 )
protected function _showGDImageWave( $im, $wave=10 )
{
$_width = imagesx( $im );
$_height = imagesy( $im );
@@ -765,44 +663,43 @@ class captchaPlugin
}
/**
* Removes extinct captcha sessions
* Clears out "dead" entries
* Removes extinct captcha sessions or 'dead' entries
*
* @access private
* @param string Optional IP address to clear out on
* @return string void
* @param string $ip_address Optional IP address to clear out on
* @return @e void
*
* <b>Example Usage:</b>
* @code
* $this->_clearSessions( $ip_address );
* @endcode
*/
private function _clearSessions( $ip_address='' )
protected function _clearSessions( $ip_address='' )
{
//-----------------------------------------
// INIT
//-----------------------------------------
/* Init vars */
$time = time() - 60 * 3600;
$extra = ( $ip_address ) ? " OR captcha_ipaddress='" . $ip_address . "'" : '';
//-----------------------------------------
// Remove...
//-----------------------------------------
/* Remove from DB */
$this->DB->delete( 'captcha', 'captcha_date < ' . $time . $extra );
}
/**
* Loads up the backgrounds.
* Retrieves the list of backgrounds from the specified path
*
* @access private
* @return array backgrounds
* @return @e array List of backgrouns found
*
* <b>Example Usage:</b>
* @code
* $images = $this->_getBackgrounds();
* @endcode
*/
private function _getBackgrounds()
protected function _getBackgrounds()
{
//-----------------------------------------
// INIT
//-----------------------------------------
/* Init vars */
$images = array();
$_path = $this->path_background;
/* Loop */
if ( $_dir = opendir( $_path ) )
{
while( false !== ( $_file = readdir( $_dir ) ) )
@@ -818,20 +715,22 @@ class captchaPlugin
}
/**
* Loads up the fonts.
* Retrieves the list of fonts from the specified path
*
* @access private
* @return array fonts
* @return @e array List of fonts found
*
* <b>Example Usage:</b>
* @code
* $fonts = $this->_getFonts();
* @endcode
*/
private function _getFonts()
protected function _getFonts()
{
//-----------------------------------------
// INIT
//-----------------------------------------
/* Init vars */
$fonts = array();
$_path = $this->path_fonts;
/* Loop */
if ( $_dir = @opendir( $_path ) )
{
while( false !== ( $_file = @readdir( $_dir ) ) )
@@ -845,5 +744,4 @@ class captchaPlugin
return $fonts;
}
}
@@ -5,6 +5,6 @@
<hr>
You have reached this page in error, please use your back button to return to the forum.
<hr>
<a href="http://www.invisionboard.com/">IP.Board</a>
<a href="http://www.invisionpower.com">IP.Board</a>
</body>
</html>
@@ -39,68 +39,83 @@
*/
define("RECAPTCHA_API_SERVER", "http://www.google.com/recaptcha/api");
define("RECAPTCHA_API_SECURE_SERVER", "https://www.google.com/recaptcha/api");
define("RECAPTCHA_VERIFY_SERVER", "www.google.com");
define("RECAPTCHA_VERIFY_SERVER", "http://www.google.com");
/**
* @file recaptcha.php Plugin for reCAPTCHA
*~TERABYTE_DOC_READY~
* $Copyright: (c) 2001 - 2011 Invision Power Services, Inc.$
* $License: This is NULLED!
* $Author: bfarber $
* @since Friday 19th May 2006 17:33
* $LastChangedDate: 2011-03-09 18:12:09 -0500 (Wed, 09 Mar 2011) $
* @version v3.2.3
* $Revision: 8004 $
*/
/**
*
* @class captchaPlugin
* @brief Plugin for reCAPTCHA
* @note This plugin is automatically loaded by classCaptcha class based on the CAPTCHA setting
*
*/
class captchaPlugin
{
/**#@+
* Registry objects
/**
* Registry Object Shortcuts
*
* @var object
* @var $registry
* @var $DB
* @var $settings
* @var $member
*/
public $registry;
public $DB;
public $settings;
public $request;
public $lang;
public $member;
public $memberData;
/**#@-*/
/**
* Error code from reCAPTCHA
* String that stores the error code from reCAPTCHA (if any)
*
* @var string
* @var $error
*/
public $error;
/**
* reCAPTCHA public key
* String that stores reCAPTCHA public key
*
* @var string
* @var $public_key
*/
public $public_key;
/**
* reCAPTCHA private key
* String that stores reCAPTCHA private key
*
* @var string
* @var $private_key
*/
public $private_key;
/**
* Flag whether to use SSL or not
* Integer flag that stores whether to use SSL or not for the connection
*
* @var string
* @var $private_key
*/
public $useSSL;
/**
* Constructor
*
* @access public
* @param object Registry Object
* @return void
* @param object $registry Registry Object
* @return @e void
*/
public function __construct( ipsRegistry $registry )
{
$this->registry = $registry;
$this->DB = $this->registry->DB();
$this->settings =& $this->registry->fetchSettings();
$this->request =& $this->registry->fetchRequest();
$this->lang = $this->registry->getClass('class_localization');
$this->member = $this->registry->member();
$this->memberData =& $this->registry->member()->fetchMemberData();
/* Settings */
$this->public_key = trim( $this->settings['recaptcha_public_key'] );
@@ -109,12 +124,16 @@ class captchaPlugin
}
/**
* Gets the challenge HTML (javascript and non-javascript version).
* Returns the reCAPTCHA template (javascript and non-javascript version).
* This is called from the browser, and the resulting reCAPTCHA HTML widget
* is embedded within the HTML form it was called from.
*
* @access public
* @return string Form HTML to display
* @return @e string HTML template for reCAPTCHA form
*
* <b>Example Usage:</b>
* @code
* $recaptchaForm = $this->getTemplate();
* @endcode
*/
public function getTemplate()
{
@@ -155,17 +174,21 @@ class captchaPlugin
}
/**
* Validate the input code
* Validates the entered captcha code
*
* @access public
* @return boolean Validation successful
* @since 1.0
* @return @e boolean TRUE if the code is valid otherwise FALSE
*
* <b>Example Usage:</b>
* @code
* $isValid = $this->validate();
* @endcode
*/
public function validate()
{
if ( !$this->private_key )
{
return '';
$this->error = 'no_private_key';
return FALSE;
}
$captcha_unique_id = $_REQUEST['recaptcha_challenge_field'];
@@ -176,16 +199,17 @@ class captchaPlugin
return false;
}
$response = $this->_recaptchaPost( RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
array (
'privatekey' => $this->private_key,
'remoteip' => $this->member->ip_address,
'challenge' => $captcha_unique_id,
'response' => $captcha_input
)
);
$classToLoad = IPSLib::loadLibrary( IPS_KERNEL_PATH . '/classFileManagement.php', 'classFileManagement' );
$communication = new $classToLoad();
$answers = explode( "\n", $response[1] );
$response = $communication->postFileContents( RECAPTCHA_VERIFY_SERVER . "/recaptcha/api/verify", array(
'privatekey' => $this->private_key,
'remoteip' => $this->member->ip_address,
'challenge' => $captcha_unique_id,
'response' => $captcha_input
) );
$answers = explode( "\n", $response );
if ( trim($answers[0]) == 'true' )
{
@@ -196,88 +220,8 @@ class captchaPlugin
/**
* It's an error
*/
$this->error = $answers[1];
$this->error = $answers[1];
return FALSE;
}
}
/**
* Gets a URL where the user can sign up for reCAPTCHA. If your application
* has a configuration page where you enter a key, you should provide a link
* using this function.
*
* @access public
* @param string $domain The domain where the page is hosted
* @param string $appname The name of your application
*/
public function getSignupUrl( $domain = null, $appname = null )
{
return "https://www.google.com/recaptcha/admin/create?" . $this->_encodeQueryString( array( 'domain' => $domain, 'app' => $appname ) );
}
/**
* Submits an HTTP POST to a reCAPTCHA server
*
* @access private
* @param string $host
* @param string $path
* @param array $data
* @param int port
* @return array response
*/
private function _recaptchaPost( $host, $path, $data, $port = 80 )
{
$req = $this->_encodeQueryString( $data );
$http_request = "POST $path HTTP/1.0\r\n";
$http_request .= "Host: $host\r\n";
$http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
$http_request .= "Content-Length: " . strlen($req) . "\r\n";
$http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
$http_request .= "\r\n";
$http_request .= $req;
$response = '';
if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) )
{
return false;
}
fwrite($fs, $http_request);
while ( !feof($fs) )
{
$response .= fgets($fs, 1160); // One TCP-IP packet
}
fclose($fs);
$response = explode( "\r\n\r\n", $response, 2 );
return $response;
}
/**
* Encode array of data into a query string
*
* @access private
* @param array $data
* @return string query string
*/
private function _encodeQueryString( $data )
{
$req = "";
foreach ( $data as $key => $value )
{
$req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
}
// Cut the last '&'
$req = substr( $req, 0, strlen($req)-1 );
return $req;
}
}
}