aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/captcha/plugins
diff options
context:
space:
mode:
authorMeik Sievertsen <acydburn@phpbb.com>2009-10-04 18:13:59 +0000
committerMeik Sievertsen <acydburn@phpbb.com>2009-10-04 18:13:59 +0000
commitbf8ac19eaa8d74f9dfd6d597190f5664e7339382 (patch)
treec3ad876736748e36cb9176a0248cc43badfc1d9a /phpBB/includes/captcha/plugins
parent3215bbf88864139dc8c7e9ac5773b1ea8a7e96c1 (diff)
downloadforums-bf8ac19eaa8d74f9dfd6d597190f5664e7339382.tar
forums-bf8ac19eaa8d74f9dfd6d597190f5664e7339382.tar.gz
forums-bf8ac19eaa8d74f9dfd6d597190f5664e7339382.tar.bz2
forums-bf8ac19eaa8d74f9dfd6d597190f5664e7339382.tar.xz
forums-bf8ac19eaa8d74f9dfd6d597190f5664e7339382.zip
Move trunk/phpBB to old_trunk/phpBB
git-svn-id: file:///svn/phpbb/trunk@10210 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/captcha/plugins')
-rw-r--r--phpBB/includes/captcha/plugins/captcha_abstract.php282
-rw-r--r--phpBB/includes/captcha/plugins/phpbb_captcha_gd_plugin.php101
-rw-r--r--phpBB/includes/captcha/plugins/phpbb_captcha_gd_wave_plugin.php57
-rw-r--r--phpBB/includes/captcha/plugins/phpbb_captcha_nogd_plugin.php55
-rw-r--r--phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php306
5 files changed, 0 insertions, 801 deletions
diff --git a/phpBB/includes/captcha/plugins/captcha_abstract.php b/phpBB/includes/captcha/plugins/captcha_abstract.php
deleted file mode 100644
index 4f494b9c69..0000000000
--- a/phpBB/includes/captcha/plugins/captcha_abstract.php
+++ /dev/null
@@ -1,282 +0,0 @@
-<?php
-/**
-*
-* @package VC
-* @version $Id$
-* @copyright (c) 2006 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-
-/**
-* This class holds the code shared by the two default 3.0 CAPTCHAs.
-*/
-abstract class phpbb_default_captcha implements phpbb_captcha_plugin
-{
- protected $confirm_id;
- protected $confirm_code;
- protected $code;
- protected $seed;
- protected $type;
- protected $solved = false;
-
- protected $min_chars = 4;
- protected $max_chars = 7;
-
- function init($type)
- {
- // read input
- $this->confirm_id = request_var('confirm_id', '');
- $this->confirm_code = request_var('confirm_code', '');
- $this->type = (int) $type;
-
- if (!strlen($this->confirm_id))
- {
- // we have no confirm ID, better get ready to display something
- $this->generate_code();
- }
- }
-
- function execute_demo()
- {
- $this->code = gen_rand_string(mt_rand($this->min_chars, $this->max_chars));
- $this->seed = hexdec(substr(unique_id(), 4, 10));
-
- // compute $seed % 0x7fffffff
- $this->seed -= 0x7fffffff * floor($this->seed / 0x7fffffff);
-
- captcha::execute($this->code, $this->seed);
- }
-
-
- function execute()
- {
- if (empty($this->code))
- {
- if (!$this->load_code())
- {
- // invalid request, bail out
- return false;
- }
- }
- captcha::execute($this->code, $this->seed);
- }
-
-
- function get_template()
- {
- phpbb::$template->set_filenames(array(
- 'captcha' => 'captcha_default.html',
- ));
-
- phpbb::$template->assign_vars(array(
- 'CONFIRM_IMAGE' => append_sid('ucp', 'mode=confirm&amp;confirm_id=' . $this->confirm_id . '&amp;type=' . $this->type),
- 'CONFIRM_ID' => $this->confirm_id,
- ));
-
- return phpbb::$template->assign_display('captcha');
- }
-
- function get_demo_template($id)
- {
- phpbb::$template->set_filenames(array(
- 'captcha_demo' => 'captcha_default_acp_demo.html',
- ));
- // acp_captcha has a delivery function; let's use it
- phpbb::$template->assign_vars(array(
- 'CONFIRM_IMAGE' => append_sid(PHPBB_ADMIN_PATH . 'index.' . PHP_EXT, 'captcha_demo=1&amp;mode=visual&amp;i=' . $id . '&amp;select_captcha=' . $this->get_class_name()),
- 'CONFIRM_ID' => $this->confirm_id,
- ));
-
- return phpbb::$template->assign_display('captcha_demo');
- }
-
- function get_hidden_fields()
- {
- $hidden_fields = array();
-
- // this is required for postig.php - otherwise we would forget about the captcha being already solved
- if ($this->solved)
- {
- $hidden_fields['confirm_code'] = $this->confirm_code;
- }
- $hidden_fields['confirm_id'] = $this->confirm_id;
- return $hidden_fields;
- }
-
- static function garbage_collect($type)
- {
- $sql = 'SELECT DISTINCT c.session_id
- FROM ' . CONFIRM_TABLE . ' c
- LEFT JOIN ' . SESSIONS_TABLE . ' s ON (c.session_id = s.session_id)
- WHERE s.session_id IS NULL' .
- ((empty($type)) ? '' : ' AND c.confirm_type = ' . (int) $type);
- $result = phpbb::$db->sql_query($sql);
-
- if ($row = phpbb::$db->sql_fetchrow($result))
- {
- $sql_in = array();
- do
- {
- $sql_in[] = (string) $row['session_id'];
- }
- while ($row = phpbb::$db->sql_fetchrow($result));
-
- if (sizeof($sql_in))
- {
- $sql = 'DELETE FROM ' . CONFIRM_TABLE . '
- WHERE ' . phpbb::$db->sql_in_set('session_id', $sql_in);
- phpbb::$db->sql_query($sql);
- }
- }
- phpbb::$db->sql_freeresult($result);
- }
-
- function uninstall()
- {
- self::garbage_collect(0);
- }
-
- function install()
- {
- return;
- }
-
- function validate()
- {
- $this->confirm_code = request_var('confirm_code', '');
-
- if (!$this->confirm_id)
- {
- $error = phpbb::$user->lang['CONFIRM_CODE_WRONG'];
- }
- else
- {
- if ($this->check_code())
- {
- // $this->delete_code(); commented out to allow posting.php to repeat the question
- $this->solved = true;
- }
- else
- {
- $error = phpbb::$user->lang['CONFIRM_CODE_WRONG'];
- }
- }
-
- if (strlen($error))
- {
- // okay, inorect answer. Let's ask a new question
- $this->generate_code();
- return $error;
- }
- else
- {
- return false;
- }
- }
-
-
- /**
- * The old way to generate code, suitable for GD and non-GD. Resets the internal state.
- */
- protected function generate_code()
- {
- $this->code = gen_rand_string(mt_rand($this->min_chars, $this->max_chars));
- $this->confirm_id = md5(unique_id(phpbb::$user->ip));
- $this->seed = hexdec(substr(unique_id(), 4, 10));
- $this->solved = false;
-
- // compute $seed % 0x7fffffff
- $this->seed -= 0x7fffffff * floor($this->seed / 0x7fffffff);
-
- $sql = 'INSERT INTO ' . CONFIRM_TABLE . ' ' . phpbb::$db->sql_build_array('INSERT', array(
- 'confirm_id' => (string) $this->confirm_id,
- 'session_id' => (string) phpbb::$user->session_id,
- 'confirm_type' => (int) $this->type,
- 'code' => (string) $this->code,
- 'seed' => (int) $this->seed)
- );
- phpbb::$db->sql_query($sql);
- }
-
- /**
- * Look up everything we need for painting&checking.
- */
- protected function load_code()
- {
- $sql = 'SELECT code, seed
- FROM ' . CONFIRM_TABLE . "
- WHERE confirm_id = '" . phpbb::$db->sql_escape($this->confirm_id) . "'
- AND session_id = '" . phpbb::$db->sql_escape(phpbb::$user->session_id) . "'
- AND confirm_type = " . $this->type;
- $result = phpbb::$db->sql_query($sql);
- $row = phpbb::$db->sql_fetchrow($result);
- phpbb::$db->sql_freeresult($result);
- if ($row)
- {
- $this->code = $row['code'];
- $this->seed = $row['seed'];
- return true;
- }
- return false;
-
- }
-
- protected function check_code()
- {
- if (empty($this->code))
- {
- if (!$this->load_code())
- {
- return false;
- }
- }
- return (strcasecmp($this->code, $this->confirm_code) === 0);
- }
-
- protected function delete_code()
- {
- $sql = 'DELETE FROM ' . CONFIRM_TABLE . "
- WHERE confirm_id = '" . phpbb::$db->sql_escape($this->confirm_id) . "'
- AND session_id = '" . phpbb::$db->sql_escape(phpbb::$user->session_id) . "'
- AND confirm_type = " . $this->type;
- phpbb::$db->sql_query($sql);
- }
-
- function get_attempt_count()
- {
- $sql = 'SELECT COUNT(session_id) AS attempts
- FROM ' . CONFIRM_TABLE . "
- WHERE session_id = '" . phpbb::$db->sql_escape(phpbb::$user->session_id) . "'
- AND confirm_type = " . $this->type;
- $result = phpbb::$db->sql_query($sql);
- $attempts = (int) phpbb::$db->sql_fetchfield('attempts');
- phpbb::$db->sql_freeresult($result);
-
- return $attempts;
- }
-
-
- function reset()
- {
- $sql = 'DELETE FROM ' . CONFIRM_TABLE . "
- WHERE session_id = '" . phpbb::$db->sql_escape(phpbb::$user->session_id) . "'
- AND confirm_type = " . (int) $this->type;
- phpbb::$db->sql_query($sql);
-
- // we leave the class usable by generating a new question
- $this->generate_code();
- }
-
-}
-
-?> \ No newline at end of file
diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_gd_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_gd_plugin.php
deleted file mode 100644
index f795349f3d..0000000000
--- a/phpBB/includes/captcha/plugins/phpbb_captcha_gd_plugin.php
+++ /dev/null
@@ -1,101 +0,0 @@
-<?php
-/**
-*
-* @package VC
-* @version $Id$
-* @copyright (c) 2006 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-/**
-* Placeholder for autoload
-*/
-include_once(PHPBB_ROOT_PATH . 'includes/captcha/plugins/captcha_abstract.' . PHP_EXT);
-
-class phpbb_captcha_gd extends phpbb_default_captcha implements phpbb_captcha_plugin
-{
-
- function __construct()
- {
- include_once(PHPBB_ROOT_PATH . 'includes/captcha/captcha_gd.' . PHP_EXT);
- }
-
- public static function get_instance()
- {
- return new phpbb_captcha_gd();
- }
-
- static function is_available()
- {
- return (@extension_loaded('gd') || can_load_dll('gd'));
- }
-
- static function get_name()
- {
- return 'CAPTCHA_GD';
- }
-
- static function get_class_name()
- {
- return 'phpbb_captcha_gd';
- }
-
- function acp_page($id, &$module)
- {
- $captcha_vars = array(
- 'captcha_gd_x_grid' => 'CAPTCHA_GD_X_GRID',
- 'captcha_gd_y_grid' => 'CAPTCHA_GD_Y_GRID',
- 'captcha_gd_foreground_noise' => 'CAPTCHA_GD_FOREGROUND_NOISE',
- 'captcha_gd' => 'CAPTCHA_GD_PREVIEWED'
- );
-
- $module->tpl_name = 'captcha_gd_acp';
- $module->page_title = 'ACP_VC_SETTINGS';
- $form_key = 'acp_captcha';
- add_form_key($form_key);
-
- $submit = request_var('submit', '');
-
- if ($submit && check_form_key($form_key))
- {
- $captcha_vars = array_keys($captcha_vars);
- foreach ($captcha_vars as $captcha_var)
- {
- $value = request_var($captcha_var, 0);
- if ($value >= 0)
- {
- set_config($captcha_var, $value);
- }
- }
- trigger_error(phpbb::$user->lang['CONFIG_UPDATED'] . adm_back_link($module->u_action));
- }
- else if ($submit)
- {
- trigger_error(phpbb::$user->lang['FORM_INVALID'] . adm_back_link($module->u_action));
- }
- else
- {
- foreach ($captcha_vars as $captcha_var => $template_var)
- {
- $var = request_var($captcha_var, (int) phpbb::$config[$captcha_var]);
- phpbb::$template->assign_var($template_var, $var);
- }
-
- phpbb::$template->assign_vars(array(
- 'CAPTCHA_PREVIEW' => $this->get_demo_template($id),
- 'CAPTCHA_NAME' => $this->get_class_name(),
- ));
-
- }
- }
-}
-
-?> \ No newline at end of file
diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_gd_wave_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_gd_wave_plugin.php
deleted file mode 100644
index 1dbebcdbd6..0000000000
--- a/phpBB/includes/captcha/plugins/phpbb_captcha_gd_wave_plugin.php
+++ /dev/null
@@ -1,57 +0,0 @@
-<?php
-/**
-*
-* @package VC
-* @version $Id$
-* @copyright (c) 2006 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-/**
-* Placeholder for autoload
-*/
-include_once(PHPBB_ROOT_PATH . 'includes/captcha/plugins/captcha_abstract.' . PHP_EXT);
-
-class phpbb_captcha_gd_wave extends phpbb_default_captcha implements phpbb_captcha_plugin
-{
-
- function __construct()
- {
- include_once(PHPBB_ROOT_PATH . 'includes/captcha/captcha_gd_wave.' . PHP_EXT);
- }
-
- public static function get_instance()
- {
- return new phpbb_captcha_gd_wave();
- }
-
- static function is_available()
- {
- return (@extension_loaded('gd') || can_load_dll('gd'));
- }
-
- static function get_name()
- {
- return 'CAPTCHA_GD_WAVE';
- }
-
- static function get_class_name()
- {
- return 'phpbb_captcha_gd_wave';
- }
-
- function acp_page($id, &$module)
- {
- trigger_error(phpbb::$user->lang['CAPTCHA_NO_OPTIONS'] . adm_back_link($module->u_action));
- }
-}
-
-?> \ No newline at end of file
diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_nogd_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_nogd_plugin.php
deleted file mode 100644
index f76c42338e..0000000000
--- a/phpBB/includes/captcha/plugins/phpbb_captcha_nogd_plugin.php
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-/**
-*
-* @package VC
-* @version $Id$
-* @copyright (c) 2006 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-include_once(PHPBB_ROOT_PATH . 'includes/captcha/plugins/captcha_abstract.' . PHP_EXT);
-
-class phpbb_captcha_nogd extends phpbb_default_captcha implements phpbb_captcha_plugin
-{
-
- function __construct()
- {
- include_once(PHPBB_ROOT_PATH . 'includes/captcha/captcha_non_gd.' . PHP_EXT);
- }
-
- public static function get_instance()
- {
- return new phpbb_captcha_nogd();
- }
-
- static function is_available()
- {
- return true;
- }
-
- static function get_name()
- {
- return 'CAPTCHA_NO_GD';
- }
-
- static function get_class_name()
- {
- return 'phpbb_captcha_nogd';
- }
-
-
- function acp_page($id, &$module)
- {
- trigger_error(phpbb::$user->lang['CAPTCHA_NO_OPTIONS'] . adm_back_link($module->u_action));
- }
-}
-
-?> \ No newline at end of file
diff --git a/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php b/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php
deleted file mode 100644
index a27909baee..0000000000
--- a/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php
+++ /dev/null
@@ -1,306 +0,0 @@
-<?php
-/**
-*
-* @package VC
-* @version $Id$
-* @copyright (c) 2006 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-// we need the classic captcha code for tracking solutions and attempts
-include_once(PHPBB_ROOT_PATH . 'includes/captcha/plugins/captcha_abstract.' . PHP_EXT);
-
-class phpbb_recaptcha extends phpbb_default_captcha implements phpbb_captcha_plugin
-{
- const recaptcha_server = 'http://api.recaptcha.net';
- const recaptcha_verify_server = 'api-verify.recaptcha.net';
- protected $challenge;
- protected $response;
-
- function init($type)
- {
- phpbb::$user->add_lang('recaptcha');
- parent::init($type);
-
- $this->challenge = request_var('recaptcha_challenge_field', '');
- $this->response = request_var('recaptcha_response_field', '');
- }
-
- public static function get_instance()
- {
- return new phpbb_recaptcha();
- }
-
- static function is_available()
- {
- phpbb::$user->add_lang('recaptcha');
- return (isset(phpbb::$config['recaptcha_pubkey']) && !empty(phpbb::$config['recaptcha_pubkey']));
- }
-
- static function get_name()
- {
- return 'CAPTCHA_RECAPTCHA';
- }
-
- static function get_class_name()
- {
- return 'phpbb_recaptcha';
- }
-
- function acp_page($id, &$module)
- {
- $captcha_vars = array(
- 'recaptcha_pubkey' => 'RECAPTCHA_PUBKEY',
- 'recaptcha_privkey' => 'RECAPTCHA_PRIVKEY',
- );
-
- $module->tpl_name = 'captcha_recaptcha_acp';
- $module->page_title = 'ACP_VC_SETTINGS';
- $form_key = 'acp_captcha';
- add_form_key($form_key);
-
- $submit = request_var('submit', '');
-
- if ($submit && check_form_key($form_key))
- {
- $captcha_vars = array_keys($captcha_vars);
- foreach ($captcha_vars as $captcha_var)
- {
- $value = request_var($captcha_var, '');
- if ($value)
- {
- set_config($captcha_var, $value);
- }
- }
- trigger_error(phpbb::$user->lang['CONFIG_UPDATED'] . adm_back_link($module->u_action));
- }
- else if ($submit)
- {
- trigger_error(phpbb::$user->lang['FORM_INVALID'] . adm_back_link($module->u_action));
- }
- else
- {
- foreach ($captcha_vars as $captcha_var => $template_var)
- {
- $var = request_var($captcha_var, (isset(phpbb::$config[$captcha_var])) ? (string) phpbb::$config[$captcha_var] : '');
- phpbb::$template->assign_var($template_var, $var);
- }
-
- phpbb::$template->assign_vars(array(
- 'CAPTCHA_PREVIEW' => $this->get_demo_template($id),
- 'CAPTCHA_NAME' => $this->get_class_name(),
- ));
-
- }
- }
-
-
- // not needed
- function execute_demo()
- {
- }
-
-
- // not needed
- function execute()
- {
- }
-
-
- function get_template()
- {
- phpbb::$template->set_filenames(array(
- 'captcha' => 'captcha_recaptcha.html',
- ));
-
- phpbb::$template->assign_vars(array(
- 'RECAPTCHA_SERVER' => self::recaptcha_server,
- 'RECAPTCHA_PUBKEY' => isset(phpbb::$config['recaptcha_pubkey']) ? phpbb::$config['recaptcha_pubkey'] : '',
- 'RECAPTCHA_ERRORGET' => '',
- 'S_RECAPTCHA_AVAILABLE' => self::is_available(),
- ));
-
- return phpbb::$template->assign_display('captcha');
- }
-
- function get_demo_template($id)
- {
- return $this->get_template();
- }
-
- function get_hidden_fields()
- {
- $hidden_fields = array();
-
- // this is required for postig.php - otherwise we would forget about the captcha being already solved
- if ($this->solved)
- {
- $hidden_fields['confirm_code'] = $this->confirm_code;
- }
- $hidden_fields['confirm_id'] = $this->confirm_id;
- return $hidden_fields;
- }
-
- function uninstall()
- {
- self::garbage_collect(0);
- }
-
- function install()
- {
- return;
- }
-
- function validate()
- {
- if (!parent::validate())
- {
- return false;
- }
- else
- {
- return $this->recaptcha_check_answer();
- }
- }
-
-
-// Code from here on is based on recaptchalib.php
-/*
- * This is a PHP library that handles calling reCAPTCHA.
- * - Documentation and latest version
- * http://recaptcha.net/plugins/php/
- * - Get a reCAPTCHA API Key
- * http://recaptcha.net/api/getkey
- * - Discussion group
- * http://groups.google.com/group/recaptcha
- *
- * Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
- * AUTHORS:
- * Mike Crawford
- * Ben Maurer
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
- /**
- * Submits an HTTP POST to a reCAPTCHA server
- * @param string $host
- * @param string $path
- * @param array $data
- * @param int port
- * @return array response
- */
- protected function _recaptcha_http_post($host, $path, $data, $port = 80)
- {
- $req = $this->_recaptcha_qsencode ($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/phpBB\r\n";
- $http_request .= "\r\n";
- $http_request .= $req;
-
- $response = '';
- if (false == ($fs = @fsockopen($host, $port, $errno, $errstr, 10)))
- {
- trigger_error('Could not open socket', E_USER_ERROR);
- }
-
- fwrite($fs, $http_request);
-
- while (!feof($fs))
- {
- // One TCP-IP packet
- $response .= fgets($fs, 1160);
- }
- fclose($fs);
-
- $response = explode("\r\n\r\n", $response, 2);
-
- return $response;
- }
-
- /**
- * Calls an HTTP POST function to verify if the user's guess was correct
- * @param array $extra_params an array of extra variables to post to the server
- * @return ReCaptchaResponse
- */
- protected function recaptcha_check_answer($extra_params = array())
- {
- // discard spam submissions
- if ($this->challenge == null || strlen($this->challenge) == 0 || $this->response == null || strlen($this->response) == 0)
- {
- return phpbb::$user->lang['RECAPTCHA_INCORRECT'];
- }
-
- $response = $this->_recaptcha_http_post(self::recaptcha_verify_server, '/verify', array(
- 'privatekey' => phpbb::$config['recaptcha_privkey'],
- 'remoteip' => phpbb::$user->ip,
- 'challenge' => $this->challenge,
- 'response' => $this->response,
- ) + $extra_params
- );
-
- $answers = explode("\n", $response[1]);
-
- if (trim($answers[0]) === 'true')
- {
- $this->solved = true;
- return false;
- }
- else
- {
- if ($answers[1] === 'incorrect-captcha-sol')
- {
- return phpbb::$user->lang['RECAPTCHA_INCORRECT'];
- }
- }
- }
-
- /**
- * Encodes the given data into a query string format
- * @param $data - array of string elements to be encoded
- * @return string - encoded request
- */
- protected function _recaptcha_qsencode($data)
- {
- $req = '';
-
- foreach ($data as $key => $value)
- {
- $req .= $key . '=' . urlencode(stripslashes($value)) . '&';
- }
- // Cut the last '&'
- $req = substr($req, 0, strlen($req) - 1);
- return $req;
- }
-}
-
-?> \ No newline at end of file