Source Code Documentation


pro\s2member-pro\includes\classes\gateways\ccbill\ccbill-button-in.inc.php


  1. <?php
  2. /**
  3. * Shortcode `[s2Member-Pro-ccBill-Button /]` (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\ccBill
  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_ccbill_button_in"))
  37. {
  38. /**
  39. * Shortcode `[s2Member-Pro-ccBill-Button /]` (inner processing routines).
  40. *
  41. * @package s2Member\ccBill
  42. * @since 1.5
  43. */
  44. class c_ws_plugin__s2member_pro_ccbill_button_in
  45. {
  46. /**
  47. * Shortcode `[s2Member-Pro-ccBill-Button /]`.
  48. *
  49. * @package s2Member\ccBill
  50. * @since 1.5
  51. *
  52. * @attaches-to ``add_shortcode("s2Member-Pro-ccBill-Button");``
  53. *
  54. * @param array $attr An array of Attributes.
  55. * @param str $content Content inside the Shortcode.
  56. * @param str $shortcode The actual Shortcode name itself.
  57. * @return str The resulting ccBill® Button Code, HTML markup.
  58. */
  59. public static function sc_ccbill_button($attr = FALSE, $content = FALSE, $shortcode = FALSE)
  60. {
  61. c_ws_plugin__s2member_no_cache::no_cache_constants /* No caching on pages that contain this Payment Button. */(true);
  62.  
  63. $attr = /* Force array. Trim quote entities. */ c_ws_plugin__s2member_utils_strings::trim_qts_deep((array)$attr);
  64.  
  65. $attr = shortcode_atts(array("ids" => "0", "exp" => "72", "level" => "1", "ccaps" => "", "desc" => "", "cc" => "USD", "custom" => $_SERVER["HTTP_HOST"], "ta" => "0", "tp" => "0", "tt" => "D", "ra" => "2.95", "rp" => "1", "rt" => "M", "rr" => "1", "modify" => "0", "cancel" => "0", "sp" => "0", "image" => "default", "sub_account" => "", "form" => "", "output" => "anchor"), $attr);
  66.  
  67. $attr["tt"] = /* Term lengths absolutely must be provided in upper-case format. Only after running shortcode_atts(). */ strtoupper($attr["tt"]);
  68. $attr["rt"] = /* Term lengths absolutely must be provided in upper-case format. Only after running shortcode_atts(). */ strtoupper($attr["rt"]);
  69. $attr["ccaps"] = /* Custom Capabilities must be typed in lower-case format. Only after running shortcode_atts(). */ strtolower($attr["ccaps"]);
  70. $attr["rr"] = /* Lifetime Subscriptions do NOT recur. Only after running shortcode_atts(). */ ($attr["rt"] === "L") ? "0" : $attr["rr"];
  71. $attr["rr"] = /* Independent Ccaps do NOT recur. Only after running shortcode_atts(). */ ($attr["level"] === "*") ? "0" : $attr["rr"];
  72.  
  73. if /* With ccBill®, a Recurring Subscription MUST have an Initial/Trial Period. */($attr["rr"] && ($attr["ta"] <= 0 || $attr["tp"] <= 0 || !$attr["tt"]))
  74. eval /* In this case, just use the same as Regular values. */('$attr["ta"] = $attr["ra"]; $attr["tp"] = $attr["rp"]; $attr["tt"] = $attr["rt"];');
  75.  
  76. if /* ccBill® Modifications/Cancellations. */($attr["modify"] || $attr["cancel"])
  77. {
  78. $default_image = $GLOBALS["WS_PLUGIN__"]["s2member_pro"]["c"]["dir_url"]."/images/ccbill-edit-button.png";
  79.  
  80. $code = trim(c_ws_plugin__s2member_utilities::evl(file_get_contents(dirname(dirname(dirname(dirname(__FILE__))))."/templates/buttons/ccbill-cancellation-button.php")));
  81. $code = preg_replace("/%%images%%/", c_ws_plugin__s2member_utils_strings::esc_ds(esc_attr($GLOBALS["WS_PLUGIN__"]["s2member_pro"]["c"]["dir_url"]."/images")), $code);
  82. $code = preg_replace("/%%wpurl%%/", c_ws_plugin__s2member_utils_strings::esc_ds(esc_attr(site_url())), $code);
  83.  
  84. $code = $_code = ($attr["image"] && $attr["image"] !== "default") ? preg_replace('/ src\="(.*?)"/', ' src="'.c_ws_plugin__s2member_utils_strings::esc_ds(esc_attr($attr["image"])).'"', $code) : preg_replace('/ src\="(.*?)"/', ' src="'.c_ws_plugin__s2member_utils_strings::esc_ds(esc_attr($default_image)).'"', $code);
  85.  
  86. $code = ($attr["output"] === "anchor") ? /* Buttons already in anchor format. */ $code : $code;
  87. if($attr["output"] === "url" && preg_match('/ href\="(.*?)"/', $code, $m) && ($href = $m[1]))
  88. $code = ($url = c_ws_plugin__s2member_utils_urls::n_amps($href));
  89.  
  90. unset /* Just a little housekeeping */($href, $url, $m);
  91. }
  92. else if /* Specific Post/Page Buttons. */($attr["sp"])
  93. {
  94. $default_image = $GLOBALS["WS_PLUGIN__"]["s2member_pro"]["c"]["dir_url"]."/images/ccbill-button.png";
  95.  
  96. $attr["sp_ids_exp"] = /* Combined "sp:ids:expiration hours". */ "sp:".$attr["ids"].":".$attr["exp"];
  97.  
  98. $code = trim(c_ws_plugin__s2member_utilities::evl(file_get_contents(dirname(dirname(dirname(dirname(__FILE__))))."/templates/buttons/ccbill-sp-checkout-button.php")));
  99. $code = preg_replace("/%%images%%/", c_ws_plugin__s2member_utils_strings::esc_ds(esc_attr($GLOBALS["WS_PLUGIN__"]["s2member_pro"]["c"]["dir_url"]."/images")), $code);
  100. $code = preg_replace("/%%wpurl%%/", c_ws_plugin__s2member_utils_strings::esc_ds(esc_attr(site_url())), $code);
  101.  
  102. $vars = array("clientAccnum" => $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_ccbill_client_id"], "clientSubacc" => (($attr["sub_account"]) ? $attr["sub_account"] : $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_ccbill_client_sid"]), "formName" => (($attr["form"]) ? $attr["form"] : $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_ccbill_form_name"]), "formPrice" => $attr["ra"], "formPeriod" => round($attr["exp"] / 24), "currencyCode" => c_ws_plugin__s2member_pro_ccbill_utilities::ccbill_currency_numr($attr["cc"]), "s2_desc" => $attr["desc"], "s2_invoice" => $attr["sp_ids_exp"], "s2_custom" => $attr["custom"], "s2_customer_ip" => $_SERVER["REMOTE_ADDR"]);
  103.  
  104. if /* Are we referencing a User/Member in the database? */($referencing = c_ws_plugin__s2member_utils_users::get_user_subscr_or_wp_id())
  105. $vars["s2_referencing"] = /* Add this into the ``$vars`` array. */ $referencing;
  106.  
  107. $code = preg_replace("/%%url%%/", c_ws_plugin__s2member_utils_strings::esc_ds(esc_attr($url = c_ws_plugin__s2member_pro_ccbill_utilities::ccbill_link_gen($vars))), $code);
  108.  
  109. $code = $_code = ($attr["image"] && $attr["image"] !== "default") ? preg_replace('/ src\="(.*?)"/', ' src="'.c_ws_plugin__s2member_utils_strings::esc_ds(esc_attr($attr["image"])).'"', $code) : preg_replace('/ src\="(.*?)"/', ' src="'.c_ws_plugin__s2member_utils_strings::esc_ds(esc_attr($default_image)).'"', $code);
  110.  
  111. $code = ($attr["output"] === "anchor") ? /* Buttons already in anchor format. */ $code : $code;
  112. $code = ($attr["output"] === "url") ? /* From the routine above. */ $url : $code;
  113.  
  114. unset /* Just a little housekeeping */($href, $url, $m);
  115. }
  116. else if /* Independent Custom Capabilities. */($attr["level"] === "*")
  117. {
  118. $default_image = $GLOBALS["WS_PLUGIN__"]["s2member_pro"]["c"]["dir_url"]."/images/ccbill-button.png";
  119.  
  120. $attr["level_ccaps_eotper"] = (!$attr["rr"] && $attr["rt"] !== "L") ? $attr["level"].":".$attr["ccaps"].":".$attr["rp"]." ".$attr["rt"] : $attr["level"].":".$attr["ccaps"];
  121. $attr["level_ccaps_eotper"] = /* Clean any trailing separators from this string. */ rtrim($attr["level_ccaps_eotper"], ":");
  122.  
  123. $code = trim(c_ws_plugin__s2member_utilities::evl(file_get_contents(dirname(dirname(dirname(dirname(__FILE__))))."/templates/buttons/ccbill-ccaps-checkout-button.php")));
  124. $code = preg_replace("/%%images%%/", c_ws_plugin__s2member_utils_strings::esc_ds(esc_attr($GLOBALS["WS_PLUGIN__"]["s2member_pro"]["c"]["dir_url"]."/images")), $code);
  125. $code = preg_replace("/%%wpurl%%/", c_ws_plugin__s2member_utils_strings::esc_ds(esc_attr(site_url())), $code);
  126.  
  127. $vars = array("clientAccnum" => $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_ccbill_client_id"], "clientSubacc" => (($attr["sub_account"]) ? $attr["sub_account"] : $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_ccbill_client_sid"]), "formName" => (($attr["form"]) ? $attr["form"] : $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_ccbill_form_name"]), "formPrice" => $attr["ra"], "formPeriod" => c_ws_plugin__s2member_pro_ccbill_utilities::ccbill_per_term_2_days($attr["rp"], $attr["rt"]), "currencyCode" => c_ws_plugin__s2member_pro_ccbill_utilities::ccbill_currency_numr($attr["cc"]), "s2_desc" => $attr["desc"], "s2_invoice" => $attr["level_ccaps_eotper"], "s2_custom" => $attr["custom"], "s2_customer_ip" => $_SERVER["REMOTE_ADDR"]);
  128.  
  129. if /* Are we referencing an account already in the database? */($referencing = c_ws_plugin__s2member_utils_users::get_user_subscr_or_wp_id())
  130. $vars["s2_referencing"] = /* Add this into the ``$vars`` array. */ $referencing;
  131.  
  132. $code = preg_replace("/%%url%%/", c_ws_plugin__s2member_utils_strings::esc_ds(esc_attr($url = c_ws_plugin__s2member_pro_ccbill_utilities::ccbill_link_gen($vars))), $code);
  133.  
  134. $code = $_code = ($attr["image"] && $attr["image"] !== "default") ? preg_replace('/ src\="(.*?)"/', ' src="'.c_ws_plugin__s2member_utils_strings::esc_ds(esc_attr($attr["image"])).'"', $code) : preg_replace('/ src\="(.*?)"/', ' src="'.c_ws_plugin__s2member_utils_strings::esc_ds(esc_attr($default_image)).'"', $code);
  135.  
  136. $code = ($attr["output"] === "anchor") ? /* Buttons already in anchor format. */ $code : $code;
  137. $code = ($attr["output"] === "url") ? /* From the routine above. */ $url : $code;
  138.  
  139. unset /* Just a little housekeeping */($href, $url, $m);
  140. }
  141. else // Otherwise, we'll process this Button normally, using Membership routines.
  142. {
  143. $default_image = $GLOBALS["WS_PLUGIN__"]["s2member_pro"]["c"]["dir_url"]."/images/ccbill-button.png";
  144.  
  145. $attr["desc"] = (!$attr["desc"]) ? $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level".$attr["level"]."_label"] : $attr["desc"];
  146.  
  147. $attr["level_ccaps_eotper"] = (!$attr["rr"] && $attr["rt"] !== "L") ? $attr["level"].":".$attr["ccaps"].":".$attr["rp"]." ".$attr["rt"] : $attr["level"].":".$attr["ccaps"];
  148. $attr["level_ccaps_eotper"] = /* Clean any trailing separators from this string. */ rtrim($attr["level_ccaps_eotper"], ":");
  149.  
  150. $code = trim(c_ws_plugin__s2member_utilities::evl(file_get_contents(dirname(dirname(dirname(dirname(__FILE__))))."/templates/buttons/ccbill-checkout-button.php")));
  151. $code = preg_replace("/%%images%%/", c_ws_plugin__s2member_utils_strings::esc_ds(esc_attr($GLOBALS["WS_PLUGIN__"]["s2member_pro"]["c"]["dir_url"]."/images")), $code);
  152. $code = preg_replace("/%%wpurl%%/", c_ws_plugin__s2member_utils_strings::esc_ds(esc_attr(site_url())), $code);
  153.  
  154. if /* This is NOT a Recurring Subscription (i.e. an Initial/Trial Period is NOT possible). */(!$attr["rr"])
  155. $vars = array("clientAccnum" => $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_ccbill_client_id"], "clientSubacc" => (($attr["sub_account"]) ? $attr["sub_account"] : $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_ccbill_client_sid"]), "formName" => (($attr["form"]) ? $attr["form"] : $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_ccbill_form_name"]), "formPrice" => $attr["ra"], "formPeriod" => c_ws_plugin__s2member_pro_ccbill_utilities::ccbill_per_term_2_days($attr["rp"], $attr["rt"]), "currencyCode" => c_ws_plugin__s2member_pro_ccbill_utilities::ccbill_currency_numr($attr["cc"]), "s2_p1" => "0 D", "s2_p3" => $attr["rp"]." ".$attr["rt"], "s2_desc" => $attr["desc"], "s2_invoice" => $attr["level_ccaps_eotper"], "s2_custom" => $attr["custom"], "s2_customer_ip" => $_SERVER["REMOTE_ADDR"]);
  156.  
  157. else // Otherwise, we need to include both an Initial and Regular/Recurring period. This will ALWAYS recur.
  158. $vars = array("clientAccnum" => $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_ccbill_client_id"], "clientSubacc" => (($attr["sub_account"]) ? $attr["sub_account"] : $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_ccbill_client_sid"]), "formName" => (($attr["form"]) ? $attr["form"] : $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_ccbill_form_name"]), "formPrice" => $attr["ta"], "formPeriod" => c_ws_plugin__s2member_pro_ccbill_utilities::ccbill_per_term_2_days($attr["tp"], $attr["tt"]), "formRecurringPrice" => $attr["ra"], "formRecurringPeriod" => c_ws_plugin__s2member_pro_ccbill_utilities::ccbill_per_term_2_days($attr["rp"], $attr["rt"]), "formRebills" => "99", "currencyCode" => c_ws_plugin__s2member_pro_ccbill_utilities::ccbill_currency_numr($attr["cc"]), "s2_p1" => $attr["tp"]." ".$attr["tt"], "s2_p3" => $attr["rp"]." ".$attr["rt"], "s2_desc" => $attr["desc"], "s2_invoice" => $attr["level_ccaps_eotper"], "s2_custom" => $attr["custom"], "s2_customer_ip" => $_SERVER["REMOTE_ADDR"]);
  159.  
  160. if /* Are we referencing an account already in the database? */($referencing = c_ws_plugin__s2member_utils_users::get_user_subscr_or_wp_id())
  161. $vars["s2_referencing"] = /* Add this into the ``$vars`` array. */ $referencing;
  162.  
  163. $code = preg_replace("/%%url%%/", c_ws_plugin__s2member_utils_strings::esc_ds(esc_attr($url = c_ws_plugin__s2member_pro_ccbill_utilities::ccbill_link_gen($vars))), $code);
  164.  
  165. $code = $_code = ($attr["image"] && $attr["image"] !== "default") ? preg_replace('/ src\="(.*?)"/', ' src="'.c_ws_plugin__s2member_utils_strings::esc_ds(esc_attr($attr["image"])).'"', $code) : preg_replace('/ src\="(.*?)"/', ' src="'.c_ws_plugin__s2member_utils_strings::esc_ds(esc_attr($default_image)).'"', $code);
  166.  
  167. $code = ($attr["output"] === "anchor") ? /* Buttons already in anchor format. */ $code : $code;
  168. $code = ($attr["output"] === "url") ? /* From the routine above. */ $url : $code;
  169.  
  170. unset /* Just a little housekeeping */($href, $url, $m);
  171. }
  172. return /* Button. */ $code;
  173. }
  174. }
  175. }
  176. ?>

pro\s2member-pro\includes\classes\gateways\ccbill\ccbill-button-in.inc.php

Source Code Documentation