1: <?php
 2: 
 3: use Xmf\Request;
 4: 
 5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 
22: 
23: defined('XOOPS_ROOT_PATH') || exit('Restricted access');
24: 
25: 26: 27: 
28: class XoopsCaptchaRecaptcha extends XoopsCaptchaMethod
29: {
30:     31: 32: 33: 34: 
35:     public function isActive()
36:     {
37:         return true;
38:     }
39: 
40:     41: 42: 43: 44: 
45:     public function render()
46:     {
47:         trigger_error("recaptcha is outdated , use recaptcha_2 in \class\captcha\config.php", E_USER_WARNING);
48:         require_once __DIR__ . '/recaptcha/recaptchalib.php';
49:         $form = "<script type=\"text/javascript\">
50:             var RecaptchaOptions = {
51:             theme : '" . $this->config['theme'] . "',
52:             lang : '" . $this->config['lang'] . "'
53:             };
54:             </script>";
55:         $form .= recaptcha_get_html($this->config['public_key']);
56: 
57:         return $form;
58:     }
59: 
60:     61: 62: 63: 64: 65: 66: 
67:     public function verify($sessionName = null)
68:     {
69:         $is_valid = false;
70:         require_once __DIR__ . '/recaptcha/recaptchalib.php';
71:         if (!empty(Request::getString('recaptcha_response_field', '', 'POST'))) {
72:             $resp = recaptcha_check_answer($this->config['private_key'], $_SERVER['REMOTE_ADDR'], Request::getString('recaptcha_challenge_field', '', 'POST'), Request::getString('recaptcha_response_field', '', 'POST'));
73:             if (!$resp->is_valid) {
74:                 $this->message[] = $resp->error;
75:             } else {
76:                 $is_valid = true;
77:             }
78:         }
79: 
80:         return $is_valid;
81:     }
82: }
83: