@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * @subpackage CAPTCHA |
18 | 18 | */ |
19 | 19 | |
20 | -include __DIR__ . '/../../../../mainfile.php'; |
|
20 | +include __DIR__.'/../../../../mainfile.php'; |
|
21 | 21 | |
22 | 22 | error_reporting(0); |
23 | 23 | $xoopsLogger->activated = false; |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | { |
54 | 54 | xoops_load('XoopsCaptcha'); |
55 | 55 | $this->captchaHandler = XoopsCaptcha::getInstance(); |
56 | - $this->config = $this->captchaHandler->loadConfig('image'); |
|
56 | + $this->config = $this->captchaHandler->loadConfig('image'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | public function loadImage() |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | { |
99 | 99 | if ($this->invalid) { |
100 | 100 | header('Content-type: image/gif'); |
101 | - readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif'); |
|
101 | + readfile(XOOPS_ROOT_PATH.'/images/subject/icon2.gif'); |
|
102 | 102 | |
103 | 103 | return null; |
104 | 104 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | return $items; |
125 | 125 | } |
126 | 126 | |
127 | - require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
128 | - $file_path = XOOPS_ROOT_PATH . "/class/captcha/image/{$name}"; |
|
127 | + require_once XOOPS_ROOT_PATH.'/class/xoopslists.php'; |
|
128 | + $file_path = XOOPS_ROOT_PATH."/class/captcha/image/{$name}"; |
|
129 | 129 | $files = XoopsLists::getFileListAsArray($file_path); |
130 | 130 | foreach ($files as $item) { |
131 | 131 | if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) { |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | public function loadFont() |
199 | 199 | { |
200 | 200 | $fonts = $this->getList('fonts', 'ttf'); |
201 | - $this->font = XOOPS_ROOT_PATH . '/class/captcha/image/fonts/' . $fonts[array_rand($fonts)]; |
|
201 | + $this->font = XOOPS_ROOT_PATH.'/class/captcha/image/fonts/'.$fonts[array_rand($fonts)]; |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | public function setImageSize() |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | { |
238 | 238 | $RandBackground = null; |
239 | 239 | if ($backgrounds = $this->getList('backgrounds', '(gif|jpg|png)')) { |
240 | - $RandBackground = XOOPS_ROOT_PATH . '/class/captcha/image/backgrounds/' . $backgrounds[array_rand($backgrounds)]; |
|
240 | + $RandBackground = XOOPS_ROOT_PATH.'/class/captcha/image/backgrounds/'.$backgrounds[array_rand($backgrounds)]; |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | return $RandBackground; |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function render() |
46 | 46 | { |
47 | - $form = $this->loadText() . ' <input type="text" name="' . $this->config['name'] . '" id="' . $this->config['name'] . '" size="' . $this->config['num_chars'] . '" maxlength="' . $this->config['num_chars'] . '" value="" />'; |
|
48 | - $form .= '<br>' . _CAPTCHA_RULE_TEXT; |
|
47 | + $form = $this->loadText().' <input type="text" name="'.$this->config['name'].'" id="'.$this->config['name'].'" size="'.$this->config['num_chars'].'" maxlength="'.$this->config['num_chars'].'" value="" />'; |
|
48 | + $form .= '<br>'._CAPTCHA_RULE_TEXT; |
|
49 | 49 | if (!empty($this->config['maxattempts'])) { |
50 | - $form .= '<br>' . sprintf(_CAPTCHA_MAXATTEMPTS, $this->config['maxattempts']); |
|
50 | + $form .= '<br>'.sprintf(_CAPTCHA_MAXATTEMPTS, $this->config['maxattempts']); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | return $form; |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function loadText() |
62 | 62 | { |
63 | - return '<span style="font-style: normal; font-weight: bold; font-size: 100%; color: #333; border: 1px solid #333; padding: 1px 5px;">' . $this->outputText . '</span>'; |
|
63 | + return '<span style="font-style: normal; font-weight: bold; font-size: 100%; color: #333; border: 1px solid #333; padding: 1px 5px;">'.$this->outputText.'</span>'; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | protected function buildQuestion() |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | public function render() |
46 | 46 | { |
47 | 47 | trigger_error("recaptcha is outdated , use recaptcha_2 in \class\captcha\config.php", E_USER_WARNING); |
48 | - require_once __DIR__ . '/recaptcha/recaptchalib.php'; |
|
48 | + require_once __DIR__.'/recaptcha/recaptchalib.php'; |
|
49 | 49 | $form = "<script type=\"text/javascript\"> |
50 | 50 | var RecaptchaOptions = { |
51 | - theme : '" . $this->config['theme'] . "', |
|
52 | - lang : '" . $this->config['lang'] . "' |
|
51 | + theme : '" . $this->config['theme']."', |
|
52 | + lang : '" . $this->config['lang']."' |
|
53 | 53 | }; |
54 | 54 | </script>"; |
55 | 55 | $form .= recaptcha_get_html($this->config['public_key']); |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | public function verify($sessionName = null) |
68 | 68 | { |
69 | 69 | $is_valid = false; |
70 | - require_once __DIR__ . '/recaptcha/recaptchalib.php'; |
|
70 | + require_once __DIR__.'/recaptcha/recaptchalib.php'; |
|
71 | 71 | if (!empty(Request::getString('recaptcha_response_field', '', 'POST'))) { |
72 | 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 | 73 | if (!$resp->is_valid) { |
@@ -24,9 +24,9 @@ |
||
24 | 24 | * the actual XOOPS config then we should do this. (Who said this? You are right!) |
25 | 25 | */ |
26 | 26 | return $config = array( |
27 | - 'disabled' => false, // Disable CAPTCHA |
|
28 | - 'mode' => 'text', // default mode, you can choose 'text', 'image', 'recaptcha'(requires api key), 'recaptcha2'(requires api key) |
|
29 | - 'name' => 'xoopscaptcha', // captcha name |
|
30 | - 'skipmember' => true, // Skip CAPTCHA check for members |
|
31 | - 'maxattempts' => 10, // Maximum attempts for each session |
|
27 | + 'disabled' => false, // Disable CAPTCHA |
|
28 | + 'mode' => 'text', // default mode, you can choose 'text', 'image', 'recaptcha'(requires api key), 'recaptcha2'(requires api key) |
|
29 | + 'name' => 'xoopscaptcha', // captcha name |
|
30 | + 'skipmember' => true, // Skip CAPTCHA check for members |
|
31 | + 'maxattempts' => 10, // Maximum attempts for each session |
|
32 | 32 | ); |
@@ -44,8 +44,8 @@ discard block |
||
44 | 44 | { |
45 | 45 | xoops_loadLanguage('captcha'); |
46 | 46 | // Load static configurations |
47 | - $this->path_basic = XOOPS_ROOT_PATH . '/class/captcha'; |
|
48 | - $this->path_plugin = XOOPS_ROOT_PATH . '/Frameworks/captcha'; |
|
47 | + $this->path_basic = XOOPS_ROOT_PATH.'/class/captcha'; |
|
48 | + $this->path_plugin = XOOPS_ROOT_PATH.'/Frameworks/captcha'; |
|
49 | 49 | $this->config = $this->loadConfig(); |
50 | 50 | $this->name = $this->config['name']; |
51 | 51 | } |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | { |
77 | 77 | $basic_config = array(); |
78 | 78 | $plugin_config = array(); |
79 | - $filename = empty($filename) ? 'config.php' : 'config.' . $filename . '.php'; |
|
80 | - if (file_exists($file = $this->path_basic . '/' . $filename)) { |
|
79 | + $filename = empty($filename) ? 'config.php' : 'config.'.$filename.'.php'; |
|
80 | + if (file_exists($file = $this->path_basic.'/'.$filename)) { |
|
81 | 81 | $basic_config = include $file; |
82 | 82 | } |
83 | - if (file_exists($file = $this->path_plugin . '/' . $filename)) { |
|
83 | + if (file_exists($file = $this->path_plugin.'/'.$filename)) { |
|
84 | 84 | $plugin_config = include $file; |
85 | 85 | } |
86 | 86 | |
@@ -129,22 +129,22 @@ discard block |
||
129 | 129 | public function loadHandler($name = null) |
130 | 130 | { |
131 | 131 | $name = !empty($name) ? $name : (empty($this->config['mode']) ? 'text' : $this->config['mode']); |
132 | - $class = 'XoopsCaptcha' . ucfirst($name); |
|
132 | + $class = 'XoopsCaptcha'.ucfirst($name); |
|
133 | 133 | if (!empty($this->handler) && get_class($this->handler) == $class) { |
134 | 134 | return $this->handler; |
135 | 135 | } |
136 | 136 | $this->handler = null; |
137 | - if (file_exists($file = $this->path_basic . '/' . $name . '.php')) { |
|
137 | + if (file_exists($file = $this->path_basic.'/'.$name.'.php')) { |
|
138 | 138 | require_once $file; |
139 | 139 | } else { |
140 | - if (file_exists($file = $this->path_plugin . '/' . $name . '.php')) { |
|
140 | + if (file_exists($file = $this->path_plugin.'/'.$name.'.php')) { |
|
141 | 141 | require_once $file; |
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
145 | 145 | if (!class_exists($class)) { |
146 | 146 | $class = 'XoopsCaptchaText'; |
147 | - require_once $this->path_basic . '/text.php'; |
|
147 | + require_once $this->path_basic.'/text.php'; |
|
148 | 148 | } |
149 | 149 | $handler = new $class($this); |
150 | 150 | if ($handler->isActive()) { |
@@ -267,10 +267,10 @@ discard block |
||
267 | 267 | $this->handler->destroyGarbage(); |
268 | 268 | } |
269 | 269 | if ($clearSession) { |
270 | - $_SESSION[$this->name . '_name'] = null; |
|
271 | - $_SESSION[$this->name . '_skipmember'] = null; |
|
272 | - $_SESSION[$this->name . '_code'] = null; |
|
273 | - $_SESSION[$this->name . '_maxattempts'] = null; |
|
270 | + $_SESSION[$this->name.'_name'] = null; |
|
271 | + $_SESSION[$this->name.'_skipmember'] = null; |
|
272 | + $_SESSION[$this->name.'_code'] = null; |
|
273 | + $_SESSION[$this->name.'_maxattempts'] = null; |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | return true; |
@@ -283,17 +283,17 @@ discard block |
||
283 | 283 | */ |
284 | 284 | public function render() |
285 | 285 | { |
286 | - $_SESSION[$this->name . '_name'] = $this->name; |
|
287 | - $_SESSION[$this->name . '_skipmember'] = $this->config['skipmember']; |
|
286 | + $_SESSION[$this->name.'_name'] = $this->name; |
|
287 | + $_SESSION[$this->name.'_skipmember'] = $this->config['skipmember']; |
|
288 | 288 | $form = ''; |
289 | 289 | if (!$this->active || empty($this->config['name'])) { |
290 | 290 | return $form; |
291 | 291 | } |
292 | 292 | |
293 | 293 | $maxAttempts = $this->config['maxattempts']; |
294 | - $_SESSION[$this->name . '_maxattempts'] = $maxAttempts; |
|
295 | - $attempt = isset($_SESSION[$this->name . '_attempt']) ? $_SESSION[$this->name . '_attempt'] : 0; |
|
296 | - $_SESSION[$this->name . '_attempt'] = $attempt; |
|
294 | + $_SESSION[$this->name.'_maxattempts'] = $maxAttempts; |
|
295 | + $attempt = isset($_SESSION[$this->name.'_attempt']) ? $_SESSION[$this->name.'_attempt'] : 0; |
|
296 | + $_SESSION[$this->name.'_attempt'] = $attempt; |
|
297 | 297 | |
298 | 298 | // Failure on too many attempts |
299 | 299 | if (!empty($maxAttempts) && $attempt > $maxAttempts) { |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | { |
331 | 331 | $code = ($code === null) ? $this->handler->getCode() : $code; |
332 | 332 | if (!empty($code)) { |
333 | - $_SESSION[$this->name . '_code'] = $code; |
|
333 | + $_SESSION[$this->name.'_code'] = $code; |
|
334 | 334 | |
335 | 335 | return true; |
336 | 336 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | 'imageftbbox'); |
47 | 47 | foreach ($required_functions as $func) { |
48 | 48 | if (!function_exists($func)) { |
49 | - trigger_error('Function ' . $func . ' is not defined', E_USER_WARNING); |
|
49 | + trigger_error('Function '.$func.' is not defined', E_USER_WARNING); |
|
50 | 50 | |
51 | 51 | return false; |
52 | 52 | } |
@@ -63,22 +63,22 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public function render() |
65 | 65 | { |
66 | - $js = "<script type='text/javascript'> |
|
66 | + $js = "<script type='text/javascript'> |
|
67 | 67 | function xoops_captcha_refresh(imgId) |
68 | 68 | { |
69 | - xoopsGetElementById(imgId).src = '" . XOOPS_URL . "/class/captcha/image/scripts/image.php?refresh='+Math.random(); |
|
69 | + xoopsGetElementById(imgId).src = '" . XOOPS_URL."/class/captcha/image/scripts/image.php?refresh='+Math.random(); |
|
70 | 70 | } |
71 | 71 | </script>"; |
72 | 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="" />'; |
|
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 | 75 | $rule = _CAPTCHA_RULE_IMAGE; |
76 | - $rule .= '<br>' . (empty($this->config['casesensitive']) ? _CAPTCHA_RULE_CASEINSENSITIVE : _CAPTCHA_RULE_CASESENSITIVE); |
|
76 | + $rule .= '<br>'.(empty($this->config['casesensitive']) ? _CAPTCHA_RULE_CASEINSENSITIVE : _CAPTCHA_RULE_CASESENSITIVE); |
|
77 | 77 | if (!empty($this->config['maxattempts'])) { |
78 | - $rule .= '<br>' . sprintf(_CAPTCHA_MAXATTEMPTS, $this->config['maxattempts']); |
|
78 | + $rule .= '<br>'.sprintf(_CAPTCHA_MAXATTEMPTS, $this->config['maxattempts']); |
|
79 | 79 | } |
80 | 80 | |
81 | - return $js . $image . '<br><br>' . $input . '<br>' . $rule; |
|
81 | + return $js.$image.'<br><br>'.$input.'<br>'.$rule; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -88,6 +88,6 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function loadImage() |
90 | 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="" />'; |
|
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 | 92 | } |
93 | 93 | } |
@@ -100,16 +100,15 @@ discard block |
||
100 | 100 | * @param string $pubkey A public key for reCAPTCHA |
101 | 101 | * @param string $error The error given by reCAPTCHA (optional, default is null) |
102 | 102 | * @param boolean $use_ssl Should the request be made over ssl? (optional, default is true) |
103 | - |
|
104 | 103 | * @return string - The HTML to be embedded in the user's form. |
105 | 104 | */ |
106 | 105 | function recaptcha_get_html ($pubkey, $error = null, $use_ssl = true) |
107 | 106 | { |
108 | - if ($pubkey == null || $pubkey == '') { |
|
109 | - die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>"); |
|
110 | - } |
|
107 | + if ($pubkey == null || $pubkey == '') { |
|
108 | + die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>"); |
|
109 | + } |
|
111 | 110 | |
112 | - if ($use_ssl) { |
|
111 | + if ($use_ssl) { |
|
113 | 112 | $server = RECAPTCHA_API_SECURE_SERVER; |
114 | 113 | } else { |
115 | 114 | $server = RECAPTCHA_API_SERVER; |
@@ -117,7 +116,7 @@ discard block |
||
117 | 116 | |
118 | 117 | $errorpart = ""; |
119 | 118 | if ($error) { |
120 | - $errorpart = "&error=" . $error; |
|
119 | + $errorpart = "&error=" . $error; |
|
121 | 120 | } |
122 | 121 | return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script> |
123 | 122 | |
@@ -141,23 +140,23 @@ discard block |
||
141 | 140 | |
142 | 141 | |
143 | 142 | /** |
144 | - * Calls an HTTP POST function to verify if the user's guess was correct |
|
145 | - * @param string $privkey |
|
146 | - * @param string $remoteip |
|
147 | - * @param string $challenge |
|
148 | - * @param string $response |
|
149 | - * @param array $extra_params an array of extra variables to post to the server |
|
150 | - * @return ReCaptchaResponse |
|
151 | - */ |
|
143 | + * Calls an HTTP POST function to verify if the user's guess was correct |
|
144 | + * @param string $privkey |
|
145 | + * @param string $remoteip |
|
146 | + * @param string $challenge |
|
147 | + * @param string $response |
|
148 | + * @param array $extra_params an array of extra variables to post to the server |
|
149 | + * @return ReCaptchaResponse |
|
150 | + */ |
|
152 | 151 | function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array()) |
153 | 152 | { |
154 | - if ($privkey == null || $privkey == '') { |
|
155 | - die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>"); |
|
156 | - } |
|
153 | + if ($privkey == null || $privkey == '') { |
|
154 | + die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>"); |
|
155 | + } |
|
157 | 156 | |
158 | - if ($remoteip == null || $remoteip == '') { |
|
159 | - die ("For security reasons, you must pass the remote ip to reCAPTCHA"); |
|
160 | - } |
|
157 | + if ($remoteip == null || $remoteip == '') { |
|
158 | + die ("For security reasons, you must pass the remote ip to reCAPTCHA"); |
|
159 | + } |
|
161 | 160 | |
162 | 161 | |
163 | 162 | |
@@ -170,13 +169,13 @@ discard block |
||
170 | 169 | } |
171 | 170 | |
172 | 171 | $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify", |
173 | - array ( |
|
174 | - 'privatekey' => $privkey, |
|
175 | - 'remoteip' => $remoteip, |
|
176 | - 'challenge' => $challenge, |
|
177 | - 'response' => $response |
|
178 | - ) + $extra_params |
|
179 | - ); |
|
172 | + array ( |
|
173 | + 'privatekey' => $privkey, |
|
174 | + 'remoteip' => $remoteip, |
|
175 | + 'challenge' => $challenge, |
|
176 | + 'response' => $response |
|
177 | + ) + $extra_params |
|
178 | + ); |
|
180 | 179 | |
181 | 180 | $answers = explode ("\n", $response [1]); |
182 | 181 | $recaptcha_response = new ReCaptchaResponse(); |
@@ -200,44 +199,44 @@ discard block |
||
200 | 199 | * @param string $appname The name of your application |
201 | 200 | */ |
202 | 201 | function recaptcha_get_signup_url ($domain = null, $appname = null) { |
203 | - return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname)); |
|
202 | + return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname)); |
|
204 | 203 | } |
205 | 204 | |
206 | 205 | function _recaptcha_aes_pad($val) { |
207 | - $block_size = 16; |
|
208 | - $numpad = $block_size - (strlen ($val) % $block_size); |
|
209 | - return str_pad($val, strlen ($val) + $numpad, chr($numpad)); |
|
206 | + $block_size = 16; |
|
207 | + $numpad = $block_size - (strlen ($val) % $block_size); |
|
208 | + return str_pad($val, strlen ($val) + $numpad, chr($numpad)); |
|
210 | 209 | } |
211 | 210 | |
212 | 211 | /* Mailhide related code */ |
213 | 212 | |
214 | 213 | function _recaptcha_aes_encrypt($val,$ky) { |
215 | - if (! function_exists ("mcrypt_encrypt")) { |
|
216 | - die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed."); |
|
217 | - } |
|
218 | - $mode=MCRYPT_MODE_CBC; |
|
219 | - $enc=MCRYPT_RIJNDAEL_128; |
|
220 | - $val=_recaptcha_aes_pad($val); |
|
221 | - return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); |
|
214 | + if (! function_exists ("mcrypt_encrypt")) { |
|
215 | + die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed."); |
|
216 | + } |
|
217 | + $mode=MCRYPT_MODE_CBC; |
|
218 | + $enc=MCRYPT_RIJNDAEL_128; |
|
219 | + $val=_recaptcha_aes_pad($val); |
|
220 | + return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); |
|
222 | 221 | } |
223 | 222 | |
224 | 223 | |
225 | 224 | function _recaptcha_mailhide_urlbase64 ($x) { |
226 | - return strtr(base64_encode ($x), '+/', '-_'); |
|
225 | + return strtr(base64_encode ($x), '+/', '-_'); |
|
227 | 226 | } |
228 | 227 | |
229 | 228 | /* gets the reCAPTCHA Mailhide url for a given email, public key and private key */ |
230 | 229 | function recaptcha_mailhide_url($pubkey, $privkey, $email) { |
231 | - if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) { |
|
232 | - die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " . |
|
233 | - "you can do so at <a href='http://www.google.com/recaptcha/mailhide/apikey'>http://www.google.com/recaptcha/mailhide/apikey</a>"); |
|
234 | - } |
|
230 | + if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) { |
|
231 | + die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " . |
|
232 | + "you can do so at <a href='http://www.google.com/recaptcha/mailhide/apikey'>http://www.google.com/recaptcha/mailhide/apikey</a>"); |
|
233 | + } |
|
235 | 234 | |
236 | 235 | |
237 | - $ky = pack('H*', $privkey); |
|
238 | - $cryptmail = _recaptcha_aes_encrypt ($email, $ky); |
|
236 | + $ky = pack('H*', $privkey); |
|
237 | + $cryptmail = _recaptcha_aes_encrypt ($email, $ky); |
|
239 | 238 | |
240 | - return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail); |
|
239 | + return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail); |
|
241 | 240 | } |
242 | 241 | |
243 | 242 | /** |
@@ -246,16 +245,16 @@ discard block |
||
246 | 245 | * the email is then displayed as [email protected] |
247 | 246 | */ |
248 | 247 | function _recaptcha_mailhide_email_parts ($email) { |
249 | - $arr = preg_split("/@/", $email ); |
|
250 | - |
|
251 | - if (strlen ($arr[0]) <= 4) { |
|
252 | - $arr[0] = substr ($arr[0], 0, 1); |
|
253 | - } else if (strlen ($arr[0]) <= 6) { |
|
254 | - $arr[0] = substr ($arr[0], 0, 3); |
|
255 | - } else { |
|
256 | - $arr[0] = substr ($arr[0], 0, 4); |
|
257 | - } |
|
258 | - return $arr; |
|
248 | + $arr = preg_split("/@/", $email ); |
|
249 | + |
|
250 | + if (strlen ($arr[0]) <= 4) { |
|
251 | + $arr[0] = substr ($arr[0], 0, 1); |
|
252 | + } else if (strlen ($arr[0]) <= 6) { |
|
253 | + $arr[0] = substr ($arr[0], 0, 3); |
|
254 | + } else { |
|
255 | + $arr[0] = substr ($arr[0], 0, 4); |
|
256 | + } |
|
257 | + return $arr; |
|
259 | 258 | } |
260 | 259 | |
261 | 260 | /** |
@@ -265,11 +264,11 @@ discard block |
||
265 | 264 | * http://www.google.com/recaptcha/mailhide/apikey |
266 | 265 | */ |
267 | 266 | function recaptcha_mailhide_html($pubkey, $privkey, $email) { |
268 | - $emailparts = _recaptcha_mailhide_email_parts ($email); |
|
269 | - $url = recaptcha_mailhide_url ($pubkey, $privkey, $email); |
|
267 | + $emailparts = _recaptcha_mailhide_email_parts ($email); |
|
268 | + $url = recaptcha_mailhide_url ($pubkey, $privkey, $email); |
|
270 | 269 | |
271 | - return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) . |
|
272 | - "' onclick=\"window.open('" . htmlentities ($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities ($emailparts [1]); |
|
270 | + return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) . |
|
271 | + "' onclick=\"window.open('" . htmlentities ($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities ($emailparts [1]); |
|
273 | 272 | |
274 | 273 | } |
275 | 274 |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | * @param $data - array of string elements to be encoded |
45 | 45 | * @return string - encoded request |
46 | 46 | */ |
47 | -function _recaptcha_qsencode ($data) { |
|
47 | +function _recaptcha_qsencode($data) { |
|
48 | 48 | $req = ""; |
49 | - foreach ( $data as $key => $value ) |
|
50 | - $req .= $key . '=' . urlencode( stripslashes($value) ) . '&'; |
|
49 | + foreach ($data as $key => $value) |
|
50 | + $req .= $key.'='.urlencode(stripslashes($value)).'&'; |
|
51 | 51 | |
52 | 52 | // Cut the last '&' |
53 | - $req=substr($req,0,strlen($req)-1); |
|
53 | + $req = substr($req, 0, strlen($req) - 1); |
|
54 | 54 | return $req; |
55 | 55 | } |
56 | 56 | |
@@ -66,24 +66,24 @@ discard block |
||
66 | 66 | */ |
67 | 67 | function _recaptcha_http_post($host, $path, $data, $port = 80) { |
68 | 68 | |
69 | - $req = _recaptcha_qsencode ($data); |
|
69 | + $req = _recaptcha_qsencode($data); |
|
70 | 70 | |
71 | 71 | $http_request = "POST $path HTTP/1.0\r\n"; |
72 | 72 | $http_request .= "Host: $host\r\n"; |
73 | 73 | $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n"; |
74 | - $http_request .= "Content-Length: " . strlen($req) . "\r\n"; |
|
74 | + $http_request .= "Content-Length: ".strlen($req)."\r\n"; |
|
75 | 75 | $http_request .= "User-Agent: reCAPTCHA/PHP\r\n"; |
76 | 76 | $http_request .= "\r\n"; |
77 | 77 | $http_request .= $req; |
78 | 78 | |
79 | 79 | $response = ''; |
80 | - if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) { |
|
80 | + if (false == ($fs = @fsockopen($host, $port, $errno, $errstr, 10))) { |
|
81 | 81 | die ('Could not open socket'); |
82 | 82 | } |
83 | 83 | |
84 | 84 | fwrite($fs, $http_request); |
85 | 85 | |
86 | - while ( !feof($fs) ) |
|
86 | + while (!feof($fs)) |
|
87 | 87 | $response .= fgets($fs, 1160); // One TCP-IP packet |
88 | 88 | fclose($fs); |
89 | 89 | $response = explode("\r\n\r\n", $response, 2); |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | |
104 | 104 | * @return string - The HTML to be embedded in the user's form. |
105 | 105 | */ |
106 | -function recaptcha_get_html ($pubkey, $error = null, $use_ssl = true) |
|
106 | +function recaptcha_get_html($pubkey, $error = null, $use_ssl = true) |
|
107 | 107 | { |
108 | 108 | if ($pubkey == null || $pubkey == '') { |
109 | 109 | die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>"); |
@@ -117,12 +117,12 @@ discard block |
||
117 | 117 | |
118 | 118 | $errorpart = ""; |
119 | 119 | if ($error) { |
120 | - $errorpart = "&error=" . $error; |
|
120 | + $errorpart = "&error=".$error; |
|
121 | 121 | } |
122 | - return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script> |
|
122 | + return '<script type="text/javascript" src="'.$server.'/challenge?k='.$pubkey.$errorpart.'"></script> |
|
123 | 123 | |
124 | 124 | <noscript> |
125 | - <iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/> |
|
125 | + <iframe src="'. $server.'/noscript?k='.$pubkey.$errorpart.'" height="300" width="500" frameborder="0"></iframe><br/> |
|
126 | 126 | <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea> |
127 | 127 | <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/> |
128 | 128 | </noscript>'; |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @param array $extra_params an array of extra variables to post to the server |
150 | 150 | * @return ReCaptchaResponse |
151 | 151 | */ |
152 | -function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array()) |
|
152 | +function recaptcha_check_answer($privkey, $remoteip, $challenge, $response, $extra_params = array()) |
|
153 | 153 | { |
154 | 154 | if ($privkey == null || $privkey == '') { |
155 | 155 | die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>"); |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | return $recaptcha_response; |
170 | 170 | } |
171 | 171 | |
172 | - $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify", |
|
173 | - array ( |
|
172 | + $response = _recaptcha_http_post(RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify", |
|
173 | + array( |
|
174 | 174 | 'privatekey' => $privkey, |
175 | 175 | 'remoteip' => $remoteip, |
176 | 176 | 'challenge' => $challenge, |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | ) + $extra_params |
179 | 179 | ); |
180 | 180 | |
181 | - $answers = explode ("\n", $response [1]); |
|
181 | + $answers = explode("\n", $response [1]); |
|
182 | 182 | $recaptcha_response = new ReCaptchaResponse(); |
183 | 183 | |
184 | - if (trim ($answers [0]) == 'true') { |
|
184 | + if (trim($answers [0]) == 'true') { |
|
185 | 185 | $recaptcha_response->is_valid = true; |
186 | 186 | } |
187 | 187 | else { |
@@ -199,45 +199,45 @@ discard block |
||
199 | 199 | * @param string $domain The domain where the page is hosted |
200 | 200 | * @param string $appname The name of your application |
201 | 201 | */ |
202 | -function recaptcha_get_signup_url ($domain = null, $appname = null) { |
|
203 | - return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname)); |
|
202 | +function recaptcha_get_signup_url($domain = null, $appname = null) { |
|
203 | + return "https://www.google.com/recaptcha/admin/create?"._recaptcha_qsencode(array('domains' => $domain, 'app' => $appname)); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | function _recaptcha_aes_pad($val) { |
207 | 207 | $block_size = 16; |
208 | - $numpad = $block_size - (strlen ($val) % $block_size); |
|
209 | - return str_pad($val, strlen ($val) + $numpad, chr($numpad)); |
|
208 | + $numpad = $block_size - (strlen($val) % $block_size); |
|
209 | + return str_pad($val, strlen($val) + $numpad, chr($numpad)); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /* Mailhide related code */ |
213 | 213 | |
214 | -function _recaptcha_aes_encrypt($val,$ky) { |
|
215 | - if (! function_exists ("mcrypt_encrypt")) { |
|
214 | +function _recaptcha_aes_encrypt($val, $ky) { |
|
215 | + if (!function_exists("mcrypt_encrypt")) { |
|
216 | 216 | die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed."); |
217 | 217 | } |
218 | - $mode=MCRYPT_MODE_CBC; |
|
219 | - $enc=MCRYPT_RIJNDAEL_128; |
|
220 | - $val=_recaptcha_aes_pad($val); |
|
218 | + $mode = MCRYPT_MODE_CBC; |
|
219 | + $enc = MCRYPT_RIJNDAEL_128; |
|
220 | + $val = _recaptcha_aes_pad($val); |
|
221 | 221 | return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); |
222 | 222 | } |
223 | 223 | |
224 | 224 | |
225 | -function _recaptcha_mailhide_urlbase64 ($x) { |
|
226 | - return strtr(base64_encode ($x), '+/', '-_'); |
|
225 | +function _recaptcha_mailhide_urlbase64($x) { |
|
226 | + return strtr(base64_encode($x), '+/', '-_'); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /* gets the reCAPTCHA Mailhide url for a given email, public key and private key */ |
230 | 230 | function recaptcha_mailhide_url($pubkey, $privkey, $email) { |
231 | 231 | if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) { |
232 | - die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " . |
|
232 | + die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, ". |
|
233 | 233 | "you can do so at <a href='http://www.google.com/recaptcha/mailhide/apikey'>http://www.google.com/recaptcha/mailhide/apikey</a>"); |
234 | 234 | } |
235 | 235 | |
236 | 236 | |
237 | 237 | $ky = pack('H*', $privkey); |
238 | - $cryptmail = _recaptcha_aes_encrypt ($email, $ky); |
|
238 | + $cryptmail = _recaptcha_aes_encrypt($email, $ky); |
|
239 | 239 | |
240 | - return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail); |
|
240 | + return "http://www.google.com/recaptcha/mailhide/d?k=".$pubkey."&c="._recaptcha_mailhide_urlbase64($cryptmail); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -245,15 +245,15 @@ discard block |
||
245 | 245 | * eg, given johndoe@example,com return ["john", "example.com"]. |
246 | 246 | * the email is then displayed as [email protected] |
247 | 247 | */ |
248 | -function _recaptcha_mailhide_email_parts ($email) { |
|
249 | - $arr = preg_split("/@/", $email ); |
|
248 | +function _recaptcha_mailhide_email_parts($email) { |
|
249 | + $arr = preg_split("/@/", $email); |
|
250 | 250 | |
251 | - if (strlen ($arr[0]) <= 4) { |
|
252 | - $arr[0] = substr ($arr[0], 0, 1); |
|
253 | - } else if (strlen ($arr[0]) <= 6) { |
|
254 | - $arr[0] = substr ($arr[0], 0, 3); |
|
251 | + if (strlen($arr[0]) <= 4) { |
|
252 | + $arr[0] = substr($arr[0], 0, 1); |
|
253 | + } else if (strlen($arr[0]) <= 6) { |
|
254 | + $arr[0] = substr($arr[0], 0, 3); |
|
255 | 255 | } else { |
256 | - $arr[0] = substr ($arr[0], 0, 4); |
|
256 | + $arr[0] = substr($arr[0], 0, 4); |
|
257 | 257 | } |
258 | 258 | return $arr; |
259 | 259 | } |
@@ -265,11 +265,11 @@ discard block |
||
265 | 265 | * http://www.google.com/recaptcha/mailhide/apikey |
266 | 266 | */ |
267 | 267 | function recaptcha_mailhide_html($pubkey, $privkey, $email) { |
268 | - $emailparts = _recaptcha_mailhide_email_parts ($email); |
|
269 | - $url = recaptcha_mailhide_url ($pubkey, $privkey, $email); |
|
268 | + $emailparts = _recaptcha_mailhide_email_parts($email); |
|
269 | + $url = recaptcha_mailhide_url($pubkey, $privkey, $email); |
|
270 | 270 | |
271 | - return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) . |
|
272 | - "' onclick=\"window.open('" . htmlentities ($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities ($emailparts [1]); |
|
271 | + return htmlentities($emailparts[0])."<a href='".htmlentities($url). |
|
272 | + "' onclick=\"window.open('".htmlentities($url)."', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@".htmlentities($emailparts [1]); |
|
273 | 273 | |
274 | 274 | } |
275 | 275 |
@@ -46,8 +46,9 @@ discard block |
||
46 | 46 | */ |
47 | 47 | function _recaptcha_qsencode ($data) { |
48 | 48 | $req = ""; |
49 | - foreach ( $data as $key => $value ) |
|
50 | - $req .= $key . '=' . urlencode( stripslashes($value) ) . '&'; |
|
49 | + foreach ( $data as $key => $value ) { |
|
50 | + $req .= $key . '=' . urlencode( stripslashes($value) ) . '&'; |
|
51 | + } |
|
51 | 52 | |
52 | 53 | // Cut the last '&' |
53 | 54 | $req=substr($req,0,strlen($req)-1); |
@@ -83,8 +84,10 @@ discard block |
||
83 | 84 | |
84 | 85 | fwrite($fs, $http_request); |
85 | 86 | |
86 | - while ( !feof($fs) ) |
|
87 | - $response .= fgets($fs, 1160); // One TCP-IP packet |
|
87 | + while ( !feof($fs) ) { |
|
88 | + $response .= fgets($fs, 1160); |
|
89 | + } |
|
90 | + // One TCP-IP packet |
|
88 | 91 | fclose($fs); |
89 | 92 | $response = explode("\r\n\r\n", $response, 2); |
90 | 93 | |
@@ -183,8 +186,7 @@ discard block |
||
183 | 186 | |
184 | 187 | if (trim ($answers [0]) == 'true') { |
185 | 188 | $recaptcha_response->is_valid = true; |
186 | - } |
|
187 | - else { |
|
189 | + } else { |
|
188 | 190 | $recaptcha_response->is_valid = false; |
189 | 191 | $recaptcha_response->error = $answers [1]; |
190 | 192 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | { |
50 | 50 | $form = '<script src="https://www.google.com/recaptcha/api.js"></script>'; |
51 | 51 | $form .= '<div class="form-group"><div class="g-recaptcha" data-sitekey="' |
52 | - . $this->config['website_key'] . '"></div></div>'; |
|
52 | + . $this->config['website_key'].'"></div></div>'; |
|
53 | 53 | return $form; |
54 | 54 | } |
55 | 55 | |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | { |
65 | 65 | $isValid = false; |
66 | 66 | $recaptchaResponse = Request::getString('g-recaptcha-response', ''); |
67 | - $recaptchaVerifyURL = 'https://www.google.com/recaptcha/api/siteverify?secret=' . $this->config['secret_key'] |
|
68 | - . '&response=' . $recaptchaResponse . '&remoteip=' . IPAddress::fromRequest()->asReadable(); |
|
67 | + $recaptchaVerifyURL = 'https://www.google.com/recaptcha/api/siteverify?secret='.$this->config['secret_key'] |
|
68 | + . '&response='.$recaptchaResponse.'&remoteip='.IPAddress::fromRequest()->asReadable(); |
|
69 | 69 | $usedCurl = false; |
70 | - if (function_exists('curl_init') && false !== ($curlHandle = curl_init())) { |
|
70 | + if (function_exists('curl_init') && false !== ($curlHandle = curl_init())) { |
|
71 | 71 | curl_setopt($curlHandle, CURLOPT_URL, $recaptchaVerifyURL); |
72 | 72 | curl_setopt($curlHandle, CURLOPT_FAILONERROR, true); |
73 | 73 | curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1); |
@@ -23,5 +23,5 @@ |
||
23 | 23 | |
24 | 24 | return $config = array( |
25 | 25 | 'website_key' => 'YourWebsiteKey', //https://www.google.com/recaptcha/intro/index.html YourWebsiteKey |
26 | - 'secret_key' => 'YourSecretKey', //https://www.google.com/recaptcha/intro/index.html YourSecretKey |
|
26 | + 'secret_key' => 'YourSecretKey', //https://www.google.com/recaptcha/intro/index.html YourSecretKey |
|
27 | 27 | ); |