Source Code Documentation


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

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

Source Code Documentation