Studioforty9_Recaptcha - Version 1.2.0

Version Notes

Tested on Magento versions: 1.7.0.2, 1.8.0.0, 1.8.1.0, 1.9.0.1 and 1.9.1.0. See https://travis-ci.org/StudioForty9/Recaptcha for more.

Download this release

Release Info

Developer StudioForty9
Extension Studioforty9_Recaptcha
Version 1.2.0
Comparing to
See all releases


Code changes from version 1.0.1 to 1.2.0

Files changed (25) hide show
  1. app/code/community/Studioforty9/Recaptcha/Block/Autorender.php +18 -2
  2. app/code/community/Studioforty9/Recaptcha/Block/Explicit.php +72 -0
  3. app/code/community/Studioforty9/Recaptcha/Helper/Data.php +109 -3
  4. app/code/community/Studioforty9/Recaptcha/Helper/Request.php +12 -8
  5. app/code/community/Studioforty9/Recaptcha/Helper/Response.php +15 -2
  6. app/code/community/Studioforty9/Recaptcha/Model/Observer.php +94 -0
  7. app/code/community/Studioforty9/Recaptcha/Model/Observer/Contacts.php +0 -88
  8. app/code/community/Studioforty9/Recaptcha/Model/Source/Theme.php +2 -2
  9. app/code/community/Studioforty9/Recaptcha/Test/Block/Autorender.php +0 -115
  10. app/code/community/Studioforty9/Recaptcha/Test/Config/Module.php +0 -97
  11. app/code/community/Studioforty9/Recaptcha/Test/Helper/Request.php +0 -167
  12. app/code/community/Studioforty9/Recaptcha/Test/Helper/Response.php +0 -105
  13. app/code/community/Studioforty9/Recaptcha/Test/Model/Observer/Contacts.php +0 -268
  14. app/code/community/Studioforty9/Recaptcha/Test/Model/Source/Theme.php +0 -42
  15. app/code/community/Studioforty9/Recaptcha/etc/config.xml +33 -5
  16. app/code/community/Studioforty9/Recaptcha/etc/system.xml +38 -2
  17. app/design/frontend/base/default/layout/studioforty9_recaptcha.xml +21 -3
  18. app/design/frontend/base/default/template/studioforty9/recaptcha/autorender.phtml +5 -2
  19. app/design/frontend/base/default/template/studioforty9/recaptcha/explicit.phtml +34 -0
  20. app/design/frontend/base/default/template/studioforty9/recaptcha/samples/base/contacts/form.phtml +74 -0
  21. app/design/frontend/base/default/template/studioforty9/recaptcha/samples/base/persistent/customer/form/register.phtml +193 -0
  22. app/design/frontend/base/default/template/studioforty9/recaptcha/samples/base/review/form.phtml +133 -0
  23. app/design/frontend/base/default/template/studioforty9/recaptcha/samples/base/sendfriend/send.phtml +144 -0
  24. app/etc/modules/Studioforty9_Recaptcha.xml +2 -2
  25. package.xml +31 -18
app/code/community/Studioforty9/Recaptcha/Block/Autorender.php CHANGED
@@ -5,9 +5,9 @@
5
  * @category Studioforty9
6
  * @package Studioforty9_Recaptcha
7
  * @author StudioForty9 <info@studioforty9.com>
8
- * @copyright 2014 StudioForty9 (http://www.studioforty9.com)
9
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
- * @version 1.0.0
11
  * @link https://github.com/studioforty9/recaptcha
12
  */
13
 
@@ -56,4 +56,20 @@ class Studioforty9_Recaptcha_Block_Autorender extends Mage_Core_Block_Template
56
 
57
  return $html;
58
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  }
5
  * @category Studioforty9
6
  * @package Studioforty9_Recaptcha
7
  * @author StudioForty9 <info@studioforty9.com>
8
+ * @copyright 2015 StudioForty9 (http://www.studioforty9.com)
9
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
+ * @version 1.1.0
11
  * @link https://github.com/studioforty9/recaptcha
12
  */
13
 
56
 
57
  return $html;
58
  }
59
+
60
+ /**
61
+ * Determine if the module configuration settings allow displaying
62
+ * the widget in the current context.
63
+ *
64
+ * @param string $route
65
+ * @return bool
66
+ */
67
+ public function isAllowed($route)
68
+ {
69
+ if ($this->hasData('allow') && $this->getData('allow')) {
70
+ return true;
71
+ }
72
+
73
+ return Mage::helper('studioforty9_recaptcha')->isAllowed($route);
74
+ }
75
  }
app/code/community/Studioforty9/Recaptcha/Block/Explicit.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Studioforty9_Recaptcha
4
+ *
5
+ * @category Studioforty9
6
+ * @package Studioforty9_Recaptcha
7
+ * @author StudioForty9 <info@studioforty9.com>
8
+ * @copyright 2015 StudioForty9 (http://www.studioforty9.com)
9
+ * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
+ * @version 1.1.0
11
+ * @link https://github.com/studioforty9/recaptcha
12
+ */
13
+
14
+ /**
15
+ * Studioforty9_Recaptcha_Block_Explicit
16
+ *
17
+ * @category Studioforty9
18
+ * @package Studioforty9_Recaptcha
19
+ * @subpackage Block
20
+ */
21
+ class Studioforty9_Recaptcha_Block_Explicit extends Mage_Core_Block_Template
22
+ {
23
+ /**
24
+ * Get the reCAPTACHA javascript code.
25
+ *
26
+ * @return string
27
+ */
28
+ public function getRecaptchaScript()
29
+ {
30
+ if (! Mage::helper('studioforty9_recaptcha')->isEnabled()) {
31
+ return '';
32
+ }
33
+
34
+ return '<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer></script>';
35
+ }
36
+
37
+ /**
38
+ * Get the recaptcha theme setting.
39
+ *
40
+ * @return string
41
+ */
42
+ public function getTheme()
43
+ {
44
+ return Mage::helper('studioforty9_recaptcha')->getTheme();
45
+ }
46
+
47
+ /**
48
+ * Get the recaptcha site key.
49
+ *
50
+ * @return string
51
+ */
52
+ public function getSiteKey()
53
+ {
54
+ return Mage::helper('studioforty9_recaptcha')->getSiteKey();
55
+ }
56
+
57
+ /**
58
+ * Determine if the module configuration settings allow displaying
59
+ * the widget in the current context.
60
+ *
61
+ * @param string $route
62
+ * @return bool
63
+ */
64
+ public function isAllowed($route)
65
+ {
66
+ if ($this->hasData('allow') && $this->getData('allow')) {
67
+ return true;
68
+ }
69
+
70
+ return Mage::helper('studioforty9_recaptcha')->isAllowed($route);
71
+ }
72
+ }
app/code/community/Studioforty9/Recaptcha/Helper/Data.php CHANGED
@@ -5,9 +5,9 @@
5
  * @category Studioforty9
6
  * @package Studioforty9_Recaptcha
7
  * @author StudioForty9 <info@studioforty9.com>
8
- * @copyright 2014 StudioForty9 (http://www.studioforty9.com)
9
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
- * @version 1.0.0
11
  * @link https://github.com/studioforty9/recaptcha
12
  */
13
 
@@ -21,10 +21,19 @@
21
  */
22
  class Studioforty9_Recaptcha_Helper_Data extends Mage_Core_Helper_Abstract
23
  {
 
 
 
 
24
  const MODULE_ENABLED = 'google/recaptcha/enabled';
 
 
 
 
25
  const MODULE_KEY_SITE = 'google/recaptcha/site_key';
26
  const MODULE_KEY_SECRET = 'google/recaptcha/secret_key';
27
  const MODULE_KEY_THEME = 'google/recaptcha/theme';
 
28
 
29
  /**
30
  * Is the module enabled in configuration.
@@ -34,7 +43,51 @@ class Studioforty9_Recaptcha_Helper_Data extends Mage_Core_Helper_Abstract
34
  */
35
  public function isEnabled()
36
  {
37
- return (bool) Mage::getStoreConfig(self::MODULE_ENABLED);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  }
39
 
40
  /**
@@ -69,4 +122,57 @@ class Studioforty9_Recaptcha_Helper_Data extends Mage_Core_Helper_Abstract
69
  {
70
  return Mage::getStoreConfig(self::MODULE_KEY_THEME);
71
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  }
5
  * @category Studioforty9
6
  * @package Studioforty9_Recaptcha
7
  * @author StudioForty9 <info@studioforty9.com>
8
+ * @copyright 2015 StudioForty9 (http://www.studioforty9.com)
9
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
+ * @version 1.1.0
11
  * @link https://github.com/studioforty9/recaptcha
12
  */
13
 
21
  */
22
  class Studioforty9_Recaptcha_Helper_Data extends Mage_Core_Helper_Abstract
23
  {
24
+ /**#@+
25
+ * Configuration paths.
26
+ * @var string
27
+ */
28
  const MODULE_ENABLED = 'google/recaptcha/enabled';
29
+ const MODULE_ENABLED_CONTACTS = 'google/recaptcha/enabled_contacts';
30
+ const MODULE_ENABLED_REVIEWS = 'google/recaptcha/enabled_reviews';
31
+ const MODULE_ENABLED_SENDFRIEND = 'google/recaptcha/enabled_sendfriend';
32
+ const MODULE_ENABLED_CUSTOMER_REG = 'google/recaptcha/enabled_customer_registration';
33
  const MODULE_KEY_SITE = 'google/recaptcha/site_key';
34
  const MODULE_KEY_SECRET = 'google/recaptcha/secret_key';
35
  const MODULE_KEY_THEME = 'google/recaptcha/theme';
36
+ /**#@-*/
37
 
38
  /**
39
  * Is the module enabled in configuration.
43
  */
44
  public function isEnabled()
45
  {
46
+ return Mage::getStoreConfigFlag(self::MODULE_ENABLED);
47
+ }
48
+
49
+ /**
50
+ * Is the recaptcha enabled on the contacts form.
51
+ *
52
+ * @codeCoverageIgnore
53
+ * @return bool
54
+ */
55
+ public function isContactsEnabled()
56
+ {
57
+ return Mage::getStoreConfigFlag(self::MODULE_ENABLED_CONTACTS);
58
+ }
59
+
60
+ /**
61
+ * Is the recaptcha enabled on the product review form.
62
+ *
63
+ * @codeCoverageIgnore
64
+ * @return bool
65
+ */
66
+ public function isReviewsEnabled()
67
+ {
68
+ return Mage::getStoreConfigFlag(self::MODULE_ENABLED_REVIEWS);
69
+ }
70
+
71
+ /**
72
+ * Is the recaptcha enabled on the product send to friend form.
73
+ *
74
+ * @codeCoverageIgnore
75
+ * @return bool
76
+ */
77
+ public function isSendFriendEnabled()
78
+ {
79
+ return Mage::getStoreConfigFlag(self::MODULE_ENABLED_SENDFRIEND);
80
+ }
81
+
82
+ /**
83
+ * Is the recaptcha enabled on the customer registration form.
84
+ *
85
+ * @codeCoverageIgnore
86
+ * @return bool
87
+ */
88
+ public function isCustomerRegistrationEnabled()
89
+ {
90
+ return Mage::getStoreConfigFlag(self::MODULE_ENABLED_CUSTOMER_REG);
91
  }
92
 
93
  /**
122
  {
123
  return Mage::getStoreConfig(self::MODULE_KEY_THEME);
124
  }
125
+
126
+ /**
127
+ * Get the redirect URL.
128
+ * - no visitor_data or last_url stored in core/session
129
+ * return the base_url
130
+ * - no visitor_data but last_url is stored in core/session
131
+ * return the last_url
132
+ * - visitor_data exists but request_uri does not, but last_url is stored in core/session
133
+ * return the last_url
134
+ * - request_uri exists
135
+ * return the request_uri
136
+ *
137
+ * @todo Unit Test this method.
138
+ * @return string
139
+ */
140
+ public function getRedirectUrl()
141
+ {
142
+ $_session = Mage::getSingleton('core/session');
143
+
144
+ if (! $_session->hasVisitorData() && !$_session->hasLastUrl()) {
145
+ return Mage::getBaseUrl();
146
+ }
147
+
148
+ if (! $_session->hasVisitorData() && $_session->hasLastUrl()) {
149
+ return $_session->getLastUrl();
150
+ }
151
+
152
+ $visitorData = $_session->getVisitorData();
153
+ if (! array_key_exists('request_uri', $visitorData) && $_session->hasLastUrl()) {
154
+ return $_session->getLastUrl();
155
+ }
156
+
157
+ return $visitorData['request_uri'];
158
+ }
159
+
160
+ /**
161
+ * Is the module allowed to run.
162
+ *
163
+ * @todo Unit Test this method.
164
+ * @param string $route
165
+ * @return bool
166
+ */
167
+ public function isAllowed($route)
168
+ {
169
+ $acl = array(
170
+ 'contacts' => $this->isContactsEnabled(),
171
+ 'review' => $this->isReviewsEnabled(),
172
+ 'customer' => $this->isCustomerRegistrationEnabled(),
173
+ 'sendfriend' => $this->isSendFriendEnabled()
174
+ );
175
+
176
+ return ($this->isEnabled() && array_key_exists($route, $acl) && $acl[$route] === true);
177
+ }
178
  }
app/code/community/Studioforty9/Recaptcha/Helper/Request.php CHANGED
@@ -5,9 +5,9 @@
5
  * @category Studioforty9
6
  * @package Studioforty9_Recaptcha
7
  * @author StudioForty9 <info@studioforty9.com>
8
- * @copyright 2014 StudioForty9 (http://www.studioforty9.com)
9
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
- * @version 1.0.0
11
  * @link https://github.com/studioforty9/recaptcha
12
  */
13
 
@@ -73,13 +73,17 @@ class Studioforty9_Recaptcha_Helper_Request extends Mage_Core_Helper_Abstract
73
 
74
  $client = $this->getHttpClient();
75
  $client->setParameterGet($params);
76
-
77
- $response = $client->request('GET');
78
- $data = Mage::helper('core')->jsonDecode($response->getBody());
79
-
80
  $errors = array();
81
- if (array_key_exists('error-codes', $data)) {
82
- $errors = $data['error-codes'];
 
 
 
 
 
 
 
 
83
  }
84
 
85
  return new Studioforty9_Recaptcha_Helper_Response($data['success'], $errors);
5
  * @category Studioforty9
6
  * @package Studioforty9_Recaptcha
7
  * @author StudioForty9 <info@studioforty9.com>
8
+ * @copyright 2015 StudioForty9 (http://www.studioforty9.com)
9
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
+ * @version 1.1.0
11
  * @link https://github.com/studioforty9/recaptcha
12
  */
13
 
73
 
74
  $client = $this->getHttpClient();
75
  $client->setParameterGet($params);
 
 
 
 
76
  $errors = array();
77
+
78
+ try {
79
+ $response = $client->request('GET');
80
+ $data = Mage::helper('core')->jsonDecode($response->getBody());
81
+ if (array_key_exists('error-codes', $data)) {
82
+ $errors = $data['error-codes'];
83
+ }
84
+ } catch (Exception $e) {
85
+ $data = array('success' => false);
86
+ Mage::logException($e);
87
  }
88
 
89
  return new Studioforty9_Recaptcha_Helper_Response($data['success'], $errors);
app/code/community/Studioforty9/Recaptcha/Helper/Response.php CHANGED
@@ -5,9 +5,9 @@
5
  * @category Studioforty9
6
  * @package Studioforty9_Recaptcha
7
  * @author StudioForty9 <info@studioforty9.com>
8
- * @copyright 2014 StudioForty9 (http://www.studioforty9.com)
9
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
- * @version 1.0.0
11
  * @link https://github.com/studioforty9/recaptcha
12
  */
13
 
@@ -145,4 +145,17 @@ class Studioforty9_Recaptcha_Helper_Response extends Mage_Core_Helper_Abstract
145
 
146
  return $this->_errorDescriptions[$errorCode];
147
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  }
5
  * @category Studioforty9
6
  * @package Studioforty9_Recaptcha
7
  * @author StudioForty9 <info@studioforty9.com>
8
+ * @copyright 2015 StudioForty9 (http://www.studioforty9.com)
9
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
+ * @version 1.1.0
11
  * @link https://github.com/studioforty9/recaptcha
12
  */
13
 
145
 
146
  return $this->_errorDescriptions[$errorCode];
147
  }
148
+
149
+ /**
150
+ * Log the error to file.
151
+ */
152
+ public function log()
153
+ {
154
+ Mage::log(
155
+ sprintf(
156
+ 'reCAPTCHA Errors: %1$s',
157
+ implode(', ', $this->getErrors())
158
+ )
159
+ );
160
+ }
161
  }
app/code/community/Studioforty9/Recaptcha/Model/Observer.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Studioforty9_Recaptcha
4
+ *
5
+ * @category Studioforty9
6
+ * @package Studioforty9_Recaptcha
7
+ * @author StudioForty9 <info@studioforty9.com>
8
+ * @copyright 2015 StudioForty9 (http://www.studioforty9.com)
9
+ * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
+ * @version 1.1.0
11
+ * @link https://github.com/studioforty9/recaptcha
12
+ */
13
+
14
+ /**
15
+ * Studioforty9_Recaptcha_Model_Observer
16
+ *
17
+ * @category Studioforty9
18
+ * @package Studioforty9_Recaptcha
19
+ * @subpackage Model
20
+ * @author StudioForty9 <info@studioforty9.com>
21
+ */
22
+ class Studioforty9_Recaptcha_Model_Observer
23
+ {
24
+ /**
25
+ * @var Studioforty9_Recaptcha_Helper_Data
26
+ */
27
+ protected $_helper;
28
+
29
+ /**
30
+ * Set the module data helper.
31
+ */
32
+ public function __construct()
33
+ {
34
+ $this->_helper = Mage::helper('studioforty9_recaptcha');
35
+ }
36
+
37
+ /**
38
+ * Get the module data helper
39
+ *
40
+ * @return Studioforty9_Recaptcha_Helper_Data
41
+ */
42
+ public function getHelper()
43
+ {
44
+ return $this->_helper;
45
+ }
46
+
47
+ /**
48
+ * Run the event on the pre dispatch observer for:
49
+ * - controller_action_predispatch_index_post
50
+ * - controller_action_predispatch_review_product_post
51
+ *
52
+ * @param Varien_Event_Observer $observer The observer from the controller
53
+ * @return Varien_Event_Observer
54
+ */
55
+ public function onPostPreDispatch(Varien_Event_Observer $observer)
56
+ {
57
+ if (! $this->getHelper()->isEnabled()) {
58
+ return $observer;
59
+ }
60
+ /** @var Mage_Core_Controller_Front_Action $controller */
61
+ $controller = $observer->getEvent()->getControllerAction();
62
+
63
+ if (! $this->getHelper()->isAllowed($controller->getRequest()->getRouteName())) {
64
+ return $observer;
65
+ }
66
+
67
+ /** @var Studioforty9_Recaptcha_Helper_Request $request */
68
+ $request = Mage::helper('studioforty9_recaptcha/request');
69
+ /** @var Studioforty9_Recaptcha_Helper_Response $response */
70
+ $response = $request->verify();
71
+
72
+ if ($response->isSuccess()) {
73
+ return $observer;
74
+ }
75
+
76
+ Mage::getSingleton('core/session')->addError(
77
+ $response->__(
78
+ 'There was an error with the recaptcha code, please try again.'
79
+ )
80
+ );
81
+
82
+ if ($response->hasErrors()) {
83
+ $response->log();
84
+ }
85
+
86
+ $flag = Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH;
87
+ $redirectUrl = $this->getHelper()->getRedirectUrl();
88
+ $controller->getResponse()->setRedirect($redirectUrl)->sendResponse();
89
+ $controller->getRequest()->setDispatched(true);
90
+ $controller->setFlag('', $flag, true);
91
+
92
+ return $controller;
93
+ }
94
+ }
app/code/community/Studioforty9/Recaptcha/Model/Observer/Contacts.php DELETED
@@ -1,88 +0,0 @@
1
- <?php
2
- /**
3
- * Studioforty9_Recaptcha
4
- *
5
- * @category Studioforty9
6
- * @package Studioforty9_Recaptcha
7
- * @author StudioForty9 <info@studioforty9.com>
8
- * @copyright 2014 StudioForty9 (http://www.studioforty9.com)
9
- * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
- * @version 1.0.0
11
- * @link https://github.com/studioforty9/recaptcha
12
- */
13
-
14
- /**
15
- * Studioforty9_Recaptcha_Model_Observer_Contacts
16
- *
17
- * @category Studioforty9
18
- * @package Studioforty9_Recaptcha
19
- * @subpackage Model
20
- * @author StudioForty9 <info@studioforty9.com>
21
- */
22
- class Studioforty9_Recaptcha_Model_Observer_Contacts
23
- {
24
- /**
25
- * Run the event on the contacts module, index controller, post action
26
- * pre dispatch observer.
27
- *
28
- * @param Varien_Event_Observer $observer The observer from the controller
29
- *
30
- * @return Varien_Event_Observer
31
- */
32
- public function onContactsPostPreDispatch(Varien_Event_Observer $observer)
33
- {
34
- if (!Mage::helper('studioforty9_recaptcha')->isEnabled()) {
35
- return $observer;
36
- }
37
-
38
- /** @var Mage_Contacts_IndexController $controller */
39
- $controller = $observer->getEvent()->getControllerAction();
40
-
41
- /** @var Studioforty9_Recaptcha_Helper_Request $request */
42
- $request = Mage::helper('studioforty9_recaptcha/request');
43
- /** @var Studioforty9_Recaptcha_Helper_Response $response */
44
- $response = $request->verify();
45
-
46
- if ($response->isFailure()) {
47
- Mage::getSingleton('core/session')->addError(
48
- $response->__(
49
- 'There was an error with the recaptcha code, please try again.'
50
- )
51
- );
52
-
53
- if ($response->hasErrors()) {
54
- $this->_logErrors($response);
55
- }
56
-
57
- $redirectUrl = $controller->getRequest()->getBaseUrl() . '/contacts';
58
- $controller->getResponse()->setRedirect($redirectUrl)->sendResponse();
59
- $controller->getRequest()->setDispatched(true);
60
- $controller->setFlag(
61
- '',
62
- Mage_Core_Controller_Front_Action::FLAG_NO_DISPATCH,
63
- true
64
- );
65
-
66
- return $controller;
67
- }
68
-
69
- return $observer;
70
- }
71
-
72
- /**
73
- * Log the errors from Google reCAPTCHA to system.log
74
- *
75
- * @param Studioforty9_Recaptcha_Helper_Response $response The response helper
76
- *
77
- * @return void
78
- */
79
- protected function _logErrors(Studioforty9_Recaptcha_Helper_Response $response)
80
- {
81
- Mage::log(
82
- sprintf(
83
- 'reCAPTCHA Errors: %1$s',
84
- implode(', ', $response->getErrors())
85
- )
86
- );
87
- }
88
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Studioforty9/Recaptcha/Model/Source/Theme.php CHANGED
@@ -5,9 +5,9 @@
5
  * @category Studioforty9
6
  * @package Studioforty9_Recaptcha
7
  * @author StudioForty9 <info@studioforty9.com>
8
- * @copyright 2014 StudioForty9 (http://www.studioforty9.com)
9
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
- * @version 1.0.0
11
  * @link https://github.com/studioforty9/recaptcha
12
  */
13
 
5
  * @category Studioforty9
6
  * @package Studioforty9_Recaptcha
7
  * @author StudioForty9 <info@studioforty9.com>
8
+ * @copyright 2015 StudioForty9 (http://www.studioforty9.com)
9
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
+ * @version 1.1.0
11
  * @link https://github.com/studioforty9/recaptcha
12
  */
13
 
app/code/community/Studioforty9/Recaptcha/Test/Block/Autorender.php DELETED
@@ -1,115 +0,0 @@
1
- <?php
2
- /**
3
- * Studioforty9_Recaptcha
4
- *
5
- * @category Studioforty9
6
- * @package Studioforty9_Recaptcha
7
- * @author StudioForty9 <info@studioforty9.com>
8
- * @copyright 2014 StudioForty9 (http://www.studioforty9.com)
9
- * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
- * @version 1.0.0
11
- * @link https://github.com/studioforty9/recaptcha
12
- */
13
-
14
- /**
15
- * Studioforty9_Recaptcha_Test_Block_Autorender
16
- *
17
- * @category Studioforty9
18
- * @package Studioforty9_Recaptcha
19
- * @subpackage Test
20
- * @author StudioForty9 <info@studioforty9.com>
21
- */
22
- class Studioforty9_Recaptcha_Test_Block_Autorender extends EcomDev_PHPUnit_Test_Case
23
- {
24
- /** @var Studioforty9_Recaptcha_Block_Autorender */
25
- protected $block;
26
-
27
- public function setUp()
28
- {
29
- $this->block = new Studioforty9_Recaptcha_Block_Autorender();
30
-
31
- parent::setUp();
32
- }
33
-
34
- protected function getMockDataHelper($enabled, $theme = 'light', $siteKey = '123456789', $secretKey = '987654321')
35
- {
36
- $helper = $this->getHelperMock('studioforty9_recaptcha', array(
37
- 'isEnabled', 'getSiteKey', 'getSecretKey', 'getTheme'
38
- ), false, array(), null, false);
39
-
40
- $helper->expects($this->any())
41
- ->method('isEnabled')
42
- ->will($this->returnValue($enabled));
43
-
44
-
45
- $helper->expects($this->any())
46
- ->method('getSiteKey')
47
- ->will($this->returnValue($siteKey));
48
-
49
-
50
- $helper->expects($this->any())
51
- ->method('getSecretKey')
52
- ->will($this->returnValue($secretKey));
53
-
54
-
55
- $helper->expects($this->any())
56
- ->method('getTheme')
57
- ->will($this->returnValue($theme));
58
-
59
- return $helper;
60
- }
61
-
62
- public function test_getRecaptchaScript_returns_empty_string_when_module_disabled()
63
- {
64
- $dataHelper = $this->getMockDataHelper(false);
65
- $this->replaceByMock('helper', 'studioforty9_recaptcha', $dataHelper);
66
-
67
- $expected = '';
68
- $actual = $this->block->getRecaptchaScript();
69
- $this->assertEquals($expected, $actual);
70
- }
71
-
72
- public function test_getRecaptchaScript_returns_script_tag_html_when_module_enabled()
73
- {
74
- $dataHelper = $this->getMockDataHelper(true);
75
- $this->replaceByMock('helper', 'studioforty9_recaptcha', $dataHelper);
76
-
77
- $expected = '<script src="https://www.google.com/recaptcha/api.js"></script>';
78
- $actual = $this->block->getRecaptchaScript();
79
- $this->assertEquals($expected, $actual);
80
- }
81
-
82
- public function test_getRecaptchaHtml_returns_empty_string_when_module_disabled()
83
- {
84
- $dataHelper = $this->getMockDataHelper(false);
85
- $this->replaceByMock('helper', 'studioforty9_recaptcha', $dataHelper);
86
-
87
- $expected = '';
88
- $actual = $this->block->getRecaptchaHtml();
89
- $this->assertEquals($expected, $actual);
90
- }
91
-
92
- public function test_getRecaptchaHtml_returns_expected_html_when_module_enabled_using_light_theme()
93
- {
94
- $dataHelper = $this->getMockDataHelper(true, 'light');
95
- $this->replaceByMock('helper', 'studioforty9_recaptcha', $dataHelper);
96
-
97
- $theme = 'light';
98
- $siteKey = '123456789';
99
- $expected = sprintf('<div class="g-recaptcha" data-theme="%s" data-sitekey="%s"></div>', $theme, $siteKey);
100
- $actual = $this->block->getRecaptchaHtml();
101
- $this->assertEquals($expected, $actual);
102
- }
103
-
104
- public function test_getRecaptchaHtml_returns_expected_html_when_module_enabled_using_dark_theme()
105
- {
106
- $dataHelper = $this->getMockDataHelper(true, 'dark');
107
- $this->replaceByMock('helper', 'studioforty9_recaptcha', $dataHelper);
108
-
109
- $theme = 'dark';
110
- $siteKey = '123456789';
111
- $expected = sprintf('<div class="g-recaptcha" data-theme="%s" data-sitekey="%s"></div>', $theme, $siteKey);
112
- $actual = $this->block->getRecaptchaHtml();
113
- $this->assertEquals($expected, $actual);
114
- }
115
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Studioforty9/Recaptcha/Test/Config/Module.php DELETED
@@ -1,97 +0,0 @@
1
- <?php
2
- /**
3
- * Studioforty9_Recaptcha
4
- *
5
- * @category Studioforty9
6
- * @package Studioforty9_Recaptcha
7
- * @author StudioForty9 <info@studioforty9.com>
8
- * @copyright 2014 StudioForty9 (http://www.studioforty9.com)
9
- * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
- * @version 1.0.0
11
- * @link https://github.com/studioforty9/recaptcha
12
- */
13
-
14
- /**
15
- * Studioforty9_Recaptcha_Test_Config_Module
16
- *
17
- * @category Studioforty9
18
- * @package Studioforty9_Recaptcha
19
- * @subpackage Test
20
- * @author StudioForty9 <info@studioforty9.com>
21
- */
22
- class Studioforty9_Recaptcha_Test_Config_Module extends EcomDev_PHPUnit_Test_Case_Config
23
- {
24
-
25
- public function test_module_is_in_correct_code_pool()
26
- {
27
- $this->assertModuleCodePool('community');
28
- }
29
-
30
-
31
- public function test_module_version_is_correct()
32
- {
33
- $this->assertModuleVersion('1.0.0');
34
- }
35
-
36
-
37
- public function test_block_are_configured()
38
- {
39
- $this->assertBlockAlias('studioforty9_recaptcha/autorender', 'Studioforty9_Recaptcha_Block_Autorender');
40
- }
41
-
42
-
43
- public function test_models_are_configured()
44
- {
45
- $this->assertModelAlias('studioforty9_recaptcha/observer_contacts', 'Studioforty9_Recaptcha_Model_Observer_Contacts');
46
- }
47
-
48
-
49
- public function test_helpers_are_configured()
50
- {
51
- $this->assertHelperAlias('studioforty9_recaptcha/data', 'Studioforty9_Recaptcha_Helper_Data');
52
- $this->assertHelperAlias('studioforty9_recaptcha/request', 'Studioforty9_Recaptcha_Helper_Request');
53
- $this->assertHelperAlias('studioforty9_recaptcha/response', 'Studioforty9_Recaptcha_Helper_Response');
54
- }
55
-
56
-
57
- public function test_access_granted_for_config_acl()
58
- {
59
-
60
- $this->assertConfigNodeValue(
61
- 'adminhtml/acl/resources/admin/children/system/children/config/children/studioforty9_recaptcha/title',
62
- 'ReCaptcha Configuration Settings'
63
- );
64
- }
65
-
66
- public function test_config_has_event_observer_defined()
67
- {
68
- $this->assertEventObserverDefined(
69
- 'frontend',
70
- 'controller_action_predispatch_contacts_index_post',
71
- 'studioforty9_recaptcha/observer_contacts',
72
- 'onContactsPostPreDispatch'
73
- );
74
- }
75
-
76
- /*public function test_config_defaults()
77
- {
78
- $this->assertDefaultConfigValue('google/recaptcha/enabled', '0');
79
- $this->assertDefaultConfigValue('google/recaptcha/site_key', '');
80
- $this->assertDefaultConfigValue('google/recaptcha/secret_key', '');
81
- $this->assertDefaultConfigValue('google/recaptcha/theme', 'light');
82
- }*/
83
-
84
- public function test_layout_updates_are_correct()
85
- {
86
- $this->assertLayoutFileDefined('frontend', 'studioforty9_recaptcha.xml', 'studioforty9_recaptcha');
87
- $this->assertLayoutFileExists('frontend', 'studioforty9_recaptcha.xml', 'default', 'base');
88
- }
89
-
90
- public function test_translate_nodes_are_correct()
91
- {
92
- $this->assertConfigNodeValue(
93
- 'frontend/translate/modules/studioforty9_recaptcha/files/default',
94
- 'Studioforty9_Recaptcha.csv'
95
- );
96
- }
97
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Studioforty9/Recaptcha/Test/Helper/Request.php DELETED
@@ -1,167 +0,0 @@
1
- <?php
2
- /**
3
- * Studioforty9_Recaptcha
4
- *
5
- * @category Studioforty9
6
- * @package Studioforty9_Recaptcha
7
- * @author StudioForty9 <info@studioforty9.com>
8
- * @copyright 2014 StudioForty9 (http://www.studioforty9.com)
9
- * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
- * @version 1.0.0
11
- * @link https://github.com/studioforty9/recaptcha
12
- */
13
-
14
- /**
15
- * Mock_Http_Client
16
- *
17
- * @category Studioforty9
18
- * @package Studioforty9_Recaptcha
19
- * @subpackage Test
20
- * @author StudioForty9 <info@studioforty9.com>
21
- */
22
- class Mock_Http_Client extends Varien_Http_Client
23
- {
24
- protected function _trySetCurlAdapter()
25
- {
26
- $this->setAdapter(new Zend_Http_Client_Adapter_Test());
27
- return $this;
28
- }
29
- }
30
-
31
- /**
32
- * Studioforty9_Recaptcha_Test_Helper_Request
33
- *
34
- * @category Studioforty9
35
- * @package Studioforty9_Recaptcha
36
- * @subpackage Test
37
- * @author StudioForty9 <info@studioforty9.com>
38
- */
39
- class Studioforty9_Recaptcha_Test_Helper_Request extends EcomDev_PHPUnit_Test_Case
40
- {
41
- /** @var Studioforty9_Recaptcha_Helper_Request $helper */
42
- protected $helper;
43
-
44
- /**
45
- * Get a mock response object with the body value already set.
46
- *
47
- * @param string $body
48
- * @return Zend_Http_Response
49
- */
50
- protected function getMockResponse($body)
51
- {
52
- $response = $this->getMockBuilder('Zend_Http_Response')
53
- ->disableOriginalConstructor()
54
- ->setMethods(array('getBody'))
55
- ->getMock();
56
-
57
- $response->expects($this->any())->method('getBody')->will($this->returnValue($body));
58
-
59
- return $response;
60
- }
61
-
62
- /**
63
- * Get a mock request object with the response value already set.
64
- *
65
- * @param string $response
66
- * @return Mock_Http_Client
67
- */
68
- protected function getMockRequest($response)
69
- {
70
- $client = $this->getMockBuilder('Mock_Http_Client')
71
- ->disableOriginalConstructor()
72
- ->setMethods(array('request'))
73
- ->getMock();
74
-
75
- $client->expects($this->any())->method('request')->will($this->returnValue($response));
76
-
77
- return $client;
78
- }
79
-
80
- public function setUp()
81
- {
82
- $this->helper = new Studioforty9_Recaptcha_Helper_Request();
83
- }
84
-
85
- public function test_getHttpClient_returns_expected_object_when_set()
86
- {
87
- $this->helper->setHttpClient(new Mock_Http_Client());
88
- $this->assertInstanceOf('Mock_Http_Client', $this->helper->getHttpClient());
89
- }
90
-
91
- public function test_getHttpClient_returns_expected_object_when_not_set()
92
- {
93
- $this->assertInstanceOf('Varien_Http_Client', $this->helper->getHttpClient());
94
- }
95
-
96
- public function test_verify_with_missing_secret_key()
97
- {
98
- // Create a mock request object and replace the one stored in the registry
99
- Mage::app()->getRequest()->setPost(Studioforty9_Recaptcha_Helper_Request::REQUEST_RESPONSE, 'test');
100
- $mockResponse = $this->getMockResponse('{"success":false,"error-codes": ["missing-input-secret"]}');
101
- $mockRequest = $this->getMockRequest($mockResponse);
102
-
103
- // Create a mock client object and set it on the object
104
- $this->helper->setHttpClient($mockRequest);
105
- $response = $this->helper->verify();
106
-
107
- $this->assertInstanceOf('Studioforty9_Recaptcha_Helper_Response', $response);
108
- $this->assertFalse($response->isSuccess());
109
- $this->assertTrue($response->hasErrors());
110
- $errors = $response->getErrors();
111
- $this->assertEquals('The secret parameter is missing.', $errors[0]);
112
- }
113
-
114
- public function test_verify_with_invalid_secret_key()
115
- {
116
- // Create a mock request object and replace the one stored in the registry
117
- Mage::app()->getRequest()->setPost(Studioforty9_Recaptcha_Helper_Request::REQUEST_RESPONSE, 'test');
118
- $mockResponse = $this->getMockResponse('{"success":false,"error-codes": ["invalid-input-secret"]}');
119
- $mockRequest = $this->getMockRequest($mockResponse);
120
-
121
- // Create a mock client object and set it on the object
122
- $this->helper->setHttpClient($mockRequest);
123
- $response = $this->helper->verify();
124
-
125
- $this->assertInstanceOf('Studioforty9_Recaptcha_Helper_Response', $response);
126
- $this->assertFalse($response->isSuccess());
127
- $this->assertTrue($response->hasErrors());
128
- $errors = $response->getErrors();
129
- $this->assertEquals('The secret parameter is invalid or malformed.', $errors[0]);
130
- }
131
-
132
- public function test_verify_with_missing_input_response()
133
- {
134
- // Create a mock request object and replace the one stored in the registry
135
- Mage::app()->getRequest()->setPost(Studioforty9_Recaptcha_Helper_Request::REQUEST_RESPONSE, 'test');
136
- $mockResponse = $this->getMockResponse('{"success":false,"error-codes": ["missing-input-response"]}');
137
- $mockRequest = $this->getMockRequest($mockResponse);
138
-
139
- // Create a mock client object and set it on the object
140
- $this->helper->setHttpClient($mockRequest);
141
- $response = $this->helper->verify();
142
-
143
- $this->assertInstanceOf('Studioforty9_Recaptcha_Helper_Response', $response);
144
- $this->assertFalse($response->isSuccess());
145
- $this->assertTrue($response->hasErrors());
146
- $errors = $response->getErrors();
147
- $this->assertEquals('The response parameter is missing.', $errors[0]);
148
- }
149
-
150
- public function test_verify_with_invalid_input_response()
151
- {
152
- // Create a mock request object and replace the one stored in the registry
153
- Mage::app()->getRequest()->setPost(Studioforty9_Recaptcha_Helper_Request::REQUEST_RESPONSE, 'test');
154
- $mockResponse = $this->getMockResponse('{"success":false,"error-codes": ["invalid-input-response"]}');
155
- $mockRequest = $this->getMockRequest($mockResponse);
156
-
157
- // Create a mock client object and set it on the object
158
- $this->helper->setHttpClient($mockRequest);
159
- $response = $this->helper->verify();
160
-
161
- $this->assertInstanceOf('Studioforty9_Recaptcha_Helper_Response', $response);
162
- $this->assertFalse($response->isSuccess());
163
- $this->assertTrue($response->hasErrors());
164
- $errors = $response->getErrors();
165
- $this->assertEquals('The response parameter is invalid or malformed.', $errors[0]);
166
- }
167
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Studioforty9/Recaptcha/Test/Helper/Response.php DELETED
@@ -1,105 +0,0 @@
1
- <?php
2
- /**
3
- * Studioforty9_Recaptcha
4
- *
5
- * @category Studioforty9
6
- * @package Studioforty9_Recaptcha
7
- * @author StudioForty9 <info@studioforty9.com>
8
- * @copyright 2014 StudioForty9 (http://www.studioforty9.com)
9
- * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
- * @version 1.0.0
11
- * @link https://github.com/studioforty9/recaptcha
12
- */
13
-
14
- /**
15
- * Studioforty9_Recaptcha_Test_Helper_Response
16
- *
17
- * @category Studioforty9
18
- * @package Studioforty9_Recaptcha
19
- * @subpackage Test
20
- * @author StudioForty9 <info@studioforty9.com>
21
- */
22
- class Studioforty9_Recaptcha_Test_Helper_Response extends EcomDev_PHPUnit_Test_Case
23
- {
24
- /** @var Studioforty9_Recaptcha_Helper_Response $helper */
25
- protected $helper;
26
-
27
- public function test_can_construct_with_success_true()
28
- {
29
- $helper = new Studioforty9_Recaptcha_Helper_Response(true);
30
- $this->assertTrue($helper->isSuccess());
31
- }
32
-
33
- public function test_can_construct_with_success_false()
34
- {
35
- $helper = new Studioforty9_Recaptcha_Helper_Response(false);
36
- $this->assertTrue($helper->isFailure());
37
- }
38
-
39
- public function test_error_code_strings_are_correct()
40
- {
41
- $this->assertEquals('missing-input-secret', Studioforty9_Recaptcha_Helper_Response::MISSING_INPUT_SECRET);
42
- $this->assertEquals('invalid-input-secret', Studioforty9_Recaptcha_Helper_Response::INVALID_INPUT_SECRET);
43
- $this->assertEquals('missing-input-response', Studioforty9_Recaptcha_Helper_Response::MISSING_INPUT_RESPONSE);
44
- $this->assertEquals('invalid-input-response', Studioforty9_Recaptcha_Helper_Response::INVALID_INPUT_RESPONSE);
45
- }
46
-
47
- public function test_error_descriptions_are_correct()
48
- {
49
- $helper = new Studioforty9_Recaptcha_Helper_Response(false);
50
-
51
- $this->assertEquals(
52
- 'The secret parameter is missing.',
53
- $helper->getErrorDescription(Studioforty9_Recaptcha_Helper_Response::MISSING_INPUT_SECRET)
54
- );
55
- $this->assertEquals(
56
- 'The secret parameter is invalid or malformed.',
57
- $helper->getErrorDescription(Studioforty9_Recaptcha_Helper_Response::INVALID_INPUT_SECRET)
58
- );
59
- $this->assertEquals(
60
- 'The response parameter is missing.',
61
- $helper->getErrorDescription(Studioforty9_Recaptcha_Helper_Response::MISSING_INPUT_RESPONSE)
62
- );
63
- $this->assertEquals(
64
- 'The response parameter is invalid or malformed.',
65
- $helper->getErrorDescription(Studioforty9_Recaptcha_Helper_Response::INVALID_INPUT_RESPONSE)
66
- );
67
- }
68
-
69
- public function test_getErrorDescription_returns_unknown_error_string_when_something_unknown_is_passed_in()
70
- {
71
- $helper = new Studioforty9_Recaptcha_Helper_Response(false);
72
- $this->assertEquals(
73
- 'Unknown error.',
74
- $helper->getErrorDescription('not a real error')
75
- );
76
- }
77
-
78
- public function test_hasErrors_returns_false_when_constructed_with_no_errors()
79
- {
80
- $helper = new Studioforty9_Recaptcha_Helper_Response(false);
81
- $this->assertFalse($helper->hasErrors());
82
- }
83
-
84
- public function test_hasErrors_returns_true_when_constructed_with_errors()
85
- {
86
- $helper = new Studioforty9_Recaptcha_Helper_Response(false, array(Studioforty9_Recaptcha_Helper_Response::MISSING_INPUT_RESPONSE));
87
- $this->assertTrue($helper->hasErrors());
88
- }
89
-
90
- public function test_getErrors_returns_expected_descriptions()
91
- {
92
- $errorCodes = array(
93
- Studioforty9_Recaptcha_Helper_Response::MISSING_INPUT_SECRET,
94
- Studioforty9_Recaptcha_Helper_Response::INVALID_INPUT_SECRET,
95
- Studioforty9_Recaptcha_Helper_Response::MISSING_INPUT_RESPONSE,
96
- Studioforty9_Recaptcha_Helper_Response::INVALID_INPUT_RESPONSE
97
- );
98
- $helper = new Studioforty9_Recaptcha_Helper_Response(false, $errorCodes);
99
- $errors = $helper->getErrors();
100
-
101
- $this->assertCount(4, $errors);
102
- $this->assertInternalType('array', $errors);
103
- $this->assertEquals($errors[0], 'The secret parameter is missing.');
104
- }
105
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Studioforty9/Recaptcha/Test/Model/Observer/Contacts.php DELETED
@@ -1,268 +0,0 @@
1
- <?php
2
- /**
3
- * Studioforty9_Recaptcha
4
- *
5
- * @category Studioforty9
6
- * @package Studioforty9_Recaptcha
7
- * @author StudioForty9 <info@studioforty9.com>
8
- * @copyright 2014 StudioForty9 (http://www.studioforty9.com)
9
- * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
- * @version 1.0.0
11
- * @link https://github.com/studioforty9/recaptcha
12
- */
13
-
14
- /**
15
- * Studioforty9_Recaptcha_Test_Model_Observer_Contacts
16
- *
17
- * @category Studioforty9
18
- * @package Studioforty9_Recaptcha
19
- * @subpackage Test
20
- * @author StudioForty9 <info@studioforty9.com>
21
- */
22
- class Studioforty9_Recaptcha_Test_Model_Observer_Contacts extends EcomDev_PHPUnit_Test_Case
23
- {
24
- /** @var Studioforty9_Recaptcha_Model_Observer_Contacts $observer */
25
- protected $observer;
26
-
27
- /** @var Mage_Core_Model_Session $session */
28
- protected $session;
29
-
30
- public function setUp()
31
- {
32
- $this->session = $this->replaceSession('core/session');
33
- $this->observer = new Studioforty9_Recaptcha_Model_Observer_Contacts();
34
- }
35
-
36
- public function test_onContactsPostPreDispatch_returns_observer_when_module_disabled()
37
- {
38
- $dataHelper = $this->getMockDataHelper();
39
- $dataHelper->expects($this->once())->method('isEnabled')->will($this->returnValue(false));
40
- $this->replaceByMock('helper', 'studioforty9_recaptcha', $dataHelper);
41
-
42
- $observer = $this->getMockObserver();
43
- $result = $this->observer->onContactsPostPreDispatch($observer);
44
-
45
- $this->assertInstanceOf('Varien_Event_Observer', $result);
46
- }
47
-
48
- public function test_onContactsPostPreDispatch_returns_observer_on_verify_success_when_module_enabled()
49
- {
50
- // Expect studioforty9_recaptcha::isEnabled to be called once
51
- $dataHelper = $this->getMockDataHelper();
52
- $dataHelper->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
53
- $this->replaceByMock('helper', 'studioforty9_recaptcha', $dataHelper);
54
-
55
- $responseHelper = new Studioforty9_Recaptcha_Helper_Response(true);
56
-
57
- // Expect verify to be called once and return $responseHelper
58
- $requestHelper = $this->getMockRequestHelper();
59
- $requestHelper->expects($this->once())->method('verify')->will($this->returnValue($responseHelper));
60
- $this->replaceByMock('helper', 'studioforty9_recaptcha/request', $requestHelper);
61
-
62
- // Mock the controller object
63
- $controller = $this->getMockController();
64
- // Mock the event object
65
- // Expect getControllerAction to be called once and return $controller
66
- $event = $this->getMockEvent($controller);
67
- // Mock the observer object
68
- $observer = $this->getMockObserver();
69
- // Expect getEvent to be called once and return the event object
70
- $observer->expects($this->once())->method('getEvent')->will($this->returnValue($event));
71
-
72
- // Call the onContactsPostPreDispatch method
73
- $result = $this->observer->onContactsPostPreDispatch($observer);
74
-
75
- $this->assertInstanceOf('Varien_Event_Observer', $result);
76
- }
77
-
78
- public function test_onContactsPostPreDispatch_returns_controller_on_verify_failed_with_module_enabled()
79
- {
80
- // Mock the data helper
81
- $dataHelper = $this->getMockDataHelper();
82
- // Expect isEnabled to called once and return true
83
- $dataHelper->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
84
- $this->replaceByMock('helper', 'studioforty9_recaptcha', $dataHelper);
85
-
86
- // Setup the expected response
87
- $responseHelper = new Studioforty9_Recaptcha_Helper_Response(false, array('missing-input-response'));
88
-
89
- // Mock the request helper
90
- $requestHelper = $this->getMockRequestHelper();
91
- // Expect verify to be called once and return the $responseHelper
92
- $requestHelper->expects($this->once())->method('verify')->will($this->returnValue($responseHelper));
93
- $this->replaceByMock('helper', 'studioforty9_recaptcha/request', $requestHelper);
94
-
95
- // Mock the response object
96
- $response = $this->getMockResponse();
97
-
98
- // Expect setRedirect to be called once
99
- // It should set the redirect url to the base url + /contacts
100
- // And return the response object
101
- $response->expects($this->once())
102
- ->method('setRedirect')
103
- ->with($this->equalTo(Mage::getBaseUrl() . '/contacts'))
104
- ->will($this->returnSelf());
105
-
106
- // Expect sendResponse to be called once
107
- // And return the response object
108
- $response->expects($this->once())
109
- ->method('sendResponse')
110
- ->will($this->returnSelf());
111
-
112
- // Mock the request object
113
- $request = $this->getMockRequest();
114
-
115
- // Expect setDispatched to be called once
116
- // It should set the value to true
117
- // And return the request object
118
- $request->expects($this->once())
119
- ->method('setDispatched')
120
- ->with($this->equalTo(true))
121
- ->will($this->returnSelf());
122
-
123
- // Expect getBaseUrl to be called once
124
- // And return the base url of the website
125
- $request->expects($this->once())
126
- ->method('getBaseUrl')
127
- ->will($this->returnValue(Mage::getBaseUrl()));
128
-
129
- // Mock the controller object
130
- $controller = $this->getMockController();
131
-
132
- // Expect getResponse to be called once
133
- // And return the response object
134
- $controller->expects($this->once())
135
- ->method('getResponse')
136
- ->will($this->returnValue($response));
137
-
138
- // Expect getRequest to be called twice
139
- // 1. For getBaseUrl
140
- // 2. For setDispatched
141
- // And return the request object
142
- $controller->expects($this->exactly(2))
143
- ->method('getRequest')
144
- ->will($this->returnValue($request));
145
-
146
- // Expect setFlag to be called once
147
- // It should set the following parameters:
148
- // 1. $action : '' (empty string)
149
- // 2. $flag : Mage_Core_Controller_Front_Action::FLAG_NO_DISPATCH ('no-dispatch')
150
- // 3. $value : true
151
- // And return the controller object
152
- $controller->expects($this->once())
153
- ->method('setFlag')
154
- ->with(
155
- $this->equalTo(''),
156
- $this->equalTo(Mage_Core_Controller_Front_Action::FLAG_NO_DISPATCH),
157
- $this->equalTo(true)
158
- )
159
- ->will($this->returnSelf());
160
-
161
- // Mock the event object
162
- $event = $this->getMockEvent($controller);
163
-
164
- // Mock the observer object
165
- $observer = $this->getMockObserver();
166
-
167
- // Expect getEvent to be called once and return the event object
168
- $observer->expects($this->once())->method('getEvent')->will($this->returnValue($event));
169
-
170
- // Run the observer
171
- $result = $this->observer->onContactsPostPreDispatch($observer);
172
-
173
- // If all went to plan, we should have our controller back
174
- $this->assertInstanceOf('Mage_Core_Controller_Front_Action', $result);
175
-
176
- // Does the session have a new message?
177
- $this->assertEquals(
178
- 'There was an error with the recaptcha code, please try again.',
179
- $this->session->getMessages()->getLastAddedMessage()->getCode()
180
- );
181
- }
182
-
183
- /* ----- MOCK OBJECTS ----- */
184
-
185
- protected function getMockResponse()
186
- {
187
- // Mock Response
188
- $response = $this->getMockBuilder('Zend_Controller_Response_Abstract')
189
- ->disableOriginalConstructor()
190
- ->setMethods(array('setRedirect', 'sendResponse'))
191
- ->getMock();
192
-
193
- return $response;
194
- }
195
-
196
- protected function getMockRequest()
197
- {
198
- $request = $this->getMockBuilder('Zend_Controller_Request_Abstract')
199
- ->disableOriginalConstructor()
200
- ->setMethods(array('setDispatched', 'getBaseUrl'))
201
- ->getMock();
202
-
203
- return $request;
204
- }
205
-
206
- protected function getMockController()
207
- {
208
- // Mock Controller
209
- $controller = $this->getMockBuilder('Mage_Core_Controller_Front_Action')
210
- ->disableOriginalConstructor()
211
- ->setMethods(array('getResponse', 'getRequest', 'setFlag'))
212
- ->getMock();
213
-
214
- return $controller;
215
- }
216
-
217
- protected function getMockObserver()
218
- {
219
- $observer = $this->getMockBuilder('Varien_Event_Observer')
220
- ->disableOriginalConstructor()
221
- ->setMethods(array('getEvent'))
222
- ->getMock();
223
-
224
- return $observer;
225
- }
226
-
227
- protected function getMockDataHelper()
228
- {
229
- $helper = $this->getHelperMock('studioforty9_recaptcha', array(
230
- 'isEnabled', 'getSiteKey', 'getSecretKey', 'getTheme'
231
- ), false, array(), null, false);
232
-
233
- return $helper;
234
- }
235
-
236
- protected function getMockRequestHelper()
237
- {
238
- $helper = $this->getHelperMock('studioforty9_recaptcha/request', array('verify'), false, array(), null, false);
239
-
240
- return $helper;
241
- }
242
-
243
- protected function getMockEvent($controller)
244
- {
245
- $event = $this->getMockBuilder('Varien_Event')
246
- ->disableOriginalConstructor()
247
- ->setMethods(array('getControllerAction'))
248
- ->getMock();
249
-
250
- $event->expects($this->once())
251
- ->method('getControllerAction')
252
- ->will($this->returnValue($controller));
253
-
254
- return $event;
255
- }
256
-
257
- protected function replaceSession($type)
258
- {
259
- $session = $this->getModelMockBuilder($type)
260
- ->disableOriginalConstructor()
261
- ->setMethods(null)
262
- ->getMock();
263
-
264
- $this->replaceByMock('singleton', $type, $session);
265
-
266
- return $session;
267
- }
268
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Studioforty9/Recaptcha/Test/Model/Source/Theme.php DELETED
@@ -1,42 +0,0 @@
1
- <?php
2
- /**
3
- * Studioforty9_Recaptcha
4
- *
5
- * @category Studioforty9
6
- * @package Studioforty9_Recaptcha
7
- * @author StudioForty9 <info@studioforty9.com>
8
- * @copyright 2014 StudioForty9 (http://www.studioforty9.com)
9
- * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
- * @version 1.0.0
11
- * @link https://github.com/studioforty9/recaptcha
12
- */
13
-
14
- /**
15
- * Studioforty9_Recaptcha_Test_Model_Source_Theme
16
- *
17
- * @category Studioforty9
18
- * @package Studioforty9_Recaptcha
19
- * @subpackage Test
20
- * @author StudioForty9 <info@studioforty9.com>
21
- */
22
- class Studioforty9_Recaptcha_Test_Model_Source_Theme extends EcomDev_PHPUnit_Test_Case
23
- {
24
- /** @var Studioforty9_Recaptcha_Model_Source_Theme $observer */
25
- protected $model;
26
-
27
- public function setUp()
28
- {
29
- $this->model = new Studioforty9_Recaptcha_Model_Source_Theme();
30
- }
31
-
32
- public function test_toOptionArray_returns_expected_array()
33
- {
34
- $options = $this->model->toOptionArray();
35
-
36
- $this->assertArrayHasKey('light', $options);
37
- $this->assertArrayHasKey('dark', $options);
38
-
39
- $this->assertEquals('Light', $options['light']);
40
- $this->assertEquals('Dark', $options['dark']);
41
- }
42
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Studioforty9/Recaptcha/etc/config.xml CHANGED
@@ -6,16 +6,16 @@
6
  * @category Studioforty9
7
  * @package Studioforty9_Recaptcha
8
  * @author StudioForty9 <info@studioforty9.com>
9
- * @copyright 2014 StudioForty9 (http://www.studioforty9.com)
10
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
11
- * @version 1.0.0
12
  * @link https://github.com/studioforty9/recaptcha
13
  */
14
  -->
15
  <config>
16
  <modules>
17
  <Studioforty9_Recaptcha>
18
- <version>1.0.0</version>
19
  </Studioforty9_Recaptcha>
20
  </modules>
21
  <global>
@@ -56,11 +56,35 @@
56
  <controller_action_predispatch_contacts_index_post>
57
  <observers>
58
  <studioforty9_recaptcha>
59
- <class>studioforty9_recaptcha/observer_contacts</class>
60
- <method>onContactsPostPreDispatch</method>
61
  </studioforty9_recaptcha>
62
  </observers>
63
  </controller_action_predispatch_contacts_index_post>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  </events>
65
  </frontend>
66
  <adminhtml>
@@ -92,6 +116,10 @@
92
  <google>
93
  <recaptcha>
94
  <enabled>0</enabled>
 
 
 
 
95
  <site_key></site_key>
96
  <secret_key></secret_key>
97
  <theme>light</theme>
6
  * @category Studioforty9
7
  * @package Studioforty9_Recaptcha
8
  * @author StudioForty9 <info@studioforty9.com>
9
+ * @copyright 2015 StudioForty9 (http://www.studioforty9.com)
10
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
11
+ * @version 1.1.0
12
  * @link https://github.com/studioforty9/recaptcha
13
  */
14
  -->
15
  <config>
16
  <modules>
17
  <Studioforty9_Recaptcha>
18
+ <version>1.1.0</version>
19
  </Studioforty9_Recaptcha>
20
  </modules>
21
  <global>
56
  <controller_action_predispatch_contacts_index_post>
57
  <observers>
58
  <studioforty9_recaptcha>
59
+ <class>studioforty9_recaptcha/observer</class>
60
+ <method>onPostPreDispatch</method>
61
  </studioforty9_recaptcha>
62
  </observers>
63
  </controller_action_predispatch_contacts_index_post>
64
+ <controller_action_predispatch_review_product_post>
65
+ <observers>
66
+ <studioforty9_recaptcha>
67
+ <class>studioforty9_recaptcha/observer</class>
68
+ <method>onPostPreDispatch</method>
69
+ </studioforty9_recaptcha>
70
+ </observers>
71
+ </controller_action_predispatch_review_product_post>
72
+ <controller_action_predispatch_customer_account_createpost>
73
+ <observers>
74
+ <studioforty9_recaptcha>
75
+ <class>studioforty9_recaptcha/observer</class>
76
+ <method>onPostPreDispatch</method>
77
+ </studioforty9_recaptcha>
78
+ </observers>
79
+ </controller_action_predispatch_customer_account_createpost>
80
+ <controller_action_predispatch_sendfriend_product_sendmail>
81
+ <observers>
82
+ <studioforty9_recaptcha>
83
+ <class>studioforty9_recaptcha/observer</class>
84
+ <method>onPostPreDispatch</method>
85
+ </studioforty9_recaptcha>
86
+ </observers>
87
+ </controller_action_predispatch_sendfriend_product_sendmail>
88
  </events>
89
  </frontend>
90
  <adminhtml>
116
  <google>
117
  <recaptcha>
118
  <enabled>0</enabled>
119
+ <enabled_contacts>0</enabled_contacts>
120
+ <enabled_reviews>0</enabled_reviews>
121
+ <enabled_sendfriend>0</enabled_sendfriend>
122
+ <enabled_customer_registration>0</enabled_customer_registration>
123
  <site_key></site_key>
124
  <secret_key></secret_key>
125
  <theme>light</theme>
app/code/community/Studioforty9/Recaptcha/etc/system.xml CHANGED
@@ -6,9 +6,9 @@
6
  * @category Studioforty9
7
  * @package Studioforty9_Recaptcha
8
  * @author StudioForty9 <info@studioforty9.com>
9
- * @copyright 2014 StudioForty9 (http://www.studioforty9.com)
10
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
11
- * @version 1.0.0
12
  * @link https://github.com/studioforty9/recaptcha
13
  */
14
  -->
@@ -33,6 +33,42 @@
33
  <show_in_website>1</show_in_website>
34
  <show_in_store>1</show_in_store>
35
  </enabled>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  <site_key translate="label">
37
  <label>Site Key</label>
38
  <frontend_type>text</frontend_type>
6
  * @category Studioforty9
7
  * @package Studioforty9_Recaptcha
8
  * @author StudioForty9 <info@studioforty9.com>
9
+ * @copyright 2015 StudioForty9 (http://www.studioforty9.com)
10
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
11
+ * @version 1.1.0
12
  * @link https://github.com/studioforty9/recaptcha
13
  */
14
  -->
33
  <show_in_website>1</show_in_website>
34
  <show_in_store>1</show_in_store>
35
  </enabled>
36
+ <enabled_contacts translate="label">
37
+ <label>Enabled on Contact Form</label>
38
+ <frontend_type>select</frontend_type>
39
+ <source_model>adminhtml/system_config_source_yesno</source_model>
40
+ <sort_order>11</sort_order>
41
+ <show_in_default>1</show_in_default>
42
+ <show_in_website>1</show_in_website>
43
+ <show_in_store>1</show_in_store>
44
+ </enabled_contacts>
45
+ <enabled_reviews translate="label">
46
+ <label>Enabled on Product Review Form</label>
47
+ <frontend_type>select</frontend_type>
48
+ <source_model>adminhtml/system_config_source_yesno</source_model>
49
+ <sort_order>12</sort_order>
50
+ <show_in_default>1</show_in_default>
51
+ <show_in_website>1</show_in_website>
52
+ <show_in_store>1</show_in_store>
53
+ </enabled_reviews>
54
+ <enabled_sendfriend translate="label">
55
+ <label>Enabled on Product Send to Friend Form</label>
56
+ <frontend_type>select</frontend_type>
57
+ <source_model>adminhtml/system_config_source_yesno</source_model>
58
+ <sort_order>13</sort_order>
59
+ <show_in_default>1</show_in_default>
60
+ <show_in_website>1</show_in_website>
61
+ <show_in_store>1</show_in_store>
62
+ </enabled_sendfriend>
63
+ <enabled_customer_registration translate="label">
64
+ <label>Enabled on Customer Registration Form</label>
65
+ <frontend_type>select</frontend_type>
66
+ <source_model>adminhtml/system_config_source_yesno</source_model>
67
+ <sort_order>14</sort_order>
68
+ <show_in_default>1</show_in_default>
69
+ <show_in_website>1</show_in_website>
70
+ <show_in_store>1</show_in_store>
71
+ </enabled_customer_registration>
72
  <site_key translate="label">
73
  <label>Site Key</label>
74
  <frontend_type>text</frontend_type>
app/design/frontend/base/default/layout/studioforty9_recaptcha.xml CHANGED
@@ -6,9 +6,9 @@
6
  * @category Studioforty9
7
  * @package Studioforty9_Recaptcha
8
  * @author StudioForty9 <info@studioforty9.com>
9
- * @copyright 2014 StudioForty9 (http://www.studioforty9.com)
10
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
11
- * @version 1.0.0
12
  * @link https://github.com/studioforty9/recaptcha
13
  */
14
  -->
@@ -16,8 +16,26 @@
16
 
17
  <contacts_index_index>
18
  <reference name="contactForm">
19
- <block type="studioforty9_recaptcha/autorender" name="studioforty9.recaptcha.autorender" template="studioforty9/recaptcha/autorender.phtml"/>
20
  </reference>
21
  </contacts_index_index>
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  </layout>
6
  * @category Studioforty9
7
  * @package Studioforty9_Recaptcha
8
  * @author StudioForty9 <info@studioforty9.com>
9
+ * @copyright 2015 StudioForty9 (http://www.studioforty9.com)
10
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
11
+ * @version 1.1.0
12
  * @link https://github.com/studioforty9/recaptcha
13
  */
14
  -->
16
 
17
  <contacts_index_index>
18
  <reference name="contactForm">
19
+ <block type="studioforty9_recaptcha/explicit" name="studioforty9.recaptcha.explicit" template="studioforty9/recaptcha/explicit.phtml"/>
20
  </reference>
21
  </contacts_index_index>
22
 
23
+ <review_product_list>
24
+ <reference name="product.review.form">
25
+ <block type="studioforty9_recaptcha/explicit" name="studioforty9.recaptcha.explicit" template="studioforty9/recaptcha/explicit.phtml"/>
26
+ </reference>
27
+ </review_product_list>
28
+
29
+ <customer_account_create>
30
+ <reference name="customer_form_register">
31
+ <block type="studioforty9_recaptcha/explicit" name="studioforty9.recaptcha.explicit" template="studioforty9/recaptcha/explicit.phtml"/>
32
+ </reference>
33
+ </customer_account_create>
34
+
35
+ <sendfriend_product_send>
36
+ <reference name="sendfriend.send">
37
+ <block type="studioforty9_recaptcha/explicit" name="studioforty9.recaptcha.explicit" template="studioforty9/recaptcha/explicit.phtml"/>
38
+ </reference>
39
+ </sendfriend_product_send>
40
+
41
  </layout>
app/design/frontend/base/default/template/studioforty9/recaptcha/autorender.phtml CHANGED
@@ -5,14 +5,17 @@
5
  * @category Studioforty9
6
  * @package Studioforty9_Recaptcha
7
  * @author StudioForty9 <info@studioforty9.com>
8
- * @copyright 2014 StudioForty9 (http://www.studioforty9.com)
9
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
- * @version 1.0.0
11
  * @link https://github.com/studioforty9/recaptcha
12
  * @see Studioforty9_Recaptcha_Block_Autorender
13
  */
14
  ?>
 
15
  <div class="recaptcha">
16
  <?php echo $this->getRecaptchaHtml(); ?>
17
  <?php echo $this->getRecaptchaScript(); ?>
 
18
  </div>
 
5
  * @category Studioforty9
6
  * @package Studioforty9_Recaptcha
7
  * @author StudioForty9 <info@studioforty9.com>
8
+ * @copyright 2015 StudioForty9 (http://www.studioforty9.com)
9
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
+ * @version 1.1.0
11
  * @link https://github.com/studioforty9/recaptcha
12
  * @see Studioforty9_Recaptcha_Block_Autorender
13
  */
14
  ?>
15
+ <?php if ($this->isAllowed($this->getRequest()->getRouteName())): ?>
16
  <div class="recaptcha">
17
  <?php echo $this->getRecaptchaHtml(); ?>
18
  <?php echo $this->getRecaptchaScript(); ?>
19
+
20
  </div>
21
+ <?php endif; ?>
app/design/frontend/base/default/template/studioforty9/recaptcha/explicit.phtml ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Studioforty9_Recaptcha
4
+ *
5
+ * @category Studioforty9
6
+ * @package Studioforty9_Recaptcha
7
+ * @author StudioForty9 <info@studioforty9.com>
8
+ * @copyright 2015 StudioForty9 (http://www.studioforty9.com)
9
+ * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
+ * @version 1.1.0
11
+ * @link https://github.com/studioforty9/recaptcha
12
+ * @see Studioforty9_Recaptcha_Block_Explicit
13
+ */
14
+ ?>
15
+ <?php if ($this->isAllowed($this->getRequest()->getRouteName())): ?>
16
+ <div class="recaptcha" style="overflow:hidden;position:relative;">
17
+ <input type="checkbox" id="recaptcha-verification-1" name="recaptcha-verification-1" value="" class="hide required-entry" style="visibility:hidden;position:absolute;left:-1000000px" />
18
+ <div id="recaptcha-1"></div>
19
+ <script type="text/javascript">
20
+ var onloadCallback = function() {
21
+ grecaptcha.render('recaptcha-1', {
22
+ 'sitekey': "<?php echo $this->getSiteKey(); ?>",
23
+ 'theme': "<?php echo $this->getTheme(); ?>",
24
+ 'callback': function(response) {
25
+ console.log(response);
26
+ $('recaptcha-verification-1').writeAttribute('value', 'checked');
27
+ $('recaptcha-verification-1').checked = true;
28
+ }
29
+ });
30
+ };
31
+ </script>
32
+ <?php echo $this->getRecaptchaScript(); ?>
33
+ </div>
34
+ <?php endif; ?>
app/design/frontend/base/default/template/studioforty9/recaptcha/samples/base/contacts/form.phtml ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
28
+ <div class="page-title">
29
+ <h1><?php echo Mage::helper('contacts')->__('Contact Us') ?></h1>
30
+ </div>
31
+ <form action="<?php echo $this->getFormAction(); ?>" id="contactForm" method="post">
32
+ <div class="fieldset">
33
+ <h2 class="legend"><?php echo Mage::helper('contacts')->__('Contact Information') ?></h2>
34
+ <ul class="form-list">
35
+ <li class="fields">
36
+ <div class="field">
37
+ <label for="name" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Name') ?></label>
38
+ <div class="input-box">
39
+ <input name="name" id="name" title="<?php echo Mage::helper('contacts')->__('Name') ?>" value="<?php echo $this->htmlEscape($this->helper('contacts')->getUserName()) ?>" class="input-text required-entry" type="text" />
40
+ </div>
41
+ </div>
42
+ <div class="field">
43
+ <label for="email" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Email') ?></label>
44
+ <div class="input-box">
45
+ <input name="email" id="email" title="<?php echo Mage::helper('contacts')->__('Email') ?>" value="<?php echo $this->htmlEscape($this->helper('contacts')->getUserEmail()) ?>" class="input-text required-entry validate-email" type="text" />
46
+ </div>
47
+ </div>
48
+ </li>
49
+ <li>
50
+ <label for="telephone"><?php echo Mage::helper('contacts')->__('Telephone') ?></label>
51
+ <div class="input-box">
52
+ <input name="telephone" id="telephone" title="<?php echo Mage::helper('contacts')->__('Telephone') ?>" value="" class="input-text" type="text" />
53
+ </div>
54
+ </li>
55
+ <li class="wide">
56
+ <label for="comment" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Comment') ?></label>
57
+ <div class="input-box">
58
+ <textarea name="comment" id="comment" title="<?php echo Mage::helper('contacts')->__('Comment') ?>" class="required-entry input-text" cols="5" rows="3"></textarea>
59
+ </div>
60
+ </li>
61
+ </ul>
62
+ </div>
63
+ <?php echo $this->getChildHtml('studioforty9.recaptcha.explicit'); ?>
64
+ <div class="buttons-set">
65
+ <p class="required"><?php echo Mage::helper('contacts')->__('* Required Fields') ?></p>
66
+ <input type="text" name="hideit" id="hideit" value="" style="display:none !important;" />
67
+ <button type="submit" title="<?php echo Mage::helper('contacts')->__('Submit') ?>" class="button"><span><span><?php echo Mage::helper('contacts')->__('Submit') ?></span></span></button>
68
+ </div>
69
+ </form>
70
+ <script type="text/javascript">
71
+ //<![CDATA[
72
+ var contactForm = new VarienForm('contactForm', true);
73
+ //]]>
74
+ </script>
app/design/frontend/base/default/template/studioforty9/recaptcha/samples/base/persistent/customer/form/register.phtml ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php
28
+ /**
29
+ * Create account form template
30
+ *
31
+ * @see app/design/frontend/base/default/template/customer/form/register.phtml
32
+ */
33
+ /** @var $this Mage_Customer_Block_Form_Register */
34
+ ?>
35
+ <div class="account-create">
36
+ <div class="page-title">
37
+ <h1><?php echo $this->__('Create an Account') ?></h1>
38
+ </div>
39
+ <?php echo $this->getChildHtml('form_fields_before')?>
40
+ <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
41
+ <form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="form-validate">
42
+ <div class="fieldset">
43
+ <input type="hidden" name="success_url" value="<?php echo $this->getSuccessUrl() ?>" />
44
+ <input type="hidden" name="error_url" value="<?php echo $this->getErrorUrl() ?>" />
45
+ <h2 class="legend"><?php echo $this->__('Personal Information') ?></h2>
46
+ <ul class="form-list">
47
+ <li class="fields">
48
+ <?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>
49
+ </li>
50
+ <li>
51
+ <label for="email_address" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
52
+ <div class="input-box">
53
+ <input type="text" name="email" id="email_address" value="<?php echo $this->escapeHtml($this->getFormData()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="input-text validate-email required-entry" />
54
+ </div>
55
+ </li>
56
+ <?php if ($this->isNewsletterEnabled()): ?>
57
+ <li class="control">
58
+ <div class="input-box">
59
+ <input type="checkbox" name="is_subscribed" title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" id="is_subscribed"<?php if($this->getFormData()->getIsSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox" />
60
+ </div>
61
+ <label for="is_subscribed"><?php echo $this->__('Sign Up for Newsletter') ?></label>
62
+ </li>
63
+ <?php endif ?>
64
+ <?php $_dob = $this->getLayout()->createBlock('customer/widget_dob') ?>
65
+ <?php if ($_dob->isEnabled()): ?>
66
+ <li><?php echo $_dob->setDate($this->getFormData()->getDob())->toHtml() ?></li>
67
+ <?php endif ?>
68
+ <?php $_taxvat = $this->getLayout()->createBlock('customer/widget_taxvat') ?>
69
+ <?php if ($_taxvat->isEnabled()): ?>
70
+ <li><?php echo $_taxvat->setTaxvat($this->getFormData()->getTaxvat())->toHtml() ?></li>
71
+ <?php endif ?>
72
+ <?php $_gender = $this->getLayout()->createBlock('customer/widget_gender') ?>
73
+ <?php if ($_gender->isEnabled()): ?>
74
+ <li><?php echo $_gender->setGender($this->getFormData()->getGender())->toHtml() ?></li>
75
+ <?php endif ?>
76
+ </ul>
77
+ </div>
78
+ <?php if($this->getShowAddressFields()): ?>
79
+ <div class="fieldset">
80
+ <input type="hidden" name="create_address" value="1" />
81
+ <h2 class="legend"><?php echo $this->__('Address Information') ?></h2>
82
+ <ul class="form-list">
83
+ <li class="fields">
84
+ <div class="field">
85
+ <label for="company"><?php echo $this->__('Company') ?></label>
86
+ <div class="input-box">
87
+ <input type="text" name="company" id="company" value="<?php echo $this->escapeHtml($this->getFormData()->getCompany()) ?>" title="<?php echo $this->__('Company') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('company') ?>" />
88
+ </div>
89
+ </div>
90
+ <div class="field">
91
+ <label for="telephone" class="required"><em>*</em><?php echo $this->__('Telephone') ?></label>
92
+ <div class="input-box">
93
+ <input type="text" name="telephone" id="telephone" value="<?php echo $this->escapeHtml($this->getFormData()->getTelephone()) ?>" title="<?php echo $this->__('Telephone') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('telephone') ?>" />
94
+ </div>
95
+ </div>
96
+ </li>
97
+ <?php $_streetValidationClass = $this->helper('customer/address')->getAttributeValidationClass('street'); ?>
98
+ <li class="wide">
99
+ <label for="street_1" class="required"><em>*</em><?php echo $this->__('Street Address') ?></label>
100
+ <div class="input-box">
101
+ <input type="text" name="street[]" value="<?php echo $this->escapeHtml($this->getFormData()->getStreet(1)) ?>" title="<?php echo $this->__('Street Address') ?>" id="street_1" class="input-text <?php echo $_streetValidationClass ?>" />
102
+ </div>
103
+ </li>
104
+ <?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
105
+ <?php for ($_i = 2, $_n = $this->helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?>
106
+ <li class="wide">
107
+ <div class="input-box">
108
+ <input type="text" name="street[]" value="<?php echo $this->escapeHtml($this->getFormData()->getStreet($_i)) ?>" title="<?php echo $this->__('Street Address %s', $_i) ?>" id="street_<?php echo $_i ?>" class="input-text <?php echo $_streetValidationClass ?>" />
109
+ </div>
110
+ </li>
111
+ <?php endfor; ?>
112
+ <li class="fields">
113
+ <div class="field">
114
+ <label for="city" class="required"><em>*</em><?php echo $this->__('City') ?></label>
115
+ <div class="input-box">
116
+ <input type="text" name="city" value="<?php echo $this->escapeHtml($this->getFormData()->getCity()) ?>" title="<?php echo $this->__('City') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>" id="city" />
117
+ </div>
118
+ </div>
119
+ <div class="field">
120
+ <label for="region_id" class="required"><em>*</em><?php echo $this->__('State/Province') ?></label>
121
+ <div class="input-box">
122
+ <select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" class="validate-select" style="display:none;">
123
+ <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
124
+ </select>
125
+ <script type="text/javascript">
126
+ //<![CDATA[
127
+ $('region_id').setAttribute('defaultValue', "<?php echo $this->getFormData()->getRegionId() ?>");
128
+ //]]>
129
+ </script>
130
+ <input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>" style="display:none;" />
131
+ </div>
132
+ </div>
133
+ </li>
134
+ <li class="fields">
135
+ <div class="field">
136
+ <label for="zip" class="required"><em>*</em><?php echo $this->__('Zip/Postal Code') ?></label>
137
+ <div class="input-box">
138
+ <input type="text" name="postcode" value="<?php echo $this->escapeHtml($this->getFormData()->getPostcode()) ?>" title="<?php echo $this->__('Zip/Postal Code') ?>" id="zip" class="input-text validate-zip-international <?php echo $this->helper('customer/address')->getAttributeValidationClass('postcode') ?>" />
139
+ </div>
140
+ </div>
141
+ <div class="field">
142
+ <label for="country" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
143
+ <div class="input-box">
144
+ <?php echo $this->getCountryHtmlSelect() ?>
145
+ </div>
146
+ </div>
147
+ </li>
148
+ </ul>
149
+ <input type="hidden" name="default_billing" value="1" />
150
+ <input type="hidden" name="default_shipping" value="1" />
151
+ </div>
152
+ <?php endif; ?>
153
+ <div class="fieldset">
154
+ <h2 class="legend"><?php echo $this->__('Login Information') ?></h2>
155
+ <ul class="form-list">
156
+ <li class="fields">
157
+ <div class="field">
158
+ <label for="password" class="required"><em>*</em><?php echo $this->__('Password') ?></label>
159
+ <div class="input-box">
160
+ <input type="password" name="password" id="password" title="<?php echo $this->__('Password') ?>" class="input-text required-entry validate-password" />
161
+ </div>
162
+ </div>
163
+ <div class="field">
164
+ <label for="confirmation" class="required"><em>*</em><?php echo $this->__('Confirm Password') ?></label>
165
+ <div class="input-box">
166
+ <input type="password" name="confirmation" title="<?php echo $this->__('Confirm Password') ?>" id="confirmation" class="input-text required-entry validate-cpassword" />
167
+ </div>
168
+ </div>
169
+ </li>
170
+ <?php echo $this->getChildHtml('form.additional.info'); ?>
171
+ <?php echo $this->getChildHtml('persistent.remember.me'); ?>
172
+ </ul>
173
+ <?php echo $this->getChildHtml('persistent.remember.me.tooltip'); ?>
174
+ </div>
175
+ <?php echo $this->getChildHtml('studioforty9.recaptcha.explicit'); ?>
176
+ <div class="buttons-set">
177
+ <p class="required"><?php echo $this->__('* Required Fields') ?></p>
178
+ <p class="back-link"><a href="<?php echo $this->escapeUrl($this->getBackUrl()) ?>" class="back-link"><small>&laquo; </small><?php echo $this->__('Back') ?></a></p>
179
+ <button type="submit" title="<?php echo $this->__('Submit') ?>" class="button"><span><span><?php echo $this->__('Submit') ?></span></span></button>
180
+ </div>
181
+ <?php if (Mage::helper('checkout')->isContextCheckout()): ?>
182
+ <input name="context" type="hidden" value="checkout" />
183
+ <?php endif; ?>
184
+ </form>
185
+ <script type="text/javascript">
186
+ //<![CDATA[
187
+ var dataForm = new VarienForm('form-validate', true);
188
+ <?php if($this->getShowAddressFields()): ?>
189
+ new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
190
+ <?php endif; ?>
191
+ //]]>
192
+ </script>
193
+ </div>
app/design/frontend/base/default/template/studioforty9/recaptcha/samples/base/review/form.phtml ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <div class="form-add">
28
+ <h2><?php echo $this->__('Write Your Own Review') ?></h2>
29
+ <?php if ($this->getAllowWriteReviewFlag()): ?>
30
+ <form action="<?php echo $this->getAction() ?>" method="post" id="review-form">
31
+ <fieldset>
32
+ <?php echo $this->getChildHtml('form_fields_before')?>
33
+ <h3><?php echo $this->__("You're reviewing:"); ?> <span><?php echo $this->htmlEscape($this->getProductInfo()->getName()) ?></span></h3>
34
+ <?php if( $this->getRatings() && $this->getRatings()->getSize()): ?>
35
+ <h4><?php echo $this->__('How do you rate this product?') ?> <em class="required">*</em></h4>
36
+ <span id="input-message-box"></span>
37
+ <table class="data-table" id="product-review-table">
38
+ <col />
39
+ <col width="1" />
40
+ <col width="1" />
41
+ <col width="1" />
42
+ <col width="1" />
43
+ <col width="1" />
44
+ <thead>
45
+ <tr>
46
+ <th>&nbsp;</th>
47
+ <th><span class="nobr"><?php echo $this->__('1 star') ?></span></th>
48
+ <th><span class="nobr"><?php echo $this->__('2 stars') ?></span></th>
49
+ <th><span class="nobr"><?php echo $this->__('3 stars') ?></span></th>
50
+ <th><span class="nobr"><?php echo $this->__('4 stars') ?></span></th>
51
+ <th><span class="nobr"><?php echo $this->__('5 stars') ?></span></th>
52
+ </tr>
53
+ </thead>
54
+ <tbody>
55
+ <?php foreach ($this->getRatings() as $_rating): ?>
56
+ <tr>
57
+ <th><?php echo $this->escapeHtml($_rating->getRatingCode()) ?></th>
58
+ <?php foreach ($_rating->getOptions() as $_option): ?>
59
+ <td class="value"><input type="radio" name="ratings[<?php echo $_rating->getId() ?>]" id="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>" value="<?php echo $_option->getId() ?>" class="radio" /></td>
60
+ <?php endforeach; ?>
61
+ </tr>
62
+ <?php endforeach; ?>
63
+ </tbody>
64
+ </table>
65
+ <input type="hidden" name="validate_rating" class="validate-rating" value="" />
66
+ <script type="text/javascript">decorateTable('product-review-table')</script>
67
+ <?php endif; ?>
68
+ <ul class="form-list">
69
+ <li>
70
+ <label for="nickname_field" class="required"><em>*</em><?php echo $this->__('Nickname') ?></label>
71
+ <div class="input-box">
72
+ <input type="text" name="nickname" id="nickname_field" class="input-text required-entry" value="<?php echo $this->htmlEscape($data->getNickname()) ?>" />
73
+ </div>
74
+ </li>
75
+ <li>
76
+ <label for="summary_field" class="required"><em>*</em><?php echo $this->__('Summary of Your Review') ?></label>
77
+ <div class="input-box">
78
+ <input type="text" name="title" id="summary_field" class="input-text required-entry" value="<?php echo $this->htmlEscape($data->getTitle()) ?>" />
79
+ </div>
80
+ </li>
81
+ <li>
82
+ <label for="review_field" class="required"><em>*</em><?php echo $this->__('Review') ?></label>
83
+ <div class="input-box">
84
+ <textarea name="detail" id="review_field" cols="5" rows="3" class="required-entry"><?php echo $this->htmlEscape($data->getDetail()) ?></textarea>
85
+ </div>
86
+ </li>
87
+ </ul>
88
+ </fieldset>
89
+ <?php echo $this->getChildHtml('studioforty9.recaptcha.explicit'); ?>
90
+ <div class="buttons-set">
91
+ <button type="submit" title="<?php echo $this->__('Submit Review') ?>" class="button"><span><span><?php echo $this->__('Submit Review') ?></span></span></button>
92
+ </div>
93
+ </form>
94
+ <script type="text/javascript">
95
+ //<![CDATA[
96
+ var dataForm = new VarienForm('review-form');
97
+ Validation.addAllThese(
98
+ [
99
+ ['validate-rating', '<?php echo $this->__('Please select one of each of the ratings above') ?>', function(v) {
100
+ var trs = $('product-review-table').select('tr');
101
+ var inputs;
102
+ var error = 1;
103
+
104
+ for( var j=0; j < trs.length; j++ ) {
105
+ var tr = trs[j];
106
+ if( j > 0 ) {
107
+ inputs = tr.select('input');
108
+
109
+ for( i in inputs ) {
110
+ if( inputs[i].checked == true ) {
111
+ error = 0;
112
+ }
113
+ }
114
+
115
+ if( error == 1 ) {
116
+ return false;
117
+ } else {
118
+ error = 1;
119
+ }
120
+ }
121
+ }
122
+ return true;
123
+ }]
124
+ ]
125
+ );
126
+ //]]>
127
+ </script>
128
+ <?php else: ?>
129
+ <p class="review-nologged" id="review-form">
130
+ <?php echo $this->__('Only registered users can write reviews. Please, <a href="%s">log in</a> or <a href="%s">register</a>', $this->getLoginLink(), Mage::helper('customer')->getRegisterUrl()) ?>
131
+ </p>
132
+ <?php endif ?>
133
+ </div>
app/design/frontend/base/default/template/studioforty9/recaptcha/samples/base/sendfriend/send.phtml ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ /* @var $this Mage_Sendfriend_Block_Send */
27
+ /**
28
+ * Send to friend form
29
+ *
30
+ * @see Mage_Sendfriend_Block_Send
31
+ */
32
+ ?>
33
+ <script type="text/javascript">
34
+ //<![CDATA[
35
+ i=0;
36
+ var recipCount = 1;
37
+ var maxRecip = <?php echo $this->getMaxRecipients() ?>;
38
+ function remove_recipient(i){
39
+ $('recipients_name'+i).up(2).remove();
40
+ recipCount--;
41
+ if(recipCount<maxRecip && maxRecip != 0) {
42
+ $('add_recipient_button').show();
43
+ $('max_recipient_message').hide();
44
+ }
45
+ return false;
46
+ }
47
+
48
+ function add_recipient(){
49
+ ul = $('recipients_options');
50
+ var li_mail = Element.extend(document.createElement("LI"));
51
+ li_mail.addClassName('fields additional-row');
52
+ li_mail.innerHTML = '<p><a href="delete_email" title="<?php echo $this->__('Remove Email') ?>" onclick="remove_recipient('+i+'); return false" class="btn-remove"><?php echo $this->__('Remove Email') ?>"<\/a><\/p>'
53
+ li_mail.innerHTML += '<div class="field"><label for="recipients_name'+i+'" class="required"><em>*<\/em><?php echo $this->__('Name:') ?><\/label><div class="input-box"><input name="recipients[name][]" type="text" class="input-text required-entry" id="recipients_name'+i+'" /><\/div>';
54
+ li_mail.innerHTML += '<div class="field"><label for="recipients_email'+i+'" class="required"><em>*<\/em><?php echo $this->__('Email Address:') ?><\/label><div class="input-box"><input name="recipients[email][]" value="" title="<?php echo $this->__('Email Address') ?>" id="recipients_email'+i+'" type="text" class="input-text required-entry validate-email" /><\/div><\/div>';
55
+ i++;
56
+ recipCount++;
57
+ if(recipCount>=maxRecip && maxRecip != 0) {
58
+ $('add_recipient_button').hide();
59
+ $('max_recipient_message').show();
60
+ }
61
+
62
+ ul.appendChild(li_mail);
63
+ }
64
+ //]]>
65
+ </script>
66
+
67
+ <div class="send-friend">
68
+ <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
69
+ <div class="page-title">
70
+ <h1><?php echo $this->__('Email to a Friend') ?></h1>
71
+ </div>
72
+ <form action="<?php echo $this->getSendUrl() ?>" method="post" id="product_sendtofriend_form">
73
+ <div class="fieldset">
74
+ <?php echo $this->getBlockHtml('formkey')?>
75
+ <h2 class="legend"><?php echo $this->__('Sender:') ?></h2>
76
+ <ul class="form-list" id="sender_options">
77
+ <li class="fields">
78
+ <div class="field">
79
+ <label for="sender_name" class="required"><em>*</em><?php echo $this->__('Name:') ?></label>
80
+ <div class="input-box">
81
+ <input name="sender[name]" value="<?php echo $this->htmlEscape($this->getUserName()) ?>" title="<?php echo $this->__('Name') ?>" id="sender_name" type="text" class="input-text required-entry" />
82
+ </div>
83
+ </div>
84
+ <div class="field">
85
+ <label for="sender_email" class="required"><em>*</em><?php echo $this->__('Email:') ?></label>
86
+ <div class="input-box">
87
+ <input name="sender[email]" value="<?php echo $this->htmlEscape($this->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" id="sender_email" type="text" class="input-text required-entry validate-email" />
88
+ </div>
89
+ </div>
90
+ </li>
91
+ <li class="wide">
92
+ <label for="sender_message" class="required"><em>*</em><?php echo $this->__('Message:') ?></label>
93
+ <div class="input-box">
94
+ <textarea name="sender[message]" class="input-text required-entry" id="sender_message" cols="3" rows="3"><?php echo $this->htmlEscape($this->getMessage())?></textarea>
95
+ </div>
96
+ </li>
97
+ </ul>
98
+ </div>
99
+ <div class="fieldset">
100
+ <h2 class="legend"><?php echo $this->__('Recipient:') ?></h2>
101
+ <ul class="form-list" id="recipients_options">
102
+ <li class="fields">
103
+ <div class="field">
104
+ <label for="recipients_name" class="required"><em>*</em><?php echo $this->__('Name:') ?></label>
105
+ <div class="input-box">
106
+ <input name="recipients[name][]" type="text" class="input-text required-entry" id="recipients_name" />
107
+ </div>
108
+ </div>
109
+ <div class="field">
110
+ <label for="recipients_email" class="required"><em>*</em><?php echo $this->__('Email Address:') ?></label>
111
+ <div class="input-box">
112
+ <input name="recipients[email][]" value="" title="<?php echo $this->__('Email Address') ?>" id="recipients_email" type="text" class="input-text required-entry validate-email" />
113
+ </div>
114
+ </div>
115
+ </li>
116
+ </ul>
117
+ </div>
118
+ <?php echo $this->getChildHtml('studioforty9.recaptcha.explicit'); ?>
119
+ <div class="buttons-set">
120
+ <p class="back-link"><a href="#" onclick="history.back(); return false;"><small>&laquo; </small><?php echo $this->__('Back') ?></a></p>
121
+ <button type="submit" class="button<?php if (!$this->canSend()):?> disabled<?php endif ?>"<?php if (!$this->canSend()):?> disabled="disabled"<?php endif ?>><span><span><?php echo $this->__('Send Email') ?></span></span></button>
122
+ <div id="max_recipient_message" style="display:none;">
123
+ <?php if ($this->getMaxRecipients()): ?>
124
+ <p class="limit"><?php echo $this->__('Maximum %d email addresses allowed.', $this->getMaxRecipients()) ?></p>
125
+ <?php endif; ?>
126
+ </div>
127
+ <?php if (1 < $this->getMaxRecipients()): ?>
128
+ <p id="add_recipient_button">
129
+ <button type="button" onclick="add_recipient();" class="button"><span><span><?php echo $this->__('Add Recipient') ?></span></span></button>
130
+ </p>
131
+ <?php endif; ?>
132
+ </div>
133
+ </form>
134
+ <script type="text/javascript">
135
+ //<![CDATA[
136
+ var productSendtofriendForm = new VarienForm('product_sendtofriend_form');
137
+ productSendtofriendForm.submit = function() {
138
+ if(this.validator.validate()) {
139
+ this.form.submit();
140
+ }
141
+ }.bind(productSendtofriendForm);
142
+ //]]>
143
+ </script>
144
+ </div>
app/etc/modules/Studioforty9_Recaptcha.xml CHANGED
@@ -6,9 +6,9 @@
6
  * @category Studioforty9
7
  * @package Studioforty9_Recaptcha
8
  * @author StudioForty9 <info@studioforty9.com>
9
- * @copyright 2014 StudioForty9 (http://www.studioforty9.com)
10
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
11
- * @version 1.0.0
12
  * @link https://github.com/studioforty9/recaptcha
13
  */
14
  -->
6
  * @category Studioforty9
7
  * @package Studioforty9_Recaptcha
8
  * @author StudioForty9 <info@studioforty9.com>
9
+ * @copyright 2015 StudioForty9 (http://www.studioforty9.com)
10
  * @license https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
11
+ * @version 1.2.0
12
  * @link https://github.com/studioforty9/recaptcha
13
  */
14
  -->
package.xml CHANGED
@@ -1,33 +1,46 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Studioforty9_Recaptcha</name>
4
- <version>1.0.1</version>
5
- <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/BSD-3-Clause">BSDL</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>Google reCAPTCHA for the Contacts page form.</summary>
10
- <description>&lt;h3&gt;Support and Feature Requests&lt;/h3&gt;&#xD;
11
  &#xD;
12
- https://github.com/studioforty9/recaptcha/issues&#xD;
13
  &#xD;
14
- &lt;h3&gt;How to Configure&lt;/h3&gt;&#xD;
15
  &#xD;
16
- &lt;ol&gt;&#xD;
17
- &lt;li&gt;Once you've got the module installed, sign into your Google account and visit https://www.google.com/recaptcha.&lt;/li&gt;&#xD;
18
- &lt;li&gt;Hit the "Get reCAPTCHA" link and you'll be taken to your account overview page. Register a new site by adding a label and any domains you want to allow for this specific reCAPTCHA widget.&lt;/li&gt;&#xD;
19
- &lt;li&gt;Under 'Adding reCAPTCHA to your site' you should see 'Keys', specifically your 'Site Key' and 'Secret Key', copy and paste both keys into their respective configuration fields under 'System -&gt; Configuration -&gt; Sales -&gt; Google API -&gt; Google ReCaptcha'.&lt;/li&gt;&#xD;
20
- &lt;li&gt;Copy the /contacts/form.phtml template over to your theme, if you haven't already done so, just above the `buttons-set` div paste in the following code:&lt;/li&gt;&#xD;
 
 
 
 
 
 
 
 
21
  &lt;/ul&gt;&#xD;
22
- &lt;?php echo $this-&gt;getChildHtml('studioforty9.recaptcha.autorender'); ?&gt;&#xD;
23
  &#xD;
 
24
  &#xD;
25
- </description>
26
- <notes>Tested on Magento versions: 1.8.0.0, 1.8.1.0, 1.9.0.1 and 1.9.1.0</notes>
27
- <authors><author><name>StudioForty9</name><user>SF9</user><email>info@studioforty9.com</email></author><author><name>Eoghan O'Brien</name><user>eoghanobrien</user><email>eoghan@eoghanobrien.com</email></author></authors>
28
- <date>2014-12-19</date>
29
- <time>13:09:31</time>
30
- <contents><target name="magecommunity"><dir name="Studioforty9"><dir name="Recaptcha"><dir name="Block"><file name="Autorender.php" hash="7a2e7003a75cff32829adac6ebd2846c"/></dir><dir name="Helper"><file name="Data.php" hash="e3839c00e2837b28193d23e63f533b37"/><file name="Request.php" hash="84f061fe40931b993c339d29d26fceab"/><file name="Response.php" hash="aad903c4cd076ea78f96ddeb179f1b85"/></dir><dir name="Model"><dir name="Observer"><file name="Contacts.php" hash="824d5739d6a854312c20764b10a8762e"/></dir><dir name="Source"><file name="Theme.php" hash="4dd05e3bbce98ee7e4ed3bab33fd3365"/></dir></dir><dir name="Test"><dir name="Block"><file name="Autorender.php" hash="a5e6de4f6f0298bd709cd404d34ccd0e"/></dir><dir name="Config"><file name="Module.php" hash="e4ce75427cf4dd943b9b83a47fdabf58"/></dir><dir name="Helper"><file name="Request.php" hash="efae2d639b27e416e0175fac0e6ac638"/><file name="Response.php" hash="c602e7c60e4ad66ff13bc77bdbb1fba5"/></dir><dir name="Model"><dir name="Observer"><file name="Contacts.php" hash="2d4c043d55d275c6d73530f7937a1ecc"/></dir><dir name="Source"><file name="Theme.php" hash="8da1a1f9317b2407bca042d088c4ce1d"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="43efbe22717cc133f6bf91ff713764c5"/><file name="system.xml" hash="c9a73cd77c5c0d0c001f1bf848cabaae"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="studioforty9_recaptcha.xml" hash="57f4c8f17f08c04985cd582f4768191e"/></dir><dir name="template"><dir name="studioforty9"><dir name="recaptcha"><file name="autorender.phtml" hash="71a2e1820a9b8e83cba2b3f711cb5eaa"/></dir></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="Studioforty9_Recaptcha.csv" hash="6387abc316e524840fa3b1fcc49dc25d"/></dir></target><target name="mageetc"><dir name="modules"><file name="Studioforty9_Recaptcha.xml" hash="6f8f14cebd2b8681e2631d1c4b7acf0b"/></dir></target></contents>
 
 
 
 
 
31
  <compatible/>
32
  <dependencies><required><php><min>5.3.0</min><max>5.5.99</max></php></required></dependencies>
33
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Studioforty9_Recaptcha</name>
4
+ <version>1.2.0</version>
5
+ <stability>devel</stability>
6
  <license uri="http://opensource.org/licenses/BSD-3-Clause">BSDL</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>Protect your website from spam and abuse while letting real people pass through with ease! </summary>
10
+ <description>&lt;p&gt;The reCAPTCHA extension uses Google's reCAPTCHA widget (&lt;a href="https://www.google.com/recaptcha/intro/index.html"&gt;read more&lt;/a&gt;) to lower the friction when identifying real people and provide powerful protection against spam.&lt;/p&gt;&#xD;
11
  &#xD;
12
+ &lt;h2&gt;Support and Feature Requests&lt;/h2&gt;&#xD;
13
  &#xD;
14
+ &lt;p&gt;Support and feature request are hosted on GitHub please direct any queries there first: &lt;a href="https://github.com/studioforty9/recaptcha/issues"&gt;https://github.com/studioforty9/recaptcha/issues&lt;/a&gt;.&lt;/p&gt;&#xD;
15
  &#xD;
16
+ &lt;p&gt;If you don't have a GitHub account then you can contact us via our &lt;a href="http://www.studioforty9.com/contact-us"&gt;website&lt;/a&gt;.&lt;/p&gt;&#xD;
17
+ &#xD;
18
+ &#xD;
19
+ &#xD;
20
+ &lt;h2&gt;Features&lt;/h2&gt;&#xD;
21
+ &#xD;
22
+ &lt;p&gt;Add the Google ReCaptcha widget to front-end forms in Magento, we currently support the following forms:&lt;/p&gt;&#xD;
23
+ &#xD;
24
+ &lt;ul&gt;&#xD;
25
+ &lt;li&gt;Contact page form&lt;/li&gt;&#xD;
26
+ &lt;li&gt;Product Review form&lt;/li&gt;&#xD;
27
+ &lt;li&gt;Customer Registration form&lt;/li&gt;&#xD;
28
+ &lt;li&gt;Product Send to friend form&lt;/li&gt;&#xD;
29
  &lt;/ul&gt;&#xD;
 
30
  &#xD;
31
+ &lt;h2&gt;Usage&lt;/h2&gt;&#xD;
32
  &#xD;
33
+ &lt;ol&gt;&#xD;
34
+ &lt;li&gt;Once you've got the module installed, sign into your Google account and visit &lt;a href="https://www.google.com/recaptcha"&gt;https://www.google.com/recaptcha&lt;/a&gt;.&lt;/li&gt;&#xD;
35
+ &lt;li&gt;Hit the &amp;quot;Get reCAPTCHA&amp;quot; link and you'll be taken to your account overview page. Register a new site by adding a label and any domains you want to allow for this specific reCAPTCHA widget.&lt;/li&gt;&#xD;
36
+ &lt;li&gt;Under 'Adding reCAPTCHA to your site' you should see 'Keys', specifically your 'Site Key' and 'Secret Key', copy and paste both keys into their respective configuration fields under 'System -&amp;gt; Configuration -&amp;gt; Sales -&amp;gt; Google API -&amp;gt; Google ReCaptcha'.&lt;/li&gt;&#xD;
37
+ &lt;li&gt;&lt;a href="https://drive.google.com/file/d/0B3hRj4-KZpxMRkJEZ0JFeGNRM2c/view?usp=sharing"&gt;Follow the instructions here.&lt;/a&gt;&lt;/li&gt;&#xD;
38
+ &lt;/ol&gt;</description>
39
+ <notes>Tested on Magento versions: 1.7.0.2, 1.8.0.0, 1.8.1.0, 1.9.0.1 and 1.9.1.0. See https://travis-ci.org/StudioForty9/Recaptcha for more.</notes>
40
+ <authors><author><name>StudioForty9</name><user>SF9</user><email>info@studioforty9.com</email></author><author><name>Eoghan O'Brien</name><user>eoghanobrien</user><email>eoghan@studioforty9.com</email></author></authors>
41
+ <date>2015-02-21</date>
42
+ <time>15:58:19</time>
43
+ <contents><target name="magecommunity"><dir name="Studioforty9"><dir name="Recaptcha"><dir name="Block"><file name="Autorender.php" hash="ca9fce4b930fd8b6077d6f3b2f04e3bb"/><file name="Explicit.php" hash="32c6e9255f5599282b24f03fd8891c06"/></dir><dir name="Helper"><file name="Data.php" hash="6b408bede840977d15132404f132f210"/><file name="Request.php" hash="375c4cde8c292e2360a909498c620db6"/><file name="Response.php" hash="2017ced9053966ccea2c4d23cd52d8ff"/></dir><dir name="Model"><file name="Observer.php" hash="0d67e5dadc00623dc44789228433394a"/><dir name="Source"><file name="Theme.php" hash="7ebe33c57b125ca2520037e862b57075"/></dir></dir><dir name="etc"><file name="config.xml" hash="49ee7e7b3fa81fb662b408e9b6282e81"/><file name="system.xml" hash="da98d3715a9116ff96b898df1e306ddf"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="studioforty9_recaptcha.xml" hash="ca3b59003d7473a73fc4283606fc21b4"/></dir><dir name="template"><dir name="studioforty9"><dir name="recaptcha"><file name="autorender.phtml" hash="d93df7b156aa90ba2c184606a0149202"/><file name="explicit.phtml" hash="fdab9be006a22da28400400e2c34ff93"/><dir name="samples"><dir name="base"><dir name="contacts"><file name="form.phtml" hash="f14cc54dde83a12cb9bac124127902be"/></dir><dir name="persistent"><dir name="customer"><dir name="form"><file name="register.phtml" hash="c4a6ccf18099d9d47ff55edf78e0f416"/></dir></dir></dir><dir name="review"><file name="form.phtml" hash="f7e8587e72a51b124ff2c2bcfd8e20b4"/></dir><dir name="sendfriend"><file name="send.phtml" hash="2f49f6800e901d1d63362dc5391cd971"/></dir></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="Studioforty9_Recaptcha.csv" hash="6387abc316e524840fa3b1fcc49dc25d"/></dir></target><target name="mageetc"><dir name="modules"><file name="Studioforty9_Recaptcha.xml" hash="4ea774e9a930bddc77ab8d408b81e008"/></dir></target></contents>
44
  <compatible/>
45
  <dependencies><required><php><min>5.3.0</min><max>5.5.99</max></php></required></dependencies>
46
  </package>