aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authorTristan Darricau <github@nicofuma.fr>2014-08-08 18:02:03 +0200
committerTristan Darricau <github@nicofuma.fr>2014-08-11 01:15:49 +0200
commit160ff7b912243dc14d871b820213ddcd20dd06f4 (patch)
treed6d2f0e7fa38cc5944c7a0fa438c1deea2adc1c6 /phpBB
parente0d377bca70cff7846ba920a03b717aac1d208a4 (diff)
downloadforums-160ff7b912243dc14d871b820213ddcd20dd06f4.tar
forums-160ff7b912243dc14d871b820213ddcd20dd06f4.tar.gz
forums-160ff7b912243dc14d871b820213ddcd20dd06f4.tar.bz2
forums-160ff7b912243dc14d871b820213ddcd20dd06f4.tar.xz
forums-160ff7b912243dc14d871b820213ddcd20dd06f4.zip
[ticket/11854] Move captcha stuff to phpbb/ and use DI for plugins
PHPBB3-11854
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/config/captcha.yml43
-rw-r--r--phpBB/config/services.yml1
-rw-r--r--phpBB/includes/acp/acp_captcha.php17
-rw-r--r--phpBB/includes/captcha/captcha_factory.php100
-rw-r--r--phpBB/includes/captcha/plugins/phpbb_captcha_gd_wave_plugin.php69
-rw-r--r--phpBB/includes/captcha/plugins/phpbb_captcha_nogd_plugin.php70
-rw-r--r--phpBB/includes/functions.php7
-rw-r--r--phpBB/includes/ucp/ucp_confirm.php5
-rw-r--r--phpBB/includes/ucp/ucp_login_link.php4
-rw-r--r--phpBB/includes/ucp/ucp_register.php3
-rw-r--r--phpBB/phpbb/auth/provider/db.php8
-rw-r--r--phpBB/phpbb/captcha/factory.php83
-rw-r--r--phpBB/phpbb/captcha/gd.php (renamed from phpBB/includes/captcha/captcha_gd.php)10
-rw-r--r--phpBB/phpbb/captcha/gd_wave.php (renamed from phpBB/includes/captcha/captcha_gd_wave.php)4
-rw-r--r--phpBB/phpbb/captcha/non_gd.php (renamed from phpBB/includes/captcha/captcha_non_gd.php)10
-rw-r--r--phpBB/phpbb/captcha/plugins/captcha_abstract.php (renamed from phpBB/includes/captcha/plugins/captcha_abstract.php)32
-rw-r--r--phpBB/phpbb/captcha/plugins/gd.php (renamed from phpBB/includes/captcha/plugins/phpbb_captcha_gd_plugin.php)52
-rw-r--r--phpBB/phpbb/captcha/plugins/gd_wave.php50
-rw-r--r--phpBB/phpbb/captcha/plugins/nogd.php50
-rw-r--r--phpBB/phpbb/captcha/plugins/qa.php (renamed from phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php)40
-rw-r--r--phpBB/phpbb/captcha/plugins/recaptcha.php (renamed from phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php)41
-rw-r--r--phpBB/phpbb/session.php8
-rw-r--r--phpBB/posting.php3
-rw-r--r--phpBB/report.php3
24 files changed, 313 insertions, 400 deletions
diff --git a/phpBB/config/captcha.yml b/phpBB/config/captcha.yml
new file mode 100644
index 0000000000..527dba2257
--- /dev/null
+++ b/phpBB/config/captcha.yml
@@ -0,0 +1,43 @@
+services:
+ captchas.factory:
+ class: phpbb\captcha\factory
+ arguments:
+ - @service_container
+ - @captchas.plugins.service_collection
+
+ captchas.plugins.service_collection:
+ class: phpbb\di\service_collection
+ arguments:
+ - @service_container
+ tags:
+ - { name: service_collection, tag: captchas.plugins }
+
+ core.captcha.plugins.gd:
+ class: phpbb\captcha\plugins\gd
+ scope: prototype # scope MUST be prototype for this to work! # scope MUST be prototype for this to work!
+ tags:
+ - { name: captchas.plugins }
+
+ core.captcha.plugins.gd_wave:
+ class: phpbb\captcha\plugins\gd_wave
+ scope: prototype # scope MUST be prototype for this to work! # scope MUST be prototype for this to work!
+ tags:
+ - { name: captchas.plugins }
+
+ core.captcha.plugins.nogd:
+ class: phpbb\captcha\plugins\nogd
+ scope: prototype # scope MUST be prototype for this to work! # scope MUST be prototype for this to work!
+ tags:
+ - { name: captchas.plugins }
+
+ core.captcha.plugins.qa:
+ class: phpbb\captcha\plugins\qa
+ scope: prototype # scope MUST be prototype for this to work! # scope MUST be prototype for this to work!
+ tags:
+ - { name: captchas.plugins }
+
+ core.captcha.plugins.recaptcha:
+ class: phpbb\captcha\plugins\recaptcha
+ scope: prototype # scope MUST be prototype for this to work! # scope MUST be prototype for this to work!
+ tags:
+ - { name: captchas.plugins }
diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml
index 6b06deb256..a588046245 100644
--- a/phpBB/config/services.yml
+++ b/phpBB/config/services.yml
@@ -10,6 +10,7 @@ imports:
- { resource: mimetype_guessers.yml }
- { resource: passwords.yml }
- { resource: profilefields.yml }
+ - { resource: captcha.yml }
- { resource: parameters.yml }
services:
diff --git a/phpBB/includes/acp/acp_captcha.php b/phpBB/includes/acp/acp_captcha.php
index a625005bf8..099acf707b 100644
--- a/phpBB/includes/acp/acp_captcha.php
+++ b/phpBB/includes/acp/acp_captcha.php
@@ -26,12 +26,11 @@ class acp_captcha
function main($id, $mode)
{
global $db, $user, $auth, $template;
- global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
+ global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container;
$user->add_lang('acp/board');
- include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
- $factory = new phpbb_captcha_factory();
+ $factory = $phpbb_container->get('captchas.factory');
$captchas = $factory->get_captcha_types();
$selected = request_var('select_captcha', $config['captcha_plugin']);
@@ -47,7 +46,7 @@ class acp_captcha
// Delegate
if ($configure)
{
- $config_captcha = phpbb_captcha_factory::get_instance($selected);
+ $config_captcha = $factory->get_instance($selected);
$config_captcha->acp_page($id, $this);
}
else
@@ -79,11 +78,11 @@ class acp_captcha
// sanity check
if (isset($captchas['available'][$selected]))
{
- $old_captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
+ $old_captcha = $factory->get_instance($config['captcha_plugin']);
$old_captcha->uninstall();
set_config('captcha_plugin', $selected);
- $new_captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
+ $new_captcha = $factory->get_instance($config['captcha_plugin']);
$new_captcha->install();
add_log('admin', 'LOG_CONFIG_VISUAL');
@@ -114,7 +113,7 @@ class acp_captcha
$captcha_select .= '<option value="' . $value . '"' . $current . ' class="disabled-option">' . $user->lang($title) . '</option>';
}
- $demo_captcha = phpbb_captcha_factory::get_instance($selected);
+ $demo_captcha = $factory->get_instance($selected);
foreach ($config_vars as $config_var => $options)
{
@@ -137,9 +136,9 @@ class acp_captcha
*/
function deliver_demo($selected)
{
- global $db, $user, $config;
+ global $db, $user, $config, $phpbb_container;
- $captcha = phpbb_captcha_factory::get_instance($selected);
+ $captcha = $phpbb_container->get('captchas.factory')->get_instance($selected);
$captcha->init(CONFIRM_REG);
$captcha->execute_demo();
diff --git a/phpBB/includes/captcha/captcha_factory.php b/phpBB/includes/captcha/captcha_factory.php
deleted file mode 100644
index ebeb695282..0000000000
--- a/phpBB/includes/captcha/captcha_factory.php
+++ /dev/null
@@ -1,100 +0,0 @@
-<?php
-/**
-*
-* This file is part of the phpBB Forum Software package.
-*
-* @copyright (c) phpBB Limited <https://www.phpbb.com>
-* @license GNU General Public License, version 2 (GPL-2.0)
-*
-* For full copyright and license information, please see
-* the docs/CREDITS.txt file.
-*
-*/
-
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-/**
-* A small class for 3.0.x (no autoloader in 3.0.x)
-*/
-class phpbb_captcha_factory
-{
- /**
- * return an instance of class $name in file $name_plugin.php
- */
- static public function get_instance($name)
- {
- global $phpbb_root_path, $phpEx;
-
- $name = basename($name);
- if (!class_exists($name))
- {
- include($phpbb_root_path . "includes/captcha/plugins/{$name}_plugin." . $phpEx);
- }
- $instance = call_user_func(array($name, 'get_instance'));
- return $instance;
- }
-
- /**
- * Call the garbage collector
- */
- function garbage_collect($name)
- {
- global $phpbb_root_path, $phpEx;
-
- $name = basename($name);
- if (!class_exists($name))
- {
- include($phpbb_root_path . "includes/captcha/plugins/{$name}_plugin." . $phpEx);
- }
- $captcha = self::get_instance($name);
- $captcha->garbage_collect(0);
- }
-
- /**
- * return a list of all discovered CAPTCHA plugins
- */
- function get_captcha_types()
- {
- global $phpbb_root_path, $phpEx, $phpbb_extension_manager;
-
- $captchas = array(
- 'available' => array(),
- 'unavailable' => array(),
- );
-
- $finder = $phpbb_extension_manager->get_finder();
- $captcha_plugin_classes = $finder
- ->extension_directory('/captcha')
- ->suffix('_plugin')
- ->core_path('includes/captcha/plugins/')
- ->get_classes();
-
- foreach ($captcha_plugin_classes as $class)
- {
- // 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))
- {
- include($phpbb_root_path . "includes/captcha/plugins/$old_class.$phpEx");
- $class = preg_replace('/_plugin$/', '', $old_class);
- }
-
- 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'));
- }
- }
-
- return $captchas;
- }
-}
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 b6ccabaa2e..0000000000
--- a/phpBB/includes/captcha/plugins/phpbb_captcha_gd_wave_plugin.php
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-/**
-*
-* This file is part of the phpBB Forum Software package.
-*
-* @copyright (c) phpBB Limited <https://www.phpbb.com>
-* @license GNU General Public License, version 2 (GPL-2.0)
-*
-* For full copyright and license information, please see
-* the docs/CREDITS.txt file.
-*
-*/
-
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-/**
-* Placeholder for autoload
-*/
-if (!class_exists('phpbb_default_captcha', false))
-{
- include($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
-}
-
-class phpbb_captcha_gd_wave extends phpbb_default_captcha
-{
-
- function phpbb_captcha_gd_wave()
- {
- global $phpbb_root_path, $phpEx;
-
- if (!class_exists('captcha'))
- {
- include_once($phpbb_root_path . 'includes/captcha/captcha_gd_wave.' . $phpEx);
- }
- }
-
- static public function get_instance()
- {
- return new phpbb_captcha_gd_wave();
- }
-
- static public function is_available()
- {
- return @extension_loaded('gd');
- }
-
- static public function get_name()
- {
- return 'CAPTCHA_GD_3D';
- }
-
- function get_class_name()
- {
- return 'phpbb_captcha_gd_wave';
- }
-
- function acp_page($id, &$module)
- {
- global $config, $db, $template, $user;
-
- trigger_error($user->lang['CAPTCHA_NO_OPTIONS'] . adm_back_link($module->u_action));
- }
-}
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 64f788a659..0000000000
--- a/phpBB/includes/captcha/plugins/phpbb_captcha_nogd_plugin.php
+++ /dev/null
@@ -1,70 +0,0 @@
-<?php
-/**
-*
-* This file is part of the phpBB Forum Software package.
-*
-* @copyright (c) phpBB Limited <https://www.phpbb.com>
-* @license GNU General Public License, version 2 (GPL-2.0)
-*
-* For full copyright and license information, please see
-* the docs/CREDITS.txt file.
-*
-*/
-
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-/**
-* Placeholder for autoload
-*/
-if (!class_exists('phpbb_default_captcha', false))
-{
- include($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
-}
-
-class phpbb_captcha_nogd extends phpbb_default_captcha
-{
-
- function phpbb_captcha_nogd()
- {
- global $phpbb_root_path, $phpEx;
-
- if (!class_exists('captcha'))
- {
- include_once($phpbb_root_path . 'includes/captcha/captcha_non_gd.' . $phpEx);
- }
- }
-
- static public function get_instance()
- {
- $instance = new phpbb_captcha_nogd();
- return $instance;
- }
-
- static public function is_available()
- {
- return true;
- }
-
- static public function get_name()
- {
- return 'CAPTCHA_NO_GD';
- }
-
- function get_class_name()
- {
- return 'phpbb_captcha_nogd';
- }
-
- function acp_page($id, &$module)
- {
- global $user;
-
- trigger_error($user->lang['CAPTCHA_NO_OPTIONS'] . adm_back_link($module->u_action));
- }
-}
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 6a2edb0d58..d0a32030e3 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -2730,11 +2730,6 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa
global $db, $user, $template, $auth, $phpEx, $phpbb_root_path, $config;
global $request, $phpbb_container;
- if (!class_exists('phpbb_captcha_factory', false))
- {
- include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
- }
-
$err = '';
// Make sure user->setup() has been called
@@ -2844,7 +2839,7 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa
{
case LOGIN_ERROR_ATTEMPTS:
- $captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
+ $captcha = $phpbb_container->get('captchas.factory')->get_instance($config['captcha_plugin']);
$captcha->init(CONFIRM_LOGIN);
// $captcha->reset();
diff --git a/phpBB/includes/ucp/ucp_confirm.php b/phpBB/includes/ucp/ucp_confirm.php
index bcba32cdf6..8ade142e2b 100644
--- a/phpBB/includes/ucp/ucp_confirm.php
+++ b/phpBB/includes/ucp/ucp_confirm.php
@@ -36,10 +36,9 @@ class ucp_confirm
function main($id, $mode)
{
- global $db, $user, $phpbb_root_path, $config, $phpEx;
+ global $db, $user, $phpbb_root_path, $config, $phpEx, $phpbb_container;
- include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
- $captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
+ $captcha = $phpbb_container->get('captchas.factory')->get_instance($config['captcha_plugin']);
$captcha->init(request_var('type', 0));
$captcha->execute();
diff --git a/phpBB/includes/ucp/ucp_login_link.php b/phpBB/includes/ucp/ucp_login_link.php
index a8762313fd..7c768992f7 100644
--- a/phpBB/includes/ucp/ucp_login_link.php
+++ b/phpBB/includes/ucp/ucp_login_link.php
@@ -181,7 +181,7 @@ class ucp_login_link
*/
protected function process_login_result($result)
{
- global $config, $request, $template, $user;
+ global $config, $request, $template, $user, $phpbb_container;
$login_error = null;
@@ -197,7 +197,7 @@ class ucp_login_link
{
case LOGIN_ERROR_ATTEMPTS:
- $captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
+ $captcha = $phpbb_container->get('captchas.factory')->get_instance($config['captcha_plugin']);
$captcha->init(CONFIRM_LOGIN);
$template->assign_vars(array(
diff --git a/phpBB/includes/ucp/ucp_register.php b/phpBB/includes/ucp/ucp_register.php
index 97934fc32d..dbe2233553 100644
--- a/phpBB/includes/ucp/ucp_register.php
+++ b/phpBB/includes/ucp/ucp_register.php
@@ -182,8 +182,7 @@ class ucp_register
// The CAPTCHA kicks in here. We can't help that the information gets lost on language change.
if ($config['enable_confirm'])
{
- include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
- $captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
+ $captcha = $phpbb_container->get('captchas.factory')->get_instance($config['captcha_plugin']);
$captcha->init(CONFIRM_REG);
}
diff --git a/phpBB/phpbb/auth/provider/db.php b/phpBB/phpbb/auth/provider/db.php
index 142a47247f..cb7a2f8b1a 100644
--- a/phpBB/phpbb/auth/provider/db.php
+++ b/phpBB/phpbb/auth/provider/db.php
@@ -146,13 +146,7 @@ class db extends \phpbb\auth\provider\base
// Every auth module is able to define what to do by itself...
if ($show_captcha)
{
- // Visual Confirmation handling
- if (!class_exists('phpbb_captcha_factory', false))
- {
- include ($this->phpbb_root_path . 'includes/captcha/captcha_factory.' . $this->php_ext);
- }
-
- $captcha = \phpbb_captcha_factory::get_instance($this->config['captcha_plugin']);
+ $captcha = $this->captchas_manager->get_instance($this->config['captcha_plugin']);
$captcha->init(CONFIRM_LOGIN);
$vc_response = $captcha->validate($row);
if ($vc_response)
diff --git a/phpBB/phpbb/captcha/factory.php b/phpBB/phpbb/captcha/factory.php
new file mode 100644
index 0000000000..6164b12e85
--- /dev/null
+++ b/phpBB/phpbb/captcha/factory.php
@@ -0,0 +1,83 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace phpbb\captcha;
+
+/**
+* A small class for 3.0.x (no autoloader in 3.0.x)
+*/
+class factory
+{
+ /**
+ * @var \Symfony\Component\DependencyInjection\ContainerInterface
+ */
+ private $container;
+
+ /**
+ * @var \phpbb\di\service_collection
+ */
+ private $plugins;
+
+ /**
+ * Constructor
+ *
+ * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
+ * @param \phpbb\di\service_collection $plugins
+ */
+ public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container,\phpbb\di\service_collection $plugins)
+ {
+ $this->container = $container;
+ $this->plugins = $plugins;
+ }
+
+ //static public function get_instance($name)
+
+ public function get_instance($name)
+ {
+ return $this->container->get($name);
+ }
+
+ /**
+ * Call the garbage collector
+ */
+ function garbage_collect($name)
+ {
+ $captcha = $this->get_instance($name);
+ $captcha->garbage_collect(0);
+ }
+
+ /**
+ * return a list of all registered CAPTCHA plugins
+ */
+ function get_captcha_types()
+ {
+ $captchas = array(
+ 'available' => array(),
+ 'unavailable' => array(),
+ );
+
+ foreach ($this->plugins as $plugin => $plugin_instance)
+ {
+ if ($plugin_instance->is_available())
+ {
+ $captchas['available'][$plugin] = $plugin_instance->get_name();
+ }
+ else
+ {
+ $captchas['unavailable'][$plugin] = $plugin_instance->get_name();
+ }
+ }
+
+ return $captchas;
+ }
+}
diff --git a/phpBB/includes/captcha/captcha_gd.php b/phpBB/phpbb/captcha/gd.php
index 7e37cc33f9..682022c8ed 100644
--- a/phpBB/includes/captcha/captcha_gd.php
+++ b/phpBB/phpbb/captcha/gd.php
@@ -11,15 +11,9 @@
*
*/
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
+namespace phpbb\captcha;
-class captcha
+class gd
{
var $width = 360;
var $height = 96;
diff --git a/phpBB/includes/captcha/captcha_gd_wave.php b/phpBB/phpbb/captcha/gd_wave.php
index c2a4d3a31e..d48fc753a5 100644
--- a/phpBB/includes/captcha/captcha_gd_wave.php
+++ b/phpBB/phpbb/captcha/gd_wave.php
@@ -11,10 +11,12 @@
*
*/
+namespace phpbb\captcha;
+
/**
* Wave3D CAPTCHA
*/
-class captcha
+class gd_wave
{
var $width = 360;
var $height = 96;
diff --git a/phpBB/includes/captcha/captcha_non_gd.php b/phpBB/phpbb/captcha/non_gd.php
index 91970ea7a4..0a7aeb0e6c 100644
--- a/phpBB/includes/captcha/captcha_non_gd.php
+++ b/phpBB/phpbb/captcha/non_gd.php
@@ -11,19 +11,13 @@
*
*/
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
+namespace phpbb\captcha;
/**
* Main non-gd captcha class
* @ignore
*/
-class captcha
+class non_gd
{
var $filtered_pngs;
var $width = 320;
diff --git a/phpBB/includes/captcha/plugins/captcha_abstract.php b/phpBB/phpbb/captcha/plugins/captcha_abstract.php
index 8e1e61bdb7..982798e464 100644
--- a/phpBB/includes/captcha/plugins/captcha_abstract.php
+++ b/phpBB/phpbb/captcha/plugins/captcha_abstract.php
@@ -11,18 +11,12 @@
*
*/
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
+namespace phpbb\captcha\plugins;
/**
* This class holds the code shared by the two default 3.0.x CAPTCHAs.
*/
-class phpbb_captcha_plugins_captcha_abstract
+abstract class captcha_abstract
{
var $confirm_id;
var $confirm_code;
@@ -65,7 +59,8 @@ class phpbb_captcha_plugins_captcha_abstract
// compute $seed % 0x7fffffff
$this->seed -= 0x7fffffff * floor($this->seed / 0x7fffffff);
- $captcha = new captcha();
+ $generator = $this->get_generator_class();
+ $captcha = new $generator();
define('IMAGE_OUTPUT', 1);
$captcha->execute($this->code, $this->seed);
}
@@ -80,7 +75,8 @@ class phpbb_captcha_plugins_captcha_abstract
return false;
}
}
- $captcha = new captcha();
+ $generator = $this->get_generator_class();
+ $captcha = new $generator();
define('IMAGE_OUTPUT', 1);
$captcha->execute($this->code, $this->seed);
}
@@ -130,7 +126,7 @@ class phpbb_captcha_plugins_captcha_abstract
// acp_captcha has a delivery function; let's use it
$template->assign_vars(array(
- 'CONFIRM_IMAGE' => append_sid($phpbb_admin_path . 'index.' . $phpEx, 'captcha_demo=1&amp;mode=visual&amp;i=' . $id . '&amp;select_captcha=' . $this->get_class_name()) . $variables,
+ 'CONFIRM_IMAGE' => append_sid($phpbb_admin_path . 'index.' . $phpEx, 'captcha_demo=1&amp;mode=visual&amp;i=' . $id . '&amp;select_captcha=' . $this->get_service_name()) . $variables,
'CONFIRM_ID' => $this->confirm_id,
));
@@ -364,11 +360,13 @@ class phpbb_captcha_plugins_captcha_abstract
return false;
}
-}
+ /**
+ * @return string the name of the service corresponding to the plugin
+ */
+ abstract function get_service_name();
-/**
-* Old class name for legacy use. The new class name is auto loadable.
-*/
-class phpbb_default_captcha extends phpbb_captcha_plugins_captcha_abstract
-{
+ /**
+ * @return string the name of the class used to generate the captcha
+ */
+ abstract function get_generator_class();
}
diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_gd_plugin.php b/phpBB/phpbb/captcha/plugins/gd.php
index 8dbd458ede..c1d8c83095 100644
--- a/phpBB/includes/captcha/plugins/phpbb_captcha_gd_plugin.php
+++ b/phpBB/phpbb/captcha/plugins/gd.php
@@ -11,25 +11,10 @@
*
*/
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
+namespace phpbb\captcha\plugins;
-/**
-* Placeholder for autoload
-*/
-if (!class_exists('phpbb_default_captcha', false))
+class gd extends captcha_abstract
{
- include($phpbb_root_path . 'includes/captcha/plugins/captcha_abstract.' . $phpEx);
-}
-
-class phpbb_captcha_gd extends phpbb_default_captcha
-{
-
var $captcha_vars = array(
'captcha_gd_x_grid' => 'CAPTCHA_GD_X_GRID',
'captcha_gd_y_grid' => 'CAPTCHA_GD_Y_GRID',
@@ -40,25 +25,25 @@ class phpbb_captcha_gd extends phpbb_default_captcha
'captcha_gd_fonts' => 'CAPTCHA_GD_FONTS',
);
- function phpbb_captcha_gd()
+ public function is_available()
{
- global $phpbb_root_path, $phpEx;
-
- if (!class_exists('captcha'))
- {
- include($phpbb_root_path . 'includes/captcha/captcha_gd.' . $phpEx);
- }
+ return @extension_loaded('gd');
}
- static public function get_instance()
+ /**
+ * @return string the name of the service corresponding to the plugin
+ */
+ function get_service_name()
{
- $instance = new phpbb_captcha_gd();
- return $instance;
+ return 'core.captcha.plugins.gd';
}
- static public function is_available()
+ /**
+ * @return string the name of the class used to generate the captcha
+ */
+ function get_generator_class()
{
- return @extension_loaded('gd');
+ return '\\phpbb\\captcha\\gd';
}
/**
@@ -69,16 +54,11 @@ class phpbb_captcha_gd extends phpbb_default_captcha
return true;
}
- static public function get_name()
+ public function get_name()
{
return 'CAPTCHA_GD';
}
- function get_class_name()
- {
- return 'phpbb_captcha_gd';
- }
-
function acp_page($id, &$module)
{
global $db, $user, $auth, $template;
@@ -129,7 +109,7 @@ class phpbb_captcha_gd extends phpbb_default_captcha
$template->assign_vars(array(
'CAPTCHA_PREVIEW' => $this->get_demo_template($id),
- 'CAPTCHA_NAME' => $this->get_class_name(),
+ 'CAPTCHA_NAME' => $this->get_service_name(),
'U_ACTION' => $module->u_action,
));
}
diff --git a/phpBB/phpbb/captcha/plugins/gd_wave.php b/phpBB/phpbb/captcha/plugins/gd_wave.php
new file mode 100644
index 0000000000..2d38ef08dd
--- /dev/null
+++ b/phpBB/phpbb/captcha/plugins/gd_wave.php
@@ -0,0 +1,50 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace phpbb\captcha\plugins;
+
+class gd_wave extends captcha_abstract
+{
+ public function is_available()
+ {
+ return @extension_loaded('gd');
+ }
+
+ public function get_name()
+ {
+ return 'CAPTCHA_GD_3D';
+ }
+
+ /**
+ * @return string the name of the service corresponding to the plugin
+ */
+ function get_service_name()
+ {
+ return 'core.captcha.plugins.gd_wave';
+ }
+
+ /**
+ * @return string the name of the class used to generate the captcha
+ */
+ function get_generator_class()
+ {
+ return '\\phpbb\\captcha\\gd_wave';
+ }
+
+ function acp_page($id, &$module)
+ {
+ global $config, $db, $template, $user;
+
+ trigger_error($user->lang['CAPTCHA_NO_OPTIONS'] . adm_back_link($module->u_action));
+ }
+}
diff --git a/phpBB/phpbb/captcha/plugins/nogd.php b/phpBB/phpbb/captcha/plugins/nogd.php
new file mode 100644
index 0000000000..dbf0664a62
--- /dev/null
+++ b/phpBB/phpbb/captcha/plugins/nogd.php
@@ -0,0 +1,50 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace phpbb\captcha\plugins;
+
+class nogd extends captcha_abstract
+{
+ public function is_available()
+ {
+ return true;
+ }
+
+ public function get_name()
+ {
+ return 'CAPTCHA_NO_GD';
+ }
+
+ /**
+ * @return string the name of the service corresponding to the plugin
+ */
+ function get_service_name()
+ {
+ return 'core.captcha.plugins.nogd';
+ }
+
+ /**
+ * @return string the name of the class used to generate the captcha
+ */
+ function get_generator_class()
+ {
+ return '\\phpbb\\captcha\\non_gd';
+ }
+
+ function acp_page($id, &$module)
+ {
+ global $user;
+
+ trigger_error($user->lang['CAPTCHA_NO_OPTIONS'] . adm_back_link($module->u_action));
+ }
+}
diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/phpbb/captcha/plugins/qa.php
index 5a44755365..6dab573c3e 100644
--- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php
+++ b/phpBB/phpbb/captcha/plugins/qa.php
@@ -11,13 +11,7 @@
*
*/
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
+namespace phpbb\captcha\plugins;
global $table_prefix;
@@ -29,7 +23,7 @@ define('CAPTCHA_QA_CONFIRM_TABLE', $table_prefix . 'qa_confirm');
* And now to something completely different. Let's make a captcha without extending the abstract class.
* QA CAPTCHA sample implementation
*/
-class phpbb_captcha_qa
+class qa
{
var $confirm_id;
var $answer;
@@ -98,19 +92,9 @@ class phpbb_captcha_qa
}
/**
- * API function
- */
- static public function get_instance()
- {
- $instance = new phpbb_captcha_qa();
-
- return $instance;
- }
-
- /**
* See if the captcha has created its tables.
*/
- static public function is_installed()
+ public function is_installed()
{
global $db;
@@ -122,14 +106,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
*/
- static public function is_available()
+ 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 (!self::is_installed())
+ if (!$this->is_installed())
{
return false;
}
@@ -163,9 +147,9 @@ class phpbb_captcha_qa
/**
* API function
*/
- function get_class_name()
+ function get_service_name()
{
- return 'phpbb_captcha_qa';
+ return 'core.captcha.plugins.qa';
}
/**
@@ -621,12 +605,12 @@ class phpbb_captcha_qa
$action = request_var('action', '');
// we have two pages, so users might want to navigate from one to the other
- $list_url = $module->u_action . "&amp;configure=1&amp;select_captcha=" . $this->get_class_name();
+ $list_url = $module->u_action . "&amp;configure=1&amp;select_captcha=" . $this->get_service_name();
$template->assign_vars(array(
'U_ACTION' => $module->u_action,
'QUESTION_ID' => $question_id ,
- 'CLASS' => $this->get_class_name(),
+ 'CLASS' => $this->get_service_name(),
));
// show the list?
@@ -636,7 +620,7 @@ class phpbb_captcha_qa
}
else if ($question_id && $action == 'delete')
{
- if ($this->get_class_name() !== $config['captcha_plugin'] || !$this->acp_is_last($question_id))
+ if ($this->get_service_name() !== $config['captcha_plugin'] || !$this->acp_is_last($question_id))
{
if (confirm_box(true))
{
@@ -650,7 +634,7 @@ class phpbb_captcha_qa
'question_id' => $question_id,
'action' => $action,
'configure' => 1,
- 'select_captcha' => $this->get_class_name(),
+ 'select_captcha' => $this->get_service_name(),
))
);
}
@@ -759,7 +743,7 @@ class phpbb_captcha_qa
while ($row = $db->sql_fetchrow($result))
{
- $url = $module->u_action . "&amp;question_id={$row['question_id']}&amp;configure=1&amp;select_captcha=" . $this->get_class_name() . '&amp;';
+ $url = $module->u_action . "&amp;question_id={$row['question_id']}&amp;configure=1&amp;select_captcha=" . $this->get_service_name() . '&amp;';
$template->assign_block_vars('questions', array(
'QUESTION_TEXT' => $row['question_text'],
diff --git a/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php b/phpBB/phpbb/captcha/plugins/recaptcha.php
index 12cc49ef9b..9fffea756e 100644
--- a/phpBB/includes/captcha/plugins/phpbb_recaptcha_plugin.php
+++ b/phpBB/phpbb/captcha/plugins/recaptcha.php
@@ -11,21 +11,9 @@
*
*/
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
+namespace phpbb\captcha\plugins;
-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);
-}
-
-class phpbb_recaptcha extends phpbb_default_captcha
+class recaptcha extends \phpbb\captcha\plugins\captcha_abstract
{
var $recaptcha_server = 'http://www.google.com/recaptcha/api';
var $recaptcha_server_secure = 'https://www.google.com/recaptcha/api'; // class constants :(
@@ -55,13 +43,7 @@ class phpbb_recaptcha extends phpbb_default_captcha
$this->response = request_var('recaptcha_response_field', '');
}
- static public function get_instance()
- {
- $instance = new phpbb_recaptcha();
- return $instance;
- }
-
- static public function is_available()
+ public function is_available()
{
global $config, $user;
$user->add_lang('captcha_recaptcha');
@@ -81,9 +63,20 @@ class phpbb_recaptcha extends phpbb_default_captcha
return 'CAPTCHA_RECAPTCHA';
}
- function get_class_name()
+ /**
+ * @return string the name of the service corresponding to the plugin
+ */
+ function get_service_name()
+ {
+ return 'core.captcha.plugins.recaptcha';
+ }
+
+ /**
+ * @return string the name of the class used to generate the captcha
+ */
+ function get_generator_class()
{
- return 'phpbb_recaptcha';
+ throw new \Exception('Go out devil!');
}
function acp_page($id, &$module)
@@ -131,7 +124,7 @@ class phpbb_recaptcha extends phpbb_default_captcha
$template->assign_vars(array(
'CAPTCHA_PREVIEW' => $this->get_demo_template($id),
- 'CAPTCHA_NAME' => $this->get_class_name(),
+ 'CAPTCHA_NAME' => $this->get_service_name(),
'U_ACTION' => $module->u_action,
));
diff --git a/phpBB/phpbb/session.php b/phpBB/phpbb/session.php
index 5a0d7c0031..a9dde5bbaa 100644
--- a/phpBB/phpbb/session.php
+++ b/phpBB/phpbb/session.php
@@ -962,7 +962,7 @@ class session
*/
function session_gc()
{
- global $db, $config, $phpbb_root_path, $phpEx;
+ global $db, $config, $phpbb_root_path, $phpEx, $phpbb_container;
$batch_size = 10;
@@ -1022,11 +1022,7 @@ class session
}
// only called from CRON; should be a safe workaround until the infrastructure gets going
- if (!class_exists('phpbb_captcha_factory', false))
- {
- include($phpbb_root_path . "includes/captcha/captcha_factory." . $phpEx);
- }
- $captcha_factory = new \phpbb_captcha_factory();
+ $captcha_factory = $phpbb_container->get('captchas.factory');
$captcha_factory->garbage_collect($config['captcha_plugin']);
$sql = 'DELETE FROM ' . LOGIN_ATTEMPT_TABLE . '
diff --git a/phpBB/posting.php b/phpBB/posting.php
index 6638caa94b..6d6297741b 100644
--- a/phpBB/posting.php
+++ b/phpBB/posting.php
@@ -241,8 +241,7 @@ $user->setup(array('posting', 'mcp', 'viewtopic'), $post_data['forum_style']);
if ($config['enable_post_confirm'] && !$user->data['is_registered'])
{
- include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
- $captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
+ $captcha = $phpbb_container->get('captchas.factory')->get_instance($config['captcha_plugin']);
$captcha->init(CONFIRM_POST);
}
diff --git a/phpBB/report.php b/phpBB/report.php
index 3684c2162f..39df109904 100644
--- a/phpBB/report.php
+++ b/phpBB/report.php
@@ -151,8 +151,7 @@ else
if ($config['enable_post_confirm'] && !$user->data['is_registered'])
{
- include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
- $captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
+ $captcha = $phpbb_container->get('captchas.factory')->get_instance($config['captcha_plugin']);
$captcha->init(CONFIRM_REPORT);
}