aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/captcha
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes/captcha')
-rw-r--r--phpBB/includes/captcha/captcha_factory.php52
-rw-r--r--phpBB/includes/captcha/captcha_gd.php5
-rw-r--r--phpBB/includes/captcha/captcha_gd_wave.php5
-rw-r--r--phpBB/includes/captcha/captcha_non_gd.php5
-rw-r--r--phpBB/includes/captcha/plugins/captcha_abstract.php24
-rw-r--r--phpBB/includes/captcha/plugins/phpbb_captcha_gd_plugin.php38
-rw-r--r--phpBB/includes/captcha/plugins/phpbb_captcha_gd_wave_plugin.php27
-rw-r--r--phpBB/includes/captcha/plugins/phpbb_captcha_nogd_plugin.php15
-rw-r--r--phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php70
-rw-r--r--phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php22
10 files changed, 95 insertions, 168 deletions
diff --git a/phpBB/includes/captcha/captcha_factory.php b/phpBB/includes/captcha/captcha_factory.php
index 131c0b3b77..fac45087e3 100644
--- a/phpBB/includes/captcha/captcha_factory.php
+++ b/phpBB/includes/captcha/captcha_factory.php
@@ -2,9 +2,8 @@
/**
*
* @package VC
-* @version $Id$
* @copyright (c) 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
@@ -26,7 +25,7 @@ class phpbb_captcha_factory
/**
* return an instance of class $name in file $name_plugin.php
*/
- function &get_instance($name)
+ static public function get_instance($name)
{
global $phpbb_root_path, $phpEx;
@@ -51,7 +50,8 @@ class phpbb_captcha_factory
{
include($phpbb_root_path . "includes/captcha/plugins/{$name}_plugin." . $phpEx);
}
- call_user_func(array($name, 'garbage_collect'), 0);
+ $captcha = self::get_instance($name);
+ $captcha->garbage_collect(0);
}
/**
@@ -59,42 +59,40 @@ class phpbb_captcha_factory
*/
function get_captcha_types()
{
- global $phpbb_root_path, $phpEx;
+ global $phpbb_root_path, $phpEx, $phpbb_extension_manager;
$captchas = array(
'available' => array(),
'unavailable' => array(),
);
- $dp = @opendir($phpbb_root_path . 'includes/captcha/plugins');
+ $finder = $phpbb_extension_manager->get_finder();
+ $captcha_plugin_classes = $finder
+ ->extension_directory('/captcha')
+ ->suffix('_plugin')
+ ->core_path('includes/captcha/plugins/')
+ ->get_classes();
- if ($dp)
+ foreach ($captcha_plugin_classes as $class)
{
- while (($file = readdir($dp)) !== false)
+ // check if this class needs to be loaded in legacy mode
+ $old_class = preg_replace('/^phpbb_captcha_plugins_/', '', $class);
+ if (file_exists($phpbb_root_path . "includes/captcha/plugins/$old_class.$phpEx") && !class_exists($old_class))
{
- if ((preg_match('#_plugin\.' . $phpEx . '$#', $file)))
- {
- $name = preg_replace('#^(.*?)_plugin\.' . $phpEx . '$#', '\1', $file);
- if (!class_exists($name))
- {
- include($phpbb_root_path . "includes/captcha/plugins/$file");
- }
+ include($phpbb_root_path . "includes/captcha/plugins/$old_class.$phpEx");
+ $class = preg_replace('/_plugin$/', '', $old_class);
+ }
- if (call_user_func(array($name, 'is_available')))
- {
- $captchas['available'][$name] = call_user_func(array($name, 'get_name'));
- }
- else
- {
- $captchas['unavailable'][$name] = call_user_func(array($name, 'get_name'));
- }
- }
+ if (call_user_func(array($class, 'is_available')))
+ {
+ $captchas['available'][$class] = call_user_func(array($class, 'get_name'));
+ }
+ else
+ {
+ $captchas['unavailable'][$class] = call_user_func(array($class, 'get_name'));
}
- closedir($dp);
}
return $captchas;
}
}
-
-?> \ No newline at end of file
diff --git a/phpBB/includes/captcha/captcha_gd.php b/phpBB/includes/captcha/captcha_gd.php
index ecdad43978..f58b590c4b 100644
--- a/phpBB/includes/captcha/captcha_gd.php
+++ b/phpBB/includes/captcha/captcha_gd.php
@@ -2,9 +2,8 @@
/**
*
* @package VC
-* @version $Id$
* @copyright (c) 2006 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
@@ -2636,5 +2635,3 @@ class colour_manager
}
}
}
-
-?> \ No newline at end of file
diff --git a/phpBB/includes/captcha/captcha_gd_wave.php b/phpBB/includes/captcha/captcha_gd_wave.php
index 27422513d9..e19f54f777 100644
--- a/phpBB/includes/captcha/captcha_gd_wave.php
+++ b/phpBB/includes/captcha/captcha_gd_wave.php
@@ -2,9 +2,8 @@
/**
*
* @package VC
-* @version $Id$
* @copyright (c) 2006 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
@@ -841,5 +840,3 @@ class captcha
);
}
}
-
-?> \ No newline at end of file
diff --git a/phpBB/includes/captcha/captcha_non_gd.php b/phpBB/includes/captcha/captcha_non_gd.php
index 2adf909b96..bb5067cafa 100644
--- a/phpBB/includes/captcha/captcha_non_gd.php
+++ b/phpBB/includes/captcha/captcha_non_gd.php
@@ -2,9 +2,8 @@
/**
*
* @package VC
-* @version $Id$
* @copyright (c) 2006 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
@@ -388,5 +387,3 @@ class captcha
);
}
}
-
-?> \ No newline at end of file
diff --git a/phpBB/includes/captcha/plugins/captcha_abstract.php b/phpBB/includes/captcha/plugins/captcha_abstract.php
index 21cacd730c..7fd88feeb5 100644
--- a/phpBB/includes/captcha/plugins/captcha_abstract.php
+++ b/phpBB/includes/captcha/plugins/captcha_abstract.php
@@ -2,9 +2,8 @@
/**
*
* @package VC
-* @version $Id$
* @copyright (c) 2006, 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
@@ -22,7 +21,7 @@ if (!defined('IN_PHPBB'))
*
* @package VC
*/
-class phpbb_default_captcha
+class phpbb_captcha_plugins_captcha_abstract
{
var $confirm_id;
var $confirm_code;
@@ -207,7 +206,6 @@ class phpbb_default_captcha
{
if ($this->check_code())
{
- // $this->delete_code(); commented out to allow posting.php to repeat the question
$this->solved = true;
}
else
@@ -329,17 +327,6 @@ class phpbb_default_captcha
return (strcasecmp($this->code, $this->confirm_code) === 0);
}
- function delete_code()
- {
- global $db, $user;
-
- $sql = 'DELETE FROM ' . CONFIRM_TABLE . "
- WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
- AND session_id = '" . $db->sql_escape($user->session_id) . "'
- AND confirm_type = " . $this->type;
- $db->sql_query($sql);
- }
-
function get_attempt_count()
{
return $this->attempts;
@@ -377,4 +364,9 @@ class phpbb_default_captcha
}
-?> \ No newline at end of file
+/**
+* Old class name for legacy use. The new class name is auto loadable.
+*/
+class phpbb_default_captcha extends phpbb_captcha_plugins_captcha_abstract
+{
+}
diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_gd_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_gd_plugin.php
index 6e899adc16..80f5b65967 100644
--- a/phpBB/includes/captcha/plugins/phpbb_captcha_gd_plugin.php
+++ b/phpBB/includes/captcha/plugins/phpbb_captcha_gd_plugin.php
@@ -2,9 +2,8 @@
/**
*
* @package VC
-* @version $Id$
* @copyright (c) 2006, 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
@@ -19,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* Placeholder for autoload
*/
-if (!class_exists('phpbb_default_captcha'))
+if (!class_exists('phpbb_default_captcha', false))
{
include($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
}
@@ -50,27 +49,15 @@ class phpbb_captcha_gd extends phpbb_default_captcha
}
}
- function &get_instance()
+ static public function get_instance()
{
- $instance =& new phpbb_captcha_gd();
+ $instance = new phpbb_captcha_gd();
return $instance;
}
- function is_available()
+ static public function is_available()
{
- global $phpbb_root_path, $phpEx;
-
- if (@extension_loaded('gd'))
- {
- return true;
- }
-
- if (!function_exists('can_load_dll'))
- {
- include($phpbb_root_path . 'includes/functions_install.' . $phpEx);
- }
-
- return can_load_dll('gd');
+ return @extension_loaded('gd');
}
/**
@@ -81,7 +68,7 @@ class phpbb_captcha_gd extends phpbb_default_captcha
return true;
}
- function get_name()
+ static public function get_name()
{
return 'CAPTCHA_GD';
}
@@ -152,14 +139,19 @@ class phpbb_captcha_gd extends phpbb_default_captcha
global $config;
$config_old = $config;
+
+ $config = new \phpbb\config\config(array());
+ foreach ($config_old as $key => $value)
+ {
+ $config->set($key, $value);
+ }
+
foreach ($this->captcha_vars as $captcha_var => $template_var)
{
- $config[$captcha_var] = request_var($captcha_var, (int) $config[$captcha_var]);
+ $config->set($captcha_var, request_var($captcha_var, (int) $config[$captcha_var]));
}
parent::execute_demo();
$config = $config_old;
}
}
-
-?> \ 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
index 2f55d15efd..0d4b8bd451 100644
--- a/phpBB/includes/captcha/plugins/phpbb_captcha_gd_wave_plugin.php
+++ b/phpBB/includes/captcha/plugins/phpbb_captcha_gd_wave_plugin.php
@@ -2,9 +2,8 @@
/**
*
* @package VC
-* @version $Id$
* @copyright (c) 2006, 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
@@ -19,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* Placeholder for autoload
*/
-if (!class_exists('phpbb_default_captcha'))
+if (!class_exists('phpbb_default_captcha', false))
{
include($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
}
@@ -40,29 +39,17 @@ class phpbb_captcha_gd_wave extends phpbb_default_captcha
}
}
- function get_instance()
+ static public function get_instance()
{
return new phpbb_captcha_gd_wave();
}
- function is_available()
+ static public function is_available()
{
- global $phpbb_root_path, $phpEx;
-
- if (@extension_loaded('gd'))
- {
- return true;
- }
-
- if (!function_exists('can_load_dll'))
- {
- include($phpbb_root_path . 'includes/functions_install.' . $phpEx);
- }
-
- return can_load_dll('gd');
+ return @extension_loaded('gd');
}
- function get_name()
+ static public function get_name()
{
return 'CAPTCHA_GD_3D';
}
@@ -79,5 +66,3 @@ class phpbb_captcha_gd_wave extends phpbb_default_captcha
trigger_error($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
index ac30ed4297..c5ef8c78b0 100644
--- a/phpBB/includes/captcha/plugins/phpbb_captcha_nogd_plugin.php
+++ b/phpBB/includes/captcha/plugins/phpbb_captcha_nogd_plugin.php
@@ -2,9 +2,8 @@
/**
*
* @package VC
-* @version $Id$
* @copyright (c) 2006, 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
@@ -19,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* Placeholder for autoload
*/
-if (!class_exists('phpbb_default_captcha'))
+if (!class_exists('phpbb_default_captcha', false))
{
include($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
}
@@ -40,18 +39,18 @@ class phpbb_captcha_nogd extends phpbb_default_captcha
}
}
- function &get_instance()
+ static public function get_instance()
{
- $instance =& new phpbb_captcha_nogd();
+ $instance = new phpbb_captcha_nogd();
return $instance;
}
- function is_available()
+ static public function is_available()
{
return true;
}
- function get_name()
+ static public function get_name()
{
return 'CAPTCHA_NO_GD';
}
@@ -68,5 +67,3 @@ class phpbb_captcha_nogd extends phpbb_default_captcha
trigger_error($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_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php
index 45f76bd676..82333f739e 100644
--- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php
+++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php
@@ -2,9 +2,8 @@
/**
*
* @package VC
-* @version $Id$
* @copyright (c) 2006, 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
@@ -87,7 +86,7 @@ class phpbb_captcha_qa
}
$db->sql_freeresult($result);
}
-
+
// okay, if there is a confirm_id, we try to load that confirm's state. If not, we try to find one
if (!$this->load_answer() && (!$this->load_confirm_id() || !$this->load_answer()))
{
@@ -99,9 +98,9 @@ class phpbb_captcha_qa
/**
* API function
*/
- function &get_instance()
+ static public function get_instance()
{
- $instance =& new phpbb_captcha_qa();
+ $instance = new phpbb_captcha_qa();
return $instance;
}
@@ -109,15 +108,11 @@ class phpbb_captcha_qa
/**
* See if the captcha has created its tables.
*/
- function is_installed()
+ static public function is_installed()
{
- global $db, $phpbb_root_path, $phpEx;
+ global $db;
- if (!class_exists('phpbb_db_tools'))
- {
- include("$phpbb_root_path/includes/db/db_tools.$phpEx");
- }
- $db_tool = new phpbb_db_tools($db);
+ $db_tool = new \phpbb\db\tools($db);
return $db_tool->sql_table_exists(CAPTCHA_QUESTIONS_TABLE);
}
@@ -125,14 +120,14 @@ class phpbb_captcha_qa
/**
* API function - for the captcha to be available, it must have installed itself and there has to be at least one question in the board's default lang
*/
- function is_available()
+ static public function is_available()
{
global $config, $db, $phpbb_root_path, $phpEx, $user;
// load language file for pretty display in the ACP dropdown
$user->add_lang('captcha_qa');
- if (!phpbb_captcha_qa::is_installed())
+ if (!self::is_installed())
{
return false;
}
@@ -158,7 +153,7 @@ class phpbb_captcha_qa
/**
* API function
*/
- function get_name()
+ static public function get_name()
{
return 'CAPTCHA_QA';
}
@@ -298,13 +293,9 @@ class phpbb_captcha_qa
*/
function install()
{
- global $db, $phpbb_root_path, $phpEx;
+ global $db;
- if (!class_exists('phpbb_db_tools'))
- {
- include("$phpbb_root_path/includes/db/db_tools.$phpEx");
- }
- $db_tool = new phpbb_db_tools($db);
+ $db_tool = new \phpbb\db\tools($db);
$tables = array(CAPTCHA_QUESTIONS_TABLE, CAPTCHA_ANSWERS_TABLE, CAPTCHA_QA_CONFIRM_TABLE);
@@ -365,12 +356,12 @@ class phpbb_captcha_qa
global $config, $db, $user;
$error = '';
-
+
if (!sizeof($this->question_ids))
{
return false;
}
-
+
if (!$this->confirm_id)
{
$error = $user->lang['CONFIRM_QUESTION_WRONG'];
@@ -379,7 +370,6 @@ class phpbb_captcha_qa
{
if ($this->check_answer())
{
- // $this->delete_code(); commented out to allow posting.php to repeat the question
$this->solved = true;
}
else
@@ -434,7 +424,7 @@ class phpbb_captcha_qa
function reselect_question()
{
global $db, $user;
-
+
if (!sizeof($this->question_ids))
{
return false;
@@ -482,8 +472,8 @@ class phpbb_captcha_qa
global $db, $user;
$sql = 'SELECT confirm_id
- FROM ' . CAPTCHA_QA_CONFIRM_TABLE . "
- WHERE
+ FROM ' . CAPTCHA_QA_CONFIRM_TABLE . "
+ WHERE
session_id = '" . $db->sql_escape($user->session_id) . "'
AND lang_iso = '" . $db->sql_escape($this->question_lang) . "'
AND confirm_type = " . $this->type;
@@ -505,7 +495,7 @@ class phpbb_captcha_qa
function load_answer()
{
global $db, $user;
-
+
if (!strlen($this->confirm_id) || !sizeof($this->question_ids))
{
return false;
@@ -567,20 +557,6 @@ class phpbb_captcha_qa
}
/**
- * API function - clean the entry
- */
- function delete_code()
- {
- global $db, $user;
-
- $sql = 'DELETE FROM ' . CAPTCHA_QA_CONFIRM_TABLE . "
- WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
- AND session_id = '" . $db->sql_escape($user->session_id) . "'
- AND confirm_type = " . $this->type;
- $db->sql_query($sql);
- }
-
- /**
* API function
*/
function get_attempt_count()
@@ -628,7 +604,7 @@ class phpbb_captcha_qa
$user->add_lang('acp/board');
$user->add_lang('captcha_qa');
- if (!$this->is_installed())
+ if (!self::is_installed())
{
$this->install();
}
@@ -990,9 +966,9 @@ class phpbb_captcha_qa
return $langs;
}
-
-
-
+
+
+
/**
* See if there is a question other than the one we have
*/
@@ -1018,5 +994,3 @@ class phpbb_captcha_qa
}
}
}
-
-?> \ 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
index 0b0270f568..cb21b04ec5 100644
--- a/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php
+++ b/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php
@@ -2,9 +2,8 @@
/**
*
* @package VC
-* @version $Id$
* @copyright (c) 2006, 2008 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
@@ -16,7 +15,7 @@ if (!defined('IN_PHPBB'))
exit;
}
-if (!class_exists('phpbb_default_captcha'))
+if (!class_exists('phpbb_default_captcha', false))
{
// we need the classic captcha code for tracking solutions and attempts
include($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
@@ -41,7 +40,8 @@ class phpbb_recaptcha extends phpbb_default_captcha
// PHP4 Constructor
function phpbb_recaptcha()
{
- $this->recaptcha_server = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? $this->recaptcha_server_secure : $this->recaptcha_server;
+ global $request;
+ $this->recaptcha_server = $request->is_secure() ? $this->recaptcha_server_secure : $this->recaptcha_server;
}
function init($type)
@@ -54,13 +54,13 @@ class phpbb_recaptcha extends phpbb_default_captcha
$this->response = request_var('recaptcha_response_field', '');
}
- function &get_instance()
+ static public function get_instance()
{
- $instance =& new phpbb_recaptcha();
+ $instance = new phpbb_recaptcha();
return $instance;
}
- function is_available()
+ static public function is_available()
{
global $config, $user;
$user->add_lang('captcha_recaptcha');
@@ -75,7 +75,7 @@ class phpbb_recaptcha extends phpbb_default_captcha
return true;
}
- function get_name()
+ static public function get_name()
{
return 'CAPTCHA_RECAPTCHA';
}
@@ -163,7 +163,7 @@ class phpbb_recaptcha extends phpbb_default_captcha
'RECAPTCHA_SERVER' => $this->recaptcha_server,
'RECAPTCHA_PUBKEY' => isset($config['recaptcha_pubkey']) ? $config['recaptcha_pubkey'] : '',
'RECAPTCHA_ERRORGET' => '',
- 'S_RECAPTCHA_AVAILABLE' => $this->is_available(),
+ 'S_RECAPTCHA_AVAILABLE' => self::is_available(),
'S_CONFIRM_CODE' => true,
'S_TYPE' => $this->type,
'L_CONFIRM_EXPLAIN' => $explain,
@@ -270,7 +270,7 @@ class phpbb_recaptcha extends phpbb_default_captcha
$response = '';
if (false == ($fs = @fsockopen($host, $port, $errno, $errstr, 10)))
{
- trigger_error('Could not open socket', E_USER_ERROR);
+ trigger_error('RECAPTCHA_SOCKET_ERROR', E_USER_ERROR);
}
fwrite($fs, $http_request);
@@ -341,5 +341,3 @@ class phpbb_recaptcha extends phpbb_default_captcha
return $req;
}
}
-
-?> \ No newline at end of file