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 +18 -0
- app/code/community/DigitalPianism/ReviewCaptcha/controllers/IndexController.php +107 -0
- app/code/community/DigitalPianism/ReviewCaptcha/etc/config.xml +57 -0
- app/design/frontend/base/default/layout/digitalpianism/reviewcaptcha.xml +22 -0
- app/etc/modules/DigitalPianism_ReviewCaptcha.xml +11 -0
- package.xml +54 -0
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><h2>Description</h2>
|
| 11 |
+
<p>Beeing spammed by the product review form on your Magento website ? Digital Pianism Review Captcha module is the solution.</p>
|
| 12 |
+
<p>With this extension, you will be able to use the original Magento captcha on the product review form.</p>
|
| 13 |
+

|
| 14 |
+
<h2>Installation</h2>
|
| 15 |
+

|
| 16 |
+
<h3>Configuration</h3>
|
| 17 |
+

|
| 18 |
+
<ul>
|
| 19 |
+
<li>Install the module manually or via Magento Connect.</li>
|
| 20 |
+
<li>Flush the cache</li>
|
| 21 |
+
<li>Access System > Configuration > Customer Configuration > Captcha</li>
|
| 22 |
+
<li>If you're not using the Magento captcha on your website yet, set Enable CAPTCHA on Frontend to Yes</li>
|
| 23 |
+
<li>Then choose Review Form in the Forms multiselect.</li>
|
| 24 |
+
<li>Save the configuration</li>
|
| 25 |
+
</ul>
|
| 26 |
+

|
| 27 |
+
<h3>Template integration</h3>
|
| 28 |
+

|
| 29 |
+
<p>The only code manipulation that you need to do is modify the following template: app/design/frontend/<your_package>/<your_theme>/template/review/form.phtml</p>
|
| 30 |
+

|
| 31 |
+
<p>All you have to do is add the following piece of the code after the last li closing tag:</p>
|
| 32 |
+

|
| 33 |
+
<pre><?php echo $this->getChildHtml('form.additional.info'); ?></pre>
|
| 34 |
+

|
| 35 |
+
<p>Here is an example with the base/default template:</p>
|
| 36 |
+

|
| 37 |
+
<pre>
|
| 38 |
+
<li>
|
| 39 |
+
<label for="review_field" class="required"><em>*</em><?php echo $this->__('Review') ?></label>
|
| 40 |
+
<div class="input-box">
|
| 41 |
+
<textarea name="detail" id="review_field" cols="5" rows="3" class="required-entry"><?php echo $this->escapeHtml($data->getDetail()) ?></textarea>
|
| 42 |
+
</div>
|
| 43 |
+
</li>
|
| 44 |
+
<?php echo $this->getChildHtml('form.additional.info'); ?>
|
| 45 |
+
</ul>
|
| 46 |
+
</pre></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>
|
