aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/captcha/captcha_factory.php
blob: 62fb90d3c5805d9fb01ca39ae143fd0c163c5da6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
*
* @package VC
* @copyright (c) 2008 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

/**
* @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
			->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;
	}
}