Source Code Documentation


s2member\includes\classes\paypal-return-in-web-accept-sp.inc.php


  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.  
  20. if (!class_exists ("c_ws_plugin__s2member_paypal_return_in_web_accept_sp"))
  21. {
  22. /**
  23. * s2Member's PayPal® Auto-Return/PDT handler (inner processing routine).
  24. *
  25. * @package s2Member\PayPal
  26. * @since 110720
  27. */
  28. class c_ws_plugin__s2member_paypal_return_in_web_accept_sp
  29. {
  30. /**
  31. * s2Member's PayPal® Auto-Return/PDT handler (inner processing routine).
  32. *
  33. * @package s2Member\PayPal
  34. * @since 110720
  35. *
  36. * @param array $vars Required. An array of defined variables passed by {@link s2Member\PayPal\c_ws_plugin__s2member_paypal_return_in::paypal_return()}.
  37. * @return array|bool The original ``$paypal`` array passed in (extracted) from ``$vars``, or false when conditions do NOT apply.
  38. *
  39. * @todo Optimize with ``empty()`` and ``isset()``.
  40. */
  41. public static function /* Conditional phase for ``c_ws_plugin__s2member_paypal_notify_in::paypal_notify()``. */ cp ($vars = array ())
  42. {
  43. extract /* Extract all vars passed in from: ``c_ws_plugin__s2member_paypal_notify_in::paypal_notify()``. */($vars);
  44.  
  45. if ((!empty ($paypal["txn_type"]) && preg_match ("/^web_accept$/i", $paypal["txn_type"]))
  46. && (!empty ($paypal["item_number"]) && preg_match ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["sp_access_item_number_regex"], $paypal["item_number"]))
  47. && (empty ($paypal["payment_status"]) || empty ($payment_status_issues) || !preg_match ($payment_status_issues, $paypal["payment_status"]))
  48. && (!empty ($paypal["txn_id"])))
  49. {
  50. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  51. do_action ("ws_plugin__s2member_during_paypal_return_before_sp_access", get_defined_vars ());
  52. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  53.  
  54. if (!get_transient ($transient_rtn = "s2m_rtn_" . md5 ("s2member_transient_" . $_paypal_s)) && set_transient ($transient_rtn, time (), 31556926 * 10))
  55. {
  56. $paypal["s2member_log"][] = "s2Member `txn_type` identified as ( `web_accept` ) for Specific Post/Page Access.";
  57.  
  58. list (, $paypal["sp_ids"], $paypal["hours"]) = preg_split ("/\:/", $paypal["item_number"], 3);
  59.  
  60. $paypal["ip"] = (preg_match ("/ip address/i", $paypal["option_name2"]) && $paypal["option_selection2"]) ? $paypal["option_selection2"] : "";
  61. $paypal["ip"] = (!$paypal["ip"] && preg_match ("/^[a-z0-9]+~[0-9\.]+$/i", $paypal["invoice"])) ? preg_replace ("/^[a-z0-9]+~/i", "", $paypal["invoice"]) : $paypal["ip"];
  62. $paypal["ip"] = (!$paypal["ip"] && $_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : $paypal["ip"];
  63.  
  64. if (($sp_access_url = c_ws_plugin__s2member_sp_access::sp_access_link_gen ($paypal["sp_ids"], $paypal["hours"], false)))
  65. {
  66. $processing = $during = /* Yes, we ARE processing this. */ true;
  67.  
  68. setcookie ("s2member_sp_tracking", ($s2member_sp_tracking = c_ws_plugin__s2member_utils_encryption::encrypt ($paypal["txn_id"])), time () + 31556926, COOKIEPATH, COOKIE_DOMAIN) . setcookie ("s2member_sp_tracking", $s2member_sp_tracking, time () + 31556926, SITECOOKIEPATH, COOKIE_DOMAIN) . ($_COOKIE["s2member_sp_tracking"] = $s2member_sp_tracking);
  69.  
  70. $paypal["s2member_log"][] = "Transient Tracking Cookie set on ( `web_accept` ) for Specific Post/Page Access.";
  71.  
  72. if ($processing && ($code = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["sp_tracking_codes"]) && is_array ($cv = preg_split ("/\|/", $paypal["custom"])))
  73. {
  74. if (($code = preg_replace ("/%%cv([0-9]+)%%/ei", 'trim($cv[$1])', $code)) && ($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)))
  75. 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)))
  76. 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)))
  77. if (($code = preg_replace ("/%%full_name%%/i", c_ws_plugin__s2member_utils_strings::esc_ds (trim ($paypal["first_name"] . " " . $paypal["last_name"])), $code)))
  78. if (($code = preg_replace ("/%%payer_email%%/i", c_ws_plugin__s2member_utils_strings::esc_ds ($paypal["payer_email"]), $code)))
  79. if (($code = preg_replace ("/%%user_ip%%/i", c_ws_plugin__s2member_utils_strings::esc_ds ($paypal["ip"]), $code)))
  80.  
  81. if (($code = trim (preg_replace ("/%%(.+?)%%/i", "", $code)))) // This gets stored into a Transient Queue.
  82. {
  83. $paypal["s2member_log"][] = "Storing Specific Post/Page Tracking Codes into a Transient Queue. These will be processed on-site.";
  84. set_transient ("s2m_" . md5 ("s2member_transient_sp_tracking_codes_" . $paypal["txn_id"]), $code, 43200);
  85. }
  86. }
  87. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  88. do_action ("ws_plugin__s2member_during_paypal_return_during_sp_access", get_defined_vars ());
  89. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  90.  
  91. if (apply_filters ("ws_plugin__s2member_immediate_sp_access_redirection", false, get_defined_vars ()))
  92. {
  93. $paypal["s2member_log"][] = "Redirecting Customer immediately to the Specific Post/Page.";
  94.  
  95. wp_redirect /* Immediate redirection to Specific Post/Page. */($sp_access_url);
  96. }
  97. else if /* Using a custom success redirection URL? */ ($custom_success_redirection)
  98. {
  99. $paypal["s2member_log"][] = "Redirecting Customer to a custom URL on success: " . $custom_success_redirection;
  100.  
  101. wp_redirect($custom_success_redirection);
  102. }
  103. else // Else use the default return URL in this scenario, which is the Specific Post/Page.
  104. {
  105. $paypal["s2member_log"][] = "Redirecting Customer to the Specific Post/Page (after displaying a thank-you message).";
  106.  
  107. echo c_ws_plugin__s2member_return_templates::return_template ($paypal["subscr_gateway"],
  108. _x ('<strong>Thank You! Your transaction has been approved.</strong>', "s2member-front", "s2member"),
  109. _x ("Continue (Click Here)", "s2member-front", "s2member"), $sp_access_url);
  110. }
  111. }
  112. else // Otherwise, the ID must have been invalid. Or the Post/Page was deleted.
  113. {
  114. $paypal["s2member_log"][] = "Unable to generate Specific Post/Page Access Link. Does your Leading Post/Page still exist?";
  115.  
  116. $paypal["s2member_log"][] = "Redirecting Customer to the Home Page (after displaying an error message).";
  117.  
  118. echo c_ws_plugin__s2member_return_templates::return_template ($paypal["subscr_gateway"],
  119. _x ('<strong>ERROR:</strong> Unable to generate Access Link.<br />Please contact Support for assistance.', "s2member-front", "s2member"),
  120. _x ("Back To Home Page", "s2member-front", "s2member"), home_url ("/"));
  121. }
  122. }
  123. else // Page Expired. Duplicate Return-Data.
  124. {
  125. $paypal["s2member_log"][] = "Page Expired. Duplicate Return-Data.";
  126. $paypal["s2member_log"][] = "s2Member `txn_type` identified as ( `web_accept` ) for Specific Post/Page Access.";
  127. $paypal["s2member_log"][] = "Page Expired. Redirecting Customer to the Home Page (after displaying an error message).";
  128.  
  129. echo c_ws_plugin__s2member_return_templates::return_template ($paypal["subscr_gateway"],
  130. _x ('<strong>Page Expired:</strong> Duplicate Return-Data.<br />Please contact Support if you need any assistance.', "s2member-front", "s2member"),
  131. _x ("Back To Home Page", "s2member-front", "s2member"), home_url ("/"));
  132. }
  133. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  134. do_action ("ws_plugin__s2member_during_paypal_return_after_sp_access", get_defined_vars ());
  135. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  136.  
  137. return apply_filters ("c_ws_plugin__s2member_paypal_return_in_web_accept_sp", $paypal, get_defined_vars ());
  138. }
  139. else return apply_filters ("c_ws_plugin__s2member_paypal_return_in_web_accept_sp", false, get_defined_vars ());
  140. }
  141. }
  142. }
  143. ?>

s2member\includes\classes\paypal-return-in-web-accept-sp.inc.php

Source Code Documentation