Source Code Documentation


pro\s2member-pro\includes\functions\api-functions.inc.php


  1. <?php
  2. /**
  3. * Core API Functions *(for site owners)*.
  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\API_Functions
  31. * @since 1.0
  32. */
  33. if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
  34. exit ("Do not access this file directly.");
  35. /**
  36. * Allows for the inclusion of the Pro Login Widget directly into a theme/plugin file.
  37. *
  38. * This function will return the HTML output from the widget function call.
  39. * Example usage: ``<!php echo s2member_pro_login_widget(); !>``
  40. *
  41. * The ``$options`` parameter (array) is completely optional *(i.e. NOT required)*.
  42. * It can be passed in as an array of options; overriding some or all of these defaults:
  43. *
  44. * o ``"title" => "Membership Login"``
  45. * Title when NOT logged in, or leave this blank if you'd prefer not to show a title.
  46. *
  47. * o ``"signup_url" => "%%automatic%%"``
  48. * Full Signup URL, or use `%%automatic%%` for the Membership Options Page. If you leave this blank, it will not be shown.
  49. *
  50. * o ``"login_redirect" => ""``
  51. * Empty ( i.e. `""` ) = Login Welcome Page, `%%previous%%` = Previous Page, `%%home%%` = Home Page, or use a full URL of your own.
  52. *
  53. * o ``"logged_out_code" => ""``
  54. * HTML/PHP code to display when logged out. May also contain WP Shortcodes if you like.
  55. *
  56. * o ``"profile_title" => "My Profile Summary"``
  57. * Title when a User is logged in. Or you can leave this blank if you'd prefer not to show a title.
  58. *
  59. * o ``"display_gravatar" => "1"``
  60. * Display Gravatar image when logged in? `1` = yes, `0` = no. Gravatars are based on email address.
  61. *
  62. * o ``"link_gravatar" => "1"``
  63. * Link Gravatar image to Gravatar.com? `1` = yes, `0` = no. Allows Users to setup a Gravatar.
  64. *
  65. * o ``"display_name" => "1"``
  66. * Display the current User's WordPress® "Display Name" when logged in? `1` = yes, `0` = no.
  67. *
  68. * o ``"logged_in_code" => ""``
  69. * HTML/PHP code to display when logged in. May also contain WP Shortcodes if you like.
  70. *
  71. * o ``"logout_redirect" => "%%home%%"``
  72. * Empty ( i.e. `""` ) = Login Screen, `%%previous%%` = Previous Page, `%%home%%` = Home Page, or use a full URL of your own.
  73. *
  74. * o ``"my_account_url" => "%%automatic%%"``
  75. * Full URL of your own, or use `%%automatic%%` for the Login Welcome Page. Leave empty to not show this at all.
  76. *
  77. * o ``"my_profile_url" => "%%automatic%%"``
  78. * Full URL of your own, or use `%%automatic%%` for a JavaScript popup. Leave empty to not show this at all.
  79. *
  80. * The ``$args`` parameter (array) is also completely optional *(i.e. NOT required)*.
  81. * It can be passed in as an array of options: overriding some or all of these defaults:
  82. *
  83. * o ``"before_widget" => ""``
  84. * HTML code to display before the widget.
  85. *
  86. * o ``"before_title" => "<h3>"``
  87. * HTML code to display before the title.
  88. *
  89. * o ``"after_title" => "</h3>"``
  90. * HTML code to display after the title.
  91. *
  92. * o ``"after_widget" => ""``
  93. * HTML code to display after the widget.
  94. *
  95. * @package s2Member\API_Functions
  96. * @since 1.5
  97. *
  98. * @param array $options Optional. See function description for details.
  99. * @param array $args Optional. See function description for details.
  100. * @return str The Pro Login Widget, HTML markup.
  101. */
  102. if (!function_exists ("s2member_pro_login_widget"))
  103. {
  104. function s2member_pro_login_widget ($options = FALSE, $args = FALSE)
  105. {
  106. $args = (is_array ($args)) ? $args : array ("before_widget" => "", "before_title" => "<h3>", "after_title" => "</h3>", "after_widget" => "");
  107.  
  108. ob_start(); // Begin output buffering.
  109.  
  110. c_ws_plugin__s2member_pro_login_widget::widget($args, $options);
  111.  
  112. return ob_get_clean();
  113. }
  114. }
  115. /**
  116. * Pulls an array of details from the PayPal® Pro API; related to a customer's Recurring Billing Profile.
  117. *
  118. * This function will return an array of data (as described below); else an empty array if no Recurring Billing Profile exists.
  119. * Example usage: ``<!php print_r(s2member_pro_paypal_rbp_for_user(123)); !>``
  120. *
  121. * Array elements returned by this function correlate with the PayPal® Pro API call method: `GetRecurringPaymentsProfileDetails`.
  122. * Please see {@link https://www.x.com/developers/paypal/documentation-tools/api/getrecurringpaymentsprofiledetails-api-operation-nvp}.
  123. *
  124. * @package s2Member\API_Functions
  125. * @since 130405
  126. *
  127. * @param str|int $user_id Optional. A specific User ID. Defaults to the current User ID that is logged into the site.
  128. * @return array An array of data (from the PayPal® Pro API); else an empty array if no Recurring Billing Profile exists.
  129. *
  130. * Array elements returned by this function correlate with the PayPal® Pro API call method: `GetRecurringPaymentsProfileDetails`.
  131. * Please see {@link https://www.x.com/developers/paypal/documentation-tools/api/getrecurringpaymentsprofiledetails-api-operation-nvp}.
  132. *
  133. * @note If your PayPal® Pro account uses the Payflow™ Edition API, please use {@link s2member_pro_payflow_rbp_for_user()} instead.
  134. */
  135. if (!function_exists ("s2member_pro_paypal_rbp_for_user"))
  136. {
  137. function s2member_pro_paypal_rbp_for_user ($user_id = FALSE)
  138. {
  139. $user_id = (integer)$user_id;
  140. $user_id = ($user_id) ? $user_id : get_current_user_id();
  141. if(!$user_id) return array();
  142.  
  143. $user_subscr_id = get_user_option ("s2member_subscr_id", $user_id);
  144. if(!$user_subscr_id) return array();
  145.  
  146. $paypal["METHOD"] = "GetRecurringPaymentsProfileDetails";
  147. $paypal["PROFILEID"] = $user_subscr_id;
  148.  
  149. if (is_array($paypal = c_ws_plugin__s2member_paypal_utilities::paypal_api_response ($paypal)) && empty($paypal["__error"]))
  150. return $paypal;
  151.  
  152. return array();
  153. }
  154. }
  155. /**
  156. * Pulls last/next billing times from the PayPal® Pro API; associated with a customer's Recurring Billing Profile.
  157. *
  158. * This function will return an array of data (as described below); else an empty array if no Recurring Billing Profile exists.
  159. * Example usage: ``<!php print_r(s2member_pro_paypal_rbp_times_for_user(123)); !>``
  160. *
  161. * Array elements returned by this function include: `last_billing_time`, `next_billing_time` (both as UTC Unix timestamps).
  162. *
  163. * @package s2Member\API_Functions
  164. * @since 130405
  165. *
  166. * @param str|int $user_id Optional. A specific User ID. Defaults to the current User ID that is logged into the site.
  167. * @return array Array elements: `last_billing_time`, `next_billing_time` (both as UTC Unix timestamps);
  168. * else an empty array if no Recurring Billing Profile exists.
  169. *
  170. * If one or more times (e.g. `last_billing_time`, `next_billing_time`) are irrelevant (i.e. there was no payment received yet; or there are no future payments to receive);
  171. * that time will default to a value of `0` indicating it's irrelevant and/or not applicable.
  172. *
  173. * @note If your PayPal® Pro account uses the Payflow™ Edition API, please use {@link s2member_pro_payflow_rbp_times_for_user()} instead.
  174. */
  175. if (!function_exists ("s2member_pro_paypal_rbp_times_for_user"))
  176. {
  177. function s2member_pro_paypal_rbp_times_for_user ($user_id = FALSE)
  178. {
  179. if(!($paypal = s2member_pro_paypal_rbp_for_user($user_id)))
  180. return array();
  181.  
  182. $array = array("last_billing_time" => 0, "next_billing_time" => 0);
  183.  
  184. if(preg_match("/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}/", $paypal["LASTPAYMENTDATE"]))
  185. $array["last_billing_time"] = strtotime($paypal["LASTPAYMENTDATE"]);
  186.  
  187. if(($paypal["TOTALBILLINGCYCLES"] === "0" || $paypal["NUMCYCLESREMAINING"] > 0) && preg_match ("/^(Active|ActiveProfile)$/i", $paypal["STATUS"]))
  188. if(preg_match("/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}/", $paypal["NEXTBILLINGDATE"]))
  189. $array["next_billing_time"] = strtotime($paypal["NEXTBILLINGDATE"]);
  190.  
  191. return $array;
  192. }
  193. }
  194. /**
  195. * Pulls an array of details from PayPal® Pro (Payflow™ Edition) API; related to a customer's Recurring Billing Profile.
  196. *
  197. * This function will return an array of data (as described below); else an empty array if no Recurring Billing Profile exists.
  198. * Example usage: ``<!php print_r(s2member_pro_payflow_rbp_for_user(123)); !>``
  199. *
  200. * Array elements returned by this function correlate with the PayPal® Pro (Payflow™ Edition) API call method: `ACTION=I`.
  201. * Please see {@link https://www.paypalobjects.com/webstatic/en_US/developer/docs/pdf/wpppe_rp_guide.pdf#page=54}.
  202. *
  203. * @package s2Member\API_Functions
  204. * @since 130405
  205. *
  206. * @param str|int $user_id Optional. A specific User ID. Defaults to the current User ID that is logged into the site.
  207. * @return array An array of data from the PayPal® Pro (Payflow™ Edition) API; else an empty array if no Recurring Billing Profile exists.
  208. *
  209. * Array elements returned by this function correlate with the PayPal® Pro (Payflow™ Edition) API call method: `ACTION=I`.
  210. * Please see {@link https://www.paypalobjects.com/webstatic/en_US/developer/docs/pdf/wpppe_rp_guide.pdf#page=54}.
  211. */
  212. if (!function_exists ("s2member_pro_payflow_rbp_for_user"))
  213. {
  214. function s2member_pro_payflow_rbp_for_user ($user_id = FALSE)
  215. {
  216. $user_id = (integer)$user_id;
  217. $user_id = ($user_id) ? $user_id : get_current_user_id();
  218. if(!$user_id) return array();
  219.  
  220. $user_subscr_id = get_user_option ("s2member_subscr_id", $user_id);
  221. if(!$user_subscr_id) return array();
  222.  
  223. if(!class_exists("c_ws_plugin__s2member_pro_paypal_utilities"))
  224. return array();
  225.  
  226. if (is_array($payflow = c_ws_plugin__s2member_pro_paypal_utilities::payflow_get_profile ($user_subscr_id)))
  227. return $payflow;
  228.  
  229. return array();
  230. }
  231. }
  232. /**
  233. * Pulls last/next billing times from the PayPal® Pro (Payflow™ Edition) API; associated with a customer's Recurring Billing Profile.
  234. *
  235. * This function will return an array of data (as described below); else an empty array if no Recurring Billing Profile exists.
  236. * Example usage: ``<!php print_r(s2member_pro_payflow_rbp_times_for_user(123)); !>``
  237. *
  238. * Array elements returned by this function include: `last_billing_time`, `next_billing_time` (both as UTC Unix timestamps).
  239. *
  240. * @package s2Member\API_Functions
  241. * @since 130405
  242. *
  243. * @param str|int $user_id Optional. A specific User ID. Defaults to the current User ID that is logged into the site.
  244. * @return array Array elements: `last_billing_time`, `next_billing_time` (both as UTC Unix timestamps);
  245. * else an empty array if no Recurring Billing Profile exists.
  246. *
  247. * If one or more times (e.g. `last_billing_time`, `next_billing_time`) are irrelevant (i.e. there was no payment received yet; or there are no future payments to receive);
  248. * that time will default to a value of `0` indicating it's irrelevant and/or not applicable.
  249. */
  250. if (!function_exists ("s2member_pro_payflow_rbp_times_for_user"))
  251. {
  252. function s2member_pro_payflow_rbp_times_for_user ($user_id = FALSE)
  253. {
  254. if(!($payflow = s2member_pro_payflow_rbp_for_user($user_id)))
  255. return array();
  256.  
  257. $array = array("last_billing_time" => 0, "next_billing_time" => 0);
  258.  
  259. if(($last_billing_time = get_user_option("s2member_last_payment_time", $user_id)))
  260. $array["last_billing_time"] = $last_billing_time; // Must use this because the PayFlow® API does not offer it up.
  261.  
  262. if(($payflow["TERM"] === "0" || $payflow["PAYMENTSLEFT"] > 0) && preg_match ("/^(Active|ActiveProfile)$/i", $payflow["STATUS"]))
  263. if(preg_match("/^[0-9]{8}/", $payflow["NEXTPAYMENT"]))
  264. $array["next_billing_time"] = strtotime($payflow["NEXTPAYMENT"]);
  265.  
  266. return $array;
  267. }
  268. }
  269. ?>

pro\s2member-pro\includes\functions\api-functions.inc.php

Source Code Documentation