PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/s2member/includes/classes/paypal-return-in-wa-ccaps-wo-level.inc.php

https://gitlab.com/Gashler/dp
PHP | 201 lines | 143 code | 26 blank | 32 comment | 67 complexity | 5c4a4e6c757fab45e93e09501844099f MD5 | raw file
  1. <?php
  2. /**
  3. * s2Member's PayPal® Auto-Return/PDT handler (inner processing routine).
  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\PayPal
  15. * @since 110720
  16. */
  17. if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
  18. exit("Do not access this file directly.");
  19. if (!class_exists ("c_ws_plugin__s2member_paypal_return_in_wa_ccaps_wo_level"))
  20. {
  21. /**
  22. * s2Member's PayPal® Auto-Return/PDT handler (inner processing routine).
  23. *
  24. * @package s2Member\PayPal
  25. * @since 110720
  26. */
  27. class c_ws_plugin__s2member_paypal_return_in_wa_ccaps_wo_level
  28. {
  29. /**
  30. * s2Member's PayPal® Auto-Return/PDT handler (inner processing routine).
  31. *
  32. * @package s2Member\PayPal
  33. * @since 110720
  34. *
  35. * @param array $vars Required. An array of defined variables passed by {@link s2Member\PayPal\c_ws_plugin__s2member_paypal_return_in::paypal_return()}.
  36. * @return array|bool The original ``$paypal`` array passed in (extracted) from ``$vars``, or false when conditions do NOT apply.
  37. *
  38. * @todo Optimize with ``empty()`` and ``isset()``.
  39. */
  40. public static function /* Conditional phase for ``c_ws_plugin__s2member_paypal_notify_in::paypal_notify()``. */ cp ($vars = array ())
  41. {
  42. extract /* Extract all vars passed in from: ``c_ws_plugin__s2member_paypal_notify_in::paypal_notify()``. */($vars);
  43. if ((!empty ($paypal["txn_type"]) && preg_match ("/^web_accept$/i", $paypal["txn_type"]))
  44. && (!empty ($paypal["item_number"]) && preg_match ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["membership_item_number_wo_level_regex"], $paypal["item_number"]))
  45. && (empty ($paypal["payment_status"]) || empty ($payment_status_issues) || !preg_match ($payment_status_issues, $paypal["payment_status"]))
  46. && (!empty ($paypal["txn_id"]) && ($paypal["subscr_id"] = $paypal["txn_id"])) && (!empty ($paypal["payer_email"])))
  47. {
  48. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  49. do_action ("ws_plugin__s2member_during_paypal_return_before_new_ccaps", get_defined_vars ());
  50. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  51. if (!get_transient ($transient_rtn = "s2m_rtn_" . md5 ("s2member_transient_" . $_paypal_s)) && set_transient ($transient_rtn, time (), 31556926 * 10))
  52. {
  53. $paypal["s2member_log"][] = "s2Member `txn_type` identified as ( `web_accept` ) w/ update vars for Capabilities w/o Level.";
  54. list ($paypal["level"], $paypal["ccaps"], $paypal["eotper"]) = preg_split ("/\:/", $paypal["item_number"], 3);
  55. $paypal["ip"] = (preg_match ("/ip address/i", $paypal["option_name2"]) && $paypal["option_selection2"]) ? $paypal["option_selection2"] : "";
  56. $paypal["ip"] = (!$paypal["ip"] && preg_match ("/^[a-z0-9]+~[0-9\.]+$/i", $paypal["invoice"])) ? preg_replace ("/^[a-z0-9]+~/i", "", $paypal["invoice"]) : $paypal["ip"];
  57. $paypal["ip"] = (!$paypal["ip"] && $_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : $paypal["ip"];
  58. if /* Must have this information for Capability additions. */ (preg_match ("/(referenc|associat|updat|upgrad)/i", $paypal["option_name1"]) && $paypal["option_selection1"])
  59. {
  60. if (($user_id = c_ws_plugin__s2member_utils_users::get_user_id_with ($paypal["txn_id"], $paypal["option_selection1"])) && is_object ($user = new WP_User ($user_id)) && $user->ID)
  61. {
  62. if /* Do NOT process this routine on Administrators. */ (!$user->has_cap ("administrator"))
  63. {
  64. $processing = $during = /* Yes, we ARE processing this. */ true;
  65. $fields = /* These will be needed in the routines below. */ get_user_option ("s2member_custom_fields", $user_id);
  66. $user_reg_ip = /* Original IP during Registration. */ get_user_option ("s2member_registration_ip", $user_id);
  67. $user_reg_ip = $paypal["ip"] = /* Now merge conditionally. */ ($user_reg_ip) ? $user_reg_ip : $paypal["ip"];
  68. if (is_multisite () && !is_user_member_of_blog ($user_id) /* Must have a Role on this Blog. */)
  69. {
  70. add_existing_user_to_blog(array ("user_id" => $user_id, "role" => get_option ("default_role")));
  71. $user = new WP_User ($user_id);
  72. }
  73. if ($paypal["ccaps"] && preg_match ("/^-all/", str_replace ("+", "", $paypal["ccaps"])))
  74. foreach ($user->allcaps as $cap => $cap_enabled)
  75. if (preg_match ("/^access_s2member_ccap_/", $cap))
  76. $user->remove_cap ($ccap = $cap);
  77. if ($paypal["ccaps"] && preg_replace ("/^-all[\r\n\t\s;,]*/", "", str_replace ("+", "", $paypal["ccaps"])))
  78. foreach (preg_split ("/[\r\n\t\s;,]+/", preg_replace ("/^-all[\r\n\t\s;,]*/", "", str_replace ("+", "", $paypal["ccaps"]))) as $ccap)
  79. if (strlen ($ccap = trim (strtolower (preg_replace ("/[^a-z_0-9]/i", "", $ccap)))))
  80. $user->add_cap ("access_s2member_ccap_" . $ccap);
  81. if (!get_user_option ("s2member_registration_ip", $user_id))
  82. update_user_option ($user_id, "s2member_registration_ip", $paypal["ip"]);
  83. $paypal["s2member_log"][] = "s2Member Custom Capabilities updated w/ advanced update routines.";
  84. setcookie ("s2member_tracking", ($s2member_tracking = c_ws_plugin__s2member_utils_encryption::encrypt ($paypal["subscr_id"])), time () + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie ("s2member_tracking", $s2member_tracking, time () + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN) . ($_COOKIE["s2member_tracking"] = $s2member_tracking);
  85. $paypal["s2member_log"][] = "Transient Tracking Cookie set on ( `web_accept` ) w/ update vars for Capabilities w/o Level.";
  86. if ($processing && ($code = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["ccap_tracking_codes"]) && is_array ($cv = preg_split ("/\|/", $paypal["custom"])))
  87. {
  88. if (($code = preg_replace ("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $code)) && ($code = preg_replace ("/%%subscr_id%%/i", c_ws_plugin__s2member_utils_strings::esc_ds ($paypal["subscr_id"]), $code)))
  89. if (($code = preg_replace ("/%%amount%%/i", c_ws_plugin__s2member_utils_strings::esc_ds ($paypal["mc_gross"]), $code)) && ($code = preg_replace ("/%%txn_id%%/i", c_ws_plugin__s2member_utils_strings::esc_ds ($paypal["txn_id"]), $code)))
  90. if (($code = preg_replace ("/%%item_number%%/i", c_ws_plugin__s2member_utils_strings::esc_ds ($paypal["item_number"]), $code)) && ($code = preg_replace ("/%%item_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds ($paypal["item_name"]), $code)))
  91. if (($code = preg_replace ("/%%first_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds ($paypal["first_name"]), $code)) && ($code = preg_replace ("/%%last_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds ($paypal["last_name"]), $code)))
  92. if (($code = preg_replace ("/%%full_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds (trim ($paypal["first_name"] . " " . $paypal["last_name"])), $code)))
  93. if (($code = preg_replace ("/%%payer_email%%/i", c_ws_plugin__s2member_utils_strings::esc_ds ($paypal["payer_email"]), $code)))
  94. {
  95. if (($code = preg_replace ("/%%user_first_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds ($user->first_name), $code)) && ($code = preg_replace ("/%%user_last_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds ($user->last_name), $code)))
  96. if (($code = preg_replace ("/%%user_full_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds (trim ($user->first_name . " " . $user->last_name)), $code)))
  97. if (($code = preg_replace ("/%%user_email%%/i", c_ws_plugin__s2member_utils_strings::esc_ds ($user->user_email), $code)))
  98. if (($code = preg_replace ("/%%user_login%%/i", c_ws_plugin__s2member_utils_strings::esc_ds ($user->user_login), $code)))
  99. if (($code = preg_replace ("/%%user_ip%%/i", c_ws_plugin__s2member_utils_strings::esc_ds ($user_reg_ip), $code)))
  100. if (($code = preg_replace ("/%%user_id%%/i", c_ws_plugin__s2member_utils_strings::esc_ds ($user_id), $code)))
  101. {
  102. if (is_array ($fields) && !empty ($fields))
  103. foreach /* Custom Registration/Profile Fields. */ ($fields as $var => $val)
  104. if (!($code = preg_replace ("/%%" . preg_quote ($var, "/") . "%%/i", c_ws_plugin__s2member_utils_strings::esc_ds (maybe_serialize ($val)), $code)))
  105. break;
  106. if (($code = trim (preg_replace ("/%%(.+?)%%/i", "", $code))) /* This gets stored into a Transient Queue. */)
  107. {
  108. $paypal["s2member_log"][] = "Storing Payment Tracking Codes into a Transient Queue. These will be processed on-site.";
  109. set_transient ("s2m_" . md5 ("s2member_transient_ccap_tracking_codes_" . $paypal["txn_id"]), $code, 43200);
  110. }
  111. }
  112. }
  113. }
  114. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  115. do_action ("ws_plugin__s2member_during_paypal_return_during_new_ccaps", get_defined_vars ());
  116. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  117. if (($redirection_url_after_capabilities = apply_filters ("ws_plugin__s2member_redirection_url_after_capabilities", false, get_defined_vars ())))
  118. {
  119. $paypal["s2member_log"][] = "Redirecting Customer to a custom URL after Capabilities: " . $redirection_url_after_capabilities;
  120. wp_redirect($redirection_url_after_capabilities);
  121. }
  122. else // Else, use standard/default handling in this scenario. Have the Customer log in again.
  123. {
  124. $paypal["s2member_log"][] = "Redirecting Customer to the Login Page (after displaying a quick thank-you message). They need to log back in.";
  125. echo c_ws_plugin__s2member_return_templates::return_template ($paypal["subscr_gateway"],
  126. '<strong>' . _x ("Thank you! You now have access to:", "s2member-front", "s2member") . '<br /><em>' . esc_html ($paypal["item_name"]) . '</em></strong>',
  127. _x ("Please Log Back In (Click Here)", "s2member-front", "s2member"), wp_login_url ());
  128. }
  129. }
  130. else // Unable to add new Capabilities. The existing User ID is associated with an Administrator. Stopping here.
  131. {
  132. $paypal["s2member_log"][] = "Unable to add new Capabilities. The existing User ID is associated with an Administrator. Stopping here. Otherwise, an Administrator could lose access. Please make sure that you are NOT logged in as an Administrator while testing.";
  133. $paypal["s2member_log"][] = "Redirecting Customer to the Home Page (after displaying an error message).";
  134. echo c_ws_plugin__s2member_return_templates::return_template ($paypal["subscr_gateway"],
  135. _x ('<strong>ERROR:</strong> Unable to add new Capabilities.<br />Please contact Support for assistance.<br /><br />The existing User ID is associated with an Administrator. Stopping here. Otherwise, an Administrator could lose access. Please make sure that you are NOT logged in as an Administrator while testing.', "s2member-front", "s2member"),
  136. _x ("Back To Home Page", "s2member-front", "s2member"), home_url ("/"));
  137. }
  138. }
  139. else // Unable to add new Capabilities. Could not get the existing User ID from the DB.
  140. {
  141. $paypal["s2member_log"][] = "Unable to add new Capabilities. Could not get the existing User ID from the DB.";
  142. $paypal["s2member_log"][] = "Redirecting Customer to the Home Page (after displaying an error message).";
  143. echo c_ws_plugin__s2member_return_templates::return_template ($paypal["subscr_gateway"],
  144. _x ('<strong>ERROR:</strong> Unable to add new Capabilities.<br />Please contact Support for assistance.<br /><br />Could not get the existing User ID from the DB.', "s2member-front", "s2member"),
  145. _x ("Back To Home Page", "s2member-front", "s2member"), home_url ("/"));
  146. }
  147. }
  148. else // Unable to add new Capabilities. Missing User/Member details.
  149. {
  150. $paypal["s2member_log"][] = "Unable to add new Capabilities. Missing User/Member details. Please check the `on0` and `os0` variables in your Button Code.";
  151. $paypal["s2member_log"][] = "Redirecting Customer to the Home Page (after displaying an error message).";
  152. echo c_ws_plugin__s2member_return_templates::return_template ($paypal["subscr_gateway"],
  153. _x ('<strong>ERROR:</strong> Unable to add new Capabilities.<br />Please contact Support for assistance.<br /><br />Missing User/Member details.', "s2member-front", "s2member"),
  154. _x ("Back To Home Page", "s2member-front", "s2member"), home_url ("/"));
  155. }
  156. }
  157. else // Page Expired. Duplicate Return-Data.
  158. {
  159. $paypal["s2member_log"][] = "Page Expired. Duplicate Return-Data.";
  160. $paypal["s2member_log"][] = "s2Member `txn_type` identified as ( `web_accept` ) w/ update vars for Capabilities w/o Level.";
  161. $paypal["s2member_log"][] = "Page Expired. Redirecting Customer to the Home Page (after displaying an error message).";
  162. echo c_ws_plugin__s2member_return_templates::return_template ($paypal["subscr_gateway"],
  163. _x ('<strong>Page Expired:</strong> Duplicate Return-Data.<br />Please contact Support if you need any assistance.', "s2member-front", "s2member"),
  164. _x ("Back To Home Page", "s2member-front", "s2member"), home_url ("/"));
  165. }
  166. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  167. do_action ("ws_plugin__s2member_during_paypal_return_after_new_ccaps", get_defined_vars ());
  168. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  169. return apply_filters ("c_ws_plugin__s2member_paypal_return_in_wa_ccaps_wo_level", $paypal, get_defined_vars ());
  170. }
  171. else return apply_filters ("c_ws_plugin__s2member_paypal_return_in_wa_ccaps_wo_level", false, get_defined_vars ());
  172. }
  173. }
  174. }
  175. ?>