Source Code Documentation


pro\s2member-pro\includes\menu-pages\ccbill-menu-pages-s.js


  1. /**
  2. * Core JavaScript routines for ccBill® menu pages.
  3. *
  4. * Copyright: © 2009-2011
  5. * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
  6. * (coded in the USA)
  7. *
  8. * This WordPress® plugin (s2Member Pro) is comprised of two parts:
  9. *
  10. * o (1) Its PHP code is licensed under the GPL license, as is WordPress®.
  11. * You should have received a copy of the GNU General Public License,
  12. * along with this software. In the main directory, see: /licensing/
  13. * If not, see: {@link http://www.gnu.org/licenses/}.
  14. *
  15. * o (2) All other parts of (s2Member Pro); including, but not limited to:
  16. * the CSS code, some JavaScript code, images, and design;
  17. * are licensed according to the license purchased.
  18. * See: {@link http://www.s2member.com/prices/}
  19. *
  20. * Unless you have our prior written consent, you must NOT directly or indirectly license,
  21. * sub-license, sell, resell, or provide for free; part (2) of the s2Member Pro Module;
  22. * or make an offer to do any of these things. All of these things are strictly
  23. * prohibited with part (2) of the s2Member Pro Module.
  24. *
  25. * Your purchase of s2Member Pro includes free lifetime upgrades via s2Member.com
  26. * (i.e. new features, bug fixes, updates, improvements); along with full access
  27. * to our video tutorial library: {@link http://www.s2member.com/videos/}
  28. *
  29. * @package s2Member\Menu_Pages
  30. * @since 1.5
  31. */
  32. jQuery(document).ready (function($)
  33. {
  34. var esc_attr = esc_html = /* Convert special characters. */ function(str)
  35. {
  36. return String(str).replace (/"/g, '&quot;').replace (/\</g, '&lt;').replace (/\>/g, '&gt;');
  37. };
  38.  
  39. if (location.href.match (/page\=ws-plugin--s2member-pro-ccbill-ops/))
  40. {
  41. $('select#ws-plugin--s2member-auto-eot-system-enabled').change (function()
  42. {
  43. var $this = $(this), val = $this.val ();
  44. var $viaCron = $('p#ws-plugin--s2member-auto-eot-system-enabled-via-cron');
  45.  
  46. if /* Display Cron instructions. */ (val == 2)
  47. $viaCron.show ()
  48. else // Hide instructions.
  49. $viaCron.hide ();
  50. });
  51. }
  52.  
  53. else if (location.href.match (/page\=ws-plugin--s2member-pro-ccbill-buttons/))
  54. {
  55. $('div.ws-menu-page select[id]').filter ( /* Filter all select elements with an id. */function()
  56. {
  57. return this.id.match (/^ws-plugin--s2member-pro-level[1-9][0-9]*-term$/);
  58. }).change (function()
  59. {
  60. var button = this.id.replace (/^ws-plugin--s2member-pro-(.+?)-term$/g, '$1');
  61.  
  62. var trialDisabled = ($(this).val ().split ('-')[2].replace (/[^0-1]/g, '') === '0') ? 1 : 0;
  63.  
  64. $('p#ws-plugin--s2member-pro-' + button + '-trial-line').css ('display', (trialDisabled ? 'none' : ''));
  65. $('span#ws-plugin--s2member-pro-' + button + '-trial-then').css ('display', (trialDisabled ? 'none' : ''));
  66.  
  67. (trialDisabled) ? $('input#ws-plugin--s2member-pro-' + button + '-trial-period').val (0) : null;
  68. (trialDisabled) ? $('input#ws-plugin--s2member-pro-' + button + '-trial-amount').val ('0.00') : null;
  69. });
  70.  
  71. $('div.ws-menu-page input[id]').filter ( /* Filter all input elements with an id. */function()
  72. {
  73. return this.id.match (/^ws-plugin--s2member-pro-(level[1-9][0-9]*|ccap)-ccaps$/);
  74. }).keyup (function()
  75. {
  76. var value = this.value.replace (/^(-all|-al|-a|-)[;,]*/gi, ''), _all = (this.value.match (/^(-all|-al|-a|-)[;,]*/i)) ? '-all,' : '';
  77. if /* Only if there is a problem with the actual values; because this causes interruptions. */ (value.match (/[^a-z_0-9,]/))
  78. this.value = _all + $.trim ($.trim (value).replace (/[ \-]/g, '_').replace (/[^a-z_0-9,]/gi, '').toLowerCase ());
  79. });
  80.  
  81. ws_plugin__s2member_pro_ccbillButtonGenerate = /* Handles ccBill® Button Generation. */ function(button)
  82. {
  83. var shortCodeTemplate = '[s2Member-Pro-ccBill-Button %%attrs%% image="default" output="anchor" /]', shortCodeTemplateAttrs = '', labels = {};
  84.  
  85. eval("<?php echo c_ws_plugin__s2member_utils_strings::esc_dq($vars['labels']); ?>");
  86.  
  87. var shortCode = $('input#ws-plugin--s2member-pro-' + button + '-shortcode');
  88.  
  89. var level = /* Just strip the button name to get the Level number. */ button.replace (/^level/, '');
  90. var label = /* Labels may NOT contain double-quotes. */ labels['level' + level].replace (/"/g, "");
  91. var desc = $.trim ($('input#ws-plugin--s2member-pro-' + button + '-desc').val ().replace (/"/g, ""));
  92.  
  93. var trialAmount = $('input#ws-plugin--s2member-pro-' + button + '-trial-amount').val ().replace (/[^0-9\.]/g, '');
  94. var trialPeriod = $('input#ws-plugin--s2member-pro-' + button + '-trial-period').val ().replace (/[^0-9]/g, '');
  95. var trialTerm = $('select#ws-plugin--s2member-pro-' + button + '-trial-term').val ().replace (/[^A-Z]/g, '');
  96.  
  97. var regAmount = $('input#ws-plugin--s2member-pro-' + button + '-amount').val ().replace (/[^0-9\.]/g, '');
  98. var regPeriod = $('select#ws-plugin--s2member-pro-' + button + '-term').val ().split ('-')[0].replace (/[^0-9]/g, '');
  99. var regTerm = $('select#ws-plugin--s2member-pro-' + button + '-term').val ().split ('-')[1].replace (/[^A-Z]/g, '');
  100. var regRecur = $('select#ws-plugin--s2member-pro-' + button + '-term').val ().split ('-')[2].replace (/[^0-1]/g, '');
  101.  
  102. var currencyCode = $('select#ws-plugin--s2member-pro-' + button + '-currency').val ().replace (/[^A-Z]/g, '');
  103.  
  104. var cCaps = $.trim ($.trim ($('input#ws-plugin--s2member-pro-' + button + '-ccaps').val ()).replace (/^(-all|-al|-a|-)[;,]*/gi, '').replace (/[ \-]/g, '_').replace (/[^a-z_0-9,]/gi, '').toLowerCase ());
  105. cCaps = ($.trim ($('input#ws-plugin--s2member-pro-' + button + '-ccaps').val ()).match (/^(-all|-al|-a|-)[;,]*/i)) ? ((cCaps) ? '-all,' : '-all') + cCaps.toLowerCase () : cCaps.toLowerCase ();
  106.  
  107. trialPeriod = /* Buy Now / Non-Recurring is absolutely NOT compatible w/ Trial Periods. */ (!regRecur || regRecur === '0') ? '0' : trialPeriod;
  108. trialAmount = /* Check Trial Amount. */ (!trialAmount || isNaN(trialAmount) || trialAmount < 0.01 || trialPeriod <= 0) ? '0' : trialAmount;
  109.  
  110. var levelCcapsPer = (!regRecur || regRecur === '0') ? level + ':' + cCaps + ':' + regPeriod + ' ' + regTerm : level + ':' + cCaps;
  111. levelCcapsPer = /* Clean any trailing separators from this string. */ levelCcapsPer.replace (/\:+$/g, '');
  112.  
  113. if (trialAmount !== '0' && (isNaN(trialAmount) || trialAmount < 2.95))
  114. {
  115. alert('— Oops, a slight problem: —\n\nWhen provided, Trial Amount must be >= 2.95');
  116. return false;
  117. }
  118. else if (trialTerm === 'D' && trialPeriod > 0 && /* Min: 2. */ trialPeriod < 2)
  119. {
  120. alert('— Oops, a slight problem: —\n\nMinimum Trial Days is: 2.');
  121. return false;
  122. }
  123. else if (trialTerm === 'D' && trialPeriod > /* Max: 365 days. */ 365)
  124. {
  125. alert('— Oops, a slight problem: —\n\nMaximum Trial Days is: 365.');
  126. return false;
  127. }
  128. else if (!regAmount || isNaN(regAmount) || regAmount < 2.95)
  129. {
  130. alert('— Oops, a slight problem: —\n\nAmount must be >= 2.95');
  131. return false;
  132. }
  133. else if /* Each Button should have a Description. */ (!desc)
  134. {
  135. alert('— Oops, a slight problem: —\n\nPlease type a Description for this Button.');
  136. return false;
  137. }
  138.  
  139. shortCodeTemplateAttrs += 'level="' + esc_attr(level) + '" ccaps="' + esc_attr(cCaps) + '" desc="' + esc_attr(desc) + '" cc="' + esc_attr(currencyCode) + '" custom="<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (esc_attr ($_SERVER["HTTP_HOST"])); ?>"';
  140. shortCodeTemplateAttrs += ' ta="' + esc_attr(trialAmount) + '" tp="' + esc_attr(trialPeriod) + '" tt="' + esc_attr(trialTerm) + '" ra="' + esc_attr(regAmount) + '" rp="' + esc_attr(regPeriod) + '" rt="' + esc_attr(regTerm) + '" rr="' + esc_attr(regRecur) + '"';
  141. shortCode.val (shortCodeTemplate.replace (/%%attrs%%/, shortCodeTemplateAttrs));
  142.  
  143. alert('Your Button has been generated.\nPlease copy/paste the Shortcode into your Membership Options Page.');
  144.  
  145. shortCode.each ( /* Focus and select the Shortcode. */function()
  146. {
  147. this.focus (), this.select ();
  148. });
  149.  
  150. return false;
  151. };
  152.  
  153. ws_plugin__s2member_pro_ccbillCcapButtonGenerate = /* Handles ccBill® Button Generation. */ function()
  154. {
  155. var shortCodeTemplate = '[s2Member-Pro-ccBill-Button %%attrs%% image="default" output="anchor" /]', shortCodeTemplateAttrs = '';
  156.  
  157. var shortCode = $('input#ws-plugin--s2member-pro-ccap-shortcode');
  158.  
  159. var desc = $.trim ($('input#ws-plugin--s2member-pro-ccap-desc').val ().replace (/"/g, ""));
  160.  
  161. var regAmount = $('input#ws-plugin--s2member-pro-ccap-amount').val ().replace (/[^0-9\.]/g, '');
  162. var regPeriod = $('select#ws-plugin--s2member-pro-ccap-term').val ().split ('-')[0].replace (/[^0-9]/g, '');
  163. var regTerm = $('select#ws-plugin--s2member-pro-ccap-term').val ().split ('-')[1].replace (/[^A-Z]/g, '');
  164. var regRecur = $('select#ws-plugin--s2member-pro-ccap-term').val ().split ('-')[2].replace (/[^0-1]/g, '');
  165.  
  166. var currencyCode = $('select#ws-plugin--s2member-pro-ccap-currency').val ().replace (/[^A-Z]/g, '');
  167.  
  168. var cCaps = $.trim ($.trim ($('input#ws-plugin--s2member-pro-ccap-ccaps').val ()).replace (/^(-all|-al|-a|-)[;,]*/gi, '').replace (/[ \-]/g, '_').replace (/[^a-z_0-9,]/gi, '').toLowerCase ());
  169. cCaps = ($.trim ($('input#ws-plugin--s2member-pro-ccap-ccaps').val ()).match (/^(-all|-al|-a|-)[;,]*/i)) ? ((cCaps) ? '-all,' : '-all') + cCaps.toLowerCase () : cCaps.toLowerCase ();
  170.  
  171. var levelCcapsPer = ((!regRecur || regRecur === '0') && regTerm !== 'L') ? '*:' + cCaps + ':' + regPeriod + ' ' + regTerm : '*:' + cCaps;
  172. levelCcapsPer = /* Clean any trailing separators from this string. */ levelCcapsPer.replace (/\:+$/g, '');
  173.  
  174. if (!regAmount || isNaN(regAmount) || regAmount < 2.95)
  175. {
  176. alert('— Oops, a slight problem: —\n\nAmount must be >= 2.95');
  177. return false;
  178. }
  179. else if /* Must have some Independent Custom Capabilities. */ (!cCaps || cCaps === '-all')
  180. {
  181. alert('— Oops, a slight problem: —\n\nPlease provide at least one Custom Capability.');
  182. return false;
  183. }
  184. else if /* Each Button should have a Description. */ (!desc)
  185. {
  186. alert('— Oops, a slight problem: —\n\nPlease type a Description for this Button.');
  187. return false;
  188. }
  189.  
  190. shortCodeTemplateAttrs += 'level="*" ccaps="' + esc_attr(cCaps) + '" desc="' + esc_attr(desc) + '" cc="' + esc_attr(currencyCode) + '" custom="<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (esc_attr ($_SERVER["HTTP_HOST"])); ?>"';
  191. shortCodeTemplateAttrs += ' ra="' + esc_attr(regAmount) + '" rp="' + esc_attr(regPeriod) + '" rt="' + esc_attr(regTerm) + '" rr="' + esc_attr(regRecur) + '"';
  192. shortCode.val (shortCodeTemplate.replace (/%%attrs%%/, shortCodeTemplateAttrs));
  193.  
  194. alert('Your Button has been generated.\nPlease copy/paste the Shortcode into your WordPress® Editor.');
  195.  
  196. shortCode.each ( /* Focus and select the Shortcode. */function()
  197. {
  198. this.focus (), this.select ();
  199. });
  200.  
  201. return false;
  202. };
  203.  
  204. ws_plugin__s2member_pro_ccbillSpButtonGenerate = /* Handles ccBill® Button Generation for Specific Post/Page Access. */ function()
  205. {
  206. var shortCodeTemplate = '[s2Member-Pro-ccBill-Button %%attrs%% image="default" output="button" /]', shortCodeTemplateAttrs = '';
  207.  
  208. var shortCode = $('input#ws-plugin--s2member-pro-sp-shortcode');
  209.  
  210. var leading = $('select#ws-plugin--s2member-pro-sp-leading-id').val ().replace (/[^0-9]/g, '');
  211. var additionals = $('select#ws-plugin--s2member-pro-sp-additional-ids').val () || [];
  212. var hours = $('select#ws-plugin--s2member-pro-sp-hours').val ().replace (/[^0-9]/g, '');
  213. var regAmount = $('input#ws-plugin--s2member-pro-sp-amount').val ().replace (/[^0-9\.]/g, '');
  214. var desc = $.trim ($('input#ws-plugin--s2member-pro-sp-desc').val ().replace (/"/g, ''));
  215. var currencyCode = $('select#ws-plugin--s2member-pro-sp-currency').val ().replace (/[^A-Z]/g, '');
  216.  
  217. if /* Must have a Leading Post/Page ID to work with. Otherwise, Link generation will fail. */ (!leading)
  218. {
  219. alert('— Oops, a slight problem: —\n\nPlease select a Leading Post/Page.\n\n*Tip* If there are no Posts/Pages in the menu, it\'s because you\'ve not configured s2Member for Specific Post/Page Access yet. See: s2Member -› Restriction Options -› Specific Post/Page Access.');
  220. return false;
  221. }
  222. else if (!regAmount || isNaN(regAmount) || regAmount < 2.95)
  223. {
  224. alert('— Oops, a slight problem: —\n\nAmount must be >= 2.95');
  225. return false;
  226. }
  227. else if /* Each Button should have a Description. */ (!desc)
  228. {
  229. alert('— Oops, a slight problem: —\n\nPlease type a Description for this Button.');
  230. return false;
  231. }
  232.  
  233. for (var i = 0, ids = leading; i < additionals.length; i++)
  234. if (additionals[i] && additionals[i] !== leading)
  235. ids += ',' + additionals[i];
  236.  
  237. var spIdsHours = /* Combined sp:ids:expiration hours. */ 'sp:' + ids + ':' + hours;
  238.  
  239. shortCodeTemplateAttrs += 'sp="1" ids="' + esc_attr(ids) + '" exp="' + esc_attr(hours) + '" desc="' + esc_attr(desc) + '" cc="' + esc_attr(currencyCode) + '"';
  240. shortCodeTemplateAttrs += ' custom="<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (esc_attr ($_SERVER["HTTP_HOST"])); ?>" ra="' + esc_attr(regAmount) + '"';
  241. shortCode.val (shortCodeTemplate.replace (/%%attrs%%/, shortCodeTemplateAttrs));
  242.  
  243. alert('Your Button has been generated.\nPlease copy/paste the Shortcode into your WordPress® Editor.');
  244.  
  245. shortCode.each ( /* Focus and select the Shortcode. */function()
  246. {
  247. this.focus (), this.select ();
  248. });
  249.  
  250. return false;
  251. };
  252.  
  253. ws_plugin__s2member_pro_ccbillRegLinkGenerate = /* Handles ccBill® Link Generation. */ function()
  254. {
  255. var level = $('select#ws-plugin--s2member-pro-reg-link-level').val ().replace (/[^0-9]/g, '');
  256. var subscrID = $.trim ($('input#ws-plugin--s2member-pro-reg-link-subscr-id').val ());
  257. var custom = $.trim ($('input#ws-plugin--s2member-pro-reg-link-custom').val ());
  258. var cCaps = $.trim ($.trim ($('input#ws-plugin--s2member-pro-reg-link-ccaps').val ()).replace (/[ \-]/g, '_').replace (/[^a-z_0-9,]/gi, '').toLowerCase ());
  259. var fixedTerm = $.trim ($('input#ws-plugin--s2member-pro-reg-link-fixed-term').val ().replace (/[^A-Z 0-9]/gi, '').toUpperCase ());
  260. var $link = $('p#ws-plugin--s2member-pro-reg-link'), $loading = $('img#ws-plugin--s2member-pro-reg-link-loading');
  261.  
  262. var levelCcapsPer = (fixedTerm && !fixedTerm.match (/L$/)) ? level + ':' + cCaps + ':' + fixedTerm : level + ':' + cCaps;
  263. levelCcapsPer = /* Clean any trailing separators from this string. */ levelCcapsPer.replace (/\:+$/g, '');
  264.  
  265. if /* We must have a Paid Subscr. ID value. */ (!subscrID)
  266. {
  267. alert('— Oops, a slight problem: —\n\nPaid Subscr. ID is a required value.');
  268. return false;
  269. }
  270. else if (!custom || custom.indexOf ('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq ($_SERVER["HTTP_HOST"]); ?>') !== 0)
  271. {
  272. alert('— Oops, a slight problem: —\n\nThe Custom Value MUST start with your domain name.');
  273. return false;
  274. }
  275. else if /* Check format. */ (fixedTerm && !fixedTerm.match (/^[1-9]+ (D|W|M|Y|L)$/))
  276. {
  277. alert('— Oops, a slight problem: —\n\nThe Fixed Term Length is not formatted properly.');
  278. return false;
  279. }
  280.  
  281. $link.hide (), $loading.show (), $.post (ajaxurl, {action: 'ws_plugin__s2member_reg_access_link_via_ajax', ws_plugin__s2member_reg_access_link_via_ajax: '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (wp_create_nonce ("ws-plugin--s2member-reg-access-link-via-ajax")); ?>', s2member_reg_access_link_subscr_gateway: 'ccbill', s2member_reg_access_link_subscr_id: subscrID, s2member_reg_access_link_custom: custom, s2member_reg_access_link_item_number: levelCcapsPer}, function(response)
  282. {
  283. $link.show ().html ('<a href="' + esc_attr(response) + '" target="_blank" rel="external">' + esc_html(response) + '</a>'), $loading.hide ();
  284. });
  285.  
  286. return false;
  287. };
  288.  
  289. ws_plugin__s2member_pro_ccbillSpLinkGenerate = /* Handles ccBill® Link Generation. */ function()
  290. {
  291. var leading = $('select#ws-plugin--s2member-pro-sp-link-leading-id').val ().replace (/[^0-9]/g, '');
  292. var additionals = $('select#ws-plugin--s2member-pro-sp-link-additional-ids').val () || [];
  293. var hours = $('select#ws-plugin--s2member-pro-sp-link-hours').val ().replace (/[^0-9]/g, '');
  294. var $link = $('p#ws-plugin--s2member-pro-sp-link'), $loading = $('img#ws-plugin--s2member-pro-sp-link-loading');
  295.  
  296. if /* Must have a Leading Post/Page ID to work with. Otherwise, Link generation will fail. */ (!leading)
  297. {
  298. alert('— Oops, a slight problem: —\n\nPlease select a Leading Post/Page.\n\n*Tip* If there are no Posts/Pages in the menu, it\'s because you\'ve not configured s2Member for Specific Post/Page Access yet. See: s2Member -› Restriction Options -› Specific Post/Page Access.');
  299. return false;
  300. }
  301.  
  302. for (var i = 0, ids = leading; i < additionals.length; i++)
  303. if (additionals[i] && additionals[i] !== leading)
  304. ids += ',' + additionals[i];
  305.  
  306. $link.hide (), $loading.show (), $.post (ajaxurl, {action: 'ws_plugin__s2member_sp_access_link_via_ajax', ws_plugin__s2member_sp_access_link_via_ajax: '<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (wp_create_nonce ("ws-plugin--s2member-sp-access-link-via-ajax")); ?>', s2member_sp_access_link_ids: ids, s2member_sp_access_link_hours: hours}, function(response)
  307. {
  308. $link.show ().html ('<a href="' + esc_attr(response) + '" target="_blank" rel="external">' + esc_html(response) + '</a>'), $loading.hide ();
  309. });
  310.  
  311. return false;
  312. };
  313. }
  314. });

pro\s2member-pro\includes\menu-pages\ccbill-menu-pages-s.js

Source Code Documentation