1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/includes/captcha/captcha_factory.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,100 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package VC
1.8 +* @version $Id$
1.9 +* @copyright (c) 2008 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +/**
1.15 +* @ignore
1.16 +*/
1.17 +if (!defined('IN_PHPBB'))
1.18 +{
1.19 + exit;
1.20 +}
1.21 +
1.22 +/**
1.23 +* A small class for 3.0.x (no autoloader in 3.0.x)
1.24 +*
1.25 +* @package VC
1.26 +*/
1.27 +class phpbb_captcha_factory
1.28 +{
1.29 + /**
1.30 + * return an instance of class $name in file $name_plugin.php
1.31 + */
1.32 + function &get_instance($name)
1.33 + {
1.34 + global $phpbb_root_path, $phpEx;
1.35 +
1.36 + $name = basename($name);
1.37 + if (!class_exists($name))
1.38 + {
1.39 + include($phpbb_root_path . "includes/captcha/plugins/{$name}_plugin." . $phpEx);
1.40 + }
1.41 + $instance = call_user_func(array($name, 'get_instance'));
1.42 + return $instance;
1.43 + }
1.44 +
1.45 + /**
1.46 + * Call the garbage collector
1.47 + */
1.48 + function garbage_collect($name)
1.49 + {
1.50 + global $phpbb_root_path, $phpEx;
1.51 +
1.52 + $name = basename($name);
1.53 + if (!class_exists($name))
1.54 + {
1.55 + include($phpbb_root_path . "includes/captcha/plugins/{$name}_plugin." . $phpEx);
1.56 + }
1.57 + call_user_func(array($name, 'garbage_collect'), 0);
1.58 + }
1.59 +
1.60 + /**
1.61 + * return a list of all discovered CAPTCHA plugins
1.62 + */
1.63 + function get_captcha_types()
1.64 + {
1.65 + global $phpbb_root_path, $phpEx;
1.66 +
1.67 + $captchas = array(
1.68 + 'available' => array(),
1.69 + 'unavailable' => array(),
1.70 + );
1.71 +
1.72 + $dp = @opendir($phpbb_root_path . 'includes/captcha/plugins');
1.73 +
1.74 + if ($dp)
1.75 + {
1.76 + while (($file = readdir($dp)) !== false)
1.77 + {
1.78 + if ((preg_match('#_plugin\.' . $phpEx . '$#', $file)))
1.79 + {
1.80 + $name = preg_replace('#^(.*?)_plugin\.' . $phpEx . '$#', '\1', $file);
1.81 + if (!class_exists($name))
1.82 + {
1.83 + include($phpbb_root_path . "includes/captcha/plugins/$file");
1.84 + }
1.85 +
1.86 + if (call_user_func(array($name, 'is_available')))
1.87 + {
1.88 + $captchas['available'][$name] = call_user_func(array($name, 'get_name'));
1.89 + }
1.90 + else
1.91 + {
1.92 + $captchas['unavailable'][$name] = call_user_func(array($name, 'get_name'));
1.93 + }
1.94 + }
1.95 + }
1.96 + closedir($dp);
1.97 + }
1.98 +
1.99 + return $captchas;
1.100 + }
1.101 +}
1.102 +
1.103 +?>
1.104 \ No newline at end of file