PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 120213
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v120213
260917 260913 260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 All 189 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 120213, at includes/classes/utils-captchas.inc.php

87 lines 3.8 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 * Public/private keys to use for reCAPTCHA™.
32 *
33 * @package s2Member\Utilities
34 * @since 111203
35 *
36 * @return array An array with with two elements: `public` and `private`.
37 */
38 public static function recaptcha_keys ()
39 {
40 $public = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["recaptcha"]["public_key"];
41 $private = /* Private key. */ $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["recaptcha"]["private_key"];
42 /**/
43 return apply_filters ("ws_plugin__s2member_recaptcha_keys", array ("public" => $public, "private" => $private), get_defined_vars ());
44 }
45 /**
46 * Verifies a reCAPTCHA™ code via Google®.
47 *
48 * @package s2Member\Utilities
49 * @since 3.5
50 *
51 * @param str $challenge The value of `recaptcha_challenge_field` during form submisson.
52 * @param str $response The value of `recaptcha_response_field` during form submission.
53 * @return bool True if ``$response`` is valid, else false.
54 */
55 public static function recaptcha_code_validates ($challenge = FALSE, $response = FALSE)
56 {
57 $keys = c_ws_plugin__s2member_utils_captchas::recaptcha_keys ();
58 $post_vars = array ("privatekey" => $keys["private"], "remoteip" => $_SERVER["REMOTE_ADDR"], "challenge" => $challenge, "response" => $response);
59 /**/
60 return preg_match ("/^true/i", trim (c_ws_plugin__s2member_utils_urls::remote ("http://www.google.com/recaptcha/api/verify", $post_vars)));
61 }
62 /**
63 * Builds a reCAPTCHA™ JavaScript `script` tag for display.
64 *
65 * @package s2Member\Utilities
66 * @since 3.5
67 *
68 * @param str $theme Optional. The theme used in display. Defaults to `clean`.
69 * @param str $tabindex Optional. Value of `tabindex=""` attribute. Defaults to `-1`.
70 * @param str $error Optional. An error message to display.
71 * @return str HTML markup for JavaScript tag.
72 */
73 public static function recaptcha_script_tag ($theme = FALSE, $tabindex = FALSE, $error = FALSE)
74 {
75 $theme = ($theme) ? $theme : "clean";
76 $tabindex = (strlen ($tabindex)) ? (int)$tabindex : -1;
77 $keys = c_ws_plugin__s2member_utils_captchas::recaptcha_keys ();
78 /**/
79 $options = '<script type="text/javascript">' . "if(typeof RecaptchaOptions !== 'object'){ var RecaptchaOptions = {theme: '" . c_ws_plugin__s2member_utils_strings::esc_js_sq ($theme) . "', lang: '" . c_ws_plugin__s2member_utils_strings::esc_js_sq ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["recaptcha"]["lang"]) . "', tabindex: " . $tabindex . " }; }" . '</script>' . "\n";
80 $no_tabindex_icons = '<script type="text/javascript">' . "if(typeof jQuery === 'function'){ jQuery('td a[id^=\"recaptcha\"]').removeAttr('tabindex'); }" . '</script>';
81 $adjustments = (!apply_filters ("c_ws_plugin__s2member_utils_tabindex_recaptcha_icons", false, get_defined_vars ())) ? $no_tabindex_icons : "";
82 /**/
83 return $options . '<script type="text/javascript" src="' . esc_attr ('https://www.google.com/recaptcha/api/challenge?k=' . urlencode ($keys["public"])) . '' . (($error) ? '&amp;error=' . urlencode ($error) : '') . '"></script>' . $adjustments;
84 }
85 }
86 }
87 ?>