diff --git a/friendly-captcha/includes/core.php b/friendly-captcha/includes/core.php index 4eb3600..edc60d7 100644 --- a/friendly-captcha/includes/core.php +++ b/friendly-captcha/includes/core.php @@ -57,6 +57,7 @@ class FriendlyCaptcha_Plugin { public static $option_pb_login_integration_active_name = "frcaptcha_pb_login_integration_active"; public static $option_pb_register_integration_active_name = "frcaptcha_pb_register_integration_active"; public static $option_pb_reset_password_integration_active_name = "frcaptcha_pb_reset_password_integration_active"; + public static $option_divi_integration_active_name = "frcaptcha_divi_integration_active"; public static $option_widget_language_name = "frcaptcha_widget_language"; public static $option_widget_dark_theme_active_name = "frcaptcha_widget_dark_theme_active"; @@ -222,6 +223,11 @@ public function get_pb_reset_password_active() { return get_option(FriendlyCaptcha_Plugin::$option_pb_reset_password_integration_active_name) == 1; } + public function get_divi_active() { + return get_option(FriendlyCaptcha_Plugin::$option_divi_integration_active_name) == 1; + } + + /* Widget options */ public function get_widget_language() { @@ -379,6 +385,10 @@ public function get_global_puzzle_endpoint_active() { } if (FriendlyCaptcha_Plugin::$instance->get_pb_reset_password_active()) { - require plugin_dir_path( __FILE__ ) . '../modules/profile-builder/profile_builder_reset_password.php'; + require plugin_dir_path(__FILE__) . '../modules/profile-builder/profile_builder_reset_password.php'; + } + + if (FriendlyCaptcha_Plugin::$instance->get_divi_active()) { + require plugin_dir_path( __FILE__ ) . '../modules/divi/divi.php'; } // } diff --git a/friendly-captcha/includes/settings.php b/friendly-captcha/includes/settings.php index ee29289..237c8d7 100644 --- a/friendly-captcha/includes/settings.php +++ b/friendly-captcha/includes/settings.php @@ -140,6 +140,11 @@ function frcaptcha_settings_init() { FriendlyCaptcha_Plugin::$option_pb_reset_password_integration_active_name ); + register_setting( + FriendlyCaptcha_Plugin::$option_group, + FriendlyCaptcha_Plugin::$option_divi_integration_active_name + ); + /*Widget settings */ register_setting( FriendlyCaptcha_Plugin::$option_group, @@ -552,6 +557,18 @@ function frcaptcha_settings_init() { ) ); + add_settings_field( + 'frcaptcha_settings_divi_integration_field', + 'Divi Theme Contact Form', 'frcaptcha_settings_field_callback', + 'friendly_captcha_admin', + 'frcaptcha_integrations_settings_section', + array( + "option_name" => FriendlyCaptcha_Plugin::$option_divi_integration_active_name, + "description" => "Enable Friendly Captcha and replace ReCaptcha in the Divi Theme contact form.
Important: Please choose 'FriendlyCaptcha verification' as spam protection in each individual Divi contact form.", + "type" => "checkbox" + ) + ); + /* Widget settings section */ // Section diff --git a/friendly-captcha/modules/divi/divi.php b/friendly-captcha/modules/divi/divi.php new file mode 100644 index 0000000..a2b6f74 --- /dev/null +++ b/friendly-captcha/modules/divi/divi.php @@ -0,0 +1,88 @@ +is_configured() or !$plugin->get_divi_active()) { + return; + } + + $_names_by_slug['third-party']['frcaptcha'] = 'FriendlyCaptcha verification'; + return $_names_by_slug; + } + + public static function injectAccount($value, $option = 'et_core_api_spam_options') + { + $plugin = FriendlyCaptcha_Plugin::$instance; + + if (!$plugin->is_configured() or !$plugin->get_divi_active()) { + return; + } + + $value = maybe_unserialize($value); + $value['accounts']['frcaptcha']['default'] = [ + 'site_key' => 'default', + 'secret_key' => 'default' + ]; + + return $value; + + } + + public static function addWidget($output, $tag = null) + { + if (!in_array($tag, self::SUPPORTED_SHORTCODES)) { + return $output; + } + + $plugin = FriendlyCaptcha_Plugin::$instance; + + if (!$plugin->is_configured() or !$plugin->get_divi_active()) { + return; + } + + $output = str_replace(self::INSERT_BEFORE, + frcaptcha_generate_widget_tag_from_plugin(FriendlyCaptcha_Plugin::$instance) . self::INSERT_BEFORE, + $output + ); + + return $output; + } + + /** + * Fake Token in POST + * + * @see \ET_Builder_Module_Type_WithSpamProtection::is_spam_submission + */ + public static function fakeToken() + { + if (isset($_POST['frc-captcha-solution'])) { + $_POST['token'] = $_POST['frc-captcha-solution']; + } + } +} diff --git a/friendly-captcha/modules/divi/frcaptcha_divi_core_addon.php b/friendly-captcha/modules/divi/frcaptcha_divi_core_addon.php new file mode 100644 index 0000000..e6e8e86 --- /dev/null +++ b/friendly-captcha/modules/divi/frcaptcha_divi_core_addon.php @@ -0,0 +1,95 @@ +_add_actions_and_filters(); + } + + protected function _add_actions_and_filters() { + if ( ! is_admin() && ! et_core_is_fb_enabled() ) { + add_action( 'wp_enqueue_scripts', array( $this, 'action_wp_enqueue_scripts' ) ); + } + } + + public function action_wp_enqueue_scripts() { + $plugin = FriendlyCaptcha_Plugin::$instance; + + if ( !$plugin->is_configured() ) { + return; + } + + if ( ! $this->is_enabled() ) { + return; + } + + frcaptcha_enqueue_widget_scripts(true); + + wp_dequeue_script('et-core-api-spam-recaptcha'); + } + + public function is_enabled() { + $has_frcaptcha_module = true; + + if ( class_exists( 'ET_Dynamic_Assets' ) ) { + $et_dynamic_module_framework = et_builder_dynamic_module_framework(); + $is_dynamic_framework_enabled = et_builder_is_frontend() && 'on' === $et_dynamic_module_framework; + $is_dynamic_css_enabled = et_builder_is_frontend() && et_use_dynamic_css(); + + if ( $is_dynamic_framework_enabled && $is_dynamic_css_enabled ) { + $et_dynamic_assets = ET_Dynamic_Assets::init(); + $saved_shortcodes = $et_dynamic_assets->get_saved_page_shortcodes(); + $frcaptcha_modules = array( 'et_pb_contact_form', 'et_pb_signup' ); + $has_frcaptcha_module = ! empty( array_intersect( $saved_shortcodes, $frcaptcha_modules ) ); + } + } + + return $has_frcaptcha_module; + } + + public function verify_form_submission() { + $plugin = FriendlyCaptcha_Plugin::$instance; + + if ( !$plugin->is_configured() ) { + return array( + 'success' => true, + 'score' => 100000, + ); + } + + if ( ! $this->is_enabled() ) { + return array( + 'success' => true, + 'score' => 100000, + ); + } + + $solution = et_()->array_get_sanitized( $_POST, 'token' ); + + $plugin = FriendlyCaptcha_Plugin::$instance; + $verification = frcaptcha_verify_captcha_solution($solution, $plugin->get_sitekey(), $plugin->get_api_key()); + + if ( $verification["success"] ) { + return array( + 'success' => true, + 'score' => 100000, + ); + } else { + return 'Captcha error'; + } + } + + public function get_account_fields() { + return array(); + } +} diff --git a/friendly-captcha/modules/divi/index.php b/friendly-captcha/modules/divi/index.php new file mode 100644 index 0000000..bacffcc --- /dev/null +++ b/friendly-captcha/modules/divi/index.php @@ -0,0 +1 @@ +is_configured() ) { @@ -25,7 +25,7 @@ function frcaptcha_enqueue_widget_scripts() { true ); - if ( $plugin->get_enable_mutation_observer() ) { + if ( $forceMutationObserver || $plugin->get_enable_mutation_observer() ) { wp_enqueue_script( 'friendly-captcha-mutation-observer', plugin_dir_url( __FILE__ ) . 'mutation-observer.js', array(), @@ -61,7 +61,10 @@ function frcaptcha_transform_friendly_captcha_script_tags( $tag, $handle, $src ) if ( 'friendly-captcha-widget-fallback' == $handle) { return str_replace( 'get_global_puzzle_endpoint_active(); $eu = $plugin->get_eu_puzzle_endpoint_active(); - + if ($global && $eu) { $extra_attributes = "data-puzzle-endpoint=\"https://eu-api.friendlycaptcha.eu/api/v1/puzzle,https://api.friendlycaptcha.com/api/v1/puzzle\""; } else if ($eu) {