Version Description
Remove ALL possibility of conflicts with other plugins that also include Google reCAPTCHA library
Download this release
Release Info
Developer | megnicholas |
Plugin | Contact Form Clean and Simple |
Version | 4.2.2 |
Comparing to | |
See all releases |
Code changes from version 4.2.1 to 4.2.2
- class.cscf_contact.php +1 -1
- class.cscf_settings.php +1 -1
- clean-and-simple-contact-form-by-meg-nicholas.php +3 -6
- readme.txt +11 -1
- recaptcha-php-1.11/LICENSE +0 -22
- recaptcha-php-1.11/README +0 -7
- recaptcha-php-1.11/example-captcha.php +0 -37
- recaptcha-php-1.11/example-mailhide.php +0 -17
- recaptcha-php-1.11/recaptchalib.php → recaptchalib-1.11.php +18 -88
- views/contact-form.view.php +1 -1
class.cscf_contact.php
CHANGED
@@ -77,7 +77,7 @@ class cscf_Contact
|
|
77 |
|
78 |
if ($this->RecaptchaPublicKey <> '' && $this->RecaptchaPrivateKey <> '')
|
79 |
{
|
80 |
-
$resp =
|
81 |
|
82 |
if (!$resp->is_valid) $this->Errors['recaptcha'] = __('Sorry the code wasn\'t entered correctly please try again.','cleanandsimple');
|
83 |
}
|
77 |
|
78 |
if ($this->RecaptchaPublicKey <> '' && $this->RecaptchaPrivateKey <> '')
|
79 |
{
|
80 |
+
$resp = cscf_recaptcha_check_answer($this->RecaptchaPrivateKey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
|
81 |
|
82 |
if (!$resp->is_valid) $this->Errors['recaptcha'] = __('Sorry the code wasn\'t entered correctly please try again.','cleanandsimple');
|
83 |
}
|
class.cscf_settings.php
CHANGED
@@ -249,7 +249,7 @@ class cscf_settings
|
|
249 |
function print_section_info_recaptcha()
|
250 |
{
|
251 |
print __('Enter your reCAPTCHA settings below :','cleanandsimple');
|
252 |
-
print "<p>" . __('To use reCAPTCHA you must get an API key from','cleanandsimple')." <a target='_blank' href='" .
|
253 |
}
|
254 |
public
|
255 |
function print_section_info_message()
|
249 |
function print_section_info_recaptcha()
|
250 |
{
|
251 |
print __('Enter your reCAPTCHA settings below :','cleanandsimple');
|
252 |
+
print "<p>" . __('To use reCAPTCHA you must get an API key from','cleanandsimple')." <a target='_blank' href='" . cscf_recaptcha_get_signup_url($_SERVER['SERVER_NAME']). "'>Google reCAPTCHA</a></p>";
|
253 |
}
|
254 |
public
|
255 |
function print_section_info_message()
|
clean-and-simple-contact-form-by-meg-nicholas.php
CHANGED
@@ -7,7 +7,7 @@
|
|
7 |
Plugin Name: Clean and Simple Contact Form
|
8 |
Plugin URI: http://www.megnicholas.co.uk/wordpress-plugins/clean-and-simple-contact-form
|
9 |
Description: A clean and simple contact form with Google reCAPTCHA and Twitter Bootstrap markup.
|
10 |
-
Version: 4.2.
|
11 |
Author: Meghan Nicholas
|
12 |
Author URI: http://www.megnicholas.co.uk
|
13 |
License: GPLv2 or later
|
@@ -40,10 +40,7 @@ include ('class.cscf_contact.php');
|
|
40 |
include ('class.view.php');
|
41 |
include ('class.cscf_filters.php');
|
42 |
include ('ajax.php');
|
43 |
-
|
44 |
-
if ( ! function_exists("recaptcha_get_html") ) {
|
45 |
-
include ('recaptcha-php-1.11/recaptchalib.php');
|
46 |
-
}
|
47 |
|
48 |
if (!defined('CSCF_THEME_DIR')) define('CSCF_THEME_DIR', ABSPATH . 'wp-content/themes/' . get_template());
|
49 |
|
@@ -55,7 +52,7 @@ if (!defined('CSCF_PLUGIN_URL')) define('CSCF_PLUGIN_URL', WP_PLUGIN_URL . '/' .
|
|
55 |
|
56 |
if (!defined('CSCF_VERSION_KEY')) define('CSCF_VERSION_KEY', 'cscf_version');
|
57 |
|
58 |
-
if (!defined('CSCF_VERSION_NUM')) define('CSCF_VERSION_NUM', '4.2.
|
59 |
|
60 |
if (!defined('CSCF_OPTIONS_KEY')) define('CSCF_OPTIONS_KEY', 'cscf_options');
|
61 |
|
7 |
Plugin Name: Clean and Simple Contact Form
|
8 |
Plugin URI: http://www.megnicholas.co.uk/wordpress-plugins/clean-and-simple-contact-form
|
9 |
Description: A clean and simple contact form with Google reCAPTCHA and Twitter Bootstrap markup.
|
10 |
+
Version: 4.2.2
|
11 |
Author: Meghan Nicholas
|
12 |
Author URI: http://www.megnicholas.co.uk
|
13 |
License: GPLv2 or later
|
40 |
include ('class.view.php');
|
41 |
include ('class.cscf_filters.php');
|
42 |
include ('ajax.php');
|
43 |
+
include ('recaptchalib-1.11.php');
|
|
|
|
|
|
|
44 |
|
45 |
if (!defined('CSCF_THEME_DIR')) define('CSCF_THEME_DIR', ABSPATH . 'wp-content/themes/' . get_template());
|
46 |
|
52 |
|
53 |
if (!defined('CSCF_VERSION_KEY')) define('CSCF_VERSION_KEY', 'cscf_version');
|
54 |
|
55 |
+
if (!defined('CSCF_VERSION_NUM')) define('CSCF_VERSION_NUM', '4.2.2');
|
56 |
|
57 |
if (!defined('CSCF_OPTIONS_KEY')) define('CSCF_OPTIONS_KEY', 'cscf_options');
|
58 |
|
readme.txt
CHANGED
@@ -6,7 +6,7 @@ License URI: http://www.gnu.org/licenses/gpl.html
|
|
6 |
Tags: simple, contact, form, contact button, contact form, contact form plugin, contacts, contacts form plugin, contact me, feedback form, bootstrap, twitter, google, reCAPTCHA, ajax, secure
|
7 |
Requires at least: 3.3
|
8 |
Tested up to: 3.6.1
|
9 |
-
Stable tag: 4.2.
|
10 |
|
11 |
A clean and simple AJAX contact form with Google reCAPTCHA and Twitter Bootstrap markup.
|
12 |
|
@@ -173,7 +173,15 @@ This makes the form responsive to all types of media. If you want to have a fixe
|
|
173 |
Currently you may only have one contact form per page. You CAN however put the contact form on more than one page using the same shortcode.
|
174 |
Note that making changes to the settings will affect all implementations of the plugin across your site.
|
175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
== Changelog ==
|
|
|
|
|
177 |
= 4.2.1 =
|
178 |
* Fixed potential conflict with other themes or plugins that use Google reCAPTCHA. reCAPTCHA library is not loaded if it already loaded by another plugin or theme.
|
179 |
* Recaptcha library function is now used to generate the sign up url on the settings page. The site domain is passed into the url for convenience.
|
@@ -251,6 +259,8 @@ Polish thanks to Patryk Peas
|
|
251 |
|
252 |
|
253 |
== Upgrade Notice ==
|
|
|
|
|
254 |
= 4.2.1 =
|
255 |
Translation and housekeeping updates
|
256 |
= 4.2.0 =
|
6 |
Tags: simple, contact, form, contact button, contact form, contact form plugin, contacts, contacts form plugin, contact me, feedback form, bootstrap, twitter, google, reCAPTCHA, ajax, secure
|
7 |
Requires at least: 3.3
|
8 |
Tested up to: 3.6.1
|
9 |
+
Stable tag: 4.2.2
|
10 |
|
11 |
A clean and simple AJAX contact form with Google reCAPTCHA and Twitter Bootstrap markup.
|
12 |
|
173 |
Currently you may only have one contact form per page. You CAN however put the contact form on more than one page using the same shortcode.
|
174 |
Note that making changes to the settings will affect all implementations of the plugin across your site.
|
175 |
|
176 |
+
= Will this work with other plugins that use Google reCAPTCHA? =
|
177 |
+
Yes it will. HOWEVER, you cannot have more than one reCAPTCHA on a page. This is a constraint created by Google.
|
178 |
+
So for example, if your 'Contact Me' page has comments below it,
|
179 |
+
the reCAPTCHA for the contact form will be displayed correctly but not in the comments form below.
|
180 |
+
The comments form will never validate due to no supplied reCAPTCHA code.
|
181 |
+
|
182 |
== Changelog ==
|
183 |
+
* 4.2.2
|
184 |
+
* Recaptcha library has now been namespaced to 'cscf' to remove ALL possibility of conflicts with other plugins that also include this library.
|
185 |
= 4.2.1 =
|
186 |
* Fixed potential conflict with other themes or plugins that use Google reCAPTCHA. reCAPTCHA library is not loaded if it already loaded by another plugin or theme.
|
187 |
* Recaptcha library function is now used to generate the sign up url on the settings page. The site domain is passed into the url for convenience.
|
259 |
|
260 |
|
261 |
== Upgrade Notice ==
|
262 |
+
= 4.2.2 =
|
263 |
+
Remove ALL possibility of conflicts with other plugins that also include Google reCAPTCHA library
|
264 |
= 4.2.1 =
|
265 |
Translation and housekeeping updates
|
266 |
= 4.2.0 =
|
recaptcha-php-1.11/LICENSE
DELETED
@@ -1,22 +0,0 @@
|
|
1 |
-
Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
|
2 |
-
AUTHORS:
|
3 |
-
Mike Crawford
|
4 |
-
Ben Maurer
|
5 |
-
|
6 |
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 |
-
of this software and associated documentation files (the "Software"), to deal
|
8 |
-
in the Software without restriction, including without limitation the rights
|
9 |
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 |
-
copies of the Software, and to permit persons to whom the Software is
|
11 |
-
furnished to do so, subject to the following conditions:
|
12 |
-
|
13 |
-
The above copyright notice and this permission notice shall be included in
|
14 |
-
all copies or substantial portions of the Software.
|
15 |
-
|
16 |
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 |
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 |
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19 |
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 |
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 |
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 |
-
THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
recaptcha-php-1.11/README
DELETED
@@ -1,7 +0,0 @@
|
|
1 |
-
reCAPTCHA README
|
2 |
-
================
|
3 |
-
|
4 |
-
The reCAPTCHA PHP Lirary helps you use the reCAPTCHA API. Documentation
|
5 |
-
for this library can be found at
|
6 |
-
|
7 |
-
http://recaptcha.net/plugins/php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
recaptcha-php-1.11/example-captcha.php
DELETED
@@ -1,37 +0,0 @@
|
|
1 |
-
<html>
|
2 |
-
<body>
|
3 |
-
<form action="" method="post">
|
4 |
-
<?php
|
5 |
-
|
6 |
-
require_once('recaptchalib.php');
|
7 |
-
|
8 |
-
// Get a key from https://www.google.com/recaptcha/admin/create
|
9 |
-
$publickey = "";
|
10 |
-
$privatekey = "";
|
11 |
-
|
12 |
-
# the response from reCAPTCHA
|
13 |
-
$resp = null;
|
14 |
-
# the error code from reCAPTCHA, if any
|
15 |
-
$error = null;
|
16 |
-
|
17 |
-
# was there a reCAPTCHA response?
|
18 |
-
if ($_POST["recaptcha_response_field"]) {
|
19 |
-
$resp = recaptcha_check_answer ($privatekey,
|
20 |
-
$_SERVER["REMOTE_ADDR"],
|
21 |
-
$_POST["recaptcha_challenge_field"],
|
22 |
-
$_POST["recaptcha_response_field"]);
|
23 |
-
|
24 |
-
if ($resp->is_valid) {
|
25 |
-
echo "You got it!";
|
26 |
-
} else {
|
27 |
-
# set the error code so that we can display it
|
28 |
-
$error = $resp->error;
|
29 |
-
}
|
30 |
-
}
|
31 |
-
echo recaptcha_get_html($publickey, $error);
|
32 |
-
?>
|
33 |
-
<br/>
|
34 |
-
<input type="submit" value="submit" />
|
35 |
-
</form>
|
36 |
-
</body>
|
37 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
recaptcha-php-1.11/example-mailhide.php
DELETED
@@ -1,17 +0,0 @@
|
|
1 |
-
<html><body>
|
2 |
-
<?
|
3 |
-
require_once ("recaptchalib.php");
|
4 |
-
|
5 |
-
// get a key at http://www.google.com/recaptcha/mailhide/apikey
|
6 |
-
$mailhide_pubkey = '';
|
7 |
-
$mailhide_privkey = '';
|
8 |
-
|
9 |
-
?>
|
10 |
-
|
11 |
-
The Mailhide version of example@example.com is
|
12 |
-
<? echo recaptcha_mailhide_html ($mailhide_pubkey, $mailhide_privkey, "example@example.com"); ?>. <br>
|
13 |
-
|
14 |
-
The url for the email is:
|
15 |
-
<? echo recaptcha_mailhide_url ($mailhide_pubkey, $mailhide_privkey, "example@example.com"); ?> <br>
|
16 |
-
|
17 |
-
</body></html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
recaptcha-php-1.11/recaptchalib.php → recaptchalib-1.11.php
RENAMED
@@ -35,16 +35,16 @@
|
|
35 |
/**
|
36 |
* The reCAPTCHA server URL's
|
37 |
*/
|
38 |
-
define("
|
39 |
-
define("
|
40 |
-
define("
|
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
|
48 |
$req = "";
|
49 |
foreach ( $data as $key => $value )
|
50 |
$req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
|
@@ -64,9 +64,9 @@ function _recaptcha_qsencode ($data) {
|
|
64 |
* @param int port
|
65 |
* @return array response
|
66 |
*/
|
67 |
-
function
|
68 |
|
69 |
-
$req =
|
70 |
|
71 |
$http_request = "POST $path HTTP/1.0\r\n";
|
72 |
$http_request .= "Host: $host\r\n";
|
@@ -103,16 +103,16 @@ function _recaptcha_http_post($host, $path, $data, $port = 80) {
|
|
103 |
|
104 |
* @return string - The HTML to be embedded in the user's form.
|
105 |
*/
|
106 |
-
function
|
107 |
{
|
108 |
if ($pubkey == null || $pubkey == '') {
|
109 |
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>");
|
110 |
}
|
111 |
|
112 |
if ($use_ssl) {
|
113 |
-
$server =
|
114 |
} else {
|
115 |
-
$server =
|
116 |
}
|
117 |
|
118 |
$errorpart = "";
|
@@ -132,9 +132,9 @@ function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
|
|
132 |
|
133 |
|
134 |
/**
|
135 |
-
* A
|
136 |
*/
|
137 |
-
class
|
138 |
var $is_valid;
|
139 |
var $error;
|
140 |
}
|
@@ -147,9 +147,9 @@ class ReCaptchaResponse {
|
|
147 |
* @param string $challenge
|
148 |
* @param string $response
|
149 |
* @param array $extra_params an array of extra variables to post to the server
|
150 |
-
* @return
|
151 |
*/
|
152 |
-
function
|
153 |
{
|
154 |
if ($privkey == null || $privkey == '') {
|
155 |
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>");
|
@@ -163,13 +163,13 @@ function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $ex
|
|
163 |
|
164 |
//discard spam submissions
|
165 |
if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
|
166 |
-
$recaptcha_response = new
|
167 |
$recaptcha_response->is_valid = false;
|
168 |
$recaptcha_response->error = 'incorrect-captcha-sol';
|
169 |
return $recaptcha_response;
|
170 |
}
|
171 |
|
172 |
-
$response =
|
173 |
array (
|
174 |
'privatekey' => $privkey,
|
175 |
'remoteip' => $remoteip,
|
@@ -179,7 +179,7 @@ function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $ex
|
|
179 |
);
|
180 |
|
181 |
$answers = explode ("\n", $response [1]);
|
182 |
-
$recaptcha_response = new
|
183 |
|
184 |
if (trim ($answers [0]) == 'true') {
|
185 |
$recaptcha_response->is_valid = true;
|
@@ -199,78 +199,8 @@ function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $ex
|
|
199 |
* @param string $domain The domain where the page is hosted
|
200 |
* @param string $appname The name of your application
|
201 |
*/
|
202 |
-
function
|
203 |
-
return "https://www.google.com/recaptcha/admin/create?" .
|
204 |
-
}
|
205 |
-
|
206 |
-
function _recaptcha_aes_pad($val) {
|
207 |
-
$block_size = 16;
|
208 |
-
$numpad = $block_size - (strlen ($val) % $block_size);
|
209 |
-
return str_pad($val, strlen ($val) + $numpad, chr($numpad));
|
210 |
-
}
|
211 |
-
|
212 |
-
/* Mailhide related code */
|
213 |
-
|
214 |
-
function _recaptcha_aes_encrypt($val,$ky) {
|
215 |
-
if (! function_exists ("mcrypt_encrypt")) {
|
216 |
-
die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
|
217 |
-
}
|
218 |
-
$mode=MCRYPT_MODE_CBC;
|
219 |
-
$enc=MCRYPT_RIJNDAEL_128;
|
220 |
-
$val=_recaptcha_aes_pad($val);
|
221 |
-
return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
|
222 |
-
}
|
223 |
-
|
224 |
-
|
225 |
-
function _recaptcha_mailhide_urlbase64 ($x) {
|
226 |
-
return strtr(base64_encode ($x), '+/', '-_');
|
227 |
-
}
|
228 |
-
|
229 |
-
/* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
|
230 |
-
function recaptcha_mailhide_url($pubkey, $privkey, $email) {
|
231 |
-
if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) {
|
232 |
-
die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " .
|
233 |
-
"you can do so at <a href='http://www.google.com/recaptcha/mailhide/apikey'>http://www.google.com/recaptcha/mailhide/apikey</a>");
|
234 |
-
}
|
235 |
-
|
236 |
-
|
237 |
-
$ky = pack('H*', $privkey);
|
238 |
-
$cryptmail = _recaptcha_aes_encrypt ($email, $ky);
|
239 |
-
|
240 |
-
return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
|
241 |
-
}
|
242 |
-
|
243 |
-
/**
|
244 |
-
* gets the parts of the email to expose to the user.
|
245 |
-
* eg, given johndoe@example,com return ["john", "example.com"].
|
246 |
-
* the email is then displayed as john...@example.com
|
247 |
-
*/
|
248 |
-
function _recaptcha_mailhide_email_parts ($email) {
|
249 |
-
$arr = preg_split("/@/", $email );
|
250 |
-
|
251 |
-
if (strlen ($arr[0]) <= 4) {
|
252 |
-
$arr[0] = substr ($arr[0], 0, 1);
|
253 |
-
} else if (strlen ($arr[0]) <= 6) {
|
254 |
-
$arr[0] = substr ($arr[0], 0, 3);
|
255 |
-
} else {
|
256 |
-
$arr[0] = substr ($arr[0], 0, 4);
|
257 |
-
}
|
258 |
-
return $arr;
|
259 |
-
}
|
260 |
-
|
261 |
-
/**
|
262 |
-
* Gets html to display an email address given a public an private key.
|
263 |
-
* to get a key, go to:
|
264 |
-
*
|
265 |
-
* http://www.google.com/recaptcha/mailhide/apikey
|
266 |
-
*/
|
267 |
-
function recaptcha_mailhide_html($pubkey, $privkey, $email) {
|
268 |
-
$emailparts = _recaptcha_mailhide_email_parts ($email);
|
269 |
-
$url = recaptcha_mailhide_url ($pubkey, $privkey, $email);
|
270 |
-
|
271 |
-
return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) .
|
272 |
-
"' 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]);
|
273 |
-
|
274 |
}
|
275 |
|
276 |
|
35 |
/**
|
36 |
* The reCAPTCHA server URL's
|
37 |
*/
|
38 |
+
define("CSCF_RECAPTCHA_API_SERVER", "http://www.google.com/recaptcha/api");
|
39 |
+
define("CSCF_RECAPTCHA_API_SECURE_SERVER", "https://www.google.com/recaptcha/api");
|
40 |
+
define("CSCF_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 _cscf_recaptcha_qsencode ($data) {
|
48 |
$req = "";
|
49 |
foreach ( $data as $key => $value )
|
50 |
$req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
|
64 |
* @param int port
|
65 |
* @return array response
|
66 |
*/
|
67 |
+
function _cscf_recaptcha_http_post($host, $path, $data, $port = 80) {
|
68 |
|
69 |
+
$req = _cscf_recaptcha_qsencode ($data);
|
70 |
|
71 |
$http_request = "POST $path HTTP/1.0\r\n";
|
72 |
$http_request .= "Host: $host\r\n";
|
103 |
|
104 |
* @return string - The HTML to be embedded in the user's form.
|
105 |
*/
|
106 |
+
function cscf_recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
|
107 |
{
|
108 |
if ($pubkey == null || $pubkey == '') {
|
109 |
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>");
|
110 |
}
|
111 |
|
112 |
if ($use_ssl) {
|
113 |
+
$server = CSCF_RECAPTCHA_API_SECURE_SERVER;
|
114 |
} else {
|
115 |
+
$server = CSCF_RECAPTCHA_API_SERVER;
|
116 |
}
|
117 |
|
118 |
$errorpart = "";
|
132 |
|
133 |
|
134 |
/**
|
135 |
+
* A cscf_ReCaptchaResponse is returned from cscf_recaptcha_check_answer()
|
136 |
*/
|
137 |
+
class cscf_ReCaptchaResponse {
|
138 |
var $is_valid;
|
139 |
var $error;
|
140 |
}
|
147 |
* @param string $challenge
|
148 |
* @param string $response
|
149 |
* @param array $extra_params an array of extra variables to post to the server
|
150 |
+
* @return cscf_ReCaptchaResponse
|
151 |
*/
|
152 |
+
function cscf_recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
|
153 |
{
|
154 |
if ($privkey == null || $privkey == '') {
|
155 |
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>");
|
163 |
|
164 |
//discard spam submissions
|
165 |
if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
|
166 |
+
$recaptcha_response = new cscf_ReCaptchaResponse();
|
167 |
$recaptcha_response->is_valid = false;
|
168 |
$recaptcha_response->error = 'incorrect-captcha-sol';
|
169 |
return $recaptcha_response;
|
170 |
}
|
171 |
|
172 |
+
$response = _cscf_recaptcha_http_post (CSCF_RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
|
173 |
array (
|
174 |
'privatekey' => $privkey,
|
175 |
'remoteip' => $remoteip,
|
179 |
);
|
180 |
|
181 |
$answers = explode ("\n", $response [1]);
|
182 |
+
$recaptcha_response = new cscf_ReCaptchaResponse();
|
183 |
|
184 |
if (trim ($answers [0]) == 'true') {
|
185 |
$recaptcha_response->is_valid = true;
|
199 |
* @param string $domain The domain where the page is hosted
|
200 |
* @param string $appname The name of your application
|
201 |
*/
|
202 |
+
function cscf_recaptcha_get_signup_url ($domain = null, $appname = null) {
|
203 |
+
return "https://www.google.com/recaptcha/admin/create?" . _cscf_recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
}
|
205 |
|
206 |
|
views/contact-form.view.php
CHANGED
@@ -112,7 +112,7 @@
|
|
112 |
<div class="control-group form-group<?php
|
113 |
if (isset($contact->Errors['recaptcha'])) echo ' error'; ?>">
|
114 |
<div id="recaptcha_div">
|
115 |
-
<?php echo
|
116 |
<div for="cscf_recaptcha" class="help-block has-error error"><?php if (isset($contact->Errors['recaptcha'])) echo $contact->Errors['recaptcha']; ?></div>
|
117 |
</div>
|
118 |
</div>
|
112 |
<div class="control-group form-group<?php
|
113 |
if (isset($contact->Errors['recaptcha'])) echo ' error'; ?>">
|
114 |
<div id="recaptcha_div">
|
115 |
+
<?php echo cscf_recaptcha_get_html($contact->RecaptchaPublicKey,null,isset($_SERVER['HTTPS'])); ?>
|
116 |
<div for="cscf_recaptcha" class="help-block has-error error"><?php if (isset($contact->Errors['recaptcha'])) echo $contact->Errors['recaptcha']; ?></div>
|
117 |
</div>
|
118 |
</div>
|