PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 110815
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v110815
260913 260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 120219 All 188 releases
s2member / includes / classes / utils-captchas.inc.php

utils-captchas.inc.php in s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions 110815, at includes/classes/utils-captchas.inc.php

69 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Captcha utilities.
4 *
5 * Copyright: © 2009-2011
6 * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
7 * ( coded in the USA )
8 *
9 * Released under the terms of the GNU General Public License.
10 * You should have received a copy of the GNU General Public License,
11 * along with this software. In the main directory, see: /licensing/
12 * If not, see: {@link http://www.gnu.org/licenses/}.
13 *
14 * @package s2Member\Utilities
15 * @since 3.5
16 */
17 if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
18 exit("Do not access this file directly.");
19 /**/
20 if (!class_exists ("c_ws_plugin__s2member_utils_captchas"))
21 {
22 /**
23 * Captcha utilities.
24 *
25 * @package s2Member\Utilities
26 * @since 3.5
27 */
28 class c_ws_plugin__s2member_utils_captchas
29 {
30 /**
31 * Verifies a reCaptcha code though a connection to Google®.
32 *
33 * @package s2Member\Utilities
34 * @since 3.5
35 *
36 * @param str $challenge The value of `recaptcha_challenge_field` during form submisson.
37 * @param str $response The value of `recaptcha_response_field` during form submission.
38 * @return bool True if ``$response`` is valid, else false.
39 */
40 public static function recaptcha_code_validates ($challenge = FALSE, $response = FALSE)
41 {
42 $post_vars = array ("privatekey" => $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["recaptcha"]["private_key"], "remoteip" => $_SERVER["REMOTE_ADDR"], "challenge" => $challenge, "response" => $response);
43 /**/
44 return preg_match ("/^true/i", trim (c_ws_plugin__s2member_utils_urls::remote ("http://www.google.com/recaptcha/api/verify", $post_vars)));
45 }
46 /**
47 * Builds a reCaptcha JavaScript `script` tag for display.
48 *
49 * @package s2Member\Utilities
50 * @since 3.5
51 *
52 * @param str $theme Optional. The theme used in display. Defaults to `clean`.
53 * @param str $tabindex Optional. Value of `tabindex=""` attribute. Defaults to `-1`.
54 * @param str $error Optional. An error message to display.
55 * @return str HTML markup for JavaScript tag.
56 */
57 public static function recaptcha_script_tag ($theme = FALSE, $tabindex = FALSE, $error = FALSE)
58 {
59 $theme = ($theme) ? $theme : "clean"; /* Defaults to the `clean` theme style. */
60 $tabindex = (strlen ($tabindex)) ? (int)$tabindex : -1; /* -1 default. */
61 /**/
62 $options = '<script type="text/javascript">' . "if(typeof RecaptchaOptions !== 'object'){ var RecaptchaOptions = {theme: '" . c_ws_plugin__s2member_utils_strings::esc_sq ($theme) . "', lang: '" . c_ws_plugin__s2member_utils_strings::esc_sq ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["recaptcha"]["lang"]) . "', tabindex: " . $tabindex . " }; }" . '</script>' . "\n";
63 $adjustments = '<script type="text/javascript">' . "if(typeof jQuery === 'function'){ jQuery('td a[id^=\"recaptcha\"]').removeAttr('tabindex'); }" . '</script>';
64 /**/
65 return $options . '<script type="text/javascript" src="' . esc_attr ('https://www.google.com/recaptcha/api/challenge?k=' . urlencode ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["recaptcha"]["public_key"])) . '' . (($error) ? '&amp;error=' . urlencode ($error) : '') . '"></script>' . $adjustments;
66 }
67 }
68 }
69 ?>