DigitalPianism_ReviewCaptcha - Version 0.0.4

Version Notes

- Original release

Download this release

Release Info

Developer Digital Pianism
Extension DigitalPianism_ReviewCaptcha
Version 0.0.4
Comparing to
See all releases


Version 0.0.4

app/code/community/DigitalPianism/ReviewCaptcha/Block/Form.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class DigitalPianism_ReviewCaptcha_Block_Form
5
+ */
6
+ class DigitalPianism_ReviewCaptcha_Block_Form extends Mage_Review_Block_Form
7
+ {
8
+
9
+ /**
10
+ * @return string
11
+ */
12
+ public function getAction()
13
+ {
14
+ $productId = Mage::app()->getRequest()->getParam('id', false);
15
+ return Mage::getUrl('reviewcaptcha/index/post', array('id' => $productId));
16
+ }
17
+
18
+ }
app/code/community/DigitalPianism/ReviewCaptcha/controllers/IndexController.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Mage/Review/controllers/ProductController.php';
3
+
4
+ /**
5
+ * Review controller
6
+ *
7
+ * @category Mage
8
+ * @package Mage_Review
9
+ * @author Magento Core Team <core@magentocommerce.com>
10
+ */
11
+ class DigitalPianism_ReviewCaptcha_IndexController extends Mage_Review_ProductController
12
+ {
13
+ protected $_realModuleName = 'Mage_Review';
14
+ /**
15
+ * Submit new review action
16
+ *
17
+ */
18
+ public function postAction()
19
+ {
20
+ if ($data = Mage::getSingleton('review/session')->getFormData(true)) {
21
+ $rating = array();
22
+ if (isset($data['ratings']) && is_array($data['ratings'])) {
23
+ $rating = $data['ratings'];
24
+ }
25
+ } else {
26
+ $data = $this->getRequest()->getPost();
27
+ $rating = $this->getRequest()->getParam('ratings', array());
28
+ }
29
+
30
+ if (($product = $this->_initProduct()) && !empty($data)) {
31
+ $session = Mage::getSingleton('core/session');
32
+ /* @var $session Mage_Core_Model_Session */
33
+ $review = Mage::getModel('review/review')->setData($data);
34
+ /* @var $review Mage_Review_Model_Review */
35
+
36
+ $validate = $review->validate();
37
+
38
+ // Captcha check
39
+ $formId = "review_captcha";
40
+ $captchaModel = Mage::helper("captcha")->getCaptcha($formId);
41
+ if ($captchaModel->isRequired())
42
+ {
43
+ if (!$captchaModel->isCorrect($this->_getCaptchaString($this->getRequest(), $formId)))
44
+ {
45
+ $validate = false;
46
+ $validate[] = $this->__('Incorrect CAPTCHA.');
47
+ }
48
+ }
49
+
50
+ if ($validate === true) {
51
+ try {
52
+ $review->setEntityId($review->getEntityIdByCode(Mage_Review_Model_Review::ENTITY_PRODUCT_CODE))
53
+ ->setEntityPkValue($product->getId())
54
+ ->setStatusId(Mage_Review_Model_Review::STATUS_PENDING)
55
+ ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId())
56
+ ->setStoreId(Mage::app()->getStore()->getId())
57
+ ->setStores(array(Mage::app()->getStore()->getId()))
58
+ ->save();
59
+
60
+ foreach ($rating as $ratingId => $optionId) {
61
+ Mage::getModel('rating/rating')
62
+ ->setRatingId($ratingId)
63
+ ->setReviewId($review->getId())
64
+ ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId())
65
+ ->addOptionVote($optionId, $product->getId());
66
+ }
67
+
68
+ $review->aggregate();
69
+ $session->addSuccess($this->__('Your review has been accepted for moderation.'));
70
+ }
71
+ catch (Exception $e) {
72
+ $session->setFormData($data);
73
+ $session->addError($this->__('Unable to post the review.'));
74
+ }
75
+ }
76
+ else {
77
+ $session->setFormData($data);
78
+ if (is_array($validate)) {
79
+ foreach ($validate as $errorMessage) {
80
+ $session->addError($errorMessage);
81
+ }
82
+ }
83
+ else {
84
+ $session->addError($this->__('Unable to post the review.'));
85
+ }
86
+ }
87
+ }
88
+
89
+ if ($redirectUrl = Mage::getSingleton('review/session')->getRedirectUrl(true)) {
90
+ $this->_redirectUrl($redirectUrl);
91
+ return;
92
+ }
93
+ $this->_redirectReferer();
94
+ }
95
+
96
+ /**
97
+ * @param $request
98
+ * @param $formId
99
+ * @return mixed
100
+ */
101
+ protected function _getCaptchaString($request, $formId)
102
+ {
103
+ $captchaParams = $request->getPost(Mage_Captcha_Helper_Data::INPUT_NAME_FIELD_VALUE);
104
+ return $captchaParams[$formId];
105
+ }
106
+
107
+ }
app/code/community/DigitalPianism/ReviewCaptcha/etc/config.xml ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <DigitalPianism_ReviewCaptcha>
5
+ <version>0.0.4</version>
6
+ </DigitalPianism_ReviewCaptcha>
7
+ </modules>
8
+
9
+ <global>
10
+ <blocks>
11
+ <review>
12
+ <rewrite>
13
+ <form>DigitalPianism_ReviewCaptcha_Block_Form</form>
14
+ </rewrite>
15
+ </review>
16
+ </blocks>
17
+ </global>
18
+
19
+ <frontend>
20
+ <routers>
21
+ <review_captcha>
22
+ <use>standard</use>
23
+ <args>
24
+ <module>DigitalPianism_ReviewCaptcha</module>
25
+ <frontName>reviewcaptcha</frontName>
26
+ </args>
27
+ </review_captcha>
28
+ </routers>
29
+
30
+ <layout>
31
+ <updates>
32
+ <review_captcha>
33
+ <file>digitalpianism/reviewcaptcha.xml</file>
34
+ </review_captcha>
35
+ </updates>
36
+ </layout>
37
+ </frontend>
38
+ <default>
39
+ <!-- Required for the in built Magento Captcha -->
40
+ <captcha>
41
+ <frontend>
42
+ <areas>
43
+ <review_captcha>
44
+ <label>Product Review Form</label>
45
+ </review_captcha>
46
+ </areas>
47
+ </frontend>
48
+ </captcha>
49
+ <customer>
50
+ <captcha>
51
+ <always_for>
52
+ <review_captcha>1</review_captcha>
53
+ </always_for>
54
+ </captcha>
55
+ </customer>
56
+ </default>
57
+ </config>
app/design/frontend/base/default/layout/digitalpianism/reviewcaptcha.xml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <layout version="0.1.0">
4
+
5
+ <review_product_list>
6
+ <reference name="head">
7
+ <action method="addJs"><file>mage/captcha.js</file></action>
8
+ </reference>
9
+
10
+ <reference name="product.review.form">
11
+ <!-- Add the Magento Captcha -->
12
+ <block type="core/text_list" name="form.additional.info">
13
+ <block type="captcha/captcha" name="captcha">
14
+ <action method="setFormId"><formId>review_captcha</formId></action>
15
+ <action method="setImgWidth"><width>230</width></action>
16
+ <action method="setImgHeight"><height>50</height></action>
17
+ </block>
18
+ </block>
19
+ </reference>
20
+ </review_product_list>
21
+
22
+ </layout>
app/etc/modules/DigitalPianism_ReviewCaptcha.xml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <DigitalPianism_ReviewCaptcha>
4
+ <active>true</active>
5
+ <codePool>community</codePool>
6
+ <depends>
7
+ <Mage_Review/>
8
+ </depends>
9
+ </DigitalPianism_ReviewCaptcha>
10
+ </modules>
11
+ </config>
package.xml ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>DigitalPianism_ReviewCaptcha</name>
4
+ <version>0.0.4</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>This module lets you use the Magento captcha on the product review form.</summary>
10
+ <description>&lt;h2&gt;Description&lt;/h2&gt;&#xD;
11
+ &lt;p&gt;Beeing spammed by the product review form on your Magento website ? Digital Pianism Review Captcha module is the solution.&lt;/p&gt;&#xD;
12
+ &lt;p&gt;With this extension, you will be able to use the original Magento captcha on the product review form.&lt;/p&gt;&#xD;
13
+ &#xD;
14
+ &lt;h2&gt;Installation&lt;/h2&gt;&#xD;
15
+ &#xD;
16
+ &lt;h3&gt;Configuration&lt;/h3&gt;&#xD;
17
+ &#xD;
18
+ &lt;ul&gt;&#xD;
19
+ &lt;li&gt;Install the module manually or via Magento Connect.&lt;/li&gt;&#xD;
20
+ &lt;li&gt;Flush the cache&lt;/li&gt;&#xD;
21
+ &lt;li&gt;Access System &gt; Configuration &gt; Customer Configuration &gt; Captcha&lt;/li&gt;&#xD;
22
+ &lt;li&gt;If you're not using the Magento captcha on your website yet, set Enable CAPTCHA on Frontend to Yes&lt;/li&gt;&#xD;
23
+ &lt;li&gt;Then choose Review Form in the Forms multiselect.&lt;/li&gt;&#xD;
24
+ &lt;li&gt;Save the configuration&lt;/li&gt;&#xD;
25
+ &lt;/ul&gt;&#xD;
26
+ &#xD;
27
+ &lt;h3&gt;Template integration&lt;/h3&gt;&#xD;
28
+ &#xD;
29
+ &lt;p&gt;The only code manipulation that you need to do is modify the following template: app/design/frontend/&lt;your_package&gt;/&lt;your_theme&gt;/template/review/form.phtml&lt;/p&gt;&#xD;
30
+ &#xD;
31
+ &lt;p&gt;All you have to do is add the following piece of the code after the last li closing tag:&lt;/p&gt;&#xD;
32
+ &#xD;
33
+ &lt;pre&gt;&lt;?php echo $this-&gt;getChildHtml('form.additional.info'); ?&gt;&lt;/pre&gt;&#xD;
34
+ &#xD;
35
+ &lt;p&gt;Here is an example with the base/default template:&lt;/p&gt;&#xD;
36
+ &#xD;
37
+ &lt;pre&gt;&#xD;
38
+ &lt;li&gt;&#xD;
39
+ &lt;label for="review_field" class="required"&gt;&lt;em&gt;*&lt;/em&gt;&lt;?php echo $this-&gt;__('Review') ?&gt;&lt;/label&gt;&#xD;
40
+ &lt;div class="input-box"&gt;&#xD;
41
+ &lt;textarea name="detail" id="review_field" cols="5" rows="3" class="required-entry"&gt;&lt;?php echo $this-&gt;escapeHtml($data-&gt;getDetail()) ?&gt;&lt;/textarea&gt;&#xD;
42
+ &lt;/div&gt;&#xD;
43
+ &lt;/li&gt;&#xD;
44
+ &lt;?php echo $this-&gt;getChildHtml('form.additional.info'); ?&gt;&#xD;
45
+ &lt;/ul&gt;&#xD;
46
+ &lt;/pre&gt;</description>
47
+ <notes>- Original release</notes>
48
+ <authors><author><name>Digital Pianism</name><user>digitalpianism</user><email>contact@digital-pianism.com</email></author></authors>
49
+ <date>2015-11-16</date>
50
+ <time>21:14:23</time>
51
+ <contents><target name="magecommunity"><dir name="DigitalPianism"><dir name="ReviewCaptcha"><dir name="Block"><file name="Form.php" hash="cd6ec652a8fcebcf99c9c9cb6aeae35c"/></dir><dir name="controllers"><file name="IndexController.php" hash="2948058816f32ff8647e1c2145094083"/></dir><dir name="etc"><file name="config.xml" hash="651004f1c3d96394599ab72df3d4e7df"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="DigitalPianism_ReviewCaptcha.xml" hash="0e864d11c329f0c4b961dd29d0e19ecc"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="digitalpianism"><file name="reviewcaptcha.xml" hash="f347bc64a1519b3d26c9a34fa63915fb"/></dir></dir></dir></dir></dir></target></contents>
52
+ <compatible/>
53
+ <dependencies><required><php><min>4.1.0</min><max>6.0.0</max></php></required></dependencies>
54
+ </package>