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