1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
18:
19: class Xcaptcha extends XoopsCaptcha
20: {
21: public $captchaHandler;
22:
23: public $config = array();
24:
25: public $plugin_List = array();
26:
27: public $plugin_config = array();
28:
29: public $xcaptcha_path_plugin;
30:
31: public function __construct()
32: {
33: $this->captchaHandler = XoopsCaptcha::getInstance();
34: $this->config = $this->loadConfig();
35: $this->plugin_List = $this->getPluginList();
36: $this->plugin_config = $this->loadConfigPlugin();
37: $this->xcaptcha_path_plugin = \XoopsBaseConfig::get('root-path') . '/modules/xcaptcha/plugins';
38: }
39:
40: static function getInstance()
41: {
42: static $instance;
43: if (!isset($instance)) {
44: $class = __CLASS__;
45: $instance = new $class();
46: }
47: return $instance;
48: }
49:
50: public function loadConfig($name = 'config')
51: {
52: return $this->captchaHandler->loadConfig($name);
53: }
54:
55: public function loadBasicConfig($filename = null)
56: {
57: return $this->captchaHandler->loadBasicConfig($filename);
58: }
59:
60: public function readConfig($file = 'config')
61: {
62: return $this->captchaHandler->readConfig($file);
63: }
64:
65: public function writeConfig($file = 'config', $data)
66: {
67: return $this->captchaHandler->writeConfig($file, $data);
68: }
69:
70: public function getPluginList()
71: {
72: $ret = array();
73:
74: foreach (glob($this->captchaHandler->path_basic . '/config.*.php') as $filename) {
75: $plugin_List = preg_replace('/(config\.)(.*)(\.php)/', '$2', basename($filename));
76: $ret[$plugin_List] = $plugin_List;
77: }
78: return $ret;
79: }
80:
81: public function loadConfigPlugin()
82: {
83: $config = array();
84: foreach ($this->plugin_List as $key) {
85: $config = $this->loadConfig($key);
86: }
87: return $config;
88: }
89:
90: public function VerifyData()
91: {
92: $system = System::getInstance();
93: $config = array();
94: $_POST['disabled'] = $system->cleanVars($_POST, 'disabled', false, 'boolean');
95: $_POST['mode'] = $system->cleanVars($_POST, 'mode', 'image', 'string');
96: $_POST['name'] = $system->cleanVars($_POST, 'name', 'xoopscaptcha', 'string');
97: $_POST['skipmember'] = $system->cleanVars($_POST, 'skipmember', false, 'boolean');
98: $_POST['maxattempts'] = $system->cleanVars($_POST, 'maxattempts', 10, 'int');
99: foreach (array_keys($this->config) as $key) {
100: $config[$key] = $_POST[$key];
101: }
102: return $config;
103: }
104:
105: public function loadPluginHandler($name = null)
106: {
107: $name = empty($name) ? 'text' : $name;
108: $class = 'Xcaptcha' . ucfirst($name);
109: $this->Pluginhandler = null;
110: if (XoopsLoad::fileExists($file = $this->xcaptcha_path_plugin . '/' . $name . '.php')) {
111: require_once $file;
112: $this->Pluginhandler = new $class($this);
113: }
114: return $this->Pluginhandler;
115: }
116: }
117: