Source Code Documentation


pro\s2member-pro\includes\classes\gateways\paypal\paypal-registration-in.inc.php


  1. <?php
  2. /**
  3. * PayPal® Registration Form (inner processing routines).
  4. *
  5. * Copyright: © 2009-2011
  6. * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
  7. * (coded in the USA)
  8. *
  9. * This WordPress® plugin (s2Member Pro) is comprised of two parts:
  10. *
  11. * o (1) Its PHP code is licensed under the GPL license, as is WordPress®.
  12. * You should have received a copy of the GNU General Public License,
  13. * along with this software. In the main directory, see: /licensing/
  14. * If not, see: {@link http://www.gnu.org/licenses/}.
  15. *
  16. * o (2) All other parts of (s2Member Pro); including, but not limited to:
  17. * the CSS code, some JavaScript code, images, and design;
  18. * are licensed according to the license purchased.
  19. * See: {@link http://www.s2member.com/prices/}
  20. *
  21. * Unless you have our prior written consent, you must NOT directly or indirectly license,
  22. * sub-license, sell, resell, or provide for free; part (2) of the s2Member Pro Module;
  23. * or make an offer to do any of these things. All of these things are strictly
  24. * prohibited with part (2) of the s2Member Pro Module.
  25. *
  26. * Your purchase of s2Member Pro includes free lifetime upgrades via s2Member.com
  27. * (i.e. new features, bug fixes, updates, improvements); along with full access
  28. * to our video tutorial library: {@link http://www.s2member.com/videos/}
  29. *
  30. * @package s2Member\PayPal
  31. * @since 1.5
  32. */
  33. if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
  34. exit("Do not access this file directly.");
  35.  
  36. if (!class_exists ("c_ws_plugin__s2member_pro_paypal_registration_in"))
  37. {
  38. /**
  39. * PayPal® Registration Form (inner processing routines).
  40. *
  41. * @package s2Member\PayPal
  42. * @since 1.5
  43. */
  44. class c_ws_plugin__s2member_pro_paypal_registration_in
  45. {
  46. /**
  47. * Handles processing of Pro Form registrations.
  48. *
  49. * @package s2Member\PayPal
  50. * @since 1.5
  51. *
  52. * @attaches-to ``add_action("init");``
  53. *
  54. * @return null Or exits script execution after a custom URL redirection.
  55. */
  56. public static function paypal_registration ()
  57. {
  58. if (!empty ($_POST["s2member_pro_paypal_registration"]["nonce"]) && ($nonce = $_POST["s2member_pro_paypal_registration"]["nonce"]) && wp_verify_nonce ($nonce, "s2member-pro-paypal-registration"))
  59. {
  60. $GLOBALS["ws_plugin__s2member_pro_paypal_registration_response"] = array (); // This holds the global response details.
  61. $global_response = &$GLOBALS["ws_plugin__s2member_pro_paypal_registration_response"]; // This is a shorter reference.
  62.  
  63. $post_vars = c_ws_plugin__s2member_utils_strings::trim_deep (stripslashes_deep ($_POST["s2member_pro_paypal_registration"]));
  64. $post_vars["attr"] = unserialize (c_ws_plugin__s2member_utils_encryption::decrypt ($post_vars["attr"])); // And run a Filter.
  65. $post_vars["attr"] = apply_filters ("ws_plugin__s2member_pro_paypal_registration_post_attr", $post_vars["attr"], get_defined_vars ());
  66.  
  67. $post_vars["recaptcha_challenge_field"] = (!$post_vars["recaptcha_challenge_field"]) ? trim (stripslashes ($_POST["recaptcha_challenge_field"])) : $post_vars["recaptcha_challenge_field"];
  68. $post_vars["recaptcha_response_field"] = (!$post_vars["recaptcha_response_field"]) ? trim (stripslashes ($_POST["recaptcha_response_field"])) : $post_vars["recaptcha_response_field"];
  69.  
  70. $post_vars["name"] = trim ($post_vars["first_name"] . " " . $post_vars["last_name"]);
  71. $post_vars["email"] = apply_filters ("user_registration_email", sanitize_email ($post_vars["email"]), get_defined_vars ());
  72. $post_vars["username"] = (is_multisite()) ? strtolower($post_vars["username"]) : $post_vars["username"]; // Force lowercase.
  73. $post_vars["username"] = preg_replace ("/\s+/", "", sanitize_user (($post_vars["_o_username"] = $post_vars["username"]), is_multisite ()));
  74.  
  75. if (!c_ws_plugin__s2member_pro_paypal_responses::paypal_form_attr_validation_errors ($post_vars["attr"])) // Must NOT have any attr errors.
  76. {
  77. if (!($error = c_ws_plugin__s2member_pro_paypal_responses::paypal_form_submission_validation_errors ("registration", $post_vars)))
  78. {
  79. if (!($create_user = array ())) // Build post fields for registration configuration, and then the creation array.
  80. {
  81. $_POST["ws_plugin__s2member_custom_reg_field_user_pass1"] = $post_vars["password1"]; // Fake this for registration configuration.
  82. $_POST["ws_plugin__s2member_custom_reg_field_first_name"] = $post_vars["first_name"]; // Fake this for registration configuration.
  83. $_POST["ws_plugin__s2member_custom_reg_field_last_name"] = $post_vars["last_name"]; // Fake this for registration configuration.
  84. $_POST["ws_plugin__s2member_custom_reg_field_opt_in"] = $post_vars["custom_fields"]["opt_in"]; // Fake this too.
  85.  
  86. if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"])
  87. foreach (json_decode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
  88. {
  89. $field_var = preg_replace ("/[^a-z0-9]/i", "_", strtolower ($field["id"]));
  90. $field_id_class = preg_replace ("/_/", "-", $field_var);
  91.  
  92. if (isset ($post_vars["custom_fields"][$field_var]))
  93. $_POST["ws_plugin__s2member_custom_reg_field_" . $field_var] = $post_vars["custom_fields"][$field_var];
  94. }
  95.  
  96. $GLOBALS["ws_plugin__s2member_registration_vars"]["ws_plugin__s2member_custom_reg_field_s2member_level"] = $post_vars["attr"]["level"];
  97. $GLOBALS["ws_plugin__s2member_registration_vars"]["ws_plugin__s2member_custom_reg_field_s2member_ccaps"] = $post_vars["attr"]["ccaps"];
  98. $GLOBALS["ws_plugin__s2member_registration_vars"]["ws_plugin__s2member_custom_reg_field_s2member_auto_eot_time"] = $post_vars["attr"]["tp"] . " " . $post_vars["attr"]["tt"];
  99. $_EOT_ = &$GLOBALS["ws_plugin__s2member_registration_vars"]["ws_plugin__s2member_custom_reg_field_s2member_auto_eot_time"]; // Quick/shorter reference to this var.
  100. $_EOT_ = ($post_vars["attr"]["tp"] && $post_vars["attr"]["tt"]) ? date ("Y-m-d H:i:s", c_ws_plugin__s2member_utils_time::auto_eot_time ("", "", "", $_EOT_)) : "";
  101. $GLOBALS["ws_plugin__s2member_registration_vars"]["ws_plugin__s2member_custom_reg_field_s2member_custom"] = $post_vars["attr"]["custom"];
  102. unset($_EOT_); // We can unset this shorter/reference variable now.
  103.  
  104. $GLOBALS["ws_plugin__s2member_registration_return_url"] = $post_vars["attr"]["success"]; // Custom success return.
  105.  
  106. $create_user["user_login"] = $post_vars["username"]; // Copy this into a separate array for `wp_create_user()`.
  107. $create_user["user_pass"] = wp_generate_password (); // Which may fire `c_ws_plugin__s2member_registrations::generate_password()`.
  108. $create_user["user_email"] = $post_vars["email"]; // Copy this into a separate array for `wp_create_user()`.
  109. }
  110.  
  111. if ($post_vars["password1"] && $post_vars["password1"] === $create_user["user_pass"]) // A custom Password is being used?
  112. {
  113. if (((is_multisite () && ($new__user_id = c_ws_plugin__s2member_registrations::ms_create_existing_user ($create_user["user_login"], $create_user["user_email"], $create_user["user_pass"]))) || ($new__user_id = wp_create_user ($create_user["user_login"], $create_user["user_pass"], $create_user["user_email"]))) && !is_wp_error ($new__user_id))
  114. {
  115. update_user_option ($new__user_id, "default_password_nag", false, true);
  116. wp_new_user_notification ($new__user_id, $create_user["user_pass"]);
  117.  
  118. $global_response = array ("response" => sprintf (_x ('<strong>Thank you.</strong> Please <a href="%s" rel="nofollow">login</a>.', "s2member-front", "s2member"), esc_attr (wp_login_url ())));
  119.  
  120. if ($post_vars["attr"]["success"] && substr ($GLOBALS["ws_plugin__s2member_registration_return_url"], 0, 2) === substr ($post_vars["attr"]["success"], 0, 2) && ($custom_success_url = str_ireplace (array ("%%s_response%%", /* Deprecated in v111106 ». */ "%%response%%"), array (urlencode (c_ws_plugin__s2member_utils_encryption::encrypt ($global_response["response"])), urlencode ($global_response["response"])), $GLOBALS["ws_plugin__s2member_registration_return_url"])) && ($custom_success_url = trim (preg_replace ("/%%(.+?)%%/i", "", $custom_success_url))))
  121. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig ($custom_success_url, "s2p-v")) . exit ();
  122. }
  123. else // Else, an error reponse should be given.
  124. {
  125. $global_response = array ("response" => _x ('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true);
  126. }
  127. }
  128. else // Otherwise, they'll need to check their email for the auto-generated Password.
  129. {
  130. if (((is_multisite () && ($new__user_id = c_ws_plugin__s2member_registrations::ms_create_existing_user ($create_user["user_login"], $create_user["user_email"], $create_user["user_pass"]))) || ($new__user_id = wp_create_user ($create_user["user_login"], $create_user["user_pass"], $create_user["user_email"]))) && !is_wp_error ($new__user_id))
  131. {
  132. update_user_option ($new__user_id, "default_password_nag", true, true);
  133. wp_new_user_notification ($new__user_id, $create_user["user_pass"]);
  134.  
  135. $global_response = array ("response" => _x ('<strong>Thank you.</strong> You\'ll receive an email momentarily.', "s2member-front", "s2member"));
  136.  
  137. if ($post_vars["attr"]["success"] && substr ($GLOBALS["ws_plugin__s2member_registration_return_url"], 0, 2) === substr ($post_vars["attr"]["success"], 0, 2) && ($custom_success_url = str_ireplace (array ("%%s_response%%", /* Deprecated in v111106 ». */ "%%response%%"), array (urlencode (c_ws_plugin__s2member_utils_encryption::encrypt ($global_response["response"])), urlencode ($global_response["response"])), $GLOBALS["ws_plugin__s2member_registration_return_url"])) && ($custom_success_url = trim (preg_replace ("/%%(.+?)%%/i", "", $custom_success_url))))
  138. wp_redirect(c_ws_plugin__s2member_utils_urls::add_s2member_sig ($custom_success_url, "s2p-v")) . exit ();
  139. }
  140. else // Else, an error reponse should be given.
  141. {
  142. $global_response = array ("response" => _x ('<strong>Oops.</strong> A slight problem. Please contact Support for assistance.', "s2member-front", "s2member"), "error" => true);
  143. }
  144. }
  145. }
  146. else // Else, an error.
  147. {
  148. $global_response = $error;
  149. }
  150. }
  151. }
  152. }
  153. }
  154. }
  155. ?>

pro\s2member-pro\includes\classes\gateways\paypal\paypal-registration-in.inc.php

Source Code Documentation