1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-29 18:50:25 +02:00
php-phpbb/phpBB/includes/captcha/captcha_factory.php
Nils Adermann 61df8a87d1 [feature/extension-manager] Allow extensions to define captcha plugins.
The base class for captcha plugins has been renamed, but the old name continues
to exist as an empty subclass of it for backwards compatability.

PHPBB3-10323
2011-09-29 15:42:47 +02:00

100 lines
2.1 KiB
PHP

<?php
/**
*
* @package VC
* @version $Id$
* @copyright (c) 2008 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* A small class for 3.0.x (no autoloader in 3.0.x)
*
* @package VC
*/
class phpbb_captcha_factory
{
/**
* return an instance of class $name in file $name_plugin.php
*/
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);
}
call_user_func(array($name, '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
->directory('/captcha')
->suffix('_plugin')
->default_path('includes/captcha/plugins/')
->default_directory('')
->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;
}
}