Source Code Documentation


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


  1. /**
  2. * Core JavaScript routines for AliPay® 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-alipay-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-alipay-buttons/))
  54. {
  55. $('div.ws-menu-page input[id]').filter ( /* Filter all input elements with an id. */function()
  56. {
  57. return this.id.match (/^ws-plugin--s2member-pro-(level[1-9][0-9]*|ccap)-ccaps$/);
  58. }).keyup (function()
  59. {
  60. var value = this.value.replace (/^(-all|-al|-a|-)[;,]*/gi, ''), _all = (this.value.match (/^(-all|-al|-a|-)[;,]*/i)) ? '-all,' : '';
  61. if /* Only if there is a problem with the actual values; because this causes interruptions. */ (value.match (/[^a-z_0-9,]/))
  62. this.value = _all + $.trim ($.trim (value).replace (/[ \-]/g, '_').replace (/[^a-z_0-9,]/gi, '').toLowerCase ());
  63. });
  64.  
  65. ws_plugin__s2member_pro_alipayButtonGenerate = /* Handles AliPay® Button Generation. */ function(button)
  66. {
  67. var shortCodeTemplate = '[s2Member-Pro-AliPay-Button %%attrs%% image="default" output="anchor" /]', shortCodeTemplateAttrs = '', labels = {};
  68.  
  69. eval("<?php echo c_ws_plugin__s2member_utils_strings::esc_dq($vars['labels']); ?>");
  70.  
  71. var shortCode = $('input#ws-plugin--s2member-pro-' + button + '-shortcode');
  72.  
  73. var level = button.replace (/^level/, '');
  74. var label = /* Labels may NOT contain any double-quotes. */ labels['level' + level].replace (/"/g, "");
  75. var desc = $.trim ($('input#ws-plugin--s2member-pro-' + button + '-desc').val ().replace (/"/g, ""));
  76.  
  77. var regAmount = $('input#ws-plugin--s2member-pro-' + button + '-amount').val ().replace (/[^0-9\.]/g, '');
  78. var regPeriod = $('select#ws-plugin--s2member-pro-' + button + '-term').val ().split ('-')[0].replace (/[^0-9]/g, '');
  79. var regTerm = $('select#ws-plugin--s2member-pro-' + button + '-term').val ().split ('-')[1].replace (/[^A-Z]/g, '');
  80.  
  81. 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 ());
  82. cCaps = ($.trim ($('input#ws-plugin--s2member-pro-' + button + '-ccaps').val ()).match (/^(-all|-al|-a|-)[;,]*/i)) ? ((cCaps) ? '-all,' : '-all') + cCaps.toLowerCase () : cCaps.toLowerCase ();
  83.  
  84. var levelCcapsPer = (regTerm !== 'L') ? level + ':' + cCaps + ':' + regPeriod + ' ' + regTerm : level + ':' + cCaps;
  85. levelCcapsPer = /* Clean any trailing separators from this string. */ levelCcapsPer.replace (/\:+$/g, '');
  86.  
  87. if (!regAmount || isNaN(regAmount) || regAmount < 0.01)
  88. {
  89. alert('— Oops, a slight problem: —\n\nAmount must be >= 0.01');
  90. return false;
  91. }
  92. else if (regAmount > /* $10,000.00 maximum. */ 10000.00)
  93. {
  94. alert('— Oops, a slight problem: —\n\nMaximum Amount is: 10000.00');
  95. return false;
  96. }
  97. else if /* Each Button should have a Description. */ (!desc)
  98. {
  99. alert('— Oops, a slight problem: —\n\nPlease type a Description for this Button.');
  100. return false;
  101. }
  102.  
  103. shortCodeTemplateAttrs += 'level="' + esc_attr(level) + '" ccaps="' + esc_attr(cCaps) + '" desc="' + esc_attr(desc) + '" custom="<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (esc_attr ($_SERVER["HTTP_HOST"])); ?>"';
  104. shortCodeTemplateAttrs += ' ra="' + esc_attr(regAmount) + '" rp="' + esc_attr(regPeriod) + '" rt="' + esc_attr(regTerm) + '"';
  105. shortCode.val (shortCodeTemplate.replace (/%%attrs%%/, shortCodeTemplateAttrs));
  106.  
  107. alert('Your Button has been generated.\nPlease copy/paste the Shortcode into your Membership Options Page.');
  108.  
  109. shortCode.each ( /* Focus and select the Shortcode. */function()
  110. {
  111. this.focus (), this.select ();
  112. });
  113.  
  114. return false;
  115. };
  116.  
  117. ws_plugin__s2member_pro_alipayCcapButtonGenerate = /* Handles AliPay® Button Generation. */ function()
  118. {
  119. var shortCodeTemplate = '[s2Member-Pro-AliPay-Button %%attrs%% image="default" output="anchor" /]', shortCodeTemplateAttrs = '';
  120.  
  121. var shortCode = $('input#ws-plugin--s2member-pro-ccap-shortcode');
  122.  
  123. var desc = $.trim ($('input#ws-plugin--s2member-pro-ccap-desc').val ().replace (/"/g, ""));
  124.  
  125. var regAmount = $('input#ws-plugin--s2member-pro-ccap-amount').val ().replace (/[^0-9\.]/g, '');
  126. var regPeriod = $('select#ws-plugin--s2member-pro-ccap-term').val ().split ('-')[0].replace (/[^0-9]/g, '');
  127. var regTerm = $('select#ws-plugin--s2member-pro-ccap-term').val ().split ('-')[1].replace (/[^A-Z]/g, '');
  128.  
  129. 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 ());
  130. cCaps = ($.trim ($('input#ws-plugin--s2member-pro-ccap-ccaps').val ()).match (/^(-all|-al|-a|-)[;,]*/i)) ? ((cCaps) ? '-all,' : '-all') + cCaps.toLowerCase () : cCaps.toLowerCase ();
  131.  
  132. var levelCcapsPer = (regTerm !== 'L') ? '*:' + cCaps + ':' + regPeriod + ' ' + regTerm : '*:' + cCaps;
  133. levelCcapsPer = /* Clean any trailing separators. */ levelCcapsPer.replace (/\:+$/g, '');
  134.  
  135. if (!regAmount || isNaN(regAmount) || regAmount < 0.01)
  136. {
  137. alert('— Oops, a slight problem: —\n\nAmount must be >= 0.01');
  138. return false;
  139. }
  140. else if (regAmount > /* $10,000.00 maximum. */ 10000.00)
  141. {
  142. alert('— Oops, a slight problem: —\n\nMaximum Amount is: 10000.00');
  143. return false;
  144. }
  145. else if /* Must have some Independent Custom Capabilities. */ (!cCaps || cCaps === '-all')
  146. {
  147. alert('— Oops, a slight problem: —\n\nPlease provide at least one Custom Capability.');
  148. return false;
  149. }
  150. else if /* Each Button should have a Description. */ (!desc)
  151. {
  152. alert('— Oops, a slight problem: —\n\nPlease type a Description for this Button.');
  153. return false;
  154. }
  155.  
  156. shortCodeTemplateAttrs += 'level="*" ccaps="' + esc_attr(cCaps) + '" desc="' + esc_attr(desc) + '" custom="<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (esc_attr ($_SERVER["HTTP_HOST"])); ?>"';
  157. shortCodeTemplateAttrs += ' ra="' + esc_attr(regAmount) + '" rp="' + esc_attr(regPeriod) + '" rt="' + esc_attr(regTerm) + '"';
  158. shortCode.val (shortCodeTemplate.replace (/%%attrs%%/, shortCodeTemplateAttrs));
  159.  
  160. alert('Your Button has been generated.\nPlease copy/paste the Shortcode into your WordPress® Editor.');
  161.  
  162. shortCode.each ( /* Focus and select the Shortcode. */function()
  163. {
  164. this.focus (), this.select ();
  165. });
  166.  
  167. return false;
  168. };
  169.  
  170. ws_plugin__s2member_pro_alipaySpButtonGenerate = /* Handles AliPay® Button Generation for Specific Post/Page Access. */ function()
  171. {
  172. var shortCodeTemplate = '[s2Member-Pro-AliPay-Button %%attrs%% image="default" output="anchor" /]', shortCodeTemplateAttrs = '';
  173.  
  174. var shortCode = $('input#ws-plugin--s2member-pro-sp-shortcode');
  175.  
  176. var leading = $('select#ws-plugin--s2member-pro-sp-leading-id').val ().replace (/[^0-9]/g, '');
  177. var additionals = $('select#ws-plugin--s2member-pro-sp-additional-ids').val () || [];
  178. var hours = $('select#ws-plugin--s2member-pro-sp-hours').val ().replace (/[^0-9]/g, '');
  179. var regAmount = $('input#ws-plugin--s2member-pro-sp-amount').val ().replace (/[^0-9\.]/g, '');
  180. var desc = $.trim ($('input#ws-plugin--s2member-pro-sp-desc').val ().replace (/"/g, ''));
  181.  
  182. if /* Must have a Leading Post/Page ID to work with. Otherwise, Link generation will fail. */ (!leading)
  183. {
  184. 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.');
  185. return false;
  186. }
  187. else if (!regAmount || isNaN(regAmount) || regAmount < 0.01)
  188. {
  189. alert('— Oops, a slight problem: —\n\nAmount must be >= 0.01');
  190. return false;
  191. }
  192. else if (regAmount > /* $10,000.00 maximum. */ 10000.00)
  193. {
  194. alert('— Oops, a slight problem: —\n\nMaximum Amount is: 10000.00');
  195. return false;
  196. }
  197. else if /* Each Button should have a Description. */ (!desc)
  198. {
  199. alert('— Oops, a slight problem: —\n\nPlease type a Description for this Button.');
  200. return false;
  201. }
  202.  
  203. for (var i = 0, ids = leading; i < additionals.length; i++)
  204. if (additionals[i] && additionals[i] !== leading)
  205. ids += ',' + additionals[i];
  206.  
  207. var /* Combined sp:ids:expiration hours. */ spIdsHours = 'sp:' + ids + ':' + hours;
  208.  
  209. shortCodeTemplateAttrs += 'sp="1" ids="' + esc_attr(ids) + '" exp="' + esc_attr(hours) + '" desc="' + esc_attr(desc) + '"';
  210. shortCodeTemplateAttrs += ' custom="<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (esc_attr ($_SERVER["HTTP_HOST"])); ?>" ra="' + esc_attr(regAmount) + '"';
  211. shortCode.val (shortCodeTemplate.replace (/%%attrs%%/, shortCodeTemplateAttrs));
  212.  
  213. alert('Your Button has been generated.\nPlease copy/paste the Shortcode into your WordPress® Editor.');
  214.  
  215. shortCode.each ( /* Focus and select the Shortcode. */function()
  216. {
  217. this.focus (), this.select ();
  218. });
  219.  
  220. return false;
  221. };
  222.  
  223. ws_plugin__s2member_pro_alipayRegLinkGenerate = /* Handles AliPay® Link Generation. */ function()
  224. {
  225. var level = $('select#ws-plugin--s2member-pro-reg-link-level').val ().replace (/[^0-9]/g, '');
  226. var subscrID = $.trim ($('input#ws-plugin--s2member-pro-reg-link-subscr-id').val ());
  227. var custom = $.trim ($('input#ws-plugin--s2member-pro-reg-link-custom').val ());
  228. var cCaps = $.trim ($.trim ($('input#ws-plugin--s2member-pro-reg-link-ccaps').val ()).replace (/[ \-]/g, '_').replace (/[^a-z_0-9,]/gi, '').toLowerCase ());
  229. var fixedTerm = $.trim ($('input#ws-plugin--s2member-pro-reg-link-fixed-term').val ().replace (/[^A-Z 0-9]/gi, '').toUpperCase ());
  230. var $link = $('p#ws-plugin--s2member-pro-reg-link'), $loading = $('img#ws-plugin--s2member-pro-reg-link-loading');
  231.  
  232. var levelCcapsPer = (fixedTerm && !fixedTerm.match (/L$/)) ? level + ':' + cCaps + ':' + fixedTerm : level + ':' + cCaps;
  233. levelCcapsPer = /* Clean any trailing separators from this string. */ levelCcapsPer.replace (/\:+$/g, '');
  234.  
  235. if /* We must have a Paid Subscr. ID value. */ (!subscrID)
  236. {
  237. alert('— Oops, a slight problem: —\n\nPaid Subscr. ID is a required value.');
  238. return false;
  239. }
  240. else if (!custom || custom.indexOf ('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq ($_SERVER["HTTP_HOST"]); ?>') !== 0)
  241. {
  242. alert('— Oops, a slight problem: —\n\nThe Custom Value MUST start with your domain name.');
  243. return false;
  244. }
  245. else if /* Check format. */ (fixedTerm && !fixedTerm.match (/^[1-9]+ (D|W|M|Y|L)$/))
  246. {
  247. alert('— Oops, a slight problem: —\n\nThe Fixed Term Length is not formatted properly.');
  248. return false;
  249. }
  250.  
  251. $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: 'alipay', s2member_reg_access_link_subscr_id: subscrID, s2member_reg_access_link_custom: custom, s2member_reg_access_link_item_number: levelCcapsPer}, function(response)
  252. {
  253. $link.show ().html ('<a href="' + esc_attr(response) + '" target="_blank" rel="external">' + esc_html(response) + '</a>'), $loading.hide ();
  254. });
  255.  
  256. return false;
  257. };
  258.  
  259. ws_plugin__s2member_pro_alipaySpLinkGenerate = /* Handles AliPay® Link Generation. */ function()
  260. {
  261. var leading = $('select#ws-plugin--s2member-pro-sp-link-leading-id').val ().replace (/[^0-9]/g, '');
  262. var additionals = $('select#ws-plugin--s2member-pro-sp-link-additional-ids').val () || [];
  263. var hours = $('select#ws-plugin--s2member-pro-sp-link-hours').val ().replace (/[^0-9]/g, '');
  264. var $link = $('p#ws-plugin--s2member-pro-sp-link'), $loading = $('img#ws-plugin--s2member-pro-sp-link-loading');
  265.  
  266. if /* Must have a Leading Post/Page ID to work with. Otherwise, Link generation will fail. */ (!leading)
  267. {
  268. 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.');
  269. return false;
  270. }
  271.  
  272. for (var i = 0, ids = leading; i < additionals.length; i++)
  273. if (additionals[i] && additionals[i] !== leading)
  274. ids += ',' + additionals[i];
  275.  
  276. $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)
  277. {
  278. $link.show ().html ('<a href="' + esc_attr(response) + '" target="_blank" rel="external">' + esc_html(response) + '</a>'), $loading.hide ();
  279. });
  280.  
  281. return false;
  282. };
  283. }
  284. });

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

Source Code Documentation