Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion classes/factories/FrmCaptchaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FrmCaptchaFactory {
*
* @since 6.8.4
*
* @param string $captcha_type Either 'active', 'recaptcha', 'hcaptcha' or 'turnstile'. If active, the global setting will be used.
* @param string $captcha_type Either 'active', 'recaptcha', 'hcaptcha', 'turnstile' or 'infopeak'. If active, the global setting will be used.
*
* @return FrmFieldCaptchaSettings
*/
Expand Down Expand Up @@ -41,6 +41,7 @@ private static function get_settings_class( $active_captcha ) {
'recaptcha' => 'FrmRecaptchaSettings',
'hcaptcha' => 'FrmHcaptchaSettings',
'turnstile' => 'FrmTurnstileSettings',
'infopeak' => 'FrmInfopeakSettings',
);

if ( ! isset( $settings_classes[ $active_captcha ] ) ) {
Expand Down
135 changes: 135 additions & 0 deletions classes/models/FrmInfopeakSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( 'You are not allowed to call this page directly.' );
}

/**
* @since x.x
*/
class FrmInfopeakSettings extends FrmFieldCaptchaSettings {

/**
* InfoPeak Captcha has a reCAPTCHA compatible siteverify endpoint.
*
* @since x.x
*
* @return void
*/
protected function set_endpoint() {
$this->endpoint = 'https://captcha.infopeak.io/siteverify';
}

/**
* @since x.x
*
* @return string
*/
public function get_name() {
return 'InfoPeak Captcha';
}

/**
* @since x.x
*
* @return string
*/
public function get_element_class_name() {
return 'infopeak-captcha';
}

/**
* @since x.x
*
* @return string
*/
public function get_documentation_url() {
return 'https://accounts.infopeak.io/signup?plan=captcha';
}

/**
* InfoPeak Captcha global settings are saved as infopeak_pubkey and infopeak_privkey.
*
* @since x.x
*
* @return string
*/
public function get_settings_prefix() {
return 'infopeak_';
}

/**
* @since x.x
*
* @return string
*/
public function get_site_key_tooltip() {
return __(
'InfoPeak Captcha is an EU-hosted captcha without cookies or image puzzles. The visitor\'s browser solves a small proof-of-work challenge while the form is filled in.',
'formidable'
);
}

/**
* The widget has a single size and theme, so the data-size and data-theme attributes are not used.
*
* @since x.x
*
* @param array $attributes
* @param array $field
*
* @return array
*/
public function add_front_end_element_attributes( $attributes, $field ) {
return $attributes;
}

/**
* @since x.x
*
* @return bool
*/
public function should_show_captcha_size() {
return false;
}

/**
* @since x.x
*
* @return bool
*/
public function should_show_captcha_theme() {
return false;
}

/**
* Add the error codes that are specific to InfoPeak Captcha.
*
* @since x.x
*
* @return array<string,string>
*/
public function get_error_code_messages() {
return array_merge(
parent::get_error_code_messages(),
array(
'quota-exceeded' => __( 'The monthly verification quota for this InfoPeak Captcha site key is used up.', 'formidable' ),
)
);
}

/**
* A used up quota cannot be fixed by the person filling out the form.
*
* @since x.x
*
* @return array<int,string>
*/
public function get_configuration_error_codes() {
return array_merge(
parent::get_configuration_error_codes(),
array(
'quota-exceeded',
)
);
}
}
25 changes: 25 additions & 0 deletions classes/models/FrmSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,24 @@ class FrmSettings {
*/
public $turnstile_privkey;

/**
* Settings for InfoPeak Captcha.
*/

/**
* @since x.x
*
* @var string
*/
public $infopeak_pubkey;

/**
* @since x.x
*
* @var string|null
*/
public $infopeak_privkey;

/**
* @var bool
*/
Expand Down Expand Up @@ -476,6 +494,10 @@ private function fill_captcha_settings() {
$this->turnstile_privkey = '';
}

if ( ! isset( $this->infopeak_privkey ) ) {
$this->infopeak_privkey = '';
}

if ( ! isset( $this->pubkey ) ) {
// Get the options from the database.
$recaptcha_opt = is_multisite() ? get_site_option( 'recaptcha' ) : get_option( 'recaptcha' );
Expand Down Expand Up @@ -519,6 +541,7 @@ private function set_supported_captcha() {
'recaptcha' => '',
'hcaptcha' => 'hcaptcha_',
'turnstile' => 'turnstile_',
'infopeak' => 'infopeak_',
);

if ( array_key_exists( $this->active_captcha, $prefixes ) ) {
Expand Down Expand Up @@ -648,6 +671,8 @@ private function update_settings( $params ) {
$this->hcaptcha_privkey = trim( $params['frm_hcaptcha_privkey'] );
$this->turnstile_pubkey = trim( $params['frm_turnstile_pubkey'] );
$this->turnstile_privkey = trim( $params['frm_turnstile_privkey'] );
$this->infopeak_pubkey = trim( $params['frm_infopeak_pubkey'] );
$this->infopeak_privkey = trim( $params['frm_infopeak_privkey'] );
$this->load_style = $params['frm_load_style'];
$this->custom_css = $params['frm_custom_css'];
$this->default_email = $params['frm_default_email'];
Expand Down
23 changes: 23 additions & 0 deletions classes/models/fields/FrmFieldCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ protected function api_url() {
return $this->hcaptcha_api_url();
}

if ( 'infopeak' === $active_mode ) {
return $this->infopeak_api_url();
}

return $this->turnstile_api_url();
}

Expand Down Expand Up @@ -305,6 +309,25 @@ protected function turnstile_api_url() {
);
}

/**
* The InfoPeak Captcha script renders every .infopeak-captcha element on the page.
* It also renders new elements when it runs again, which happens when a form page is loaded with AJAX.
*
* @since x.x
*
* @return string
*/
protected function infopeak_api_url() {
/**
* Allows updating the InfoPeak Captcha js api url.
*
* @since x.x
*
* @param string $api_js_url
*/
return apply_filters( 'frm_infopeak_js_url', 'https://captcha.infopeak.io/infopeak-captcha.js' );
}

/**
* @param FrmSettings $frm_settings
*
Expand Down
35 changes: 32 additions & 3 deletions classes/views/frm-settings/captcha/captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@
<?php esc_html_e( 'Select captcha type', 'formidable' ); ?>
</p>
<div class="frm_captchas frm-long-icon-buttons" role="tablist" aria-labelledby="frm_captcha_type_label">
<input type="radio" name="frm_active_captcha" id="frm-recaptcha" value="recaptcha" data-frmhide="#hcaptcha_settings,#turnstile_settings" data-frmshow="#recaptcha_settings" <?php checked( $frm_settings->active_captcha, 'recaptcha' ); ?> />
<input type="radio" name="frm_active_captcha" id="frm-recaptcha" value="recaptcha" data-frmhide="#hcaptcha_settings,#turnstile_settings,#infopeak_settings" data-frmshow="#recaptcha_settings" <?php checked( $frm_settings->active_captcha, 'recaptcha' ); ?> />
<label for="frm-recaptcha" id="frm-recaptcha-tab" role="tab" tabindex="<?php echo 'recaptcha' === $frm_settings->active_captcha ? '0' : '-1'; ?>" aria-selected="<?php echo 'recaptcha' === $frm_settings->active_captcha ? 'true' : 'false'; ?>" aria-controls="recaptcha_settings">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 38 38"><path fill="#1C3AA9" d="M38.6 19a19.8 19.8 0 0 0 0-.7V2.8L34.3 7a19.1 19.1 0 0 0-30.1.6l7 7a9.3 9.3 0 0 1 2.9-3.1c1.2-1 3-1.8 5.3-1.8l.7.1a9.3 9.3 0 0 1 7.1 4.3l-5 5h16.4"/><path fill="#4285F4" d="M19.3 0H3l4.3 4.3a19.1 19.1 0 0 0 .5 30l7.1-7a9.3 9.3 0 0 1-3.2-2.8c-1-1.2-1.7-3-1.7-5.4v-.6a9.3 9.3 0 0 1 4.4-7.1l5 5V0"/><path fill="#ABABAB" d="M.3 19.1v16.4l4.3-4.3a19.1 19.1 0 0 0 30-.5l-7-7.2a9.3 9.3 0 0 1-2.8 3.2c-1.3 1-3 1.8-5.4 1.8a2 2 0 0 1-.7-.1 9.3 9.3 0 0 1-7-4.3l4.9-5H.3"/></svg>
<?php esc_html_e( 'reCAPTCHA', 'formidable' ); ?>
</label>
<input type="radio" name="frm_active_captcha" id="frm-hcaptcha" value="hcaptcha" data-frmhide="#recaptcha_settings,#turnstile_settings" data-frmshow="#hcaptcha_settings" <?php checked( $frm_settings->active_captcha, 'hcaptcha' ); ?> />
<input type="radio" name="frm_active_captcha" id="frm-hcaptcha" value="hcaptcha" data-frmhide="#recaptcha_settings,#turnstile_settings,#infopeak_settings" data-frmshow="#hcaptcha_settings" <?php checked( $frm_settings->active_captcha, 'hcaptcha' ); ?> />
<label for="frm-hcaptcha" id="frm-hcaptcha-tab" role="tab" tabindex="<?php echo 'hcaptcha' === $frm_settings->active_captcha ? '0' : '-1'; ?>" aria-selected="<?php echo 'hcaptcha' === $frm_settings->active_captcha ? 'true' : 'false'; ?>" aria-controls="hcaptcha_settings">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 38 38"><path fill="#0074BF" d="M28.8 33.3H24V38h4.8v-4.8Z" opacity=".5"/><path fill="#0074BF" d="M24 33.3h-4.8V38H24v-4.8Zm-4.8 0h-4.7V38h4.8v-4.8Z" opacity=".7"/><path fill="#0074BF" d="M14.5 33.3H9.7V38h4.8v-4.8Z" opacity=".5"/><path fill="#0082BF" d="M33.5 28.5h-4.8v4.8h4.8v-4.8Z" opacity=".7"/><path fill="#0082BF" d="M28.8 28.5H24v4.8h4.8v-4.8Z" opacity=".8"/><path fill="#0082BF" d="M24 28.5h-4.8v4.8H24v-4.8Zm-4.8 0h-4.7v4.8h4.8v-4.8Z"/><path fill="#0082BF" d="M14.5 28.5H9.7v4.8h4.8v-4.8Z" opacity=".8"/><path fill="#0082BF" d="M9.8 28.5H5v4.8h4.8v-4.8Z" opacity=".7"/><path fill="#008FBF" d="M38.3 23.8h-4.8v4.7h4.8v-4.8Z" opacity=".5"/><path fill="#008FBF" d="M33.5 23.8h-4.8v4.7h4.8v-4.8Z" opacity=".8"/><path fill="#008FBF" d="M28.8 23.8H24v4.7h4.8v-4.8Zm-4.8 0h-4.8v4.7H24v-4.8Zm-4.8 0h-4.7v4.7h4.8v-4.8Zm-4.7 0H9.7v4.7h4.8v-4.8Z"/><path fill="#008FBF" d="M9.8 23.8H5v4.7h4.8v-4.8Z" opacity=".8"/><path fill="#008FBF" d="M5 23.8H.2v4.7H5v-4.8Z" opacity=".5"/><path fill="#009DBF" d="M38.3 19h-4.8v4.8h4.8V19Z" opacity=".7"/><path fill="#009DBF" d="M33.5 19h-4.8v4.8h4.8V19Zm-4.8 0H24v4.8h4.8V19ZM24 19h-4.8v4.8H24V19Zm-4.8 0h-4.7v4.8h4.8V19Zm-4.7 0H9.7v4.8h4.8V19Zm-4.8 0H5v4.8h4.8V19Z"/><path fill="#009DBF" d="M5 19H.2v4.8H5V19Z" opacity=".7"/><path fill="#00ABBF" d="M38.3 14.3h-4.8V19h4.8v-4.8Z" opacity=".7"/><path fill="#00ABBF" d="M33.5 14.3h-4.8V19h4.8v-4.8Zm-4.8 0H24V19h4.8v-4.8Zm-4.7 0h-4.8V19H24v-4.8Zm-4.8 0h-4.7V19h4.8v-4.8Zm-4.7 0H9.7V19h4.8v-4.8Zm-4.8 0H5V19h4.8v-4.8Z"/><path fill="#00ABBF" d="M5 14.3H.2V19H5v-4.8Z" opacity=".7"/><path fill="#00B9BF" d="M38.3 9.5h-4.8v4.8h4.8V9.4Z" opacity=".5"/><path fill="#00B9BF" d="M33.5 9.5h-4.8v4.8h4.8V9.4Z" opacity=".8"/><path fill="#00B9BF" d="M28.8 9.5H24v4.8h4.8V9.4Zm-4.8 0h-4.8v4.8H24V9.4Zm-4.8 0h-4.7v4.8h4.8V9.4Zm-4.7 0H9.7v4.8h4.8V9.4Z"/><path fill="#00B9BF" d="M9.8 9.5H5v4.8h4.8V9.4Z" opacity=".8"/><path fill="#00B9BF" d="M5 9.5H.2v4.8H5V9.4Z" opacity=".5"/><path fill="#00C6BF" d="M33.5 4.8h-4.8v4.7h4.8V4.7Z" opacity=".7"/><path fill="#00C6BF" d="M28.8 4.8H24v4.7h4.8V4.7Z" opacity=".8"/><path fill="#00C6BF" d="M24 4.8h-4.8v4.7H24V4.7Zm-4.8 0h-4.7v4.7h4.8V4.7Z"/><path fill="#00C6BF" d="M14.5 4.8H9.7v4.7h4.8V4.7Z" opacity=".8"/><path fill="#00C6BF" d="M9.8 4.8H5v4.7h4.8V4.7Z" opacity=".7"/><path fill="#00D4BF" d="M28.8 0H24v4.8h4.8V0Z" opacity=".5"/><path fill="#00D4BF" d="M24 0h-4.8v4.8H24V0Zm-4.8 0h-4.7v4.8h4.8V0Z" opacity=".7"/><path fill="#00D4BF" d="M14.5 0H9.7v4.8h4.8V0Z" opacity=".5"/><path fill="#fff" d="m12.8 17.5 1.3-3c.4-.7.4-1.7-.1-2.2a1 1 0 0 0-.3-.2 1.5 1.5 0 0 0-1.2-.1 2 2 0 0 0-1.1.8L8.9 19c-.7 1.9-.4 5.4 2.2 8 2.8 2.7 6.8 3.4 9.3 1.5l.3-.2 7.9-6.6c.3-.3 1-1 .4-1.7-.5-.7-1.4-.2-1.8 0l-4.5 3.3a.2.2 0 0 1-.3 0c-.1-.1-.2-.5 0-.6l7-6c.5-.5.6-1.2.1-1.8-.4-.5-1.2-.5-1.8 0l-6.2 4.9a.3.3 0 0 1-.4 0v-.1c-.1-.2-.2-.4 0-.5l7-6.9a1.4 1.4 0 0 0 .1-2 1.3 1.3 0 0 0-1-.3c-.3 0-.6.1-1 .4l-7.1 6.8c-.2.1-.5 0-.6-.2v-.2l5.6-6.3c.5-.5.6-1.4 0-2-.4-.5-1.3-.5-1.9 0l-8.4 9.3c-.3.3-.8.3-1 .2v-.5Z"/></svg>
<?php esc_html_e( 'hCaptcha', 'formidable' ); ?>
</label>
<input type="radio" name="frm_active_captcha" id="frm-turnstile" value="turnstile" data-frmhide="#recaptcha_settings,#hcaptcha_settings" data-frmshow="#turnstile_settings" <?php checked( $frm_settings->active_captcha, 'turnstile' ); ?> />
<input type="radio" name="frm_active_captcha" id="frm-turnstile" value="turnstile" data-frmhide="#recaptcha_settings,#hcaptcha_settings,#infopeak_settings" data-frmshow="#turnstile_settings" <?php checked( $frm_settings->active_captcha, 'turnstile' ); ?> />
<label for="frm-turnstile" id="frm-turnstile-tab" role="tab" tabindex="<?php echo 'turnstile' === $frm_settings->active_captcha ? '0' : '-1'; ?>" aria-selected="<?php echo 'turnstile' === $frm_settings->active_captcha ? 'true' : 'false'; ?>" aria-controls="turnstile_settings">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 65.6 30"><g clip-path="url(#turnstileClipPath)"><path fill="#FBAD41" d="M52.7 13H52a.4.4 0 0 0-.3.3l-1 3.3c-.3 1.4-.2 2.7.5 3.6.6.9 1.6 1.4 2.9 1.5l5 .3c.2 0 .3 0 .4.2a.5.5 0 0 1 0 .4.6.6 0 0 1-.5.4l-5.3.3c-2.8.2-5.9 2.5-7 5.3l-.3 1a.3.3 0 0 0 .2.4h18a.5.5 0 0 0 .5-.4 13.1 13.1 0 0 0 .5-3.5 13 13 0 0 0-12.9-13"/><path fill="#F6821F" d="m44.8 29.6.3-1.2c.4-1.4.3-2.7-.4-3.6a3.6 3.6 0 0 0-2.9-1.5L18.2 23a.5.5 0 0 1-.4-.2.5.5 0 0 1 0-.4.6.6 0 0 1 .5-.4l23.9-.4a8.5 8.5 0 0 0 7-5.2l1.3-3.6a1 1 0 0 0 0-.5C49 5.3 42.9 0 35.5 0c-6.9 0-12.7 4.5-14.8 10.7a7 7 0 0 0-4.9-1.4 7 7 0 0 0-6.2 6.3 7.1 7.1 0 0 0 .2 2.5A10 10 0 0 0 0 29.6a.5.5 0 0 0 .5.4h43.7a.6.6 0 0 0 .5-.4"/></g><defs><clipPath id="turnstileClipPath"><path fill="#FFF" d="M0 0h204v30H0z"/></clipPath></defs></svg>
<?php esc_html_e( 'Turnstile', 'formidable' ); ?>
</label>
<input type="radio" name="frm_active_captcha" id="frm-infopeak" value="infopeak" data-frmhide="#recaptcha_settings,#hcaptcha_settings,#turnstile_settings" data-frmshow="#infopeak_settings" <?php checked( $frm_settings->active_captcha, 'infopeak' ); ?> />
<label for="frm-infopeak" id="frm-infopeak-tab" role="tab" tabindex="<?php echo 'infopeak' === $frm_settings->active_captcha ? '0' : '-1'; ?>" aria-selected="<?php echo 'infopeak' === $frm_settings->active_captcha ? 'true' : 'false'; ?>" aria-controls="infopeak_settings">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="8 8 84 84"><rect x="8" y="8" width="46.5" height="28.5" rx="4" fill="#7C3AED"/><rect x="63.5" y="8" width="28.5" height="46.5" rx="4" fill="#0EA5E9"/><rect x="45.5" y="63.5" width="46.5" height="28.5" rx="4" fill="#10B981"/><rect x="8" y="45.5" width="28.5" height="46.5" rx="4" fill="#F59E0B"/></svg>
<?php esc_html_e( 'InfoPeak', 'formidable' ); ?>
</label>
</div>

<div class="frm_note_style frm-with-icon frm-mb-0 frm_hidden">
Expand Down Expand Up @@ -151,6 +156,30 @@
</details>
</div>

<?php
$captcha_settings_attrs = array(
'id' => 'infopeak_settings',
'role' => 'tabpanel',
'aria-labelledby' => 'frm-infopeak-tab',
);

if ( 'infopeak' !== $frm_settings->active_captcha ) {
$captcha_settings_attrs['class'] = 'frm_hidden';
}
?>
<div<?php FrmAppHelper::array_to_html_params( $captcha_settings_attrs, true ); ?>>
<?php
$captcha = 'infopeak';
require FrmAppHelper::plugin_path() . '/classes/views/frm-settings/captcha/captcha_summary.php';
?>
<div class="frm_grid_container">
<?php
require FrmAppHelper::plugin_path() . '/classes/views/frm-settings/captcha/captcha_keys.php';
?>
</div>
</details>
</div>

<h3 class="frm-settings-section-heading"><?php esc_html_e( 'Spam checks', 'formidable' ); ?></h3>
<?php
$spam_handling = FrmSpamEntriesHelper::sanitize_handling( $frm_settings->spam_handling );
Expand Down
Binary file added images/infopeak.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions js/formidable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,11 @@ function frmFrontFormJS() {
);
}

// InfoPeak Captcha tokens can only be used once, so get a new one for the next submit.
if ( window.infopeakCaptcha ) {
object.querySelectorAll( '.infopeak-captcha' ).forEach( captchaEl => window.infopeakCaptcha.reset( captchaEl ) );
}

jQuery( document ).trigger( 'frmFormErrors', [ object, response ] );

fieldsets.forEach( field => field.classList.remove( 'frm_doing_ajax' ) );
Expand Down
Loading