| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
die( 'You are not allowed to call this page directly.' ); |
| 4 |
} |
| 5 |
|
| 6 |
/** |
| 7 |
* @since 6.8.4 |
| 8 |
*/ |
| 9 |
class FrmRecaptchaSettings extends FrmFieldCaptchaSettings { |
| 10 |
|
| 11 |
/** |
| 12 |
* @since 6.8.4 |
| 13 |
* |
| 14 |
* @return void |
| 15 |
*/ |
| 16 |
protected function set_endpoint() { |
| 17 |
$this->endpoint = 'https://www.google.com/recaptcha/api/siteverify'; |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* @since 6.8.4 |
| 22 |
* |
| 23 |
* @return string |
| 24 |
*/ |
| 25 |
public function getName() { |
| 26 |
return 'reCAPTCHA'; |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
/** |
| 31 |
* @since 6.8.4 |
| 32 |
* |
| 33 |
* @return string |
| 34 |
*/ |
| 35 |
public function get_element_class_name() { |
| 36 |
return 'g-recaptcha'; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* @since 6.8.4 |
| 41 |
* |
| 42 |
* @return string |
| 43 |
*/ |
| 44 |
public function get_documentation_url() { |
| 45 |
return 'https://www.google.com/recaptcha/'; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* @since 6.8.4 |
| 50 |
* |
| 51 |
* @return string |
| 52 |
*/ |
| 53 |
public function get_site_key_tooltip() { |
| 54 |
return __( 'reCAPTCHA is a free, accessible CAPTCHA service that helps to digitize books while blocking spam on your blog. reCAPTCHA asks commenters to retype two words scanned from a book to prove that they are a human. This verifies that they are not a spambot.', 'formidable' ); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Add additional element attributes for reCAPTCHA. |
| 59 |
* |
| 60 |
* @since 6.8.4 |
| 61 |
* |
| 62 |
* @param array $attributes |
| 63 |
* @param array $field |
| 64 |
* @return array |
| 65 |
*/ |
| 66 |
public function add_front_end_element_attributes( $attributes, $field ) { |
| 67 |
$attributes = parent::add_front_end_element_attributes( $attributes, $field ); |
| 68 |
$captcha_size = $attributes['data-size']; |
| 69 |
|
| 70 |
if ( $captcha_size === 'invisible' && ! $this->frm_settings->re_multi ) { |
| 71 |
$attributes['data-callback'] = 'frmAfterRecaptcha'; |
| 72 |
} |
| 73 |
|
| 74 |
return $attributes; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* @since 6.8.4 |
| 79 |
* |
| 80 |
* @param array $field |
| 81 |
* @return string |
| 82 |
*/ |
| 83 |
protected function get_captcha_size( $field ) { |
| 84 |
if ( $this->captcha_is_invisible() ) { |
| 85 |
return 'invisible'; |
| 86 |
} |
| 87 |
return parent::get_captcha_size( $field ); |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Show the Captcha field size setting if the captcha is visible. |
| 92 |
* |
| 93 |
* @since 6.8.4 |
| 94 |
* |
| 95 |
* @return bool |
| 96 |
*/ |
| 97 |
public function should_show_captcha_size() { |
| 98 |
return ! $this->captcha_is_invisible(); |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* @since 6.8.4 |
| 103 |
* |
| 104 |
* @return bool |
| 105 |
*/ |
| 106 |
public function should_show_captcha_theme() { |
| 107 |
return ! $this->captcha_is_invisible(); |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* @since 6.8.4 |
| 112 |
* |
| 113 |
* @return bool |
| 114 |
*/ |
| 115 |
private function captcha_is_invisible() { |
| 116 |
return in_array( $this->frm_settings->re_type, array( 'invisible', 'v3' ), true ); |
| 117 |
} |
| 118 |
} |
| 119 |
|