| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Modules\Form; |
| 4 |
|
| 5 |
use FluentForm\Framework\Foundation\Application; |
| 6 |
use FluentForm\Framework\Helpers\ArrayHelper; |
| 7 |
|
| 8 |
|
| 9 |
class HoneyPot |
| 10 |
{ |
| 11 |
private $app; |
| 12 |
|
| 13 |
public function __construct(Application $application) |
| 14 |
{ |
| 15 |
$this->app = $application; |
| 16 |
} |
| 17 |
|
| 18 |
public function renderHoneyPot($form) |
| 19 |
{ |
| 20 |
if (!$this->isEnabled($form->id)) { |
| 21 |
return; |
| 22 |
} |
| 23 |
?> |
| 24 |
<span style="display: none !important;"><input type="checkbox" name="<?php echo $this->getFieldName($form->id); ?>" value="1" |
| 25 |
style="display:none !important;" tabindex="-1" autocomplete="off"></span> |
| 26 |
<?php |
| 27 |
} |
| 28 |
|
| 29 |
public function verify($insertData, $requestData, $formId) |
| 30 |
{ |
| 31 |
if (!$this->isEnabled($formId)) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
// Now verify |
| 36 |
if (ArrayHelper::get($requestData, $this->getFieldName($formId))) { |
| 37 |
// It's a bot! Block him |
| 38 |
wp_send_json( |
| 39 |
array( |
| 40 |
'errors' => 'Sorry! You can not submit this form at this moment!' |
| 41 |
), 422); |
| 42 |
} |
| 43 |
|
| 44 |
return; |
| 45 |
} |
| 46 |
|
| 47 |
public function isEnabled($formId = false) |
| 48 |
{ |
| 49 |
$option = get_option('_fluentform_global_form_settings'); |
| 50 |
$status = ArrayHelper::get($option, 'misc.honeypotStatus') == 'yes'; |
| 51 |
return apply_filters('fluentform_honeypot_status', $status, $formId); |
| 52 |
} |
| 53 |
|
| 54 |
private function getFieldName($formId) |
| 55 |
{ |
| 56 |
return apply_filters('fluentform_honeypot_name', 'item__' . $formId . '__fluent_checkme_', $formId); |
| 57 |
} |
| 58 |
|
| 59 |
} |