Source Code Documentation


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


  1. /**
  2. * Core JavaScript routines for Google® 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-google-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-google-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-1BN]/g, '') === 'BN') ? 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_googleButtonGenerate = /* Handles Google® Button Generation. */ function(button)
  82. {
  83. var shortCodeTemplate = '[s2Member-Pro-Google-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-1BN]/g, '');
  101. var /* These options are NOT yet configurable. */ regRecurTimes = '', regRecurRetries = '2';
  102.  
  103. var currencyCode = $('select#ws-plugin--s2member-pro-' + button + '-currency').val ().replace (/[^A-Z]/g, '');
  104.  
  105. 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 ());
  106. cCaps = ($.trim ($('input#ws-plugin--s2member-pro-' + button + '-ccaps').val ()).match (/^(-all|-al|-a|-)[;,]*/i)) ? ((cCaps) ? '-all,' : '-all') + cCaps.toLowerCase () : cCaps.toLowerCase ();
  107.  
  108. trialPeriod = /* Lifetime (1-L-BN) and Buy Now ( BN ) access is absolutely NOT compatible w/ Trial Periods. */ (regRecur === 'BN') ? '0' : trialPeriod;
  109. trialAmount = /* Validate Trial Amount. */ (!trialAmount || isNaN(trialAmount) || trialAmount < 0.01 || trialPeriod <= 0) ? '0' : trialAmount;
  110.  
  111. var levelCcapsPer = (regRecur === 'BN' && regTerm !== 'L') ? level + ':' + cCaps + ':' + regPeriod + ' ' + regTerm : level + ':' + cCaps;
  112. levelCcapsPer = /* Clean any trailing separators from this string. */ levelCcapsPer.replace (/\:+$/g, '');
  113.  
  114. if (trialAmount !== '0' && (isNaN(trialAmount) || trialAmount < 0.00))
  115. {
  116. alert('— Oops, a slight problem: —\n\nWhen provided, Trial Amount must be >= 0.00');
  117. return false;
  118. }
  119. else if (trialAmount !== '0' && trialAmount > /* $10,000.00 maximum. */ 10000.00)
  120. {
  121. alert('— Oops, a slight problem: —\n\nMaximum Trial Amount is: 10000.00');
  122. return false;
  123. }
  124. else if (trialTerm === 'D' && /* Some validation on the Trial Period. Max days: 7. */ trialPeriod > 7)
  125. {
  126. alert('— Oops, a slight problem: —\n\nMaximum Trial Days is: 7.\nIf you want to offer more than 7 days, please choose Weeks or Months from the drop-down.');
  127. return false;
  128. }
  129. else if (trialTerm === 'W' && /* Some validation on the Trial Period. 52 max. */ trialPeriod > 52)
  130. {
  131. alert('— Oops, a slight problem: —\n\nMaximum Trial Weeks is: 52.\nIf you want to offer more than 52 weeks, please choose Months from the drop-down.');
  132. return false;
  133. }
  134. else if (trialTerm === 'M' && /* Some validation on the Trial Period. 12 max. */ trialPeriod > 12)
  135. {
  136. alert('— Oops, a slight problem: —\n\nMaximum Trial Months is: 12.\nIf you want to offer more than 12 months, please choose Years from the drop-down.');
  137. return false;
  138. }
  139. else if (trialTerm === 'Y' && /* 1 year max. */ trialPeriod > 1)
  140. {
  141. alert('— Oops, a slight problem: —\n\nMax Trial Period Years is: 1.');
  142. return false;
  143. }
  144. else if (!regAmount || isNaN(regAmount) || regAmount < 0.01)
  145. {
  146. alert('— Oops, a slight problem: —\n\nAmount must be >= 0.01');
  147. return false;
  148. }
  149. else if (regAmount > /* $10,000.00 maximum. */ 10000.00)
  150. {
  151. alert('— Oops, a slight problem: —\n\nMaximum Amount is: 10000.00');
  152. return false;
  153. }
  154. else if /* Each Button should have a Description. */ (!desc)
  155. {
  156. alert('— Oops, a slight problem: —\n\nPlease type a Description for this Button.');
  157. return false;
  158. }
  159.  
  160. 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"])); ?>"';
  161. 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) + '" rrt="' + esc_attr(regRecurTimes) + '"';
  162. shortCode.val (shortCodeTemplate.replace (/%%attrs%%/, shortCodeTemplateAttrs));
  163.  
  164. alert('Your Button has been generated.\nPlease copy/paste the Shortcode into your Membership Options Page.');
  165.  
  166. shortCode.each ( /* Focus and select the Shortcode. */function()
  167. {
  168. this.focus (), this.select ();
  169. });
  170.  
  171. return false;
  172. };
  173.  
  174. ws_plugin__s2member_pro_googleCcapButtonGenerate = /* Handles Google® Button Generation. */ function()
  175. {
  176. var shortCodeTemplate = '[s2Member-Pro-Google-Button %%attrs%% image="default" output="anchor" /]', shortCodeTemplateAttrs = '';
  177.  
  178. var shortCode = $('input#ws-plugin--s2member-pro-ccap-shortcode');
  179.  
  180. var desc = $.trim ($('input#ws-plugin--s2member-pro-ccap-desc').val ().replace (/"/g, ""));
  181.  
  182. var regAmount = $('input#ws-plugin--s2member-pro-ccap-amount').val ().replace (/[^0-9\.]/g, '');
  183. var regPeriod = $('select#ws-plugin--s2member-pro-ccap-term').val ().split ('-')[0].replace (/[^0-9]/g, '');
  184. var regTerm = $('select#ws-plugin--s2member-pro-ccap-term').val ().split ('-')[1].replace (/[^A-Z]/g, '');
  185. var regRecur = $('select#ws-plugin--s2member-pro-ccap-term').val ().split ('-')[2].replace (/[^0-1BN]/g, '');
  186.  
  187. var currencyCode = $('select#ws-plugin--s2member-pro-ccap-currency').val ().replace (/[^A-Z]/g, '');
  188.  
  189. 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 ());
  190. cCaps = ($.trim ($('input#ws-plugin--s2member-pro-ccap-ccaps').val ()).match (/^(-all|-al|-a|-)[;,]*/i)) ? ((cCaps) ? '-all,' : '-all') + cCaps.toLowerCase () : cCaps.toLowerCase ();
  191.  
  192. var levelCcapsPer = (regRecur === 'BN' && regTerm !== 'L') ? '*:' + cCaps + ':' + regPeriod + ' ' + regTerm : '*:' + cCaps;
  193. levelCcapsPer = /* Clean any trailing separators from this string. */ levelCcapsPer.replace (/\:+$/g, '');
  194.  
  195. if (!regAmount || isNaN(regAmount) || regAmount < 0.01)
  196. {
  197. alert('— Oops, a slight problem: —\n\nAmount must be >= 0.01');
  198. return false;
  199. }
  200. else if (regAmount > /* $10,000.00 maximum. */ 10000.00)
  201. {
  202. alert('— Oops, a slight problem: —\n\nMaximum Amount is: 10000.00');
  203. return false;
  204. }
  205. else if /* Must have some Independent Custom Capabilities. */ (!cCaps || cCaps === '-all')
  206. {
  207. alert('— Oops, a slight problem: —\n\nPlease provide at least one Custom Capability.');
  208. return false;
  209. }
  210. else if /* Each Button should have a Description. */ (!desc)
  211. {
  212. alert('— Oops, a slight problem: —\n\nPlease type a Description for this Button.');
  213. return false;
  214. }
  215.  
  216. 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"])); ?>"';
  217. shortCodeTemplateAttrs += ' ra="' + esc_attr(regAmount) + '" rp="' + esc_attr(regPeriod) + '" rt="' + esc_attr(regTerm) + '" rr="' + esc_attr(regRecur) + '"';
  218. shortCode.val (shortCodeTemplate.replace (/%%attrs%%/, shortCodeTemplateAttrs));
  219.  
  220. alert('Your Button has been generated.\nPlease copy/paste the Shortcode into your WordPress® Editor.');
  221.  
  222. shortCode.each ( /* Focus and select the Shortcode. */function()
  223. {
  224. this.focus (), this.select ();
  225. });
  226.  
  227. return false;
  228. };
  229.  
  230. ws_plugin__s2member_pro_googleSpButtonGenerate = /* Handles Google® Button Generation for Specific Post/Page Access. */ function()
  231. {
  232. var shortCodeTemplate = '[s2Member-Pro-Google-Button %%attrs%% image="default" output="button" /]', shortCodeTemplateAttrs = '';
  233.  
  234. var shortCode = $('input#ws-plugin--s2member-pro-sp-shortcode');
  235.  
  236. var leading = $('select#ws-plugin--s2member-pro-sp-leading-id').val ().replace (/[^0-9]/g, '');
  237. var additionals = $('select#ws-plugin--s2member-pro-sp-additional-ids').val () || [];
  238. var hours = $('select#ws-plugin--s2member-pro-sp-hours').val ().replace (/[^0-9]/g, '');
  239. var regAmount = $('input#ws-plugin--s2member-pro-sp-amount').val ().replace (/[^0-9\.]/g, '');
  240. var desc = $.trim ($('input#ws-plugin--s2member-pro-sp-desc').val ().replace (/"/g, ''));
  241. var currencyCode = $('select#ws-plugin--s2member-pro-sp-currency').val ().replace (/[^A-Z]/g, '');
  242.  
  243. if /* Must have a Leading Post/Page ID to work with. Otherwise, Link generation will fail. */ (!leading)
  244. {
  245. 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.');
  246. return false;
  247. }
  248. else if (!regAmount || isNaN(regAmount) || regAmount < 0.01)
  249. {
  250. alert('— Oops, a slight problem: —\n\nAmount must be >= 0.01');
  251. return false;
  252. }
  253. else if (regAmount > /* $10,000.00 maximum. */ 10000.00)
  254. {
  255. alert('— Oops, a slight problem: —\n\nMaximum Amount is: 10000.00');
  256. return false;
  257. }
  258. else if /* Each Button should have a Description. */ (!desc)
  259. {
  260. alert('— Oops, a slight problem: —\n\nPlease type a Description for this Button.');
  261. return false;
  262. }
  263.  
  264. for (var i = 0, ids = leading; i < additionals.length; i++)
  265. if (additionals[i] && additionals[i] !== leading)
  266. ids += ',' + additionals[i];
  267.  
  268. var spIdsHours = /* Combined sp:ids:expiration hours. */ 'sp:' + ids + ':' + hours;
  269.  
  270. shortCodeTemplateAttrs += 'sp="1" ids="' + esc_attr(ids) + '" exp="' + esc_attr(hours) + '" desc="' + esc_attr(desc) + '" cc="' + esc_attr(currencyCode) + '"';
  271. shortCodeTemplateAttrs += ' custom="<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq (esc_attr ($_SERVER["HTTP_HOST"])); ?>" ra="' + esc_attr(regAmount) + '"';
  272. shortCode.val (shortCodeTemplate.replace (/%%attrs%%/, shortCodeTemplateAttrs));
  273.  
  274. alert('Your Button has been generated.\nPlease copy/paste the Shortcode into your WordPress® Editor.');
  275.  
  276. shortCode.each ( /* Focus and select the Shortcode. */function()
  277. {
  278. this.focus (), this.select ();
  279. });
  280.  
  281. return false;
  282. };
  283.  
  284. ws_plugin__s2member_pro_googleRegLinkGenerate = /* Handles Google® Link Generation. */ function()
  285. {
  286. var level = $('select#ws-plugin--s2member-pro-reg-link-level').val ().replace (/[^0-9]/g, '');
  287. var subscrID = $.trim ($('input#ws-plugin--s2member-pro-reg-link-subscr-id').val ());
  288. var custom = $.trim ($('input#ws-plugin--s2member-pro-reg-link-custom').val ());
  289. var cCaps = $.trim ($.trim ($('input#ws-plugin--s2member-pro-reg-link-ccaps').val ()).replace (/[ \-]/g, '_').replace (/[^a-z_0-9,]/gi, '').toLowerCase ());
  290. var fixedTerm = $.trim ($('input#ws-plugin--s2member-pro-reg-link-fixed-term').val ().replace (/[^A-Z 0-9]/gi, '').toUpperCase ());
  291. var $link = $('p#ws-plugin--s2member-pro-reg-link'), $loading = $('img#ws-plugin--s2member-pro-reg-link-loading');
  292.  
  293. var levelCcapsPer = (fixedTerm && !fixedTerm.match (/L$/)) ? level + ':' + cCaps + ':' + fixedTerm : level + ':' + cCaps;
  294. levelCcapsPer = /* Clean any trailing separators from this string. */ levelCcapsPer.replace (/\:+$/g, '');
  295.  
  296. if /* We must have a Paid Subscr. ID value. */ (!subscrID)
  297. {
  298. alert('— Oops, a slight problem: —\n\nPaid Subscr. ID is a required value.');
  299. return false;
  300. }
  301. else if (!custom || custom.indexOf ('<?php echo c_ws_plugin__s2member_utils_strings::esc_js_sq ($_SERVER["HTTP_HOST"]); ?>') !== 0)
  302. {
  303. alert('— Oops, a slight problem: —\n\nThe Custom Value MUST start with your domain name.');
  304. return false;
  305. }
  306. else if /* Check format. */ (fixedTerm && !fixedTerm.match (/^[1-9]+ (D|W|M|Y|L)$/))
  307. {
  308. alert('— Oops, a slight problem: —\n\nThe Fixed Term Length is not formatted properly.');
  309. return false;
  310. }
  311.  
  312. $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: 'google', s2member_reg_access_link_subscr_id: subscrID, s2member_reg_access_link_custom: custom, s2member_reg_access_link_item_number: levelCcapsPer}, function(response)
  313. {
  314. $link.show ().html ('<a href="' + esc_attr(response) + '" target="_blank" rel="external">' + esc_html(response) + '</a>'), $loading.hide ();
  315. });
  316.  
  317. return false;
  318. };
  319.  
  320. ws_plugin__s2member_pro_googleSpLinkGenerate = /* Handles Google® Link Generation. */ function()
  321. {
  322. var leading = $('select#ws-plugin--s2member-pro-sp-link-leading-id').val ().replace (/[^0-9]/g, '');
  323. var additionals = $('select#ws-plugin--s2member-pro-sp-link-additional-ids').val () || [];
  324. var hours = $('select#ws-plugin--s2member-pro-sp-link-hours').val ().replace (/[^0-9]/g, '');
  325. var $link = $('p#ws-plugin--s2member-pro-sp-link'), $loading = $('img#ws-plugin--s2member-pro-sp-link-loading');
  326.  
  327. if /* Must have a Leading Post/Page ID to work with. Otherwise, Link generation will fail. */ (!leading)
  328. {
  329. 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.');
  330. return false;
  331. }
  332.  
  333. for (var i = 0, ids = leading; i < additionals.length; i++)
  334. if (additionals[i] && additionals[i] !== leading)
  335. ids += ',' + additionals[i];
  336.  
  337. $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)
  338. {
  339. $link.show ().html ('<a href="' + esc_attr(response) + '" target="_blank" rel="external">' + esc_html(response) + '</a>'), $loading.hide ();
  340. });
  341.  
  342. return false;
  343. };
  344. }
  345. });

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

Source Code Documentation