contactsformcaptcha - Version 1.4.0

Version Notes

Implemented reCaptcha V2.0

Download this release

Release Info

Developer Magento Core Team
Extension contactsformcaptcha
Version 1.4.0
Comparing to
See all releases


Code changes from version 1.3.1 to 1.4.0

app/code/community/OlegKoval/ContactsFormCaptcha/Model/System/Config/Source/Dropdown/Lang.php CHANGED
@@ -4,10 +4,14 @@
4
  *
5
  * @category OlegKoval
6
  * @package OlegKoval_ContactsFormCaptcha
7
- * @copyright Copyright (c) 2012 Oleg Koval
8
  * @author Oleg Koval <oleh.koval@gmail.com>
9
  */
10
  class OlegKoval_ContactsFormCaptcha_Model_System_Config_Source_Dropdown_Lang {
 
 
 
 
11
  public function toOptionArray() {
12
  return array(
13
  array(
4
  *
5
  * @category OlegKoval
6
  * @package OlegKoval_ContactsFormCaptcha
7
+ * @copyright Copyright (c) 2012 - 2016 Oleg Koval
8
  * @author Oleg Koval <oleh.koval@gmail.com>
9
  */
10
  class OlegKoval_ContactsFormCaptcha_Model_System_Config_Source_Dropdown_Lang {
11
+ /**
12
+ * Generate lang options array
13
+ * @return array
14
+ */
15
  public function toOptionArray() {
16
  return array(
17
  array(
app/code/community/OlegKoval/ContactsFormCaptcha/Model/System/Config/Source/Dropdown/Theme.php CHANGED
@@ -4,27 +4,23 @@
4
  *
5
  * @category OlegKoval
6
  * @package OlegKoval_ContactsFormCaptcha
7
- * @copyright Copyright (c) 2012 Oleg Koval
8
  * @author Oleg Koval <oleh.koval@gmail.com>
9
  */
10
  class OlegKoval_ContactsFormCaptcha_Model_System_Config_Source_Dropdown_Theme {
 
 
 
 
11
  public function toOptionArray() {
12
  return array(
13
  array(
14
- 'value' => 'red',
15
- 'label' => 'Red (default)',
16
  ),
17
  array(
18
- 'value' => 'white',
19
- 'label' => 'White',
20
- ),
21
- array(
22
- 'value' => 'blackglass',
23
- 'label' => 'Blackglass',
24
- ),
25
- array(
26
- 'value' => 'clean',
27
- 'label' => 'Clean',
28
  ),
29
  );
30
  }
4
  *
5
  * @category OlegKoval
6
  * @package OlegKoval_ContactsFormCaptcha
7
+ * @copyright Copyright (c) 2012 - 2016 Oleg Koval
8
  * @author Oleg Koval <oleh.koval@gmail.com>
9
  */
10
  class OlegKoval_ContactsFormCaptcha_Model_System_Config_Source_Dropdown_Theme {
11
+ /**
12
+ * Generate theme options array
13
+ * @return array
14
+ */
15
  public function toOptionArray() {
16
  return array(
17
  array(
18
+ 'value' => 'light',
19
+ 'label' => 'Light (default)',
20
  ),
21
  array(
22
+ 'value' => 'dark',
23
+ 'label' => 'Dark',
 
 
 
 
 
 
 
 
24
  ),
25
  );
26
  }
app/code/community/OlegKoval/ContactsFormCaptcha/controllers/IndexController.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @category OlegKoval
6
  * @package OlegKoval_ContactsFormCaptcha
7
- * @copyright Copyright (c) 2012 Oleg Koval
8
  * @author Oleg Koval <oleh.koval@gmail.com>
9
  */
10
  //include controller to override it
@@ -18,7 +18,7 @@ class OlegKoval_ContactsFormCaptcha_IndexController extends Mage_Contacts_IndexC
18
  const XML_PATH_CFC_LANG = 'contacts/olegkoval_contactsformcaptcha/lang';
19
 
20
  /**
21
- * Check if "Contacts Form Captcha" is enabled
22
  */
23
  public function preDispatch() {
24
  parent::preDispatch();
@@ -33,17 +33,13 @@ class OlegKoval_ContactsFormCaptcha_IndexController extends Mage_Contacts_IndexC
33
  $this->getLayout()->getBlock('contactForm')->setFormAction(Mage::getUrl('*/*/post'));
34
 
35
  if (Mage::getStoreConfigFlag(self::XML_PATH_CFC_ENABLED)) {
36
- //include reCaptcha library
37
- require_once(Mage::getBaseDir('lib') . DS .'reCaptcha'. DS .'recaptchalib.php');
38
-
39
  //create captcha html-code
40
- $publickey = Mage::getStoreConfig(self::XML_PATH_CFC_PUBLIC_KEY);
41
- $captcha_code = recaptcha_get_html($publickey, null, Mage::app()->getStore()->isCurrentlySecure());
42
 
43
  //get reCaptcha theme name
44
  $theme = Mage::getStoreConfig(self::XML_PATH_CFC_THEME);
45
- if (strlen($theme) == 0 || !in_array($theme, array('red', 'white', 'blackglass', 'clean'))) {
46
- $theme = 'red';
47
  }
48
 
49
  //get reCaptcha lang name
@@ -51,10 +47,8 @@ class OlegKoval_ContactsFormCaptcha_IndexController extends Mage_Contacts_IndexC
51
  if (strlen($lang) == 0 || !in_array($lang, array('en', 'nl', 'fr', 'de', 'pt', 'ru', 'es', 'tr'))) {
52
  $lang = 'en';
53
  }
54
- //small hack for language feature - because it's not working as described in documentation
55
- $captcha_code = str_replace('?k=', '?hl='. $lang .'&amp;k=', $captcha_code);
56
 
57
- $this->getLayout()->getBlock('contactForm')->setCaptchaCode($captcha_code)
58
  ->setCaptchaTheme($theme)
59
  ->setCaptchaLang($lang);
60
  }
@@ -66,7 +60,6 @@ class OlegKoval_ContactsFormCaptcha_IndexController extends Mage_Contacts_IndexC
66
 
67
  /**
68
  * Handle post request of Contact form
69
- * @return [type] [description]
70
  */
71
  public function postAction() {
72
  if (Mage::getStoreConfigFlag(self::XML_PATH_CFC_ENABLED)) {
@@ -77,15 +70,7 @@ class OlegKoval_ContactsFormCaptcha_IndexController extends Mage_Contacts_IndexC
77
  Mage::getSingleton('core/session')->setData('contactForm', $formData);
78
 
79
  if ($post) {
80
- //include reCaptcha library
81
- require_once(Mage::getBaseDir('lib') . DS .'reCaptcha'. DS .'recaptchalib.php');
82
-
83
- //validate captcha
84
- $privatekey = Mage::getStoreConfig(self::XML_PATH_CFC_PRIVATE_KEY);
85
- $remote_addr = $this->getRequest()->getServer('REMOTE_ADDR');
86
- $captcha = recaptcha_check_answer($privatekey, $remote_addr, $post["recaptcha_challenge_field"], $post["recaptcha_response_field"]);
87
-
88
- if (!$captcha->is_valid) {
89
  throw new Exception($this->__("The reCAPTCHA wasn't entered correctly. Go back and try it again."), 1);
90
  }
91
 
@@ -107,4 +92,40 @@ class OlegKoval_ContactsFormCaptcha_IndexController extends Mage_Contacts_IndexC
107
  //everything is OK - call parent action
108
  parent::postAction();
109
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  }
4
  *
5
  * @category OlegKoval
6
  * @package OlegKoval_ContactsFormCaptcha
7
+ * @copyright Copyright (c) 2012 - 2016 Oleg Koval
8
  * @author Oleg Koval <oleh.koval@gmail.com>
9
  */
10
  //include controller to override it
18
  const XML_PATH_CFC_LANG = 'contacts/olegkoval_contactsformcaptcha/lang';
19
 
20
  /**
21
+ * @see parent::preDispatch
22
  */
23
  public function preDispatch() {
24
  parent::preDispatch();
33
  $this->getLayout()->getBlock('contactForm')->setFormAction(Mage::getUrl('*/*/post'));
34
 
35
  if (Mage::getStoreConfigFlag(self::XML_PATH_CFC_ENABLED)) {
 
 
 
36
  //create captcha html-code
37
+ $siteKey = Mage::getStoreConfig(self::XML_PATH_CFC_PUBLIC_KEY);
 
38
 
39
  //get reCaptcha theme name
40
  $theme = Mage::getStoreConfig(self::XML_PATH_CFC_THEME);
41
+ if (strlen($theme) == 0 || !in_array($theme, array('dark', 'light'))) {
42
+ $theme = 'light';
43
  }
44
 
45
  //get reCaptcha lang name
47
  if (strlen($lang) == 0 || !in_array($lang, array('en', 'nl', 'fr', 'de', 'pt', 'ru', 'es', 'tr'))) {
48
  $lang = 'en';
49
  }
 
 
50
 
51
+ $this->getLayout()->getBlock('contactForm')->setSiteKey($siteKey)
52
  ->setCaptchaTheme($theme)
53
  ->setCaptchaLang($lang);
54
  }
60
 
61
  /**
62
  * Handle post request of Contact form
 
63
  */
64
  public function postAction() {
65
  if (Mage::getStoreConfigFlag(self::XML_PATH_CFC_ENABLED)) {
70
  Mage::getSingleton('core/session')->setData('contactForm', $formData);
71
 
72
  if ($post) {
73
+ if (!isset($post['g-recaptcha-response']) || !$this->isCaptchaValid($post['g-recaptcha-response'])) {
 
 
 
 
 
 
 
 
74
  throw new Exception($this->__("The reCAPTCHA wasn't entered correctly. Go back and try it again."), 1);
75
  }
76
 
92
  //everything is OK - call parent action
93
  parent::postAction();
94
  }
95
+
96
+ /**
97
+ * Check if captcha is valid
98
+ * @param string $captchaResponse
99
+ * @return boolean
100
+ */
101
+ private function isCaptchaValid($captchaResponse) {
102
+ $result = false;
103
+
104
+ $params = array(
105
+ 'secret' => Mage::getStoreConfig(self::XML_PATH_CFC_PRIVATE_KEY),
106
+ 'response' => $captchaResponse
107
+ );
108
+
109
+ $ch = curl_init('https://www.google.com/recaptcha/api/siteverify');
110
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1) ;
111
+ curl_setopt($ch, CURLOPT_HEADER, 0);
112
+ curl_setopt($ch, CURLOPT_POST, 1);
113
+ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
114
+ curl_setopt($ch, CURLOPT_VERBOSE, 1);
115
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
116
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
117
+ curl_setopt($ch, CURLOPT_TIMEOUT, 30);
118
+ $requestResult = trim(curl_exec($ch));
119
+ curl_close($ch);
120
+
121
+ if (is_array(json_decode($requestResult, true))) {
122
+ $response = json_decode($requestResult, true);
123
+
124
+ if (isset($response['success']) && $response['success'] === true) {
125
+ $result = true;
126
+ }
127
+ }
128
+
129
+ return $result;
130
+ }
131
  }
app/code/community/OlegKoval/ContactsFormCaptcha/etc/config.xml CHANGED
@@ -5,14 +5,14 @@
5
  *
6
  * @category OlegKoval
7
  * @package OlegKoval_ContactsFormCaptcha
8
- * @copyright Copyright (c) 2012 Oleg Koval
9
  * @author Oleg Koval <oleh.koval@gmail.com>
10
  */
11
  -->
12
  <config>
13
  <modules>
14
  <OlegKoval_ContactsFormCaptcha>
15
- <version>1.3.1</version>
16
  <depends>
17
  <Mage_Contacts/>
18
  </depends>
5
  *
6
  * @category OlegKoval
7
  * @package OlegKoval_ContactsFormCaptcha
8
+ * @copyright Copyright (c) 2012 - 2016 Oleg Koval
9
  * @author Oleg Koval <oleh.koval@gmail.com>
10
  */
11
  -->
12
  <config>
13
  <modules>
14
  <OlegKoval_ContactsFormCaptcha>
15
+ <version>1.4.0</version>
16
  <depends>
17
  <Mage_Contacts/>
18
  </depends>
app/code/community/OlegKoval/ContactsFormCaptcha/etc/system.xml CHANGED
@@ -5,7 +5,7 @@
5
  *
6
  * @category OlegKoval
7
  * @package OlegKoval_ContactsFormCaptcha
8
- * @copyright Copyright (c) 2012 Oleg Koval
9
  * @author Oleg Koval <oleh.koval@gmail.com>
10
  */
11
  -->
5
  *
6
  * @category OlegKoval
7
  * @package OlegKoval_ContactsFormCaptcha
8
+ * @copyright Copyright (c) 2012 - 2016 Oleg Koval
9
  * @author Oleg Koval <oleh.koval@gmail.com>
10
  */
11
  -->
app/design/frontend/base/default/layout/contactsformcaptcha.xml CHANGED
@@ -5,7 +5,7 @@
5
  *
6
  * @category OlegKoval
7
  * @package OlegKoval_ContactsFormCaptcha
8
- * @copyright Copyright (c) 2012 Oleg Koval
9
  * @author Oleg Koval <oleh.koval@gmail.com>
10
  */
11
  -->
5
  *
6
  * @category OlegKoval
7
  * @package OlegKoval_ContactsFormCaptcha
8
+ * @copyright Copyright (c) 2012 - 2016 Oleg Koval
9
  * @author Oleg Koval <oleh.koval@gmail.com>
10
  */
11
  -->
app/design/frontend/base/default/template/contactsformcaptcha/form.phtml CHANGED
@@ -33,13 +33,15 @@
33
  <div class="page-title">
34
  <h1><?php echo Mage::helper('contacts')->__('Contact Us') ?></h1>
35
  </div>
 
36
  <script type="text/javascript">
37
- //<![CDATA[
38
- var RecaptchaOptions = {
39
- theme : '<?php echo $this->getCaptchaTheme(); ?>',
40
- lang : '<?php echo $this->getCaptchaLang(); ?>',
41
- };
42
- //]]>
 
43
  </script>
44
  <form action="<?php echo $this->getFormAction(); ?>" id="contactForm" method="post">
45
  <div class="fieldset">
@@ -73,7 +75,7 @@
73
  </li>
74
  <li class="wide">
75
  <div class="input-box">
76
- <?php echo $this->getCaptchaCode(); ?>
77
  </div>
78
  </li>
79
  </ul>
33
  <div class="page-title">
34
  <h1><?php echo Mage::helper('contacts')->__('Contact Us') ?></h1>
35
  </div>
36
+ <script src="https://www.google.com/recaptcha/api.js?onload=renderReCaptcha&render=explicit" async defer></script>
37
  <script type="text/javascript">
38
+ function renderReCaptcha() {
39
+ grecaptcha.render('re_captcha', {
40
+ sitekey: '<?php echo $this->getSiteKey(); ?>',
41
+ theme: '<?php echo $this->getCaptchaTheme(); ?>',
42
+ lang: '<?php echo $this->getCaptchaLang(); ?>'
43
+ });
44
+ }
45
  </script>
46
  <form action="<?php echo $this->getFormAction(); ?>" id="contactForm" method="post">
47
  <div class="fieldset">
75
  </li>
76
  <li class="wide">
77
  <div class="input-box">
78
+ <div id="re_captcha"></div>
79
  </div>
80
  </li>
81
  </ul>
app/etc/modules/OlegKoval_ContactsFormCaptcha.xml CHANGED
@@ -5,7 +5,7 @@
5
  *
6
  * @category OlegKoval
7
  * @package OlegKoval_ContactsFormCaptcha
8
- * @copyright Copyright (c) 2012 Oleg Koval
9
  * @author Oleg Koval <oleh.koval@gmail.com>
10
  */
11
  -->
5
  *
6
  * @category OlegKoval
7
  * @package OlegKoval_ContactsFormCaptcha
8
+ * @copyright Copyright (c) 2012 - 2016 Oleg Koval
9
  * @author Oleg Koval <oleh.koval@gmail.com>
10
  */
11
  -->
lib/reCaptcha/recaptchalib.php DELETED
@@ -1,276 +0,0 @@
1
- <?php
2
- /*
3
- * This is a PHP library that handles calling reCAPTCHA.
4
- * - Documentation and latest version
5
- * http://recaptcha.net/plugins/php/
6
- * - Get a reCAPTCHA API Key
7
- * https://www.google.com/recaptcha/admin/create
8
- * - Discussion group
9
- * http://groups.google.com/group/recaptcha
10
- *
11
- * Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
12
- * AUTHORS:
13
- * Mike Crawford
14
- * Ben Maurer
15
- *
16
- * Permission is hereby granted, free of charge, to any person obtaining a copy
17
- * of this software and associated documentation files (the "Software"), to deal
18
- * in the Software without restriction, including without limitation the rights
19
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
- * copies of the Software, and to permit persons to whom the Software is
21
- * furnished to do so, subject to the following conditions:
22
- *
23
- * The above copyright notice and this permission notice shall be included in
24
- * all copies or substantial portions of the Software.
25
- *
26
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32
- * THE SOFTWARE.
33
- */
34
-
35
- /**
36
- * The reCAPTCHA server URL's
37
- */
38
- define("RECAPTCHA_API_SERVER", "http://www.google.com/recaptcha/api");
39
- define("RECAPTCHA_API_SECURE_SERVER", "https://www.google.com/recaptcha/api");
40
- define("RECAPTCHA_VERIFY_SERVER", "www.google.com");
41
-
42
- /**
43
- * Encodes the given data into a query string format
44
- * @param $data - array of string elements to be encoded
45
- * @return string - encoded request
46
- */
47
- function _recaptcha_qsencode ($data) {
48
- $req = "";
49
- foreach ( $data as $key => $value )
50
- $req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
51
-
52
- // Cut the last '&'
53
- $req=substr($req,0,strlen($req)-1);
54
- return $req;
55
- }
56
-
57
-
58
-
59
- /**
60
- * Submits an HTTP POST to a reCAPTCHA server
61
- * @param string $host
62
- * @param string $path
63
- * @param array $data
64
- * @param int port
65
- * @return array response
66
- */
67
- function _recaptcha_http_post($host, $path, $data, $port = 80) {
68
-
69
- $req = _recaptcha_qsencode ($data);
70
-
71
- $http_request = "POST $path HTTP/1.0\r\n";
72
- $http_request .= "Host: $host\r\n";
73
- $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
74
- $http_request .= "Content-Length: " . strlen($req) . "\r\n";
75
- $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
76
- $http_request .= "\r\n";
77
- $http_request .= $req;
78
-
79
- $response = '';
80
- if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
81
- die ('Could not open socket');
82
- }
83
-
84
- fwrite($fs, $http_request);
85
-
86
- while ( !feof($fs) )
87
- $response .= fgets($fs, 1160); // One TCP-IP packet
88
- fclose($fs);
89
- $response = explode("\r\n\r\n", $response, 2);
90
-
91
- return $response;
92
- }
93
-
94
-
95
-
96
- /**
97
- * Gets the challenge HTML (javascript and non-javascript version).
98
- * This is called from the browser, and the resulting reCAPTCHA HTML widget
99
- * is embedded within the HTML form it was called from.
100
- * @param string $pubkey A public key for reCAPTCHA
101
- * @param string $error The error given by reCAPTCHA (optional, default is null)
102
- * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false)
103
- * @return string - The HTML to be embedded in the user's form.
104
- */
105
- function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
106
- {
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
- }
110
-
111
- if ($use_ssl) {
112
- $server = RECAPTCHA_API_SECURE_SERVER;
113
- } else {
114
- $server = RECAPTCHA_API_SERVER;
115
- }
116
-
117
- $errorpart = "";
118
- if ($error) {
119
- $errorpart = "&amp;error=" . $error;
120
- }
121
- return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script>
122
-
123
- <noscript>
124
- <iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/>
125
- <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
126
- <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
127
- </noscript>';
128
- }
129
-
130
-
131
-
132
-
133
- /**
134
- * A ReCaptchaResponse is returned from recaptcha_check_answer()
135
- */
136
- class ReCaptchaResponse {
137
- var $is_valid;
138
- var $error;
139
- }
140
-
141
-
142
- /**
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
- */
151
- function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
152
- {
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
- }
156
-
157
- if ($remoteip == null || $remoteip == '') {
158
- die ("For security reasons, you must pass the remote ip to reCAPTCHA");
159
- }
160
-
161
-
162
-
163
- //discard spam submissions
164
- if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
165
- $recaptcha_response = new ReCaptchaResponse();
166
- $recaptcha_response->is_valid = false;
167
- $recaptcha_response->error = 'incorrect-captcha-sol';
168
- return $recaptcha_response;
169
- }
170
-
171
- $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
172
- array (
173
- 'privatekey' => $privkey,
174
- 'remoteip' => $remoteip,
175
- 'challenge' => $challenge,
176
- 'response' => $response
177
- ) + $extra_params
178
- );
179
-
180
- $answers = explode ("\n", $response [1]);
181
- $recaptcha_response = new ReCaptchaResponse();
182
-
183
- if (trim ($answers [0]) == 'true') {
184
- $recaptcha_response->is_valid = true;
185
- }
186
- else {
187
- $recaptcha_response->is_valid = false;
188
- $recaptcha_response->error = $answers [1];
189
- }
190
- return $recaptcha_response;
191
-
192
- }
193
-
194
- /**
195
- * gets a URL where the user can sign up for reCAPTCHA. If your application
196
- * has a configuration page where you enter a key, you should provide a link
197
- * using this function.
198
- * @param string $domain The domain where the page is hosted
199
- * @param string $appname The name of your application
200
- */
201
- function recaptcha_get_signup_url ($domain = null, $appname = null) {
202
- return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname));
203
- }
204
-
205
- function _recaptcha_aes_pad($val) {
206
- $block_size = 16;
207
- $numpad = $block_size - (strlen ($val) % $block_size);
208
- return str_pad($val, strlen ($val) + $numpad, chr($numpad));
209
- }
210
-
211
- /* Mailhide related code */
212
-
213
- function _recaptcha_aes_encrypt($val,$ky) {
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");
221
- }
222
-
223
-
224
- function _recaptcha_mailhide_urlbase64 ($x) {
225
- return strtr(base64_encode ($x), '+/', '-_');
226
- }
227
-
228
- /* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
229
- function recaptcha_mailhide_url($pubkey, $privkey, $email) {
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
- }
234
-
235
-
236
- $ky = pack('H*', $privkey);
237
- $cryptmail = _recaptcha_aes_encrypt ($email, $ky);
238
-
239
- return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
240
- }
241
-
242
- /**
243
- * gets the parts of the email to expose to the user.
244
- * eg, given johndoe@example,com return ["john", "example.com"].
245
- * the email is then displayed as john...@example.com
246
- */
247
- function _recaptcha_mailhide_email_parts ($email) {
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;
258
- }
259
-
260
- /**
261
- * Gets html to display an email address given a public an private key.
262
- * to get a key, go to:
263
- *
264
- * http://www.google.com/recaptcha/mailhide/apikey
265
- */
266
- function recaptcha_mailhide_html($pubkey, $privkey, $email) {
267
- $emailparts = _recaptcha_mailhide_email_parts ($email);
268
- $url = recaptcha_mailhide_url ($pubkey, $privkey, $email);
269
-
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]);
272
-
273
- }
274
-
275
-
276
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>contactsformcaptcha</name>
4
- <version>1.3.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/OSL-3.0">OSL v3.0</license>
7
  <channel>community</channel>
@@ -12,11 +12,11 @@
12
  &#xD;
13
  &#xD;
14
  This extension uses reCaptcha library (http://www.google.com/recaptcha).</description>
15
- <notes>Added autodetecting of secure mode. Modified labels of config options.</notes>
16
  <authors><author><name>Oleg Koval</name><user>auto-converted</user><email>oleh.koval@gmail.com</email></author></authors>
17
- <date>2016-01-09</date>
18
- <time>14:46:57</time>
19
- <contents><target name="magecommunity"><dir name="OlegKoval"><dir name="ContactsFormCaptcha"><dir name="Model"><dir name="System"><dir name="Config"><dir name="Source"><dir name="Dropdown"><file name="Lang.php" hash="c3b3814ccfc3f97fb8807f0d4ad69d8c"/><file name="Theme.php" hash="c0a7eb1ad6e2157b5f822d0a5d30022c"/></dir></dir></dir></dir></dir><dir name="controllers"><file name="IndexController.php" hash="20cd5985f31d0c960a10ed2581350368"/></dir><dir name="etc"><file name="config.xml" hash="1d43e3e113e335f3aed32071fd73b0e3"/><file name="system.xml" hash="8dfefc416bfb626600a79115dfa5ddd6"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="OlegKoval_ContactsFormCaptcha.xml" hash="9b7cbc1587fc43d6a0cd1106bc19a4fc"/></dir></target><target name="magelib"><dir name="reCaptcha"><file name="recaptchalib.php" hash="f80a9f01727de68aba8e98f1e37345a9"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="contactsformcaptcha.xml" hash="c51cd3c07d757ee1985653544fffb2fd"/></dir><dir name="template"><dir name="contactsformcaptcha"><file name="form.phtml" hash="bb89546be7a1730937089f1769438ffc"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="OlegKoval_ContactsFormCaptcha.csv" hash="5e430d77c352109bf67305e56b4a3845"/></dir></target></contents>
20
  <compatible/>
21
  <dependencies/>
22
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>contactsformcaptcha</name>
4
+ <version>1.4.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/OSL-3.0">OSL v3.0</license>
7
  <channel>community</channel>
12
  &#xD;
13
  &#xD;
14
  This extension uses reCaptcha library (http://www.google.com/recaptcha).</description>
15
+ <notes>Implemented reCaptcha V2.0</notes>
16
  <authors><author><name>Oleg Koval</name><user>auto-converted</user><email>oleh.koval@gmail.com</email></author></authors>
17
+ <date>2016-04-05</date>
18
+ <time>11:17:40</time>
19
+ <contents><target name="magecommunity"><dir name="OlegKoval"><dir name="ContactsFormCaptcha"><dir name="Model"><dir name="System"><dir name="Config"><dir name="Source"><dir name="Dropdown"><file name="Lang.php" hash="03f3c49ec2dcaccaef8af691d717c6e0"/><file name="Theme.php" hash="e378be865954e4e23047b576618d1e66"/></dir></dir></dir></dir></dir><dir name="controllers"><file name="IndexController.php" hash="8ccb4c819b849e8d3babd0ebf0469e29"/></dir><dir name="etc"><file name="config.xml" hash="f62eed1bc71abbf55f5046d0eb49ef1b"/><file name="system.xml" hash="1b51861c32ee644f56f6bb2d0649c8ee"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="OlegKoval_ContactsFormCaptcha.xml" hash="aa8aecf0aae35f405c3908112baa0eac"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="contactsformcaptcha.xml" hash="c5fb2a235c46fe4946a7fbdf81eaa1b9"/></dir><dir name="template"><dir name="contactsformcaptcha"><file name="form.phtml" hash="c41688f8b47d23cccb6e783d753d63eb"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="OlegKoval_ContactsFormCaptcha.csv" hash="5e430d77c352109bf67305e56b4a3845"/></dir></target></contents>
20
  <compatible/>
21
  <dependencies/>
22
  </package>