Version Notes
"Contacts Form Captcha" extension add in easy way the captcha to "Contact Us" form.
Download this release
Release Info
Developer | Magento Core Team |
Extension | contactsformcaptcha |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/community/OlegKoval/ContactsFormCaptcha/controllers/IndexController.php +87 -0
- app/code/community/OlegKoval/ContactsFormCaptcha/etc/config.xml +41 -0
- app/code/community/OlegKoval/ContactsFormCaptcha/etc/system.xml +57 -0
- app/design/frontend/base/default/layout/contactsformcaptcha.xml +26 -0
- app/design/frontend/base/default/template/contactsformcaptcha/form.phtml +78 -0
- app/etc/modules/OlegKoval_ContactsFormCaptcha.xml +19 -0
- app/locale/en_US/OlegKoval_ContactsFormCaptcha.csv +6 -0
- lib/reCaptcha/recaptchalib.php +276 -0
- package.xml +20 -0
app/code/community/OlegKoval/ContactsFormCaptcha/controllers/IndexController.php
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contacts Form Captcha index controller
|
4 |
+
*
|
5 |
+
* @category OlegKoval
|
6 |
+
* @package OlegKoval_ContactsFormCaptcha
|
7 |
+
* @copyright Copyright (c) 2012 Oleg Koval
|
8 |
+
* @author Oleg Koval <oleh.koval@gmail.com>
|
9 |
+
*/
|
10 |
+
//include controller to override it
|
11 |
+
require_once(Mage::getBaseDir('app') . DS .'code'. DS .'core'. DS .'Mage'. DS .'Contacts'. DS .'controllers'. DS .'IndexController.php');
|
12 |
+
|
13 |
+
class OlegKoval_ContactsFormCaptcha_IndexController extends Mage_Contacts_IndexController {
|
14 |
+
const XML_PATH_CFC_ENABLED = 'contacts/olegkoval_contactsformcaptcha/enabled';
|
15 |
+
const XML_PATH_CFC_PUBLIC_KEY = 'contacts/olegkoval_contactsformcaptcha/public_key';
|
16 |
+
const XML_PATH_CFC_PRIVATE_KEY = 'contacts/olegkoval_contactsformcaptcha/private_key';
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Check if "Contacts Form Captcha" is enabled
|
20 |
+
*/
|
21 |
+
public function preDispatch() {
|
22 |
+
parent::preDispatch();
|
23 |
+
}
|
24 |
+
|
25 |
+
/**
|
26 |
+
* Method which handle action of displaying contact form
|
27 |
+
*/
|
28 |
+
public function indexAction() {
|
29 |
+
$this->loadLayout();
|
30 |
+
|
31 |
+
if (Mage::getStoreConfigFlag(self::XML_PATH_CFC_ENABLED)) {
|
32 |
+
//include reCaptcha library
|
33 |
+
require_once(Mage::getBaseDir('lib') . DS .'reCaptcha'. DS .'recaptchalib.php');
|
34 |
+
|
35 |
+
//create captcha html-code
|
36 |
+
$publickey = Mage::getStoreConfig(self::XML_PATH_CFC_PUBLIC_KEY);
|
37 |
+
$captcha_code = recaptcha_get_html($publickey);
|
38 |
+
|
39 |
+
$this->getLayout()->getBlock('contactForm')->setTemplate('contactsformcaptcha/form.phtml')->setFormAction(Mage::getUrl('*/*/post'))->setCaptchaCode($captcha_code);
|
40 |
+
}
|
41 |
+
else {
|
42 |
+
$this->getLayout()->getBlock('contactForm')->setFormAction(Mage::getUrl('*/*/post'));
|
43 |
+
}
|
44 |
+
|
45 |
+
$this->_initLayoutMessages('customer/session');
|
46 |
+
$this->_initLayoutMessages('catalog/session');
|
47 |
+
$this->renderLayout();
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Handle post request of Contact form
|
52 |
+
* @return [type] [description]
|
53 |
+
*/
|
54 |
+
public function postAction() {
|
55 |
+
if (Mage::getStoreConfigFlag(self::XML_PATH_CFC_ENABLED)) {
|
56 |
+
try {
|
57 |
+
$post = $this->getRequest()->getPost();
|
58 |
+
if ($post) {
|
59 |
+
//include reCaptcha library
|
60 |
+
require_once(Mage::getBaseDir('lib') . DS .'reCaptcha'. DS .'recaptchalib.php');
|
61 |
+
|
62 |
+
//validate captcha
|
63 |
+
$privatekey = Mage::getStoreConfig(self::XML_PATH_CFC_PRIVATE_KEY);
|
64 |
+
$remote_addr = $this->getRequest()->getServer('REMOTE_ADDR');
|
65 |
+
$captcha = recaptcha_check_answer($privatekey, $remote_addr, $post["recaptcha_challenge_field"], $post["recaptcha_response_field"]);
|
66 |
+
|
67 |
+
if (!$captcha->is_valid) {
|
68 |
+
throw new Exception("The reCAPTCHA wasn't entered correctly. Go back and try it again.", 1);
|
69 |
+
}
|
70 |
+
}
|
71 |
+
else {
|
72 |
+
throw new Exception('', 1);
|
73 |
+
}
|
74 |
+
}
|
75 |
+
catch (Exception $e) {
|
76 |
+
if (strlen($e->getMessage()) > 0) {
|
77 |
+
Mage::getSingleton('customer/session')->addError($this->__($e->getMessage()));
|
78 |
+
}
|
79 |
+
$this->_redirect('*/*/');
|
80 |
+
return;
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
//everything is OK - call parent action
|
85 |
+
parent::postAction();
|
86 |
+
}
|
87 |
+
}
|
app/code/community/OlegKoval/ContactsFormCaptcha/etc/config.xml
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Contacts Form Captcha
|
5 |
+
*
|
6 |
+
* @category OlegKoval
|
7 |
+
* @package OlegKoval_ContactsFormCaptcha
|
8 |
+
* @copyright Copyright (c) 2012 Oleg Koval
|
9 |
+
* @author Oleg Koval <oleh.koval@gmail.com>
|
10 |
+
*/
|
11 |
+
-->
|
12 |
+
<config>
|
13 |
+
<modules>
|
14 |
+
<OlegKoval_ContactsFormCaptcha>
|
15 |
+
<version>1.0.0</version>
|
16 |
+
<depends>
|
17 |
+
<Mage_Contacts/>
|
18 |
+
</depends>
|
19 |
+
</OlegKoval_ContactsFormCaptcha>
|
20 |
+
</modules>
|
21 |
+
|
22 |
+
<global>
|
23 |
+
<blocks>
|
24 |
+
<contactsformcaptcha>
|
25 |
+
<class>OlegKoval_ContactsFormCaptcha_Block</class>
|
26 |
+
</contactsformcaptcha>
|
27 |
+
</blocks>
|
28 |
+
</global>
|
29 |
+
|
30 |
+
<frontend>
|
31 |
+
<routers>
|
32 |
+
<contacts>
|
33 |
+
<args>
|
34 |
+
<modules>
|
35 |
+
<contactsformcaptcha before="Mage_Customer">OlegKoval_ContactsFormCaptcha</contactsformcaptcha>
|
36 |
+
</modules>
|
37 |
+
</args>
|
38 |
+
</contacts>
|
39 |
+
</routers>
|
40 |
+
</frontend>
|
41 |
+
</config>
|
app/code/community/OlegKoval/ContactsFormCaptcha/etc/system.xml
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Contacts Form Captcha
|
5 |
+
*
|
6 |
+
* @category OlegKoval
|
7 |
+
* @package OlegKoval_ContactsFormCaptcha
|
8 |
+
* @copyright Copyright (c) 2012 Oleg Koval
|
9 |
+
* @author Oleg Koval <oleh.koval@gmail.com>
|
10 |
+
*/
|
11 |
+
-->
|
12 |
+
<config>
|
13 |
+
<sections>
|
14 |
+
<contacts>
|
15 |
+
<groups>
|
16 |
+
<olegkoval_contactsformcaptcha translate="label">
|
17 |
+
<label>Contacts Form Captcha</label>
|
18 |
+
<frontend_type>text</frontend_type>
|
19 |
+
<sort_order>100</sort_order>
|
20 |
+
<show_in_default>1</show_in_default>
|
21 |
+
<show_in_website>1</show_in_website>
|
22 |
+
<show_in_store>1</show_in_store>
|
23 |
+
<fields>
|
24 |
+
<enabled translate="label">
|
25 |
+
<label>Enable Captcha</label>
|
26 |
+
<frontend_type>select</frontend_type>
|
27 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
28 |
+
<backend_model>contacts/system_config_backend_links</backend_model>
|
29 |
+
<sort_order>10</sort_order>
|
30 |
+
<show_in_default>1</show_in_default>
|
31 |
+
<show_in_website>1</show_in_website>
|
32 |
+
<show_in_store>1</show_in_store>
|
33 |
+
</enabled>
|
34 |
+
<public_key translate="label">
|
35 |
+
<label>Public Key</label>
|
36 |
+
<comment>You got this from the signup page: https://www.google.com/recaptcha/admin/create</comment>
|
37 |
+
<frontend_type>text</frontend_type>
|
38 |
+
<sort_order>20</sort_order>
|
39 |
+
<show_in_default>1</show_in_default>
|
40 |
+
<show_in_website>1</show_in_website>
|
41 |
+
<show_in_store>1</show_in_store>
|
42 |
+
</public_key>
|
43 |
+
<private_key translate="label">
|
44 |
+
<label>Private Key</label>
|
45 |
+
<comment>You got this from the signup page: https://www.google.com/recaptcha/admin/create</comment>
|
46 |
+
<frontend_type>text</frontend_type>
|
47 |
+
<sort_order>30</sort_order>
|
48 |
+
<show_in_default>1</show_in_default>
|
49 |
+
<show_in_website>1</show_in_website>
|
50 |
+
<show_in_store>1</show_in_store>
|
51 |
+
</private_key>
|
52 |
+
</fields>
|
53 |
+
</olegkoval_contactsformcaptcha>
|
54 |
+
</groups>
|
55 |
+
</contacts>
|
56 |
+
</sections>
|
57 |
+
</config>
|
app/design/frontend/base/default/layout/contactsformcaptcha.xml
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Contacts Form Captcha
|
5 |
+
*
|
6 |
+
* @category OlegKoval
|
7 |
+
* @package OlegKoval_ContactsFormCaptcha
|
8 |
+
* @copyright Copyright (c) 2012 Oleg Koval
|
9 |
+
* @author Oleg Koval <oleh.koval@gmail.com>
|
10 |
+
*/
|
11 |
+
-->
|
12 |
+
<layout version="0.1.0">
|
13 |
+
<contactsformcaptcha_index_index translate="label">
|
14 |
+
<label>Contact Us Form</label>
|
15 |
+
<reference name="head">
|
16 |
+
<action method="setTitle" translate="title" module="contacts"><title>Contact Us</title></action>
|
17 |
+
</reference>
|
18 |
+
<reference name="root">
|
19 |
+
<action method="setTemplate"><template>page/2columns-right.phtml</template></action>
|
20 |
+
<action method="setHeaderTitle" translate="title" module="contacts"><title>Contact Us</title></action>
|
21 |
+
</reference>
|
22 |
+
<reference name="content">
|
23 |
+
<block type="core/template" name="contactsFormCaptcha" template="contactsformcaptcha/form.phtml"/>
|
24 |
+
</reference>
|
25 |
+
</contactsformcaptcha_index_index>
|
26 |
+
</layout>
|
app/design/frontend/base/default/template/contactsformcaptcha/form.phtml
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
<li class="wide">
|
62 |
+
<div class="input-box">
|
63 |
+
<?php echo $this->getCaptchaCode(); ?>
|
64 |
+
</div>
|
65 |
+
</li>
|
66 |
+
</ul>
|
67 |
+
</div>
|
68 |
+
<div class="buttons-set">
|
69 |
+
<p class="required"><?php echo Mage::helper('contacts')->__('* Required Fields') ?></p>
|
70 |
+
<input type="text" name="hideit" id="hideit" value="hideit" style="display:none !important;" />
|
71 |
+
<button type="submit" title="<?php echo Mage::helper('contacts')->__('Submit') ?>" class="button"><span><span><?php echo Mage::helper('contacts')->__('Submit') ?></span></span></button>
|
72 |
+
</div>
|
73 |
+
</form>
|
74 |
+
<script type="text/javascript">
|
75 |
+
//<![CDATA[
|
76 |
+
var contactForm = new VarienForm('contactForm', true);
|
77 |
+
//]]>
|
78 |
+
</script>
|
app/etc/modules/OlegKoval_ContactsFormCaptcha.xml
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Contacts Form Captcha
|
5 |
+
*
|
6 |
+
* @category OlegKoval
|
7 |
+
* @package OlegKoval_ContactsFormCaptcha
|
8 |
+
* @copyright Copyright (c) 2012 Oleg Koval
|
9 |
+
* @author Oleg Koval <oleh.koval@gmail.com>
|
10 |
+
*/
|
11 |
+
-->
|
12 |
+
<config>
|
13 |
+
<modules>
|
14 |
+
<OlegKoval_ContactsFormCaptcha>
|
15 |
+
<active>true</active>
|
16 |
+
<codePool>community</codePool>
|
17 |
+
</OlegKoval_ContactsFormCaptcha>
|
18 |
+
</modules>
|
19 |
+
</config>
|
app/locale/en_US/OlegKoval_ContactsFormCaptcha.csv
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"Contacts Form Captcha","Contacts Form Captcha"
|
2 |
+
"Enable Captcha","Enable Captcha"
|
3 |
+
"Public Key","Public Key"
|
4 |
+
"Private Key","Private Key"
|
5 |
+
"You got this from the signup page: https://www.google.com/recaptcha/admin/create","You got this from the signup page: https://www.google.com/recaptcha/admin/create"
|
6 |
+
"The reCAPTCHA wasn't entered correctly. Go back and try it again.","The reCAPTCHA wasn't entered correctly. Go back and try it again."
|
lib/reCaptcha/recaptchalib.php
ADDED
@@ -0,0 +1,276 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* This is a PHP library that handles calling reCAPTCHA.
|
4 |
+
* - Documentation and latest version
|
5 |
+
* http://recaptcha.net/plugins/php/
|
6 |
+
* - Get a reCAPTCHA API Key
|
7 |
+
* https://www.google.com/recaptcha/admin/create
|
8 |
+
* - Discussion group
|
9 |
+
* http://groups.google.com/group/recaptcha
|
10 |
+
*
|
11 |
+
* Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
|
12 |
+
* AUTHORS:
|
13 |
+
* Mike Crawford
|
14 |
+
* Ben Maurer
|
15 |
+
*
|
16 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
17 |
+
* of this software and associated documentation files (the "Software"), to deal
|
18 |
+
* in the Software without restriction, including without limitation the rights
|
19 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
20 |
+
* copies of the Software, and to permit persons to whom the Software is
|
21 |
+
* furnished to do so, subject to the following conditions:
|
22 |
+
*
|
23 |
+
* The above copyright notice and this permission notice shall be included in
|
24 |
+
* all copies or substantial portions of the Software.
|
25 |
+
*
|
26 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
27 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
28 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
29 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
30 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
31 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
32 |
+
* THE SOFTWARE.
|
33 |
+
*/
|
34 |
+
|
35 |
+
/**
|
36 |
+
* The reCAPTCHA server URL's
|
37 |
+
*/
|
38 |
+
define("RECAPTCHA_API_SERVER", "http://www.google.com/recaptcha/api");
|
39 |
+
define("RECAPTCHA_API_SECURE_SERVER", "https://www.google.com/recaptcha/api");
|
40 |
+
define("RECAPTCHA_VERIFY_SERVER", "www.google.com");
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Encodes the given data into a query string format
|
44 |
+
* @param $data - array of string elements to be encoded
|
45 |
+
* @return string - encoded request
|
46 |
+
*/
|
47 |
+
function _recaptcha_qsencode ($data) {
|
48 |
+
$req = "";
|
49 |
+
foreach ( $data as $key => $value )
|
50 |
+
$req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
|
51 |
+
|
52 |
+
// Cut the last '&'
|
53 |
+
$req=substr($req,0,strlen($req)-1);
|
54 |
+
return $req;
|
55 |
+
}
|
56 |
+
|
57 |
+
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Submits an HTTP POST to a reCAPTCHA server
|
61 |
+
* @param string $host
|
62 |
+
* @param string $path
|
63 |
+
* @param array $data
|
64 |
+
* @param int port
|
65 |
+
* @return array response
|
66 |
+
*/
|
67 |
+
function _recaptcha_http_post($host, $path, $data, $port = 80) {
|
68 |
+
|
69 |
+
$req = _recaptcha_qsencode ($data);
|
70 |
+
|
71 |
+
$http_request = "POST $path HTTP/1.0\r\n";
|
72 |
+
$http_request .= "Host: $host\r\n";
|
73 |
+
$http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
|
74 |
+
$http_request .= "Content-Length: " . strlen($req) . "\r\n";
|
75 |
+
$http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
|
76 |
+
$http_request .= "\r\n";
|
77 |
+
$http_request .= $req;
|
78 |
+
|
79 |
+
$response = '';
|
80 |
+
if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
|
81 |
+
die ('Could not open socket');
|
82 |
+
}
|
83 |
+
|
84 |
+
fwrite($fs, $http_request);
|
85 |
+
|
86 |
+
while ( !feof($fs) )
|
87 |
+
$response .= fgets($fs, 1160); // One TCP-IP packet
|
88 |
+
fclose($fs);
|
89 |
+
$response = explode("\r\n\r\n", $response, 2);
|
90 |
+
|
91 |
+
return $response;
|
92 |
+
}
|
93 |
+
|
94 |
+
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Gets the challenge HTML (javascript and non-javascript version).
|
98 |
+
* This is called from the browser, and the resulting reCAPTCHA HTML widget
|
99 |
+
* is embedded within the HTML form it was called from.
|
100 |
+
* @param string $pubkey A public key for reCAPTCHA
|
101 |
+
* @param string $error The error given by reCAPTCHA (optional, default is null)
|
102 |
+
* @param boolean $use_ssl Should the request be made over ssl? (optional, default is false)
|
103 |
+
* @return string - The HTML to be embedded in the user's form.
|
104 |
+
*/
|
105 |
+
function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
|
106 |
+
{
|
107 |
+
if ($pubkey == null || $pubkey == '') {
|
108 |
+
die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
|
109 |
+
}
|
110 |
+
|
111 |
+
if ($use_ssl) {
|
112 |
+
$server = RECAPTCHA_API_SECURE_SERVER;
|
113 |
+
} else {
|
114 |
+
$server = RECAPTCHA_API_SERVER;
|
115 |
+
}
|
116 |
+
|
117 |
+
$errorpart = "";
|
118 |
+
if ($error) {
|
119 |
+
$errorpart = "&error=" . $error;
|
120 |
+
}
|
121 |
+
return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script>
|
122 |
+
|
123 |
+
<noscript>
|
124 |
+
<iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/>
|
125 |
+
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
|
126 |
+
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
|
127 |
+
</noscript>';
|
128 |
+
}
|
129 |
+
|
130 |
+
|
131 |
+
|
132 |
+
|
133 |
+
/**
|
134 |
+
* A ReCaptchaResponse is returned from recaptcha_check_answer()
|
135 |
+
*/
|
136 |
+
class ReCaptchaResponse {
|
137 |
+
var $is_valid;
|
138 |
+
var $error;
|
139 |
+
}
|
140 |
+
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Calls an HTTP POST function to verify if the user's guess was correct
|
144 |
+
* @param string $privkey
|
145 |
+
* @param string $remoteip
|
146 |
+
* @param string $challenge
|
147 |
+
* @param string $response
|
148 |
+
* @param array $extra_params an array of extra variables to post to the server
|
149 |
+
* @return ReCaptchaResponse
|
150 |
+
*/
|
151 |
+
function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
|
152 |
+
{
|
153 |
+
if ($privkey == null || $privkey == '') {
|
154 |
+
die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
|
155 |
+
}
|
156 |
+
|
157 |
+
if ($remoteip == null || $remoteip == '') {
|
158 |
+
die ("For security reasons, you must pass the remote ip to reCAPTCHA");
|
159 |
+
}
|
160 |
+
|
161 |
+
|
162 |
+
|
163 |
+
//discard spam submissions
|
164 |
+
if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
|
165 |
+
$recaptcha_response = new ReCaptchaResponse();
|
166 |
+
$recaptcha_response->is_valid = false;
|
167 |
+
$recaptcha_response->error = 'incorrect-captcha-sol';
|
168 |
+
return $recaptcha_response;
|
169 |
+
}
|
170 |
+
|
171 |
+
$response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
|
172 |
+
array (
|
173 |
+
'privatekey' => $privkey,
|
174 |
+
'remoteip' => $remoteip,
|
175 |
+
'challenge' => $challenge,
|
176 |
+
'response' => $response
|
177 |
+
) + $extra_params
|
178 |
+
);
|
179 |
+
|
180 |
+
$answers = explode ("\n", $response [1]);
|
181 |
+
$recaptcha_response = new ReCaptchaResponse();
|
182 |
+
|
183 |
+
if (trim ($answers [0]) == 'true') {
|
184 |
+
$recaptcha_response->is_valid = true;
|
185 |
+
}
|
186 |
+
else {
|
187 |
+
$recaptcha_response->is_valid = false;
|
188 |
+
$recaptcha_response->error = $answers [1];
|
189 |
+
}
|
190 |
+
return $recaptcha_response;
|
191 |
+
|
192 |
+
}
|
193 |
+
|
194 |
+
/**
|
195 |
+
* gets a URL where the user can sign up for reCAPTCHA. If your application
|
196 |
+
* has a configuration page where you enter a key, you should provide a link
|
197 |
+
* using this function.
|
198 |
+
* @param string $domain The domain where the page is hosted
|
199 |
+
* @param string $appname The name of your application
|
200 |
+
*/
|
201 |
+
function recaptcha_get_signup_url ($domain = null, $appname = null) {
|
202 |
+
return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname));
|
203 |
+
}
|
204 |
+
|
205 |
+
function _recaptcha_aes_pad($val) {
|
206 |
+
$block_size = 16;
|
207 |
+
$numpad = $block_size - (strlen ($val) % $block_size);
|
208 |
+
return str_pad($val, strlen ($val) + $numpad, chr($numpad));
|
209 |
+
}
|
210 |
+
|
211 |
+
/* Mailhide related code */
|
212 |
+
|
213 |
+
function _recaptcha_aes_encrypt($val,$ky) {
|
214 |
+
if (! function_exists ("mcrypt_encrypt")) {
|
215 |
+
die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
|
216 |
+
}
|
217 |
+
$mode=MCRYPT_MODE_CBC;
|
218 |
+
$enc=MCRYPT_RIJNDAEL_128;
|
219 |
+
$val=_recaptcha_aes_pad($val);
|
220 |
+
return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
|
221 |
+
}
|
222 |
+
|
223 |
+
|
224 |
+
function _recaptcha_mailhide_urlbase64 ($x) {
|
225 |
+
return strtr(base64_encode ($x), '+/', '-_');
|
226 |
+
}
|
227 |
+
|
228 |
+
/* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
|
229 |
+
function recaptcha_mailhide_url($pubkey, $privkey, $email) {
|
230 |
+
if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) {
|
231 |
+
die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " .
|
232 |
+
"you can do so at <a href='http://www.google.com/recaptcha/mailhide/apikey'>http://www.google.com/recaptcha/mailhide/apikey</a>");
|
233 |
+
}
|
234 |
+
|
235 |
+
|
236 |
+
$ky = pack('H*', $privkey);
|
237 |
+
$cryptmail = _recaptcha_aes_encrypt ($email, $ky);
|
238 |
+
|
239 |
+
return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
|
240 |
+
}
|
241 |
+
|
242 |
+
/**
|
243 |
+
* gets the parts of the email to expose to the user.
|
244 |
+
* eg, given johndoe@example,com return ["john", "example.com"].
|
245 |
+
* the email is then displayed as john...@example.com
|
246 |
+
*/
|
247 |
+
function _recaptcha_mailhide_email_parts ($email) {
|
248 |
+
$arr = preg_split("/@/", $email );
|
249 |
+
|
250 |
+
if (strlen ($arr[0]) <= 4) {
|
251 |
+
$arr[0] = substr ($arr[0], 0, 1);
|
252 |
+
} else if (strlen ($arr[0]) <= 6) {
|
253 |
+
$arr[0] = substr ($arr[0], 0, 3);
|
254 |
+
} else {
|
255 |
+
$arr[0] = substr ($arr[0], 0, 4);
|
256 |
+
}
|
257 |
+
return $arr;
|
258 |
+
}
|
259 |
+
|
260 |
+
/**
|
261 |
+
* Gets html to display an email address given a public an private key.
|
262 |
+
* to get a key, go to:
|
263 |
+
*
|
264 |
+
* http://www.google.com/recaptcha/mailhide/apikey
|
265 |
+
*/
|
266 |
+
function recaptcha_mailhide_html($pubkey, $privkey, $email) {
|
267 |
+
$emailparts = _recaptcha_mailhide_email_parts ($email);
|
268 |
+
$url = recaptcha_mailhide_url ($pubkey, $privkey, $email);
|
269 |
+
|
270 |
+
return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) .
|
271 |
+
"' onclick=\"window.open('" . htmlentities ($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities ($emailparts [1]);
|
272 |
+
|
273 |
+
}
|
274 |
+
|
275 |
+
|
276 |
+
?>
|
package.xml
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>contactsformcaptcha</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://opensource.org/licenses/OSL-3.0">OSL v3.0</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Add captcha to "Contact Us" form.</summary>
|
10 |
+
<description>"Contacts Form Captcha" extension add in easy way the captcha to "Contact Us" form.
|
11 |
+

|
12 |
+
This extension uses reCaptcha library (http://www.google.com/recaptcha).</description>
|
13 |
+
<notes>"Contacts Form Captcha" extension add in easy way the captcha to "Contact Us" form.</notes>
|
14 |
+
<authors><author><name>Oleg Koval</name><user>auto-converted</user><email>oleh.koval@gmail.com</email></author></authors>
|
15 |
+
<date>2012-10-09</date>
|
16 |
+
<time>07:07:21</time>
|
17 |
+
<contents><target name="magecommunity"><dir name="OlegKoval"><dir name="ContactsFormCaptcha"><dir name="controllers"><file name="IndexController.php" hash="08f4e53fd3aa9707e8c72ef079dc034f"/></dir><dir name="etc"><file name="config.xml" hash="5554c3b28b769a95f1f4618a63a47883"/><file name="system.xml" hash="dfafc3f4c35dcebbce3724a1125f9d23"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="OlegKoval_ContactsFormCaptcha.xml" hash="9b7cbc1587fc43d6a0cd1106bc19a4fc"/></dir></target><target name="magelocale"><dir name="en_US"><file name="OlegKoval_ContactsFormCaptcha.csv" hash="a13e19dd1a4af77cf79394ca43f6bc0f"/></dir></target><target name="magelib"><dir name="reCaptcha"><file name="recaptchalib.php" hash="f80a9f01727de68aba8e98f1e37345a9"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="contactsformcaptcha.xml" hash="797d1d456b4f7e6d4bdbb4308065b5fa"/></dir><dir name="template"><dir name="contactsformcaptcha"><file name="form.phtml" hash="9b55935c7c91b9a53d99c5f8ef55285d"/></dir></dir></dir></dir></dir></target></contents>
|
18 |
+
<compatible/>
|
19 |
+
<dependencies/>
|
20 |
+
</package>
|