phpBB
Statistics
| Revision:

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

History | View | Annotate | Download (2.1 kB)

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