Source Code Documentation


s2member-pro\includes\classes\gateways\clickbank\clickbank-utilities.inc.php


  1. <?php
  2. /**
  3. * ClickBank® utilities.
  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\ClickBank
  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_clickbank_utilities"))
  37. {
  38. /**
  39. * ClickBank® utilities.
  40. *
  41. * @package s2Member\ClickBank
  42. * @since 1.5
  43. */
  44. class c_ws_plugin__s2member_pro_clickbank_utilities
  45. {
  46. /**
  47. * Formulates request Authorization headers.
  48. *
  49. * @package s2Member\ClickBank
  50. * @since 1.5
  51. *
  52. * @return array Request Authorization headers for ClickBank® API communication.
  53. */
  54. public static function clickbank_api_headers()
  55. {
  56. $req["headers"]["Accept"] = "application/json";
  57. $req["headers"]["Authorization"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_clickbank_developer_key"].":".$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_clickbank_clerk_key"];
  58. /**/
  59. return $req; /* Return array with headers.*/
  60. }
  61. /**
  62. * Get ``$_POST`` or ``$_REQUEST`` vars from ClickBank®.
  63. *
  64. * @package s2Member\ClickBank
  65. * @since 1.5
  66. *
  67. * @return array|bool An array of verified ``$_POST`` or ``$_REQUEST`` variables, else false.
  68. *
  69. * @todo Continue optimizing this routine with ``empty()`` and ``isset()``.
  70. * @todo Candidate for the use of ``ifsetor()``?
  71. */
  72. public static function clickbank_postvars()
  73. {
  74. if(!empty($_REQUEST["s2member_pro_clickbank_return"]) && !empty($_REQUEST["cbpop"]))
  75. {
  76. $postvars = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_REQUEST));
  77. /**/
  78. foreach($postvars as $var => $value)
  79. if(preg_match("/^s2member_/", $var))
  80. unset($postvars[$var]);
  81. /**/
  82. $cbpop = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_clickbank_secret_key"];
  83. $cbpop .= "|".$postvars["cbreceipt"]."|".$postvars["time"]."|".$postvars["item"];
  84. /**/
  85. $mb = function_exists("mb_convert_encoding") ? @mb_convert_encoding($cbpop, "UTF-8", $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["mb_detection_order"]) : $cbpop;
  86. $cbpop = ($mb) ? $mb : $cbpop; /* Double check this, just in case conversion fails. */
  87. $cbpop = strtoupper(substr(sha1($cbpop), 0, 8));
  88. /**/
  89. if($postvars["cbpop"] === $cbpop)
  90. return $postvars;
  91. /**/
  92. else /* Nope. */
  93. return false;
  94. }
  95. else if(!empty($_REQUEST["s2member_pro_clickbank_notify"]) && !empty($_REQUEST["cverify"]))
  96. {
  97. $postvars = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_REQUEST));
  98. /**/
  99. foreach($postvars as $var => $value)
  100. if(preg_match("/^s2member_/", $var))
  101. unset($postvars[$var]);
  102. /**/
  103. $cverify = ""; /* Initialize verification. */
  104. /**/
  105. ($keys = array_keys($postvars)).sort($keys);
  106. foreach($keys as $key) /* Go through keys. */
  107. if($key && !preg_match("/^(cverify)$/", $key))
  108. $cverify .= $postvars[$key]."|";
  109. /**/
  110. $cverify .= $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_clickbank_secret_key"];
  111. /**/
  112. $mb = function_exists("mb_convert_encoding") ? @mb_convert_encoding($cverify, "UTF-8", $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["mb_detection_order"]) : $cverify;
  113. $cverify = ($mb) ? $mb : $cverify; /* Double check this, just in case conversion fails. */
  114. $cverify = strtoupper(substr(sha1($cverify), 0, 8));
  115. /**/
  116. if($postvars["cverify"] === $cverify)
  117. return $postvars;
  118. /**/
  119. else /* Nope. */
  120. return false;
  121. }
  122. else /* Nope. */
  123. return false;
  124. }
  125. /**
  126. * Parses s2Vars passed through by ClickBank®.
  127. *
  128. * @package s2Member\ClickBank
  129. * @since 111205
  130. *
  131. * @param str $cvendthru Expects the URL-encoded query string of s2Vars, including `_s2member_sig`.
  132. * @param str $type Optional. The type of ClickBank® transaction. This deals with backward compatibility.
  133. * For SALE transactions, do NOT accept the older format. For others, remain backward compatible.
  134. * @return array Array of s2Vars. Possibly an empty array.
  135. */
  136. public static function clickbank_parse_s2vars($cvendthru = FALSE, $type = FALSE)
  137. {
  138. wp_parse_str((string)$cvendthru, $s2vars);
  139. $s2vars = c_ws_plugin__s2member_utils_strings::trim_deep($s2vars);
  140. /**/
  141. foreach($s2vars as $var => $value /* Pulls out `s2_|_s2member_sig` vars. */)
  142. if(!preg_match("/^(?:s2_|_s2member_sig)/", $var))
  143. unset($s2vars[$var]);
  144. /**/
  145. $is_sale = preg_match("/^(?:TEST_)?SALE$/i", (string)$type);
  146. if(!$is_sale || c_ws_plugin__s2member_utils_urls::s2member_sig_ok(http_build_query($s2vars, null, "&")))
  147. return /* Looks good. Return ``$s2vars``. */ $s2vars;
  148. /**/
  149. return /* Default empty array. */ array();
  150. }
  151. /**
  152. * Credit card reminder on Return Page templates.
  153. *
  154. * @package s2Member\ClickBank
  155. * @since 110720
  156. *
  157. * @attaches-to ``add_filter("ws_plugin__s2member_return_template_support");``
  158. *
  159. * @param str $support The current value for the `%%support%%` Replacement Code, passed through by the Filter.
  160. * @param array $vars An array of defined variables, passed through by the Filter.
  161. * @return str The ``$support`` value, after possible modification.
  162. */
  163. public static function clickbank_cc_reminder($support = FALSE, $vars = FALSE)
  164. {
  165. if(!empty($vars["template"]) && $vars["template"] === "clickbank")
  166. return $support. /* Now add the reminder below this. ClickBank® requires site owners to display this. */
  167. '<div class="cc-reminder">'._x('<strong>Reminder:</strong> Purchases at this site will appear on your credit card or bank statement as: <code>ClickBank®</code> or <code>CLKBANK*COM</code>.', "s2member-front", "s2member").'</div>';
  168. /**/
  169. return $support;
  170. }
  171. }
  172. }
  173. ?>

s2member-pro\includes\classes\gateways\clickbank\clickbank-utilities.inc.php

Source Code Documentation