|
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
|
|
|
* CAPTCHA for Image mode |
|
14
|
|
|
* |
|
15
|
|
|
* Based on DuGris' SecurityImage |
|
16
|
|
|
* |
|
17
|
|
|
* PHP 5.3 |
|
18
|
|
|
* |
|
19
|
|
|
* @category Xoops\Class\Captcha\CaptchaMethod |
|
20
|
|
|
* @package CaptchaMethod |
|
21
|
|
|
* @author Taiwen Jiang <[email protected]> |
|
22
|
|
|
* @copyright 2013 XOOPS Project (http://xoops.org) |
|
23
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
|
24
|
|
|
* @version $Id$ |
|
25
|
|
|
* @link http://xoops.org |
|
26
|
|
|
* @since 2.6.0 |
|
27
|
|
|
*/ |
|
28
|
|
|
class XoopsCaptchaImage extends XoopsCaptchaMethod |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* XoopsCaptchaImage::isActive() |
|
33
|
|
|
* |
|
34
|
|
|
* @return bool |
|
35
|
|
|
*/ |
|
36
|
1 |
|
public function isActive() |
|
37
|
|
|
{ |
|
38
|
1 |
|
if (!extension_loaded('gd')) { |
|
39
|
|
|
trigger_error('GD library is not loaded', E_USER_WARNING); |
|
40
|
|
|
return false; |
|
41
|
|
View Code Duplication |
} else { |
|
42
|
|
|
$required_functions = array( |
|
43
|
1 |
|
'imagecreatetruecolor' , |
|
44
|
|
|
'imagecolorallocate' , |
|
45
|
|
|
'imagefilledrectangle' , |
|
46
|
|
|
'imagejpeg' , |
|
47
|
|
|
'imagedestroy' , |
|
48
|
|
|
'imageftbbox'); |
|
49
|
1 |
|
foreach ($required_functions as $func) { |
|
50
|
1 |
|
if (!function_exists($func)) { |
|
51
|
|
|
trigger_error('Function ' . $func . ' is not defined', E_USER_WARNING); |
|
52
|
|
|
return false; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
1 |
|
return true; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* XoopsCaptchaImage::render() |
|
61
|
|
|
* |
|
62
|
|
|
* @return string |
|
63
|
|
|
*/ |
|
64
|
1 |
|
public function render() |
|
65
|
|
|
{ |
|
66
|
1 |
|
$xoops_url = \XoopsBaseConfig::get('url'); |
|
67
|
|
|
$js = "<script type='text/javascript'> |
|
68
|
|
|
function xoops_captcha_refresh(imgId) |
|
69
|
|
|
{ |
|
70
|
1 |
|
xoopsGetElementById(imgId).src = '" . $xoops_url . "/class/captcha/image/scripts/image.php?refresh='+Math.random(); |
|
71
|
|
|
} |
|
72
|
|
|
</script>"; |
|
73
|
1 |
|
$image = $this->loadImage(); |
|
74
|
1 |
|
$image .= "<br /><a href=\"javascript: xoops_captcha_refresh('" . ($this->config['name']) . "')\">" . XoopsLocale::CLICK_TO_REFRESH_IMAGE_IF_NOT_CLEAR . "</a>"; |
|
75
|
1 |
|
$input = '<input type="text" name="' . $this->config['name'] . '" id="' . $this->config['name'] . '" size="' . $this->config['num_chars'] . '" maxlength="' . $this->config['num_chars'] . '" value="" required>'; |
|
76
|
1 |
|
$rule = XoopsLocale::INPUT_LETTERS_IN_THE_IMAGE; |
|
77
|
1 |
|
$rule .= '<br />' . (empty($this->config['casesensitive']) ? XoopsLocale::CODE_IS_CASE_INSENSITIVE : XoopsLocale::CODE_IS_CASE_SENSITIVE); |
|
78
|
1 |
View Code Duplication |
if (!empty($this->config['maxattempts'])) { |
|
79
|
|
|
$rule .= '<br />' . sprintf(XoopsLocale::F_MAXIMUM_ATTEMPTS, $this->config['maxattempts']); |
|
80
|
|
|
} |
|
81
|
1 |
|
return $js . $image . '<br /><br />' . $input . '<br />' . $rule; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* XoopsCaptchaImage::loadImage() |
|
86
|
|
|
* |
|
87
|
|
|
* @return string |
|
88
|
|
|
*/ |
|
89
|
2 |
|
public function loadImage() |
|
90
|
|
|
{ |
|
91
|
2 |
|
$xoops_url = \XoopsBaseConfig::get('url'); |
|
92
|
2 |
|
return '<img id="' . ($this->config["name"]) . '" src="' . $xoops_url . '/class/captcha/image/scripts/image.php" onclick=\'this.src="' . $xoops_url . '/class/captcha/image/scripts/image.php?refresh="+Math.random()' . '\' style="cursor: pointer; vertical-align: middle;" alt="" />'; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|