phpBB
Statistics
| Revision:

root / trunk / phpBB / includes / captcha / captcha_factory.php

History | View | Annotate | Download (2.1 kB)

1
<?php
2
/**
3
*
4
* @package VC
5
* @copyright (c) 2008 phpBB Group
6
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
*
8
*/
9
10
/**
11
* @ignore
12
*/
13
if (!defined('IN_PHPBB'))
14
{
15
        exit;
16
}
17
18
/**
19
* A small class for 3.0.x (no autoloader in 3.0.x)
20
*
21
* @package VC
22
*/
23
class phpbb_captcha_factory
24
{
25
        /**
26
        * return an instance of class $name in file $name_plugin.php
27
        */
28
        function get_instance($name)
29
        {
30
                global $phpbb_root_path, $phpEx;
31
32
                $name = basename($name);
33
                if (!class_exists($name))
34
                {
35
                        include($phpbb_root_path . "includes/captcha/plugins/{$name}_plugin." . $phpEx);
36
                }
37
                $instance = call_user_func(array($name, 'get_instance'));
38
                return $instance;
39
        }
40
41
        /**
42
        * Call the garbage collector
43
        */
44
        function garbage_collect($name)
45
        {
46
                global $phpbb_root_path, $phpEx;
47
48
                $name = basename($name);
49
                if (!class_exists($name))
50
                {
51
                        include($phpbb_root_path . "includes/captcha/plugins/{$name}_plugin." . $phpEx);
52
                }
53
                call_user_func(array($name, 'garbage_collect'), 0);
54
        }
55
56
        /**
57
        * return a list of all discovered CAPTCHA plugins
58
        */
59
        function get_captcha_types()
60
        {
61
                global $phpbb_root_path, $phpEx, $phpbb_extension_manager;
62
63
                $captchas = array(
64
                        'available'                => array(),
65
                        'unavailable'        => array(),
66
                );
67
68
                $finder = $phpbb_extension_manager->get_finder();
69
                $captcha_plugin_classes = $finder
70
                        ->extension_directory('/captcha')
71
                        ->suffix('_plugin')
72
                        ->core_path('includes/captcha/plugins/')
73
                        ->get_classes();
74
75
                foreach ($captcha_plugin_classes as $class)
76
                {
77
                        // check if this class needs to be loaded in legacy mode
78
                        $old_class = preg_replace('/^phpbb_captcha_plugins_/', '', $class);
79
                        if (file_exists($phpbb_root_path . "includes/captcha/plugins/$old_class.$phpEx") && !class_exists($old_class))
80
                        {
81
                                include($phpbb_root_path . "includes/captcha/plugins/$old_class.$phpEx");
82
                                $class = preg_replace('/_plugin$/', '', $old_class);
83
                        }
84
85
                        if (call_user_func(array($class, 'is_available')))
86
                        {
87
                                $captchas['available'][$class] = call_user_func(array($class, 'get_name'));
88
                        }
89
                        else
90
                        {
91
                                $captchas['unavailable'][$class] = call_user_func(array($class, 'get_name'));
92
                        }
93
                }
94
95
                return $captchas;
96
        }
97
}