1 line
10 KiB
JavaScript
1 line
10 KiB
JavaScript
!function(h){let b={handleTabClick:function(e){var s=h(e).attr("data-tab");h(".onecom_tabs_panel").fadeOut("fast"),h(e).parent().find(".active").removeClass("active"),h(e).addClass("active"),h("#"+s).fadeIn("fast")},formSubmission:function(s){h(s).on("click",".oc-save",function(e){e.preventDefault();e=h(s).attr("id");h(this).siblings("#oc_sp_spinner").removeClass("success").addClass("is_active"),"sp-settings"==e?(h(this).val("Saving"),b.protectionForm(s,h(this))):"sp-advanced-settings"==e?(h(this).val("Saving"),b.advanceSettings(s,h(this))):"sp-diagnostics"==e?b.spamDiagnostics(s,h(this)):"sp-clear-logs"==e&&(h(this).val("Clearing"),b.spamClearlogs(s,h(this)))})},protectionForm:function(s,t){var e=document.forms["sp-protect-options"].elements,i={action:"oc_save_settings",checks:{oc_sp_accept:e.oc_sp_accept.checked,oc_sp_referrer:e.oc_sp_referrer.checked,oc_sp_long:e.oc_sp_long.checked,oc_sp_short:e.oc_sp_short.checked,oc_sp_bbcode:e.oc_sp_bbcode.checked,oc_sp_exploit:e.oc_sp_exploit.checked,oc_sp_quickres:e.oc_sp_quickres.checked,oc_max_login_val:e.oc_max_login_val.value,oc_block_time:e.oc_block_time.value,one_sp_nonce:e.one_sp_nonce.value}};if(!b.protectionFormValidate(e))return h(t).siblings("#oc_sp_spinner").removeClass("is_active"),h(t).val("Save"),!1;h.post(ajaxurl,i,function(e){h(t).siblings("#oc_sp_spinner").removeClass("is_active"),e.success&&(h(t).siblings("#oc_sp_spinner").addClass("success"),h(s).parents().find(".notice-success").hide(),h("#oc-sp-success").fadeIn("slow"),h(s).find("input:submit").attr("disabled",!0),h(t).val("Save"),b.disableSubmit(),setTimeout(function(){h(t).siblings("#oc_sp_spinner").removeClass("success")},6e3))})},protectionFormValidate:function(e){let s,t=e.oc_max_login_val.value,i=e.oc_block_time.value;return null!==t&&""!==t&&/^([1-9]|10)$/.test(t.trim())||(h("input[name=oc_max_login_val]").addClass("oc_input_error"),s=1),null!==i&&""!==t&&/^(1[0-9]|[2-9][0-9]|[1-8][0-9]{2}|900)$/.test(i.trim())||(h("input[name=oc_block_time]").addClass("oc_input_error"),s=1),1!==s||(0===h(".sp-protect-options").find(".oc-dg-err").length&&h(".last-form-item").after('<div class="notice notice-error oc-dg-err"><p class="error">'+onespnotice.failed_login_validation_msg+"</p></div>"),!1)},advanceSettings:function(e,s){let t=document.forms["sp-advanced-settings"].elements,i=t.oc_sp_whitelistuser.checked,o=t.oc_spwhitelistip.checked,n=t.oc_spbadusragent.checked,a=t.oc_sp_urlshort.checked,c=t.oc_sp_proburl.checked,r={action:"oc_save_advanced_settings",oc_sp_whitelistuser:i,oc_spbadusragent:n,oc_sp_urlshort:a,oc_sp_proburl:c,oc_spwhitelistip:o,one_sp_nonce:t.one_sp_nonce.value,whitelist_usernames:""!==t.oc_whitelist_usernames.value?t.oc_whitelist_usernames.value.split("\n"):"",whitelist_ips:""!==t.oc_whitelist_ips.value?t.oc_whitelist_ips.value.split("\n"):"",whitelist_agents:""!==t.oc_whitelist_useragent.value?t.oc_whitelist_useragent.value.split("\n"):"",url_shorteners:""!==t.oc_url_shorters.value?t.oc_url_shorters.value.split("\n"):"",exploit_urls:""!==t.oc_exploit_urls.value?t.oc_exploit_urls.value.split("\n"):""};i||delete r.whitelist_usernames,o||delete r.whitelist_ips,n||delete r.whitelist_agents,a||delete r.url_shorteners,c||delete r.exploit_urls,b.executeAjaxRequest(e,r,s)},executeAjaxRequest:function(s,e,t){h.post(ajaxurl,e,function(e){h(t).siblings("#oc_sp_spinner").removeClass("is_active"),e.success&&(h(t).siblings("#oc_sp_spinner").addClass("success"),h(s).parents().find(".notice-success").hide(),h(s).parents().find(".advanced-settings").fadeIn("slow"),h(s).find("input:submit").attr("disabled",!0),h(t).val("Save"),b.disableSubmit(),setTimeout(function(){h(t).siblings("#oc_sp_spinner").removeClass("success")},6e3))})},spamDiagnostics:function(s,t){h(t).val("Checking");let e=document.forms["sp-diagnostics"].elements,i=h(s);i.parent().find(".oc-dg-err");if(5===i.find(":input").filter(function(){return""===h.trim(this.value)}).length)return h(s).parents().find(".oc-dg-err").remove(),i.parent().prepend('<div class="notice notice-error oc-dg-err"><p class="error">'+onespnotice.oc_notice+"</p></div>"),h(t).siblings("#oc_sp_spinner").removeClass("is_active"),h(t).val("Check for spam"),!1;if(!b.diagnosticsFormValidate(e))return h(s).parents().find(".oc-dg-err").remove(),i.parent().prepend('<div class="notice notice-error oc-dg-err"><p class="error">'+onespnotice.generic_validation_msg+"</p></div>"),h(t).siblings("#oc_sp_spinner").removeClass("is_active"),h(t).val("Check for spam"),!1;h(s).find("input:submit").attr("disabled",!0),h(s).parents().find(".oc-dg-err").remove();var o={action:"oc_check_spam_diagnostics",oc_validate_ip:e.oc_validate_ip.value,oc_validate_user:e.oc_validate_user.value,oc_validate_email:e.oc_validate_email.value,oc_validate_user_agent:e.oc_validate_user_agent.value,oc_validate_content:e.oc_validate_content.value,one_sp_nonce:e.one_sp_nonce.value};h.post(ajaxurl,o,function(e){h(t).siblings("#oc_sp_spinner").removeClass("is_active"),e.success&&(h(t).siblings("#oc_sp_spinner").addClass("success"),h(s).parents().find(".ocdg-results").html(e.data),h(s).find("input:submit").attr("disabled",!1),h(s)[0].reset(),h(t).val("Check for spam"),setTimeout(function(){h(t).siblings("#oc_sp_spinner").removeClass("success")},6e3))})},diagnosticsFormValidate:function(e){let s;var t=e.oc_validate_ip.value;let i=e.oc_validate_email.value;return 0<t.length&&!/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(t)&&!/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){0,7}[0-9a-fA-F]{1,4}|(([0-9a-fA-F]{1,4}:)*[0-9a-fA-F]{1,4})?::(([0-9a-fA-F]{1,4}:)*[0-9a-fA-F]{1,4})?|([0-9a-fA-F]{1,4}:){1,7}:|:(:[0-9a-fA-F]{1,4}){1,7})(%.+)?$/.test(t)&&(h("#ocvalidateip").addClass("oc_input_error"),s=1),0<i.length&&!/^\S+@\S+\.\S+$/.test(i.trim())&&(h("#ocvalidateemail").addClass("oc_input_error"),s=1),1!==s},spamClearlogs:function(s,t){h(s).find("input:submit").attr("disabled",!0);var e={action:"oc_clear_spam_logs",one_sp_nonce:h(s).find(".one_sp_nonce").val()};h.post(ajaxurl,e,function(e){h(t).siblings("#oc_sp_spinner").removeClass("is_active"),e.success&&(h(s).parents().find(".notice-success").hide(),h(t).siblings("#oc_sp_spinner").addClass("success"),h(s).parents().find(".one-sp-logs").html(e.data),h(s).find("input:submit").attr("disabled",!1))})},disableSubmit:function(){var e=[h("form.sp-protect-options"),h("form.sp-blocked-lists")],e=h.map(e,function(e){return e.get()});h(e).each(function(){h(this).data("serialized",h(this).serialize())}).on("change input",function(){h(this).find("input:submit").attr("disabled",h(this).serialize()==h(this).data("serialized"))}).find("input:submit, button:submit").attr("disabled",!0)},disableTextArea:function(e,s,t=""){e&&!0===e.prop("checked")?(s.prop("disabled",!1).css("background","#ffffff"),""!==t&&t.prop("disabled",!1).css("background","#ffffff")):e&&!0!==e.prop("checked")&&(s.prop("disabled",!0).css("background","#f0f0f1"),""!==t&&t.prop("disabled",!0).css("background","#f0f0f1"))},toggleOnChange:function(e,s,t=""){e.on("change",function(){var e=h(this).prop("checked");s.prop("disabled",!e),""!==t&&t.prop("disabled",!e),e?(s.css("background","#ffffff"),""!==t&&t.css("background","#ffffff")):(s.css("background","#f0f0f1"),""!==t&&t.css("background","#f0f0f1"))})}};h(document).ready(function(){h("form.sp-diagnostics input").focus(function(){h("form.sp-diagnostics input").removeClass("oc_input_error")}),h("form.sp-protect-options input").focus(function(){h("form.sp-protect-options input").removeClass("oc_input_error"),h("form.sp-protect-options .oc-dg-err").remove()}),h(".onecom_tab").click(function(e){b.handleTabClick(h(this)),h(".onecom_tab.active").data("tab")}),h(".oc-duration-filter").change(function(e){const s=h(this);if(s.hasClass("disabled-section"))return!1;h(".filter-summary ul li").removeClass("active"),s.parent().hasClass("active")||s.parent().addClass("active");var t={action:"oc_get_summary",duration:h("option:selected",this).data("duration")};h("span#oc_switch_spinner").css("visibility","visible");const i=h(".oc-summary-body").find(".oc_total_count"),o=h(".oc-summary-body").find(".oc_comment_count"),n=h(".oc-summary-body").find(".oc_registration_count"),a=h(".oc-summary-body").find(".oc_failed_login_count"),c=h(".oc-summary-body").find(".oc_other_count");h.post(ajaxurl,t,function(e){i.html(e.total_count),o.html(e.comments_count),n.html(e.registration_count),a.html(e.failed_login),c.html(e.other_count),h("#oc_switch_spinner").css("visibility","hidden")})});const e=h(".sp-blocked-lists"),s=e.find("#spbadusragent"),t=e.find("#spurlshort"),i=e.find("#spprobchk"),o=e.find("#spwhitelistusername"),n=e.find("#spwhitelistIP"),a=e.find(".oc_whitelist_usernames"),c=e.find(".oc-whitelist-ip"),r=e.find(".oc-whitelist-useragent"),l=e.find(".oc-url-shorters"),d=e.find(".oc-exploit-urls"),p=h("#spquickres"),_=h(".oc_max_login_val"),u=h(".oc_block_time");if(b.disableTextArea(o,a),b.disableTextArea(n,c),b.disableTextArea(s,r),b.disableTextArea(t,l),b.disableTextArea(i,d),b.disableTextArea(p,_,u),b.toggleOnChange(o,a),b.toggleOnChange(n,c),b.toggleOnChange(s,r),b.toggleOnChange(t,l),b.toggleOnChange(i,d),b.toggleOnChange(p,_,u),h(".oc-show-modal").on("click",function(e){e.preventDefault(),jQuery.ajax({url:ajaxurl,type:"POST",data:{action:"show_plugin_dependent_popup",popupContent:onespnotice.popupContent},success:function(e){void 0!==e.success&&!0===e.success&&(h("#oc_um_overlay").html(e.data),e=location.search,h("#oc_um_overlay").show(),ocSetModalData({isPremium:!0,feature:"spam_protection",featureAction:"getStarted",referrer:e}))},error:function(e,s,t){}})}),0===document.getElementsByClassName("disabled-section").length){let e=new IntersectionObserver(function(e){!0===e[0].isIntersecting?(h(".oc-sp-float-btn").hide(),h(".float-spinner").removeClass("success").hide()):(h(".oc-sp-float-btn").show(),h(".float-spinner").show())},{threshold:[0]});e.observe(document.querySelector("#onecom-sp-ui #settings .oc-save")),e.observe(document.querySelector("#onecom-sp-ui #advanced_settings .oc-save"))}var f=h("#onecom-sp-ui").find("form.sp-protect-options"),m=h("#onecom-sp-ui").find("form.sp-blocked-lists"),v=h("#onecom-sp-ui").find("form.sp-diagnostics"),g=h("#onecom-sp-ui").find("form#sp-clear-logs");b.formSubmission(f),b.formSubmission(m),b.formSubmission(v),b.formSubmission(g),b.disableSubmit()})}(jQuery); |