1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
28: class XoopsCaptchaImage extends XoopsCaptchaMethod
29: {
30:
31: 32: 33: 34: 35:
36: public function isActive()
37: {
38: if (!extension_loaded('gd')) {
39: trigger_error('GD library is not loaded', E_USER_WARNING);
40: return false;
41: } else {
42: $required_functions = array(
43: 'imagecreatetruecolor' ,
44: 'imagecolorallocate' ,
45: 'imagefilledrectangle' ,
46: 'imagejpeg' ,
47: 'imagedestroy' ,
48: 'imageftbbox');
49: foreach ($required_functions as $func) {
50: if (!function_exists($func)) {
51: trigger_error('Function ' . $func . ' is not defined', E_USER_WARNING);
52: return false;
53: }
54: }
55: }
56: return true;
57: }
58:
59: 60: 61: 62: 63:
64: public function render()
65: {
66: $xoops_url = \XoopsBaseConfig::get('url');
67: $js = "<script type='text/javascript'>
68: function xoops_captcha_refresh(imgId)
69: {
70: xoopsGetElementById(imgId).src = '" . $xoops_url . "/class/captcha/image/scripts/image.php?refresh='+Math.random();
71: }
72: </script>";
73: $image = $this->loadImage();
74: $image .= "<br /><a href=\"javascript: xoops_captcha_refresh('" . ($this->config['name']) . "')\">" . XoopsLocale::CLICK_TO_REFRESH_IMAGE_IF_NOT_CLEAR . "</a>";
75: $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: $rule = XoopsLocale::INPUT_LETTERS_IN_THE_IMAGE;
77: $rule .= '<br />' . (empty($this->config['casesensitive']) ? XoopsLocale::CODE_IS_CASE_INSENSITIVE : XoopsLocale::CODE_IS_CASE_SENSITIVE);
78: if (!empty($this->config['maxattempts'])) {
79: $rule .= '<br />' . sprintf(XoopsLocale::F_MAXIMUM_ATTEMPTS, $this->config['maxattempts']);
80: }
81: return $js . $image . '<br /><br />' . $input . '<br />' . $rule;
82: }
83:
84: 85: 86: 87: 88:
89: public function loadImage()
90: {
91: $xoops_url = \XoopsBaseConfig::get('url');
92: 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: