1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: /**
13: * Abstract class for CAPTCHA method
14: *
15: * Currently there are two types of CAPTCHA forms, text and image
16: * The default mode is "text", it can be changed in the priority:
17: * 1 If mode is set through XoopsFormCaptcha::setConfig("mode", $mode), take it
18: * 2 Elseif mode is set though captcha/config.php, take it
19: * 3 Else, take "text"
20: *
21: * PHP 5.3
22: *
23: * @category Xoops\Class\Captcha\CaptchaMethod
24: * @package CaptchaMethod
25: * @author Taiwen Jiang <phppp@users.sourceforge.net>
26: * @copyright 2013 XOOPS Project (http://xoops.org)
27: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
28: * @version $Id$
29: * @link http://xoops.org
30: * @since 2.6.0
31: */
32: abstract class XoopsCaptchaMethod
33: {
34: /**
35: * @var XoopsCaptcha
36: */
37: public $handler;
38:
39: /**
40: * @var array
41: */
42: public $config;
43:
44: /**
45: * @var string
46: */
47: public $code;
48:
49: /**
50: * XoopsCaptchaMethod::__construct()
51: *
52: * @param mixed $handler
53: */
54: public function __construct($handler = null)
55: {
56: $this->handler = $handler;
57: }
58:
59: /**
60: * XoopsCaptchaMethod::isActive()
61: *
62: * @return bool
63: */
64: public function isActive()
65: {
66: return true;
67: }
68:
69: /**
70: * XoopsCaptchaMethod::loadConfig()
71: *
72: * @param string $name
73: *
74: * @return array
75: */
76: public function loadConfig($name = '')
77: {
78: if (!is_object($this->handler))
79: $this->config = array();
80: else
81: $this->config = empty($name)
82: ? $this->handler->config
83: : array_merge($this->handler->config, $this->handler->loadConfig($name));
84: }
85:
86: /**
87: * XoopsCaptchaMethod::getCode()
88: *
89: * @return string
90: */
91: public function getCode()
92: {
93: return (string)($this->code);
94: }
95:
96: /**
97: * XoopsCaptchaMethod::render()
98: *
99: * @return string
100: */
101: public function render()
102: {
103: return '';
104: }
105:
106: /**
107: * @return string
108: */
109: public function renderValidationJS()
110: {
111: return '';
112: }
113:
114: /**
115: * XoopsCaptchaMethod::verify()
116: *
117: * @param string $sessionName
118: *
119: * @return bool
120: */
121: public function verify($sessionName = null)
122: {
123: $is_valid = false;
124: if (!empty($_SESSION["{$sessionName}_code"])) {
125: $func = !empty($this->config['casesensitive']) ? 'strcmp' : 'strcasecmp';
126: $is_valid = !$func(trim(@$_POST[$sessionName]), $_SESSION["{$sessionName}_code"]);
127: }
128: return $is_valid;
129: }
130:
131: /**
132: * @return bool
133: */
134: public function destroyGarbage()
135: {
136: return true;
137: }
138:
139: }
140: